fix(优惠券中心):用户查询优惠券逻辑优化,回调更新订单状态
This commit is contained in:
@@ -33,6 +33,11 @@ public class CtripOrder implements Serializable {
|
||||
*/
|
||||
private String otaOrderId;
|
||||
|
||||
/**
|
||||
* 关联的订单中心订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 供应商订单号
|
||||
*/
|
||||
|
||||
+15
@@ -3,12 +3,27 @@ package com.central.coupon.feign;
|
||||
import com.central.common.constant.ServiceNameConstants;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.feign.dto.QrCodeInfo;
|
||||
import com.central.coupon.feign.dto.OrderInfo;
|
||||
import org.springframework.cloud.openfeign.FeignClient;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
||||
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, dismiss404 = true)
|
||||
public interface OrderCenterService {
|
||||
@GetMapping("/qrcode/{codeId}")
|
||||
Result<QrCodeInfo> getQrCode(@PathVariable("codeId") String codeId);
|
||||
|
||||
/**
|
||||
* 根据订单号获取订单信息
|
||||
*/
|
||||
@GetMapping("/order/{orderNo}")
|
||||
Result<OrderInfo> getOrderByOrderNo(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 更新订单状态为已支付(优惠券核销成功后调用)
|
||||
*/
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo);
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
package com.central.coupon.feign.dto;
|
||||
|
||||
import lombok.Data;
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
/**
|
||||
* 订单信息DTO
|
||||
*/
|
||||
@Data
|
||||
public class OrderInfo {
|
||||
|
||||
/**
|
||||
* 订单ID
|
||||
*/
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 用户ID
|
||||
*/
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 景区ID
|
||||
*/
|
||||
private Long tourismId;
|
||||
|
||||
/**
|
||||
* 订单金额
|
||||
*/
|
||||
private String orderAmount;
|
||||
|
||||
/**
|
||||
* 订单状态
|
||||
*/
|
||||
private Integer orderStatus;
|
||||
|
||||
/**
|
||||
* 支付类型(1:微信支付,2:优惠券支付)
|
||||
*/
|
||||
private Integer payType;
|
||||
|
||||
/**
|
||||
* 支付时间
|
||||
*/
|
||||
private LocalDateTime payTime;
|
||||
|
||||
/**
|
||||
* 二维码ID
|
||||
*/
|
||||
private String codeId;
|
||||
|
||||
/**
|
||||
* 设备SN
|
||||
*/
|
||||
private String deviceSn;
|
||||
|
||||
/**
|
||||
* 租户ID
|
||||
*/
|
||||
private String tenantId;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createTime;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updateTime;
|
||||
}
|
||||
+10
@@ -19,6 +19,16 @@ public interface CtripOrderMapper extends BaseMapper<CtripOrder> {
|
||||
*/
|
||||
CtripOrder selectByOtaOrderId(@Param("otaOrderId") String otaOrderId);
|
||||
|
||||
/**
|
||||
* 根据订单中心订单号查询携程订单
|
||||
*/
|
||||
CtripOrder selectByOrderNo(@Param("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 根据携程订单号更新订单
|
||||
*/
|
||||
int updateByOtaOrderId(CtripOrder order);
|
||||
|
||||
/**
|
||||
* 根据供应商订单号查询订单
|
||||
*
|
||||
|
||||
+34
@@ -9,7 +9,9 @@ import com.central.coupon.mapper.CtripConsumedMapper;
|
||||
import com.central.coupon.mapper.CtripOrderMapper;
|
||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
||||
import com.central.coupon.service.CtripConsumedService;
|
||||
import com.central.coupon.feign.OrderCenterService;
|
||||
import com.central.coupon.util.CtripDecryptUtil;
|
||||
import com.central.common.model.Result;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -44,6 +46,9 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
@Autowired
|
||||
private CtripApiConfig ctripApiConfig;
|
||||
|
||||
@Autowired
|
||||
private OrderCenterService orderCenterService;
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
||||
@@ -257,6 +262,9 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
ctripOrderMapper.updateById(order);
|
||||
log.info("订单状态更新为已使用,otaOrderId: {}, totalUseQuantity: {}",
|
||||
order.getOtaOrderId(), totalUseQuantity);
|
||||
|
||||
// 6. 更新订单中心订单状态(如果有关联的订单号)
|
||||
updateOrderCenterStatus(order);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
@@ -264,6 +272,32 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新订单中心订单状态
|
||||
*/
|
||||
private void updateOrderCenterStatus(CtripOrder order) {
|
||||
try {
|
||||
if (StringUtils.hasText(order.getOrderNo())) {
|
||||
log.info("开始更新订单中心订单状态,orderNo: {}", order.getOrderNo());
|
||||
|
||||
// 调用订单中心接口更新订单状态为已支付(状态1)
|
||||
Result<String> result = orderCenterService.updateOrderStatusToPaid(order.getOrderNo());
|
||||
|
||||
if (result != null && result.getResp_code() == 0) {
|
||||
log.info("订单中心订单状态更新成功,orderNo: {}", order.getOrderNo());
|
||||
} else {
|
||||
log.error("订单中心订单状态更新失败,orderNo: {}, result: {}",
|
||||
order.getOrderNo(), result);
|
||||
}
|
||||
} else {
|
||||
log.warn("携程订单未关联订单中心订单号,无法更新订单状态,otaOrderId: {}",
|
||||
order.getOtaOrderId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单中心订单状态异常,orderNo: {}", order.getOrderNo(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功响应
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user