This commit is contained in:
2025-10-31 16:58:23 +08:00
parent a82ff0d39f
commit 1a6ddce3f0
2 changed files with 20 additions and 5 deletions

View File

@@ -349,12 +349,21 @@ public class JDInnerController {
try {
String giftKey = jdProductService.createGiftCoupon(idOrUrl, amount, quantity, owner, skuName);
// 如果giftKey为null返回错误而不是成功响应
if (giftKey == null || giftKey.trim().isEmpty()) {
String errorDetail = String.format("礼金创建失败giftCouponKey为null。参数: idOrUrl=%s, amount=%.2f, quantity=%d, owner=%s, skuName=%s。可能原因商品不支持创建礼金、商品类型错误、京东API调用失败。请查看JD项目日志获取详细信息。",
idOrUrl, amount, quantity, owner, skuName);
logger.error("礼金创建失败 - giftKey为null, {}", errorDetail);
return error(errorDetail);
}
// 创建成功保存到Redis
jdProductService.saveGiftCouponToRedis(idOrUrl, giftKey, skuName, owner);
logger.info("礼金创建成功 - giftKey={}, idOrUrl={}, owner={}, amount={}, quantity={}", giftKey, idOrUrl, owner, amount, quantity);
JSONObject resp = new JSONObject();
resp.put("giftCouponKey", giftKey);
// 可选:入库/缓存
if (giftKey != null) {
jdProductService.saveGiftCouponToRedis(idOrUrl, giftKey, skuName, owner);
}
return resp;
} catch (Exception e) {
logger.error("createGiftCoupon error", e);

View File

@@ -289,7 +289,13 @@ public class JDProductService {
log.debug("礼金创建成功giftKey={}", giftKey);
return giftKey;
}
log.error("礼金创建失败code={}, msg={}", response != null ? response.getCode() : "null", response != null ? response.getMsg() : "null");
// 详细记录失败信息
String errorCode = response != null ? response.getCode() : "null";
String errorMsg = response != null ? response.getMsg() : "null";
Integer resultCode = response != null && response.getGetResult() != null ? response.getGetResult().getCode() : null;
String resultMsg = response != null && response.getGetResult() != null ? response.getGetResult().getMsg() : null;
log.error("礼金创建失败 - response.code={}, response.msg={}, result.code={}, result.msg={}, SKU={}, owner={}, amount={}, quantity={}",
errorCode, errorMsg, resultCode, resultMsg, skuId, owner, amount, quantity);
return null;
}