diff --git a/modules/EcommerceFinance/Repositories/DouyinAuthoritativeBillRepository.php b/modules/EcommerceFinance/Repositories/DouyinAuthoritativeBillRepository.php index 31c2cd58..f41d8ddf 100644 --- a/modules/EcommerceFinance/Repositories/DouyinAuthoritativeBillRepository.php +++ b/modules/EcommerceFinance/Repositories/DouyinAuthoritativeBillRepository.php @@ -12,7 +12,21 @@ use RuntimeException; class DouyinAuthoritativeBillRepository { - private const MERCHANT_BACKOFFICE_ZERO_STORE = '索菲亚妙选家具专卖店'; + /** + * 店铺后台已确认、但抖音6表未提供快照的 2026-06-30 期末余额。 + * + * @var array + */ + private const MERCHANT_BACKOFFICE_JUNE_ENDING_BALANCES = [ + '索菲亚妙选家具专卖店' => [ + 'balance' => 0.0, + 'source' => 'merchant_backoffice_zero', + ], + '君特友家具专卖店' => [ + 'balance' => 287706.90, + 'source' => 'merchant_backoffice_june_ending', + ], + ]; public function __construct( private readonly DatabaseManager $databases, @@ -188,7 +202,7 @@ class DouyinAuthoritativeBillRepository $store = trim((string) ($filters['store_name'] ?? '')); $normalizedStore = JushuitanShopBalanceRepository::normalizeStoreName($store); - $merchantBackofficeZero = $normalizedStore === self::MERCHANT_BACKOFFICE_ZERO_STORE; + $confirmedBackoffice = self::MERCHANT_BACKOFFICE_JUNE_ENDING_BALANCES[$normalizedStore] ?? null; $balance = 0.0; $hasSnapshot = false; @@ -210,8 +224,12 @@ class DouyinAuthoritativeBillRepository } } - if (! $hasSnapshot && ! $merchantBackofficeZero) { - return ['balance' => 0.0, 'date' => null, 'source' => 'none']; + if (! $hasSnapshot) { + if ($confirmedBackoffice === null) { + return ['balance' => 0.0, 'date' => null, 'source' => 'none']; + } + + $balance = round($confirmedBackoffice['balance'], 2); } if ($start->gt($baselineMonth)) { @@ -234,7 +252,7 @@ class DouyinAuthoritativeBillRepository 'balance' => $balance, 'date' => $start->subDay()->format('Y-m-d'), 'source' => $start->equalTo($baselineMonth) - ? ($hasSnapshot ? 'june_ending' : 'merchant_backoffice_zero') + ? ($hasSnapshot ? 'june_ending' : $confirmedBackoffice['source']) : 'previous_period', ]; } diff --git a/resources/assets/js/components/business/AccountBills.vue b/resources/assets/js/components/business/AccountBills.vue index 5bdd1586..f1318b63 100644 --- a/resources/assets/js/components/business/AccountBills.vue +++ b/resources/assets/js/components/business/AccountBills.vue @@ -371,13 +371,11 @@ export default { if(this.billType==='douyin'){ const openingSource=this.summary.opening_balance_source; const openingDate=this.summary.opening_balance_date; - const openingNote=openingSource==='none' - ?'未找到 2026-06-30 期末余额' - :(openingSource==='june_ending' - ?`截至 ${openingDate} 抖音6表期末余额` - :(openingSource==='merchant_backoffice_zero' - ?'店铺后台7月期初为0' - :`截至 ${openingDate} 上一账期期末`)); + let openingNote=`截至 ${openingDate} 上一账期期末`; + if(openingSource==='none')openingNote='未找到 2026-06-30 期末余额'; + else if(openingSource==='june_ending')openingNote=`截至 ${openingDate} 抖音6表期末余额`; + else if(openingSource==='merchant_backoffice_zero')openingNote='店铺后台7月期初为0'; + else if(openingSource==='merchant_backoffice_june_ending')openingNote='店铺后台6月期末余额'; return [ {label:'期初余额',value:this.moneyWan(this.summary.opening_balance),note:openingNote,className:''}, {label:'收入合计',value:this.moneyWan(this.summary.income),note:`${this.summary.count} 笔交易`,className:'is-income'}, diff --git a/tests/Unit/EcommerceFinance/DouyinAuthoritativeBillTest.php b/tests/Unit/EcommerceFinance/DouyinAuthoritativeBillTest.php index bb84f99d..56eb44ae 100644 --- a/tests/Unit/EcommerceFinance/DouyinAuthoritativeBillTest.php +++ b/tests/Unit/EcommerceFinance/DouyinAuthoritativeBillTest.php @@ -255,6 +255,49 @@ class DouyinAuthoritativeBillTest extends TestCase $this->assertNull($missing['summary']['opening_balance_date']); } + public function test_junteryou_uses_confirmed_backoffice_opening_and_rolls_forward(): void + { + $store = '抖音-君特友家具专卖店'; + $julyIncome = array_replace($this->row('2000000000000000401', '42898.74'), [ + '店铺' => $store, + '结算时间' => '2026-07-15 10:00:00', + ]); + $julyExpense = array_replace($this->row('2000000000000000402', '0.00', '307745.42'), [ + '店铺' => $store, + '账单项目' => '平台服务费', + '结算时间' => '2026-07-16 10:00:00', + ]); + $augustIncome = array_replace($this->row('2000000000000000403', '10.00'), [ + '店铺' => $store, + '结算时间' => '2026-08-15 10:00:00', + ]); + $this->import([$julyIncome, $julyExpense], 2, '42898.74', '307745.42', null, '2026-07'); + $this->import([$augustIncome], 1, '10.00', '0.00', null, '2026-08'); + + $repo = app(StoreReceivingDouyinBillMirrorRepository::class); + $july = $repo->paginate([ + 'store_name' => $store, + 'start' => '2026-07-01', + 'end' => '2026-07-31', + ], 'occurred_at', 'asc', 1, 10); + $august = $repo->paginate([ + 'store_name' => $store, + 'start' => '2026-08-01', + 'end' => '2026-08-31', + ], 'occurred_at', 'asc', 1, 10); + + $this->assertSame(287706.90, $july['summary']['opening_balance']); + $this->assertSame('2026-06-30', $july['summary']['opening_balance_date']); + $this->assertSame('merchant_backoffice_june_ending', $july['summary']['opening_balance_source']); + $this->assertSame(42898.74, $july['summary']['income']); + $this->assertSame(307745.42, $july['summary']['expense']); + $this->assertSame(22860.22, $july['summary']['balance']); + $this->assertSame(22860.22, $august['summary']['opening_balance']); + $this->assertSame('2026-07-31', $august['summary']['opening_balance_date']); + $this->assertSame('previous_period', $august['summary']['opening_balance_source']); + $this->assertSame(22870.22, $august['summary']['balance']); + } + private function import( array $rows, int $count, diff --git a/tests/Unit/View/AccountBillsTableTest.php b/tests/Unit/View/AccountBillsTableTest.php index 437995f2..a261a09d 100644 --- a/tests/Unit/View/AccountBillsTableTest.php +++ b/tests/Unit/View/AccountBillsTableTest.php @@ -214,6 +214,8 @@ class AccountBillsTableTest extends TestCase $this->assertStringContainsString("if(this.billType==='douyin')", $source); $this->assertStringContainsString('抖音6表期末余额', $source); $this->assertStringContainsString('店铺后台7月期初为0', $source); + $this->assertStringContainsString("openingSource==='merchant_backoffice_june_ending'", $source); + $this->assertStringContainsString('店铺后台6月期末余额', $source); $this->assertStringContainsString('上一账期期末', $source); $this->assertStringContainsString("note:'期初余额 + 收入合计 - 支出合计'", $source); $this->assertLessThan(