ShippingTemplateValidate.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\validate\merchant;
  12. use think\Validate;
  13. class ShippingTemplateValidate extends Validate
  14. {
  15. protected $failException = true;
  16. protected $rule = [
  17. 'name|名称' => 'require|max:32',
  18. 'type|计费方式' => 'require|in:0,1,2',
  19. 'appoint|指定包邮状态' => 'require|in:0,1',
  20. 'region|配送区域信息' => 'Array|require|min:1|region',
  21. 'undelivery|区域不配送状态' => 'require|in:0,1',
  22. 'free|包邮信息' => 'requireIf:appoint,1|Array|free',
  23. 'undelives|不配送区域信息'=>'requireIf:undelivery,1|Array|undelive',
  24. ];
  25. protected function region($value,$rule,$data)
  26. {
  27. foreach ($value as $k => $v){
  28. if ($k != 0 && empty($v['city_id']))
  29. return '配送城市信息不能为空';
  30. if (!is_numeric($v['first']) || $v['first'] < 0)
  31. return '首件条件不能小0';
  32. if (!is_numeric($v['first_price']) || $v['first_price'] < 0)
  33. return '首件金额不能小于0';
  34. if (!is_numeric($v['continue']) || ($v['continue'] < 0))
  35. return '续件必须为不小于零的整数';
  36. if (!is_numeric($v['continue_price']) || $v['continue_price'] < 0 )
  37. return '追加金额为不小于零的数';
  38. }
  39. return true;
  40. }
  41. protected function free($value,$rule,$data)
  42. {
  43. if(!$data['appoint']) return true;
  44. foreach ($value as $v){
  45. if (empty($v['city_id']))
  46. return '包邮城市信息不能为空';
  47. if (!is_int($v['number']) || $v['number'] < 0)
  48. return '包邮条件为不小于零的整数';
  49. if (!is_numeric($v['price']) ||$v['price'] < 0)
  50. return '包邮金额必须为不小于零的数字';
  51. }
  52. return true;
  53. }
  54. protected function undelive($value,$rule,$data)
  55. {
  56. if($data['undelivery']){
  57. if (empty($value['city_id']))
  58. return '不配送城市信息不能为空';
  59. }
  60. return true;
  61. }
  62. }