新增订单利润页面、共享镜像查询、筛选聚合、明细展示、列设置与导出。 验证:20 项测试通过,249 个断言;真实页面代表订单 26092142570188 验收通过。
190 lines
7.7 KiB
PHP
190 lines
7.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Unit\EcommerceFinance;
|
|
|
|
use Illuminate\Database\Schema\Blueprint;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Modules\EcommerceFinance\Repositories\GoodsProfitAfsRepository;
|
|
use Modules\EcommerceFinance\Repositories\OrderProfitRepository;
|
|
use Modules\EcommerceFinance\Services\GoodsProfitAfsLookupSchema;
|
|
use Tests\TestCase;
|
|
|
|
class OrderProfitRepositoryTest extends TestCase
|
|
{
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
config([
|
|
'database.connections.business_mirror' => [
|
|
'driver' => 'sqlite', 'database' => ':memory:', 'prefix' => '',
|
|
],
|
|
'upstream_mirrors.connection' => 'business_mirror',
|
|
]);
|
|
DB::purge('business_mirror');
|
|
|
|
$schema = Schema::connection('business_mirror');
|
|
$schema->create(GoodsProfitAfsLookupSchema::TABLE, function (Blueprint $table): void {
|
|
$table->integer('id')->primary();
|
|
$table->string('_mirror_key')->unique();
|
|
foreach ([
|
|
'undefined1', 'undefined2', 'undefined3', 'undefined4', 'undefined7',
|
|
'undefined8', 'undefined10', 'undefined11', 'undefined12', 'undefined13',
|
|
'undefined18', 'undefined20', 'undefined21', 'undefined22', 'undefined43',
|
|
'undefined45', 'undefined46', 'undefined47', 'undefined48', 'undefined49',
|
|
'undefined50', 'undefined51', 'undefined52', 'undefined53', 'undefined54',
|
|
'undefined56', 'undefined59', 'undefined61', 'undefined66', 'undefined72',
|
|
'undefined73', 'undefined151',
|
|
] as $column) {
|
|
$table->string($column)->nullable();
|
|
}
|
|
});
|
|
$schema->create('ops_jst_goods_profit_kpi_items_afs_schemas', function (Blueprint $table): void {
|
|
$table->integer('id');
|
|
$table->string('column');
|
|
$table->string('name');
|
|
});
|
|
$schema->create('business_mirror_table_states', function (Blueprint $table): void {
|
|
$table->string('dataset_key');
|
|
$table->dateTime('initial_completed_at')->nullable();
|
|
$table->dateTime('last_succeeded_at')->nullable();
|
|
$table->string('last_error_code')->nullable();
|
|
});
|
|
|
|
$db = DB::connection('business_mirror');
|
|
$db->table('business_mirror_table_states')->insert([
|
|
'dataset_key' => GoodsProfitAfsRepository::MAIN_DATASET,
|
|
'initial_completed_at' => '2026-10-01 00:00:00',
|
|
'last_succeeded_at' => '2026-10-30 10:00:00',
|
|
]);
|
|
|
|
$headers = [
|
|
'undefined1' => '内部订单号',
|
|
'undefined2' => '线上订单号',
|
|
'undefined3' => '子订单号',
|
|
'undefined4' => '售后单号',
|
|
'undefined7' => '订单时间',
|
|
'undefined8' => '店铺名称',
|
|
'undefined10' => '商品编码',
|
|
'undefined11' => '款式编码',
|
|
'undefined12' => '店铺商品编码',
|
|
'undefined13' => '店铺款式编码',
|
|
'undefined18' => '颜色及规格',
|
|
'undefined20' => '商品数量',
|
|
'undefined21' => '商品金额',
|
|
'undefined22' => '商品成本',
|
|
'undefined43' => '发货前退款金额',
|
|
'undefined45' => '发货前退平台补贴',
|
|
'undefined46' => '发货后申请数量',
|
|
'undefined47' => '发货后申请金额',
|
|
'undefined48' => '发货后申请成本',
|
|
'undefined49' => '发货后退回数量',
|
|
'undefined50' => '发货后退回金额',
|
|
'undefined51' => '发货后退回成本',
|
|
'undefined52' => '发货后退款金额',
|
|
'undefined53' => '发货后退款成本',
|
|
'undefined54' => '发货后退平台补贴',
|
|
'undefined56' => '退款类型',
|
|
'undefined59' => '分类单',
|
|
'undefined61' => '组合装',
|
|
'undefined66' => '发货仓库',
|
|
'undefined72' => '快递单号',
|
|
'undefined73' => '快递公司',
|
|
'undefined151' => '商品名称',
|
|
];
|
|
foreach ($headers as $index => $name) {
|
|
$db->table('ops_jst_goods_profit_kpi_items_afs_schemas')->insert([
|
|
'id' => (int) substr($index, 9),
|
|
'column' => $index,
|
|
'name' => $name,
|
|
]);
|
|
}
|
|
|
|
$base = [
|
|
'undefined2' => '26092142570188',
|
|
'undefined3' => '26092142570188_SKU-1E73E04C8008B3AF',
|
|
'undefined7' => '2026/9/21 9:40:36',
|
|
'undefined8' => '唯品会MP-卓禾家具特卖旗舰店',
|
|
'undefined10' => 'BJ018706N68V01',
|
|
'undefined11' => 'BJ0187',
|
|
'undefined12' => 'SKU-1E73E04C8008B3AF',
|
|
'undefined13' => 'SPU-1E73E04C800003AF',
|
|
'undefined18' => '胡桃色',
|
|
'undefined59' => '否',
|
|
'undefined61' => '非组合',
|
|
'undefined66' => '简尚-崔桥工厂仓',
|
|
'undefined72' => '76001654919378',
|
|
'undefined73' => '新北中通',
|
|
'undefined151' => '款式一 60/40/53 胡桃色',
|
|
];
|
|
$db->table(GoodsProfitAfsLookupSchema::TABLE)->insert(array_replace($base, [
|
|
'id' => 1,
|
|
'_mirror_key' => 'row-1',
|
|
'undefined1' => '9470588',
|
|
'undefined4' => '',
|
|
'undefined20' => '1',
|
|
'undefined21' => '259',
|
|
'undefined22' => '75',
|
|
'undefined43' => '0',
|
|
'undefined45' => '0',
|
|
'undefined46' => '0',
|
|
'undefined47' => '0',
|
|
'undefined48' => '0',
|
|
'undefined49' => '0',
|
|
'undefined50' => '0',
|
|
'undefined51' => '0',
|
|
'undefined52' => '0',
|
|
'undefined53' => '0',
|
|
'undefined54' => '0',
|
|
'undefined56' => '',
|
|
]));
|
|
$db->table(GoodsProfitAfsLookupSchema::TABLE)->insert(array_replace($base, [
|
|
'id' => 2,
|
|
'_mirror_key' => 'row-2',
|
|
'undefined1' => '9470588',
|
|
'undefined4' => '743208893',
|
|
'undefined20' => '0',
|
|
'undefined21' => '0',
|
|
'undefined22' => '0',
|
|
'undefined43' => '0',
|
|
'undefined45' => '0',
|
|
'undefined46' => '0',
|
|
'undefined47' => '178.3',
|
|
'undefined48' => '0',
|
|
'undefined49' => '0',
|
|
'undefined50' => '0',
|
|
'undefined51' => '0',
|
|
'undefined52' => '20',
|
|
'undefined53' => '0',
|
|
'undefined54' => '0',
|
|
'undefined56' => '仅退款',
|
|
]));
|
|
}
|
|
|
|
public function test_order_rows_are_aggregated_from_item_and_refund_lines(): void
|
|
{
|
|
$repository = app(OrderProfitRepository::class);
|
|
$result = $repository->paginate([
|
|
'from' => '2026-10-01',
|
|
'to' => '2026-10-31',
|
|
'order_no' => '26092142570188',
|
|
'shop_name' => '',
|
|
'sku_id' => '',
|
|
], 1, 25);
|
|
|
|
$this->assertCount(1, $result['rows']);
|
|
$row = $result['rows'][0];
|
|
$this->assertSame('唯品会MP-卓禾家具特卖旗舰店', $row['shop_name']);
|
|
$this->assertSame('26092142570188', $row['online_order_no']);
|
|
$this->assertSame('9470588', $row['internal_order_no']);
|
|
$this->assertEquals(75.0, $row['cost_amount']);
|
|
$this->assertEquals(20.0, $row['refund_amount']);
|
|
$this->assertEquals(178.3, $row['post_application_amount']);
|
|
$this->assertEquals(0.0, $row['post_return_amount']);
|
|
$this->assertSame('仅退款', $row['refund_type']);
|
|
$this->assertCount(2, $row['items']);
|
|
$this->assertSame(['唯品会MP-卓禾家具特卖旗舰店'], $repository->shopNames());
|
|
}
|
|
}
|