|
|
@@ -53,6 +53,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
private final LawyerServiceAreaMapper lawyerServiceAreaMapper;
|
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
|
private final LawyerExpertiseAreaMapper lawyerExpertiseAreaMapper;
|
|
|
+ private final OrderExpirationService orderExpirationService;
|
|
|
|
|
|
@Override
|
|
|
public R<IPage<LawyerConsultationOrderVO>> getConsultationOrderList(int pageNum, int pageSize, String orderNumber,
|
|
|
@@ -529,13 +530,66 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
|
|
|
return orderVO;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 取消律师咨询订单
|
|
|
+ *
|
|
|
+ * @param id 订单ID
|
|
|
+ * @return 是否取消成功
|
|
|
+ */
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public boolean cancelOrder(String id) {
|
|
|
- LambdaUpdateWrapper<LawyerConsultationOrder> lawyerConsultationOrderLambdaUpdateWrapper = new LambdaUpdateWrapper<>();
|
|
|
- lawyerConsultationOrderLambdaUpdateWrapper.eq(LawyerConsultationOrder::getId, id);
|
|
|
- lawyerConsultationOrderLambdaUpdateWrapper.set(LawyerConsultationOrder::getOrderStatus, LawyerStatusEnum.CANCEL.getStatus());
|
|
|
- int updateCount = consultationOrderMapper.update(null, lawyerConsultationOrderLambdaUpdateWrapper);
|
|
|
- return updateCount > 0;
|
|
|
+ // 参数校验
|
|
|
+ if (!StringUtils.hasText(id)) {
|
|
|
+ log.warn("取消订单失败:订单ID为空");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询订单信息
|
|
|
+ LawyerConsultationOrder order = consultationOrderMapper.selectById(id);
|
|
|
+ if (order == null) {
|
|
|
+ log.warn("取消订单失败:订单不存在,订单ID={}", id);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查订单状态:已完成或已取消的订单不允许再次取消
|
|
|
+ Integer orderStatus = order.getOrderStatus();
|
|
|
+ Integer cancelStatus = LawyerStatusEnum.CANCEL.getStatus();
|
|
|
+ if (cancelStatus.equals(orderStatus)) {
|
|
|
+ log.warn("取消订单失败:订单已取消,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果订单已完成,不允许取消
|
|
|
+ Integer completedStatus = LawyerStatusEnum.COMPLETE.getStatus(); // 3:已完成
|
|
|
+ if (completedStatus.equals(orderStatus)) {
|
|
|
+ log.warn("取消订单失败:订单已完成,不允许取消,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果订单是待支付状态,取消Redis中的订单支付超时计时
|
|
|
+ Integer waitPayStatus = LawyerStatusEnum.WAIT_PAY.getStatus(); // 0:待支付
|
|
|
+ if (waitPayStatus.equals(orderStatus) && order.getOrderNumber() != null) {
|
|
|
+ orderExpirationService.cancelOrderPaymentTimeout(order.getOrderNumber());
|
|
|
+ log.info("已取消订单支付超时计时,订单编号={}", order.getOrderNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新订单状态为已取消
|
|
|
+ LambdaUpdateWrapper<LawyerConsultationOrder> updateWrapper = new LambdaUpdateWrapper<>();
|
|
|
+ updateWrapper.eq(LawyerConsultationOrder::getId, id)
|
|
|
+ .set(LawyerConsultationOrder::getOrderStatus, cancelStatus)
|
|
|
+ .set(LawyerConsultationOrder::getUpdatedTime, new Date());
|
|
|
+
|
|
|
+ int updateCount = consultationOrderMapper.update(null, updateWrapper);
|
|
|
+ boolean success = updateCount > 0;
|
|
|
+
|
|
|
+ if (success) {
|
|
|
+ log.info("取消订单成功,订单ID={}, 订单编号={}, 原状态={}", id, order.getOrderNumber(), orderStatus);
|
|
|
+ } else {
|
|
|
+ log.error("取消订单失败:更新数据库失败,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ return success;
|
|
|
}
|
|
|
|
|
|
/**
|