Point.php 3.2 KB

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