update
This commit is contained in:
parent
21510302a8
commit
fd5146f70f
@ -11,141 +11,143 @@
|
|||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
// | author: likeadminTeam
|
// | author: likeadminTeam
|
||||||
// +----------------------------------------------------------------------
|
// +----------------------------------------------------------------------
|
||||||
|
|
||||||
namespace app\adminapi\validate\dept;
|
|
||||||
|
|
||||||
use app\common\model\auth\Admin;
|
|
||||||
use app\common\model\auth\AdminDept;
|
|
||||||
use app\common\model\dept\Dept;
|
|
||||||
use app\common\model\dept\Orgs;
|
|
||||||
use app\common\validate\BaseValidate;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 部门验证器
|
|
||||||
* Class DeptValidate
|
|
||||||
* @package app\adminapi\validate\dept
|
|
||||||
*/
|
|
||||||
class DeptValidate extends BaseValidate
|
|
||||||
{
|
|
||||||
|
|
||||||
protected $rule = [
|
|
||||||
'id' => 'require|checkDept',
|
|
||||||
'org_id' => 'require|checkOrg',
|
|
||||||
'name' => 'require|length:1,30',
|
|
||||||
'leader' => 'checkLeader',
|
|
||||||
'mobile' => 'mobile',
|
|
||||||
'status' => 'require|in:0,1',
|
|
||||||
'sort' => 'egt:0',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
protected $message = [
|
|
||||||
'id.require' => '参数缺失',
|
|
||||||
'org_id.require' => '请选择所属组织',
|
|
||||||
'name.require' => '请填写部门名称',
|
|
||||||
'name.length' => '部门名称长度须在1-30位字符',
|
|
||||||
'name.unique' => '部门名称已存在',
|
|
||||||
'leader.require' => '请选择部门负责人',
|
|
||||||
'mobile.require' => '请填写部门负责人联系电话',
|
|
||||||
'mobile.mobile' => '部门负责人联系电话格式错误',
|
|
||||||
'status.require' => '请选择部门状态',
|
|
||||||
'sort.egt' => '排序值不正确',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 添加场景
|
|
||||||
* @return DeptValidate
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/5/25 18:16
|
|
||||||
*/
|
|
||||||
public function sceneAdd()
|
|
||||||
{
|
|
||||||
return $this->remove('id', true)->append('name','checkUniqueByAdd');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 详情场景
|
|
||||||
* @return DeptValidate
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/5/25 18:16
|
|
||||||
*/
|
|
||||||
public function sceneDetail()
|
|
||||||
{
|
|
||||||
return $this->only(['id']);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 编辑场景
|
|
||||||
* @return DeptValidate
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/5/26 18:42
|
|
||||||
*/
|
|
||||||
public function sceneEdit()
|
|
||||||
{
|
|
||||||
return $this->only(['id','org_id','name','leader','mobile','status'])->append('name','checkUniqueByEdit');;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @notes 删除场景
|
|
||||||
* @return DeptValidate
|
|
||||||
* @author 段誉
|
|
||||||
* @date 2022/5/25 18:16
|
|
||||||
*/
|
|
||||||
public function sceneDelete()
|
|
||||||
{
|
|
||||||
return $this->only(['id'])->append('id','checkDept');
|
|
||||||
}
|
|
||||||
|
|
||||||
//验证唯一
|
namespace app\adminapi\validate\dept;
|
||||||
public function checkUniqueByAdd($value,$rule,$data): bool|string
|
|
||||||
|
use app\common\model\auth\Admin;
|
||||||
|
use app\common\model\auth\AdminDept;
|
||||||
|
use app\common\model\dept\Dept;
|
||||||
|
use app\common\model\dept\Orgs;
|
||||||
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 部门验证器
|
||||||
|
* Class DeptValidate
|
||||||
|
* @package app\adminapi\validate\dept
|
||||||
|
*/
|
||||||
|
class DeptValidate extends BaseValidate
|
||||||
{
|
{
|
||||||
$dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->findOrEmpty();
|
|
||||||
if(!$dep->isEmpty()){
|
protected $rule = [
|
||||||
return '部门已存在';
|
'id' => 'require|checkDept',
|
||||||
|
'org_id' => 'require|checkOrg',
|
||||||
|
'name' => 'require|length:1,30',
|
||||||
|
'leader' => 'checkLeader',
|
||||||
|
'mobile' => 'mobile',
|
||||||
|
'status' => 'require|in:0,1',
|
||||||
|
'sort' => 'egt:0',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
protected $message = [
|
||||||
|
'id.require' => '参数缺失',
|
||||||
|
'org_id.require' => '请选择所属组织',
|
||||||
|
'name.require' => '请填写部门名称',
|
||||||
|
'name.length' => '部门名称长度须在1-30位字符',
|
||||||
|
'name.unique' => '部门名称已存在',
|
||||||
|
'leader.require' => '请选择部门负责人',
|
||||||
|
'mobile.require' => '请填写部门负责人联系电话',
|
||||||
|
'mobile.mobile' => '部门负责人联系电话格式错误',
|
||||||
|
'status.require' => '请选择部门状态',
|
||||||
|
'sort.egt' => '排序值不正确',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @notes 添加场景
|
||||||
|
* @return DeptValidate
|
||||||
|
* @author 段誉
|
||||||
|
* @date 2022/5/25 18:16
|
||||||
|
*/
|
||||||
|
public function sceneAdd()
|
||||||
|
{
|
||||||
|
return $this->remove('id', true)->append('name', 'checkUniqueByAdd');
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
/**
|
||||||
public function checkUniqueByEdit($value,$rule,$data): bool|string
|
* @notes 详情场景
|
||||||
{
|
* @return DeptValidate
|
||||||
$dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->where('id','<>',$data['id'])->findOrEmpty();
|
* @author 段誉
|
||||||
if(!$dep->isEmpty()){
|
* @date 2022/5/25 18:16
|
||||||
return '部门已存在';
|
*/
|
||||||
|
public function sceneDetail()
|
||||||
|
{
|
||||||
|
return $this->only(['id']);
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
/**
|
||||||
//校验组织
|
* @notes 编辑场景
|
||||||
public function checkOrg($value): bool|string
|
* @return DeptValidate
|
||||||
{
|
* @author 段誉
|
||||||
$org = Orgs::findOrEmpty($value);
|
* @date 2022/5/26 18:42
|
||||||
if ($org->isEmpty()) {
|
*/
|
||||||
return '组织不存在';
|
public function sceneEdit()
|
||||||
|
{
|
||||||
|
return $this->only(['id', 'org_id', 'name', 'leader', 'mobile', 'status'])->append('name', 'checkUniqueByEdit');;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
/**
|
||||||
//校验部门
|
* @notes 删除场景
|
||||||
public function checkDept($value): bool|string
|
* @return DeptValidate
|
||||||
{
|
* @author 段誉
|
||||||
$dept = Dept::findOrEmpty($value);
|
* @date 2022/5/25 18:16
|
||||||
if ($dept->isEmpty()) {
|
*/
|
||||||
return '部门不存在';
|
public function sceneDelete()
|
||||||
}
|
{
|
||||||
return true;
|
return $this->only(['id'])->append('id', 'checkDept');
|
||||||
}
|
|
||||||
|
|
||||||
public function checkLeader($value){
|
|
||||||
$data = Admin::where('id',$value)->findOrEmpty();
|
|
||||||
if($data->isEmpty()){
|
|
||||||
return '负责人信息不存在';
|
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
}
|
//验证唯一
|
||||||
|
public function checkUniqueByAdd($value, $rule, $data): bool|string
|
||||||
}
|
{
|
||||||
|
$dep = Dept::where('org_id', $data['org_id'])->where('name', $data['name'])->findOrEmpty();
|
||||||
|
if (!$dep->isEmpty()) {
|
||||||
|
return '部门已存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkUniqueByEdit($value, $rule, $data): bool|string
|
||||||
|
{
|
||||||
|
$dep = Dept::where('org_id', $data['org_id'])->where('name', $data['name'])->where('id', '<>', $data['id'])->findOrEmpty();
|
||||||
|
if (!$dep->isEmpty()) {
|
||||||
|
return '部门已存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//校验组织
|
||||||
|
public function checkOrg($value): bool|string
|
||||||
|
{
|
||||||
|
$org = Orgs::findOrEmpty($value);
|
||||||
|
if ($org->isEmpty()) {
|
||||||
|
return '组织不存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
//校验部门
|
||||||
|
public function checkDept($value): bool|string
|
||||||
|
{
|
||||||
|
$dept = Dept::findOrEmpty($value);
|
||||||
|
if ($dept->isEmpty()) {
|
||||||
|
return '部门不存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkLeader($value)
|
||||||
|
{
|
||||||
|
if (empty($value)) return true;
|
||||||
|
$data = Admin::where('id', $value)->findOrEmpty();
|
||||||
|
if ($data->isEmpty()) {
|
||||||
|
return '负责人信息不存在';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user