data_unique_code('分包结算'), 'project_id' => $params['project_id'], 'contract_id' => $params['contract_id'], 'settlement_amount' => $params['settlement_amount'], 'settlement_date' => strtotime($params['settlement_date']), 'remark' => $params['remark'], 'annex' => $params['annex']? json_encode($params['annex']) : null, 'add_user' => $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 2023/12/29 13:59 */ public static function edit(array $params): bool { Db::startTrans(); try { ProjectSubcontractSettlement::where('id', $params['id'])->update([ 'project_id' => $params['project_id'], 'contract_id' => $params['contract_id'], 'settlement_amount' => $params['settlement_amount'], 'settlement_date' => strtotime($params['settlement_date']), 'remark' => $params['remark'], 'annex' => $params['annex']? json_encode($params['annex']) : null, 'add_user' => $params['add_user'], 'update_time' => time(), ]); 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/29 13:59 */ public static function delete(array $params): bool { return ProjectSubcontractSettlement::destroy($params['id']); } /** * @notes 获取分包结算详情 * @param $params * @return array * @author likeadmin * @date 2023/12/29 13:59 */ public static function detail($params): array { $data = ProjectSubcontractSettlement::field('id,settlement_code,project_id,contract_id,settlement_amount,settlement_date,remark,annex,approve_id')->findOrEmpty($params['id'])->toArray(); $project = Project::field('name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $contract = SubcontractingContract::field('supplier_id,contract_no,contract_name')->where('id',$data['contract_id'])->findOrEmpty(); $supplier = Supplier::field('supplier_code,supplier_name')->where('id',$contract['supplier_id'])->findOrEmpty(); $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; $data['contract_name'] = $contract['contract_name']; $data['contract_code'] = $contract['contract_no']; $data['supplier_name'] = $supplier['supplier_name']; $data['supplier_code'] = $supplier['supplier_code']; //合同金额 $data['contract_amount'] = SubcontractingContractDetail::where('contract_id',$data['contract_id'])->sum('amount_including_tax'); //合同洽商金额 $data['negotiation_amount'] = SubcontractingContractNegotiation::where('contract_id',$data['contract_id'])->sum('negotiation_amount'); //结算差异 $data['settlement_difference'] = bcsub(($data['contract_amount']+$data['negotiation_amount']),$data['settlement_amount']); $approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty(); $data['approve_check_status'] = $approve_data['check_status']; return $data; } public static function approve($params,$admin_id): bool{ $data = ProjectSubcontractSettlement::where('id',$params['id'])->findOrEmpty(); $approve_data = FlowApprove::where('id',$data['approve_id'])->findOrEmpty(); if(!empty($data['approve_id']) && $approve_data['check_status'] != 3){ self::setError('当前内容存在审核信息,请勿重复提交'); return false; } Db::startTrans(); try { $res = addApprove( '分包结算', $params['id'], 'app\common\model\project\ProjectSubcontractSettlement', $params['path'], $params['flow_id'], $admin_id ); if($res){ ProjectSubcontractSettlement::where('id',$params['id'])->update([ 'approve_id' => $res, ]); } Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } }