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(); } }