request->get(['page_no','page_size']); $pageNo = empty($params['page_no']) ? 1 : $params['page_no']; $pageSize = empty($params['page_size']) ? 15 : $params['page_size']; $where = []; $data = Contract::field('id,project_id,contract_code,contract_name,contract_date,amount')->where($where) ->page($pageNo,$pageSize) ->order(['id' => 'desc']) ->select()->each(function($item){ $project = Project::field('custom_id,name,project_code')->where('id',$item['project_id'])->findOrEmpty(); $custom = Custom::field('name')->where('id',$project['custom_id'])->findOrEmpty(); $item['project_name'] = $project['name']; $item['project_code'] = $project['project_code']; $item['custom_name'] = $custom['name']; //合同洽商金额 $negotiate_amount = ContractNegotiation::where('contract_id',$item['id'])->sum('negotiation_amount'); //合同实际金额 $item['contract_amount'] = $item['amount'] + $negotiate_amount; //已回款金额 $item['has_refund_amount'] = FinanceReturnedRecord::where('contract_id',$item['id'])->sum('amount'); //已开票金额 $item['has_invoice_amount'] = FinanceInvoiceApply::where('contract_id',$item['id'])->sum('invoicing_amount'); //开票未回款 $item['has_invoice_not_refund_amount'] = ($item['has_invoice_amount'] - $item['has_refund_amount']) <= 0 ? 0 : $item['has_invoice_amount'] - $item['has_refund_amount']; //回款未开票 $item['has_refund_not_invoice_amount'] = ($item['has_refund_amount'] - $item['has_invoice_amount']) <= 0 ? 0 : $item['has_refund_amount'] - $item['has_invoice_amount']; unset($item['amount']); return $item; })->toArray(); halt($data); } }