CouponRulesValidate.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. 'coupon_type'=> 'require',
  30. 'amount_require' => 'require',
  31. 'event_name' => 'require',
  32. 'expire_time' => 'require',
  33. 'goods_category_ids' => 'require',
  34. 'mold_type' => 'require|checkMoldType',
  35. 'voucher_count' => 'require',
  36. ];
  37. /**
  38. * 参数描述
  39. * @var string[]
  40. */
  41. protected $field = [
  42. 'id' => 'id',
  43. 'amount_require' => '满减金额',
  44. 'coupon_type' => '优惠券类型',
  45. 'event_name' => '优惠卷名称',
  46. 'expire_time' => '到期时间',
  47. 'mold_type' => '折扣方式',
  48. 'voucher_count' => '优惠卷数量',
  49. 'goods_category_ids' => '服务类目不能为空',
  50. ];
  51. public function checkMoldType($moldType, $rule, $data)
  52. {
  53. if ($moldType == 1) {
  54. if (!isset($data['discount_ratio'])) {
  55. return '请输入折扣';
  56. }
  57. if($data['discount_ratio'] <0 || $data['discount_ratio'] > 1){
  58. return '折扣在0~1之间';
  59. }
  60. } else if($moldType ==2){
  61. if(!isset($data['amount']) || empty($data['amount'])){
  62. return '请输入折扣金额';
  63. }
  64. }
  65. return true;
  66. }
  67. /**
  68. * @notes 添加场景
  69. * @return CouponRulesValidate
  70. * @author likeadmin
  71. * @date 2024/07/18 10:11
  72. */
  73. public function sceneAdd()
  74. {
  75. return $this->only(['amount_require','event_name','expire_time','mold_type','voucher_count']);
  76. }
  77. /**
  78. * @notes 编辑场景
  79. * @return CouponRulesValidate
  80. * @author likeadmin
  81. * @date 2024/07/18 10:11
  82. */
  83. public function sceneEdit()
  84. {
  85. return $this->only(['id','amount_require','event_name','expire_time','mold_type','voucher_count']);
  86. }
  87. /**
  88. * @notes 删除场景
  89. * @return CouponRulesValidate
  90. * @author likeadmin
  91. * @date 2024/07/18 10:11
  92. */
  93. public function sceneDelete()
  94. {
  95. return $this->only(['id']);
  96. }
  97. /**
  98. * @notes 详情场景
  99. * @return CouponRulesValidate
  100. * @author likeadmin
  101. * @date 2024/07/18 10:11
  102. */
  103. public function sceneDetail()
  104. {
  105. return $this->only(['id']);
  106. }
  107. }