OrderValidator.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Http\Validator;
  3. class OrderValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. // 当前模型所有错误提示信息
  7. public static $rules = [
  8. 'id' => 'required',
  9. 'goods' => 'required',
  10. 'num' => 'required|max:10',
  11. 'order_type' => 'required',
  12. 'pre_pay_remark' => 'string|max:200',
  13. 'after_remark' => 'string|max:200',
  14. ];
  15. public static $msgs = [
  16. 'required' => ':attribute不能为空',
  17. 'string' => ':attribute必须是字符串',
  18. 'min' => ':attribute长度不能小于:min位',
  19. 'max' => ':attribute长度不能大于:max位',
  20. 'exists' => ':attribute不存在',
  21. 'rule' => ':attribute格式不正确',
  22. 'mobile' => ':attribute格式不正确',
  23. ];
  24. // 当前模型所有验证字段
  25. public static $fields = [
  26. 'id' => 'ID',
  27. 'buy_user_id' => '下单客户',
  28. 'goods' => '下单商品',
  29. 'order_type' => '下单类型',
  30. 'num' => '数量',
  31. 'pre_pay_remark' => '预付备注',
  32. 'after_remark' => '售后备注',
  33. ];
  34. // 当前模型所有验证场景
  35. public static $scenes = [
  36. 'info'=> ['id'],
  37. 'pay'=> ['id','pay_type'],
  38. 'cancel'=> ['id','cancel_type'],
  39. 'receive'=> ['id'],
  40. 'submit'=> ['goods','order_type','num'],
  41. ];
  42. /**
  43. * 验证
  44. * @param $request
  45. * @param string $scene
  46. * @return int|mixed
  47. */
  48. public static function check($request, $scene=''){
  49. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  50. return $validator->checkParams($request, $scene);
  51. }
  52. }