普通商品资料接入聚水潭物理与管理字段 (#169)

This commit is contained in:
limeng 2026-09-12 15:51:02 +08:00
parent 5b21426595
commit e56cbddfc8
4 changed files with 126 additions and 2 deletions

View File

@ -128,6 +128,7 @@ class ProductCatalogMirrorRepository
->get()
->all();
$this->attachPhysicalFields($rows);
$purchasePriceSyncStatus = $this->purchasePriceSyncStatus();
$this->attachPurchasePrices($rows, $purchasePriceSyncStatus['initialized']);
$priceChangeSyncStatus = $this->priceChangeSyncStatus();
@ -175,6 +176,7 @@ class ProductCatalogMirrorRepository
}
$this->attachPurchasePrices($rows, $purchasePriceSyncStatus['initialized']);
$this->attachPhysicalFields($rows);
$this->attachPriceChanges($rows, $priceChangeSyncStatus['initialized']);
$this->attachWorkPlatformPrices($rows, $workPlatformPriceSyncStatus['initialized']);
foreach ($rows as $row) {
@ -188,6 +190,21 @@ class ProductCatalogMirrorRepository
}
}
/** @param list<object> $rows */
private function attachPhysicalFields(array $rows): void
{
foreach ($rows as $row) {
$row->board_material = $row->other_2 ?? null;
$row->product_type = $row->item_type ?? null;
$row->creator_id = $row->creator ?? null;
$dimensions = [$row->l ?? null, $row->w ?? null, $row->h ?? null];
$row->volume = in_array(null, $dimensions, true)
? null
: (float) $dimensions[0] * (float) $dimensions[1] * (float) $dimensions[2];
}
}
/** @param list<object> $rows */
private function attachPurchasePrices(array $rows, bool $initialized): void
{
@ -473,6 +490,14 @@ class ProductCatalogMirrorRepository
'brand',
'category',
'supplier_name',
'weight',
'l',
'w',
'h',
'unit',
'other_2',
'item_type',
'creator',
'enabled',
'stock_disabled',
'modified',

View File

@ -230,7 +230,7 @@
.product-catalog-table {
width: 100%;
min-width: 2620px;
min-width: 3180px;
border-collapse: collapse;
font-size: 0.78125rem;
}
@ -570,6 +570,15 @@
<th>变价时间</th>
<th>数据来源</th>
<th class="is-numeric">市场价</th>
<th class="is-numeric">重量(kg)</th>
<th class="is-numeric">长(cm)</th>
<th class="is-numeric">宽(cm)</th>
<th class="is-numeric">高(cm)</th>
<th class="is-numeric">体积(cm³)</th>
<th>单位</th>
<th>板材</th>
<th>类型</th>
<th>创建人</th>
<th>商品状态</th>
<th>库存同步</th>
<th>业务更新时间</th>
@ -620,6 +629,13 @@
@endforelse
</td>
<td class="is-numeric">{{ isset($row->market_price) && $row->market_price !== null ? number_format((float) $row->market_price, 2) : '-' }}</td>
@foreach (['weight', 'l', 'w', 'h', 'volume'] as $physicalField)
<td class="is-numeric">{{ isset($row->{$physicalField}) && $row->{$physicalField} !== null ? number_format((float) $row->{$physicalField}, 2) : '-' }}</td>
@endforeach
<td>{{ $row->unit ?? '-' }}</td>
<td class="is-clamped" title="{{ $row->board_material ?? '' }}">{{ $row->board_material ?? '-' }}</td>
<td>{{ $row->product_type ?? '-' }}</td>
<td class="is-code">{{ $row->creator_id ?? '-' }}</td>
<td>
<span class="product-catalog-badge {{ (int) ($row->enabled ?? 0) === 1 ? 'is-active' : ((int) ($row->enabled ?? 0) === -1 ? 'is-danger' : '') }}">
{{ $enabledLabel }}
@ -634,7 +650,7 @@
</tr>
@empty
<tr>
<td colspan="24" class="product-catalog-empty">
<td colspan="33" class="product-catalog-empty">
<span class="material-icons-outlined text-3xl block mb-2" aria-hidden="true">inventory_2</span>
@if ($productCatalogError)
数据暂时不可用。

View File

@ -73,6 +73,15 @@ class ProductCatalogPageTest extends FeatureTestCase
'brand' => '北木',
'category' => '住宅家具',
'supplier_name' => '新北供应商',
'weight' => 4.32,
'l' => 49,
'w' => 18.5,
'h' => 10.5,
'volume' => 9518.25,
'unit' => '个',
'board_material' => '正常板材',
'product_type' => '成品',
'creator_id' => 19203883,
'enabled' => 1,
'stock_disabled' => 0,
'modified' => '2026-08-15 10:00:00',
@ -140,6 +149,15 @@ class ProductCatalogPageTest extends FeatureTestCase
->assertDontSeeText('工作平台价格尚未完成首次同步')
->assertDontSeeText('商品价格变价记录尚未完成首次同步')
->assertSeeText('正常同步')
->assertSeeText('重量(kg)')
->assertSeeText('4.32')
->assertSeeText('长(cm)')
->assertSeeText('49.00')
->assertSeeText('体积(cm³)')
->assertSeeText('9,518.25')
->assertSeeText('正常板材')
->assertSeeText('成品')
->assertSeeText('19203883')
->assertDontSee('pic_url');
}

View File

@ -117,6 +117,47 @@ class ProductCatalogMirrorRepositoryTest extends TestCase
$this->assertObjectNotHasProperty('pic_url', $result['data'][0]);
}
public function test_it_exposes_physical_and_management_fields_and_calculates_volume(): void
{
$this->markReady(1);
$this->insertProduct(1, [
'weight' => 4.32,
'l' => 49,
'w' => 18.5,
'h' => 10.5,
'unit' => '个',
'other_2' => '正常板材',
'item_type' => '成品',
'creator' => 19203883,
]);
$row = $this->repository->paginate($this->filters(), 1, 25)['data'][0];
$this->assertSame('4.32', (string) $row->weight);
$this->assertSame('49', (string) $row->l);
$this->assertSame('18.5', (string) $row->w);
$this->assertSame('10.5', (string) $row->h);
$this->assertSame('9518.25', (string) $row->volume);
$this->assertSame('个', $row->unit);
$this->assertSame('正常板材', $row->board_material);
$this->assertSame('成品', $row->product_type);
$this->assertSame(19203883, (int) $row->creator_id);
}
public function test_it_keeps_volume_empty_when_any_dimension_is_missing(): void
{
$this->markReady(1);
$this->insertProduct(1, [
'l' => 49,
'w' => 18.5,
'h' => null,
]);
$row = $this->repository->paginate($this->filters(), 1, 25)['data'][0];
$this->assertNull($row->volume);
}
public function test_it_attaches_the_latest_finished_1688_drop_shipping_price_without_overwriting_product_price(): void
{
$this->markReady(1);
@ -444,6 +485,14 @@ class ProductCatalogMirrorRepositoryTest extends TestCase
$table->text('brand')->nullable();
$table->text('category')->nullable();
$table->text('supplier_name')->nullable();
$table->decimal('weight', 18, 2)->nullable();
$table->decimal('l', 18, 2)->nullable();
$table->decimal('w', 18, 2)->nullable();
$table->decimal('h', 18, 2)->nullable();
$table->string('unit')->nullable();
$table->text('other_2')->nullable();
$table->string('item_type')->nullable();
$table->integer('creator')->nullable();
$table->integer('enabled')->nullable();
$table->integer('stock_disabled')->nullable();
$table->dateTime('modified')->nullable();
@ -587,6 +636,14 @@ class ProductCatalogMirrorRepositoryTest extends TestCase
'brand' => '测试品牌',
'category' => '测试类目',
'supplier_name' => '测试供应商',
'weight' => null,
'l' => null,
'w' => null,
'h' => null,
'unit' => null,
'other_2' => null,
'item_type' => null,
'creator' => null,
'enabled' => 1,
'stock_disabled' => 0,
'modified' => '2026-08-15 10:00:00',
@ -647,6 +704,14 @@ class ProductCatalogMirrorRepositoryTest extends TestCase
['brand', 'nvarchar', 100],
['category', 'nvarchar', 100],
['supplier_name', 'nvarchar', 255],
['weight', 'decimal', null],
['l', 'decimal', null],
['w', 'decimal', null],
['h', 'decimal', null],
['unit', 'nvarchar', 50],
['other_2', 'nvarchar', 255],
['item_type', 'nvarchar', 50],
['creator', 'int', null],
['enabled', 'int', null],
['stock_disabled', 'int', null],
['modified', 'datetime', null],