CouponRulesValidate.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\adminapi\validate\coupon;
  15. use app\common\validate\BaseValidate;
  16. /**
  17. * CouponRules验证器
  18. * Class CouponRulesValidate
  19. * @package app\adminapi\validate\coupon
  20. */
  21. class CouponRulesValidate extends BaseValidate
  22. {
  23. /**
  24. * 设置校验规则
  25. * @var string[]
  26. */
  27. protected $rule = [
  28. 'id' => 'require',
  29. 'amount_require' => 'require',
  30. 'event_name' => 'require',
  31. 'expire_time' => 'require',
  32. 'goods_category_ids' => 'require',
  33. 'mold_type' => 'require|checkMoldType',
  34. 'voucher_count' => 'require',
  35. ];
  36. /**
  37. * 参数描述
  38. * @var string[]
  39. */
  40. protected $field = [
  41. 'id' => 'id',
  42. 'amount_require' => '满减金额',
  43. 'event_name' => '优惠卷名称',
  44. 'expire_time' => '到期时间',
  45. 'mold_type' => '折扣方式',
  46. 'voucher_count' => '优惠卷数量',
  47. 'goods_category_ids' => '服务类目不能为空',
  48. ];
  49. public function checkMoldType($moldType, $rule, $data)
  50. {
  51. if ($moldType == 1) {
  52. if (!isset($data['discount_ratio']) || empty($data['discount_ratio'])) {
  53. return '请输入折扣';
  54. }
  55. if($data['discount_ratio'] <0 || $data['discount_ratio'] > 10){
  56. return '折扣在0~10之间';
  57. }
  58. } else if($moldType ==2){
  59. if(!isset($data['amount']) || empty($data['amount'])){
  60. return '请输入折扣金额';
  61. }
  62. }
  63. return true;
  64. }
  65. /**
  66. * @notes 添加场景
  67. * @return CouponRulesValidate
  68. * @author likeadmin
  69. * @date 2024/07/18 10:11
  70. */
  71. public function sceneAdd()
  72. {
  73. return $this->only(['amount_require','event_name','expire_time','mold_type','voucher_count']);
  74. }
  75. /**
  76. * @notes 编辑场景
  77. * @return CouponRulesValidate
  78. * @author likeadmin
  79. * @date 2024/07/18 10:11
  80. */
  81. public function sceneEdit()
  82. {
  83. return $this->only(['id','amount_require','event_name','expire_time','mold_type','voucher_count']);
  84. }
  85. /**
  86. * @notes 删除场景
  87. * @return CouponRulesValidate
  88. * @author likeadmin
  89. * @date 2024/07/18 10:11
  90. */
  91. public function sceneDelete()
  92. {
  93. return $this->only(['id']);
  94. }
  95. /**
  96. * @notes 详情场景
  97. * @return CouponRulesValidate
  98. * @author likeadmin
  99. * @date 2024/07/18 10:11
  100. */
  101. public function sceneDetail()
  102. {
  103. return $this->only(['id']);
  104. }
  105. }