This commit is contained in:
2025-10-31 16:54:48 +08:00
parent cb1cea512a
commit 8b5aa28b8f

View File

@@ -639,8 +639,13 @@ export default {
return return
} }
// 判断成功条件code === 200 或者直接返回了giftCouponKey // 判断成功条件code === 200 giftCouponKey 不为null
const isSuccess = res.code === 200 || (res.data && (res.data.giftCouponKey || res.data.giftKey)) // 注意即使code是200如果giftCouponKey为null也应该视为失败
const hasGiftKey = res.data &&
(res.data.giftCouponKey !== null && res.data.giftCouponKey !== undefined && res.data.giftCouponKey !== '') ||
(res.data.giftKey !== null && res.data.giftKey !== undefined && res.data.giftKey !== '')
const isSuccess = res.code === 200 && hasGiftKey
if (isSuccess) { if (isSuccess) {
// 解析返回的giftCouponKey参考xbmessage中的处理方式 // 解析返回的giftCouponKey参考xbmessage中的处理方式
@@ -768,15 +773,24 @@ export default {
// 错误处理 - 更详细的错误信息 // 错误处理 - 更详细的错误信息
console.error('创建礼金失败,返回:', res) console.error('创建礼金失败,返回:', res)
let errorMsg = '创建失败' let errorMsg = '创建失败'
// 优先显示后端返回的错误信息
if (res.msg) { if (res.msg) {
errorMsg = res.msg errorMsg = res.msg
} else if (res.data && res.data.msg) { } else if (res.data && res.data.msg) {
errorMsg = res.data.msg errorMsg = res.data.msg
} else if (res.message) { }
// 如果是code:200但giftCouponKey为null的情况
else if (res.code === 200 && res.data && res.data.giftCouponKey === null) {
errorMsg = '礼金创建失败返回的礼金Key为null。可能的原因\n1. 商品不支持创建礼金\n2. 商品类型(自营/POP判断错误\n3. 京东API调用失败\n4. 商品已下架或不存在\n\n请检查\n- 商品链接是否正确\n- 商品类型是否匹配查询到的owner是否正确\n- 查看JD项目日志获取详细错误信息'
}
// 其他错误情况
else if (res.message) {
errorMsg = res.message errorMsg = res.message
} else if (typeof res === 'string') { } else if (typeof res === 'string') {
errorMsg = res errorMsg = res
} }
this.$modal.msgError('创建失败:' + errorMsg) this.$modal.msgError('创建失败:' + errorMsg)
} }
} catch (e) { } catch (e) {