解决方案模块功能完善
This commit is contained in:
parent
6f88181275
commit
131f3ece72
@ -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;
|
||||
|
||||
|
||||
/**
|
||||
@ -104,5 +107,26 @@ class CustomerDemandController extends BaseAdminController
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
@ -104,5 +104,4 @@ class CustomerDemandSolutionController extends BaseAdminController
|
||||
return $this->data($result);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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];
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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,8 +36,24 @@ 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']);
|
||||
}
|
||||
{}
|
||||
|
||||
|
||||
/**
|
||||
@ -91,4 +109,46 @@ 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;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user