From 4539031eb146d58eb3794f1cb5eb384e5c382575 Mon Sep 17 00:00:00 2001 From: qiuxiang <394405259@qq.com> Date: Thu, 26 Nov 2026 17:31:25 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=A1=A5=E5=85=85=E5=B9=B3=E6=8F=90?= =?UTF-8?q?=E5=AE=B6=E5=85=B7=E5=BA=97=E9=93=BA=E6=9C=9F=E5=88=9D=E4=BD=99?= =?UTF-8?q?=E9=A2=9D=20(#1477)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加淘宝-平提家具源头工厂零期初余额,并补充生产数据修正迁移。 --- ...d_taobao_wechat_pingti_opening_balance.php | 59 +++++++++++++++++++ ...obaoWechatBackofficeJuneEndingBalances.php | 1 + ...obaoWechatOpeningBalanceRepositoryTest.php | 36 ++++++++++- 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 database/migrations/2026_11_26_180000_add_taobao_wechat_pingti_opening_balance.php diff --git a/database/migrations/2026_11_26_180000_add_taobao_wechat_pingti_opening_balance.php b/database/migrations/2026_11_26_180000_add_taobao_wechat_pingti_opening_balance.php new file mode 100644 index 00000000..6cc45d9b --- /dev/null +++ b/database/migrations/2026_11_26_180000_add_taobao_wechat_pingti_opening_balance.php @@ -0,0 +1,59 @@ +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 + { + if (app()->environment('testing') + || (string) config('system_database.mode', 'bootstrap') === 'bootstrap') { + return; + } + + DB::connection((string) config('upstream_mirrors.connection', 'business_mirror')) + ->table(TaobaoWechatOpeningBalanceRepository::TABLE) + ->where('balance_date', TaobaoWechatBackofficeJuneEndingBalances::AS_OF_DATE) + ->where('store_name', self::STORE_NAME) + ->delete(); + } +}; diff --git a/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php b/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php index 882abd10..f0bb98db 100644 --- a/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php +++ b/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php @@ -37,6 +37,7 @@ final class TaobaoWechatBackofficeJuneEndingBalances '淘宝-全颐家具工厂店' => '86802.00', '淘宝-欧意朗森屿家栖企业店' => '16486.66', '淘宝-欧意朗雅致生活家居' => '2098.00', + '淘宝-平提家具源头工厂' => '0.00', '淘宝-知木家具源头工厂店' => '0.00', '淘宝-金色阳光时尚家居' => '23709.06', ]; diff --git a/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php b/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php index 4f9b4f87..a997b512 100644 --- a/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php @@ -77,7 +77,7 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase array_values($balances), )); - $this->assertCount(23, $balances); + $this->assertCount(24, $balances); $this->assertSame(83248878, $totalCents); $this->assertSame('27846.22', $balances['天猫-HX旗舰店101']); $this->assertSame('290881.84', $balances['天猫-亿家达旗舰店']); @@ -86,6 +86,7 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase $this->assertSame('0.00', $balances['天猫-索菲亚常州专卖店']); $this->assertSame('1371.70', $balances['天猫-斯福恩旗舰店']); $this->assertSame('16486.66', $balances['淘宝-欧意朗森屿家栖企业店']); + $this->assertSame('0.00', $balances['淘宝-平提家具源头工厂']); $this->assertSame('86802.00', $balances['淘宝-全颐家具工厂店']); } @@ -225,6 +226,39 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase )); } + public function test_pingti_zero_opening_rolls_into_october_balance(): void + { + $this->insertOpening('淘宝-平提家具源头工厂', '0.00'); + $this->insertBill('淘宝-平提家具源头工厂', '2026-08-31 10:00:00', '15134.58', '4000.00'); + $this->insertBill('淘宝-平提家具源头工厂', '2026-09-30 10:00:00', '695.00', '1504.18'); + $this->insertBill('淘宝-平提家具源头工厂', '2026-10-31 10:00:00', '1000.00', '1036.01'); + + $augustOpening = app(TaobaoWechatOpeningBalanceRepository::class) + ->openingBalance('淘宝-平提家具源头工厂', '2026-08-01'); + $octoberOpening = app(TaobaoWechatOpeningBalanceRepository::class) + ->openingBalance('淘宝-平提家具源头工厂', '2026-10-01'); + $october = DB::connection('business_mirror')->table('taobao_wechat_bill_rows') + ->where('store_name', '淘宝-平提家具源头工厂') + ->where('occurred_at', '>=', '2026-10-01 00:00:00') + ->where('occurred_at', '<', '2026-11-01 00:00:00') + ->selectRaw( + 'COALESCE(SUM(income_amount), 0) AS income, ' + . 'COALESCE(SUM(expense_amount), 0) AS expense' + ) + ->first(); + + $this->assertSame(0.0, $augustOpening['balance']); + $this->assertSame('2026-07-31', $augustOpening['date']); + $this->assertSame(10325.4, $octoberOpening['balance']); + $this->assertSame('2026-09-30', $octoberOpening['date']); + $this->assertSame(10289.39, round( + (float) $octoberOpening['balance'] + + (float) $october->income + - (float) $october->expense, + 2, + )); + } + public function test_missing_opening_balance_is_unavailable(): void { $result = app(TaobaoWechatOpeningBalanceRepository::class)