66 lines
2.6 KiB
PHP
66 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Business;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Modules\EcommerceFinance\Repositories\AfterSalesCostRowRepository;
|
|
use Modules\EcommerceFinance\View\OrderDataPageData;
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
|
|
use Tests\Feature\FeatureTestCase;
|
|
|
|
class AfterSalesCostImportTest extends FeatureTestCase
|
|
{
|
|
public function test_imported_rows_are_served_before_the_mirror(): void
|
|
{
|
|
DB::table('ops_after_sales_cost_rows')->insert(AfterSalesCostRowRepository::toRecord([
|
|
'shop_name' => '天猫-亿家达旗舰店',
|
|
'shop_code' => '18526685',
|
|
'online_order_no' => '5120748758529014849',
|
|
'internal_order_no' => '8064260',
|
|
'product_code' => 'SJ038020N1410V02',
|
|
'order_time' => '2026-06-21 18:00:00',
|
|
'product_quantity' => 1,
|
|
'product_amount' => 385.43,
|
|
'product_cost' => 110.53,
|
|
'cost_source' => '商品成本',
|
|
'combine_type' => '组合单品',
|
|
]));
|
|
|
|
$result = app(OrderDataPageData::class)->afterSalesRows([
|
|
'from' => '2026-06-01',
|
|
'to' => '2026-06-30',
|
|
'shop_names' => ['天猫-亿家达旗舰店'],
|
|
'order_no' => '',
|
|
'sku_id' => '',
|
|
], 1, 20);
|
|
|
|
$this->assertSame('imported', $result['status']['X-Caiwu-Data-Status']);
|
|
$this->assertCount(1, $result['rows']);
|
|
$this->assertSame('SJ038020N1410V02', $result['rows'][0]['product_code']);
|
|
$this->assertEquals(110.53, $result['rows'][0]['product_cost']);
|
|
}
|
|
|
|
public function test_import_command_reads_the_jst_export_file(): void
|
|
{
|
|
$path = tempnam(sys_get_temp_dir(), 'jst') . '.xlsx';
|
|
|
|
$sheet = new Spreadsheet();
|
|
$sheet->getActiveSheet()->fromArray([
|
|
['内部订单号', '线上订单号', '店铺名称', '商品编码', '商品数量', '商品金额', '商品成本', '成本来源', '组合装', '订单时间'],
|
|
['8064260', '5120748758529014849', '天猫-亿家达旗舰店', 'SJ038051N1410V01', 1, 14.54, 4.17, '商品成本', '组合单品', '2026-06-21 18:00:00'],
|
|
]);
|
|
(new Xlsx($sheet))->save($path);
|
|
|
|
$this->artisan('order-data:import-after-sales-cost', ['file' => $path])->assertSuccessful();
|
|
|
|
$this->assertDatabaseHas('ops_after_sales_cost_rows', [
|
|
'shop_name' => '天猫-亿家达旗舰店',
|
|
'product_code' => 'SJ038051N1410V01',
|
|
'cost_source' => '商品成本',
|
|
]);
|
|
|
|
@unlink($path);
|
|
}
|
|
}
|