- 新增 ec_account_ledger_remarks 映射表与 account-ledger-remarks:import 导入命令(平台/账单项目/总账备注) - 新增 AccountLedgerRemarkMap:按店铺名前缀识别平台,无前缀时用页签默认平台;缺失匹配保持空白 - 全部账户页签(含淘系支付宝自有列定义)在「店铺/店铺名称」右侧新增「总账备注」列,页面/列设置/导出共用同一份列定义 - 控制器在分页与导出流读取时补齐 payload.ledger_remark,不改动上游账单与共享镜像数据 - 用例:新增 AccountLedgerRemarkMapTest;修正唯品会 JX/MP 列清单断言
87 lines
3.5 KiB
PHP
87 lines
3.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\Cache;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Modules\EcommerceFinance\AccountBillColumns;
|
|
use Modules\EcommerceFinance\Services\AccountLedgerRemarkMap;
|
|
use Tests\TestCase;
|
|
|
|
class AccountLedgerRemarkMapTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
Cache::flush();
|
|
Schema::dropIfExists('ec_account_ledger_remarks');
|
|
Schema::create('ec_account_ledger_remarks', function (Blueprint $table): void {
|
|
$table->id();
|
|
$table->string('platform', 32);
|
|
$table->string('bill_item', 191);
|
|
$table->string('ledger_remark', 191);
|
|
$table->timestamps();
|
|
});
|
|
}
|
|
|
|
protected function tearDown(): void
|
|
{
|
|
Cache::flush();
|
|
Schema::dropIfExists('ec_account_ledger_remarks');
|
|
|
|
parent::tearDown();
|
|
}
|
|
|
|
public function test_every_account_tab_places_ledger_remark_right_after_the_store_column(): void
|
|
{
|
|
foreach (AccountBillColumns::map() as $tab => $definition) {
|
|
$columns = $definition['columns'] ?? [];
|
|
$labels = array_map(static fn (array $column): string => (string) $column[0], $columns);
|
|
|
|
$storeIndex = null;
|
|
foreach ($labels as $index => $label) {
|
|
if (in_array($label, ['店铺', '店铺名称'], true)) {
|
|
$storeIndex = $index;
|
|
break;
|
|
}
|
|
}
|
|
|
|
$this->assertNotNull($storeIndex, $tab . ' 缺少店铺列');
|
|
$this->assertSame('总账备注', $labels[$storeIndex + 1] ?? null, $tab . ' 的总账备注没有紧跟店铺列');
|
|
$this->assertSame('payload.ledger_remark', $columns[$storeIndex + 1][1] ?? null, $tab . ' 的总账备注字段不正确');
|
|
}
|
|
}
|
|
|
|
public function test_it_matches_platform_and_bill_item_then_decorates_rows(): void
|
|
{
|
|
$now = now();
|
|
DB::table('ec_account_ledger_remarks')->insert([
|
|
['platform' => '抖音', 'bill_item' => '保费扣除', 'ledger_remark' => '运费险', 'created_at' => $now, 'updated_at' => $now],
|
|
['platform' => '天猫', 'bill_item' => '天猫佣金', 'ledger_remark' => '平台佣金', 'created_at' => $now, 'updated_at' => $now],
|
|
]);
|
|
|
|
$map = new AccountLedgerRemarkMap();
|
|
|
|
$this->assertSame('运费险', $map->remark('抖音-乾廷润凯家具专卖店', '抖音', '保费扣除'));
|
|
$this->assertSame('平台佣金', $map->remark('天猫-卓尔家具旗舰店', '淘宝', '天猫佣金'));
|
|
$this->assertSame('平台佣金', $map->remark('没有平台前缀的店铺', '天猫', '天猫佣金'));
|
|
$this->assertNull($map->remark('抖音-乾廷润凯家具专卖店', '抖音', '不存在的账单项目'));
|
|
|
|
$row = $map->decorate([
|
|
'store_name' => '抖音-乾廷润凯家具专卖店',
|
|
'bill_item' => '保费扣除',
|
|
'payload' => ['settle_account' => 'TouTiaoFXGZJ'],
|
|
], 'douyin');
|
|
|
|
$this->assertSame('运费险', $row['payload']['ledger_remark']);
|
|
$this->assertSame('运费险', $row['ledger_remark']);
|
|
$this->assertSame('TouTiaoFXGZJ', $row['payload']['settle_account']);
|
|
|
|
$untouched = $map->decorate(['store_name' => '抖音-xx', 'bill_item' => '未知项目', 'payload' => []], 'douyin');
|
|
$this->assertSame([], $untouched['payload']);
|
|
}
|
|
}
|