ShippingTemplateValidate.php 2.1 KB

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