Merge pull request '售前成员模块功能完善' (#16) from zhangwei into dev
Reviewed-on: #16
This commit is contained in:
commit
c975d7a62d
@ -52,7 +52,7 @@ class ProjectPreSalesMembersController extends BaseAdminController
|
|||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$params = (new ProjectPreSalesMembersValidate())->post()->goCheck('add');
|
$params = (new ProjectPreSalesMembersValidate())->post()->goCheck('add');
|
||||||
$result = ProjectPreSalesMembersLogic::add($params);
|
$result = ProjectPreSalesMembersLogic::add($params,$this->adminId);
|
||||||
if (true === $result) {
|
if (true === $result) {
|
||||||
return $this->success('添加成功', [], 1, 1);
|
return $this->success('添加成功', [], 1, 1);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,9 @@ namespace app\adminapi\lists\project;
|
|||||||
|
|
||||||
|
|
||||||
use app\adminapi\lists\BaseAdminDataLists;
|
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\model\project\ProjectPreSalesMembers;
|
||||||
use app\common\lists\ListsSearchInterface;
|
use app\common\lists\ListsSearchInterface;
|
||||||
|
|
||||||
@ -54,11 +57,36 @@ class ProjectPreSalesMembersLists extends BaseAdminDataLists implements ListsSea
|
|||||||
*/
|
*/
|
||||||
public function lists(): array
|
public function lists(): array
|
||||||
{
|
{
|
||||||
return ProjectPreSalesMembers::where($this->searchWhere)
|
$params = $this->request->param();
|
||||||
->field(['id', 'project_id', 'technician_ids', 'business_people_ids', 'cross_departmental_personnel_ids'])
|
$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)
|
->limit($this->limitOffset, $this->limitLength)
|
||||||
->order(['id' => 'desc'])
|
->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();
|
->toArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +99,18 @@ class ProjectPreSalesMembersLists extends BaseAdminDataLists implements ListsSea
|
|||||||
*/
|
*/
|
||||||
public function count(): int
|
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;
|
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\model\project\ProjectPreSalesMembers;
|
||||||
use app\common\logic\BaseLogic;
|
use app\common\logic\BaseLogic;
|
||||||
use think\facade\Db;
|
use think\facade\Db;
|
||||||
@ -36,17 +39,17 @@ class ProjectPreSalesMembersLogic extends BaseLogic
|
|||||||
* @author likeadmin
|
* @author likeadmin
|
||||||
* @date 2023/11/14 10:15
|
* @date 2023/11/14 10:15
|
||||||
*/
|
*/
|
||||||
public static function add(array $params): bool
|
public static function add(array $params,$adminId = 0): bool
|
||||||
{
|
{
|
||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
ProjectPreSalesMembers::create([
|
ProjectPreSalesMembers::create([
|
||||||
'project_id' => $params['project_id'],
|
'project_id' => $params['project_id'],
|
||||||
'technician_ids' => $params['technician_ids'],
|
'technician_ids' => trim($params['technician_ids'],','),
|
||||||
'business_people_ids' => $params['business_people_ids'],
|
'business_people_ids' => trim($params['business_people_ids'],','),
|
||||||
'cross_departmental_personnel_ids' => $params['cross_departmental_personnel_ids']
|
'cross_departmental_personnel_ids' => trim($params['cross_departmental_personnel_ids'],','),
|
||||||
|
'add_people' => $adminId
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -69,12 +72,11 @@ class ProjectPreSalesMembersLogic extends BaseLogic
|
|||||||
Db::startTrans();
|
Db::startTrans();
|
||||||
try {
|
try {
|
||||||
ProjectPreSalesMembers::where('id', $params['id'])->update([
|
ProjectPreSalesMembers::where('id', $params['id'])->update([
|
||||||
'project_id' => $params['project_id'],
|
'project_id' => $params['project_id'],
|
||||||
'technician_ids' => $params['technician_ids'],
|
'technician_ids' => trim($params['technician_ids'],','),
|
||||||
'business_people_ids' => $params['business_people_ids'],
|
'business_people_ids' => trim($params['business_people_ids'],','),
|
||||||
'cross_departmental_personnel_ids' => $params['cross_departmental_personnel_ids']
|
'cross_departmental_personnel_ids' => trim($params['cross_departmental_personnel_ids'],','),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Db::commit();
|
Db::commit();
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
@ -107,6 +109,20 @@ class ProjectPreSalesMembersLogic extends BaseLogic
|
|||||||
*/
|
*/
|
||||||
public static function detail($params): array
|
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;
|
namespace app\adminapi\validate\project;
|
||||||
|
|
||||||
|
|
||||||
|
use app\common\model\auth\Admin;
|
||||||
|
use app\common\model\project\Project;
|
||||||
use app\common\validate\BaseValidate;
|
use app\common\validate\BaseValidate;
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +34,18 @@ class ProjectPreSalesMembersValidate extends BaseValidate
|
|||||||
*/
|
*/
|
||||||
protected $rule = [
|
protected $rule = [
|
||||||
'id' => 'require',
|
'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()
|
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']);
|
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