fix(科目映射): 未映射清单仅保留经营平台账单 #1733
@ -60,7 +60,6 @@ class AccountMappingCoverage
|
||||
'淘工厂' => '阿里巴巴',
|
||||
'唯品会MP' => '唯品会MP',
|
||||
'唯品会JX' => '唯品会JX',
|
||||
'支付宝' => '支付宝',
|
||||
];
|
||||
|
||||
/** @var array<string,list<string>> */
|
||||
@ -330,7 +329,12 @@ class AccountMappingCoverage
|
||||
$mapping = $this->coverageMappingKeys($this->store->all());
|
||||
$items = [];
|
||||
$missingRows = 0;
|
||||
$excludedRows = 0;
|
||||
foreach ($raw['pairs'] as $pair) {
|
||||
if (! $this->isPlatformBill($pair)) {
|
||||
$excludedRows += (int) $pair['source_rows'];
|
||||
continue;
|
||||
}
|
||||
if ($this->isMapped($pair, $mapping)) {
|
||||
continue;
|
||||
}
|
||||
@ -349,7 +353,7 @@ class AccountMappingCoverage
|
||||
'status' => $raw['status'],
|
||||
'scope' => 'month',
|
||||
'month' => $period,
|
||||
'source_rows' => $raw['source_rows'],
|
||||
'source_rows' => max(0, $raw['source_rows'] - $excludedRows),
|
||||
'missing_item_count' => count($items),
|
||||
'missing_row_count' => $missingRows,
|
||||
'pending_sources' => $raw['pending_sources'],
|
||||
@ -370,8 +374,13 @@ class AccountMappingCoverage
|
||||
$mapping = $this->coverageMappingKeys($this->store->all());
|
||||
$items = [];
|
||||
$missingRows = 0;
|
||||
$excludedRows = 0;
|
||||
|
||||
foreach ($raw['pairs'] as $pair) {
|
||||
if (! $this->isPlatformBill($pair)) {
|
||||
$excludedRows += (int) $pair['source_rows'];
|
||||
continue;
|
||||
}
|
||||
if ($this->isMapped($pair, $mapping)) {
|
||||
continue;
|
||||
}
|
||||
@ -396,7 +405,7 @@ class AccountMappingCoverage
|
||||
'status' => $raw['status'],
|
||||
'scope' => self::ALL_SCOPE,
|
||||
'month' => null,
|
||||
'source_rows' => $raw['source_rows'],
|
||||
'source_rows' => max(0, $raw['source_rows'] - $excludedRows),
|
||||
'missing_item_count' => count($items),
|
||||
'missing_row_count' => $missingRows,
|
||||
'pending_sources' => $raw['pending_sources'],
|
||||
@ -772,10 +781,13 @@ class AccountMappingCoverage
|
||||
continue;
|
||||
}
|
||||
$rows = (int) $group->source_rows;
|
||||
$sourceRows += $rows;
|
||||
$item = trim((string) $group->item);
|
||||
$displayItem = $item === '' ? '(未填写账单项目)' : $item;
|
||||
$platform = trim((string) $group->platform);
|
||||
if ($platform === '') {
|
||||
continue;
|
||||
}
|
||||
$sourceRows += $rows;
|
||||
$key = $platform . "\0" . $displayItem;
|
||||
|
||||
if (! isset($pairs[$key])) {
|
||||
@ -881,10 +893,13 @@ class AccountMappingCoverage
|
||||
|
||||
foreach ($groups as $group) {
|
||||
$rows = (int) $group->source_rows;
|
||||
$sourceRows += $rows;
|
||||
$item = trim((string) $group->item);
|
||||
$displayItem = $item === '' ? '(未填写账单项目)' : $item;
|
||||
$platform = trim((string) $group->platform);
|
||||
if ($platform === '') {
|
||||
continue;
|
||||
}
|
||||
$sourceRows += $rows;
|
||||
$key = $platform . "\0" . $displayItem;
|
||||
|
||||
if (! isset($pairs[$key])) {
|
||||
@ -978,6 +993,14 @@ class AccountMappingCoverage
|
||||
return isset($mapping[$platform . '|' . $item]);
|
||||
}
|
||||
|
||||
/** 清单只维护实际经营平台;资金渠道名和无法识别的店铺不进入平台账单。 */
|
||||
private function isPlatformBill(array $pair): bool
|
||||
{
|
||||
$platform = trim((string) ($pair['platform'] ?? ''));
|
||||
|
||||
return $platform !== '' && $platform !== '支付宝';
|
||||
}
|
||||
|
||||
/** @return list<string> */
|
||||
private function generations(string $periodsTable, string $start, string $end): array
|
||||
{
|
||||
|
||||
@ -49,6 +49,7 @@ class AccountMappingCoverageTest extends TestCase
|
||||
['store_name' => '天猫-另一店', 'bill_item' => '商家货款入账', 'day' => '2026-11-02 10:02:00'],
|
||||
['store_name' => '天猫-测试店', 'bill_item' => '', 'day' => '2026-11-02 10:03:00'],
|
||||
['store_name' => '天猫-测试店', 'bill_item' => '上期项目', 'day' => '2026-10-31 23:59:59'],
|
||||
['store_name' => '其他-测试店', 'bill_item' => '未知平台项目', 'day' => '2026-11-02 10:04:00'],
|
||||
]);
|
||||
$this->insertBill('taobao_alipay_bill_rows', 'occurred_at', [
|
||||
['store_name' => '支付宝-测试店', 'bill_item' => '交易收款', 'day' => '2026-11-03 10:00:00'],
|
||||
@ -92,16 +93,16 @@ class AccountMappingCoverageTest extends TestCase
|
||||
$first = $coverage->missingForMonth('2026-11');
|
||||
|
||||
$this->assertSame('ready', $first['status']);
|
||||
$this->assertSame(9, $first['source_rows']);
|
||||
$this->assertSame(4, $first['missing_item_count']);
|
||||
$this->assertSame(7, $first['missing_row_count']);
|
||||
$this->assertSame(6, $first['source_rows']);
|
||||
$this->assertSame(3, $first['missing_item_count']);
|
||||
$this->assertSame(4, $first['missing_row_count']);
|
||||
$this->assertSame([
|
||||
'交易收款|支付宝|3',
|
||||
'商家货款入账|天猫|2',
|
||||
'未映射售后费|京东|1',
|
||||
'(未填写账单项目)|天猫|1',
|
||||
], $this->missingSignature($first['items']));
|
||||
$this->assertNotContains('上期项目', array_column($first['items'], 'item'));
|
||||
$this->assertNotContains('未知平台项目', array_column($first['items'], 'item'));
|
||||
$this->assertNotContains('wx商户费', array_column($first['items'], 'item'));
|
||||
|
||||
$snapshotFiles = glob(
|
||||
@ -115,14 +116,14 @@ class AccountMappingCoverageTest extends TestCase
|
||||
Cache::flush();
|
||||
$persisted = app(AccountMappingCoverage::class)->missingForMonth('2026-11');
|
||||
$this->assertSame('ready', $persisted['status']);
|
||||
$this->assertSame(9, $persisted['source_rows']);
|
||||
$this->assertSame(6, $persisted['source_rows']);
|
||||
$this->assertSame($this->missingSignature($first['items']), $this->missingSignature($persisted['items']));
|
||||
|
||||
$this->rule($store, '天猫', '商家货款入账');
|
||||
$second = app(AccountMappingCoverage::class)->missingForMonth('2026-11');
|
||||
|
||||
$this->assertSame(3, $second['missing_item_count']);
|
||||
$this->assertSame(5, $second['missing_row_count']);
|
||||
$this->assertSame(2, $second['missing_item_count']);
|
||||
$this->assertSame(2, $second['missing_row_count']);
|
||||
$this->assertNotContains('商家货款入账', array_column($second['items'], 'item'));
|
||||
}
|
||||
|
||||
@ -136,6 +137,7 @@ class AccountMappingCoverageTest extends TestCase
|
||||
['store_name' => '天猫-测试店', 'bill_item' => '跨月未映射', 'day' => '2026-07-03 10:00:00'],
|
||||
['store_name' => '天猫-测试店', 'bill_item' => '跨月未映射', 'day' => '2026-11-03 10:00:00'],
|
||||
['store_name' => '天猫-测试店', 'bill_item' => '已映射项目', 'day' => '2026-10-03 10:00:00'],
|
||||
['store_name' => '支付宝-测试店', 'bill_item' => '资金账户项目', 'day' => '2026-10-03 10:00:00'],
|
||||
]);
|
||||
|
||||
$coverage = app(AccountMappingCoverage::class);
|
||||
@ -160,6 +162,7 @@ class AccountMappingCoverageTest extends TestCase
|
||||
['2026-06', '2026-07', '2026-11'],
|
||||
$summary['items'][0]['months'],
|
||||
);
|
||||
$this->assertNotContains('资金账户项目', array_column($summary['items'], 'item'));
|
||||
|
||||
$snapshotFiles = glob(
|
||||
$this->storageRoot . '/app/account-mapping/coverage-snapshots/all-*.json',
|
||||
@ -203,6 +206,59 @@ class AccountMappingCoverageTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function test_retained_snapshot_hides_payment_channel_and_unknown_platform_rows(): void
|
||||
{
|
||||
$directory = $this->storageRoot . '/app/account-mapping/coverage-snapshots';
|
||||
File::ensureDirectoryExists($directory);
|
||||
File::put($directory . '/all-old.json', json_encode([
|
||||
'version' => 1,
|
||||
'month' => 'all',
|
||||
'source_key' => 'old-source',
|
||||
'refreshed_at' => '2026-12-01 08:00:00',
|
||||
'raw' => [
|
||||
'status' => 'ready',
|
||||
'source_rows' => 10,
|
||||
'pending_sources' => [],
|
||||
'pairs' => [
|
||||
[
|
||||
'platform' => '天猫',
|
||||
'platform_label' => '天猫',
|
||||
'item' => '平台账单项目',
|
||||
'source_rows' => 4,
|
||||
'source_labels' => ['淘系支付宝'],
|
||||
'raw_items' => ['平台账单项目'],
|
||||
'months' => ['2026-11'],
|
||||
],
|
||||
[
|
||||
'platform' => '支付宝',
|
||||
'platform_label' => '支付宝',
|
||||
'item' => '资金账户项目',
|
||||
'source_rows' => 3,
|
||||
'source_labels' => ['淘系支付宝'],
|
||||
'raw_items' => ['资金账户项目'],
|
||||
'months' => ['2026-11'],
|
||||
],
|
||||
[
|
||||
'platform' => '',
|
||||
'platform_label' => '未识别平台',
|
||||
'item' => '未知店铺项目',
|
||||
'source_rows' => 3,
|
||||
'source_labels' => ['淘系支付宝'],
|
||||
'raw_items' => ['未知店铺项目'],
|
||||
'months' => ['2026-11'],
|
||||
],
|
||||
],
|
||||
],
|
||||
], JSON_UNESCAPED_UNICODE | JSON_THROW_ON_ERROR));
|
||||
|
||||
$summary = app(AccountMappingCoverage::class)->missingAcrossMonths();
|
||||
|
||||
$this->assertSame('ready', $summary['status']);
|
||||
$this->assertSame(4, $summary['source_rows']);
|
||||
$this->assertSame(1, $summary['missing_item_count']);
|
||||
$this->assertSame('平台账单项目', $summary['items'][0]['item']);
|
||||
}
|
||||
|
||||
public function test_interrupted_refresh_request_is_recovered_after_stale_timeout(): void
|
||||
{
|
||||
$coverage = app(AccountMappingCoverage::class);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user