Parcourir la source

下单接口修改

weifanli il y a 3 ans
Parent
commit
428696db1c

+ 42 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/UserOrderPaymentService.java

@@ -1,7 +1,12 @@
 package com.yonge.cooleshow.biz.dal.service;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.extension.service.IService;
+import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
 import com.yonge.cooleshow.biz.dal.entity.UserOrderPayment;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
+
+import java.util.Map;
 
 /**
  * 平台订单支付表 服务类
@@ -26,4 +31,41 @@ public interface UserOrderPaymentService extends IService<UserOrderPayment> {
      * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
      */
     UserOrderPayment detailByTransNo(String transNo);
+
+    /***
+     * 请求惠付接口后插入订单付款表
+     * @author liweifan
+     * @param: responseResult
+     * @param: payReq
+     * @updateTime 2022/5/6 15:13
+     * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
+     */
+    UserOrderPayment insertOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq);
+
+    /***
+     * 关闭付款单
+     * @author liweifan
+     * @param: orderNo
+     * @param: reason
+     * @updateTime 2022/5/6 14:49
+     * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
+     */
+    UserOrderPayment closePayment(String orderNo,String reason);
+
+    /***
+     * 支付关单成功
+     * @author liweifan
+     * @param: hfRes
+     * @updateTime 2022/4/27 15:33
+     */
+    void paymentCloseSucceededHandle(JSONObject hfRes);
+
+    /***
+     * 支付关单失败
+     * @author liweifan
+     * @param: hfRes
+     * @updateTime 2022/4/27 15:33
+     */
+    void paymentCloseFailedHandle(JSONObject hfRes);
+
 }

+ 0 - 1
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/MemberPriceSettingsServiceImpl.java

@@ -61,7 +61,6 @@ public class MemberPriceSettingsServiceImpl extends ServiceImpl<MemberPriceSetti
         if (null == detail) {
             return HttpResponseResult.failed("未找到会员卡信息");
         }
-        //插入会员卡信息到会员卡记录表
         OrderCreateRes orderCreateRes = new OrderCreateRes();
         orderCreateRes.setRes(true);
         orderCreateRes.setBizId(detail.getId());

+ 99 - 0
cooleshow-user/user-biz/src/main/java/com/yonge/cooleshow/biz/dal/service/impl/UserOrderPaymentServiceImpl.java

@@ -1,16 +1,31 @@
 package com.yonge.cooleshow.biz.dal.service.impl;
 
+import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.yonge.cooleshow.biz.dal.dto.req.OrderPayReq;
+import com.yonge.cooleshow.biz.dal.enums.TradeStatusEnum;
+import com.yonge.cooleshow.biz.dal.sdk.PaymentSdk;
+import com.yonge.cooleshow.common.entity.HttpResponseResult;
+import com.yonge.toolset.utils.string.StringUtil;
+import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import com.yonge.cooleshow.biz.dal.entity.UserOrderPayment;
 import com.yonge.cooleshow.biz.dal.dao.UserOrderPaymentDao;
 import com.yonge.cooleshow.biz.dal.service.UserOrderPaymentService;
 
+import java.math.BigDecimal;
+import java.math.RoundingMode;
+import java.util.Date;
+import java.util.Map;
+
 
 @Service
 public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao, UserOrderPayment> implements UserOrderPaymentService {
 
+    @Autowired
+    private PaymentSdk paymentSdk;
+
     @Override
     public UserOrderPayment detailByOrderNo(String orderNo) {
         return baseMapper.selectOne(Wrappers.<UserOrderPayment>lambdaQuery()
@@ -22,4 +37,88 @@ public class UserOrderPaymentServiceImpl extends ServiceImpl<UserOrderPaymentDao
         return baseMapper.selectOne(Wrappers.<UserOrderPayment>lambdaQuery()
                 .eq(UserOrderPayment::getTransNo, transNo));
     }
+
+
+    @Override
+    public UserOrderPayment insertOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq) {
+        UserOrderPayment orderPayment = new UserOrderPayment();
+        orderPayment.setOrderNo(payReq.getOrderNo());
+        orderPayment.setPayChannel(payReq.getPayChannel());
+        if (responseResult.getStatus()) {
+            Map<String, Object> res = responseResult.getData();
+            orderPayment.setTransNo(res.get("id").toString());
+            orderPayment.setPayAmt(
+                    new BigDecimal(res.get("pay_amt").toString()).setScale(2, RoundingMode.HALF_UP)
+            );
+            String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
+            orderPayment.setPayInfo(pay_info);
+            orderPayment.setStatus(TradeStatusEnum.pending);
+        } else {
+            orderPayment.setPayFailMsg(responseResult.getMsg());
+            orderPayment.setStatus(TradeStatusEnum.failed);
+        }
+        save(orderPayment);
+        return orderPayment;
+    }
+
+    @Override
+    public UserOrderPayment closePayment(String orderNo, String reason) {
+        UserOrderPayment orderPayment = detailByOrderNo(orderNo);
+        //未创建付款单,直接创建付款单
+        if(null == orderPayment){
+            orderPayment = new UserOrderPayment();
+            orderPayment.setOrderNo(orderNo);
+            orderPayment.setStatus(TradeStatusEnum.failed);
+            orderPayment.setPayFailMsg(StringUtil.isEmpty(reason) ? "交易取消" : reason);
+            orderPayment.setUpdateTime(new Date());
+            save(orderPayment);
+            return orderPayment;
+        }
+        //更新
+        if (!TradeStatusEnum.pending.equals(orderPayment.getStatus())) {
+            return orderPayment;
+        }
+
+        //更新付款单
+        orderPayment.setStatus(TradeStatusEnum.failed);
+        orderPayment.setPayFailMsg(StringUtil.isEmpty(reason) ? "交易取消" : reason);
+        orderPayment.setUpdateTime(new Date());
+
+        //发送支付关单请求
+        if(!StringUtil.isEmpty(orderPayment.getTransNo())){
+            HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.closePayment(orderPayment.getTransNo(), reason, "");
+            if (!responseResult.getStatus()) {
+                orderPayment.setCloseStatus(TradeStatusEnum.failed);
+                orderPayment.setCloseFailMsg(responseResult.getMsg());
+            } else {
+                orderPayment.setCloseStatus(TradeStatusEnum.pending);
+            }
+        }
+        updateById(orderPayment);
+        return orderPayment;
+    }
+
+    @Override
+    public void paymentCloseSucceededHandle(JSONObject hfRes) {
+        UserOrderPayment orderPayment = detailByTransNo(hfRes.getString("payment_id"));
+        if (null == orderPayment) {
+            return;
+        }
+        orderPayment.setCloseStatus(TradeStatusEnum.succeeded);
+        orderPayment.setUpdateTime(new Date());
+        updateById(orderPayment);
+    }
+
+
+    @Override
+    public void paymentCloseFailedHandle(JSONObject hfRes) {
+        UserOrderPayment orderPayment = detailByTransNo(hfRes.getString("payment_id"));
+        if (null == orderPayment) {
+            return;
+        }
+        orderPayment.setStatus(TradeStatusEnum.failed);
+        orderPayment.setPayFailMsg("支付关单回调失败-" + hfRes.getString("error_msg"));
+        orderPayment.setUpdateTime(new Date());
+        updateById(orderPayment);
+    }
 }

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

@@ -171,8 +171,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         if (null == detail) {
             return HttpResponseResult.failed("未找到订单信息");
         }
-        if(!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
-            && !OrderStatusEnum.PAYING.equals(detail.getStatus())){
+        if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
+                && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
             return HttpResponseResult.failed("订单已完成");
         }
         if (!StringUtil.isEmpty(detail.getTransNo())) {
@@ -213,16 +213,16 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
     @Override
     public void setOrderStatus(String orderNo, OrderStatusEnum orderStatus) {
         UserOrderVo detail = detail(orderNo);
-        if(OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
-            || OrderStatusEnum.PAYING.equals(detail.getStatus())){
+        if (OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
+                || OrderStatusEnum.PAYING.equals(detail.getStatus())) {
 
-            if(OrderStatusEnum.CLOSE.equals(orderStatus)){
-                doOrderCancel(detail,orderStatus,"测试接口-订单关闭");
+            if (OrderStatusEnum.CLOSE.equals(orderStatus)) {
+                doOrderCancel(detail, orderStatus, "测试接口-订单关闭");
             }
-            if(OrderStatusEnum.FAIL.equals(orderStatus)){
-                doOrderCancel(detail,orderStatus,"测试接口-订单交易失败");
+            if (OrderStatusEnum.FAIL.equals(orderStatus)) {
+                doOrderCancel(detail, orderStatus, "测试接口-订单交易失败");
             }
-            if(OrderStatusEnum.PAID.equals(orderStatus)){
+            if (OrderStatusEnum.PAID.equals(orderStatus)) {
                 orderSuccess(detail);
             }
         }
@@ -315,7 +315,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         //查询订单
         UserOrderVo detail = detail(payReq.getOrderNo());
         if (OrderStatusEnum.PAYING.equals(detail.getStatus())) {
-            //处于付款中状态,需要拉起付款接口返回信息,并且去到汇付
             return orderPayPaying(payReq, detail);
         }
         return HttpResponseResult.failed("订单状态异常");
@@ -330,9 +329,9 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         } else if (type.equals("payment.failed")) {//支付失败
             paymentFailedHandle(hfRes);
         } else if (type.equals("payment.close.succeeded")) {//支付关单成功
-            paymentCloseSucceededHandle(hfRes);
+            orderPaymentService.paymentCloseSucceededHandle(hfRes);
         } else if (type.equals("payment.close.failed")) {//支付关单失败
-            paymentCloseFailedHandle(hfRes);
+            orderPaymentService.paymentCloseFailedHandle(hfRes);
         }
     }
 
@@ -378,39 +377,6 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         }
     }
 
-    /***
-     * 支付关单成功
-     * @author liweifan
-     * @param: hfRes
-     * @updateTime 2022/4/27 15:33
-     */
-    private void paymentCloseSucceededHandle(JSONObject hfRes) {
-        UserOrderPayment orderPayment = orderPaymentService.detailByTransNo(hfRes.getString("payment_id"));
-        if (null == orderPayment) {
-            return;
-        }
-        orderPayment.setCloseStatus(TradeStatusEnum.succeeded);
-        orderPayment.setUpdateTime(new Date());
-        orderPaymentService.updateById(orderPayment);
-    }
-
-    /***
-     * 支付关单失败
-     * @author liweifan
-     * @param: hfRes
-     * @updateTime 2022/4/27 15:33
-     */
-    private void paymentCloseFailedHandle(JSONObject hfRes) {
-        UserOrderPayment orderPayment = orderPaymentService.detailByTransNo(hfRes.getString("payment_id"));
-        if (null == orderPayment) {
-            return;
-        }
-        orderPayment.setStatus(TradeStatusEnum.failed);
-        orderPayment.setPayFailMsg("支付关单回调失败-" + hfRes.getString("error_msg"));
-        orderPayment.setUpdateTime(new Date());
-        orderPaymentService.updateById(orderPayment);
-    }
-
     @Override
     public void pollingOrder() {
         //查询半小时前创建的并且还未完成的订单 WAIT_PAY 待支付订单 PAYING 支付中订单
@@ -444,8 +410,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         if (null == detail) {
             return;
         }
-        if(!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
-                && !OrderStatusEnum.PAYING.equals(detail.getStatus())){
+        if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
+                && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
             return;
         }
         if (!StringUtil.isEmpty(detail.getTransNo())) {
@@ -476,6 +442,17 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
      * @return: com.yonge.cooleshow.common.entity.HttpResponseResult<com.yonge.cooleshow.biz.dal.vo.res.OrderPayRes>
      */
     private HttpResponseResult<OrderPayRes> orderPayWaitPay(OrderPayReq payReq, UserOrderVo detail) {
+        OrderPayRes orderPayRes = new OrderPayRes();
+
+        UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo());
+        if (null != orderPayment && TradeStatusEnum.pending.equals(orderPayment.getStatus())
+                && !StringUtil.isEmpty(orderPayment.getPayInfo())) {
+            orderPayRes.setPay_amt(orderPayment.getPayAmt().toString());
+            orderPayRes.setPay_info(orderPayment.getPayInfo());
+            orderPayRes.setPayChannel(orderPayment.getPayChannel());
+            return HttpResponseResult.succeed(orderPayRes);
+        }
+
         PaymentReq paymentReq = new PaymentReq();
         paymentReq.setOrder_no(payReq.getOrderNo());
         paymentReq.setPay_channel(payReq.getPayChannel().getCode());
@@ -503,76 +480,21 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         //付款请求
         HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.executePayment(paymentReq);
         if (responseResult.getStatus()) {
-            OrderPayRes orderPayRes = new OrderPayRes();
             orderPayRes.setPay_amt(detail.getActualPrice().setScale(2, RoundingMode.HALF_UP).toString());
             String pay_info = ((JSONObject) responseResult.getData().get("expend")).getString("pay_info");
             orderPayRes.setPay_info(pay_info);
             orderPayRes.setPayChannel(payReq.getPayChannel());
 
             //入订单付款表,同时修改订单状态
-            insertOrderPayment(responseResult, payReq);
+            orderPaymentService.insertOrderPayment(responseResult, payReq);
+
             baseMapper.updateStatusByOrderNo(payReq.getOrderNo(), OrderStatusEnum.PAYING.getCode());
             return HttpResponseResult.succeed(orderPayRes);
         } else {
             //入订单付款表,同时修改订单状态
-            doOrderCancel(detail, OrderStatusEnum.FAIL, "订单超时");
-            errOrderPayment(responseResult, payReq);
+            doOrderCancel(detail, OrderStatusEnum.FAIL, responseResult.getMsg());
             return HttpResponseResult.failed(responseResult.getMsg());
         }
-
-    }
-
-    /***
-     * 插入订单付款单
-     * @author liweifan
-     * @param: res
-     * @param: payReq
-     * @updateTime 2022/4/13 17:56
-     * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
-     */
-    private UserOrderPayment insertOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq) {
-        UserOrderPayment orderPayment = new UserOrderPayment();
-        orderPayment.setOrderNo(payReq.getOrderNo());
-        orderPayment.setPayChannel(payReq.getPayChannel());
-        if (responseResult.getStatus()) {
-            Map<String, Object> res = responseResult.getData();
-            orderPayment.setTransNo(res.get("id").toString());
-            orderPayment.setPayAmt(
-                    new BigDecimal(res.get("pay_amt").toString()).setScale(2, RoundingMode.HALF_UP)
-            );
-            String pay_info = ((JSONObject) res.get("expend")).getString("pay_info");
-            orderPayment.setPayInfo(pay_info);
-            orderPayment.setStatus(TradeStatusEnum.pending);
-        } else {
-            orderPayment.setPayFailMsg(responseResult.getMsg());
-            orderPayment.setStatus(TradeStatusEnum.failed);
-        }
-        orderPaymentService.save(orderPayment);
-        return orderPayment;
-    }
-
-    /***
-     * 处理付款请求失败
-     * @author liweifan
-     * @param: res
-     * @param: payReq
-     * @updateTime 2022/4/13 17:56
-     * @return: com.yonge.cooleshow.biz.dal.entity.UserOrderPayment
-     */
-    private UserOrderPayment errOrderPayment(HttpResponseResult<Map<String, Object>> responseResult, OrderPayReq payReq) {
-        //查询
-        UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(payReq.getOrderNo());
-        if (null == orderPayment) {
-            orderPayment = new UserOrderPayment();
-            orderPayment.setOrderNo(payReq.getOrderNo());
-            orderPayment.setPayChannel(payReq.getPayChannel());
-        }
-        orderPayment.setPayFailMsg(responseResult.getMsg());
-        orderPayment.setStatus(TradeStatusEnum.failed);
-        orderPayment.setUpdateTime(new Date());
-
-        orderPaymentService.saveOrUpdate(orderPayment);
-        return orderPayment;
     }
 
     /***
@@ -779,25 +701,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
         userOrder.setUpdateTime(new Date());
         baseMapper.updateById(userOrder);
 
-
-        UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(userOrder.getOrderNo());
-        if (null != orderPayment) {
-            //更新付款单
-            orderPayment.setStatus(TradeStatusEnum.failed);
-            orderPayment.setPayFailMsg(StringUtil.isEmpty(reason) ? "交易取消" : reason);
-            orderPayment.setUpdateTime(new Date());
-        }
-        //发送支付关单请求
-        HttpResponseResult<Map<String, Object>> responseResult = paymentSdk.closePayment(userOrder.getTransNo(), reason, "");
-        if (!responseResult.getStatus()) {
-            orderPayment.setCloseStatus(TradeStatusEnum.failed);
-            orderPayment.setCloseFailMsg(responseResult.getMsg());
-            orderPaymentService.updateById(orderPayment);
-            return;
-        } else {
-            orderPayment.setCloseStatus(TradeStatusEnum.pending);
-            orderPaymentService.updateById(orderPayment);
-        }
+        orderPaymentService.closePayment(userOrder.getOrderNo(), reason);
     }
 
     void orderSuccess(UserOrderVo detail) {

+ 1 - 0
cooleshow-user/user-biz/src/main/resources/config/mybatis/MemberPriceSettingsMapper.xml

@@ -29,6 +29,7 @@
 			<include refid="baseColumns"/>,
 			ifnull(u.real_name_,u.username_) modifierName
 		FROM member_price_settings t
+		LEFT JOIN sys_user u on t.update_by_ = u.id_
 		where t.id_ = #{id}
 	</select>
 

+ 4 - 1
cooleshow-user/user-biz/src/main/resources/config/mybatis/VipCardRecordMapper.xml

@@ -43,7 +43,10 @@
         select
             <include refid="baseColumns"/>,
             u.phone_ as phone
-        from vip_card_record t
+        from (
+            select max(id_) as id_ from vip_card_record group by user_id_
+        ) a
+        left join vip_card_record t on a.id_ = t.id_
         left join sys_user u on t.user_id_ = u.id_
         where t.end_time_ &gt;= now()
         and t.end_time_ &lt; DATE_ADD(now(),INTERVAL 3 DAY)