ソースを参照

问题修改,0元订单直接完成

liweifan 3 年 前
コミット
7532980166

+ 12 - 2
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserOrderServiceImpl.java

@@ -2,6 +2,7 @@ package com.yonge.cooleshow.biz.dal.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.yonge.cooleshow.biz.dal.enums.*;
 import com.yonge.cooleshow.biz.dal.support.DistributedLock;
@@ -295,6 +296,11 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
             }
         }
         log.info("下单请求 start is {} end is {}", start, System.currentTimeMillis());
+
+        //判断订单是否是无需支付的订单,若是,则直接完成订单
+        if(BigDecimal.ZERO.equals(orderVo.getActualPrice())){
+            orderSuccess(orderVo);
+        }
         return HttpResponseResult.succeed(orderVo);
     }
 
@@ -665,12 +671,16 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         }
         //清除老师声部缓存
         redissonClient.getBucket(CacheNameEnum.STUDENT_SUBJECT_ITEM.getRedisKey(detail.getUserId())).delete();
-
     }
 
     private void testOrderSuccess(UserOrderVo detail) {
-        UserOrderPayment orderPayment = new UserOrderPayment();
+        if(null == detail || StringUtil.isEmpty(detail.getOrderNo())){
+            return;
+        }
+        //关闭当前正在支付的订单
+        orderPaymentService.closePaymentAndReqOpen(detail.getOrderNo(),"交易取消");
 
+        UserOrderPayment orderPayment = new UserOrderPayment();
         OpenEnum openType = OpenEnum.valueOf(paymentProperties.getOpenType());
         orderPayment.setOpenType(openType);
 

+ 7 - 2
toolset/toolset-payment/src/main/java/com/yonge/toolset/payment/original/ali/OriginalAliAppTemplate.java

@@ -26,6 +26,7 @@ import com.yonge.toolset.payment.core.props.PaymentProperties;
 import com.yonge.toolset.payment.core.service.SysConfigPaymentService;
 import com.yonge.toolset.payment.core.util.RequestKitBean;
 import com.yonge.toolset.payment.original.ali.constant.AlipayConstant;
+import com.yonge.toolset.payment.original.wx.constant.WxpayConstant;
 import com.yonge.toolset.utils.string.StringUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -277,10 +278,14 @@ public class OriginalAliAppTemplate implements PaymentTemplate {
 
                     ExecutePaymentCallBack executePayment = new ExecutePaymentCallBack();
                     String total_amount = jsonParams.getString("total_amount");
-                    String receipt_amount = jsonParams.getString("receipt_amount");
 
                     executePayment.setPayAmt(total_amount);
-                    executePayment.setFeeAmt(sub(total_amount, receipt_amount));
+                    if (!StringUtil.isEmpty(total_amount)) {
+                        String ALI_FEE_RATE = configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, AlipayConstant.ALI_FEE_RATE).getParamValue();
+                        BigDecimal feeRate = new BigDecimal(StringUtil.isEmpty(ALI_FEE_RATE) ? "0.006" : ALI_FEE_RATE);
+                        //支付宝不返回手续费,通过费率自己计算
+                        executePayment.setFeeAmt(new BigDecimal(total_amount).multiply(feeRate).setScale(2, BigDecimal.ROUND_HALF_UP).toString());
+                    }
                     executePayment.setTradeTime(jsonParams.getDate("gmt_payment"));
                     paymentCallBack.setExecutePaymentCallBack(executePayment);
                 }

+ 6 - 0
toolset/toolset-payment/src/main/java/com/yonge/toolset/payment/original/ali/constant/AlipayConstant.java

@@ -62,5 +62,11 @@ public interface AlipayConstant {
      * @updateTime 2022/5/12 14:12
      */
     String ALI_CONTENT_SIGN_TYPE = "ALI_CONTENT_SIGN_TYPE";
+    /***
+     * 支付宝-手续费率
+     * @author liweifan
+     * @updateTime 2022/5/13 14:09
+     */
+    String ALI_FEE_RATE = "ALI_FEE_RATE";
 
 }

+ 1 - 0
toolset/toolset-payment/src/main/java/com/yonge/toolset/payment/original/wx/OriginalWxAppTemplate.java

@@ -267,6 +267,7 @@ public class OriginalWxAppTemplate implements PaymentTemplate {
                     BigDecimal payAmt = new BigDecimal(result.getAmount().getTotal()).divide(new BigDecimal("100"));
                     executePayment.setPayAmt(payAmt.toString());
 
+                    //微信不返回手续费,通过
                     String WX_FEE_RATE = configPaymentService.getPaymentConfig(OpenEnum.ORIGINAL, WxpayConstant.WX_FEE_RATE).getParamValue();
 
                     BigDecimal feeRate = new BigDecimal(StringUtil.isEmpty(WX_FEE_RATE) ? "0.006" : WX_FEE_RATE);