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']); } }