截流自动化的商城平台
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

IntegralGoodsValidate.php 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace app\admin\validate\integral;
  3. use app\common\basics\Validate;
  4. use app\common\enum\IntegralGoodsEnum;
  5. use app\common\model\integral\IntegralGoods;
  6. /**
  7. * 积分商品验证
  8. * Class IntegralGoodsValidate
  9. * @package app\admin\validate\kefu
  10. */
  11. class IntegralGoodsValidate extends Validate
  12. {
  13. protected $rule = [
  14. 'id'=>'require|checkGoods',
  15. 'type' => 'require|in:1,2',
  16. 'name' => 'require',
  17. 'image' => 'require',
  18. 'market_price' => 'checkMarketPrice',
  19. 'stock' => 'require|integer',
  20. 'exchange_way' => 'requireIf:type,1',
  21. 'need_integral' => 'require|integer|checkNeedIntegral',
  22. 'need_money' => 'requireIf:exchange_way,2|checkNeedMoney',
  23. 'delivery_way' => 'requireIf:type,1',
  24. 'express_type' => 'requireIf:delivery_way,1',
  25. 'express_money' => 'requireIf:express_type,2|checkExpressMoney',
  26. 'balance' => 'requireIf:type,2|checkBalance',
  27. 'status' => 'require|in:0,1',
  28. ];
  29. protected $message = [
  30. 'id.require' => '参数缺失',
  31. 'type.require' => '请选择兑换类型',
  32. 'type.in' => '兑换类型错误',
  33. 'name.require' => '请填写商品名称',
  34. 'image.require' => '请上传商品封面',
  35. 'stock.require' => '请填写发放库存',
  36. 'stock.integer' => '请填写整数发放库存',
  37. 'exchange_way.requireIf' => '请选择兑换方式',
  38. 'need_integral.require' => '请填写兑换积分',
  39. 'need_integral.integer' => '请填写整数兑换积分',
  40. 'need_money.requireIf' => '请填写兑换金额',
  41. 'delivery_way.requireIf' => '请选择物流配送方式',
  42. 'express_type.requireIf' => '请选择物流方式',
  43. 'express_money.requireIf' => '请填写运费',
  44. 'balance.requireIf' => '请填写红包面值',
  45. 'status.require' => '请选择商品状态',
  46. 'status.in' => '商品状态参数错误',
  47. ];
  48. public function sceneAdd()
  49. {
  50. $this->remove('id', true);
  51. }
  52. public function sceneEdit()
  53. {
  54. }
  55. public function sceneDel()
  56. {
  57. $this->only(['id']);
  58. }
  59. public function sceneDetail()
  60. {
  61. $this->only(['id']);
  62. }
  63. protected function checkGoods($value, $rule, $data)
  64. {
  65. $goods = IntegralGoods::where(['id' => $value])->findOrEmpty();
  66. if ($goods->isEmpty()) {
  67. return '积分商品不存在';
  68. }
  69. if ($goods['del'] == 1) {
  70. return '积分商品已被删除';
  71. }
  72. return true;
  73. }
  74. // 验证统一运费时,运费不小于0
  75. protected function checkExpressMoney($value, $rule, $data)
  76. {
  77. // 快递配送 统一运费 运费须大于0
  78. if ($data['delivery_way'] == IntegralGoodsEnum::DELIVERY_EXPRESS
  79. && $data['express_type'] == IntegralGoodsEnum::EXPRESS_TYPE_UNIFIED
  80. && $value <= 0
  81. ) {
  82. return '请输入大于0的运费';
  83. }
  84. return true;
  85. }
  86. // 验证兑换积分需大于0
  87. protected function checkNeedIntegral($value, $rule, $data)
  88. {
  89. if ($value <= 0) {
  90. return '请输入大于0的兑换积分';
  91. }
  92. return true;
  93. }
  94. // 验证兑换方式为 积分+金额 时,金额不小于0
  95. protected function checkNeedMoney($value, $rule, $data)
  96. {
  97. if ($data['exchange_way'] == IntegralGoodsEnum::EXCHANGE_WAY_HYBRID && $value <= 0) {
  98. return '请输入大于0的兑换金额';
  99. }
  100. return true;
  101. }
  102. // 验证兑换类型为 红包时,红包面额不小于0
  103. protected function checkBalance($value, $rule, $data)
  104. {
  105. if ($data['type'] == IntegralGoodsEnum::TYPE_BALANCE && $value <= 0) {
  106. return '请输入大于0的红包面值';
  107. }
  108. return true;
  109. }
  110. protected function checkMarketPrice($value)
  111. {
  112. if (!empty($value) && $value < 0) {
  113. return '请输入正确市场价';
  114. }
  115. return true;
  116. }
  117. }