更新
This commit is contained in:
@@ -27,47 +27,20 @@ use app\common\validate\BaseValidate;
|
||||
class SetUserInfoValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'field' => 'require|checkField',
|
||||
'value' => 'require',
|
||||
'avatar' => 'string',
|
||||
'phone' => 'regex:/^1[3-9]\d{9}$/|',
|
||||
'nickname' => 'string|max:50',
|
||||
'gender' => 'in:0,1',
|
||||
'age' => 'integer|between:0,150',
|
||||
'patient_name' => 'string|max:50'
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'field.require' => '参数缺失',
|
||||
'value.require' => '值不存在',
|
||||
'phone.regex' => '手机号格式不正确',
|
||||
'nickname.max' => '昵称不能超过50个字符',
|
||||
'gender.in' => '性别参数错误',
|
||||
'age.between' => '年龄必须在0-150之间',
|
||||
'patient_name.max' => '姓名不能超过50个字符'
|
||||
];
|
||||
|
||||
|
||||
/**
|
||||
* @notes 校验字段内容
|
||||
* @param $value
|
||||
* @param $rule
|
||||
* @param $data
|
||||
* @return bool|string
|
||||
* @author 段誉
|
||||
* @date 2022/9/21 17:01
|
||||
*/
|
||||
protected function checkField($value, $rule, $data)
|
||||
{
|
||||
$allowField = [
|
||||
'nickname', 'account', 'sex', 'avatar', 'real_name',
|
||||
];
|
||||
|
||||
if (!in_array($value, $allowField)) {
|
||||
return '参数错误';
|
||||
}
|
||||
|
||||
if ($value == 'account') {
|
||||
$user = User::where([
|
||||
['account', '=', $data['value']],
|
||||
['id', '<>', $data['id']]
|
||||
])->findOrEmpty();
|
||||
if (!$user->isEmpty()) {
|
||||
return '账号已被使用!';
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user