MemberValidator.php 2.9 KB

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