From 5a2f4586f7df2ea98485f9a4401f24b3bcd95054 Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Thu, 26 Nov 2026 15:16:52 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E6=AD=A3=E6=A3=AE=E5=B1=BF?= =?UTF-8?q?=E5=AE=B6=E6=A0=96=E6=B7=98=E7=B3=BB=E5=BE=AE=E4=BF=A1=E5=85=AD?= =?UTF-8?q?=E6=9C=88=E6=9C=9F=E6=9C=AB=E4=BD=99=E9=A2=9D=20(#1460)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修正淘宝-欧意朗森屿家栖企业店 2026-06-30 淘系微信期末余额,并新增生产数据修正迁移。 --- ...aobao_wechat_senyu_june_ending_balance.php | 50 +++++++++++++++++++ ...obaoWechatBackofficeJuneEndingBalances.php | 2 +- ...obaoWechatOpeningBalanceRepositoryTest.php | 30 ++++++++++- 3 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 database/migrations/2026_11_26_150000_correct_taobao_wechat_senyu_june_ending_balance.php diff --git a/database/migrations/2026_11_26_150000_correct_taobao_wechat_senyu_june_ending_balance.php b/database/migrations/2026_11_26_150000_correct_taobao_wechat_senyu_june_ending_balance.php new file mode 100644 index 00000000..e83e7332 --- /dev/null +++ b/database/migrations/2026_11_26_150000_correct_taobao_wechat_senyu_june_ending_balance.php @@ -0,0 +1,50 @@ +environment('testing') + || (string) config('system_database.mode', 'bootstrap') === 'bootstrap') { + return; + } + + $connection = DB::connection((string) config('upstream_mirrors.connection', 'business_mirror')); + if (! $connection->getSchemaBuilder()->hasTable(TaobaoWechatOpeningBalanceRepository::TABLE)) { + return; + } + + $balance = TaobaoWechatBackofficeJuneEndingBalances::balances()[self::STORE_NAME] ?? null; + if ($balance === null) { + return; + } + + $importedAt = now(); + $connection->table(TaobaoWechatOpeningBalanceRepository::TABLE)->updateOrInsert( + [ + 'balance_date' => TaobaoWechatBackofficeJuneEndingBalances::AS_OF_DATE, + 'store_name' => self::STORE_NAME, + ], + [ + 'balance' => $balance, + 'source' => TaobaoWechatBackofficeJuneEndingBalances::SOURCE, + 'source_note' => TaobaoWechatBackofficeJuneEndingBalances::SOURCE_NOTE, + 'imported_at' => $importedAt, + 'updated_at' => $importedAt, + 'created_at' => $importedAt, + ], + ); + } + + public function down(): void + { + // This corrects user-supplied opening data; keep the corrected balance on rollback. + } +}; diff --git a/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php b/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php index 6587068e..28edf725 100644 --- a/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php +++ b/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php @@ -33,7 +33,7 @@ final class TaobaoWechatBackofficeJuneEndingBalances '淘宝-亿家达家居鞋柜电脑桌' => '40351.37', '淘宝-亿家达甄选企业店' => '5178.31', '淘宝-全颐家具工厂店' => '86802.00', - '淘宝-欧意朗森屿家栖企业店' => '0.00', + '淘宝-欧意朗森屿家栖企业店' => '16486.66', '淘宝-欧意朗雅致生活家居' => '2098.00', '淘宝-知木家具源头工厂店' => '0.00', '淘宝-金色阳光时尚家居' => '23709.06', diff --git a/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php b/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php index b210811e..1aa93747 100644 --- a/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php @@ -78,11 +78,12 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase )); $this->assertCount(21, $balances); - $this->assertSame(81600212, $totalCents); + $this->assertSame(83248878, $totalCents); $this->assertSame('27846.22', $balances['天猫-HX旗舰店101']); $this->assertSame('290881.84', $balances['天猫-亿家达旗舰店']); $this->assertSame('5155.88', $balances['天猫-亿家达宜彩专卖店']); $this->assertSame('1371.70', $balances['天猫-斯福恩旗舰店']); + $this->assertSame('16486.66', $balances['淘宝-欧意朗森屿家栖企业店']); $this->assertSame('86802.00', $balances['淘宝-全颐家具工厂店']); } @@ -128,6 +129,33 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase )); } + public function test_senyu_july_opening_rolls_the_june_ending_balance_before_withdrawal(): void + { + $this->insertOpening('淘宝-欧意朗森屿家栖企业店', '16486.66'); + $this->insertBill('淘宝-欧意朗森屿家栖企业店', '2026-07-13 17:21:38', '0.00', '16486.66'); + + $opening = app(TaobaoWechatOpeningBalanceRepository::class) + ->openingBalance('淘宝-欧意朗森屿家栖企业店', '2026-07-01'); + $july = DB::connection('business_mirror')->table('taobao_wechat_bill_rows') + ->where('store_name', '淘宝-欧意朗森屿家栖企业店') + ->where('occurred_at', '>=', '2026-07-01 00:00:00') + ->where('occurred_at', '<', '2026-08-01 00:00:00') + ->selectRaw( + 'COALESCE(SUM(income_amount), 0) AS income, ' + . 'COALESCE(SUM(expense_amount), 0) AS expense' + ) + ->first(); + + $this->assertSame(16486.66, $opening['balance']); + $this->assertSame('2026-06-30', $opening['date']); + $this->assertSame(0.0, round( + (float) $opening['balance'] + + (float) $july->income + - (float) $july->expense, + 2, + )); + } + public function test_missing_opening_balance_is_unavailable(): void { $result = app(TaobaoWechatOpeningBalanceRepository::class)