$params['org_id'], 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'subpackage_budget_code' => data_unique_code('项目分包预算'), 'remark' => $params['remark'] ?? '', 'annex' => $params['annex']? json_encode($params['annex']) : null, ]); foreach ($detail as $item) { ProjectSubpackageBudgetDetail::create([ 'project_id' => $params['project_id'], 'subpackage_budget_id' => $res->id, 'work_type' => $item['work_type'], 'work_content' => $item['work_content'], 'project_features' => $item['project_features'] ?? '', 'unit' => $item['unit'], 'num' => $item['num'], 'price' => $item['price'], 'amount' => $item['num'] * $item['price'], 'remark' => $item['remark'] ?? '', ]); } //添加审批信息 addApprove( '项目分包预算', $res->id, 'app\common\model\project\ProjectSubpackageBudget', 'app\adminapi\logic\project\ProjectSubpackageBudgetLogic', $params['approve_detail']['flow_type'], $params['approve_detail']['flow_path'], $admin_id ); 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/01/10 15:19 */ public static function edit(array $params): bool { $detail =$params['subpackage_budget_detail'];//json_decode($params['subpackage_budget_detail'],true); Db::startTrans(); try { ProjectSubpackageBudget::where('id', $params['id'])->update([ 'org_id' => $params['org_id'], 'dept_id' => $params['dept_id'], 'project_id' => $params['project_id'], 'subpackage_budget_code' => data_unique_code('项目分包预算'), 'remark' => $params['remark'] ?? '', 'annex' => $params['annex']? json_encode($params['annex']) : null, ]); foreach ($detail as $item) { if(isset($item['id']) && $item['id'] != ''){ ProjectSubpackageBudgetDetail::where('id',$item['id'])->update([ 'project_id' => $params['project_id'], 'subpackage_budget_id' => $params['id'], 'work_type' => $item['work_type'], 'work_content' => $item['work_content'], 'project_features' => $item['project_features'] ?? '', 'unit' => $item['unit'], 'num' => $item['num'], 'price' => $item['price'], 'amount' => $item['num'] * $item['price'], 'remark' => $item['remark'] ?? '', ]); }else{ ProjectSubpackageBudgetDetail::create([ 'project_id' => $params['project_id'], 'subpackage_budget_id' => $params['id'], 'work_type' => $item['work_type'], 'work_content' => $item['work_content'], 'project_features' => $item['project_features'] ?? '', 'unit' => $item['unit'], 'num' => $item['num'], 'price' => $item['price'], 'amount' => $item['num'] * $item['price'], 'remark' => $item['remark'] ?? '', ]); } } 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/01/10 15:19 */ public static function delete(array $params): bool { return ProjectSubpackageBudget::destroy($params['id']); } /** * @notes 获取分包预算详情 * @param $params * @return array * @author likeadmin * @date 2024/01/10 15:19 */ public static function detail($params): array { $data = ProjectSubpackageBudget::field('id,org_id,dept_id,project_id,subpackage_budget_code,remark,annex')->findOrEmpty($params['id']); $org = Orgs::field('name')->where('id',$data['org_id'])->findOrEmpty(); $dept = Dept::field('name')->where('id',$data['dept_id'])->findOrEmpty(); $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $data['org_name'] = $org['name']; $data['dept_name'] = $dept['name']; $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; return $data->toArray(); } }