fix: GetGoodsViewData 使用 SPEC_DIMS 顺序推断维度,不再依赖 type 字段
parent
416fe0a067
commit
4683862688
|
|
@ -510,18 +510,26 @@ class SeatSkuService extends BaseService
|
|||
return $seatSpecMap;
|
||||
}
|
||||
|
||||
// 2. 查询每个 spec_base_id 对应的 4 维 GoodsSpecValue
|
||||
// 2. 查询每个 spec_base_id 对应的 GoodsSpecValue
|
||||
$specBaseIds = array_column($specs, 'id');
|
||||
$specValues = \think\facade\Db::name('GoodsSpecValue')
|
||||
->whereIn('goods_spec_base_id', $specBaseIds)
|
||||
->order('id', 'asc') // 按插入顺序,确保维度顺序一致
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
// 3. 按 spec_base_id 分组,构建 4 维 spec 数组
|
||||
// 3. 按 spec_base_id 分组,按 SPEC_DIMS 顺序映射维度
|
||||
// 不依赖 type 字段,而是按插入顺序匹配 SPEC_DIMS
|
||||
$specByBaseId = [];
|
||||
foreach ($specValues as $sv) {
|
||||
$specByBaseId[$sv['goods_spec_base_id']][] = [
|
||||
'type' => $sv['type'] ?? '',
|
||||
$baseId = $sv['goods_spec_base_id'];
|
||||
if (!isset($specByBaseId[$baseId])) {
|
||||
$specByBaseId[$baseId] = [];
|
||||
}
|
||||
$idx = count($specByBaseId[$baseId]); // 当前维度索引
|
||||
$dimName = self::SPEC_DIMS[$idx] ?? ('dim_' . $idx);
|
||||
$specByBaseId[$baseId][] = [
|
||||
'type' => $dimName, // 使用 SPEC_DIMS 顺序推断维度名
|
||||
'value' => $sv['value'] ?? '',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue