Point.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace app\common\validate;
  3. use think\Validate;
  4. /**
  5. *
  6. *
  7. * ----------------------------------------------------------------------------
  8. *
  9. * 验证器
  10. */
  11. class Point extends Validate
  12. {
  13. protected $rule = [
  14. 'member_name' => 'require',
  15. 'points_num' => 'number|min:1',
  16. 'goodsname' => 'require',
  17. 'goodsprice' => 'require',
  18. 'goodspoints' => 'require|number',
  19. 'goodsserial' => 'require',
  20. 'goodsstorage' => 'require|number',
  21. 'sort' => 'require|number',
  22. 'limitnum' => 'checkPointLimitnum:1',
  23. 'starttime' => 'checkPointStartTime:1',
  24. 'endtime' => 'checkPointEndTime:1',
  25. 'shippingcode' => 'require'
  26. ];
  27. protected $message = [
  28. 'member_name.require' => '会员信息错误,请重新填写会员名',
  29. 'points_num.number' => '积分值必须为数字',
  30. 'points_num.min' => '积分值必须大于0',
  31. 'goodsname.require' => '请添加礼品名称',
  32. 'goodsprice.require' => '礼品原价必须为数字且大于等于0',
  33. 'goodspoints.require' => '兑换积分为整数且大于等于0',
  34. 'goodspoints.number' => '兑换积分为整数且大于等于0',
  35. 'goodsserial.require' => '请添加礼品编号',
  36. 'goodsstorage.require' => '礼品库存必须为整数且大于等于0',
  37. 'goodsstorage.number' => '礼品库存必须为整数且大于等于0',
  38. 'sort.require' => '礼品排序为整数且大于等于0',
  39. 'sort.number' => '礼品排序为整数且大于等于0',
  40. 'limitnum.checkPointLimitnum' => '礼品排序为整数且大于等于0',
  41. 'starttime.checkPointStartTime' => '请添加开始时间',
  42. 'endtime.checkPointEndTime' => '请添加结束时间',
  43. 'shippingcode.require' => '请添加物流单号'
  44. ];
  45. protected $scene = [
  46. 'pointslog' => ['member_name', 'points_num'],
  47. 'prod_add' => ['goodsname', 'goodsprice', 'goodspoints', 'goodsserial', 'goodsstorage', 'sort', 'limitnum', 'starttime', 'endtime'],
  48. 'prod_edit' => ['goodsname', 'goodsprice', 'goodspoints', 'goodsserial', 'goodsstorage', 'sort', 'limitnum', 'starttime', 'endtime'],
  49. 'order_ship' => ['shippingcode'],
  50. ];
  51. protected function checkPointLimitnum($value)
  52. {
  53. if (input('post.sort') == 1 && !is_numeric($value)) {
  54. return '礼品排序为整数且大于等于0';
  55. }
  56. return true;
  57. }
  58. protected function checkPointStartTime($value)
  59. {
  60. if (input('post.islimittime')) {
  61. if (empty($value)) {
  62. return '请添加开始时间';
  63. }
  64. }
  65. return true;
  66. }
  67. protected function checkPointEndTime($value)
  68. {
  69. if (input('post.islimittime')) {
  70. if (empty($value)) {
  71. return '请添加结束时间';
  72. }
  73. }
  74. return true;
  75. }
  76. }