diff --git a/app/adminapi/lists/custom_service/CustomServiceLists.php b/app/adminapi/lists/custom_service/CustomServiceLists.php index 13b815c1d..93a38eb6a 100644 --- a/app/adminapi/lists/custom_service/CustomServiceLists.php +++ b/app/adminapi/lists/custom_service/CustomServiceLists.php @@ -18,7 +18,7 @@ namespace app\adminapi\lists\custom_service; use app\adminapi\lists\BaseAdminDataLists; use app\common\model\custom_service\CustomService; use app\common\lists\ListsSearchInterface; - +use think\facade\Db; /** * CustomService列表 @@ -38,7 +38,7 @@ class CustomServiceLists extends BaseAdminDataLists implements ListsSearchInterf public function setSearch(): array { return [ - '=' => ['project_id', 'custom_id', 'approve_id', 'contacts', 'phone', 'date', 'classification', 'urgency', 'receiver', 'processed_admin_id', 'name', 'description', 'notes', 'annex'], + '=' => ['cs.project_id', 'cs.custom_id', 'cs.approve_id', 'cs.contacts', 'cs.phone', 'cs.date', 'cs.classification', 'cs.urgency', 'cs.receiver', 'cs.processed_admin_id', 'cs.name'], ]; } @@ -54,10 +54,18 @@ class CustomServiceLists extends BaseAdminDataLists implements ListsSearchInterf */ public function lists(): array { - return CustomService::where($this->searchWhere) - ->field(['*'])->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) - ->select() + return Db::name('CustomService')->alias('cs') + ->where($this->searchWhere) + ->whereNull('cs.delete_time') + ->leftJoin('orgs o','o.id = cs.org_id') + ->leftJoin('dept d','d.id = cs.dept_id') + ->field('cs.*, d.name as dept_name, o.name as org_name') + ->limit($this->limitOffset, $this->limitLength) + ->order(['cs.id' => 'desc']) + ->select()->each(function($item, $key){ + //关联数据后续添加 + return $item; + }) ->toArray(); } @@ -70,7 +78,11 @@ class CustomServiceLists extends BaseAdminDataLists implements ListsSearchInterf */ public function count(): int { - return CustomService::where($this->searchWhere)->count(); + return Db::name('CustomService')->alias('cs') + ->where($this->searchWhere) + ->whereNull('cs.delete_time') + ->leftJoin('orgs o','o.id = cs.org_id') + ->leftJoin('dept d','d.id = cs.dept_id')->count(); } } \ No newline at end of file diff --git a/app/adminapi/logic/custom_service/CustomServiceLogic.php b/app/adminapi/logic/custom_service/CustomServiceLogic.php index 248957960..afb7b3054 100644 --- a/app/adminapi/logic/custom_service/CustomServiceLogic.php +++ b/app/adminapi/logic/custom_service/CustomServiceLogic.php @@ -41,6 +41,8 @@ class CustomServiceLogic extends BaseLogic Db::startTrans(); try { CustomService::create([ + 'org_id' => $params['org_id'] ?? 0, + 'dept_id' => $params['dept_id'] ?? 0, 'project_id' => $params['project_id'] ?? 0, 'custom_id' => $params['custom_id'] ?? 0, 'approve_id' => $params['approve_id'] ?? 0, @@ -79,6 +81,8 @@ class CustomServiceLogic extends BaseLogic Db::startTrans(); try { CustomService::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'] ?? 0, + 'dept_id' => $params['dept_id'] ?? 0, 'project_id' => $params['project_id'] ?? 0, 'custom_id' => $params['custom_id'] ?? 0, 'approve_id' => $params['approve_id'] ?? 0, @@ -130,6 +134,8 @@ class CustomServiceLogic extends BaseLogic $customService = CustomService::findOrEmpty($params['id']); $customService->project; $customService->custom; + $customService->org; + $customService->dept; $customService->annex = json_decode($customService->annex, true); return $customService->toArray(); } diff --git a/app/common/model/custom_service/CustomService.php b/app/common/model/custom_service/CustomService.php index b4cad227d..a24fcf0ec 100644 --- a/app/common/model/custom_service/CustomService.php +++ b/app/common/model/custom_service/CustomService.php @@ -45,4 +45,26 @@ class CustomService extends BaseModel return $this->belongsTo(\app\common\model\project\Project::class, 'project_id'); } + /** + * @notes 关联org + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2023/12/20 11:01 + */ + public function org() + { + return $this->hasOne(\app\common\model\dept\Orgs::class, 'id', 'org_id'); + } + + /** + * @notes 关联dept + * @return \think\model\relation\HasOne + * @author likeadmin + * @date 2023/12/20 11:01 + */ + public function dept() + { + return $this->hasOne(\app\common\model\dept\Dept::class, 'id', 'dept_id'); + } + } \ No newline at end of file