From b72b2e12bdb4fa7641e55dca7073024ae9d2e756 Mon Sep 17 00:00:00 2001
From: yueyang <2495544247@qq.com>
Date: Fri, 27 Nov 2026 14:42:41 +0800
Subject: [PATCH] =?UTF-8?q?feat(=E5=8F=91=E7=A5=A8=E6=95=B0=E6=8D=AE):=20?=
=?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=B5=81=E7=A8=8B=E7=9B=B4=E6=8A=93=E5=AE=8C?=
=?UTF-8?q?=E6=95=B4=E5=8F=91=E7=A5=A8=E5=AD=97=E6=AE=B5=20(#1505)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
发票明细按 OA 流程附件直抓口径展示完整字段,打款时间移到最后,并从 2026-10 开始统计。
---
.../Http/Controllers/InvoiceData.php | 29 ++-
.../DingInvoiceDataMirrorRepository.php | 16 +-
.../Services/DingInvoiceSyncService.php | 19 +-
.../View/InvoiceDataPageData.php | 5 +-
.../invoice-data.blade.php | 201 ++++++++++++------
.../Feature/Business/InvoiceDataPageTest.php | 112 +++++++++-
6 files changed, 299 insertions(+), 83 deletions(-)
diff --git a/modules/EcommerceFinance/Http/Controllers/InvoiceData.php b/modules/EcommerceFinance/Http/Controllers/InvoiceData.php
index 3adacf3c..52319d70 100644
--- a/modules/EcommerceFinance/Http/Controllers/InvoiceData.php
+++ b/modules/EcommerceFinance/Http/Controllers/InvoiceData.php
@@ -33,7 +33,6 @@ class InvoiceData extends Controller
'报销类型',
'费用类型',
'收款人',
- '打款时间',
'本月付款金额',
'付款合计',
'发票张数',
@@ -41,6 +40,7 @@ class InvoiceData extends Controller
'付款差额',
'扫描状态',
'扫描说明',
+ '打款时间',
]);
foreach ($this->repository->exportRows($filters) as $row) {
$payment = (float) ($row['payment_amount'] ?? 0);
@@ -52,7 +52,6 @@ class InvoiceData extends Controller
(string) ($row['document_type'] ?? ''),
(string) ($row['expense_type'] ?? ''),
(string) ($row['payee_name'] ?? ''),
- (string) ($row['paid_at'] ?? ''),
number_format($payment, 2, '.', ''),
number_format((float) ($row['payment_total'] ?? 0), 2, '.', ''),
(int) ($row['invoice_count'] ?? 0),
@@ -60,6 +59,7 @@ class InvoiceData extends Controller
number_format(round($payment - $invoice, 2), 2, '.', ''),
(string) ($row['scan_status'] ?? ''),
(string) ($row['last_error'] ?? ''),
+ (string) ($row['paid_at'] ?? ''),
]);
}
} else {
@@ -68,9 +68,8 @@ class InvoiceData extends Controller
'标题',
'提交人',
'报销类型',
+ '费用类型',
'收款人',
- '打款时间',
- '本月付款金额',
'发票类型',
'销售方名称',
'销售方税号',
@@ -83,8 +82,14 @@ class InvoiceData extends Controller
'金额',
'税率',
'税额',
- '付款差额',
+ '本月付款金额',
+ '付款合计',
+ '发票张数',
+ '金额校对',
+ '差异金额',
'附件名称',
+ '识别来源',
+ '打款时间',
]);
foreach ($this->repository->exportRows($filters) as $row) {
$payment = (float) ($row['payment_amount'] ?? 0);
@@ -94,9 +99,8 @@ class InvoiceData extends Controller
(string) ($row['title'] ?? ''),
(string) ($row['originator_name'] ?? ''),
(string) ($row['document_type'] ?? ''),
+ (string) ($row['expense_type'] ?? ''),
(string) ($row['payee_name'] ?? ''),
- (string) ($row['paid_at'] ?? ''),
- number_format($payment, 2, '.', ''),
(string) ($row['invoice_type'] ?? ''),
(string) ($row['seller_name'] ?? ''),
(string) ($row['seller_tax_no'] ?? ''),
@@ -113,8 +117,17 @@ class InvoiceData extends Controller
$row['tax_amount'] === null
? ''
: number_format((float) $row['tax_amount'], 2, '.', ''),
- number_format(round($payment - $invoice, 2), 2, '.', ''),
+ number_format($payment, 2, '.', ''),
+ number_format((float) ($row['payment_total'] ?? 0), 2, '.', ''),
+ (int) ($row['invoice_count'] ?? 0),
+ abs(round($payment - $invoice, 2)) <= 0.005 ? '一致' : '有差异',
+ number_format(round(
+ $payment - (float) ($row['flow_invoice_total'] ?? 0),
+ 2,
+ ), 2, '.', ''),
(string) ($row['source_file_name'] ?? ''),
+ (string) ($row['ocr_provider'] ?? ''),
+ (string) ($row['paid_at'] ?? ''),
]);
}
}
diff --git a/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php b/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php
index 7d54ccac..1ac17573 100644
--- a/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php
+++ b/modules/EcommerceFinance/Repositories/DingInvoiceDataMirrorRepository.php
@@ -11,6 +11,8 @@ use RuntimeException;
class DingInvoiceDataMirrorRepository
{
+ public const FIRST_SUPPORTED_MONTH = '2026-10';
+
public const PER_PAGE_OPTIONS = [50, 100, 200];
public const VIEW_DETAIL = 'detail';
@@ -86,6 +88,7 @@ class DingInvoiceDataMirrorRepository
->where('source_scope', $this->scope())
->whereNotNull('paid_month')
->where('paid_month', '!=', '')
+ ->where('paid_month', '>=', self::FIRST_SUPPORTED_MONTH)
->distinct()
->orderByDesc('paid_month')
->pluck('paid_month')
@@ -260,6 +263,7 @@ class DingInvoiceDataMirrorRepository
'r.buyer_name',
'r.buyer_tax_no',
'r.item_name',
+ 'r.invoice_date',
'f.title',
'f.originator_name',
'f.payee_name',
@@ -333,7 +337,13 @@ class DingInvoiceDataMirrorRepository
->whereColumn('rk.source_scope', 'f.source_scope')
->whereColumn('rk.business_id', 'f.business_id')
->where(function (Builder $invoiceSearch) use ($keyword): void {
- foreach (['invoice_number', 'seller_name', 'buyer_name', 'item_name'] as $column) {
+ foreach ([
+ 'invoice_number',
+ 'seller_name',
+ 'buyer_name',
+ 'item_name',
+ 'invoice_date',
+ ] as $column) {
$invoiceSearch->orWhere("rk.{$column}", 'like', $keyword);
}
});
@@ -410,6 +420,7 @@ class DingInvoiceDataMirrorRepository
'buyer_name',
'buyer_tax_no',
'item_name',
+ 'invoice_date',
] as $column) {
$invoiceSearch->orWhere(
'summary_invoice_search.' . $column,
@@ -435,6 +446,9 @@ class DingInvoiceDataMirrorRepository
return [
'flows' => $rows->count(),
+ 'invoice_flows' => $rows->filter(
+ static fn (object $row): bool => (int) $row->invoice_count > 0,
+ )->count(),
'payment_amount' => $payment,
'invoice_count' => (int) $rows->sum('invoice_count'),
'invoice_total' => $invoice,
diff --git a/modules/EcommerceFinance/Services/DingInvoiceSyncService.php b/modules/EcommerceFinance/Services/DingInvoiceSyncService.php
index 56fb0fdf..cbd5470d 100644
--- a/modules/EcommerceFinance/Services/DingInvoiceSyncService.php
+++ b/modules/EcommerceFinance/Services/DingInvoiceSyncService.php
@@ -11,6 +11,8 @@ use Throwable;
class DingInvoiceSyncService
{
+ private const DIRECT_SOURCE_NAME = 'OA attachment scan';
+
private ConnectionInterface $connection;
public function __construct(
@@ -56,7 +58,9 @@ class DingInvoiceSyncService
->where('process_instance_id', '!=', '')
->where(function ($query): void {
$query->whereIn('scan_status', ['pending', 'failed', 'partial'])
- ->orWhereNull('scanned_at');
+ ->orWhereNull('scanned_at')
+ ->orWhereNull('source_name')
+ ->orWhere('source_name', '!=', self::DIRECT_SOURCE_NAME);
});
$flows = $query
->orderByDesc('paid_at')
@@ -73,7 +77,9 @@ class DingInvoiceSyncService
->where('process_instance_id', '!=', '')
->where(function ($query): void {
$query->whereIn('scan_status', ['pending', 'failed', 'partial'])
- ->orWhereNull('scanned_at');
+ ->orWhereNull('scanned_at')
+ ->orWhereNull('source_name')
+ ->orWhere('source_name', '!=', self::DIRECT_SOURCE_NAME);
})
->count();
@@ -140,7 +146,9 @@ class DingInvoiceSyncService
->where('process_instance_id', '!=', '')
->where(function ($query): void {
$query->whereIn('scan_status', ['pending', 'failed', 'partial'])
- ->orWhereNull('scanned_at');
+ ->orWhereNull('scanned_at')
+ ->orWhereNull('source_name')
+ ->orWhere('source_name', '!=', self::DIRECT_SOURCE_NAME);
})
->count();
$this->updateState($metrics);
@@ -160,7 +168,9 @@ class DingInvoiceSyncService
->where('process_instance_id', '!=', '')
->where(function ($query): void {
$query->whereIn('scan_status', ['pending', 'failed', 'partial'])
- ->orWhereNull('scanned_at');
+ ->orWhereNull('scanned_at')
+ ->orWhereNull('source_name')
+ ->orWhere('source_name', '!=', self::DIRECT_SOURCE_NAME);
})
->max('paid_month');
@@ -675,6 +685,7 @@ class DingInvoiceSyncService
'attachment_count' => count($files),
'scanned_file_count' => $scannedFiles,
'last_error' => $error,
+ 'source_name' => self::DIRECT_SOURCE_NAME,
'scanned_at' => $now,
'updated_at' => $now,
]);
diff --git a/modules/EcommerceFinance/View/InvoiceDataPageData.php b/modules/EcommerceFinance/View/InvoiceDataPageData.php
index a6e1de8e..59e6560f 100644
--- a/modules/EcommerceFinance/View/InvoiceDataPageData.php
+++ b/modules/EcommerceFinance/View/InvoiceDataPageData.php
@@ -34,7 +34,7 @@ class InvoiceDataPageData
$months = [];
}
$requestedMonth = trim((string) $request->query('month', ''));
- $month = preg_match('/^\d{4}-\d{2}$/', $requestedMonth) === 1
+ $month = in_array($requestedMonth, $months, true)
? $requestedMonth
: (string) ($months[0] ?? '');
$view = $request->query('invoice_view') === DingInvoiceDataMirrorRepository::VIEW_FLOWS
@@ -104,6 +104,7 @@ class InvoiceDataPageData
'invoiceStates' => DingInvoiceDataMirrorRepository::INVOICE_STATES,
'invoicePerPageOptions' => DingInvoiceDataMirrorRepository::PER_PAGE_OPTIONS,
'invoicePerPage' => $perPage,
+ 'invoiceStartMonth' => DingInvoiceDataMirrorRepository::FIRST_SUPPORTED_MONTH,
'invoiceSummary' => $detailResult['summary'],
'invoiceMirrorStatus' => $mirrorStatus,
'invoiceMirrorSyncedAt' => $state['last_succeeded_at'] ?? null,
@@ -143,8 +144,10 @@ class InvoiceDataPageData
'invoiceStates' => DingInvoiceDataMirrorRepository::INVOICE_STATES,
'invoicePerPageOptions' => DingInvoiceDataMirrorRepository::PER_PAGE_OPTIONS,
'invoicePerPage' => $perPage,
+ 'invoiceStartMonth' => DingInvoiceDataMirrorRepository::FIRST_SUPPORTED_MONTH,
'invoiceSummary' => [
'flows' => 0,
+ 'invoice_flows' => 0,
'payment_amount' => 0.0,
'invoice_count' => 0,
'invoice_total' => 0.0,
diff --git a/resources/views/business/pages/financial-operations/invoice-data.blade.php b/resources/views/business/pages/financial-operations/invoice-data.blade.php
index 92140993..8586e334 100644
--- a/resources/views/business/pages/financial-operations/invoice-data.blade.php
+++ b/resources/views/business/pages/financial-operations/invoice-data.blade.php
@@ -6,8 +6,9 @@
$flowRows = $invoiceFlowRows ?? collect();
$filters = $invoiceFilters ?? [];
$activeView = $invoiceActiveView ?? 'detail';
+ $startMonth = $invoiceStartMonth ?? '2026-10';
$statusLabels = [
- 'imported' => '已导入',
+ 'imported' => '已扫描',
'recognized' => '已识别',
'no_invoice' => '无票',
'partial' => '部分识别',
@@ -18,8 +19,8 @@
'failed' => '同步失败',
'pending' => '待同步',
'running' => '同步中',
- 'imported' => '已导入',
- 'unavailable' => '未导入',
+ 'imported' => '数据就绪',
+ 'unavailable' => '暂无数据',
];
$filterQuery = array_filter($filters, static fn (mixed $value): bool => $value !== '' && $value !== null);
$detailTabUrl = $invoicePageUrl . '?' . http_build_query(array_merge($filterQuery, [
@@ -184,7 +185,7 @@
.invoice-data-kpis {
display: grid;
margin-top: 0.75rem;
- grid-template-columns: repeat(6, minmax(0, 1fr));
+ grid-template-columns: repeat(7, minmax(0, 1fr));
overflow: hidden;
border: 1px solid var(--invoice-border);
border-radius: 0.5rem;
@@ -277,7 +278,7 @@
.invoice-data-table {
width: 100%;
- min-width: 82rem;
+ min-width: 178rem;
border-collapse: collapse;
color: var(--invoice-ink);
font-size: 0.75rem;
@@ -285,7 +286,26 @@
}
.invoice-data-table.is-flow {
- min-width: 72rem;
+ min-width: 104rem;
+ }
+
+ .invoice-data-table.is-detail th:first-child,
+ .invoice-data-table.is-detail td:first-child {
+ position: sticky;
+ left: 0;
+ z-index: 1;
+ min-width: 13rem;
+ background: var(--invoice-surface);
+ box-shadow: 1px 0 0 var(--invoice-border);
+ }
+
+ .invoice-data-table.is-detail thead th:first-child {
+ z-index: 3;
+ background: var(--invoice-soft);
+ }
+
+ .invoice-data-table.is-detail tbody tr:hover td:first-child {
+ background: #fcfaf4;
}
.invoice-data-table th,
@@ -326,6 +346,16 @@
white-space: nowrap;
}
+ .invoice-data-table .is-preline {
+ min-width: 18rem;
+ white-space: pre-line;
+ }
+
+ .invoice-data-table .is-code {
+ font-family: "JetBrains Mono", monospace;
+ white-space: nowrap;
+ }
+
.invoice-data-primary {
display: block;
color: var(--invoice-ink);
@@ -459,14 +489,18 @@
@media (max-width: 1180px) {
.invoice-data-kpis {
- grid-template-columns: repeat(3, minmax(0, 1fr));
+ grid-template-columns: repeat(4, minmax(0, 1fr));
}
- .invoice-data-kpi:nth-child(3) {
+ .invoice-data-kpi:nth-child(4) {
border-right: 0;
}
- .invoice-data-kpi:nth-child(n + 4) {
+ .invoice-data-kpi:nth-child(7) {
+ border-right: 0;
+ }
+
+ .invoice-data-kpi:nth-child(n + 5) {
border-top: 1px solid var(--invoice-border);
}
}
@@ -581,7 +615,7 @@
data-ocr-configured="{{ $invoiceOcrConfigured ? 'true' : 'false' }}"
>
document_scanner
- 抓取发票
+ 从流程抓取发票
@@ -593,10 +627,10 @@
- 数据口径:按打款时间归属月份 · 一张发票一行 · 无票流程保留
+ 数据口径:{{ $startMonth }} 起 · 通过 OA 审批流程附件自动识别 · 按打款时间归属月份 · 一张发票一行
- 镜像状态:{{ $mirrorStatusLabels[$invoiceMirrorStatus] ?? $invoiceMirrorStatus }}
+ 扫描状态:{{ $mirrorStatusLabels[$invoiceMirrorStatus] ?? $invoiceMirrorStatus }}
@if ($invoiceMirrorSyncedAt)
· 最近成功 {{ $invoiceMirrorSyncedAt }}
@endif
@@ -611,8 +645,8 @@
{{ number_format((int) ($summary['flows'] ?? 0)) }}
- 本月付款金额
- ¥{{ $wan($summary['payment_amount'] ?? 0) }} 万
+ 含票流程
+ {{ number_format((int) ($summary['invoice_flows'] ?? 0)) }}
发票张数
@@ -622,6 +656,10 @@
发票价税合计
¥{{ $wan($summary['invoice_total'] ?? 0) }} 万
+
+ 本月付款金额
+ ¥{{ $wan($summary['payment_amount'] ?? 0) }} 万
+
无票流程
{{ number_format((int) ($summary['no_invoice_flows'] ?? 0)) }}
@@ -667,52 +705,77 @@
@if ($activeView !== 'detail') hidden @endif
>