diff --git a/database/migrations/2026_11_09_230000_add_taobao_wechat_yicai_backoffice_opening.php b/database/migrations/2026_11_09_230000_add_taobao_wechat_yicai_backoffice_opening.php new file mode 100644 index 00000000..0b9f836f --- /dev/null +++ b/database/migrations/2026_11_09_230000_add_taobao_wechat_yicai_backoffice_opening.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 e4470cdd..74d8340c 100644 --- a/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php +++ b/modules/EcommerceFinance/Support/TaobaoWechatBackofficeJuneEndingBalances.php @@ -19,6 +19,7 @@ final class TaobaoWechatBackofficeJuneEndingBalances '天猫-HX旗舰店101' => '27846.22', '天猫-亿家木旗舰店' => '7296.02', '天猫-亿家达旗舰店' => '290881.84', + '天猫-亿家达宜彩专卖店' => '5155.88', '天猫-卓禾家具旗舰店' => '154923.76', '天猫-君特友家具专卖店' => '36040.63', '天猫-康帕斯旗舰店' => '0.00', diff --git a/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php b/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php index 9f52f1e8..c988de40 100644 --- a/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php +++ b/tests/Unit/EcommerceFinance/TaobaoWechatOpeningBalanceRepositoryTest.php @@ -69,7 +69,7 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase $this->assertSame(2, $result['store_count']); } - public function test_backoffice_dataset_contains_the_twenty_confirmed_store_balances(): void + public function test_backoffice_dataset_contains_the_twenty_one_confirmed_store_balances(): void { $balances = TaobaoWechatBackofficeJuneEndingBalances::balances(); $totalCents = array_sum(array_map( @@ -77,12 +77,12 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase array_values($balances), )); - $this->assertCount(20, $balances); - $this->assertSame(80947454, $totalCents); + $this->assertCount(21, $balances); + $this->assertSame(81463042, $totalCents); $this->assertSame('27846.22', $balances['天猫-HX旗舰店101']); $this->assertSame('290881.84', $balances['天猫-亿家达旗舰店']); + $this->assertSame('5155.88', $balances['天猫-亿家达宜彩专卖店']); $this->assertSame('86802.00', $balances['淘宝-全颐家具工厂店']); - $this->assertArrayNotHasKey('天猫-亿家达宜彩专卖店', $balances); } public function test_missing_opening_balance_is_unavailable(): void