ShippingTemplateValidate.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * @package merchant
  4. *
  5. * @author xaboy
  6. * @day 2020-03-26
  7. *
  8. *
  9. */
  10. namespace app\validate\merchant;
  11. use think\Validate;
  12. class ShippingTemplateValidate extends Validate
  13. {
  14. protected $failException = true;
  15. protected $rule = [
  16. 'name|名称' => 'require|max:32',
  17. 'type|计费方式' => 'require|in:0,1,2',
  18. 'appoint|指定包邮状态' => 'require|in:0,1',
  19. 'region|配送区域信息' => 'Array|require|min:1|region',
  20. 'undelivery|区域不配送状态' => 'require|in:0,1',
  21. 'free|包邮信息' => 'requireIf:appoint,1|Array|free',
  22. 'undelives|不配送区域信息'=>'requireIf:undelivery,1|Array|undelive',
  23. ];
  24. protected function region($value,$rule,$data)
  25. {
  26. foreach ($value as $k => $v){
  27. if ($k != 0 && empty($v['city_id']))
  28. return '配送城市信息不能为空';
  29. if (!is_int($v['first']) || empty($v['first']) || $v['first'] < 0)
  30. return '首件条件大于零的数字';
  31. if (!is_numeric($v['first_price']) || empty($v['first_price']) || $v['first_price'] < 0)
  32. return '首件金额必须为大于零的数字';
  33. if (!is_int($v['continue']) || ($v['continue'] < 0))
  34. return '续件必须为不小于零的整数';
  35. if (!is_numeric($v['continue_price']) || $v['continue_price'] < 0 )
  36. return '追加金额为不小于零的数';
  37. }
  38. return true;
  39. }
  40. protected function free($value,$rule,$data)
  41. {
  42. if(!$data['appoint']) return true;
  43. foreach ($value as $v){
  44. if (empty($v['city_id']))
  45. return '包邮城市信息不能为空';
  46. if (!is_int($v['number']) || empty($v['number']) || $v['number'] < 0)
  47. return '包邮条件为大于零的数字';
  48. if (!is_numeric($v['price']) || empty($v['price']) || $v['price'] < 0)
  49. return '包邮金额必须为大于零的数字';
  50. }
  51. return true;
  52. }
  53. protected function undelive($value,$rule,$data)
  54. {
  55. if($data['undelivery']){
  56. if (empty($value['city_id']))
  57. return '不配送城市信息不能为空';
  58. }
  59. return true;
  60. }
  61. }