parent
8a6e51e031
commit
cb4fc5af0d
@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\EcommerceFinance\Repositories\TaobaoWechatOpeningBalanceRepository;
|
||||
use Modules\EcommerceFinance\Support\TaobaoWechatBackofficeJuneEndingBalances;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
private const STORE_NAME = '天猫-华斯旗舰店';
|
||||
|
||||
public function up(): void
|
||||
{
|
||||
if (app()->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();
|
||||
}
|
||||
};
|
||||
@ -20,6 +20,7 @@ final class TaobaoWechatBackofficeJuneEndingBalances
|
||||
'天猫-亿家木旗舰店' => '7296.02',
|
||||
'天猫-亿家达旗舰店' => '290881.84',
|
||||
'天猫-亿家达宜彩专卖店' => '5155.88',
|
||||
'天猫-华斯旗舰店' => '0.00',
|
||||
'天猫-卓禾家具旗舰店' => '154923.76',
|
||||
'天猫-君特友家具专卖店' => '36040.63',
|
||||
'天猫-康帕斯旗舰店' => '0.00',
|
||||
|
||||
@ -77,11 +77,12 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase
|
||||
array_values($balances),
|
||||
));
|
||||
|
||||
$this->assertCount(21, $balances);
|
||||
$this->assertCount(22, $balances);
|
||||
$this->assertSame(83248878, $totalCents);
|
||||
$this->assertSame('27846.22', $balances['天猫-HX旗舰店101']);
|
||||
$this->assertSame('290881.84', $balances['天猫-亿家达旗舰店']);
|
||||
$this->assertSame('5155.88', $balances['天猫-亿家达宜彩专卖店']);
|
||||
$this->assertSame('0.00', $balances['天猫-华斯旗舰店']);
|
||||
$this->assertSame('1371.70', $balances['天猫-斯福恩旗舰店']);
|
||||
$this->assertSame('16486.66', $balances['淘宝-欧意朗森屿家栖企业店']);
|
||||
$this->assertSame('86802.00', $balances['淘宝-全颐家具工厂店']);
|
||||
@ -156,6 +157,40 @@ class TaobaoWechatOpeningBalanceRepositoryTest extends TestCase
|
||||
));
|
||||
}
|
||||
|
||||
public function test_huas_zero_opening_rolls_into_october_activity_without_a_prior_balance_error(): void
|
||||
{
|
||||
$this->insertOpening('天猫-华斯旗舰店', '0.00');
|
||||
$this->insertBill('天猫-华斯旗舰店', '2026-10-02 10:00:00', '10615.30', '0.00');
|
||||
$this->insertBill('天猫-华斯旗舰店', '2026-10-03 10:00:00', '0.00', '10000.00');
|
||||
$this->insertBill('天猫-华斯旗舰店', '2026-10-04 10:00:00', '0.00', '500.00');
|
||||
$this->insertBill('天猫-华斯旗舰店', '2026-10-05 10:00:00', '0.00', '15.30');
|
||||
|
||||
$septemberOpening = app(TaobaoWechatOpeningBalanceRepository::class)
|
||||
->openingBalance('天猫-华斯旗舰店', '2026-09-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, $septemberOpening['balance']);
|
||||
$this->assertSame('2026-08-31', $septemberOpening['date']);
|
||||
$this->assertSame(0.0, $octoberOpening['balance']);
|
||||
$this->assertSame('2026-09-30', $octoberOpening['date']);
|
||||
$this->assertSame(100.0, round(
|
||||
(float) $octoberOpening['balance']
|
||||
+ (float) $october->income
|
||||
- (float) $october->expense,
|
||||
2,
|
||||
));
|
||||
}
|
||||
|
||||
public function test_missing_opening_balance_is_unavailable(): void
|
||||
{
|
||||
$result = app(TaobaoWechatOpeningBalanceRepository::class)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user