CaiWuXiTong/tests/Unit/EcommerceFinance/ShengsuanOrderProfitDetailMapperTest.php
renshen d79a1eedfe feat: 成本运费异常接入完整订单商品明细 (#1004)
合并 PR #1004:补全订单商品明细并按条码识别缺成本。
2026-11-09 11:02:21 +08:00

83 lines
3.7 KiB
PHP

<?php
namespace Tests\Unit\EcommerceFinance;
use Modules\EcommerceFinance\Services\ShengsuanOrderProfitDetailMapper;
use Tests\TestCase;
class ShengsuanOrderProfitDetailMapperTest extends TestCase
{
public function test_maps_full_item_details_and_missing_cost_barcodes_by_order(): void
{
$mapper = new ShengsuanOrderProfitDetailMapper();
$snapshots = $mapper->snapshots([
'data' => [
'ords' => [
'fldHeads' => [
['fld' => 'c_900904', 'title' => '商品编码'],
['fld' => 'c_900910', 'title' => '商品名称'],
['fld' => 'c_900201', 'title' => '商品成本'],
['fld' => 'c_900407', 'title' => '商家运费'],
],
'dataList' => [
[
'c_900901' => '天猫-卓禾家具旗舰店',
'c_900902' => '5127581702031023636',
'c_900903' => '10097143',
'c_900904' => 'ZWJ003952N181V01',
'c_900910' => '书架',
'c_900201' => 0,
'c_900407' => 7.05,
],
[
'c_900901' => '天猫-卓禾家具旗舰店',
'c_900902' => '5127581702031023636',
'c_900903' => '10097143',
'c_900904' => 'ZWJ003952N181V02',
'c_900910' => '书架配件',
'c_900201' => 18.5,
'c_900407' => 0,
],
[
'c_900901' => '天猫-卓禾家具旗舰店',
'c_900902' => '5127581702031023637',
'c_900903' => '10097144',
'c_900904' => 'ZWJ003952N181V03',
'c_900910' => '置物架',
'c_900201' => 22,
'c_900407' => 6,
],
],
],
'afters' => [
'fldHeads' => [
['fld' => 'c_900904', 'title' => '商品编码'],
['fld' => 'c_900201', 'title' => '商品成本'],
],
'dataList' => [[
'c_900901' => '天猫-卓禾家具旗舰店',
'c_900902' => '5127581702031023636',
'c_900903' => '10097143',
'c_900904' => 'ZWJ003952N181V01',
'c_900201' => 0,
]],
],
],
]);
$this->assertCount(2, $snapshots);
$snapshot = collect($snapshots)->firstWhere('order_key', '天猫-卓禾家具旗舰店|5127581702031023636');
$this->assertSame(2, $snapshot['item_count']);
$this->assertSame(1, $snapshot['after_item_count']);
$this->assertSame(1, $snapshot['missing_cost_item_count']);
$this->assertSame(['ZWJ003952N181V01'], json_decode($snapshot['missing_cost_barcodes'], true));
$items = json_decode($snapshot['order_items'], true);
$this->assertSame('ZWJ003952N181V01', $items[0]['c_900904']);
$this->assertSame(18.5, $items[1]['c_900201']);
$this->assertCount(4, json_decode($snapshot['order_headers'], true));
$this->assertSame('商品编码', json_decode($snapshot['order_headers'], true)[0]['title']);
$this->assertArrayNotHasKey('source_payload', $snapshot);
}
}