|
|
@@ -21,6 +21,7 @@ import shop.alien.entity.store.LawyerUser;
|
|
|
import shop.alien.entity.store.dto.LawyerConsultationOrderDto;
|
|
|
import shop.alien.entity.store.dto.PayStatusRequest;
|
|
|
import shop.alien.entity.store.vo.LawyerConsultationOrderVO;
|
|
|
+import shop.alien.lawyer.feign.AlienStoreFeign;
|
|
|
import shop.alien.lawyer.service.LawyerClientConsultationOrderService;
|
|
|
import shop.alien.lawyer.service.LawyerConsultationOrderService;
|
|
|
import shop.alien.lawyer.service.LawyerUserService;
|
|
|
@@ -54,6 +55,7 @@ public class LawyerClientConsultationOrderServiceImpl extends ServiceImpl<Lawyer
|
|
|
private final LawyerServiceAreaMapper lawyerServiceAreaMapper;
|
|
|
private final LawyerUserMapper lawyerUserMapper;
|
|
|
private final OrderExpirationService orderExpirationService;
|
|
|
+ private final AlienStoreFeign alienStoreFeign;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -536,5 +538,127 @@ public class LawyerClientConsultationOrderServiceImpl extends ServiceImpl<Lawyer
|
|
|
orderVO.setNickName(lawyerUser.getNickName());
|
|
|
orderVO.setPersonalIntroduction(lawyerUser.getPersonalIntroduction());
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 律师确认订单
|
|
|
+ * <p>
|
|
|
+ * 支持两种操作:
|
|
|
+ * 1. 接单:将订单状态从待接单(1)修改为进行中(2)
|
|
|
+ * 2. 取消:将订单状态修改为已取消(4),并进行退款
|
|
|
+ * </p>
|
|
|
+ *
|
|
|
+ * @param id 订单ID
|
|
|
+ * @param actionType 操作类型:1-接单,2-取消
|
|
|
+ * @return 确认结果
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public R<Boolean> confirmOrder(Integer id, Integer actionType) {
|
|
|
+ log.info("开始律师确认订单,订单ID={}, 操作类型={}", id, actionType);
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (id == null) {
|
|
|
+ log.warn("律师确认订单失败:订单ID为空");
|
|
|
+ return R.fail("订单ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (actionType == null || (actionType != 1 && actionType != 2)) {
|
|
|
+ log.warn("律师确认订单失败:操作类型无效,actionType={}", actionType);
|
|
|
+ return R.fail("操作类型无效,1-接单,2-取消");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 查询订单信息
|
|
|
+ LawyerConsultationOrder order = consultationOrderMapper.selectById(id);
|
|
|
+ if (order == null) {
|
|
|
+ log.warn("律师确认订单失败:订单不存在,订单ID={}", id);
|
|
|
+ return R.fail("订单不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证订单状态是否为待接单(1)
|
|
|
+ Integer orderStatus = order.getOrderStatus();
|
|
|
+ Integer waitAcceptStatus = 1; // 待接单
|
|
|
+ if (!waitAcceptStatus.equals(orderStatus)) {
|
|
|
+ log.warn("律师确认订单失败:订单状态不是待接单,订单ID={}, 订单编号={}, 当前状态={}",
|
|
|
+ id, order.getOrderNumber(), orderStatus);
|
|
|
+ return R.fail("订单状态不是待接单,无法确认");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据操作类型处理
|
|
|
+ if (actionType == 1) {
|
|
|
+ // 接单:更新订单状态为进行中(2)
|
|
|
+ Integer inProgressStatus = LawyerStatusEnum.INPROGRESS.getStatus(); // 2:进行中
|
|
|
+ order.setOrderStatus(inProgressStatus);
|
|
|
+ order.setUpdatedTime(new Date());
|
|
|
+
|
|
|
+ // 执行更新操作
|
|
|
+ boolean result = this.updateById(order);
|
|
|
+ if (result) {
|
|
|
+ log.info("律师接单成功,订单ID={}, 订单编号={}, 状态从{}变更为{}",
|
|
|
+ id, order.getOrderNumber(), waitAcceptStatus, inProgressStatus);
|
|
|
+ return R.data(true, "接单成功");
|
|
|
+ } else {
|
|
|
+ log.error("律师接单失败:数据库操作失败,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ return R.fail("接单失败");
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 取消:更新订单状态为已取消(4),并进行退款
|
|
|
+ Integer cancelStatus = LawyerStatusEnum.CANCEL.getStatus(); // 4:已取消
|
|
|
+ order.setOrderStatus(cancelStatus);
|
|
|
+ order.setUpdatedTime(new Date());
|
|
|
+
|
|
|
+ // 执行更新操作
|
|
|
+ boolean result = this.updateById(order);
|
|
|
+ if (!result) {
|
|
|
+ log.error("律师取消订单失败:数据库操作失败,订单ID={}, 订单编号={}", id, order.getOrderNumber());
|
|
|
+ return R.fail("取消订单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 进行退款处理
|
|
|
+ if (order.getPaymentStatus() != null && order.getPaymentStatus() == 1) {
|
|
|
+ // 只有已支付的订单才需要退款
|
|
|
+ String orderNumber = order.getOrderNumber();
|
|
|
+ Integer orderAmount = order.getOrderAmount();
|
|
|
+
|
|
|
+ if (orderNumber == null || orderNumber.trim().isEmpty()) {
|
|
|
+ log.warn("律师取消订单失败:订单编号为空,无法退款,订单ID={}", id);
|
|
|
+ return R.fail("订单编号为空,无法退款");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (orderAmount == null || orderAmount <= 0) {
|
|
|
+ log.warn("律师取消订单失败:订单金额无效,无法退款,订单ID={}, 订单金额={}", id, orderAmount);
|
|
|
+ return R.fail("订单金额无效,无法退款");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 将订单金额从分转换为元(字符串格式,保留两位小数)
|
|
|
+ String refundAmount = String.format("%.2f", orderAmount / 100.0);
|
|
|
+ String refundReason = "律师取消订单";
|
|
|
+
|
|
|
+ try {
|
|
|
+ // 调用退款接口(全退,partialRefundCode 传空字符串)
|
|
|
+ String refundResult = alienStoreFeign.processRefund(orderNumber, refundAmount, refundReason, "");
|
|
|
+
|
|
|
+ if ("调用成功".equals(refundResult)) {
|
|
|
+ log.info("律师取消订单并退款成功,订单ID={}, 订单编号={}, 退款金额={}元",
|
|
|
+ id, orderNumber, refundAmount);
|
|
|
+ return R.data(true, "取消订单成功,退款已处理");
|
|
|
+ } else {
|
|
|
+ log.error("律师取消订单退款失败,订单ID={}, 订单编号={}, 退款结果={}",
|
|
|
+ id, orderNumber, refundResult);
|
|
|
+ // 退款失败,但订单状态已更新为已取消,返回警告信息
|
|
|
+ return R.fail("订单已取消,但退款处理失败:" + refundResult);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("律师取消订单退款异常,订单ID={}, 订单编号={}", id, orderNumber, e);
|
|
|
+ // 退款异常,但订单状态已更新为已取消,返回警告信息
|
|
|
+ return R.fail("订单已取消,但退款处理异常:" + e.getMessage());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 未支付的订单,直接取消即可
|
|
|
+ log.info("律师取消订单成功(未支付订单无需退款),订单ID={}, 订单编号={}",
|
|
|
+ id, order.getOrderNumber());
|
|
|
+ return R.data(true, "取消订单成功");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|