64 lines
2.2 KiB
PHP
64 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\EcommerceFinance\Repositories\PromotionCostRowRepository;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class PromotionCostImportTest extends FeatureTestCase
|
|
{
|
|
public function test_import_command_reads_monthly_promotion_rows(): void
|
|
{
|
|
$path = tempnam(sys_get_temp_dir(), 'jst-promotion') . '.xlsx';
|
|
$sheet = new Spreadsheet();
|
|
$sheet->getActiveSheet()->fromArray([
|
|
['店铺', '商品编码', '款式编码', '店铺商品编码', '店铺款式编码', '线上颜色规格', '8001201直通车/钻展/快车等'],
|
|
['天猫-测试店', 'SKU-1', 'STYLE-1', 'SHOP-SKU-1', 'SHOP-STYLE-1', '黑色', 12.34],
|
|
]);
|
|
(new Xlsx($sheet))->save($path);
|
|
|
|
$this->artisan('order-data:import-promotion-cost', [
|
|
'file' => $path,
|
|
'--period' => '2026-06',
|
|
])->assertSuccessful();
|
|
|
|
$this->assertDatabaseHas('ops_promotion_cost_rows', [
|
|
'source_period' => '2026-06',
|
|
'shop_name' => '天猫-测试店',
|
|
'product_code' => 'SKU-1',
|
|
'promotion_fee' => 12.34,
|
|
]);
|
|
|
|
@unlink($path);
|
|
}
|
|
|
|
public function test_imported_month_is_served_before_the_daily_mirror(): void
|
|
{
|
|
DB::table('ops_promotion_cost_rows')->insert(PromotionCostRowRepository::toRecord([
|
|
'shop_name' => '天猫-测试店',
|
|
'product_code' => 'SKU-1',
|
|
'style_code' => 'STYLE-1',
|
|
'shop_product_code' => 'SHOP-SKU-1',
|
|
'shop_style_code' => 'SHOP-STYLE-1',
|
|
'online_color_spec' => '黑色',
|
|
'promotion_fee' => 12.34,
|
|
], '2026-06'));
|
|
|
|
$this->loginAs()->get(route('business.pages.show', [
|
|
'section' => 'order-data',
|
|
'page' => 'raw-data',
|
|
'tab' => 'promotion-expenses',
|
|
'date' => '2026-06-30',
|
|
'shop_name' => ['天猫-测试店'],
|
|
]))
|
|
->assertOk()
|
|
->assertSeeText('天猫-测试店')
|
|
->assertSeeText('SKU-1')
|
|
->assertSeeText('12.34')
|
|
->assertSeeText('IMPORTED');
|
|
}
|
|
}
|