From 5679a411056375bd5e52e2c4ae1056e2adc7bcff Mon Sep 17 00:00:00 2001 From: WuYongJie <549727955@qq.com> Date: Sat, 29 Aug 2026 18:54:09 +0800 Subject: [PATCH] fix: preserve production promotion account page --- app/Http/Controllers/Business/Pages.php | 56 +++++++++ config/business_navigation.php | 10 ++ config/js_data_middle_platform.php | 17 +++ config/upstreams.php | 5 + .../PlatformPromotionAccountRepository.php | 99 ++++++++++++++++ .../View/PlatformPromotionAccountPageData.php | 108 ++++++++++++++++++ .../platform-promotion-accounts.blade.php | 89 +++++++++++++++ .../PlatformPromotionAccountPageTest.php | 100 ++++++++++++++++ 8 files changed, 484 insertions(+) create mode 100644 config/js_data_middle_platform.php create mode 100644 modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php create mode 100644 modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php create mode 100644 resources/views/business/pages/billing-transactions/platform-promotion-accounts.blade.php create mode 100644 tests/Feature/Business/PlatformPromotionAccountPageTest.php diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 6e62f11e..289212a7 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -31,6 +31,7 @@ use Modules\EcommerceFinance\Repositories\DingPayableWorkflowMirrorRepository; use Modules\EcommerceFinance\Repositories\SupplierPayableReportRepository; use Modules\EcommerceFinance\Repositories\TmallTaobaoSpreadBillRepository; use Modules\EcommerceFinance\Services\UpstreamQueryCacheFactory; +use Modules\EcommerceFinance\View\PlatformPromotionAccountPageData; use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpKernel\Exception\ServiceUnavailableHttpException; use Throwable; @@ -323,6 +324,7 @@ class Pages extends Controller 'board-deductions' => $this->contentForBoardDeductions(), 'supplier-payables-report' => $this->contentForSupplierPayablesReport(), 'payable-cloud-warehouse-vehicle-fee' => $this->contentForDingPayableWorkflows(), + 'platform-promotion-accounts' => app(PlatformPromotionAccountPageData::class)->content($tab), default => null, }; } @@ -670,6 +672,10 @@ class Pages extends Controller $pageConfig = collect($sectionConfig['pages'] ?? [])->firstWhere('slug', $page); abort_if(empty($pageConfig), 403, '当前账号没有该页面权限。'); + if ($page === 'platform-promotion-accounts') { + return $this->exportPlatformPromotionAccounts($request); + } + if ($page === 'marketing-account-bills') { return $this->exportMarketingAccountBills($request, $section, $page, $tab); } @@ -739,6 +745,56 @@ class Pages extends Controller ]); } + private function exportPlatformPromotionAccounts(Request $request) + { + $month = trim((string) $request->query('month', '')); + $month = preg_match('/^\d{4}-\d{2}$/', $month) === 1 ? $month : null; + $filters = [ + 'month' => $month, + 'shop_name' => mb_substr(trim((string) $request->query('shop_name', '')), 0, 100), + 'account' => mb_substr(trim((string) $request->query('account', '')), 0, 100), + ]; + + try { + $repository = app(\Modules\EcommerceFinance\Repositories\PlatformPromotionAccountRepository::class); + $filters['month'] = $month ?: ($repository->latestMonth() ?: now()->format('Y-m')); + $data = $repository->dashboard($filters, 5000); + } catch (Throwable $exception) { + report($exception); + + return redirect()->route('business.pages.show', [ + 'section' => 'billing-transactions', + 'page' => 'platform-promotion-accounts', + ])->with('error', '推广账户数据导出暂时无法完成,请稍后重试。'); + } + + return response()->streamDownload(function () use ($data): void { + $csv = fopen('php://output', 'w'); + fputs($csv, chr(0xEF) . chr(0xBB) . chr(0xBF)); + fputcsv($csv, ['平台', '店铺/账户', '日期', '类型', '金额(元)', '余额(元)', '备注']); + $emit = static function (string $platform, array $rows, array $map) use ($csv): void { + foreach ($rows as $row) { + fputcsv($csv, [ + $platform, + $map['name']($row), + $map['date']($row), + $map['type']($row), + $map['amount']($row), + $map['balance']($row), + $map['remark']($row), + ]); + } + }; + $emit('京东京准通', $data['jd'] ?? [], ['name' => fn ($row) => $row['shop_name'] . ' / ' . $row['account'], 'date' => fn ($row) => $row['show_date'] ?? $row['settle_datetime'], 'type' => fn ($row) => $row['trade_type_name'] ?? $row['in_out_type_name'], 'amount' => fn ($row) => $row['amount'] ?? '', 'balance' => fn ($row) => $row['balance_amount'] ?? '', 'remark' => fn ($row) => $row['remark'] ?? '']); + $emit('抖音千川', $data['dy'] ?? [], ['name' => fn ($row) => $row['shopName'] . ' / ' . $row['account'] . ' / ' . $row['qianchuanAavid'], 'date' => fn ($row) => $row['statDate'] ?? '', 'type' => fn () => '花费', 'amount' => fn ($row) => $row['cost'] ?? '', 'balance' => fn ($row) => $row['balance'] ?? '', 'remark' => fn ($row) => $row['remark'] ?? '']); + $emit('得物推广', $data['dw'] ?? [], ['name' => fn ($row) => $row['shop_name'] . ' / ' . $row['account'], 'date' => fn ($row) => $row['trade_date'] ?? $row['date_time'], 'type' => fn ($row) => $row['flow_type'] ?? '', 'amount' => fn ($row) => $row['trade_amount_yuan'] ?? '', 'balance' => fn ($row) => $row['balance_yuan'] ?? '', 'remark' => fn ($row) => $row['remark'] ?? '']); + $emit('VIP营销', $data['vipMarketing'] ?? [], ['name' => fn ($row) => $row['accountName'] . ' / ' . $row['advertiserId'], 'date' => fn ($row) => $row['dataMonth'], 'type' => fn () => '月度花费', 'amount' => fn ($row) => $row['totalCostYuan'] ?? '', 'balance' => fn () => '', 'remark' => fn ($row) => '曝光 ' . $row['totalImpressionCount']]); + fclose($csv); + }, '平台推广账户流水_' . $filters['month'] . '.csv', [ + 'Content-Type' => 'text/csv; charset=UTF-8', + ]); + } + private function exportMarketingAccountBills( Request $request, string $section, diff --git a/config/business_navigation.php b/config/business_navigation.php index ce119a30..a4d6db99 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -311,6 +311,16 @@ return [ ['slug' => 'vipshop', 'title' => '唯品会账户'], ], ], + [ + 'slug' => 'platform-promotion-accounts', + 'title' => '平台推广账户流水', + 'tabs' => [ + ['slug' => 'jd', 'title' => '京东京准通'], + ['slug' => 'douyin', 'title' => '抖音千川'], + ['slug' => 'dewu', 'title' => '得物推广账户'], + ['slug' => 'vip', 'title' => 'VIP(唯品会)'], + ], + ], ['slug' => 'deposit-account-balance', 'title' => '店铺保证金账户余额'], [ 'slug' => 'deposit-account-bills', diff --git a/config/js_data_middle_platform.php b/config/js_data_middle_platform.php new file mode 100644 index 00000000..5a9592e7 --- /dev/null +++ b/config/js_data_middle_platform.php @@ -0,0 +1,17 @@ + true, + 'connection' => [ + 'host' => env('JS_DATA_MIDDLE_PLATFORM_HOST', '218.93.191.16'), + 'port' => (int) env('JS_DATA_MIDDLE_PLATFORM_PORT', 1433), + 'database' => env('JS_DATA_MIDDLE_PLATFORM_DATABASE', 'JSDataMiddlePlatform'), + 'username' => env('JS_DATA_MIDDLE_PLATFORM_USERNAME', 'sa'), + 'password' => env('JS_DATA_MIDDLE_PLATFORM_PASSWORD', ''), + 'odbc_driver' => env('JS_DATA_MIDDLE_PLATFORM_ODBC_DRIVER', 'FreeTDS'), + 'tds_version' => env('JS_DATA_MIDDLE_PLATFORM_TDS_VERSION', '7.4'), + 'connect_timeout' => (int) env('JS_DATA_MIDDLE_PLATFORM_CONNECT_TIMEOUT', 5), + 'query_timeout' => (int) env('JS_DATA_MIDDLE_PLATFORM_QUERY_TIMEOUT', 30), + 'encryption' => env('JS_DATA_MIDDLE_PLATFORM_ENCRYPTION', 'off'), + ], +]; diff --git a/config/upstreams.php b/config/upstreams.php index 81fe5250..58499932 100644 --- a/config/upstreams.php +++ b/config/upstreams.php @@ -67,5 +67,10 @@ return [ // Windows 和其他来源继续保持现有 PDO_ODBC 行为。 'use_pdo_dblib' => true, ], + 'js_data_middle_platform' => [ + 'label' => 'JSDataMiddlePlatform 中台库', + 'config' => 'js_data_middle_platform', + 'use_pdo_dblib' => true, + ], ], ]; diff --git a/modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php b/modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php new file mode 100644 index 00000000..74fdc7c7 --- /dev/null +++ b/modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php @@ -0,0 +1,99 @@ +queries->forSource(self::SOURCE); + + $jd = $this->query($query, "SELECT TOP {$limit} data_month, shop_name, account, login_pin, in_out_type_name, trade_type_name, amount, balance_amount, settle_datetime, show_date, trade_no, remark FROM JSDataMiddlePlatform.dbo.jd_jzt_finance_records WHERE data_month = ?", [$month], $shop, $account, 'shop_name'); + $jdSummary = $this->query($query, "SELECT COALESCE(SUM(CASE WHEN in_out_type='IN' THEN amount ELSE 0 END),0) income, COALESCE(SUM(CASE WHEN in_out_type='OUT' THEN amount ELSE 0 END),0) expense, COUNT(*) record_count FROM JSDataMiddlePlatform.dbo.jd_jzt_finance_records WHERE data_month = ?", [$month], $shop, $account, 'shop_name', true)[0] ?? []; + + $douyin = $this->query($query, "SELECT TOP {$limit} shopName, account, qianchuanAavid, qianchuanAccountName, statDate, cost, income, transferOut, transferIn, balance, status, remark FROM JSDataMiddlePlatform.dbo.dy_qianchuan_finance_transactions WHERE dataMonth = ? AND rowType = N'daily' AND status = N'success'", [$month . '-01'], $shop, $account, 'shopName'); + $douyinSummary = $this->query($query, "SELECT COALESCE(SUM(cost),0) cost, COALESCE(SUM(income),0) income, COALESCE(SUM(transferOut),0) transfer_out, COALESCE(SUM(transferIn),0) transfer_in, COUNT(DISTINCT qianchuanAavid) account_count FROM JSDataMiddlePlatform.dbo.dy_qianchuan_finance_transactions WHERE dataMonth = ? AND rowType = N'daily' AND status = N'success'", [$month . '-01'], $shop, $account, 'shopName', true)[0] ?? []; + $douyinStatus = $this->query($query, "SELECT COUNT(*) status_count FROM JSDataMiddlePlatform.dbo.dy_qianchuan_finance_transactions WHERE dataMonth = ? AND rowType = N'status' AND status = N'no_permission'", [$month . '-01'], $shop, $account, 'shopName', true)[0] ?? []; + + $dewu = $this->query($query, "SELECT TOP {$limit} data_month, shop_name, account, amount_type, flow_type, trade_amount_yuan, balance_yuan, trade_date, date_time, remark FROM JSDataMiddlePlatform.dbo.dw_ad_finance_records WHERE data_month = ?", [$month], $shop, $account, 'shop_name'); + $dewuSummary = $this->query($query, 'SELECT COALESCE(SUM(total_income_amount),0) income, COALESCE(SUM(total_expense_amount),0) expense, COALESCE(SUM(net_amount),0) net, COALESCE(SUM(record_count),0) record_count FROM JSDataMiddlePlatform.dbo.dw_ad_finance_month_summaries WHERE data_month = ?', [$month], $shop, $account, 'shop_name', true)[0] ?? []; + + $vipSales = $this->query($query, "SELECT TOP {$limit} shopName, dataMonth, monthName, previousYearSalesAmount, salesTarget, actualSalesAmount, updatedAt FROM JSDataMiddlePlatform.dbo.vip_monthlySaleProgress WHERE dataMonth = ?", [$month], $shop, null, 'shopName'); + $vipTax = $this->query($query, "SELECT TOP {$limit} shopName, storeName, reportAmount, returnOrderCount, returnServiceAmount, returnSkuAmount, saleOrderCount, salesServiceAmount, salesSkuAmount, transactionNum, transactionTime FROM JSDataMiddlePlatform.dbo.vip_taxDeclarationDetail WHERE dataMonth = ?", [$month], $shop, null, 'shopName'); + $vipMarketing = $this->query($query, "SELECT TOP {$limit} account, accountName, advertiserId, dataMonth, totalCostYuan, totalImpressionCount, recordCount, updatedAt FROM JSDataMiddlePlatform.dbo.vip_marketingMonthlySummary WHERE dataMonth = ?", [$month], null, $account, 'account'); + $vipSummary = [ + 'sales' => $this->sum($vipSales, 'actualSalesAmount'), + 'target' => $this->sum($vipSales, 'salesTarget'), + 'tax' => $this->sum($vipTax, 'reportAmount'), + 'marketing_cost' => $this->sum($vipMarketing, 'totalCostYuan'), + 'impressions' => $this->sum($vipMarketing, 'totalImpressionCount'), + ]; + + return [ + 'jd' => $jd, + 'jdSummary' => $jdSummary, + 'dy' => $douyin, + 'dySummary' => $douyinSummary, + 'dyStatus' => $douyinStatus, + 'dw' => $dewu, + 'dwSummary' => $dewuSummary, + 'vipSales' => $vipSales, + 'vipTax' => $vipTax, + 'vipMarketing' => $vipMarketing, + 'vipSummary' => $vipSummary, + ]; + } + + public function latestMonth(): ?string + { + $row = $this->queries->forSource(self::SOURCE)->first( + 'SELECT MAX(data_month) AS month FROM JSDataMiddlePlatform.dbo.jd_jzt_finance_records' + ); + $month = trim((string) ($row['month'] ?? '')); + + return preg_match('/^\d{4}-\d{2}$/', $month) === 1 ? $month : null; + } + + private function query( + UpstreamReadOnlyQuery $query, + string $sql, + array $bindings, + ?string $shop, + ?string $account, + string $shopColumn, + bool $summary = false, + ): array { + if ($shop !== null && $shop !== '') { + $sql .= " AND {$shopColumn} LIKE ?"; + $bindings[] = '%' . $shop . '%'; + } + if ($account !== null && $account !== '') { + $sql .= ' AND account LIKE ?'; + $bindings[] = '%' . $account . '%'; + } + if (! $summary) { + $sql .= ' ORDER BY 1'; + } + + return $query->select($sql, $bindings); + } + + private function sum(array $rows, string $key): float + { + return round(array_sum(array_map(static fn (array $row): float => (float) ($row[$key] ?? 0), $rows)), 2); + } +} diff --git a/modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php b/modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php new file mode 100644 index 00000000..889c21f4 --- /dev/null +++ b/modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php @@ -0,0 +1,108 @@ +month(request('month')); + $month = $requestedMonth ?: now()->format('Y-m'); + $filters = [ + 'month' => $month, + 'shop_name' => $this->text(request('shop_name')), + 'account' => $this->text(request('account')), + ]; + $tab = in_array($tab, ['jd', 'douyin', 'dewu', 'vip'], true) ? $tab : 'jd'; + + try { + if ($requestedMonth === '') { + $month = $this->repository->latestMonth() ?: $month; + $filters['month'] = $month; + } + $data = $this->repository->dashboard($filters, 5000); + + return [ + 'view' => 'business.pages.billing-transactions.platform-promotion-accounts', + 'filters' => $filters, + 'data' => $data, + 'platform' => $tab, + 'rows' => $this->paginateRows($data, $tab), + 'error' => null, + ]; + } catch (ServiceUnavailableHttpException $exception) { + return [ + 'view' => 'business.pages.billing-transactions.platform-promotion-accounts', + 'filters' => $filters, + 'data' => [], + 'platform' => $tab, + 'rows' => $this->emptyPaginator(), + 'error' => $exception->getMessage(), + ]; + } catch (Throwable $exception) { + report($exception); + + return [ + 'view' => 'business.pages.billing-transactions.platform-promotion-accounts', + 'filters' => $filters, + 'data' => [], + 'platform' => $tab, + 'rows' => $this->emptyPaginator(), + 'error' => '推广账户数据暂时无法读取,请稍后重试。', + ]; + } + } + + private function paginateRows(array $data, string $tab): LengthAwarePaginator + { + $key = ['jd' => 'jd', 'douyin' => 'dy', 'dewu' => 'dw', 'vip' => 'vipSales'][$tab]; + $rows = $tab === 'vip' + ? array_merge($data['vipSales'] ?? [], $data['vipTax'] ?? [], $data['vipMarketing'] ?? []) + : ($data[$key] ?? []); + $page = max((int) request('page', 1), 1); + $perPage = 50; + + return new LengthAwarePaginator( + Collection::make($rows)->forPage($page, $perPage)->values(), + count($rows), + $perPage, + $page, + ['path' => request()->url(), 'query' => request()->except('page')], + ); + } + + private function emptyPaginator(): LengthAwarePaginator + { + return new LengthAwarePaginator([], 0, 50, 1, [ + 'path' => request()->url(), + 'query' => request()->query(), + ]); + } + + private function text(mixed $value): string + { + return mb_substr(trim((string) $value), 0, 100); + } + + private function month(mixed $value): string + { + $value = trim((string) $value); + if (preg_match('/^(\d{4})-(\d{2})$/', $value, $matches) !== 1 + || (int) $matches[2] < 1 + || (int) $matches[2] > 12) { + return ''; + } + + return $value; + } +} diff --git a/resources/views/business/pages/billing-transactions/platform-promotion-accounts.blade.php b/resources/views/business/pages/billing-transactions/platform-promotion-accounts.blade.php new file mode 100644 index 00000000..86f1f311 --- /dev/null +++ b/resources/views/business/pages/billing-transactions/platform-promotion-accounts.blade.php @@ -0,0 +1,89 @@ +@php + $data = $data ?? []; + $platform = $platform ?? 'jd'; + $summary = match ($platform) { + 'jd' => $data['jdSummary'] ?? [], + 'douyin' => $data['dySummary'] ?? [], + 'dewu' => $data['dwSummary'] ?? [], + default => $data['vipSummary'] ?? [], + }; + $titles = ['jd' => '京东京准通', 'douyin' => '抖音千川', 'dewu' => '得物推广账户', 'vip' => 'VIP(唯品会)']; + $columns = match ($platform) { + 'jd' => [['shop_name', '店铺'], ['account', '账户'], ['show_date', '日期'], ['trade_type_name', '交易类型'], ['amount', '金额'], ['balance_amount', '余额'], ['remark', '备注']], + 'douyin' => [['shopName', '店铺'], ['account', '账户'], ['qianchuanAavid', '广告账户'], ['statDate', '日期'], ['cost', '花费'], ['balance', '余额'], ['status', '状态'], ['remark', '备注']], + 'dewu' => [['shop_name', '店铺'], ['account', '账户'], ['trade_date', '日期'], ['flow_type', '收支类型'], ['trade_amount_yuan', '金额'], ['balance_yuan', '余额'], ['remark', '备注']], + default => [['shopName', '店铺'], ['storeName', '平台店铺'], ['accountName', '营销账户'], ['dataMonth', '月份'], ['actualSalesAmount', '实际销售额'], ['reportAmount', '申报金额'], ['totalCostYuan', '营销花费']], + }; + $moneyFields = ['amount', 'balance_amount', 'cost', 'balance', 'trade_amount_yuan', 'balance_yuan', 'actualSalesAmount', 'reportAmount', 'totalCostYuan']; +@endphp + +
+
+ + + + + 导出 CSV +
+ + @if (! empty($error)) + + @endif + +
+ @if ($platform === 'jd') +
入账金额
{{ number_format((float) ($summary['income'] ?? 0), 2) }}
+
出账金额
{{ number_format((float) ($summary['expense'] ?? 0), 2) }}
+
净额
{{ number_format((float) ($summary['income'] ?? 0) - (float) ($summary['expense'] ?? 0), 2) }}
+
流水笔数
{{ number_format((int) ($summary['record_count'] ?? 0)) }}
+ @elseif ($platform === 'douyin') +
总花费
{{ number_format((float) ($summary['cost'] ?? 0), 2) }}
+
收入
{{ number_format((float) ($summary['income'] ?? 0), 2) }}
+
转入
{{ number_format((float) ($summary['transfer_in'] ?? 0), 2) }}
+
账户数
{{ number_format((int) ($summary['account_count'] ?? 0)) }}
+ @elseif ($platform === 'dewu') +
总收入
{{ number_format((float) ($summary['income'] ?? 0), 2) }}
+
总支出
{{ number_format((float) ($summary['expense'] ?? 0), 2) }}
+
净额
{{ number_format((float) ($summary['net'] ?? 0), 2) }}
+
流水笔数
{{ number_format((int) ($summary['record_count'] ?? 0)) }}
+ @else +
实际销售额
{{ number_format((float) ($summary['sales'] ?? 0), 2) }}
+
销售目标
{{ number_format((float) ($summary['target'] ?? 0), 2) }}
+
涉税申报
{{ number_format((float) ($summary['tax'] ?? 0), 2) }}
+
营销花费
{{ number_format((float) ($summary['marketing_cost'] ?? 0), 2) }}
+ @endif +
+ +
+
{{ $titles[$platform] }}明细
{{ number_format($rows->total()) }} 条
+
@foreach ($columns as $column)@endforeach + @forelse ($rows as $row) + @foreach ($columns as $column) + @php($value = $row[$column[0]] ?? null) + + @endforeach + @empty + + @endforelse +
{{ $column[1] }}
{{ in_array($column[0], $moneyFields, true) && is_numeric($value) ? number_format((float) $value, 2) : ($value ?? '—') }}
该月份暂无数据
+
每页最多 50 条 · 共 {{ number_format($rows->total()) }} 条
+
+
diff --git a/tests/Feature/Business/PlatformPromotionAccountPageTest.php b/tests/Feature/Business/PlatformPromotionAccountPageTest.php new file mode 100644 index 00000000..a7b42be5 --- /dev/null +++ b/tests/Feature/Business/PlatformPromotionAccountPageTest.php @@ -0,0 +1,100 @@ +shouldReceive('latestMonth')->once()->andReturn('2026-08'); + $repository->shouldReceive('dashboard')->once()->with([ + 'month' => '2026-08', + 'shop_name' => '', + 'account' => '', + ], 5000)->andReturn($this->dashboardData()); + $this->app->instance(PlatformPromotionAccountRepository::class, $repository); + + $this->user->attachPermission( + Permission::where('name', 'read-admin-panel')->firstOrFail() + ); + + $this->loginAs() + ->get(route('business.pages.show', [ + 'section' => 'billing-transactions', + 'page' => 'platform-promotion-accounts', + 'tab' => 'jd', + ])) + ->assertOk() + ->assertSeeText('平台推广账户流水') + ->assertSeeText('京东京准通') + ->assertSeeText('测试店铺') + ->assertSeeText('导出 CSV') + ->assertSee(route('business.pages.show', [ + 'section' => 'order-data', + 'page' => 'bill-offset', + ]), false); + } + + public function test_platform_promotion_export_keeps_the_complete_filtered_month(): void + { + $repository = Mockery::mock(PlatformPromotionAccountRepository::class); + $repository->shouldReceive('latestMonth')->never(); + $repository->shouldReceive('dashboard')->once()->with([ + 'month' => '2026-08', + 'shop_name' => '测试', + 'account' => 'account-01', + ], 5000)->andReturn($this->dashboardData()); + $this->app->instance(PlatformPromotionAccountRepository::class, $repository); + + $this->user->attachPermission( + Permission::where('name', 'read-admin-panel')->firstOrFail() + ); + + $response = $this->loginAs()->get(route('business.pages.export', [ + 'section' => 'billing-transactions', + 'page' => 'platform-promotion-accounts', + 'tab' => 'jd', + 'month' => '2026-08', + 'shop_name' => '测试', + 'account' => 'account-01', + ])); + + $response->assertOk(); + $response->assertHeader('Content-Type', 'text/csv; charset=UTF-8'); + $disposition = (string) $response->headers->get('Content-Disposition'); + $this->assertStringContainsString("filename*=utf-8''", $disposition); + $this->assertStringContainsString('2026-08.csv', $disposition); + $this->assertStringContainsString('测试店铺', $response->streamedContent()); + } + + private function dashboardData(): array + { + return [ + 'jd' => [[ + 'shop_name' => '测试店铺', + 'account' => 'account-01', + 'show_date' => '2026-08-01', + 'trade_type_name' => '充值', + 'amount' => 100, + 'balance_amount' => 100, + 'remark' => '测试记录', + ]], + 'jdSummary' => ['income' => 100, 'expense' => 0, 'record_count' => 1], + 'dy' => [], + 'dySummary' => [], + 'dyStatus' => [], + 'dw' => [], + 'dwSummary' => [], + 'vipSales' => [], + 'vipTax' => [], + 'vipMarketing' => [], + 'vipSummary' => [], + ]; + } +}