From a7bb3514b7bea00bdce25bd6b31053e21ff116fd Mon Sep 17 00:00:00 2001 From: shanshi <3316401569@qq.com> Date: Thu, 3 Dec 2026 14:47:07 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=B1=95=E7=A4=BA=E8=B4=A6=E6=88=B7?= =?UTF-8?q?=E6=9C=88=E5=BA=A6=E6=9C=9F=E5=88=9D=E5=B9=B6=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=9C=9F=E5=88=9D=E9=94=81=E5=AE=9A=20(#1694)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../LockFinanceLedgerMonthlyOpening.php | 2 +- deploy/activate-incremental-release.sh | 2 + deploy/activate-release.sh | 2 + .../View/NonStoreAccountMonitorPageData.php | 13 +++++ .../non-store-accounts.blade.php | 53 +++++++++++++++++-- .../platform-account-detail.blade.php | 7 ++- .../Business/NonStoreAccountMonitorTest.php | 45 +++++++++++++++- .../Deployment/BusinessMirrorScheduleTest.php | 6 +++ .../LockFinanceLedgerMonthlyOpeningTest.php | 28 ++++++++++ 9 files changed, 150 insertions(+), 8 deletions(-) diff --git a/app/Console/Commands/LockFinanceLedgerMonthlyOpening.php b/app/Console/Commands/LockFinanceLedgerMonthlyOpening.php index c418d399c..dd2f78784 100644 --- a/app/Console/Commands/LockFinanceLedgerMonthlyOpening.php +++ b/app/Console/Commands/LockFinanceLedgerMonthlyOpening.php @@ -117,7 +117,7 @@ class LockFinanceLedgerMonthlyOpening extends Command ->orderBy('balance_date') ->orderBy('balance_at') ->orderBy('id') - ->get(['account_no', 'account_balance', 'available_balance']) as $row) { + ->get(['account_no', 'balance_date', 'account_balance', 'available_balance']) as $row) { $accountNo = $this->accountNo($row->account_no); if ($accountNo !== '') { $snapshotBefore[$accountNo] = $row; diff --git a/deploy/activate-incremental-release.sh b/deploy/activate-incremental-release.sh index 6be7d2e0f..e2831f367 100644 --- a/deploy/activate-incremental-release.sh +++ b/deploy/activate-incremental-release.sh @@ -253,6 +253,8 @@ CRON_TZ=Asia/Shanghai 30 2 * * * root /usr/bin/flock -w 1800 /run/caiwu-upstream-sync.lock /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:sync-rpt --days=7 --merge --sources=store,withdrawal --quiet >/dev/null 2>&1 5 * * * * root /usr/bin/flock -w 600 /run/caiwu-upstream-sync.lock /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:sync-rpt --days=2 --merge --sources=dingtalk,payable --quiet >/dev/null 2>&1 30 10 * * * root /usr/bin/flock -w 1800 /run/caiwu-upstream-sync.lock /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:sync-shop-data --balance-only --quiet >/dev/null 2>&1 +# 每月 1 日按上月末最后一笔真实余额锁定月度期初,供账户总览和月度资金分析直接读取。 +20 8 1 * * root /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:lock-monthly-opening --apply --quiet >/dev/null 2>&1 # 拼多多期初:账单导入后即时尝试,每日 11:30 再扫一次未就绪店铺;只在余额恒等式通过后写入。 30 11 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh pinduoduo-opening-balances:import --quiet >/dev/null 2>&1 # 财务流程明细每周完整校准一次,修正超过 48 小时重叠窗口才出现的上游改单或晚到付款。 diff --git a/deploy/activate-release.sh b/deploy/activate-release.sh index 70c3dd9ba..d2a051983 100644 --- a/deploy/activate-release.sh +++ b/deploy/activate-release.sh @@ -257,6 +257,8 @@ CRON_TZ=Asia/Shanghai 30 2 * * * root /usr/bin/flock -w 1800 /run/caiwu-upstream-sync.lock /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:sync-rpt --days=7 --merge --sources=store,withdrawal --quiet >/dev/null 2>&1 5 * * * * root /usr/bin/flock -w 600 /run/caiwu-upstream-sync.lock /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:sync-rpt --days=2 --merge --sources=dingtalk,payable --quiet >/dev/null 2>&1 30 10 * * * root /usr/bin/flock -w 1800 /run/caiwu-upstream-sync.lock /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:sync-shop-data --balance-only --quiet >/dev/null 2>&1 +# 每月 1 日按上月末最后一笔真实余额锁定月度期初,供账户总览和月度资金分析直接读取。 +20 8 1 * * root /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:lock-monthly-opening --apply --quiet >/dev/null 2>&1 # 拼多多期初:账单导入后即时尝试,每日 11:30 再扫一次未就绪店铺;只在余额恒等式通过后写入。 30 11 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh pinduoduo-opening-balances:import --quiet >/dev/null 2>&1 # 财务流程明细每周完整校准一次,修正超过 48 小时重叠窗口才出现的上游改单或晚到付款。 diff --git a/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php b/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php index 1582f7ac6..4f6e8e66f 100644 --- a/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php +++ b/modules/EcommerceFinance/View/NonStoreAccountMonitorPageData.php @@ -125,6 +125,9 @@ final class NonStoreAccountMonitorPageData $unretainedProgress = $this->progressSummary($unretained); $fundOverview = [ 'total_accounts' => $retainedSummary['count'], + 'opening_balance' => $retainedSummary['opening_balance'], + 'opening_accounts' => $retainedSummary['opening_accounts'], + 'opening_missing_accounts' => $retainedSummary['opening_missing_accounts'], 'current_balance' => $retainedSummary['current_balance'], 'available_balance' => $retainedSummary['available_balance'], 'blocked_balance' => $retainedSummary['blocked_balance'], @@ -888,8 +891,18 @@ final class NonStoreAccountMonitorPageData private function summary(Collection $rows): array { + $openingRows = $rows->filter( + static fn (array $row): bool => array_key_exists('opening_balance', $row) + && $row['opening_balance'] !== null, + ); + return [ 'count' => $rows->count(), + 'opening_balance' => $openingRows->isEmpty() + ? null + : round((float) $openingRows->sum('opening_balance'), 2), + 'opening_accounts' => $openingRows->count(), + 'opening_missing_accounts' => max(0, $rows->count() - $openingRows->count()), 'current_balance' => round((float) $rows->sum('current_balance'), 2), 'available_balance' => round((float) $rows->sum('available_balance'), 2), 'blocked_balance' => round((float) $rows->sum('blocked_balance'), 2), diff --git a/resources/views/business/pages/financial-operations/non-store-accounts.blade.php b/resources/views/business/pages/financial-operations/non-store-accounts.blade.php index 86370e48b..02112c026 100644 --- a/resources/views/business/pages/financial-operations/non-store-accounts.blade.php +++ b/resources/views/business/pages/financial-operations/non-store-accounts.blade.php @@ -3,6 +3,9 @@ ? '—' : number_format((float) $value, 2); $moneyWan = static fn ($value): string => number_format((float) $value / 10000, 2, '.', ','); + $moneyWanOptional = static fn ($value): string => $value === null || $value === '' + ? '—' + : $moneyWan($value); $currentUrl = $currentUrl ?? route('business.pages.show', [ 'section' => 'financial-operations', 'page' => 'non-store-accounts', @@ -185,7 +188,7 @@ .nsm-fund-overview__grid { display: grid; - grid-template-columns: repeat(4, minmax(0, 1fr)); + grid-template-columns: repeat(5, minmax(0, 1fr)); } .nsm-fund-kpi { @@ -224,6 +227,14 @@ color: var(--nsm-warning); } + .nsm-table-note { + display: block; + margin-top: .25rem; + color: var(--nsm-muted); + font-size: .625rem; + font-weight: 400; + } + .nsm-distribution-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); @@ -1775,6 +1786,10 @@ .nsm-fund-kpi:nth-child(4) { border-top: 1px solid #eeeae2; } + .nsm-fund-kpi:nth-child(5) { + border-left: 0; + border-top: 1px solid #eeeae2; + } .nsm-page-head { align-items: flex-start; flex-direction: column; @@ -1803,7 +1818,8 @@ } .nsm-fund-kpi + .nsm-fund-kpi, .nsm-fund-kpi:nth-child(3), - .nsm-fund-kpi:nth-child(4) { + .nsm-fund-kpi:nth-child(4), + .nsm-fund-kpi:nth-child(5) { border-top: 1px solid #eeeae2; border-left: 0; } @@ -1823,6 +1839,9 @@ data-open-retained-on-load="{{ request()->boolean('retained') ? '1' : '0' }}" data-retained-period-from="{{ $period['from'] }}" data-retained-period-to="{{ $period['to'] }}" + data-retained-period-opening="{{ $fundOverview['opening_balance'] === null ? '' : (float) $fundOverview['opening_balance'] }}" + data-retained-period-opening-accounts="{{ (int) $fundOverview['opening_accounts'] }}" + data-retained-period-opening-missing="{{ (int) $fundOverview['opening_missing_accounts'] }}" data-retained-period-total="{{ (float) $fundOverview['current_balance'] }}" data-retained-period-available="{{ (float) $fundOverview['available_balance'] }}" data-retained-period-blocked="{{ (float) $fundOverview['blocked_balance'] }}" @@ -1948,6 +1967,14 @@ {{ number_format((int) $fundOverview['total_accounts']) }} 个账户 · 金额单位:万元
+
+ 期初余额 + {{ $moneyWanOptional($fundOverview['opening_balance']) }} + + {{ number_format((int) $fundOverview['opening_accounts']) }} / + {{ number_format((int) $fundOverview['total_accounts']) }} 户已锁定月度期初 + +
期末总余额 {{ $moneyWan($fundOverview['current_balance']) }} @@ -1984,6 +2011,7 @@ 账户平台 账户数 + 期初余额 期末余额 可用金额 不可用金额 @@ -2022,6 +2050,14 @@ @endif + + {{ $moneyWanOptional($distribution['opening_balance']) }} + @if ($distribution['opening_balance'] !== null) 万 @endif + + {{ number_format((int) $distribution['opening_accounts']) }} / + {{ number_format((int) $distribution['count']) }} 户 + + {{ $moneyWan($distribution['current_balance']) }} 万 {{ $moneyWan($distribution['available_balance']) }} 万 {{ $moneyWan($distribution['blocked_balance']) }} 万 @@ -2046,6 +2082,14 @@ data-account-archive-open >{{ number_format((int) $fundOverview['total_accounts']) }} + + {{ $moneyWanOptional($fundOverview['opening_balance']) }} + @if ($fundOverview['opening_balance'] !== null) 万 @endif + + {{ number_format((int) $fundOverview['opening_accounts']) }} / + {{ number_format((int) $fundOverview['total_accounts']) }} 户 + + {{ $moneyWan($fundOverview['current_balance']) }} 万 {{ $moneyWan($fundOverview['available_balance']) }} 万 {{ $moneyWan($fundOverview['blocked_balance']) }} 万 @@ -2422,7 +2466,7 @@
@include('business.pages.financial-operations.partials.detail-column-settings', [ - 'storageKey' => 'caiwu.non-store-accounts.detail.bank-inline.columns.v2', + 'storageKey' => 'caiwu.non-store-accounts.detail.bank-inline.columns.v3', 'columns' => [ '公共信息' => [ ['key' => 'company_name', 'label' => '公司名称'], @@ -2436,6 +2480,7 @@ ['key' => 'account_no', 'label' => '登录账号/账号'], ], '资金信息' => [ + ['key' => 'opening_balance', 'label' => '期初余额'], ['key' => 'current_balance', 'label' => '期末余额'], ['key' => 'available_balance', 'label' => '可用金额'], ['key' => 'blocked_balance', 'label' => '不可用金额'], @@ -2463,6 +2508,7 @@ 连接方式 账户状态 登录账号/账号 + 期初余额 期末余额 可用金额 不可用金额 @@ -2484,6 +2530,7 @@ {{ $account['is_direct'] ? '银企直连' : '非银企直连' }} {{ $account['account_status_label'] ?: '—' }} {{ in_array($account['account_no'], ['', '/'], true) ? '—' : $account['account_no'] }} + {{ $money($account['opening_balance'] ?? null) }} @php $inlineBillUrl = $bankBillInlineUrl($account); diff --git a/resources/views/business/pages/financial-operations/partials/platform-account-detail.blade.php b/resources/views/business/pages/financial-operations/partials/platform-account-detail.blade.php index 9fc5d71e6..51761aec8 100644 --- a/resources/views/business/pages/financial-operations/partials/platform-account-detail.blade.php +++ b/resources/views/business/pages/financial-operations/partials/platform-account-detail.blade.php @@ -19,6 +19,7 @@ ['key' => 'account_no', 'label' => '登录账号/账号'], ], '资金信息' => [ + ['key' => 'opening_balance', 'label' => '期初余额'], ['key' => 'current_balance', 'label' => '当前余额'], ['key' => 'available_balance', 'label' => '可用金额'], ['key' => 'blocked_balance', 'label' => '不可用金额'], @@ -39,7 +40,7 @@ {{ $description }}
@include('business.pages.financial-operations.partials.detail-column-settings', [ - 'storageKey' => 'caiwu.non-store-accounts.detail.' . $detailId . '.columns.v2', + 'storageKey' => 'caiwu.non-store-accounts.detail.' . $detailId . '.columns.v3', 'columns' => $detailColumns, ]) @@ -53,6 +54,7 @@ 所属银行/平台 账户状态 登录账号/账号 + 期初余额 当前余额 可用金额 不可用金额 @@ -94,6 +96,7 @@ {{ $account['platform_label'] ?: '其他账户' }} {{ $account['account_status_label'] ?: '—' }} {{ in_array($account['account_no'], ['', '/'], true) ? '—' : $account['account_no'] }} + {{ $money($account['opening_balance'] ?? null) }} {{ number_format((float) $account['current_balance'], 2) }} {{ number_format((float) $account['available_balance'], 2) }} {{ number_format((float) $account['blocked_balance'], 2) }} @@ -101,7 +104,7 @@ @empty - {{ $emptyMessage }} + {{ $emptyMessage }} @endforelse diff --git a/tests/Feature/Business/NonStoreAccountMonitorTest.php b/tests/Feature/Business/NonStoreAccountMonitorTest.php index ed80f2b63..19d18468d 100644 --- a/tests/Feature/Business/NonStoreAccountMonitorTest.php +++ b/tests/Feature/Business/NonStoreAccountMonitorTest.php @@ -161,13 +161,15 @@ class NonStoreAccountMonitorTest extends FeatureTestCase $this->assertGreaterThanOrEqual(8, substr_count($html, 'data-detail-column-picker-toggle')); $this->assertStringContainsString('data-detail-column-table', $html); $this->assertStringContainsString( - 'caiwu.non-store-accounts.detail.bank-inline.columns.v2', + 'caiwu.non-store-accounts.detail.bank-inline.columns.v3', $html, ); $this->assertStringContainsString( - 'caiwu.non-store-accounts.detail.nsm-alipay-drilldown.columns.v2', + 'caiwu.non-store-accounts.detail.nsm-alipay-drilldown.columns.v3', $html, ); + $this->assertStringContainsString('data-detail-column="opening_balance"', $html); + $this->assertStringContainsString('value="opening_balance"', $html); $this->assertStringContainsString('data-detail-column="current_balance"', $html); $this->assertStringContainsString('data-detail-column="balance_updated_at">余额更新时间', $html); $this->assertStringContainsString('const initializeDetailColumnPickers', $html); @@ -211,6 +213,45 @@ class NonStoreAccountMonitorTest extends FeatureTestCase $this->assertStringContainsString('保留账户数', $html); } + public function test_monthly_opening_is_visible_in_summary_and_bank_details(): void + { + $connection = DB::connection('business_mirror'); + $connection->table('fin_account_opening')->insert([ + [ + 'account_short' => '保留直连工行', + 'opening_date' => '2026-11-01', + 'opening_balance' => 90000, + ], + [ + 'account_short' => '保留手动支付宝', + 'opening_date' => '2026-11-01', + 'opening_balance' => 50000, + ], + ]); + + $response = $this->loginAs()->get($this->pageUrl([ + 'retained' => 1, + 'period_from' => '2026-11-01', + 'period_to' => '2026-11-30', + ]))->assertOk(); + $page = app(NonStoreAccountMonitorPageData::class)->page(); + $fundOverview = $page['fundOverview']; + $bankAccount = collect($fundOverview['bank_accounts']) + ->firstWhere('account_short', '保留直连工行'); + + $this->assertSame(140000.0, $fundOverview['opening_balance']); + $this->assertSame(2, $fundOverview['opening_accounts']); + $this->assertSame(0, $fundOverview['opening_missing_accounts']); + $this->assertNotNull($bankAccount); + $this->assertSame(90000.0, $bankAccount['opening_balance']); + + $response->assertSee('data-retained-period-opening="140000"', false); + $response->assertSee('data-retained-period-opening-accounts="2"', false); + $response->assertSee('data-retained-period-opening-missing="0"', false); + $response->assertSee('data-detail-column="opening_balance">期初余额', false); + $response->assertSee('>90,000.00', false); + } + public function test_retained_dialog_amounts_follow_the_selected_period(): void { DB::connection('business_mirror')->table('fin_flow_summary_account_sources') diff --git a/tests/Unit/Deployment/BusinessMirrorScheduleTest.php b/tests/Unit/Deployment/BusinessMirrorScheduleTest.php index e460d49a9..c0a2199fc 100644 --- a/tests/Unit/Deployment/BusinessMirrorScheduleTest.php +++ b/tests/Unit/Deployment/BusinessMirrorScheduleTest.php @@ -155,6 +155,12 @@ class BusinessMirrorScheduleTest extends TestCase $contents, $script, ); + $this->assertStringContainsString( + '20 8 1 * * root /usr/bin/docker exec -u www-data caiwu_app php artisan finance-ledger:lock-monthly-opening --apply --quiet >/dev/null 2>&1', + $contents, + $script, + ); + $this->assertSame(1, substr_count($contents, 'finance-ledger:lock-monthly-opening'), $script); $this->assertStringContainsString( '30 11 * * * root /bin/sh /opt/caiwuxitong/run-finance-batch.sh pinduoduo-opening-balances:import --quiet', $contents, diff --git a/tests/Unit/EcommerceFinance/LockFinanceLedgerMonthlyOpeningTest.php b/tests/Unit/EcommerceFinance/LockFinanceLedgerMonthlyOpeningTest.php index 1d04ce437..dd7af35e6 100644 --- a/tests/Unit/EcommerceFinance/LockFinanceLedgerMonthlyOpeningTest.php +++ b/tests/Unit/EcommerceFinance/LockFinanceLedgerMonthlyOpeningTest.php @@ -172,6 +172,34 @@ class LockFinanceLedgerMonthlyOpeningTest extends TestCase ], 'business_mirror'); } + public function test_it_uses_a_bank_direct_balance_snapshot_as_the_basis(): void + { + $db = DB::connection('business_mirror'); + $db->table('fin_accounts')->insert([ + 'account_short' => '快照余额账户', + 'account_no' => '6200000000000005', + ]); + $db->table('fin_bank_direct_balance_snapshots')->insert([ + 'account_no' => '6200000000000005', + 'balance_date' => '2026-10-31', + 'balance_at' => '2026-10-31 18:00:00', + 'account_balance' => 765.43, + 'available_balance' => 700, + ]); + + $this->artisan('finance-ledger:lock-monthly-opening', [ + 'date' => '2026-11-01', + '--apply' => true, + ])->assertSuccessful(); + + $this->assertDatabaseHas('fin_account_opening', [ + 'account_short' => '快照余额账户', + 'opening_date' => '2026-11-01', + 'opening_balance' => 765.43, + 'remark' => '系统锁定:2026-10-31 最后一笔实际余额', + ], 'business_mirror'); + } + public function test_it_does_not_carry_forward_past_unpriced_transactions(): void { $db = DB::connection('business_mirror');