From 490bde6bb46538fda9e651f3512fc5de095a3491 Mon Sep 17 00:00:00 2001 From: yaooo <272523191@qq.com> Date: Sat, 23 Dec 2023 14:36:53 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E7=BB=86=E8=8A=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/adminapi/lists/custom/CustomLists.php | 27 +++++++++++++++-------- app/adminapi/logic/custom/CustomLogic.php | 10 ++++++++- app/common/model/custom/Custom.php | 22 ++++++++++++++++++ 3 files changed, 49 insertions(+), 10 deletions(-) diff --git a/app/adminapi/lists/custom/CustomLists.php b/app/adminapi/lists/custom/CustomLists.php index 44f8aaf21..7442943d5 100644 --- a/app/adminapi/lists/custom/CustomLists.php +++ b/app/adminapi/lists/custom/CustomLists.php @@ -19,7 +19,7 @@ use app\adminapi\lists\BaseAdminDataLists; use app\common\model\custom\Custom; use app\common\model\custom_follow\CustomFollow; use app\common\lists\ListsSearchInterface; - +use think\facade\Db; /** * Custom列表 @@ -39,7 +39,7 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface public function setSearch(): array { return [ - '=' => ['name', 'custom_type', 'phone', 'credit_rating', 'province', 'city', 'status'], + '=' => ['c.name', 'c.custom_type', 'c.phone', 'c.credit_rating', 'c.province', 'c.city', 'c.status'], ]; } @@ -55,12 +55,16 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface */ public function lists(): array { - return Custom::where($this->searchWhere) - ->with('province') - ->field(['*']) + return Db::name('Custom')->alias('c') + ->where($this->searchWhere) + ->whereNull('c.delete_time') + ->leftJoin('orgs o','o.id = c.org_id') + ->leftJoin('dept d','d.id = c.dept_id') + ->field('c.*, d.name as dept_name, o.name as org_name') ->limit($this->limitOffset, $this->limitLength) - ->order(['id' => 'desc']) + ->order(['c.id' => 'desc']) ->select()->each(function($item, $key){ + //关联数据后续添加 if (!empty($item['other_contacts'])) { $otherContactsArray = json_decode($item['other_contacts'], true); if (is_array($otherContactsArray)) { @@ -84,9 +88,10 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface $item['last_follow_date'] = '超过60天内'; } $item['next_follow_date'] = $customFollow['next_follow_date']; - } + } return $item; - })->toArray(); + }) + ->toArray(); } @@ -98,7 +103,11 @@ class CustomLists extends BaseAdminDataLists implements ListsSearchInterface */ public function count(): int { - return Custom::where($this->searchWhere)->count(); + return Db::name('Custom')->alias('c') + ->where($this->searchWhere) + ->whereNull('c.delete_time') + ->leftJoin('orgs o','o.id = c.org_id') + ->leftJoin('dept d','d.id = c.dept_id')->count(); } } \ No newline at end of file diff --git a/app/adminapi/logic/custom/CustomLogic.php b/app/adminapi/logic/custom/CustomLogic.php index bf5ffe5c9..927f48a13 100644 --- a/app/adminapi/logic/custom/CustomLogic.php +++ b/app/adminapi/logic/custom/CustomLogic.php @@ -41,6 +41,8 @@ class CustomLogic extends BaseLogic Db::startTrans(); try { Custom::create([ + 'org_id' => $params['org_id'] ?? 0, + 'dept_id' => $params['dept_id'] ?? 0, 'name' => $params['name'] ?? '', 'custom_type' => $params['custom_type'] ?? 0, 'parent_company' => $params['parent_company'] ?? 0, @@ -89,6 +91,8 @@ class CustomLogic extends BaseLogic Db::startTrans(); try { Custom::where('id', $params['id'])->update([ + 'org_id' => $params['org_id'] ?? 0, + 'dept_id' => $params['dept_id'] ?? 0, 'name' => $params['name'] ?? '', 'custom_type' => $params['custom_type'] ?? 0, 'parent_company' => $params['parent_company'] ?? 0, @@ -147,6 +151,10 @@ class CustomLogic extends BaseLogic */ public static function detail($params): array { - return Custom::findOrEmpty($params['id'])->toArray(); + $custom = Custom::findOrEmpty($params['id']); + $custom->org; + $custom->dept; + $custom->other_contacts = json_decode($custom->other_contacts, true); + return $custom->toArray(); } } \ No newline at end of file diff --git a/app/common/model/custom/Custom.php b/app/common/model/custom/Custom.php index 413739668..07cdd5e8f 100644 --- a/app/common/model/custom/Custom.php +++ b/app/common/model/custom/Custom.php @@ -36,4 +36,26 @@ class Custom extends BaseModel { return $this->hasOne(GeoProvince::class, 'province_code','province'); } + + /** + * @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