244 lines
6.4 KiB
PHP
Executable File
244 lines
6.4 KiB
PHP
Executable File
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
namespace app\adminapi\validate\auth;
|
||
|
||
use app\common\model\auth\Admin;
|
||
use app\common\model\dept\Dept;
|
||
use app\common\model\dept\Jobs;
|
||
use app\common\model\dept\Orgs;
|
||
use app\common\validate\BaseValidate;
|
||
|
||
/**
|
||
* 管理员验证
|
||
* Class AdminValidate
|
||
* @package app\adminapi\validate\auth
|
||
*/
|
||
class AdminValidate extends BaseValidate
|
||
{
|
||
protected $rule = [
|
||
'id' => 'require|checkAdmin',
|
||
'account' => 'require|length:1,32|unique:' . Admin::class,
|
||
'name' => 'require|length:1,16|unique:' . Admin::class,
|
||
'password' => 'require|length:6,32',
|
||
'password_confirm' => 'require|confirm:password',
|
||
'role_id' => 'require',
|
||
'disable' => 'require|in:0,1|checkAbleDisable',
|
||
'multipoint_login' => 'require|in:0,1',
|
||
'org_id' => 'checkOrg',
|
||
'dept_id' => 'checkDept',
|
||
'job_id' => 'checkJob',
|
||
'email' => 'email',
|
||
'mobile' => 'mobile|unique:oa_admin',
|
||
'sex' => 'integer|in:0,1,2',
|
||
'age' => 'integer|gt:0',
|
||
'idcard' => 'idCard',
|
||
'entry_time' => 'dateFormat:Y-m-d',
|
||
'type' => 'integer|in:0,1,2',
|
||
'status' => 'integer|in:0,1,2',
|
||
];
|
||
|
||
protected $message = [
|
||
'id.require' => '管理员id不能为空',
|
||
'account.require' => '账号不能为空',
|
||
'account.length' => '账号长度须在1-32位字符',
|
||
'account.unique' => '账号已存在',
|
||
'password.require' => '密码不能为空',
|
||
'password.length' => '密码长度须在6-32位字符',
|
||
'password_confirm.requireWith' => '确认密码不能为空',
|
||
'password_confirm.confirm' => '两次输入的密码不一致',
|
||
'name.require' => '名称不能为空',
|
||
'name.length' => '名称须在1-16位字符',
|
||
'name.unique' => '名称已存在',
|
||
'role_id.require' => '请选择角色',
|
||
'disable.require' => '请选择状态',
|
||
'disable.in' => '状态值错误',
|
||
'multipoint_login.require' => '请选择是否支持多处登录',
|
||
'multipoint_login.in' => '多处登录状态值为误',
|
||
'org_id.require' => '请选择组织',
|
||
'dept_id.requireWith' => '请选择部门',
|
||
'job_id.requireWith' => '请选择岗位',
|
||
];
|
||
|
||
protected $field = [
|
||
'id' => 'id',
|
||
'account' => '登陆账号',
|
||
'name' => '员工姓名',
|
||
'password' => '登录密码',
|
||
'password_confirm' => '确认密码',
|
||
'role_id' => '角色',
|
||
'disable' => '管理员状态',
|
||
'multipoint_login' => '多处登录',
|
||
'email' => '电子邮箱',
|
||
'mobile' => '手机号码',
|
||
'sex' => '性别',
|
||
'org_id' => '组织',
|
||
'dept_id' => '部门',
|
||
'job_id' => '职位',
|
||
'type' => '员工类型',
|
||
'age' => '年龄',
|
||
'idcard' => '身份证',
|
||
'entry_time' => '员工入职日期',
|
||
'status' => '状态',
|
||
];
|
||
|
||
/**
|
||
* @notes 添加场景
|
||
* @return AdminValidate
|
||
* @author 段誉
|
||
* @date 2021/12/29 15:46
|
||
*/
|
||
public function sceneAdd()
|
||
{
|
||
return $this->remove('id', 'require|checkAdmin')
|
||
->remove('disable', 'checkAbleDisable');
|
||
}
|
||
|
||
/**
|
||
* @notes 详情场景
|
||
* @return AdminValidate
|
||
* @author 段誉
|
||
* @date 2021/12/29 15:46
|
||
*/
|
||
public function sceneDetail()
|
||
{
|
||
return $this->only(['id']);
|
||
}
|
||
|
||
/**
|
||
* @notes 编辑场景
|
||
* @return AdminValidate
|
||
* @author 段誉
|
||
* @date 2021/12/29 15:47
|
||
*/
|
||
public function sceneEdit()
|
||
{
|
||
return $this->remove('password', true)->remove('password_confirm',true)
|
||
->append('id', 'require|checkAdmin');
|
||
}
|
||
|
||
public function scenePwd()
|
||
{
|
||
return $this->only(['id', 'password', 'password_confirm']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除场景
|
||
* @return AdminValidate
|
||
* @author 段誉
|
||
* @date 2021/12/29 15:47
|
||
*/
|
||
public function sceneDelete()
|
||
{
|
||
return $this->only(['id'])->remove('id', 'checkAdmin');
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑情况下,检查是否填密码
|
||
* @param $value
|
||
* @param $rule
|
||
* @param $data
|
||
* @return bool|string
|
||
* @author 段誉
|
||
* @date 2021/12/29 10:19
|
||
*/
|
||
public function edit($value, $rule, $data)
|
||
{
|
||
if (empty($data['password']) && empty($data['password_confirm'])) {
|
||
return true;
|
||
}
|
||
$len = strlen($value);
|
||
if ($len < 6 || $len > 32) {
|
||
return '密码长度须在6-32位字符';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 检查指定管理员是否存在
|
||
* @param $value
|
||
* @return bool|string
|
||
* @author 段誉
|
||
* @date 2021/12/29 10:19
|
||
*/
|
||
public function checkAdmin($value)
|
||
{
|
||
$admin = Admin::findOrEmpty($value);
|
||
if ($admin->isEmpty()) {
|
||
return '管理员不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 禁用校验
|
||
* @param $value
|
||
* @param $rule
|
||
* @param $data
|
||
* @return bool|string
|
||
* @author 段誉
|
||
* @date 2022/8/11 9:59
|
||
*/
|
||
public function checkAbleDisable($value, $rule, $data)
|
||
{
|
||
$admin = Admin::findOrEmpty($data['id']);
|
||
if ($admin->isEmpty()) {
|
||
return '管理员不存在';
|
||
}
|
||
|
||
if ($value && $admin['root']) {
|
||
return '超级管理员不允许被禁用';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
//验证组织
|
||
public function checkOrg($value): bool|string
|
||
{
|
||
$org = Orgs::where('id', $value)->findOrEmpty();
|
||
if ($org->isEmpty()) {
|
||
return '组织不存在';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkDept($value, $rule, $data): bool|string
|
||
{
|
||
$dept = Dept::where('id', $value)->findOrEmpty();
|
||
if ($dept->isEmpty()) {
|
||
return '部门不存在';
|
||
}
|
||
if ($dept['org_id'] != $data['org_id']) {
|
||
return '该部门不属于当前选择的组织';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
public function checkJob($value, $rule, $data): bool|string
|
||
{
|
||
$job = Jobs::where('id', $value)->findOrEmpty();
|
||
if ($job->isEmpty()) {
|
||
return '岗位不存在';
|
||
}
|
||
if ($job['dept_id'] != $data['dept_id']) {
|
||
return '该岗位不属于当前选择的部门';
|
||
}
|
||
return true;
|
||
}
|
||
|
||
} |