diff --git a/app/adminapi/controller/custom/CustomerDemandController.php b/app/adminapi/controller/custom/CustomerDemandController.php index bdb7d03b1..8fef292e7 100644 --- a/app/adminapi/controller/custom/CustomerDemandController.php +++ b/app/adminapi/controller/custom/CustomerDemandController.php @@ -20,6 +20,9 @@ use app\adminapi\controller\BaseAdminController; use app\adminapi\lists\custom\CustomerDemandLists; use app\adminapi\logic\custom\CustomerDemandLogic; use app\adminapi\validate\custom\CustomerDemandValidate; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomerDemand; +use app\common\model\project\Project; /** @@ -103,6 +106,27 @@ class CustomerDemandController extends BaseAdminController $result = CustomerDemandLogic::detail($params); return $this->data($result); } - + + //根据项目id获取客户需求列表 + public function getListByProjectId(): \think\response\Json + { + $project_id = $this->request->get('project_id'); + if(empty($project_id)){ + return $this->fail('缺少必要参数'); + } + $data = CustomerDemand::where('project_id',$project_id) + ->field(['id', 'project_id', 'theme', 'supplier', 'supplier_contacts', 'importance', 'recording_time', 'demand_content', 'annex']) + ->order(['id' => 'desc']) + ->select()->each(function($item){ + $item['importance_text'] = $item->importance_text; + $item['recording_time'] = date('Y-m-d H:i:s',$item['recording_time']); + $project = Project::field('name,custom_id')->where('id',$item['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $item['project_name'] = $project['name']; + $item['custom_name'] = $custom['name']; + return $item; + })->toArray(); + return $this->success('请求成功',$data); + } } \ No newline at end of file diff --git a/app/adminapi/controller/custom/CustomerDemandSolutionController.php b/app/adminapi/controller/custom/CustomerDemandSolutionController.php index 4d9bae12d..d6b5ca703 100644 --- a/app/adminapi/controller/custom/CustomerDemandSolutionController.php +++ b/app/adminapi/controller/custom/CustomerDemandSolutionController.php @@ -103,6 +103,5 @@ class CustomerDemandSolutionController extends BaseAdminController $result = CustomerDemandSolutionLogic::detail($params); return $this->data($result); } - - + } \ No newline at end of file diff --git a/app/adminapi/lists/custom/CustomerDemandLists.php b/app/adminapi/lists/custom/CustomerDemandLists.php index 3ec99a165..ea589e36c 100644 --- a/app/adminapi/lists/custom/CustomerDemandLists.php +++ b/app/adminapi/lists/custom/CustomerDemandLists.php @@ -16,8 +16,12 @@ namespace app\adminapi\lists\custom; use app\adminapi\lists\BaseAdminDataLists; +use app\common\model\custom\Custom; use app\common\model\custom\CustomerDemand; use app\common\lists\ListsSearchInterface; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\project\Project; /** @@ -38,7 +42,8 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter public function setSearch(): array { return [ - '=' => ['org_id', 'department_id', 'project_id', 'theme', 'supplier', 'supplier_contacts', 'importance', 'recording_time', 'demand_content', 'annex'], + '=' => ['importance', 'recording_time'], + '%like%' => ['theme', 'supplier', 'supplier_contacts'] ]; } @@ -54,11 +59,30 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter */ public function lists(): array { - return CustomerDemand::where($this->searchWhere) - ->field(['id', 'org_id', 'department_id', 'project_id', 'theme', 'supplier', 'supplier_contacts', 'importance', 'recording_time', 'demand_content', 'annex']) + $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 CustomerDemand::where($this->searchWhere)->where($where) + ->field(['id','project_id', 'theme', 'supplier', 'supplier_contacts', 'importance', 'recording_time', 'demand_content', 'annex']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($item){ + $item['importance_text'] = $item->importance_text; + $item['recording_time'] = date('Y-m-d H:i:s',$item['recording_time']); + $project = Project::field('name,custom_id')->where('id',$item['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $item['project_name'] = $project['name']; + $item['custom_name'] = $custom['name']; + return $item; + }) ->toArray(); } @@ -71,7 +95,18 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter */ public function count(): int { - return CustomerDemand::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 CustomerDemand::where($this->searchWhere)->where($where)->count(); } } \ No newline at end of file diff --git a/app/adminapi/lists/custom/CustomerDemandSolutionLists.php b/app/adminapi/lists/custom/CustomerDemandSolutionLists.php index 2316a1776..c521f3a09 100644 --- a/app/adminapi/lists/custom/CustomerDemandSolutionLists.php +++ b/app/adminapi/lists/custom/CustomerDemandSolutionLists.php @@ -16,8 +16,11 @@ namespace app\adminapi\lists\custom; use app\adminapi\lists\BaseAdminDataLists; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomerDemand; use app\common\model\custom\CustomerDemandSolution; use app\common\lists\ListsSearchInterface; +use app\common\model\project\Project; /** @@ -38,7 +41,7 @@ class CustomerDemandSolutionLists extends BaseAdminDataLists implements ListsSea public function setSearch(): array { return [ - '=' => ['theme'], + '%like%' => ['theme'], ]; } @@ -54,11 +57,35 @@ class CustomerDemandSolutionLists extends BaseAdminDataLists implements ListsSea */ public function lists(): array { - return CustomerDemandSolution::where($this->searchWhere) - ->field(['id', 'org_id', 'department_id', 'project_id', 'customer_demand_id', 'theme', 'submission_time']) + $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]; + } + if(isset($params['customer_demand_name']) && $params['customer_demand_name'] != ''){ + $demandIds = CustomerDemand::where('theme','like','%'.$params['customer_demand_name'].'%')->column('id'); + $where[] = ['customer_demand_id','in',$demandIds]; + } + return CustomerDemandSolution::where($this->searchWhere)->where($where) + ->field(['id','project_id','customer_demand_id','theme','submission_time','solution_content','customer_feedback','annex']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) - ->select() + ->select()->each(function($item){ + $item['submission_time'] = date('Y-m-d H:i:s',$item['submission_time']); + $project = Project::field('name,custom_id')->where('id',$item['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $demand = CustomerDemand::field('theme')->where('id',$item['customer_demand_id'])->findOrEmpty(); + $item['project_name'] = $project['name']; + $item['custom_name'] = $custom['name']; + $item['customer_demand_name'] = $demand['theme']; + return $item; + }) ->toArray(); } @@ -71,7 +98,22 @@ class CustomerDemandSolutionLists extends BaseAdminDataLists implements ListsSea */ public function count(): int { - return CustomerDemandSolution::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]; + } + if(isset($params['customer_demand_name']) && $params['customer_demand_name'] != ''){ + $demandIds = CustomerDemand::where('theme','like','%'.$params['customer_demand_name'].'%')->column('id'); + $where[] = ['customer_demand_id','in',$demandIds]; + } + return CustomerDemandSolution::where($this->searchWhere)->where($where)->count(); } } \ No newline at end of file diff --git a/app/adminapi/logic/custom/CustomerDemandLogic.php b/app/adminapi/logic/custom/CustomerDemandLogic.php index 4ccfb3445..7514ad2a0 100644 --- a/app/adminapi/logic/custom/CustomerDemandLogic.php +++ b/app/adminapi/logic/custom/CustomerDemandLogic.php @@ -15,8 +15,12 @@ namespace app\adminapi\logic\custom; +use app\common\model\custom\Custom; use app\common\model\custom\CustomerDemand; use app\common\logic\BaseLogic; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\project\Project; use think\facade\Db; @@ -42,7 +46,7 @@ class CustomerDemandLogic extends BaseLogic try { CustomerDemand::create([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'theme' => $params['theme'], 'supplier' => $params['supplier'], @@ -52,7 +56,6 @@ class CustomerDemandLogic extends BaseLogic 'demand_content' => $params['demand_content'], 'annex' => $params['annex'] ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -76,7 +79,7 @@ class CustomerDemandLogic extends BaseLogic try { CustomerDemand::where('id', $params['id'])->update([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'theme' => $params['theme'], 'supplier' => $params['supplier'], @@ -86,7 +89,6 @@ class CustomerDemandLogic extends BaseLogic 'demand_content' => $params['demand_content'], 'annex' => $params['annex'] ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -119,6 +121,18 @@ class CustomerDemandLogic extends BaseLogic */ public static function detail($params): array { - return CustomerDemand::findOrEmpty($params['id'])->toArray(); + $data = CustomerDemand::field('id,org_id,dept_id,project_id,theme,supplier,supplier_contacts,importance,recording_time,demand_content,annex')->findOrEmpty($params['id']); + $data['importance_text'] = $data->importance_text; + $data['recording_time'] = date('Y-m-d H:i:s',$data['recording_time']); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $project = Project::field('name,project_code,custom_id')->where('id',$data['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $data['custom_name'] = $custom['name']; + return $data->toArray(); } } \ No newline at end of file diff --git a/app/adminapi/logic/custom/CustomerDemandSolutionLogic.php b/app/adminapi/logic/custom/CustomerDemandSolutionLogic.php index 5f66ac9ca..5739c7ecc 100644 --- a/app/adminapi/logic/custom/CustomerDemandSolutionLogic.php +++ b/app/adminapi/logic/custom/CustomerDemandSolutionLogic.php @@ -15,8 +15,13 @@ namespace app\adminapi\logic\custom; +use app\common\model\custom\Custom; +use app\common\model\custom\CustomerDemand; use app\common\model\custom\CustomerDemandSolution; use app\common\logic\BaseLogic; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\project\Project; use think\facade\Db; @@ -42,7 +47,7 @@ class CustomerDemandSolutionLogic extends BaseLogic try { CustomerDemandSolution::create([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'customer_demand_id' => $params['customer_demand_id'], 'theme' => $params['theme'], @@ -51,7 +56,6 @@ class CustomerDemandSolutionLogic extends BaseLogic 'customer_feedback' => $params['customer_feedback'], 'annex' => $params['annex'] ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -75,7 +79,7 @@ class CustomerDemandSolutionLogic extends BaseLogic try { CustomerDemandSolution::where('id', $params['id'])->update([ 'org_id' => $params['org_id'], - 'department_id' => $params['department_id'], + 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'customer_demand_id' => $params['customer_demand_id'], 'theme' => $params['theme'], @@ -84,7 +88,6 @@ class CustomerDemandSolutionLogic extends BaseLogic 'customer_feedback' => $params['customer_feedback'], 'annex' => $params['annex'] ]); - Db::commit(); return true; } catch (\Exception $e) { @@ -117,6 +120,19 @@ class CustomerDemandSolutionLogic extends BaseLogic */ public static function detail($params): array { - return CustomerDemandSolution::findOrEmpty($params['id'])->toArray(); + $data = CustomerDemandSolution::field('id,org_id,dept_id,project_id,customer_demand_id,theme,submission_time,solution_content,customer_feedback,annex')->findOrEmpty($params['id'])->toArray(); + $data['submission_time'] = date('Y-m-d H:i:s',$data['submission_time']); + $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); + $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); + $project = Project::field('name,project_code,custom_id')->where('id',$data['project_id'])->findOrEmpty(); + $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); + $demand = CustomerDemand::field('theme')->where('id',$data['customer_demand_id'])->findOrEmpty(); + $data['org_name'] = $org['name']; + $data['dept_name'] = $dept['name']; + $data['project_name'] = $project['name']; + $data['project_code'] = $project['project_code']; + $data['custom_name'] = $custom['name']; + $data['customer_demand_name'] = $demand['theme']; + return $data; } } \ No newline at end of file diff --git a/app/adminapi/validate/custom/CustomerDemandSolutionValidate.php b/app/adminapi/validate/custom/CustomerDemandSolutionValidate.php index d6de1776e..45e7addde 100644 --- a/app/adminapi/validate/custom/CustomerDemandSolutionValidate.php +++ b/app/adminapi/validate/custom/CustomerDemandSolutionValidate.php @@ -15,6 +15,10 @@ namespace app\adminapi\validate\custom; +use app\common\model\custom\CustomerDemand; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\project\Project; use app\common\validate\BaseValidate; @@ -32,7 +36,23 @@ class CustomerDemandSolutionValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'customer_demand_id' => 'require|checkCustomerDemand', + 'theme' => 'require', + 'submission_time' => 'date' ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'customer_demand_id.require' => '请选择客户需求', + 'theme.require' => '请填写需求主题', + 'submission_time.date' => '提交时间数据格式错误', + ]; /** @@ -63,9 +83,7 @@ class CustomerDemandSolutionValidate extends BaseValidate * @date 2023/11/24 21:32 */ public function sceneEdit() - { - return $this->only(['id']); - } + {} /** @@ -90,5 +108,47 @@ class CustomerDemandSolutionValidate extends BaseValidate { return $this->only(['id']); } + + public function checkOrg($value): bool|string + { + $org = Orgs::where('id',$value)->findOrEmpty(); + if($org->isEmpty()) { + return '组织不存在'; + } + return true; + } + + public function checkDept($value,$rule,$data): bool|string + { + $dept = Dept::where('id',$value)->findOrEmpty(); + if($dept->isEmpty()){ + return '部门不存在'; + } + if($dept['org_id'] != $data['org_id']){ + return '当前部门不属于所选择的组织'; + } + return true; + } + + public function checkProject($value): bool|string + { + $project = Project::where('id',$value)->findOrEmpty(); + if($project->isEmpty()){ + return '项目不存在'; + } + return true; + } + + public function checkCustomerDemand($value,$rule,$data): bool|string + { + $customDemand = CustomerDemand::where('id',$value)->findOrEmpty(); + if($customDemand->isEmpty()){ + return '客户需求不存在'; + } + if($customDemand['project_id'] != $data['project_id']){ + return '客户需求与项目信息不一致'; + } + return true; + } } \ No newline at end of file diff --git a/app/adminapi/validate/custom/CustomerDemandValidate.php b/app/adminapi/validate/custom/CustomerDemandValidate.php index 2fe22e408..6c8cfce91 100644 --- a/app/adminapi/validate/custom/CustomerDemandValidate.php +++ b/app/adminapi/validate/custom/CustomerDemandValidate.php @@ -15,6 +15,9 @@ namespace app\adminapi\validate\custom; +use app\common\model\dept\Dept; +use app\common\model\dept\Orgs; +use app\common\model\project\Project; use app\common\validate\BaseValidate; @@ -32,7 +35,24 @@ class CustomerDemandValidate extends BaseValidate */ protected $rule = [ 'id' => 'require', + 'org_id' => 'require|checkOrg', + 'dept_id' => 'require|checkDept', + 'project_id' => 'require|checkProject', + 'theme' => 'require', + 'importance' => 'integer|in:1,2,3,4', + 'recording_time' => 'date', ]; + + protected $message = [ + 'id.require' => '缺少必要参数', + 'org_id.require' => '请选择组织', + 'dept_id.require' => '请选择部门', + 'project_id.require' => '请选择项目', + 'theme.require' => '请填写需求主题', + 'importance.integer' => '重要程度数据格式错误', + 'importance.in' => '重要程度数据值错误', + 'recording_time.date' => '记录时间数据格式错误', + ]; /** @@ -64,7 +84,6 @@ class CustomerDemandValidate extends BaseValidate */ public function sceneEdit() { - return $this->only(['id']); } @@ -90,5 +109,35 @@ class CustomerDemandValidate extends BaseValidate { return $this->only(['id']); } + + public function checkOrg($value): bool|string + { + $org = Orgs::where('id',$value)->findOrEmpty(); + if($org->isEmpty()) { + return '组织不存在'; + } + return true; + } + + public function checkDept($value,$rule,$data): bool|string + { + $dept = Dept::where('id',$value)->findOrEmpty(); + if($dept->isEmpty()){ + return '部门不存在'; + } + if($dept['org_id'] != $data['org_id']){ + return '当前部门不属于所选择的组织'; + } + return true; + } + + public function checkProject($value): bool|string + { + $project = Project::where('id',$value)->findOrEmpty(); + if($project->isEmpty()){ + return '项目不存在'; + } + return true; + } } \ No newline at end of file diff --git a/app/common/model/custom/CustomerDemand.php b/app/common/model/custom/CustomerDemand.php index 7d4a36089..993c37312 100644 --- a/app/common/model/custom/CustomerDemand.php +++ b/app/common/model/custom/CustomerDemand.php @@ -29,6 +29,10 @@ class CustomerDemand extends BaseModel use SoftDelete; protected $name = 'customer_demand'; protected $deleteTime = 'delete_time'; - - + + public function getImportanceTextAttr($value,$data): string + { + $res = [1=>'非常重要',2=>'重要',3=>'一般',4=>'不重要']; + return $res[$data['importance']]; + } } \ No newline at end of file