fix: 处理产品兼容性信息回显数据结构问题
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 4s

This commit is contained in:
2026-07-09 11:27:04 +08:00
parent b4b4b914c2
commit 71f4b82e4b

View File

@@ -121,17 +121,37 @@ class Product
->hidden(['product']);
// 兼容性信息
$product->compat = ProductCompatRelModel::withoutField([
$compat = ProductCompatRelModel::withoutField([
'created_at',
'updated_at',
])
->with(['compat' => function($query) {
$query->field(['id', 'label_name']);
->withJoin(['compat' => function($query) {
$query->whereNull('deleted_at');
}])
->productId($product->id)
->select()
?->bindAttr('compat', ['label_name'])
?->hidden(['compat']);
$compat_map = [];
if (!empty($compat)) {
foreach ($compat as $item) {
if (!isset($compat_map[$item['product_id']])) {
$compat_map[$item['product_id']] = [
'product_id' => $item['product_id'],
'compat' => [],
'series_name' => $item['series_name'],
'show_series_name' => $item['show_series_name'],
'remark' => $item['remark'],
];
}
$compat_map[$item['product_id']]['compat'][] = [
'compat_id' => $item['compat_id'],
'label_name' => $item['label_name'],
];
}
$compat_map = array_values($compat_map);
}
$product->compat = $compat_map;
return success('获取成功', $product);
}