['contract_id', 'invoice_type'], '%like%' => ['invoice_code', 'apply_company'], ]; } /** * @notes 获取财务管理--开票台账列表 * @return array * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author likeadmin * @date 2024/03/25 14:09 */ public function lists(): array { return FinancialInvoice::where($this->searchWhere) ->field(['id', 'contract_id', 'invoice_code', 'invoice_type', 'apply_amount', 'apply_company']) ->limit($this->limitOffset, $this->limitLength) ->order(['id' => 'desc']) ->select()->each(function ($data) { $contract = MarketingContract::field('contract_name,contract_type,part_a,part_b,signed_amount,create_time')->where('id', $data['contract_id'])->findOrEmpty(); $custom = MarketingCustom::field('name')->where('id', $contract['part_a'])->findOrEmpty(); $admin = Admin::field('name')->where('id', $data['apply_contact'])->findOrEmpty(); $data['apply_contact_name'] = $admin?->name; $data['contract_name'] = $contract['contract_name']; $data['contract_type'] = !$contract->isEmpty() ? $contract->contract_type_text : ''; $data['part_a'] = $custom['name']; $data['part_b'] = $contract['part_b']; $data['sign_money'] = $contract['signed_amount']; $data['sign_time'] = $contract['create_time']; $data['invoice_type_text'] = $data->invoice_type_text; $data['refund_amount'] = FinancialRefund::where('invoice_id', $data['id'])->sum('amount') ?? 0.00; if ($data['refund_amount'] <= 0) { $data['is_refund'] = '未到账'; } elseif ($data['refund_amount'] < $data['apply_amount']) { $data['is_refund'] = '部分到账'; } else { $data['is_refund'] = '已到账'; } $last_refund = FinancialRefund::where('invoice_id', $data['id'])->order('id desc')->findOrEmpty(); $data['refund_date'] = $last_refund['create_time'] ?? ''; }) ->toArray(); } /** * @notes 获取财务管理--开票台账数量 * @return int * @author likeadmin * @date 2024/03/25 14:09 */ public function count(): int { return FinancialInvoice::where($this->searchWhere)->count(); } }