| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- <?php
- namespace App\Http\Validator;
- class MemberValidator extends BaseValidator
- {
- // 当前模型所有验证规则
- public static $rules = [
- 'id' => 'required',
- 'username' => 'required|username|min:2|max:20',
- 'new_username' => 'required|username|min:2|max:20',
- 'password' => 'required|min:6|max:30',
- 'code' => 'required',
- 'api_key' => 'required',
- 'mobile'=> 'required|mobile',
- 'email'=> 'required|email',
- 'idcard'=> 'required|idcard',
- 'realname'=> 'required|realname|max:20',
- 'idcard_front_img'=> 'required|max:200',
- 'idcard_back_img'=> 'required|max:200',
- 'idcard_hand_img'=> 'required|max:200',
- ];
- // 当前模型所有错误提示信息
- public static $msgs = [
- 'required' => ':attribute不能为空',
- 'string' => ':attribute必须是字符串',
- 'min' => ':attribute长度不能小于:min位',
- 'max' => ':attribute长度不能大于:max位',
- 'exists' => ':attribute不存在',
- 'rule' => ':attribute格式不正确',
- 'mobile' => ':attribute格式不正确',
- 'email' => ':attribute格式不正确',
- 'username' => ':attribute格式不正确',
- 'realname' => ':attribute格式不正确',
- 'idcard' => ':attribute格式不正确',
- 'password' => ':attribute格式不正确',
- ];
- // 当前模型所有验证字段
- public static $fields = [
- 'id' => 'ID',
- 'password' => '登录密码',
- 'username' => '账号',
- 'new_username' => '新账号',
- 'code' => '验证码',
- 'mobile' => '手机号码',
- 'email' => '邮箱',
- 'realname' => '姓名',
- 'idcard' => '身份证号码',
- 'idcard_front_img' => '身份证正面',
- 'idcard_back_img' => '身份证反面',
- 'idcard_hand_img' => '身份证手持',
- 'api_key' => '接口密钥参数',
- ];
- // 当前模型所有验证场景
- public static $scenes = [
- 'info'=> ['id'],
- 'register'=> ['username','password','code'],
- 'modify'=> ['username','new_username','password','code'],
- 'password'=> ['username','password','code'],
- 'tradePassword'=> ['username','trade_password','code'],
- 'auth'=> ['realname','idcard','idcard_front_img','idcard_back_img'],
- 'login'=> ['username','password'],
- 'apiLogin'=> ['username','password','api_key'],
- 'apiRegister'=> ['username','password','api_key'],
- 'forget'=> ['username','code'],
- 'save'=> ['username','realname','gender'],
- 'mobile'=> ['mobile'],
- 'email'=> ['email'],
- ];
- /**
- * 验证
- * @param $request
- * @param string $scene
- * @return int|mixed
- */
- public static function check($request, $scene=''){
- $validator = new BaseValidator(self::$rules, self::$msgs, self::$fields, self::$scenes);
- return $validator->checkParams($request, $scene);
- }
- }
|