瀏覽代碼

支付宝微信支付退款流程修改

ldz 4 天之前
父節點
當前提交
173530c93d

+ 8 - 0
alien-entity/src/main/java/shop/alien/entity/store/LawyerConsultationOrder.java

@@ -197,6 +197,14 @@ public class LawyerConsultationOrder extends Model<LawyerConsultationOrder> {
     @TableField("time_num")
     private Integer timeNum;
 
+    @ApiModelProperty(value = "价格")
+    @TableField(exist = false)
+    private Integer price;
+
+    @ApiModelProperty(value = "方式  次 / 分钟")
+    @TableField(exist = false)
+    private String serviceType;
+
 
 
 

+ 10 - 2
alien-entity/src/main/java/shop/alien/mapper/LawyerConsultationOrderMapper.java

@@ -95,7 +95,11 @@ public interface LawyerConsultationOrderMapper extends BaseMapper<LawyerConsulta
             "accept_orders_time ," +
             "reason_order_refusal ," +
             "accept_orders_status ," +
-            "pay_type " +
+            "pay_type ," +
+            "charge_minute ,"+
+            "minute_num ,"+
+            "charge_time ,"+
+            "time_num"+
             ")"+
             "VALUES" +
             " (" +
@@ -128,7 +132,11 @@ public interface LawyerConsultationOrderMapper extends BaseMapper<LawyerConsulta
             "#{acceptOrdersTime} ," +
             "#{reasonOrderRefusal} ," +
             "#{acceptOrdersStatus} ," +
-            "#{payType} " +
+            "#{payType} ," +
+            "#{chargeMinute} ," +
+            "#{minuteNum} ," +
+            "#{chargeTime} ," +
+            "#{timeNum} " +
             ")")
             int insertOrder(LawyerConsultationOrderDto order);
 

+ 48 - 3
alien-lawyer/src/main/java/shop/alien/lawyer/service/impl/LawyerConsultationOrderServiceImpl.java

@@ -24,6 +24,7 @@ import shop.alien.entity.store.vo.LawyerConsultationOrderVO;
 import shop.alien.entity.store.vo.OrderRevenueVO;
 import shop.alien.entity.store.vo.WebSocketVo;
 import shop.alien.lawyer.config.WebSocketProcess;
+import shop.alien.lawyer.payment.PaymentStrategyFactory;
 import shop.alien.lawyer.service.LawyerConsultationOrderService;
 import shop.alien.lawyer.service.LawyerUserService;
 import shop.alien.lawyer.service.OrderExpirationService;
@@ -67,6 +68,9 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
     private final CommentAppealMapper commentAppealMapper;
     private final OrderReviewMapper orderReviewMapper;
 
+
+    private final PaymentStrategyFactory paymentStrategyFactory;
+
     /**
      * 系统发送者ID
      */
@@ -511,6 +515,21 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
             }
         }
 
+       String serviceType =lawyerConsultationOrder.getServiceType();
+
+        if (serviceType.contains("次")){
+            //对serviceType进行截取,比如"10次",想要10,则截取字符串"10",并转换为整型10
+            serviceType = serviceType.substring(0, serviceType.indexOf("次"));
+            order.setTimeNum(Integer.valueOf(serviceType));
+
+            order.setChargeTime(lawyerConsultationOrder.getPrice());
+        }
+        if (serviceType.contains("分钟")){
+            serviceType = serviceType.substring(0, serviceType.indexOf("分钟"));
+            order.setMinuteNum(Integer.valueOf(serviceType));
+            order.setChargeMinute(lawyerConsultationOrder.getPrice());
+        }
+
 
         // 设置订单状态
         order.setOrderStatus(0); // 待支付
@@ -620,8 +639,8 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
             order.setPayType(request.getPayType());
         }
         order.setOrderNumber(request.getOrderNumber());
-        order.setPaymentStatus(request.getPaymentStatus());
-        order.setOrderStatus(request.getOrderStatus());
+        order.setPaymentStatus(1);
+        order.setOrderStatus(1);
         order.setUpdatedTime(new Date());
         order.setDeleteFlag(0);
         order.setPaymentTime(new Date());
@@ -1087,7 +1106,7 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
     @Transactional(rollbackFor = Exception.class)
     public boolean cancelOrder(String id) {
         log.info("开始取消订单,订单ID={}", id);
-
+        try {
         // 1. 参数校验
         if (!StringUtils.hasText(id)) {
             log.warn("取消订单失败:订单ID为空");
@@ -1101,6 +1120,26 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
             return false;
         }
 
+        Map<String, String> params=new HashMap<>();
+        params.put("payType", "1".equals(order.getPayType()) ? "alipay" : "wechatPay");
+        params.put("outTradeNo",order.getAlipayNo());
+        params.put("totalAmount", String.valueOf(order.getOrderAmount()));
+
+            params.put("refundAmount", String.valueOf(order.getOrderAmount()));
+        if ("1".equals( order.getPayType())){
+            params.put("refundAmount", new BigDecimal(order.getOrderAmount()).divide(new BigDecimal(100)).toString());
+        }
+
+        if ("2".equals( order.getPayType())){
+            params.put("refundReason", "用户取消订单");
+        }
+
+        String refundResult =paymentStrategyFactory.getStrategy(params.get("payType")).handleRefund(params);
+
+        if (!"调用成功".equals(refundResult)){
+            log.warn("取消订单失败:订单取消失败,订单ID={}, 订单编号={}", id, order.getOrderNumber());
+            return false;
+        }
         // 3. 订单状态校验
         Integer orderStatus = order.getOrderStatus();
         String orderNumber = order.getOrderNumber();
@@ -1170,6 +1209,12 @@ public class LawyerConsultationOrderServiceImpl extends ServiceImpl<LawyerConsul
         }
 
         return success;
+
+        } catch (Exception e) {
+            log.error("取消订单失败:订单ID={}, 错误信息={}", id,  e.getMessage());
+            return false;
+        }
+
     }
 
     /**