nk-lihaink-cn/app/admin/validate/AdminCheck.php
2021-07-26 17:41:59 +08:00

56 lines
1.7 KiB
PHP

<?php
/**
* @copyright Copyright (c) 2021 勾股工作室
* @license https://opensource.org/licenses/GPL-2.0
* @link https://www.gougucms.com
*/
namespace app\admin\validate;
use think\Validate;
class AdminCheck extends Validate
{
protected $rule = [
'username' => 'require|unique:admin',
'pwd' => 'require|confirm',
'mobile' => 'require',
'nickname' => 'require',
'group_id' => 'require',
'id' => 'require',
'status' => 'require|checkStatus:-1,1',
'old_pwd' => 'require|different:pwd',
];
protected $message = [
'username.require' => '登录账号不能为空',
'pwd.require' => '密码不能为空',
'pwd.confirm' => '两次密码不一致',
'username.unique' => '同样的登录账号已经存在!',
'mobile.require' => '手机不能为空',
'nickname.require' => '昵称不能为空',
'group_id.require' => '至少要选择一个用户角色',
'id.require' => '缺少更新条件',
'status.require' => '状态为必选',
'status.checkStatus' => '系统所有者不能被禁用!',
'old_pwd.require' => '请提供旧密码',
'old_pwd.different' => '新密码不能和旧密码一样',
];
protected $scene = [
'add' => ['phone', 'nickname', 'group_id', 'pwd', 'username', 'status'],
'edit' => ['phone', 'nickname', 'group_id', 'id', 'username.unique', 'status'],
'editPersonal' => ['phone', 'nickname'],
'editpwd' => ['old_pwd', 'pwd'],
];
// 自定义验证规则
protected function checkStatus($value, $rule, $data)
{
if ($value == -1 and $data['id'] == 1) {
return $rule == false;
}
return $rule == true;
}
}