$params['approve_id'], 'years' => $params['years'], 'document_preparation_time' => $params['document_preparation_time'], 'remark' => $params['remark'], 'annex' => $params['annex'], ]); foreach ($params['detail'] ?? [] as $item) { CostBudgetAdjustDetail::create([ 'cost_budget_adjust_id' => $costBudgetAdjust->id, 'cost_subject_id' => $item['cost_subject_id'] ?? 0, 'dept_id' => $item['dept_id'] ?? 0, 'month1' => $item['month1'] ?? 0, 'month2' => $item['month2'] ?? 0, 'month3' => $item['month3'] ?? 0, 'month4' => $item['month4'] ?? 0, 'month5' => $item['month5'] ?? 0, 'month6' => $item['month6'] ?? 0, 'month7' => $item['month7'] ?? 0, 'month8' => $item['month8'] ?? 0, 'month9' => $item['month9'] ?? 0, 'month10' => $item['month10'] ?? 0, 'month11' => $item['month11'] ?? 0, 'month12' => $item['month12'] ?? 0 ]); } 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/18 15:17 */ public static function edit(array $params): bool { Db::startTrans(); try { CostBudgetAdjust::where('id', $params['id'])->update([ 'approve_id' => $params['approve_id'], 'years' => $params['years'], 'document_preparation_time' => $params['document_preparation_time'], 'remark' => $params['remark'], 'annex' => $params['annex'], ]); CostBudgetAdjustDetail::where('cost_budget_adjust_id', $params['id'])->update(['delete_time' => time()]); foreach ($params['detail'] ?? [] as $item) { CostBudgetAdjustDetail::where('cost_budget_adjust_id', $params['id'])->update([ 'cost_subject_id' => $item['cost_subject_id'] ?? 0, 'dept_id' => $item['dept_id'] ?? 0, 'month1' => $item['month1'] ?? 0, 'month2' => $item['month2'] ?? 0, 'month3' => $item['month3'] ?? 0, 'month4' => $item['month4'] ?? 0, 'month5' => $item['month5'] ?? 0, 'month6' => $item['month6'] ?? 0, 'month7' => $item['month7'] ?? 0, 'month8' => $item['month8'] ?? 0, 'month9' => $item['month9'] ?? 0, 'month10' => $item['month10'] ?? 0, 'month11' => $item['month11'] ?? 0, 'month12' => $item['month12'] ?? 0 ]); } 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/18 15:17 */ public static function delete(array $params): bool { CostBudgetAdjustDetail::where('cost_budget_adjust_id', $params['id'])->update(['delete_time' => time()]); return CostBudgetAdjust::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2023/12/18 15:17 */ public static function detail($params): array { $costBudgetAdjust = CostBudgetAdjust::findOrEmpty($params['id']); $costBudgetAdjust->detail; foreach ($costBudgetAdjust->detail as &$item) { $item->subject; } $costBudgetAdjust->org; $costBudgetAdjust->dept; return $costBudgetAdjust->toArray(); } }