WithdrawValidator.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace App\Http\Validator;
  3. class WithdrawValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'money' => 'required|min:0|max:1000000',
  9. 'realname' => 'required|string|min:2|max:20',
  10. 'account' => 'nullable|string|min:2|max:50',
  11. 'pay_type' => 'required|min:1|max:10',
  12. 'qrcode' => 'nullable|string|min:2|max:250',
  13. ];
  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. ];
  23. // 当前模型所有验证字段
  24. public static $fields = [
  25. 'id' => 'ID',
  26. 'realname' => '收款姓名',
  27. 'account' => '收款账号',
  28. 'pay_type' => '支付方式',
  29. 'qrcode' => '收款码',
  30. 'money' => '金额',
  31. ];
  32. // 当前模型所有验证场景
  33. public static $scenes = [
  34. 'info'=> ['id'],
  35. 'pay'=> ['realname','account','pay_type','money','qrcode'],
  36. ];
  37. /**
  38. * 验证
  39. * @param $request
  40. * @param string $scene
  41. * @return int|mixed
  42. */
  43. public static function check($request, $scene=''){
  44. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  45. return $validator->checkParams($request, $scene);
  46. }
  47. }