fix(ticket): 修复旧缓存不含goods字段导致的JS报错
- 缓存命中时补充构建goods字段 - 初始化和构建树数据时同步添加goods字段
parent
39230958a0
commit
3340016969
|
|
@ -280,11 +280,15 @@ class Goods
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 缓存检查
|
// 缓存检查(注意:旧缓存不含 goods 字段,需要补充)
|
||||||
$cacheKey = 'vr_tree_v4_' . $goodsId . '_' . md5(implode(',', $groupBy));
|
$cacheKey = 'vr_tree_v4_' . $goodsId . '_' . md5(implode(',', $groupBy));
|
||||||
$cached = \think\facade\Cache::get($cacheKey);
|
$cached = \think\facade\Cache::get($cacheKey);
|
||||||
if ($cached !== null) {
|
if ($cached !== null) {
|
||||||
$cached['meta']['cache_hit'] = true;
|
$cached['meta']['cache_hit'] = true;
|
||||||
|
// 旧缓存不含 goods,补充构建
|
||||||
|
if (!isset($cached['goods'])) {
|
||||||
|
$cached['goods'] = self::buildGoodsField($goodsId);
|
||||||
|
}
|
||||||
return self::success($cached);
|
return self::success($cached);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -297,6 +301,7 @@ class Goods
|
||||||
'goods_id' => $goodsId,
|
'goods_id' => $goodsId,
|
||||||
'group_by' => $groupBy,
|
'group_by' => $groupBy,
|
||||||
'tree' => [],
|
'tree' => [],
|
||||||
|
'goods' => self::buildGoodsField($goodsId),
|
||||||
'seat_templates' => new \stdClass(),
|
'seat_templates' => new \stdClass(),
|
||||||
'meta' => [
|
'meta' => [
|
||||||
'seat_count' => 0,
|
'seat_count' => 0,
|
||||||
|
|
@ -320,6 +325,7 @@ class Goods
|
||||||
'goods_id' => $goodsId,
|
'goods_id' => $goodsId,
|
||||||
'group_by' => $groupBy,
|
'group_by' => $groupBy,
|
||||||
'tree' => $treeData['tree'],
|
'tree' => $treeData['tree'],
|
||||||
|
'goods' => self::buildGoodsField($goodsId),
|
||||||
'seat_templates' => $seatTemplates,
|
'seat_templates' => $seatTemplates,
|
||||||
'session_meta' => $sessionMeta,
|
'session_meta' => $sessionMeta,
|
||||||
'peer_goods' => QueryManager::getPeerGoods($goodsId),
|
'peer_goods' => QueryManager::getPeerGoods($goodsId),
|
||||||
|
|
@ -340,6 +346,47 @@ class Goods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 构建 goods 字段(包含手机详情 content_app)
|
||||||
|
*
|
||||||
|
* 复用 GoodsService::GoodsList,传入 is_content_app=1 以包含手机端详情数据。
|
||||||
|
* 这使得 uniapp 可以仅调用 tree API 一次就获取完整数据,无需二次请求 goods/detail。
|
||||||
|
*
|
||||||
|
* @param int $goodsId
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private static function buildGoodsField(int $goodsId): array
|
||||||
|
{
|
||||||
|
$isUseMobileDetail = intval(\MyC('common_app_is_use_mobile_detail', 0, true));
|
||||||
|
|
||||||
|
$params = [
|
||||||
|
'where' => [
|
||||||
|
['id', '=', $goodsId],
|
||||||
|
['is_delete_time', '=', 0],
|
||||||
|
],
|
||||||
|
'is_content_app' => $isUseMobileDetail,
|
||||||
|
'is_spec' => 1,
|
||||||
|
'is_params' => 1,
|
||||||
|
'is_favor' => 1,
|
||||||
|
'm' => 0,
|
||||||
|
'n' => 1,
|
||||||
|
];
|
||||||
|
|
||||||
|
$ret = GoodsService::GoodsList($params);
|
||||||
|
$goods = $ret['data'][0] ?? null;
|
||||||
|
|
||||||
|
if (empty($goods)) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
// 手机端详情模式下移除 PC 富文本,减少响应体积
|
||||||
|
if ($isUseMobileDetail == 1) {
|
||||||
|
unset($goods['content_web']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $goods;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 格式化商品列表数据
|
* 格式化商品列表数据
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue