diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 7b2bcdb5..f9505b87 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -957,54 +957,44 @@ class Pages extends Controller $repository = app(JdWalletBillRepository::class); $cache = $this->upstreamCaches->forSource('jiansun'); $scopePrefix = 'jd-wallet-bills.' . $ledger; + $errors = []; + $remember = function (string $scope, array $parameters, callable $resolver, mixed $fallback) use ($cache, &$errors): mixed { + try { + return $cache->remember($scope, $parameters, $resolver); + } catch (ServiceUnavailableHttpException $exception) { + $errors[] = $exception->getMessage(); + } catch (Throwable $exception) { + report($exception); + $errors[] = '京东账单数据暂时无法读取,请稍后重试。'; + } - try { - $result = $cache->remember( - $scopePrefix . '.list', - ['filters' => $filters, 'page' => $page, 'limit' => $pageSize], - fn () => $ledger === 'consumption' - ? $repository->paginateConsumption($filters['store_name'], $filters['from'], $filters['to'], $page, $pageSize) - : $repository->paginateRecharge($filters['store_name'], $filters['from'], $filters['to'], $page, $pageSize), - ); - $summary = $cache->remember( - $scopePrefix . '.summary', - ['filters' => $filters], - fn () => $ledger === 'consumption' - ? $repository->summaryConsumption($filters['store_name'], $filters['from'], $filters['to']) - : $repository->summaryRecharge($filters['store_name'], $filters['from'], $filters['to']), - ); - $shopOptions = $cache->remember( - 'jd-wallet-bills.options', - [], - fn () => $repository->shopOptions(), - ); - } catch (ServiceUnavailableHttpException $exception) { - return [ - 'view' => 'banking.marketing_jd_wallet_bills.partials.embedded-table', - 'ledger' => $ledger, - 'bills' => new LengthAwarePaginator([], 0, $pageSize, $page, [ - 'path' => $request->url(), 'query' => $request->query(), - ]), - 'filters' => $filters, - 'summary' => ['amount_total' => 0, 'balance_total' => 0, 'count' => 0], - 'shopOptions' => [], - 'error' => $exception->getMessage(), - ]; - } catch (Throwable $exception) { - report($exception); + return $fallback; + }; - return [ - 'view' => 'banking.marketing_jd_wallet_bills.partials.embedded-table', - 'ledger' => $ledger, - 'bills' => new LengthAwarePaginator([], 0, $pageSize, $page, [ - 'path' => $request->url(), 'query' => $request->query(), - ]), - 'filters' => $filters, - 'summary' => ['amount_total' => 0, 'balance_total' => 0, 'count' => 0], - 'shopOptions' => [], - 'error' => '京东账单数据暂时无法读取,请稍后重试。', - ]; - } + // 三项分别读取,确保生产冷启动时一次请求就能登记列表、汇总和选项, + // 同时保留已经命中的共享快照,不因另一项暂缺而清空整页。 + $result = $remember( + $scopePrefix . '.list', + ['filters' => $filters, 'page' => $page, 'limit' => $pageSize], + fn () => $ledger === 'consumption' + ? $repository->paginateConsumption($filters['store_name'], $filters['from'], $filters['to'], $page, $pageSize) + : $repository->paginateRecharge($filters['store_name'], $filters['from'], $filters['to'], $page, $pageSize), + ['rows' => [], 'total' => 0], + ); + $summary = $remember( + $scopePrefix . '.summary', + ['filters' => $filters], + fn () => $ledger === 'consumption' + ? $repository->summaryConsumption($filters['store_name'], $filters['from'], $filters['to']) + : $repository->summaryRecharge($filters['store_name'], $filters['from'], $filters['to']), + ['amount_total' => 0, 'balance_total' => 0, 'count' => 0], + ); + $shopOptions = $remember( + 'jd-wallet-bills.options', + [], + fn () => $repository->shopOptions(), + [], + ); return [ 'view' => 'banking.marketing_jd_wallet_bills.partials.embedded-table', @@ -1019,7 +1009,9 @@ class Pages extends Controller 'filters' => $filters, 'summary' => $summary, 'shopOptions' => $shopOptions, - 'error' => null, + 'error' => $errors === [] + ? null + : implode(' ', array_values(array_unique(array_filter($errors)))), ]; } diff --git a/modules/EcommerceFinance/Repositories/JdWalletBillRepository.php b/modules/EcommerceFinance/Repositories/JdWalletBillRepository.php index bef1757c..77d9f126 100644 --- a/modules/EcommerceFinance/Repositories/JdWalletBillRepository.php +++ b/modules/EcommerceFinance/Repositories/JdWalletBillRepository.php @@ -144,8 +144,8 @@ class JdWalletBillRepository $bindings[] = $fromDate . ' 00:00:00'; } if ($toDate !== null && preg_match('/^\d{4}-\d{2}-\d{2}$/', $toDate) === 1) { - $conditions[] = $dateField . ' <= ?'; - $bindings[] = $toDate . ' 23:59:59'; + $conditions[] = $dateField . ' < DATEADD(day, 1, CAST(? AS date))'; + $bindings[] = $toDate; } return ['sql' => $conditions === [] ? '' : ' WHERE ' . implode(' AND ', $conditions), 'bindings' => $bindings]; diff --git a/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php b/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php index 1c09a17f..3a9f8a28 100644 --- a/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php +++ b/modules/EcommerceFinance/Services/JianSunSnapshotRefresher.php @@ -33,7 +33,7 @@ class JianSunSnapshotRefresher implements UpstreamSnapshotRefresher private readonly TmallTaobaoSpreadBillRepository $taobaoAlipay, private readonly SupplierPayableRepository $supplier, private readonly SupplierPayableReportRepository $supplierPayableReports, - private readonly ?JdWalletBillRepository $jdWallet = null, + private readonly JdWalletBillRepository $jdWallet, ) { } @@ -114,31 +114,31 @@ class JianSunSnapshotRefresher implements UpstreamSnapshotRefresher ), 'pinduoduo-bills.options' => $this->pinduoduo->storeOptions(), - 'jd-wallet-bills.recharge.list' => $this->jdWallet?->paginateRecharge( + 'jd-wallet-bills.recharge.list' => $this->jdWallet->paginateRecharge( $storeName, $fromDate, $toDate, $page, $limit, ), - 'jd-wallet-bills.recharge.summary' => $this->jdWallet?->summaryRecharge( + 'jd-wallet-bills.recharge.summary' => $this->jdWallet->summaryRecharge( $storeName, $fromDate, $toDate, ), - 'jd-wallet-bills.consumption.list' => $this->jdWallet?->paginateConsumption( + 'jd-wallet-bills.consumption.list' => $this->jdWallet->paginateConsumption( $storeName, $fromDate, $toDate, $page, $limit, ), - 'jd-wallet-bills.consumption.summary' => $this->jdWallet?->summaryConsumption( + 'jd-wallet-bills.consumption.summary' => $this->jdWallet->summaryConsumption( $storeName, $fromDate, $toDate, ), - 'jd-wallet-bills.options' => $this->jdWallet?->shopOptions(), + 'jd-wallet-bills.options' => $this->jdWallet->shopOptions(), 'taobao-alipay-bills.list' => $this->taobaoAlipay->paginate( $storeName, diff --git a/resources/assets/js/views/business/marketing-account-bills.js b/resources/assets/js/views/business/marketing-account-bills.js new file mode 100644 index 00000000..8a301b5f --- /dev/null +++ b/resources/assets/js/views/business/marketing-account-bills.js @@ -0,0 +1,206 @@ +/** + * 营销账户账单页面的服务端局部导航。 + * + * 链接始终保留完整 href 作为渐进增强回退;普通左键操作只替换当前 + * 工作区并同步 History,避免平台标签、京东账单类型、筛选和分页触发整页刷新。 + */ +(function () { + const workspaceSelector = '[data-marketing-account-bills-workspace]'; + const pagePathMarker = '/workspace/billing-transactions/marketing-account-bills'; + let activeRequest = null; + + function currentWorkspace() { + return document.querySelector(workspaceSelector); + } + + function isSupportedUrl(url) { + const target = new URL(url, window.location.origin); + + return target.origin === window.location.origin + && target.pathname.indexOf(pagePathMarker) !== -1; + } + + function updateHeader(nextDocument) { + const currentHeader = document.querySelector('[data-page-title-first]'); + const nextHeader = nextDocument.querySelector('[data-page-title-first]'); + + if (currentHeader && nextHeader) { + currentHeader.innerHTML = nextHeader.innerHTML; + } + + if (nextDocument.title) { + document.title = nextDocument.title; + } + } + + function setLoading(workspace, loading) { + const status = workspace.querySelector('[data-marketing-account-bills-status]'); + + if (loading) { + workspace.setAttribute('aria-busy', 'true'); + if (status) { + status.textContent = '正在加载账单数据'; + } + } else { + workspace.removeAttribute('aria-busy'); + } + } + + function showError(workspace, url) { + const error = workspace.querySelector('[data-marketing-account-bills-navigation-error]'); + const status = workspace.querySelector('[data-marketing-account-bills-status]'); + + setLoading(workspace, false); + + if (status) { + status.textContent = '账单内容加载失败'; + } + + if (error) { + const retry = error.querySelector('[data-marketing-account-bills-retry]'); + error.hidden = false; + if (retry) { + retry.href = url; + } + } + } + + function initialiseInsertedContent(workspace) { + if (window.Alpine && typeof window.Alpine.initTree === 'function') { + window.Alpine.initTree(workspace); + } + } + + async function navigate(url, options) { + const settings = Object.assign({ pushState: true, focus: null }, options || {}); + const workspace = currentWorkspace(); + + if (!workspace || !isSupportedUrl(url)) { + return false; + } + + if (activeRequest) { + activeRequest.abort(); + } + + const request = new AbortController(); + activeRequest = request; + setLoading(workspace, true); + + try { + const response = await window.fetch(url, { + credentials: 'same-origin', + headers: { + Accept: 'text/html', + 'X-Requested-With': 'XMLHttpRequest', + }, + signal: request.signal, + }); + + if (!response.ok) { + throw new Error(`HTTP ${response.status}`); + } + + const html = await response.text(); + const nextDocument = new DOMParser().parseFromString(html, 'text/html'); + const nextWorkspace = nextDocument.querySelector(workspaceSelector); + + if (!nextWorkspace) { + throw new Error('目标页面缺少营销账单工作区'); + } + + const importedWorkspace = document.importNode(nextWorkspace, true); + workspace.replaceWith(importedWorkspace); + initialiseInsertedContent(importedWorkspace); + updateHeader(nextDocument); + + const target = new URL(url, window.location.origin); + const relativeUrl = `${target.pathname}${target.search}${target.hash}`; + + if (settings.pushState && relativeUrl !== `${window.location.pathname}${window.location.search}${window.location.hash}`) { + window.history.pushState({ marketingAccountBills: true }, '', relativeUrl); + } + + if (settings.focus) { + const focusTarget = importedWorkspace.querySelector(settings.focus); + if (focusTarget) { + window.requestAnimationFrame(() => focusTarget.focus({ preventScroll: true })); + } + } + + return true; + } catch (error) { + if (error.name !== 'AbortError') { + showError(workspace, url); + } + + return false; + } finally { + if (activeRequest === request) { + activeRequest = null; + } + } + } + + document.addEventListener('click', (event) => { + const link = event.target.closest( + `${workspaceSelector} .business-tab-link, ` + + `${workspaceSelector} [data-jd-wallet-navigation], ` + + `${workspaceSelector} .jd-wallet-pagination a` + ); + + if (!link + || link.hasAttribute('data-marketing-account-bills-full-page') + || event.button !== 0 + || event.metaKey + || event.ctrlKey + || event.shiftKey + || event.altKey + || link.target === '_blank' + ) { + return; + } + + if (!isSupportedUrl(link.href)) { + return; + } + + event.preventDefault(); + event.stopPropagation(); + + const focusSelector = link.classList.contains('marketing-bills-subtab') + ? '.marketing-bills-subtab.is-active' + : '.business-tab-link.is-active'; + + navigate(link.href, { focus: focusSelector }); + }, true); + + document.addEventListener('submit', (event) => { + const form = event.target.closest(`${workspaceSelector} [data-jd-wallet-filter]`); + + if (!form) { + return; + } + + event.preventDefault(); + const target = new URL(form.action, window.location.origin); + + new FormData(form).forEach((value, key) => { + const normalized = String(value).trim(); + if (normalized === '') { + target.searchParams.delete(key); + } else { + target.searchParams.set(key, normalized); + } + }); + + target.searchParams.delete('page'); + navigate(target.href, { focus: '#jd-filter-store' }); + }, true); + + window.addEventListener('popstate', () => { + if (currentWorkspace() && isSupportedUrl(window.location.href)) { + navigate(window.location.href, { pushState: false }); + } + }); +}()); diff --git a/resources/views/banking/marketing_jd_wallet_bills/partials/embedded-table.blade.php b/resources/views/banking/marketing_jd_wallet_bills/partials/embedded-table.blade.php index 6bd0ec20..39825cc3 100644 --- a/resources/views/banking/marketing_jd_wallet_bills/partials/embedded-table.blade.php +++ b/resources/views/banking/marketing_jd_wallet_bills/partials/embedded-table.blade.php @@ -3,6 +3,15 @@ .marketing-bills-subtabs { display: flex; gap: 8px; margin: 0 0 16px; padding-bottom: 16px; border-bottom: 1px solid var(--vip-border, #D8D2C7); } .marketing-bills-subtab { display: inline-flex; min-height: 34px; align-items: center; gap: 6px; border: 1px solid var(--vip-border, #D8D2C7); border-radius: 8px; background: #fff; padding: 0 12px; color: #595959; font-size: 0.8125rem; font-weight: 500; } .marketing-bills-subtab:hover, .marketing-bills-subtab.is-active { border-color: var(--vip-content-accent-dark, #856632); background: var(--vip-content-accent-soft, #F7F0DE); color: var(--vip-content-accent-dark, #856632); } + .marketing-bills-subtab:focus-visible, .jd-wallet-button:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(133, 102, 50, 0.2); } + [data-marketing-account-bills-workspace][aria-busy="true"] { cursor: progress; opacity: 0.72; } + .jd-wallet-summary-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; } + .jd-wallet-summary-card { border: 1px solid var(--vip-border, #D8D2C7); border-radius: 8px; background: #fff; padding: 12px 16px; } + .jd-wallet-summary-label { color: #595959; font-size: 0.75rem; font-weight: 500; } + .jd-wallet-summary-value { margin-top: 4px; color: #171717; font-size: 0.875rem; font-weight: 700; font-variant-numeric: tabular-nums; } + .jd-wallet-filter { margin-bottom: 16px; border: 1px solid var(--vip-border, #D8D2C7); border-radius: 8px; background: var(--vip-content-bg, #F8F6F1); padding: 12px 16px; } + .jd-wallet-error { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; border: 1px solid #B80000; border-radius: 8px; background: #FFF1F1; padding: 12px 16px; color: #B80000; font-size: 0.8125rem; } + .jd-wallet-empty { padding: 40px 20px; color: #595959; text-align: center; } .jd-wallet-table-wrap { overflow-x: auto; border: 1px solid var(--vip-border, #D8D2C7); border-radius: 8px; } .jd-wallet-table { min-width: 100%; white-space: nowrap; font-size: 0.78125rem; } .jd-wallet-table th { position: sticky; top: 0; padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--vip-border, #D8D2C7); background: var(--vip-content-accent-soft, #F7F0DE); color: #171717; font-size: 0.75rem; font-weight: 600; text-align: left; } @@ -28,6 +37,7 @@ .jd-wallet-pagination .pagination-xs { display: flex; width: 100%; justify-content: center; margin-top: 0; } .jd-wallet-pagination .pagination-xs > nav, .jd-wallet-pagination .pagination-xs > nav > ul { margin-right: auto; margin-left: auto; } + @media (min-width: 640px) { .jd-wallet-summary-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } } @php @@ -41,38 +51,45 @@ $currentUrl = request()->url(); @endphp -
+
-
-
-
{{ $isConsumption ? '消耗金额合计' : '充值金额合计' }}(万元)
-
{{ number_format($amountWan, 2) }}
+
+
+
{{ $isConsumption ? '消耗金额合计' : '充值金额合计' }}(万元)
+
{{ number_format($amountWan, 2) }}
-
-
余额合计(万元)
-
{{ number_format($balanceWan, 2) }}
+
+
余额合计(万元)
+
{{ number_format($balanceWan, 2) }}
-
-
账单笔数
-
{{ number_format((int) ($summary['count'] ?? 0)) }}
+
+
账单笔数
+
{{ number_format((int) ($summary['count'] ?? 0)) }}
@if (! empty($error)) - + @endif -
+
@@ -94,7 +111,7 @@
- 清除 + 清除
共匹配 {{ $bills->total() }} 条
@@ -119,7 +136,7 @@ @endif @empty - 暂无符合条件的账单 + 当前筛选条件下没有账单,可调整筛选条件后重新查询。 @endforelse diff --git a/resources/views/business/pages/show.blade.php b/resources/views/business/pages/show.blade.php index 0255e2aa..c3bed1be 100644 --- a/resources/views/business/pages/show.blade.php +++ b/resources/views/business/pages/show.blade.php @@ -2,9 +2,8 @@ $isMarketingAccountBillsPage = ($section['slug'] ?? null) === 'billing-transactions' && ($page['slug'] ?? null) === 'marketing-account-bills'; $marketingAccountTabTitles = [ - 'taobao-alipay' => '淘系账户', - 'taobao-wechat' => '阿里巴巴账户', - 'jd-wallet' => '京东账户', + 'taobao-wechat' => 'Alibaba', + 'jd-wallet' => '京东', ]; $activeContentTitle = $activeTab['title'] ?? ($page['title'] ?? $section['title']); @@ -391,10 +390,20 @@ } -
$isMarketingAccountBillsPage, - ])> +
$isMarketingAccountBillsPage, + ]) + @if ($isMarketingAccountBillsPage) data-marketing-account-bills-workspace @endif + > + @if ($isMarketingAccountBillsPage) +

+ + @endif @if (is_string(session('success')))
{{ session('success') }}
@endif @@ -714,7 +723,11 @@ @endif
- @if (($page['slug'] ?? null) === 'store-receiving-bills') + @if ($isMarketingAccountBillsPage) + @push('scripts_start') + + @endpush + @elseif (($page['slug'] ?? null) === 'store-receiving-bills') @push('scripts_start') @endpush diff --git a/scripts/build-frontend.ps1 b/scripts/build-frontend.ps1 index ee4b4917..1dd4ee42 100644 --- a/scripts/build-frontend.ps1 +++ b/scripts/build-frontend.ps1 @@ -153,6 +153,7 @@ $jsCacheValid = Test-CacheFingerprint ` -Expected $jsFingerprint ` -RequiredOutputs @( (Join-Path $frontendOutputRoot 'js/auth/common.min.js'), + (Join-Path $frontendOutputRoot 'js/business/marketing-account-bills.min.js'), (Join-Path $frontendOutputRoot 'js/manifest.js'), (Join-Path $frontendOutputRoot 'js/vendor.js'), (Join-Path $cachedVendorPath 'apexcharts/apexcharts.min.js'), @@ -261,6 +262,7 @@ try { foreach ($output in @( 'public/js/auth/common.min.js', + 'public/js/business/marketing-account-bills.min.js', 'public/js/manifest.js', 'public/js/vendor.js', 'public/mix-manifest.json' diff --git a/tests/Feature/Business/MarketingAccountBillsTabsTest.php b/tests/Feature/Business/MarketingAccountBillsTabsTest.php index eb9c8080..be388a82 100644 --- a/tests/Feature/Business/MarketingAccountBillsTabsTest.php +++ b/tests/Feature/Business/MarketingAccountBillsTabsTest.php @@ -3,6 +3,11 @@ namespace Tests\Feature\Business; use App\Models\Auth\Permission; +use Mockery; +use Modules\EcommerceFinance\Repositories\JdWalletBillRepository; +use Modules\EcommerceFinance\Services\UpstreamQueryCache; +use Modules\EcommerceFinance\Services\UpstreamQueryCacheFactory; +use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Tests\Feature\FeatureTestCase; class MarketingAccountBillsTabsTest extends FeatureTestCase @@ -18,10 +23,10 @@ class MarketingAccountBillsTabsTest extends FeatureTestCase 'tab' => 'taobao-wechat', ])) ->assertOk() - ->assertSeeText('淘系账户') - ->assertSeeText('阿里巴巴账户') - ->assertSeeText('京东账户') - ->assertDontSeeText('淘系支付宝账户') + ->assertSeeText('淘系支付宝账户') + ->assertSeeText('Alibaba') + ->assertSeeText('京东') + ->assertDontSeeText('淘系微信账户') ->assertDontSeeText('京东网银钱包账户') ->assertSee('class="my-6 business-page--marketing-account-bills"', false); } @@ -43,7 +48,9 @@ class MarketingAccountBillsTabsTest extends FeatureTestCase ->assertSeeText('消耗账单') ->assertSeeText('金额(元)') ->assertSeeText('充值时间') - ->assertDontSeeText('投放日期'); + ->assertDontSeeText('投放日期') + ->assertSee('data-jd-wallet-panel', false) + ->assertSee('data-jd-wallet-navigation', false); $this->loginAs() ->get(route('business.pages.show', array_merge($base, ['jd_ledger' => 'consumption']))) @@ -56,6 +63,56 @@ class MarketingAccountBillsTabsTest extends FeatureTestCase ->assertDontSeeText('充值时间'); } + public function testJdWalletColdStartRegistersEveryRequiredSnapshotScope(): void + { + $this->allowMarketingAccountBillsPage(); + $scopes = []; + $cache = Mockery::mock(UpstreamQueryCache::class); + $cache->shouldReceive('remember') + ->times(3) + ->andReturnUsing(function (string $scope, array $parameters, callable $resolver) use (&$scopes): array { + $scopes[] = $scope; + + if (count($scopes) === 1) { + throw new ServiceUnavailableHttpException(30, '首份共享快照正在准备。'); + } + + return match ($scope) { + 'jd-wallet-bills.recharge.summary' => [ + 'amount_total' => 0, + 'balance_total' => 0, + 'count' => 0, + ], + 'jd-wallet-bills.options' => [], + default => ['rows' => [], 'total' => 0], + }; + }); + + $factory = Mockery::mock(UpstreamQueryCacheFactory::class); + $factory->shouldReceive('forSource') + ->once() + ->with('jiansun') + ->andReturn($cache); + + $this->app->instance(UpstreamQueryCacheFactory::class, $factory); + $this->app->instance(JdWalletBillRepository::class, Mockery::mock(JdWalletBillRepository::class)); + + $this->loginAs() + ->get(route('business.pages.show', [ + 'section' => 'billing-transactions', + 'page' => 'marketing-account-bills', + 'tab' => 'jd-wallet', + ])) + ->assertOk() + ->assertSeeText('首份共享快照正在准备。'); + + $this->assertSame([ + 'jd-wallet-bills.recharge.list', + 'jd-wallet-bills.recharge.summary', + 'jd-wallet-bills.options', + ], $scopes); + } + private function allowMarketingAccountBillsPage(): void { $this->user->update(['locale' => 'zh-CN']); diff --git a/tests/Unit/EcommerceFinance/JdWalletBillRepositoryTest.php b/tests/Unit/EcommerceFinance/JdWalletBillRepositoryTest.php index 717acbec..ad6a7b36 100644 --- a/tests/Unit/EcommerceFinance/JdWalletBillRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/JdWalletBillRepositoryTest.php @@ -75,5 +75,7 @@ class JdWalletBillRepositoryTest extends TestCase $this->assertSame('推广费开票', $consumption['rows'][0]['notes']); $this->assertSame(12.35, $summary['amount_total']); $this->assertStringContainsString('ABS(amount)', $query->calls[4]['sql']); + $this->assertStringContainsString('< DATEADD(day, 1, CAST(? AS date))', $query->calls[0]['sql']); + $this->assertSame(['2026-08-03 00:00:00', '2026-08-03'], $query->calls[0]['bindings']); } } diff --git a/tests/Unit/EcommerceFinance/JianSunSnapshotRefresherTest.php b/tests/Unit/EcommerceFinance/JianSunSnapshotRefresherTest.php index d35c3513..23cfebaa 100644 --- a/tests/Unit/EcommerceFinance/JianSunSnapshotRefresherTest.php +++ b/tests/Unit/EcommerceFinance/JianSunSnapshotRefresherTest.php @@ -7,6 +7,7 @@ use Modules\EcommerceFinance\Repositories\AlibabaBillRepository; use Modules\EcommerceFinance\Repositories\EdgeBandingRepository; use Modules\EcommerceFinance\Repositories\GoodsReconciliationRepository; use Modules\EcommerceFinance\Repositories\InventoryRepository; +use Modules\EcommerceFinance\Repositories\JdWalletBillRepository; use Modules\EcommerceFinance\Repositories\PinduoduoSpreadBillRepository; use Modules\EcommerceFinance\Repositories\ProductPriceRepository; use Modules\EcommerceFinance\Repositories\RawBoardPayablesRepository; @@ -217,6 +218,141 @@ class JianSunSnapshotRefresherTest extends TestCase $this->assertSame([['supplier' => '测试厂'], 2, 50], $rawBoardPayables->arguments); } + public function test_jd_wallet_scopes_are_available_to_background_refresh(): void + { + $jdWallet = new class extends JdWalletBillRepository { + public array $calls = []; + + public function __construct() + { + } + + public function paginateConsumption( + ?string $shopName = null, + ?string $fromDate = null, + ?string $toDate = null, + int $page = 1, + int $pageSize = 25, + ): array { + $this->calls['consumption.list'] = func_get_args(); + + return ['rows' => [], 'total' => 0]; + } + + public function paginateRecharge( + ?string $shopName = null, + ?string $fromDate = null, + ?string $toDate = null, + int $page = 1, + int $pageSize = 25, + ): array { + $this->calls['recharge.list'] = func_get_args(); + + return ['rows' => [], 'total' => 0]; + } + + public function summaryConsumption( + ?string $shopName = null, + ?string $fromDate = null, + ?string $toDate = null, + ): array { + $this->calls['consumption.summary'] = func_get_args(); + + return ['amount_total' => 0, 'balance_total' => 0, 'count' => 0]; + } + + public function summaryRecharge( + ?string $shopName = null, + ?string $fromDate = null, + ?string $toDate = null, + ): array { + $this->calls['recharge.summary'] = func_get_args(); + + return ['amount_total' => 0, 'balance_total' => 0, 'count' => 0]; + } + + public function shopOptions(): array + { + $this->calls['options'] = []; + + return ['测试京东店铺']; + } + }; + + $refresher = $this->refresher(jdWallet: $jdWallet); + $rechargeStatus = $refresher->refresh([ + 'scope' => 'jd-wallet-bills.recharge.list', + 'parameters' => [ + 'filters' => [ + 'store_name' => '测试京东店铺', + 'from' => '2026-08-01', + 'to' => '2026-08-10', + ], + 'page' => 2, + 'limit' => 50, + ], + ]); + $consumptionSummaryStatus = $refresher->refresh([ + 'scope' => 'jd-wallet-bills.consumption.summary', + 'parameters' => [ + 'filters' => [ + 'store_name' => '测试京东店铺', + 'from' => '2026-08-01', + 'to' => '2026-08-10', + ], + ], + ]); + $rechargeSummaryStatus = $refresher->refresh([ + 'scope' => 'jd-wallet-bills.recharge.summary', + 'parameters' => [ + 'filters' => [ + 'store_name' => '测试京东店铺', + 'from' => '2026-08-01', + 'to' => '2026-08-10', + ], + ], + ]); + $consumptionListStatus = $refresher->refresh([ + 'scope' => 'jd-wallet-bills.consumption.list', + 'parameters' => [ + 'filters' => [ + 'store_name' => '测试京东店铺', + 'from' => '2026-08-01', + 'to' => '2026-08-10', + ], + 'page' => 3, + 'limit' => 25, + ], + ]); + $optionsStatus = $refresher->refresh([ + 'scope' => 'jd-wallet-bills.options', + 'parameters' => [], + ]); + + $this->assertSame('fresh', $rechargeStatus); + $this->assertSame('fresh', $consumptionSummaryStatus); + $this->assertSame('fresh', $rechargeSummaryStatus); + $this->assertSame('fresh', $consumptionListStatus); + $this->assertSame('fresh', $optionsStatus); + $this->assertSame( + ['测试京东店铺', '2026-08-01', '2026-08-10', 2, 50], + $jdWallet->calls['recharge.list'], + ); + $this->assertSame( + ['测试京东店铺', '2026-08-01', '2026-08-10'], + $jdWallet->calls['consumption.summary'], + ); + $this->assertSame( + ['测试京东店铺', '2026-08-01', '2026-08-10'], + $jdWallet->calls['recharge.summary'], + ); + $this->assertSame( + ['测试京东店铺', '2026-08-01', '2026-08-10', 3, 25], + $jdWallet->calls['consumption.list'], + ); + $this->assertSame([], $jdWallet->calls['options']); + } + private function refresher( ?InventoryRepository $inventory = null, ?AlibabaBillRepository $alibaba = null, @@ -225,6 +361,7 @@ class JianSunSnapshotRefresherTest extends TestCase ?RawBoardPayablesRepository $rawBoardPayables = null, ?TmallTaobaoSpreadBillRepository $taobaoAlipay = null, ?SupplierPayableReportRepository $supplierPayableReports = null, + ?JdWalletBillRepository $jdWallet = null, ): JianSunSnapshotRefresher { return new JianSunSnapshotRefresher( new class extends JianSunQueryCache { @@ -251,6 +388,7 @@ class JianSunSnapshotRefresherTest extends TestCase $taobaoAlipay ?? $this->placeholder(TmallTaobaoSpreadBillRepository::class), $this->placeholder(SupplierPayableRepository::class), $supplierPayableReports ?? $this->placeholder(SupplierPayableReportRepository::class), + $jdWallet ?? $this->placeholder(JdWalletBillRepository::class), ); } diff --git a/webpack.mix.js b/webpack.mix.js index 13ebbb3b..259c7584 100644 --- a/webpack.mix.js +++ b/webpack.mix.js @@ -72,6 +72,7 @@ if (buildJavaScript) { // Business workspace(店铺管理 › 各子功能) .js('resources/assets/js/views/business/pages.js', 'public/js/business/pages.min.js') + .js('resources/assets/js/views/business/marketing-account-bills.js', 'public/js/business/marketing-account-bills.min.js') // Ecommerce Finance .js('resources/assets/js/views/ecommerce-finance/goods-reconciliations.js', 'public/js/ecommerce-finance/goods-reconciliations.min.js')