售前成员模块功能完善
This commit is contained in:
parent
77b4fe2ce8
commit
9a1368fa3f
@ -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);
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user