141 lines
5.1 KiB
PHP
141 lines
5.1 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\contract\Contract;
|
||
use app\common\model\custom\Custom;
|
||
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): bool
|
||
{
|
||
Db::startTrans();
|
||
try {
|
||
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']? json_encode($params['annex']) : null,
|
||
]);
|
||
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' => strtotime($params['project_approval_date']),
|
||
'start_date' => strtotime($params['start_date']),
|
||
'delivery_date' => strtotime($params['delivery_date']),
|
||
'remark' => $params['remark'],
|
||
'annex' => $params['annex']? json_encode($params['annex']) : null,
|
||
]);
|
||
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;
|
||
}
|
||
} |