MemberValidator.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Validator;
  3. class MemberValidator extends BaseValidator
  4. {
  5. // 当前模型所有验证规则
  6. public static $rules = [
  7. 'id' => 'required',
  8. 'username' => 'required|username|min:2|max:20',
  9. 'new_username' => 'required|username|min:2|max:20',
  10. 'password' => 'required|max:30',
  11. 'code' => 'required',
  12. 'mobile'=> 'required|mobile',
  13. 'email'=> 'required|email',
  14. 'idcard'=> 'required|idcard',
  15. 'realname'=> 'required|max:20',
  16. 'idcard_front_img'=> 'required|max:200',
  17. 'idcard_back_img'=> 'required|max:200',
  18. 'idcard_hand_img'=> 'required|max:200',
  19. ];
  20. // 当前模型所有错误提示信息
  21. public static $msgs = [
  22. 'required' => ':attribute不能为空',
  23. 'string' => ':attribute必须是字符串',
  24. 'min' => ':attribute长度不能小于:min位',
  25. 'max' => ':attribute长度不能大于:max位',
  26. 'exists' => ':attribute不存在',
  27. 'rule' => ':attribute格式不正确',
  28. 'mobile' => ':attribute格式不正确',
  29. 'email' => ':attribute格式不正确',
  30. 'username' => ':attribute格式不正确',
  31. 'idcard' => ':attribute格式不正确',
  32. ];
  33. // 当前模型所有验证字段
  34. public static $fields = [
  35. 'id' => 'ID',
  36. 'password' => '登录密码',
  37. 'username' => '账号',
  38. 'new_username' => '新账号',
  39. 'code' => '验证码',
  40. 'mobile' => '手机号码',
  41. 'email' => '邮箱',
  42. 'realname' => '姓名',
  43. 'idcard' => '身份证号码',
  44. 'idcard_front_img' => '身份证正面',
  45. 'idcard_back_img' => '身份证反面',
  46. 'idcard_hand_img' => '身份证手持',
  47. ];
  48. // 当前模型所有验证场景
  49. public static $scenes = [
  50. 'info'=> ['id'],
  51. 'register'=> ['username','password','code'],
  52. 'modify'=> ['username','new_username','password','code'],
  53. 'password'=> ['username','password','code'],
  54. 'tradePassword'=> ['username','trade_password','code'],
  55. 'auth'=> ['realname','idcard','idcard_front_img','idcard_back_img'],
  56. 'login'=> ['username','password'],
  57. 'forget'=> ['username','code'],
  58. 'save'=> ['username','realname','gender'],
  59. 'mobile'=> ['mobile'],
  60. 'email'=> ['email'],
  61. ];
  62. /**
  63. * 验证
  64. * @param $request
  65. * @param string $scene
  66. * @return int|mixed
  67. */
  68. public static function check($request, $scene=''){
  69. $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
  70. return $validator->checkParams($request, $scene);
  71. }
  72. }