$params['approve_id'] ?? 0, 'years' => $params['years'] ?? '', 'document_preparation_time' => $params['document_preparation_time'] ?? '', 'total' => $params['total'] ?? 0, 'remark' => $params['remark'] ?? '', 'annex' => $params['annex'] ?? '', ]); foreach ($params['detail'] ?? [] as $item) { CostBudgetDetail::create([ 'cost_budget_id' => $costBudget->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 11:26 */ public static function edit(array $params): bool { Db::startTrans(); try { CostBudget::where('id', $params['id'])->update([ 'approve_id' => $params['approve_id'] ?? 0, 'years' => $params['years'] ?? '', 'document_preparation_time' => $params['document_preparation_time'] ?? '', 'total' => $params['total'] ?? 0, 'remark' => $params['remark'] ?? '', 'annex' => $params['annex'] ?? '', ]); CostBudgetDetail::where('cost_budget_id', $params['id'])->update(['delete_time' => time()]); foreach ($params['detail'] ?? [] as $item) { CostBudgetDetail::where('cost_budget_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 11:26 */ public static function delete(array $params): bool { return CostBudget::destroy($params['id']); } /** * @notes 获取详情 * @param $params * @return array * @author likeadmin * @date 2023/12/18 11:26 */ public static function detail($params): array { $costBudget = CostBudget::findOrEmpty($params['id']); $costBudget->detail; foreach ($costBudget->detail as &$item) { $item->subject; } $costBudget->org; $costBudget->dept; unset($item); return $costBudget->toArray(); } }