fix: align vip tab with tax declaration data

This commit is contained in:
404877757@qq.com 2026-09-07 17:02:03 +08:00
parent c3719c2240
commit d66f0cf119
7 changed files with 197 additions and 31 deletions

View File

@ -93,7 +93,7 @@ class Pages extends Controller
'jd-promotion', 'douyin-promotion', 'dewu-promotion', 'vip-promotion',
];
/** @var list<string> 推广账户流水已合并到营销账户账单页的四个平台页签 */
/** @var list<string> 推广账户流水及唯品会税务数据已合并到营销账户账单页的页签 */
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', [

View File

@ -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' => '店铺保证金账户余额'],

View File

@ -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,
];
}

View File

@ -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;

View File

@ -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
<style>
.marketing-platform-promotion-page { color: #171717; }
@ -47,10 +61,12 @@
</style>
<div class="marketing-platform-promotion-page">
<form method="GET" class="promotion-toolbar" aria-label="{{ $titles[$platform] }}推广账户筛选">
<form method="GET" class="promotion-toolbar" aria-label="{{ $filterLabel }}">
<label>数据月份 <input type="month" name="month" value="{{ $filters['month'] ?? now()->format('Y-m') }}" required></label>
<label>店铺 <input type="text" name="shop_name" value="{{ $filters['shop_name'] ?? '' }}" placeholder="店铺名称"></label>
<label>账户 <input type="text" name="account" value="{{ $filters['account'] ?? '' }}" placeholder="账户名称"></label>
@if ($platform !== 'vip')
<label>账户 <input type="text" name="account" value="{{ $filters['account'] ?? '' }}" placeholder="账户名称"></label>
@endif
<button class="biz-btn biz-btn-primary" type="submit">查询</button>
<a class="biz-btn biz-btn-ghost" href="{{ route('business.pages.export', [
'section' => request()->route('section') ?? 'billing-transactions',
@ -80,10 +96,10 @@
<div class="biz-card promotion-card"><div class="promotion-card-title">净额(元)</div><div class="promotion-kpi">{{ number_format((float) ($summary['net'] ?? 0), 2) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">流水笔数</div><div class="promotion-kpi">{{ number_format((int) ($summary['record_count'] ?? 0)) }}</div></div>
@else
<div class="biz-card promotion-card"><div class="promotion-card-title">实际销售额(元)</div><div class="promotion-kpi">{{ number_format((float) ($summary['sales'] ?? 0), 2) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">销售目标(元)</div><div class="promotion-kpi">{{ number_format((float) ($summary['target'] ?? 0), 2) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">涉税申报(元)</div><div class="promotion-kpi">{{ number_format((float) ($summary['tax'] ?? 0), 2) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">营销花费(元)</div><div class="promotion-kpi">{{ number_format((float) ($summary['marketing_cost'] ?? 0), 2) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">申报金额(元)</div><div class="promotion-kpi">{{ number_format((float) ($summary['report_amount'] ?? 0), 2) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">销售订单数</div><div class="promotion-kpi">{{ number_format((int) ($summary['sale_order_count'] ?? 0)) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">退货订单数</div><div class="promotion-kpi">{{ number_format((int) ($summary['return_order_count'] ?? 0)) }}</div></div>
<div class="biz-card promotion-card"><div class="promotion-card-title">交易笔数</div><div class="promotion-kpi">{{ number_format((int) ($summary['transaction_num'] ?? 0)) }}</div></div>
@endif
</div>
@ -93,7 +109,7 @@
@forelse ($rows as $row)
<tr>@foreach ($columns as $column)
@php($value = $row[$column[0]] ?? null)
<td>{{ in_array($column[0], $moneyFields, true) && is_numeric($value) ? number_format((float) $value, 2) : ($value ?? '—') }}</td>
<td>{{ 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 ?? '—')) }}</td>
@endforeach</tr>
@empty
<tr><td colspan="{{ count($columns) }}">该月份暂无数据</td></tr>

View File

@ -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();

View File

@ -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']);
}
}