136 lines
4.2 KiB
PHP
136 lines
4.2 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\task;
|
||
|
||
|
||
use app\adminapi\logic\TaskDetailLogic;
|
||
use app\common\model\task\TaskAllocation;
|
||
use app\common\logic\BaseLogic;
|
||
use app\common\model\task\TaskType;
|
||
use think\facade\Db;
|
||
|
||
|
||
/**
|
||
* TaskAllocation逻辑
|
||
* Class TaskAllocationLogic
|
||
* @package app\adminapi\logic\task
|
||
*/
|
||
class TaskAllocationLogic extends BaseLogic
|
||
{
|
||
|
||
|
||
/**
|
||
* @notes 添加
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/02/22 10:47
|
||
*/
|
||
public static function add(array $params): bool
|
||
{
|
||
// 项目id关联任务类别
|
||
$projectId = $params['project_id'];
|
||
// 任务
|
||
$taskType = TaskType::where('cost_project_id', $projectId)->findOrEmpty();
|
||
if ($taskType->isEmpty()) {
|
||
self::setError('项目未配置任务类别');
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
// 任务分配
|
||
$taskAllocation = TaskAllocation::create([
|
||
'dataid' => generate_sn(TaskAllocation::class, 'dataid'),
|
||
'num' => generate_sn(TaskAllocation::class, 'num'),
|
||
'task_type_id' => $taskType['id'], // 任务类别id
|
||
'cost_project_id' => $taskType['cost_project_id'], // 项目id
|
||
'apptime' => $params['apptime'],
|
||
'annex' => $params['annex'],
|
||
]);
|
||
// 任务明细
|
||
$taskDetail = $params['task_detail'];
|
||
foreach ($taskDetail as $item) {
|
||
$item['task_allocation_id'] = $taskAllocation->id;
|
||
$item['task_type_id'] = $taskType['id'];
|
||
TaskDetailLogic::add($item);
|
||
}
|
||
Db::commit();
|
||
return true;
|
||
} catch (\Exception $e) {
|
||
Db::rollback();
|
||
self::setError($e->getMessage());
|
||
return false;
|
||
}
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 编辑
|
||
* @param array $params
|
||
* @return bool
|
||
* @author likeadmin
|
||
* @date 2024/02/22 10:47
|
||
*/
|
||
public static function edit(array $params): bool
|
||
{
|
||
// 项目id关联任务类别
|
||
$projectId = $params['project_id'];
|
||
// 任务
|
||
$taskType = TaskType::where('cost_project_id', $projectId)->findOrEmpty();
|
||
if ($taskType->isEmpty()) {
|
||
self::setError('项目未配置任务类别');
|
||
}
|
||
Db::startTrans();
|
||
try {
|
||
TaskAllocation::where('id', $params['id'])->update([
|
||
'task_type_id' => $taskType['id'], // 任务类别id
|
||
'cost_project_id' => $taskType['cost_project_id'], // 项目id
|
||
'apptime' => $params['apptime'],
|
||
'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 2024/02/22 10:47
|
||
*/
|
||
public static function delete(array $params): bool
|
||
{
|
||
return TaskAllocation::destroy($params['id']);
|
||
}
|
||
|
||
|
||
/**
|
||
* @notes 获取详情
|
||
* @param $params
|
||
* @return array
|
||
* @author likeadmin
|
||
* @date 2024/02/22 10:47
|
||
*/
|
||
public static function detail($params): array
|
||
{
|
||
return TaskAllocation::findOrEmpty($params['id'])->with(['taskTypeInfo', 'projectInfo'])->toArray();
|
||
}
|
||
} |