['project_id','contract_type', 'contract_code'], '%like%' => ['contract_code'] ]; } /** * @notes 获取项目合同列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2023/12/02 17:19 */ public function lists(): array { $params = $this->request->get(['project_name','business_director_name','custom_id']); $where = []; if(isset($params['project_name']) && $params['project_name'] != ''){ $project_ids = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $where[] = ['project_id','in',$project_ids]; } if(isset($params['business_director_name']) && $params['business_director_name'] != ''){ $business_director_ids = Admin::where('name','like','%'.$params['business_director_name'].'%')->column('id'); $where[] = ['business_director','in',$business_director_ids]; } if(isset($params['custom_id']) && $params['custom_id'] != ''){ $project_ids = Project::where('custom_id','=',$params['custom_id'])->column('id'); $where[] = ['project_id','in',$project_ids]; } return Contract::where($this->searchWhere)->where($where) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function($data){ $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['negotiation_amount'] = ContractNegotiation::where('contract_id',$data['id'])->sum('negotiation_amount'); //回款金额 $data['returned_amount'] = FinanceReturnedRecord::where('contract_id',$data['id'])->sum('amount'); //开票金额 $data['invoicing_amount'] = FinanceInvoiceApply::where('contract_id',$data['id'])->sum('invoicing_amount'); //退款金额 $data['refund_amount'] = FinanceRefundApply::where('contract_id',$data['id'])->sum('amount'); //实际合同金额=合同金额+洽商金额-退款金额 $data['reality_contract_amount'] = $data['amount'] + $data['negotiation_amount'] - $data['refund_amount']; //未回款金额 $data['not_returned_amount'] = $data['reality_contract_amount'] - $data['returned_amount']; //未开票金额 $data['not_invoicing_amount'] = $data['reality_contract_amount'] - $data['invoicing_amount']; //结算差异(带计算) $data['settlement_difference'] = 0; return $data; }) ->toArray(); } /** * @notes 获取项目合同数量 * @return int * @author likeadmin * @date 2023/12/02 17:19 */ public function count(): int { $params = $this->request->get(['project_name','business_director_name','custom_id']); $where = []; if(isset($params['project_name']) && $params['project_name'] != ''){ $project_ids = Project::where('name','like','%'.$params['project_name'].'%')->column('id'); $where[] = ['project_id','in',$project_ids]; } if(isset($params['business_director_name']) && $params['business_director_name'] != ''){ $business_director_ids = Admin::where('name','like','%'.$params['business_director_name'].'%')->column('id'); $where[] = ['business_director','in',$business_director_ids]; } if(isset($params['custom_id']) && $params['custom_id'] != ''){ $project_ids = Project::where('custom_id','=',$params['custom_id'])->column('id'); $where[] = ['project_id','in',$project_ids]; } return Contract::field('id')->where($this->searchWhere)->where($where)->count(); } }