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 cd86d9a8a..ea589e36c 100644 --- a/app/adminapi/lists/custom/CustomerDemandLists.php +++ b/app/adminapi/lists/custom/CustomerDemandLists.php @@ -61,14 +61,6 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter { $params = $this->request->param(); $where = []; - if(isset($params['org_name']) && $params['org_name'] != ''){ - $orgIds = Orgs::where('name','like','%'.$params['org_name'].'%')->column('id'); - $where[] = ['org_id','in',$orgIds]; - } - if(isset($params['dept_name']) && $params['dept_name'] != ''){ - $deptIds = Dept::where('name','like','%'.$params['dept_name'].'%')->column('id'); - $where[] = ['dept_id','in',$deptIds]; - } if(isset($params['project_name']) && $params['project_name'] != ''){ $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $where[] = ['project_id','in',$projectIds]; @@ -79,20 +71,15 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter $where[] = ['project_id','in',$projectIds]; } return CustomerDemand::where($this->searchWhere)->where($where) - ->field(['id', 'org_id', 'dept_id', 'project_id', 'theme', 'supplier', 'supplier_contacts', 'importance', 'recording_time', 'demand_content', 'annex']) + ->field(['id','project_id', 'theme', 'supplier', 'supplier_contacts', 'importance', 'recording_time', 'demand_content', 'annex']) ->limit($this->limitOffset, $this->limitLength) ->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']); - $org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty(); - $dept = Dept::field('name')->where('id',$item['dept_id'])->findOrEmpty(); - $project = Project::field('name,project_code,custom_id')->where('id',$item['project_id'])->findOrEmpty(); + $project = Project::field('name,custom_id')->where('id',$item['project_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); - $item['org_name'] = $org['name']; - $item['dept_name'] = $dept['name']; $item['project_name'] = $project['name']; - $item['project_code'] = $project['project_code']; $item['custom_name'] = $custom['name']; return $item; }) @@ -110,14 +97,6 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter { $params = $this->request->param(); $where = []; - if(isset($params['org_name']) && $params['org_name'] != ''){ - $orgIds = Orgs::where('name','like','%'.$params['org_name'].'%')->column('id'); - $where[] = ['org_id','in',$orgIds]; - } - if(isset($params['dept_name']) && $params['dept_name'] != ''){ - $deptIds = Dept::where('name','like','%'.$params['dept_name'].'%')->column('id'); - $where[] = ['dept_id','in',$deptIds]; - } if(isset($params['project_name']) && $params['project_name'] != ''){ $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $where[] = ['project_id','in',$projectIds]; 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/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