This commit is contained in:
weiz 2024-02-01 14:40:49 +08:00
parent 350d4f0454
commit 880025f7ba
3 changed files with 22 additions and 8 deletions

View File

@ -4,6 +4,7 @@
use app\adminapi\lists\BaseAdminDataLists;
use app\common\lists\ListsSearchInterface;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
@ -44,7 +45,9 @@
->order(['sort' => 'desc', 'id' => 'desc'])
->select()->each(function($item){
$org = Orgs::where('id',$item['org_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['leader'])->findOrEmpty();
$item['org_name'] = $org->isEmpty() ? '' : $org['name'];
$item['leader'] = $admin['name'];
return $item;
})
->toArray();

View File

@ -16,6 +16,7 @@ namespace app\adminapi\logic\dept;
use app\common\enum\YesNoEnum;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
use app\common\model\dept\Dept;
use app\common\model\dept\Jobs;
use app\common\model\dept\Orgs;
@ -101,14 +102,16 @@ class DeptLogic extends BaseLogic
*/
public static function detail($params): array
{
$dept = Dept::field('id,name,org_id,leader,mobile,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
if($dept->isEmpty()){
$data = Dept::field('id,name,org_id,leader,mobile,status,sort,create_time')->where('id',$params['id'])->findOrEmpty();
if($data->isEmpty()){
return [];
}
$org = Orgs::where('id',$dept['org_id'])->findOrEmpty();
$dept['org_name'] = $org->isEmpty() ? '' : $org['name'];
$dept['status_text'] = $dept->status_text;
return $dept->toArray();
$org = Orgs::where('id',$data['org_id'])->findOrEmpty();
$data['org_name'] = $org->isEmpty() ? '' : $org['name'];
$data['status_text'] = $data->status_text;
$admin = Admin::field('name')->where('id',$data['leader'])->findOrEmpty();
$data['leader'] = $admin['name'];
return $data->toArray();
}
}

View File

@ -33,7 +33,7 @@ class DeptValidate extends BaseValidate
'id' => 'require|checkDept',
'org_id' => 'require|checkOrg',
'name' => 'require|length:1,30',
'leader' => 'require',
'leader' => 'require|checkLeader',
'mobile' => 'require|mobile',
'status' => 'require|in:0,1',
'sort' => 'egt:0',
@ -46,7 +46,7 @@ class DeptValidate extends BaseValidate
'name.require' => '请填写部门名称',
'name.length' => '部门名称长度须在1-30位字符',
'name.unique' => '部门名称已存在',
'leader.require' => '请填写部门负责人',
'leader.require' => '请选择部门负责人',
'mobile.require' => '请填写部门负责人联系电话',
'mobile.mobile' => '部门负责人联系电话格式错误',
'status.require' => '请选择部门状态',
@ -140,4 +140,12 @@ class DeptValidate extends BaseValidate
return true;
}
public function checkLeader($value){
$data = Admin::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '负责人信息不存在';
}
return true;
}
}