diff --git a/app/Http/Controllers/Business/Pages.php b/app/Http/Controllers/Business/Pages.php index 9dc7391a7..8bd465f69 100644 --- a/app/Http/Controllers/Business/Pages.php +++ b/app/Http/Controllers/Business/Pages.php @@ -93,7 +93,7 @@ class Pages extends Controller 'jd-promotion', 'douyin-promotion', 'dewu-promotion', 'vip-promotion', ]; - /** @var list 推广账户流水已合并到营销账户账单页的四个平台页签 */ + /** @var list 推广账户流水及唯品会税务数据已合并到营销账户账单页的页签 */ protected const PROMOTION_MARKETING_TABS = [ 'jd-promotion', 'douyin-promotion', 'dewu-promotion', 'vip-promotion', ]; @@ -1185,6 +1185,34 @@ class Pages extends Controller return response()->streamDownload(function () use ($data, $platform): void { $csv = fopen('php://output', 'w'); fputs($csv, chr(0xEF) . chr(0xBB) . chr(0xBF)); + + if ($platform === 'vip') { + fputcsv($csv, [ + '平台', '店铺', '平台店铺', '申报金额(元)', '退货订单数', + '退货服务金额(元)', '退货商品金额(元)', '销售订单数', + '销售服务金额(元)', '销售商品金额(元)', '交易笔数', '交易时间', + ]); + foreach ($data['vipTax'] ?? [] as $row) { + fputcsv($csv, [ + '唯品会税务数据', + $row['shopName'] ?? '', + $row['storeName'] ?? '', + $row['reportAmount'] ?? '', + $row['returnOrderCount'] ?? '', + $row['returnServiceAmount'] ?? '', + $row['returnSkuAmount'] ?? '', + $row['saleOrderCount'] ?? '', + $row['salesServiceAmount'] ?? '', + $row['salesSkuAmount'] ?? '', + $row['transactionNum'] ?? '', + $row['transactionTime'] ?? '', + ]); + } + fclose($csv); + + return; + } + fputcsv($csv, ['平台', '店铺/账户', '日期', '类型', '金额(元)', '余额(元)', '备注']); $emit = static function (string $platform, array $rows, array $map) use ($csv): void { foreach ($rows as $row) { @@ -1205,8 +1233,6 @@ class Pages extends Controller $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'] ?? '']); } elseif ($platform === 'dewu') { $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'] ?? '']); - } else { - $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); }, '店铺营销账户账单_' . $platform . '_' . $filters['month'] . '.csv', [ diff --git a/config/business_navigation.php b/config/business_navigation.php index c94684667..c062e6985 100644 --- a/config/business_navigation.php +++ b/config/business_navigation.php @@ -362,7 +362,7 @@ return [ ['slug' => 'jd-promotion', 'title' => '京东京准通'], ['slug' => 'douyin-promotion', 'title' => '抖音千川'], ['slug' => 'dewu-promotion', 'title' => '得物推广账户'], - ['slug' => 'vip-promotion', 'title' => '唯品会推广'], + ['slug' => 'vip-promotion', 'title' => '唯品会税务数据'], ], ], ['slug' => 'deposit-account-balance', 'title' => '店铺保证金账户余额'], diff --git a/modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php b/modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php index a54b0b282..4d14b1736 100644 --- a/modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php +++ b/modules/EcommerceFinance/Repositories/PlatformPromotionAccountRepository.php @@ -6,7 +6,7 @@ use InvalidArgumentException; use Modules\EcommerceFinance\Services\UpstreamReadOnlyQuery; use Modules\EcommerceFinance\Services\UpstreamReadOnlyQueryFactory; -/** 固定字段、固定表的四平台推广账户只读查询。 */ +/** 固定字段、固定表的推广账户及唯品会税务数据只读查询。 */ class PlatformPromotionAccountRepository { private const SOURCE = 'js_data_middle_platform'; @@ -18,7 +18,7 @@ class PlatformPromotionAccountRepository public function dashboard(array $filters, int $limit = 200, ?string $platform = null): array { if ($platform !== null && ! in_array($platform, ['jd', 'douyin', 'dewu', 'vip'], true)) { - throw new InvalidArgumentException('未知的推广账户平台。'); + throw new InvalidArgumentException('未知的推广账户或税务数据平台。'); } $month = $filters['month']; @@ -34,9 +34,7 @@ class PlatformPromotionAccountRepository $douyinStatus = []; $dewu = []; $dewuSummary = []; - $vipSales = []; $vipTax = []; - $vipMarketing = []; $vipSummary = []; if ($platform === null || $platform === 'jd') { @@ -56,15 +54,12 @@ class PlatformPromotionAccountRepository } if ($platform === null || $platform === 'vip') { - $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'), + 'report_amount' => $this->sum($vipTax, 'reportAmount'), + 'return_order_count' => $this->sum($vipTax, 'returnOrderCount'), + 'sale_order_count' => $this->sum($vipTax, 'saleOrderCount'), + 'transaction_num' => $this->sum($vipTax, 'transactionNum'), ]; } @@ -76,9 +71,10 @@ class PlatformPromotionAccountRepository 'dyStatus' => $douyinStatus, 'dw' => $dewu, 'dwSummary' => $dewuSummary, - 'vipSales' => $vipSales, + // 保留旧键为空数组,避免调用方因契约变更报错;唯品会页签只使用税务明细。 + 'vipSales' => [], 'vipTax' => $vipTax, - 'vipMarketing' => $vipMarketing, + 'vipMarketing' => [], 'vipSummary' => $vipSummary, ]; } diff --git a/modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php b/modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php index 1d5022523..9552e0218 100644 --- a/modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php +++ b/modules/EcommerceFinance/View/PlatformPromotionAccountPageData.php @@ -81,10 +81,8 @@ class PlatformPromotionAccountPageData 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] ?? []); + $key = ['jd' => 'jd', 'douyin' => 'dy', 'dewu' => 'dw', 'vip' => 'vipTax'][$tab]; + $rows = $data[$key] ?? []; $page = max((int) request('page', 1), 1); $perPage = 50; diff --git a/resources/views/banking/marketing_platform_promotion_bills/partials/embedded-table.blade.php b/resources/views/banking/marketing_platform_promotion_bills/partials/embedded-table.blade.php index 2dd1220c1..229c26710 100644 --- a/resources/views/banking/marketing_platform_promotion_bills/partials/embedded-table.blade.php +++ b/resources/views/banking/marketing_platform_promotion_bills/partials/embedded-table.blade.php @@ -8,14 +8,28 @@ 'dewu' => $data['dwSummary'] ?? [], default => $data['vipSummary'] ?? [], }; - $titles = ['jd' => '京东京准通', 'douyin' => '抖音千川', 'dewu' => '得物推广账户', 'vip' => '唯品会推广']; + $titles = ['jd' => '京东京准通', 'douyin' => '抖音千川', 'dewu' => '得物推广账户', 'vip' => '唯品会税务数据']; + $filterLabel = $platform === 'vip' ? $titles[$platform] . '筛选' : $titles[$platform] . '推广账户筛选'; $columns = match ($platform) { 'jd' => [['shop_name', '店铺'], ['account', '账户'], ['show_date', '日期'], ['trade_type_name', '交易类型'], ['amount', '金额'], ['balance_amount', '余额'], ['remark', '备注']], 'douyin' => [['shopName', '店铺'], ['account', '账户'], ['qianchuanAavid', '广告账户'], ['statDate', '日期'], ['cost', '花费'], ['income', '收入'], ['transferIn', '转入'], ['transferOut', '转出'], ['balance', '余额'], ['status', '状态'], ['remark', '备注']], 'dewu' => [['shop_name', '店铺'], ['account', '账户'], ['trade_date', '日期'], ['amount_type', '金额类型'], ['flow_type', '收支类型'], ['trade_amount_yuan', '金额'], ['balance_yuan', '余额'], ['remark', '备注']], - default => [['shopName', '店铺'], ['storeName', '平台店铺'], ['accountName', '营销账户'], ['dataMonth', '月份'], ['actualSalesAmount', '实际销售额'], ['reportAmount', '申报金额'], ['totalCostYuan', '营销花费']], + default => [ + ['shopName', '店铺'], + ['storeName', '平台店铺'], + ['reportAmount', '申报金额(元)'], + ['returnOrderCount', '退货订单数'], + ['returnServiceAmount', '退货服务金额(元)'], + ['returnSkuAmount', '退货商品金额(元)'], + ['saleOrderCount', '销售订单数'], + ['salesServiceAmount', '销售服务金额(元)'], + ['salesSkuAmount', '销售商品金额(元)'], + ['transactionNum', '交易笔数'], + ['transactionTime', '交易时间'], + ], }; - $moneyFields = ['amount', 'balance_amount', 'cost', 'income', 'transferIn', 'transferOut', 'balance', 'trade_amount_yuan', 'balance_yuan', 'actualSalesAmount', 'reportAmount', 'totalCostYuan']; + $moneyFields = ['amount', 'balance_amount', 'cost', 'income', 'transferIn', 'transferOut', 'balance', 'trade_amount_yuan', 'balance_yuan', 'reportAmount', 'returnServiceAmount', 'returnSkuAmount', 'salesServiceAmount', 'salesSkuAmount']; + $integerFields = ['returnOrderCount', 'saleOrderCount', 'transactionNum']; @endphp
-
+ - + @if ($platform !== 'vip') + + @endif
净额(元)
{{ 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) }}
+
申报金额(元)
{{ number_format((float) ($summary['report_amount'] ?? 0), 2) }}
+
销售订单数
{{ number_format((int) ($summary['sale_order_count'] ?? 0)) }}
+
退货订单数
{{ number_format((int) ($summary['return_order_count'] ?? 0)) }}
+
交易笔数
{{ number_format((int) ($summary['transaction_num'] ?? 0)) }}
@endif @@ -93,7 +109,7 @@ @forelse ($rows as $row) @foreach ($columns as $column) @php($value = $row[$column[0]] ?? null) - {{ in_array($column[0], $moneyFields, true) && is_numeric($value) ? number_format((float) $value, 2) : ($value ?? '—') }} + {{ in_array($column[0], $moneyFields, true) && is_numeric($value) ? number_format((float) $value, 2) : (in_array($column[0], $integerFields, true) && is_numeric($value) ? number_format((int) $value) : ($value ?? '—')) }} @endforeach @empty 该月份暂无数据 diff --git a/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php b/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php index 9eaf313cf..18325f4bb 100644 --- a/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php +++ b/tests/Feature/Business/MarketingPlatformPromotionBillsTest.php @@ -75,6 +75,100 @@ class MarketingPlatformPromotionBillsTest extends FeatureTestCase $this->assertStringContainsString('测试店铺', $response->streamedContent()); } + public function test_vip_tab_uses_tax_declaration_data_without_marketing_fields(): void + { + $this->allowMarketingAccountBillsPage(); + + $repository = Mockery::mock(PlatformPromotionAccountRepository::class); + $repository->shouldReceive('latestMonth')->once()->andReturn('2026-08'); + $repository->shouldReceive('dashboard')->once()->with([ + 'month' => '2026-08', + 'shop_name' => '', + 'account' => '', + ], 5000, 'vip')->andReturn([ + 'vipTax' => [[ + 'shopName' => '唯品测试店', + 'storeName' => '唯品平台店', + 'reportAmount' => 123.45, + 'returnOrderCount' => 2, + 'returnServiceAmount' => 3.2, + 'returnSkuAmount' => 4.3, + 'saleOrderCount' => 10, + 'salesServiceAmount' => 5.4, + 'salesSkuAmount' => 6.5, + 'transactionNum' => 12, + 'transactionTime' => '2026-08-31 23:59:59', + ]], + 'vipSummary' => [ + 'report_amount' => 123.45, + 'return_order_count' => 2, + 'sale_order_count' => 10, + 'transaction_num' => 12, + ], + ]); + $this->app->instance(PlatformPromotionAccountRepository::class, $repository); + + $this->loginAs() + ->get(route('business.pages.show', [ + 'section' => 'billing-transactions', + 'page' => 'marketing-account-bills', + 'tab' => 'vip-promotion', + ])) + ->assertOk() + ->assertSeeText('唯品会税务数据') + ->assertSee('aria-label="唯品会税务数据筛选"', false) + ->assertSeeText('申报金额(元)') + ->assertSeeText('退货订单数') + ->assertSeeText('唯品测试店') + ->assertSeeText('123.45') + ->assertDontSeeText('营销花费') + ->assertDontSeeText('实际销售额') + ->assertDontSeeText('销售目标'); + } + + public function test_vip_export_contains_tax_declaration_fields_only(): void + { + $this->allowMarketingAccountBillsPage(); + + $repository = Mockery::mock(PlatformPromotionAccountRepository::class); + $repository->shouldReceive('latestMonth')->never(); + $repository->shouldReceive('dashboard')->once()->with([ + 'month' => '2026-08', + 'shop_name' => '', + 'account' => '', + ], 5000, 'vip')->andReturn([ + 'vipTax' => [[ + 'shopName' => '唯品测试店', + 'storeName' => '唯品平台店', + 'reportAmount' => 123.45, + 'returnOrderCount' => 2, + 'returnServiceAmount' => 3.2, + 'returnSkuAmount' => 4.3, + 'saleOrderCount' => 10, + 'salesServiceAmount' => 5.4, + 'salesSkuAmount' => 6.5, + 'transactionNum' => 12, + 'transactionTime' => '2026-08-31 23:59:59', + ]], + ]); + $this->app->instance(PlatformPromotionAccountRepository::class, $repository); + + $response = $this->loginAs()->get(route('business.pages.export', [ + 'section' => 'billing-transactions', + 'page' => 'marketing-account-bills', + 'tab' => 'vip-promotion', + 'month' => '2026-08', + ])); + + $response->assertOk()->assertDownload('_vip_2026-08.csv'); + $csv = $response->streamedContent(); + $this->assertStringContainsString('唯品会税务数据', $csv); + $this->assertStringContainsString('申报金额(元)', $csv); + $this->assertStringContainsString('唯品测试店', $csv); + $this->assertStringNotContainsString('营销花费', $csv); + $this->assertStringNotContainsString('VIP营销', $csv); + } + public function test_removed_platform_promotion_directory_returns_to_the_current_page_with_feedback(): void { $this->allowMarketingAccountBillsPage(); diff --git a/tests/Unit/EcommerceFinance/PlatformPromotionAccountRepositoryTest.php b/tests/Unit/EcommerceFinance/PlatformPromotionAccountRepositoryTest.php index c63435bca..d5a1f16cf 100644 --- a/tests/Unit/EcommerceFinance/PlatformPromotionAccountRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/PlatformPromotionAccountRepositoryTest.php @@ -52,4 +52,40 @@ class PlatformPromotionAccountRepositoryTest extends TestCase 'month' => '2026-08', ], 200, 'unknown'); } + + public function test_vip_dashboard_only_queries_tax_declaration_details(): void + { + $factory = Mockery::mock(UpstreamReadOnlyQueryFactory::class); + $query = Mockery::mock(UpstreamReadOnlyQuery::class); + $factory->shouldReceive('forSource')->once()->with('js_data_middle_platform')->andReturn($query); + $query->shouldReceive('select')->once()->with( + Mockery::on(static fn (string $sql): bool => str_contains($sql, 'vip_taxDeclarationDetail') + && str_contains($sql, 'SELECT TOP 5000') + && ! str_contains($sql, 'vip_marketingMonthlySummary') + && ! str_contains($sql, 'vip_monthlySaleProgress')), + ['2026-08'], + )->andReturn([ + [ + 'shopName' => '唯品测试店', + 'reportAmount' => 123.45, + 'returnOrderCount' => 2, + 'saleOrderCount' => 10, + 'transactionNum' => 12, + ], + ]); + + $result = (new PlatformPromotionAccountRepository($factory))->dashboard([ + 'month' => '2026-08', + 'shop_name' => '', + 'account' => '', + ], 5000, 'vip'); + + $this->assertCount(1, $result['vipTax']); + $this->assertSame([], $result['vipSales']); + $this->assertSame([], $result['vipMarketing']); + $this->assertSame(123.45, $result['vipSummary']['report_amount']); + $this->assertSame(2.0, $result['vipSummary']['return_order_count']); + $this->assertSame(10.0, $result['vipSummary']['sale_order_count']); + $this->assertSame(12.0, $result['vipSummary']['transaction_num']); + } }