This commit is contained in:
weiz 2024-04-10 15:53:41 +08:00
parent 21510302a8
commit fd5146f70f

View File

@ -12,22 +12,22 @@
// | author: likeadminTeam // | author: likeadminTeam
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\adminapi\validate\dept; namespace app\adminapi\validate\dept;
use app\common\model\auth\Admin; use app\common\model\auth\Admin;
use app\common\model\auth\AdminDept; use app\common\model\auth\AdminDept;
use app\common\model\dept\Dept; use app\common\model\dept\Dept;
use app\common\model\dept\Orgs; use app\common\model\dept\Orgs;
use app\common\validate\BaseValidate; use app\common\validate\BaseValidate;
/** /**
* 部门验证器 * 部门验证器
* Class DeptValidate * Class DeptValidate
* @package app\adminapi\validate\dept * @package app\adminapi\validate\dept
*/ */
class DeptValidate extends BaseValidate class DeptValidate extends BaseValidate
{ {
protected $rule = [ protected $rule = [
'id' => 'require|checkDept', 'id' => 'require|checkDept',
@ -62,7 +62,7 @@ class DeptValidate extends BaseValidate
*/ */
public function sceneAdd() public function sceneAdd()
{ {
return $this->remove('id', true)->append('name','checkUniqueByAdd'); return $this->remove('id', true)->append('name', 'checkUniqueByAdd');
} }
@ -86,7 +86,7 @@ class DeptValidate extends BaseValidate
*/ */
public function sceneEdit() public function sceneEdit()
{ {
return $this->only(['id','org_id','name','leader','mobile','status'])->append('name','checkUniqueByEdit');; return $this->only(['id', 'org_id', 'name', 'leader', 'mobile', 'status'])->append('name', 'checkUniqueByEdit');;
} }
@ -98,23 +98,23 @@ class DeptValidate extends BaseValidate
*/ */
public function sceneDelete() public function sceneDelete()
{ {
return $this->only(['id'])->append('id','checkDept'); return $this->only(['id'])->append('id', 'checkDept');
} }
//验证唯一 //验证唯一
public function checkUniqueByAdd($value,$rule,$data): bool|string public function checkUniqueByAdd($value, $rule, $data): bool|string
{ {
$dep = Dept::where('org_id',$data['org_id'])->where('name',$data['name'])->findOrEmpty(); $dep = Dept::where('org_id', $data['org_id'])->where('name', $data['name'])->findOrEmpty();
if(!$dep->isEmpty()){ if (!$dep->isEmpty()) {
return '部门已存在'; return '部门已存在';
} }
return true; return true;
} }
public function checkUniqueByEdit($value,$rule,$data): bool|string 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(); $dep = Dept::where('org_id', $data['org_id'])->where('name', $data['name'])->where('id', '<>', $data['id'])->findOrEmpty();
if(!$dep->isEmpty()){ if (!$dep->isEmpty()) {
return '部门已存在'; return '部门已存在';
} }
return true; return true;
@ -140,12 +140,14 @@ class DeptValidate extends BaseValidate
return true; return true;
} }
public function checkLeader($value){ public function checkLeader($value)
$data = Admin::where('id',$value)->findOrEmpty(); {
if($data->isEmpty()){ if (empty($value)) return true;
$data = Admin::where('id', $value)->findOrEmpty();
if ($data->isEmpty()) {
return '负责人信息不存在'; return '负责人信息不存在';
} }
return true; return true;
} }
} }