fix(优惠券中心):携程接口优化
This commit is contained in:
+39
-39
@@ -91,7 +91,7 @@ public class CtripCouponController {
|
||||
* 处理创建优惠券请求(内部方法,供统一接口调用)
|
||||
*/
|
||||
public CtripCouponResponse processCreateCouponRequest(Object requestBody,
|
||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
||||
log.info("收到携程创建优惠券请求,IP: {}", httpRequest.getRemoteAddr());
|
||||
log.info("请求URL: {}", httpRequest.getRequestURL());
|
||||
log.info("请求URI: {}", httpRequest.getRequestURI());
|
||||
@@ -143,18 +143,18 @@ public class CtripCouponController {
|
||||
log.error("未知的请求体类型:{}", requestBody != null ? requestBody.getClass().getSimpleName() : "null");
|
||||
return buildErrorResponse("0001", "未知的请求体类型");
|
||||
}
|
||||
|
||||
// 验证请求体不为空
|
||||
if (request == null || request.isEmpty()) {
|
||||
log.error("请求体为空");
|
||||
return buildErrorResponse("0001", "请求体不能为空");
|
||||
}
|
||||
|
||||
|
||||
// 验证请求体不为空
|
||||
if (request == null || request.isEmpty()) {
|
||||
log.error("请求体为空");
|
||||
return buildErrorResponse("0001", "请求体不能为空");
|
||||
}
|
||||
|
||||
// 检查是否是携程标准请求格式(包含header和body)
|
||||
if (request.containsKey("header") && request.containsKey("body")) {
|
||||
log.info("检测到携程标准请求格式(包含header和body)");
|
||||
Object bodyObj = request.get("body");
|
||||
|
||||
Object bodyObj = request.get("body");
|
||||
|
||||
if (bodyObj instanceof String) {
|
||||
// body是加密字符串,需要解密
|
||||
String encryptedBody = (String) bodyObj;
|
||||
@@ -175,12 +175,12 @@ public class CtripCouponController {
|
||||
} catch (Exception e) {
|
||||
log.error("解析body失败: {}", e.getMessage());
|
||||
return buildErrorResponse("0001", "解析body失败: " + e.getMessage());
|
||||
}
|
||||
} else if (bodyObj instanceof Map) {
|
||||
}
|
||||
} else if (bodyObj instanceof Map) {
|
||||
// body已经是Map对象
|
||||
request = (Map<String, Object>) bodyObj;
|
||||
log.info("body已经是Map格式,新的请求体: {}", request);
|
||||
} else {
|
||||
} else {
|
||||
log.error("未知的body类型: {}", bodyObj != null ? bodyObj.getClass().getSimpleName() : "null");
|
||||
return buildErrorResponse("0001", "未知的body类型");
|
||||
}
|
||||
@@ -197,9 +197,9 @@ public class CtripCouponController {
|
||||
String sequenceId = (String) request.get("sequenceId");
|
||||
|
||||
// 从contacts中获取用户手机号
|
||||
String userPhone = null;
|
||||
String userPhone = null;
|
||||
List<Map<String, Object>> contacts = (List<Map<String, Object>>) request.get("contacts");
|
||||
if (contacts != null && !contacts.isEmpty()) {
|
||||
if (contacts != null && !contacts.isEmpty()) {
|
||||
Map<String, Object> firstContact = contacts.get(0);
|
||||
userPhone = (String) firstContact.get("mobile");
|
||||
log.info("从联系人中获取到手机号: {}", userPhone);
|
||||
@@ -207,8 +207,8 @@ public class CtripCouponController {
|
||||
|
||||
// 从items中获取优惠券信息(如果有的话)
|
||||
List<Map<String, Object>> items = (List<Map<String, Object>>) request.get("items");
|
||||
if (items != null && !items.isEmpty()) {
|
||||
Map<String, Object> item = items.get(0);
|
||||
if (items != null && !items.isEmpty()) {
|
||||
Map<String, Object> item = items.get(0);
|
||||
String itemId = (String) item.get("PLU");
|
||||
BigDecimal price = null;
|
||||
if (item.get("price") != null) {
|
||||
@@ -247,10 +247,10 @@ public class CtripCouponController {
|
||||
log.error("手机号格式不正确: {}", userPhone);
|
||||
return buildErrorResponse("0005", "手机号格式不正确");
|
||||
}
|
||||
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
log.info("携程优惠券已存在,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
|
||||
// 幂等校验
|
||||
if (couponService.existsByUserPhoneAndCtripCouponId(userPhone, ctripCouponId)) {
|
||||
log.info("携程优惠券已存在,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
// 返回订单创建成功响应
|
||||
String supplierOrderId = generateSupplierOrderId(otaOrderId);
|
||||
return buildSuccessResponseWithOrder(otaOrderId, supplierOrderId, items);
|
||||
@@ -264,21 +264,21 @@ public class CtripCouponController {
|
||||
ctripOrderId = parts[1]; // 取第二部分作为订单ID
|
||||
log.info("从ctripCouponId中提取订单ID: {} -> {}", ctripCouponId, ctripOrderId);
|
||||
}
|
||||
}
|
||||
|
||||
// 创建优惠券
|
||||
boolean success = couponService.createCouponFromCtrip(
|
||||
ctripCouponId, userPhone, couponName, couponType, amount,
|
||||
}
|
||||
|
||||
// 创建优惠券
|
||||
boolean success = couponService.createCouponFromCtrip(
|
||||
ctripCouponId, userPhone, couponName, couponType, amount,
|
||||
validStartTime, validEndTime, ctripOrderId
|
||||
);
|
||||
|
||||
if (success) {
|
||||
);
|
||||
|
||||
if (success) {
|
||||
log.info("从订单创建请求中成功创建优惠券,userPhone: {}, ctripCouponId: {}, otaOrderId: {}",
|
||||
userPhone, ctripCouponId, otaOrderId);
|
||||
// 返回订单创建成功响应
|
||||
String supplierOrderId = generateSupplierOrderId(otaOrderId);
|
||||
return buildSuccessResponseWithOrder(otaOrderId, supplierOrderId, items);
|
||||
} else {
|
||||
} else {
|
||||
log.error("从订单创建请求中创建优惠券失败,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return buildErrorResponse("0004", "优惠券创建失败");
|
||||
}
|
||||
@@ -407,15 +407,15 @@ public class CtripCouponController {
|
||||
ctripCouponId, userPhone, couponName, couponType, amount,
|
||||
validStartTime, validEndTime, ctripOrderId
|
||||
);
|
||||
|
||||
if (success) {
|
||||
|
||||
if (success) {
|
||||
log.info("携程优惠券创建成功,userPhone: {}, ctripCouponId: {}, orderNo: {}, itemId: {}",
|
||||
userPhone, ctripCouponId, orderNo, itemId);
|
||||
return buildSuccessResponse();
|
||||
} else {
|
||||
} else {
|
||||
log.error("携程优惠券创建失败,userPhone: {}, ctripCouponId: {}", userPhone, ctripCouponId);
|
||||
return buildErrorResponse("0004", "优惠券创建失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("处理携程创建优惠券请求异常", e);
|
||||
@@ -436,7 +436,7 @@ public class CtripCouponController {
|
||||
@Operation(summary = "携程核销优惠券接口")
|
||||
@PostMapping("/verify")
|
||||
public CtripCouponResponse verifyCtripCoupon(@RequestBody Map<String, Object> request,
|
||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
||||
jakarta.servlet.http.HttpServletRequest httpRequest) {
|
||||
log.info("收到携程核销优惠券请求,IP: {}", httpRequest.getRemoteAddr());
|
||||
|
||||
// 验证请求体不为空
|
||||
@@ -542,7 +542,7 @@ public class CtripCouponController {
|
||||
log.info("携程优惠券取消成功,ctripCouponId: {}, orderNo: {}, userPhone: {}",
|
||||
ctripCouponId, orderNo, coupon.getUserPhone());
|
||||
return buildSuccessResponse();
|
||||
} else {
|
||||
} else {
|
||||
log.error("携程优惠券取消失败,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
return buildErrorResponse("0005", "优惠券取消失败");
|
||||
}
|
||||
@@ -574,7 +574,7 @@ public class CtripCouponController {
|
||||
log.error("请求体为空");
|
||||
return buildErrorResponse("0001", "请求体不能为空");
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
// 提取请求参数
|
||||
String ctripCouponId = (String) request.get("ctripCouponId");
|
||||
@@ -620,7 +620,7 @@ public class CtripCouponController {
|
||||
log.info("携程优惠券核销成功(SDK),ctripCouponId: {}, orderNo: {}, userPhone: {}",
|
||||
ctripCouponId, orderNo, coupon.getUserPhone());
|
||||
return buildSuccessResponse();
|
||||
} else {
|
||||
} else {
|
||||
log.error("携程优惠券核销失败,ctripCouponId: {}, orderNo: {}", ctripCouponId, orderNo);
|
||||
return buildErrorResponse("0006", "优惠券核销失败");
|
||||
}
|
||||
@@ -733,7 +733,7 @@ public class CtripCouponController {
|
||||
result.put("updateTime", coupon.getUpdateTime());
|
||||
|
||||
return Result.succeed(result);
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("查询携程优惠券状态异常", e);
|
||||
return Result.failed("查询失败: " + e.getMessage());
|
||||
|
||||
Reference in New Issue
Block a user