128 lines
4.5 KiB
PHP
128 lines
4.5 KiB
PHP
<?php
|
||
// +----------------------------------------------------------------------
|
||
// | likeadmin快速开发前后端分离管理后台(PHP版)
|
||
// +----------------------------------------------------------------------
|
||
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
|
||
// | 开源版本可自由商用,可去除界面版权logo
|
||
// | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
|
||
// | github下载:https://github.com/likeshop-github/likeadmin
|
||
// | 访问官网:https://www.likeadmin.cn
|
||
// | likeadmin团队 版权所有 拥有最终解释权
|
||
// +----------------------------------------------------------------------
|
||
// | author: likeadminTeam
|
||
// +----------------------------------------------------------------------
|
||
|
||
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;
|
||
|
||
|
||
/**
|
||
* ProjectPreSalesMembers逻辑
|
||
* Class ProjectPreSalesMembersLogic
|
||
* @package app\adminapi\logic\project
|
||
*/
|
||
class ProjectPreSalesMembersLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/11/14 10:15
|
||
*/
|
||
public static function add(array $params,$adminId = 0): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectPreSalesMembers::create([
|
||
'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'],','),
|
||
'add_people' => $adminId
|
||
]);
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/11/14 10:15
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
ProjectPreSalesMembers::where('id', $params['id'])->update([
|
||
'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) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 删除
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2023/11/14 10:15
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return ProjectPreSalesMembers::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2023/11/14 10:15
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
$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;
|
||
}
|
||
} |