解决方案模块功能完善

This commit is contained in:
weiz 2023-12-12 10:26:38 +08:00
parent 6f88181275
commit 131f3ece72
6 changed files with 159 additions and 39 deletions

View File

@ -20,6 +20,9 @@ use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\custom\CustomerDemandLists; use app\adminapi\lists\custom\CustomerDemandLists;
use app\adminapi\logic\custom\CustomerDemandLogic; use app\adminapi\logic\custom\CustomerDemandLogic;
use app\adminapi\validate\custom\CustomerDemandValidate; 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); $result = CustomerDemandLogic::detail($params);
return $this->data($result); 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);
}
} }

View File

@ -103,6 +103,5 @@ class CustomerDemandSolutionController extends BaseAdminController
$result = CustomerDemandSolutionLogic::detail($params); $result = CustomerDemandSolutionLogic::detail($params);
return $this->data($result); return $this->data($result);
} }
} }

View File

@ -61,14 +61,6 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter
{ {
$params = $this->request->param(); $params = $this->request->param();
$where = []; $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'] != ''){ if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds]; $where[] = ['project_id','in',$projectIds];
@ -79,20 +71,15 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter
$where[] = ['project_id','in',$projectIds]; $where[] = ['project_id','in',$projectIds];
} }
return CustomerDemand::where($this->searchWhere)->where($where) 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) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->order(['id' => 'desc'])
->select()->each(function($item){ ->select()->each(function($item){
$item['importance_text'] = $item->importance_text; $item['importance_text'] = $item->importance_text;
$item['recording_time'] = date('Y-m-d H:i:s',$item['recording_time']); $item['recording_time'] = date('Y-m-d H:i:s',$item['recording_time']);
$org = Orgs::field('name')->where('id',$item['org_id'])->findOrEmpty(); $project = Project::field('name,custom_id')->where('id',$item['project_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();
$custom = Custom::field('name')->where('id',$project['custom_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_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
$item['custom_name'] = $custom['name']; $item['custom_name'] = $custom['name'];
return $item; return $item;
}) })
@ -110,14 +97,6 @@ class CustomerDemandLists extends BaseAdminDataLists implements ListsSearchInter
{ {
$params = $this->request->param(); $params = $this->request->param();
$where = []; $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'] != ''){ if(isset($params['project_name']) && $params['project_name'] != ''){
$projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $projectIds = Project::where('name','like','%'.$params['project_name'].'%')->column('id');
$where[] = ['project_id','in',$projectIds]; $where[] = ['project_id','in',$projectIds];

View File

@ -16,8 +16,11 @@ namespace app\adminapi\lists\custom;
use app\adminapi\lists\BaseAdminDataLists; 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\model\custom\CustomerDemandSolution;
use app\common\lists\ListsSearchInterface; 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 public function setSearch(): array
{ {
return [ return [
'=' => ['theme'], '%like%' => ['theme'],
]; ];
} }
@ -54,11 +57,35 @@ class CustomerDemandSolutionLists extends BaseAdminDataLists implements ListsSea
*/ */
public function lists(): array public function lists(): array
{ {
return CustomerDemandSolution::where($this->searchWhere) $params = $this->request->param();
->field(['id', 'org_id', 'department_id', 'project_id', 'customer_demand_id', 'theme', 'submission_time']) $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) ->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc']) ->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(); ->toArray();
} }
@ -71,7 +98,22 @@ class CustomerDemandSolutionLists extends BaseAdminDataLists implements ListsSea
*/ */
public function count(): int 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();
} }
} }

View File

@ -15,8 +15,13 @@
namespace app\adminapi\logic\custom; 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\model\custom\CustomerDemandSolution;
use app\common\logic\BaseLogic; 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; use think\facade\Db;
@ -42,7 +47,7 @@ class CustomerDemandSolutionLogic extends BaseLogic
try { try {
CustomerDemandSolution::create([ CustomerDemandSolution::create([
'org_id' => $params['org_id'], 'org_id' => $params['org_id'],
'department_id' => $params['department_id'], 'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'], 'project_id' => $params['project_id'],
'customer_demand_id' => $params['customer_demand_id'], 'customer_demand_id' => $params['customer_demand_id'],
'theme' => $params['theme'], 'theme' => $params['theme'],
@ -51,7 +56,6 @@ class CustomerDemandSolutionLogic extends BaseLogic
'customer_feedback' => $params['customer_feedback'], 'customer_feedback' => $params['customer_feedback'],
'annex' => $params['annex'] 'annex' => $params['annex']
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -75,7 +79,7 @@ class CustomerDemandSolutionLogic extends BaseLogic
try { try {
CustomerDemandSolution::where('id', $params['id'])->update([ CustomerDemandSolution::where('id', $params['id'])->update([
'org_id' => $params['org_id'], 'org_id' => $params['org_id'],
'department_id' => $params['department_id'], 'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'], 'project_id' => $params['project_id'],
'customer_demand_id' => $params['customer_demand_id'], 'customer_demand_id' => $params['customer_demand_id'],
'theme' => $params['theme'], 'theme' => $params['theme'],
@ -84,7 +88,6 @@ class CustomerDemandSolutionLogic extends BaseLogic
'customer_feedback' => $params['customer_feedback'], 'customer_feedback' => $params['customer_feedback'],
'annex' => $params['annex'] 'annex' => $params['annex']
]); ]);
Db::commit(); Db::commit();
return true; return true;
} catch (\Exception $e) { } catch (\Exception $e) {
@ -117,6 +120,19 @@ class CustomerDemandSolutionLogic extends BaseLogic
*/ */
public static function detail($params): array 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;
} }
} }

View File

@ -15,6 +15,10 @@
namespace app\adminapi\validate\custom; 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; use app\common\validate\BaseValidate;
@ -32,7 +36,23 @@ class CustomerDemandSolutionValidate extends BaseValidate
*/ */
protected $rule = [ protected $rule = [
'id' => 'require', '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 * @date 2023/11/24 21:32
*/ */
public function sceneEdit() public function sceneEdit()
{ {}
return $this->only(['id']);
}
/** /**
@ -90,5 +108,47 @@ class CustomerDemandSolutionValidate extends BaseValidate
{ {
return $this->only(['id']); 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;
}
} }