where('id',$params['buy_bidding_document_id'])->findOrEmpty(); $returned_money = $params['returned_money'];//json_decode($params['returned_money'],true); Db::startTrans(); try { $contractRes = Contract::create([ "org_id" => $params['org_id'], "dept_id" =>$params['dept_id'], "project_id" => $buy_bidding_document['project_id'], "buy_bidding_document_id" => $params['buy_bidding_document_id'], "contract_name" =>$params['contract_name'], 'contract_code' => data_unique_code('PHT'), "contract_type" => $params['contract_type'], "contract_pricing_method" => $params['contract_pricing_method'], "party_a" => $params['party_a'], "party_a_contact_address" => $params['party_a_contact_address'] ?? '', "party_a_diretor" => $params['party_a_diretor'] ?? '', "party_a_phone" => $params['party_a_phone'] ?? '', "party_a_mobile" => $params['party_a_mobile'] ?? '', "party_a_email" => $params['party_a_email'] ?? '', "party_b" => $params['party_b'], "party_b_contact_address" => $params['party_b_contact_address'] ?? '', "party_b_diretor" => $params['party_b_diretor'] ?? '', "party_b_phone" => $params['party_b_phone'] ?? '', "party_b_mobile" => $params['party_b_mobile'] ?? '', "party_b_email" => $params['party_b_email'] ?? '', "amount" => $params['amount'], "business_director" => $params['business_director'], "contract_status" => $params['contract_status'], "expire" => strtotime($params['expire']), "contract_date" => strtotime($params['contract_date']), "main_content" => $params['main_content'] ?? '', "remark" => $params['remark'] ?? '', 'annex' => $params['annex']? json_encode($params['annex']) : null, ]); foreach ($returned_money as $item) { FinanceReturnedMoney::create([ 'project_id' => $buy_bidding_document['project_id'], 'contract_id' => $contractRes->id, 'return_date' => strtotime($item['return_date']), 'period' => $item['period'], 'amount' => $item['amount'], 'return_status' => 2, 'return_duty_id' => 0, 'remark' => $item['remark'] ?? '', 'annex' => null, ]); } Project::where('id',$buy_bidding_document['project_id'])->update([ 'status' => 3, '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/02 17:19 */ public static function edit(array $params): bool { $buy_bidding_document = BidBuyBiddingDocument::field('project_id')->where('id',$params['buy_bidding_document_id'])->findOrEmpty(); $returned_money = $params['returned_money']; Db::startTrans(); try { Contract::where('id', $params['id'])->update([ "org_id" => $params['org_id'], "dept_id" =>$params['dept_id'], "project_id" => $buy_bidding_document['project_id'], "buy_bidding_document_id" => $params['buy_bidding_document_id'], "contract_name" =>$params['contract_name'], "contract_type" => $params['contract_type'], "contract_pricing_method" => $params['contract_pricing_method'], "party_a" => $params['party_a'], "party_a_contact_address" => $params['party_a_contact_address'] ?? '', "party_a_diretor" => $params['party_a_diretor'] ?? '', "party_a_phone" => $params['party_a_phone'] ?? '', "party_a_mobile" => $params['party_a_mobile'] ?? '', "party_a_email" => $params['party_a_email'] ?? '', "party_b" => $params['party_b'], "party_b_contact_address" => $params['party_b_contact_address'] ?? '', "party_b_diretor" => $params['party_b_diretor'] ?? '', "party_b_phone" => $params['party_b_phone'] ?? '', "party_b_mobile" => $params['party_b_mobile'] ?? '', "party_b_email" => $params['party_b_email'] ?? '', "amount" => $params['amount'], "business_director" => $params['business_director'], "contract_status" => $params['contract_status'], "expire" => strtotime($params['expire']), "contract_date" => strtotime($params['contract_date']), "main_content" => $params['main_content'] ?? '', "remark" => $params['remark'] ?? '', 'annex' => $params['annex']? json_encode($params['annex']) : null, ]); foreach ($returned_money as $item) { if(isset($item['id']) && $item['id'] != ''){ FinanceReturnedMoney::where('id',$item['id'])->update([ 'project_id' => $buy_bidding_document['project_id'], 'contract_id' => $params['id'], 'return_date' => strtotime($item['return_date']), 'period' => $item['period'], 'amount' => $item['amount'], 'return_status' => 2, 'return_duty_id' => 0, 'remark' => $item['remark'] ?? '', 'annex' => null, ]); }else{ FinanceReturnedMoney::create([ 'project_id' => $buy_bidding_document['project_id'], 'contract_id' => $params['id'], 'return_date' => strtotime($item['return_date']), 'period' => $item['period'], 'amount' => $item['amount'], 'return_status' => 2, 'return_duty_id' => 0, 'remark' => $item['remark'] ?? '', 'annex' => null, ]); } } 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/02 17:19 */ public static function delete(array $params): bool { return Contract::destroy($params['id']); } /** * @notes 获取项目合同详情 * @param $params * @return array * @author likeadmin * @date 2023/12/02 17:19 */ public static function detail($params): array { $data = Contract::findOrEmpty($params['id']); $project = Project::field('custom_id,name,project_code')->where('id',$data['project_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); $buy_bidding_document = BidBuyBiddingDocument::field('bid_document_no')->where('id',$data['buy_bidding_document_id'])->findOrEmpty(); $business_director = Admin::field('name')->where('id',$data['business_director'])->findOrEmpty(); $data['custom_name'] = $custom['name']; $data['bid_document_no'] = $buy_bidding_document['bid_document_no']; $data['project_name'] = $project['name']; $data['project_code'] = $project['project_code']; $data['contract_type_text'] = $data->contract_type_text; $data['contract_pricing_method_text'] = $data->contract_pricing_method_text; $data['contract_status_text'] = $data->contract_status_text; $data['contract_pricing_method_text'] = $data->contract_pricing_method_text; $data['business_director_name'] = $business_director['name']; $data['returned_amount'] = FinanceReturnedRecord::where('contract_id',$data['id'])->sum('amount'); return $data->toArray(); } }