From 9a1368fa3f3f5cbb547c31b83b78b263a02188e1 Mon Sep 17 00:00:00 2001 From: weiz Date: Mon, 11 Dec 2023 14:06:08 +0800 Subject: [PATCH] =?UTF-8?q?=E5=94=AE=E5=89=8D=E6=88=90=E5=91=98=E6=A8=A1?= =?UTF-8?q?=E5=9D=97=E5=8A=9F=E8=83=BD=E5=AE=8C=E5=96=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectPreSalesMembersController.php | 2 +- .../project/ProjectPreSalesMembersLists.php | 47 +++++++++++++++++-- .../project/ProjectPreSalesMembersLogic.php | 38 ++++++++++----- .../ProjectPreSalesMembersValidate.php | 40 +++++++++++++++- 4 files changed, 109 insertions(+), 18 deletions(-) diff --git a/app/adminapi/controller/project/ProjectPreSalesMembersController.php b/app/adminapi/controller/project/ProjectPreSalesMembersController.php index 873f2b72a..368297c65 100644 --- a/app/adminapi/controller/project/ProjectPreSalesMembersController.php +++ b/app/adminapi/controller/project/ProjectPreSalesMembersController.php @@ -52,7 +52,7 @@ class ProjectPreSalesMembersController extends BaseAdminController public function add() { $params = (new ProjectPreSalesMembersValidate())->post()->goCheck('add'); - $result = ProjectPreSalesMembersLogic::add($params); + $result = ProjectPreSalesMembersLogic::add($params,$this->adminId); if (true === $result) { return $this->success('添加成功', [], 1, 1); } diff --git a/app/adminapi/lists/project/ProjectPreSalesMembersLists.php b/app/adminapi/lists/project/ProjectPreSalesMembersLists.php index 6d8aaafd7..91b4d4a1c 100644 --- a/app/adminapi/lists/project/ProjectPreSalesMembersLists.php +++ b/app/adminapi/lists/project/ProjectPreSalesMembersLists.php @@ -16,6 +16,9 @@ namespace app\adminapi\lists\project; use app\adminapi\lists\BaseAdminDataLists; +use app\common\model\auth\Admin; +use app\common\model\custom\Custom; +use app\common\model\project\Project; use app\common\model\project\ProjectPreSalesMembers; use app\common\lists\ListsSearchInterface; @@ -54,11 +57,36 @@ class ProjectPreSalesMembersLists extends BaseAdminDataLists implements ListsSea */ public function lists(): array { - return ProjectPreSalesMembers::where($this->searchWhere) - ->field(['id', 'project_id', 'technician_ids', 'business_people_ids', 'cross_departmental_personnel_ids']) + $params = $this->request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['custom_name']) && $params['custom_name'] != ''){ + $customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + return ProjectPreSalesMembers::where($this->searchWhere)->where($where) + ->field(['id,project_id,technician_ids,business_people_ids,cross_departmental_personnel_ids,add_people,create_time']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($item){ + $project = Project::field('id,custom_id,name')->where('id',$item['project_id'])->findOrEmpty(); + $custom = Custom::field('id,name')->where('id',$project['custom_id'])->findOrEmpty(); + $technician = Admin::where('id','in',$item['technician_ids'])->column('name'); + $business_people = Admin::where('id','in',$item['business_people_ids'])->column('name'); + $cross_departmental_personnel = Admin::where('id','in',$item['cross_departmental_personnel_ids'])->column('name'); + $add_people = Admin::field('name')->where('id',$item['add_people'])->findOrEmpty(); + $item['project_name'] = $project['name']; + $item['custom_name'] = $custom['name']; + $item['technician'] = implode(',',$technician); + $item['business_people'] = implode(',',$business_people); + $item['cross_departmental_personnel'] = implode(',',$cross_departmental_personnel); + $item['add_people'] = $add_people['name']; + unset($item['technician_ids'],$item['business_people_ids'],$item['cross_departmental_personnel_ids']); + }) ->toArray(); } @@ -71,7 +99,18 @@ class ProjectPreSalesMembersLists extends BaseAdminDataLists implements ListsSea */ public function count(): int { - return ProjectPreSalesMembers::where($this->searchWhere)->count(); + $params = $this->request->param(); + $where = []; + if(isset($params['project_name']) && $params['project_name'] != ''){ + $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + if(isset($params['custom_name']) && $params['custom_name'] != ''){ + $customIds = Custom::where('name','like','%'.$params['custom_name'].'%')->column('id'); + $projectIds = Project::where('custom_id','in',$customIds)->column('id'); + $where[] = ['project_id','in',$projectIds]; + } + return ProjectPreSalesMembers::where($this->searchWhere)->where($where)->count(); } } \ No newline at end of file diff --git a/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php b/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php index 21e30e229..20719e752 100644 --- a/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php +++ b/app/adminapi/logic/project/ProjectPreSalesMembersLogic.php @@ -15,6 +15,9 @@ namespace app\adminapi\logic\project; +use app\common\model\auth\Admin; +use app\common\model\custom\Custom; +use app\common\model\project\Project; use app\common\model\project\ProjectPreSalesMembers; use app\common\logic\BaseLogic; use think\facade\Db; @@ -36,17 +39,17 @@ class ProjectPreSalesMembersLogic extends BaseLogic * @author likeadmin * @date 2023/11/14 10:15 */ - public static function add(array $params): bool + public static function add(array $params,$adminId = 0): bool { Db::startTrans(); try { ProjectPreSalesMembers::create([ 'project_id' => $params['project_id'], - 'technician_ids' => $params['technician_ids'], - 'business_people_ids' => $params['business_people_ids'], - 'cross_departmental_personnel_ids' => $params['cross_departmental_personnel_ids'] + 'technician_ids' => trim($params['technician_ids'],','), + 'business_people_ids' => trim($params['business_people_ids'],','), + 'cross_departmental_personnel_ids' => trim($params['cross_departmental_personnel_ids'],','), + 'add_people' => $adminId ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -69,12 +72,11 @@ class ProjectPreSalesMembersLogic extends BaseLogic Db::startTrans(); try { ProjectPreSalesMembers::where('id', $params['id'])->update([ - 'project_id' => $params['project_id'], - 'technician_ids' => $params['technician_ids'], - 'business_people_ids' => $params['business_people_ids'], - 'cross_departmental_personnel_ids' => $params['cross_departmental_personnel_ids'] + 'project_id' => $params['project_id'], + 'technician_ids' => trim($params['technician_ids'],','), + 'business_people_ids' => trim($params['business_people_ids'],','), + 'cross_departmental_personnel_ids' => trim($params['cross_departmental_personnel_ids'],','), ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -107,6 +109,20 @@ class ProjectPreSalesMembersLogic extends BaseLogic */ public static function detail($params): array { - return ProjectPreSalesMembers::findOrEmpty($params['id'])->toArray(); + $data = ProjectPreSalesMembers::field('id,project_id,technician_ids,business_people_ids,cross_departmental_personnel_ids,add_people,create_time')->findOrEmpty($params['id'])->toArray(); + $project = Project::field('id,custom_id,name')->where('id',$data['project_id'])->findOrEmpty(); + $custom = Custom::field('id,name')->where('id',$project['custom_id'])->findOrEmpty(); + $technician = Admin::where('id','in',$data['technician_ids'])->column('name'); + $business_people = Admin::where('id','in',$data['business_people_ids'])->column('name'); + $cross_departmental_personnel = Admin::where('id','in',$data['cross_departmental_personnel_ids'])->column('name'); + $add_people = Admin::field('name')->where('id',$data['add_people'])->findOrEmpty(); + $data['project_name'] = $project['name']; + $data['custom_name'] = $custom['name']; + $data['technician'] = implode(',',$technician); + $data['business_people'] = implode(',',$business_people); + $data['cross_departmental_personnel'] = implode(',',$cross_departmental_personnel); + $data['add_people'] = $add_people['name']; + unset($data['technician_ids'],$data['business_people_ids'],$data['cross_departmental_personnel_ids']); + return $data; } } \ No newline at end of file diff --git a/app/adminapi/validate/project/ProjectPreSalesMembersValidate.php b/app/adminapi/validate/project/ProjectPreSalesMembersValidate.php index 4ab11416e..01815d8e6 100644 --- a/app/adminapi/validate/project/ProjectPreSalesMembersValidate.php +++ b/app/adminapi/validate/project/ProjectPreSalesMembersValidate.php @@ -15,6 +15,8 @@ namespace app\adminapi\validate\project; +use app\common\model\auth\Admin; +use app\common\model\project\Project; use app\common\validate\BaseValidate; @@ -32,7 +34,18 @@ class ProjectPreSalesMembersValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'project_id' => 'require|checkProject', + 'technician_ids' => 'require|checkUser', + 'business_people_ids' => 'require|checkUser', + 'cross_departmental_personnel_ids' => 'checkUser' ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'project_id.require' => '请选择项目', + 'technician_ids.require' => '请选择技术人员', + 'business_people_ids.require' => '请选择商务人员', + ]; /** @@ -64,7 +77,7 @@ class ProjectPreSalesMembersValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id']); + return $this->only(['id','project_id','technician_ids','business_people_ids']); } @@ -90,5 +103,28 @@ class ProjectPreSalesMembersValidate extends BaseValidate { return $this->only(['id']); } - + + public function checkProject($value): bool|string + { + $project = Project::where('id',$value)->findOrEmpty(); + if($project->isEmpty()){ + return '项目不存在'; + } + return true; + } + + public function checkUser($value): bool|string + { + $ids = explode(',',trim($value,',')); + if(empty($ids)){ + return '请选择人员'; + } + foreach ($ids as $v) { + $admin = Admin::field('id')->where('id',$v)->findOrEmpty(); + if($admin->isEmpty()){ + return '人员不存在'; + } + } + return true; + } } \ No newline at end of file