fix(优惠券中心):用户查询优惠券逻辑优化,回调更新订单状态
This commit is contained in:
@@ -33,6 +33,11 @@ public class CtripOrder implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private String otaOrderId;
|
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.constant.ServiceNameConstants;
|
||||||
import com.central.common.model.Result;
|
import com.central.common.model.Result;
|
||||||
import com.central.coupon.feign.dto.QrCodeInfo;
|
import com.central.coupon.feign.dto.QrCodeInfo;
|
||||||
|
import com.central.coupon.feign.dto.OrderInfo;
|
||||||
import org.springframework.cloud.openfeign.FeignClient;
|
import org.springframework.cloud.openfeign.FeignClient;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
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)
|
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, dismiss404 = true)
|
||||||
public interface OrderCenterService {
|
public interface OrderCenterService {
|
||||||
@GetMapping("/qrcode/{codeId}")
|
@GetMapping("/qrcode/{codeId}")
|
||||||
Result<QrCodeInfo> getQrCode(@PathVariable("codeId") String 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 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.mapper.CtripOrderMapper;
|
||||||
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
import com.central.coupon.model.CtripConsumedNoticeResponse;
|
||||||
import com.central.coupon.service.CtripConsumedService;
|
import com.central.coupon.service.CtripConsumedService;
|
||||||
|
import com.central.coupon.feign.OrderCenterService;
|
||||||
import com.central.coupon.util.CtripDecryptUtil;
|
import com.central.coupon.util.CtripDecryptUtil;
|
||||||
|
import com.central.common.model.Result;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
@@ -44,6 +46,9 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CtripApiConfig ctripApiConfig;
|
private CtripApiConfig ctripApiConfig;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private OrderCenterService orderCenterService;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Transactional
|
@Transactional
|
||||||
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
public CtripConsumedNoticeResponse consumeOrder(CtripConsumeRequest request) {
|
||||||
@@ -257,6 +262,9 @@ public class CtripConsumedServiceImpl implements CtripConsumedService {
|
|||||||
ctripOrderMapper.updateById(order);
|
ctripOrderMapper.updateById(order);
|
||||||
log.info("订单状态更新为已使用,otaOrderId: {}, totalUseQuantity: {}",
|
log.info("订单状态更新为已使用,otaOrderId: {}, totalUseQuantity: {}",
|
||||||
order.getOtaOrderId(), totalUseQuantity);
|
order.getOtaOrderId(), totalUseQuantity);
|
||||||
|
|
||||||
|
// 6. 更新订单中心订单状态(如果有关联的订单号)
|
||||||
|
updateOrderCenterStatus(order);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 构建成功响应
|
* 构建成功响应
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -4,29 +4,33 @@
|
|||||||
|
|
||||||
<!-- 根据携程订单号查询订单 -->
|
<!-- 根据携程订单号查询订单 -->
|
||||||
<select id="selectByOtaOrderId" resultType="com.central.coupon.entity.CtripOrder">
|
<select id="selectByOtaOrderId" resultType="com.central.coupon.entity.CtripOrder">
|
||||||
SELECT
|
SELECT * FROM t_ctrip_order WHERE ota_order_id = #{otaOrderId}
|
||||||
id,
|
|
||||||
ota_order_id,
|
|
||||||
supplier_order_id,
|
|
||||||
sequence_id,
|
|
||||||
confirm_type,
|
|
||||||
order_last_confirm_time,
|
|
||||||
status,
|
|
||||||
total_amount,
|
|
||||||
currency,
|
|
||||||
create_time,
|
|
||||||
update_time,
|
|
||||||
create_by,
|
|
||||||
update_by,
|
|
||||||
remark,
|
|
||||||
tenant_id
|
|
||||||
FROM t_ctrip_order
|
|
||||||
WHERE ota_order_id = #{otaOrderId}
|
|
||||||
AND deleted = 0
|
|
||||||
ORDER BY create_time DESC
|
|
||||||
LIMIT 1
|
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据订单中心订单号查询携程订单 -->
|
||||||
|
<select id="selectByOrderNo" resultType="com.central.coupon.entity.CtripOrder">
|
||||||
|
SELECT * FROM t_ctrip_order WHERE order_no = #{orderNo}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<!-- 根据携程订单号更新订单 -->
|
||||||
|
<update id="updateByOtaOrderId" parameterType="com.central.coupon.entity.CtripOrder">
|
||||||
|
UPDATE t_ctrip_order
|
||||||
|
SET supplier_order_id = #{supplierOrderId},
|
||||||
|
sequence_id = #{sequenceId},
|
||||||
|
confirm_type = #{confirmType},
|
||||||
|
order_last_confirm_time = #{orderLastConfirmTime},
|
||||||
|
status = #{status},
|
||||||
|
total_amount = #{totalAmount},
|
||||||
|
currency = #{currency},
|
||||||
|
update_time = #{updateTime},
|
||||||
|
create_by = #{createBy},
|
||||||
|
update_by = #{updateBy},
|
||||||
|
remark = #{remark},
|
||||||
|
tenant_id = #{tenantId},
|
||||||
|
order_no = #{orderNo}
|
||||||
|
WHERE ota_order_id = #{otaOrderId}
|
||||||
|
</update>
|
||||||
|
|
||||||
<!-- 根据供应商订单号查询订单 -->
|
<!-- 根据供应商订单号查询订单 -->
|
||||||
<select id="selectBySupplierOrderId" resultType="com.central.coupon.entity.CtripOrder">
|
<select id="selectBySupplierOrderId" resultType="com.central.coupon.entity.CtripOrder">
|
||||||
SELECT
|
SELECT
|
||||||
|
|||||||
+59
@@ -45,6 +45,7 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Order information
|
* Order information
|
||||||
@@ -1149,4 +1150,62 @@ public class OrderController {
|
|||||||
}
|
}
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "更新订单状态为已支付(优惠券核销成功后调用)")
|
||||||
|
@PostMapping("/order/{orderNo}/status/paid")
|
||||||
|
public Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo) {
|
||||||
|
log.info("优惠券核销成功,更新订单状态为已支付,orderNo: {}", orderNo);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Order order = orderService.getOrderByNumber(orderNo);
|
||||||
|
if (order == null) {
|
||||||
|
log.error("订单不存在,orderNo: {}", orderNo);
|
||||||
|
return Result.failed("订单不存在");
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查订单当前状态
|
||||||
|
if (order.getOrderStatus().equals(OrderStatus.UNPAID.getId())) {
|
||||||
|
// 更新订单状态为已支付排队中
|
||||||
|
order.setOrderStatus(OrderStatus.PAID.getId());
|
||||||
|
// 设置支付类型为优惠券支付
|
||||||
|
order.setPayType(2); // 2表示优惠券支付
|
||||||
|
// 设置支付时间
|
||||||
|
order.setPayTime(new Date());
|
||||||
|
|
||||||
|
boolean result = orderService.updateOrder(order);
|
||||||
|
if (result) {
|
||||||
|
log.info("订单状态更新成功,orderNo: {}, 新状态: {}", orderNo, OrderStatus.PAID.getId());
|
||||||
|
return Result.succeed("订单状态更新成功");
|
||||||
|
} else {
|
||||||
|
log.error("订单状态更新失败,orderNo: {}", orderNo);
|
||||||
|
return Result.failed("订单状态更新失败");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.warn("订单状态不正确,无法更新为已支付,orderNo: {}, 当前状态: {}",
|
||||||
|
orderNo, order.getOrderStatus());
|
||||||
|
return Result.failed("订单状态不正确,无法更新为已支付");
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("更新订单状态异常,orderNo: {}", orderNo, e);
|
||||||
|
return Result.failed("更新订单状态异常: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Operation(summary = "根据订单号获取订单信息")
|
||||||
|
@GetMapping("/order/{orderNo}")
|
||||||
|
public Result<Order> getOrderByOrderNo(@PathVariable("orderNo") String orderNo) {
|
||||||
|
log.info("根据订单号获取订单信息,orderNo: {}", orderNo);
|
||||||
|
|
||||||
|
try {
|
||||||
|
Order order = orderService.getOrderByNumber(orderNo);
|
||||||
|
if (order == null) {
|
||||||
|
return Result.failed("订单不存在");
|
||||||
|
}
|
||||||
|
return Result.succeed(order);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("获取订单信息异常,orderNo: {}", orderNo, e);
|
||||||
|
return Result.failed("获取订单信息异常: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user