Compare commits

...

2 Commits

Author SHA1 Message Date
Council 3340016969 fix(ticket): 修复旧缓存不含goods字段导致的JS报错
- 缓存命中时补充构建goods字段
- 初始化和构建树数据时同步添加goods字段
2026-06-13 10:57:07 +08:00
Council 39230958a0 fix(ticket): 修复票务勾选时下拉框不刷新的 JS 报错 2026-06-12 13:51:24 +08:00
3 changed files with 72 additions and 3 deletions

View File

@ -280,11 +280,15 @@ class Goods
}
try {
// 缓存检查
// 缓存检查(注意:旧缓存不含 goods 字段,需要补充)
$cacheKey = 'vr_tree_v4_' . $goodsId . '_' . md5(implode(',', $groupBy));
$cached = \think\facade\Cache::get($cacheKey);
if ($cached !== null) {
$cached['meta']['cache_hit'] = true;
// 旧缓存不含 goods补充构建
if (!isset($cached['goods'])) {
$cached['goods'] = self::buildGoodsField($goodsId);
}
return self::success($cached);
}
@ -297,6 +301,7 @@ class Goods
'goods_id' => $goodsId,
'group_by' => $groupBy,
'tree' => [],
'goods' => self::buildGoodsField($goodsId),
'seat_templates' => new \stdClass(),
'meta' => [
'seat_count' => 0,
@ -320,6 +325,7 @@ class Goods
'goods_id' => $goodsId,
'group_by' => $groupBy,
'tree' => $treeData['tree'],
'goods' => self::buildGoodsField($goodsId),
'seat_templates' => $seatTemplates,
'session_meta' => $sessionMeta,
'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;
}
/**
* 格式化商品列表数据
*/

View File

@ -82,7 +82,7 @@ class AdminGoodsIndex
// 触发chosen组件更新如果已初始化
if ($.fn.chosen && select.classList.contains('chosen-init-success')) {
select.trigger('chosen:updated');
$(select).trigger('chosen:updated');
}
return true;

View File

@ -364,11 +364,19 @@ class AdminGoodsSave
});
};
// 备份原始的 produce_region 选项 HTML
let originalRegionOptionsHtml = '';
// ── 动态替换 produce_region 下拉选项为 level=2 城市 ──
const replaceCityOptions = () => {
const select = document.querySelector('select[name="produce_region"]');
if (!select) return;
// 备份原始选项 HTML仅在第一次被替换前备份
if (!originalRegionOptionsHtml) {
originalRegionOptionsHtml = select.innerHTML;
}
// 优先使用 PHP 传递的保存值(城市 ID这是最可靠的数据源
const savedValue = AppData.savedProduceRegion || 0;
@ -391,7 +399,18 @@ class AdminGoodsSave
// 触发chosen组件更新如果使用了chosen插件
if ($.fn.chosen) {
select.trigger('chosen:updated');
$(select).trigger('chosen:updated');
}
};
const restoreCityOptions = () => {
const select = document.querySelector('select[name="produce_region"]');
if (!select || !originalRegionOptionsHtml) return;
select.innerHTML = originalRegionOptionsHtml;
if ($.fn.chosen) {
$(select).trigger('chosen:updated');
}
};
@ -400,6 +419,9 @@ class AdminGoodsSave
if (val) {
// 票务商品模式:替换城市下拉选项
replaceCityOptions();
} else {
// 恢复原始选项
restoreCityOptions();
}
}, { immediate: true });