| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Http\Validator;
- class AgentValidator extends BaseValidator
- {
- // 当前模型所有验证规则
- public static $rules = [
- 'id' => 'required',
- 'mobile' => 'required|mobile',
- 'realname' => 'required|max:30',
- 'sms_code' => 'required|min:4|max:6',
- 'sms_type' => 'required',
- 'province' => 'required',
- 'area' => 'required',
- ];
- // 当前模型所有错误提示信息
- public static $msgs = [
- 'required' => ':attribute不能为空',
- 'string' => ':attribute必须是字符串',
- 'min' => ':attribute长度不能小于:min位',
- 'max' => ':attribute长度不能大于:max位',
- 'exists' => ':attribute不存在',
- 'rule' => ':attribute格式不正确',
- 'mobile' => ':attribute格式不正确',
- ];
- // 当前模型所有验证字段
- public static $fields = [
- 'id' => 'ID',
- 'code' => '微信授权码',
- 'openid' => '微信ID',
- 'access_token' => 'access_token',
- 'avatar' => '头像',
- 'gender' => '性别',
- 'nickname' => '昵称',
- 'realname' => '姓名',
- 'mobile' => '手机号',
- 'sms_code' => '手机验证码',
- 'sms_type' => '验证码类型',
- 'scene' => '修改类型',
- 'province' => '代理所属省份',
- 'area' => '代理城市',
- ];
- // 当前模型所有验证场景
- public static $scenes = [
- 'info'=> ['id'],
- 'mobile'=> ['mobile','code','scene'],
- 'modify'=> ['id'],
- 'reg'=> ['mobile','sms_code','nickname'],
- 'apply'=> ['mobile','realname','province','area'],
- 'sms'=> ['mobile','sms_type'],
- 'collect'=> ['id','status'],
- ];
- /**
- * 验证
- * @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);
- }
- }
|