AgentValidator.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Validator;
  3. class AgentValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'mobile' => 'required|mobile',
  9. 'realname' => 'required|max:30',
  10. 'sms_code' => 'required|min:4|max:6',
  11. 'sms_type' => 'required',
  12. 'province' => 'required',
  13. 'area' => 'required',
  14. ];
  15. // 当前模型所有错误提示信息
  16. public static $msgs = [
  17. 'required' => ':attribute不能为空',
  18. 'string' => ':attribute必须是字符串',
  19. 'min' => ':attribute长度不能小于:min位',
  20. 'max' => ':attribute长度不能大于:max位',
  21. 'exists' => ':attribute不存在',
  22. 'rule' => ':attribute格式不正确',
  23. 'mobile' => ':attribute格式不正确',
  24. ];
  25. // 当前模型所有验证字段
  26. public static $fields = [
  27. 'id' => 'ID',
  28. 'code' => '微信授权码',
  29. 'openid' => '微信ID',
  30. 'access_token' => 'access_token',
  31. 'avatar' => '头像',
  32. 'gender' => '性别',
  33. 'nickname' => '昵称',
  34. 'realname' => '姓名',
  35. 'mobile' => '手机号',
  36. 'sms_code' => '手机验证码',
  37. 'sms_type' => '验证码类型',
  38. 'scene' => '修改类型',
  39. 'province' => '代理所属省份',
  40. 'area' => '代理城市',
  41. ];
  42. // 当前模型所有验证场景
  43. public static $scenes = [
  44. 'info'=> ['id'],
  45. 'mobile'=> ['mobile','code','scene'],
  46. 'modify'=> ['id'],
  47. 'reg'=> ['mobile','sms_code','nickname'],
  48. 'apply'=> ['mobile','realname','province','area'],
  49. 'sms'=> ['mobile','sms_type'],
  50. 'collect'=> ['id','status'],
  51. ];
  52. /**
  53. * 验证
  54. * @param $request
  55. * @param string $scene
  56. * @return int|mixed
  57. */
  58. public static function check($request, $scene=''){
  59. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  60. return $validator->checkParams($request, $scene);
  61. }
  62. }