新增项目经理委任模块

This commit is contained in:
weiz 2023-12-18 10:42:33 +08:00
parent d25a0057e7
commit 78d92a176e
8 changed files with 715 additions and 0 deletions

View File

@ -0,0 +1,108 @@
<?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\controller\project;
use app\adminapi\controller\BaseAdminController;
use app\adminapi\lists\project\ProjectManagerAppointmentLists;
use app\adminapi\logic\project\ProjectManagerAppointmentLogic;
use app\adminapi\validate\project\ProjectManagerAppointmentValidate;
/**
* 项目经理委任控制器
* Class ProjectManagerAppointmentController
* @package app\adminapi\controller\project
*/
class ProjectManagerAppointmentController extends BaseAdminController
{
/**
* @notes 获取项目经理委任列表
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function lists()
{
return $this->dataLists(new ProjectManagerAppointmentLists());
}
/**
* @notes 添加项目经理委任
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function add()
{
$params = (new ProjectManagerAppointmentValidate())->post()->goCheck('add');
$result = ProjectManagerAppointmentLogic::add($params,$this->adminId);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ProjectManagerAppointmentLogic::getError());
}
/**
* @notes 编辑项目经理委任
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function edit()
{
$params = (new ProjectManagerAppointmentValidate())->post()->goCheck('edit');
$result = ProjectManagerAppointmentLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ProjectManagerAppointmentLogic::getError());
}
/**
* @notes 删除项目经理委任
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function delete()
{
$params = (new ProjectManagerAppointmentValidate())->post()->goCheck('delete');
ProjectManagerAppointmentLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取项目经理委任详情
* @return \think\response\Json
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function detail()
{
$params = (new ProjectManagerAppointmentValidate())->goCheck('detail');
$result = ProjectManagerAppointmentLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,100 @@
<?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\lists\project;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\auth\Admin;
use app\common\model\contract\Contract;
use app\common\model\custom\Custom;
use app\common\model\dict\DictData;
use app\common\model\process_approval\ProcessApproval;
use app\common\model\project\Project;
use app\common\model\project\ProjectManagerAppointment;
use app\common\lists\ListsSearchInterface;
use app\common\model\project\ProjectTypeSet;
/**
* 项目经理委任列表
* Class ProjectManagerAppointmentLists
* @package app\adminapi\listsproject
*/
class ProjectManagerAppointmentLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function setSearch(): array
{
return [
'=' => ['project_approval_date', 'start_date', 'delivery_date'],
];
}
/**
* @notes 获取项目经理委任列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function lists(): array
{
return ProjectManagerAppointment::where($this->searchWhere)
->field(['id', 'project_id', 'contract_id', 'project_type_id', 'project_manager', 'amount', 'project_approval_date', 'start_date', 'delivery_date'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()->each(function($item){
$process = ProcessApproval::field('process_code,submit_step')->where('model','ProjectManagerAppointment')->where('data_id',$item['id'])->findOrEmpty();
$step = DictData::where('type_value','project_manager_entrusted_approval_process')->column('name','value');
$project = Project::field('name,project_code,custom_id')->where('id',$item['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$contract = Contract::field('contract_code')->where('id',$item['contract_id'])->findOrEmpty();
$projectType = ProjectTypeSet::field('name')->where('id',$item['project_type_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$item['project_manager'])->findOrEmpty();
$item['process_code'] = $process['process_code'];
$item['process_step'] = $step[$process['submit_step']];
$item['project_name'] = $project['name'];
$item['project_code'] = $project['project_code'];
$item['custom_name'] = $custom['name'];
$item['contract_code'] = $contract['contract_code'];
$item['project_type_name'] = $projectType['name'];
$item['project_manager_name'] = $admin['name'];
})
->toArray();
}
/**
* @notes 获取项目经理委任数量
* @return int
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function count(): int
{
return ProjectManagerAppointment::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,163 @@
<?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\contract\Contract;
use app\common\model\custom\Custom;
use app\common\model\process_approval\ProcessApproval;
use app\common\model\process_approval\ProcessApprovalLogs;
use app\common\model\project\Project;
use app\common\model\project\ProjectManagerAppointment;
use app\common\logic\BaseLogic;
use app\common\model\project\ProjectTypeSet;
use think\facade\Db;
/**
* 项目经理委任逻辑
* Class ProjectManagerAppointmentLogic
* @package app\adminapi\logic\project
*/
class ProjectManagerAppointmentLogic extends BaseLogic
{
/**
* @notes 添加项目经理委任
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/15 15:22
*/
public static function add(array $params,$adminId): bool
{
Db::startTrans();
try {
$process_approval_data = json_decode($params['process_approval'],true);
$projectRes = ProjectManagerAppointment::create([
'org_id' => $params['org_id'],
'dept_id' => $params['dept_id'],
'project_id' => $params['project_id'],
'contract_id' => $params['contract_id'],
'project_type_id' => $params['project_type_id'],
'project_manager' => $params['project_manager'],
'amount' => $params['amount'],
'project_approval_date' => strtotime($params['project_approval_date']),
'start_date' => strtotime($params['start_date']),
'delivery_date' => strtotime($params['delivery_date']),
'remark' => $params['remark'],
'annex' => $params['annex'],
]);
$processRes = ProcessApproval::create([
'process_code' => process_code('项目经理委任'),
'current_step' => $process_approval_data['current_step'],
'action' => $process_approval_data['action'],
'submit_step' => $process_approval_data['submit_step'],
'check_user' => $process_approval_data['check_user'],
'check_opinions' => $process_approval_data['check_opinions'] ?? '',
'copy_user' => $process_approval_data['copy_user'] ?? '',
'promoter' => $adminId,
'schedule' => 0,
'model' => 'ProjectManagerAppointment',
'data_id' => $projectRes->id,
]);
ProcessApprovalLogs::create([
'process_id' => $processRes->id,
'step' => $process_approval_data['current_step'],
'action' => $process_approval_data['action'],
'create_time' => time()
]);
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/12/15 15:22
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ProjectManagerAppointment::where('id', $params['id'])->update([
'project_id' => $params['project_id'],
'contract_id' => $params['contract_id'],
'project_type_id' => $params['project_type_id'],
'project_manager' => $params['project_manager'],
'amount' => $params['amount'],
'project_approval_date' => $params['project_approval_date'],
'start_date' => $params['start_date'],
'delivery_date' => $params['delivery_date'],
'remark' => $params['remark'],
'annex' => $params['annex'],
]);
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/12/15 15:22
*/
public static function delete(array $params): bool
{
return ProjectManagerAppointment::destroy($params['id']);
}
/**
* @notes 获取项目经理委任详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/15 15:22
*/
public static function detail($params): array
{
$data = ProjectManagerAppointment::field('id,project_id,contract_id,project_type_id,project_manager,amount,project_approval_date,start_date,delivery_date,remark,annex')->findOrEmpty($params['id'])->toArray();
$project = Project::field('name,project_code,custom_id')->where('id',$data['project_id'])->findOrEmpty();
$custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty();
$contract = Contract::field('contract_code')->where('id',$data['contract_id'])->findOrEmpty();
$projectType = ProjectTypeSet::field('name')->where('id',$data['project_type_id'])->findOrEmpty();
$admin = Admin::field('name')->where('id',$data['project_manager'])->findOrEmpty();
$data['project_name'] = $project['name'];
$data['project_code'] = $project['project_code'];
$data['custom_name'] = $custom['name'];
$data['contract_code'] = $contract['contract_code'];
$data['project_type_name'] = $projectType['name'];
$data['project_manager_name'] = $admin['name'];
return $data;
}
}

View File

@ -0,0 +1,260 @@
<?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\validate\project;
use app\common\model\auth\Admin;
use app\common\model\contract\Contract;
use app\common\model\dept\Dept;
use app\common\model\dept\Orgs;
use app\common\model\dict\DictData;
use app\common\model\project\Project;
use app\common\model\project\ProjectManagerAppointment;
use app\common\model\project\ProjectTypeSet;
use app\common\validate\BaseValidate;
/**
* 项目经理委任验证器
* Class ProjectManagerAppointmentValidate
* @package app\adminapi\validate\project
*/
class ProjectManagerAppointmentValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require|checkData',
'org_id' => 'require|checkOrg',
'dept_id' => 'require|checkDept',
'project_id' => 'require|checkProject',
'contract_id' => 'require|checkContract',
'project_type_id' => 'require|checkProjectType',
'project_manager' => 'require|checkUser',
'amount' => 'require|float|egt:0',
'project_approval_date' => 'require|date',
'start_date' => 'require|date',
'delivery_date' => 'require|date',
'process_approval' => 'require|checkProcessApproval'
];
protected $message = [
'id.require' => '缺少必要参数',
'org_id.require' => '请选择组织',
'dept_id.require' => '请选择部门',
'project_id.require' => '请选择项目',
'contract_id.require' => '请选择合同',
'project_type_id.require' => '请选择项目类型',
'project_manager.require' => '请选择项目经理',
'amount.require' => '请填写项目金额',
'amount.float' => '项目金额必须是数字',
'amount.egt' => '项目金额必须大于等于0',
'project_approval_date.require' => '请选择立项日期',
'project_approval_date.date' => '立项日期格式错误',
'start_date.require' => '请选择项目开始日期',
'start_date.date' => '项目开始日期格式错误',
'delivery_date.require' => '请选择项目交付日期',
'delivery_date.date' => '项目交付日期格式错误',
'process_approval.require' => '请填写流程审批信息'
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
'project_id' => '项目id',
'contract_id' => '合同id',
'org_id' => '组织id',
'dept_id' => '部门id',
'project_type_id' => '项目类型',
'project_manager' => '项目经理',
'amount' => '项目金额',
'project_approval_date' => '立项日期',
'start_date' => '项目开始日期',
'delivery_date' => '项目交付日期',
];
/**
* @notes 添加场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneAdd()
{
return $this->remove('id',true);
}
/**
* @notes 编辑场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneEdit()
{
return $this->only(['id','project_id','contract_id','project_type_id','project_manager','amount','project_approval_date','start_date','delivery_date']);;
}
/**
* @notes 删除场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ProjectManagerAppointmentValidate
* @author likeadmin
* @date 2023/12/15 15:22
*/
public function sceneDetail()
{
return $this->only(['id']);
}
public function checkData($value): bool|string
{
$data = ProjectManagerAppointment::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '数据不存在';
}
return true;
}
public function checkOrg($value): bool|string
{
$data = Orgs::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '组织不存在';
}
return true;
}
public function checkDept($value,$rule,$data): bool|string
{
$dept = Dept::where('id',$value)->findOrEmpty();
if($dept->isEmpty()){
return '部门不存在';
}
if($data['org_id'] != $dept['org_id']){
return '部门不属于当前选择的组织';
}
return true;
}
public function checkProject($value): bool|string
{
$data = Project::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目不存在';
}
return true;
}
public function checkContract($value): bool|string
{
$data = Contract::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '合同不存在';
}
return true;
}
public function checkProjectType($value): bool|string
{
$data = ProjectTypeSet::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '项目类型不存在';
}
return true;
}
public function checkUser($value): bool|string
{
$data = Admin::where('id',$value)->findOrEmpty();
if($data->isEmpty()){
return '用户不存在';
}
return true;
}
public function checkProcessApproval($value): bool|string
{
$param = json_decode($value,true);
if(empty($param)){
return '流程审批信息错误';
}
if(empty($param['current_step'])){
return '请选择当前步骤';
}else{
$curr_steps = DictData::where('type_value','project_manager_entrusted_approval_process')->column('value');
if(!in_array($param['current_step'],$curr_steps)){
return '当前步骤无效';
}
}
if(empty($param['action'])){
return '请选择处理动作';
}else{
$action = DictData::where('type_value','approval_process_action')->column('value');
if(!in_array($param['action'],$action)){
return '处理动作无效';
}
}
if(empty($param['submit_step'])){
return '请选择送审步骤';
}else{
$submit_steps = DictData::where('type_value','project_manager_entrusted_approval_process')->column('value');
if(!in_array($param['submit_step'],$submit_steps)){
return '送审步骤无效';
}
}
if(empty($param['check_user'])){
return '请指定处理人';
}else{
$data = Admin::where('id',$param['check_user'])->findOrEmpty();
if($data->isEmpty()){
return '处理人不存在';
}
}
if(isset($param['copy_user']) || $param['copy_user'] != ''){
$copy_user_ids = explode(',',$param['copy_user']);
foreach ($copy_user_ids as $v) {
$data = Admin::where('id',$v)->findOrEmpty();
if($data->isEmpty()){
return '抄送人不存在';
}
}
}
return true;
}
}

View File

@ -327,3 +327,9 @@ function buildTree($items, $parentField, $parentId = 0): array
}
return $tree;
}
function process_code($str): string
{
//质量检查单-20231215-0001
return $str.'-'.date('Ymd',time()).'-'.mt_rand(100000, 999999);
}

View File

@ -0,0 +1,13 @@
<?php
namespace app\common\model\process_approval;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
class ProcessApproval extends BaseModel
{
use SoftDelete;
protected $name = 'process_approval';
protected $deleteTime = 'delete_time';
}

View File

@ -0,0 +1,13 @@
<?php
namespace app\common\model\process_approval;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
class ProcessApprovalLogs extends BaseModel
{
use SoftDelete;
protected $name = 'process_approval_logs';
protected $deleteTime = 'delete_time';
}

View File

@ -0,0 +1,52 @@
<?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\common\model\project;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 项目经理委任模型
* Class ProjectManagerAppointment
* @package app\common\model\project
*/
class ProjectManagerAppointment extends BaseModel
{
use SoftDelete;
protected $name = 'project_manager_appointment';
protected $deleteTime = 'delete_time';
public function getProjectApprovalDateAttr($value)
{
return date('Y-m-d',$value);
}
public function getStartDateAttr($value)
{
return date('Y-m-d',$value);
}
public function getDeliveryDateAttr($value)
{
return date('Y-m-d',$value);
}
public function getannexAttr($value)
{
return json_decode($value,true);
}
}