dropIfExists($table); $schema->create($table, function (Blueprint $t) { $t->string('generation'); $t->string('record_code'); $t->string('store_name'); $t->string('bill_item'); $t->string('order_no'); $t->dateTime('occurred_at'); $t->decimal('income', 18, 2); $t->decimal('expense', 18, 2); $t->text('row_data'); }); } foreach (['jd_daily_bill_periods', 'douyin_authoritative_periods'] as $table) { $schema->dropIfExists($table); $schema->create($table, function (Blueprint $t) { $t->string('active_generation'); $t->date('period_start'); $t->date('period_end'); }); DB::connection('business_mirror')->table($table)->insert(['active_generation' => 'CURRENT', 'period_start' => '2026-11-01', 'period_end' => '2026-11-21']); } (require database_path('migrations/2026_11_20_180000_index_planting_income_order_lookups.php'))->up(); $mapping = \Mockery::mock(AccountLedgerRemarkMap::class); $mapping->shouldReceive('decorate')->andReturnUsing(static fn ($row) => $row + ['ledger_remark' => '订单收入']); $repo = new PlantingReimbursementIncomeRepository(app('db'), $mapping); foreach ([ ['1', 'CURRENT', '京东-测试', 'ACCOUNT-1', 'FULL-ORDER'], ['2', 'OLD', '京东-测试', 'ACCOUNT-2', 'FULL-ORDER'], ['3', 'CURRENT', '京喜-测试', 'ACCOUNT-3', 'FULL-ORDER'], ['4', 'CURRENT', '京东-测试', 'FULL-ORDER', null], ['5', 'CURRENT', '京东-测试', 'FULL-ORDER', 'DIFFERENT-ORDER'], ['6', 'CURRENT', '京东-测试', 'FULL-ORDER-SUFFIX', null], ] as [$code, $generation, $store, $order, $online]) { $row = ['generation' => $generation, 'record_code' => $code, 'store_name' => $store, 'bill_item' => '货款(收)', 'order_no' => $order, 'occurred_at' => '2026-11-19 10:00:00', 'income' => '3.00', 'expense' => '1.00']; $row['row_data'] = json_encode($row + ['payload' => ['online_order_no' => $online]]); DB::connection('business_mirror')->table('jd_daily_bill_rows')->insert($row); } $rows = iterator_to_array($repo->records(['jd-transactions' => ['FULL-ORDER']], '2026-10-25 00:00:00', '2026-11-21 00:00:00')); $this->assertEqualsCanonicalizing(['1', '4'], array_column($rows, 'record_code')); $this->assertSame(['FULL-ORDER'], array_values(array_unique(array_column($rows, 'online_order_no')))); $this->assertSame('订单收入', $rows[0]['ledger_remark']); $jingxi = iterator_to_array($repo->records(['jingxi' => ['FULL-ORDER']], '2026-10-25 00:00:00', '2026-11-21 00:00:00')); $this->assertSame(['3'], array_column($jingxi, 'record_code')); $this->assertTrue($schema->hasIndex('jd_daily_bill_rows', 'planting_jd_order_time')); } }