engineering/app/adminapi/logic/project/ProjectWbsSetLogic.php
2023-12-13 17:03:28 +08:00

146 lines
4.9 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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\project\ProjectRoleSet;
use app\common\model\project\ProjectTypeSet;
use app\common\model\project\ProjectWbsSet;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 项目WBS设置逻辑
* Class ProjectWbsSetLogic
* @package app\adminapi\logic\project
*/
class ProjectWbsSetLogic extends BaseLogic
{
/**
* @notes 添加项目WBS设置
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/13 15:09
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$pid = 0;
if(isset($params['sup_wbs_code']) && $params['sup_wbs_code'] != ''){
$supData = ProjectWbsSet::where('wbs_code',$params['sup_wbs_code'])->findOrEmpty();
$pid = !$supData->isEmpty() ? $supData['id'] : 0;
}
ProjectWbsSet::create([
'project_type_id' => $params['project_type_id'],
'pid' => $pid,
'wbs_code' => $params['wbs_code'],
'name' => $params['name'],
'work_standards' => $params['work_standards'],
'project_role_id' => $params['project_role_id'],
'output_data' => $params['output_data'],
'sort' => $params['sort'],
'weight' => $params['weight']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑项目WBS设置
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/13 15:09
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
$pid = 0;
if(isset($params['sup_wbs_code']) && $params['sup_wbs_code'] != ''){
$supData = ProjectWbsSet::where('wbs_code',$params['sup_wbs_code'])->findOrEmpty();
$pid = !$supData->isEmpty() ? $supData['id'] : 0;
}
ProjectWbsSet::where('id', $params['id'])->update([
'project_type_id' => $params['project_type_id'],
'pid' => $pid,
'wbs_code' => $params['wbs_code'],
'name' => $params['name'],
'work_standards' => $params['work_standards'],
'project_role_id' => $params['project_role_id'],
'output_data' => $params['output_data'],
'sort' => $params['sort'],
'weight' => $params['weight']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除项目WBS设置
* @param array $params
* @return bool
* @author likeadmin
* @date 2023/12/13 15:09
*/
public static function delete(array $params): bool
{
$data = ProjectWbsSet::where('pid',$params['id'])->findOrEmpty();
if(!$data->isEmpty()){
self::setError('当前节点存在子节点,不能删除');
return false;
}
return ProjectWbsSet::destroy($params['id']);
}
/**
* @notes 获取项目WBS设置详情
* @param $params
* @return array
* @author likeadmin
* @date 2023/12/13 15:09
*/
public static function detail($params): array
{
$data = ProjectWbsSet::field('id,project_type_id,pid,wbs_code,name,work_standards,project_role_id,output_data,sort,weight')->findOrEmpty($params['id'])->toArray();
$projectType = ProjectTypeSet::field('id,name')->where('id',$data['project_type_id'])->findOrEmpty();
$projectRole = ProjectRoleSet::field('id,name')->where('id',$data['project_role_id'])->findOrEmpty();
$projectWbs = ProjectWbsSet::field('wbs_code')->where('id',$data['pid'])->findOrEmpty();
$data['project_type_name'] = $projectType->isEmpty() ? '' : $projectType->name;
$data['project_role_name'] = $projectRole->isEmpty() ? '' : $projectRole->name;
$data['sup_wbs_code']= $projectWbs->isEmpty() ? '' : $projectWbs->wbs_code;
return $data;
}
}