From 6159dc58f50d3e4680779b7989bbd4d49a76bad5 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期五, 09 五月 2025 19:13:35 +0800
Subject: [PATCH] 添加日志

---
 src/main/java/com/taoke/autopay/controller/client/OrderController.java |  284 +++++++++++++++++++++++++++++++++++++++++---------------
 1 files changed, 205 insertions(+), 79 deletions(-)

diff --git a/src/main/java/com/taoke/autopay/controller/client/OrderController.java b/src/main/java/com/taoke/autopay/controller/client/OrderController.java
index 6ddb44c..dc44d01 100644
--- a/src/main/java/com/taoke/autopay/controller/client/OrderController.java
+++ b/src/main/java/com/taoke/autopay/controller/client/OrderController.java
@@ -11,19 +11,20 @@
 import com.taoke.autopay.entity.*;
 
 import com.taoke.autopay.exception.KeyOrderException;
+import com.taoke.autopay.exception.KeyVerifyException;
 import com.taoke.autopay.exception.WxOrderCountException;
 import com.taoke.autopay.factory.OrderFactory;
-import com.taoke.autopay.service.ClientInfoService;
-import com.taoke.autopay.service.KeyOrderService;
-import com.taoke.autopay.service.WxUserOrderCountService;
-import com.taoke.autopay.service.WxUserSettingService;
-import com.taoke.autopay.utils.JsonUtil;
-import com.taoke.autopay.utils.StringUtil;
-import com.taoke.autopay.utils.TimeUtil;
+import com.taoke.autopay.manager.OrderPayFailProcessor;
+import com.taoke.autopay.manager.PayCountVerifyManager;
+import com.taoke.autopay.service.*;
+import com.taoke.autopay.utils.*;
 import com.taoke.autopay.utils.order.DYOrderApi;
+import com.taoke.autopay.utils.order.OrderChannelApiUtil;
+import com.taoke.autopay.utils.order.OrderChannelUtil;
 import com.taoke.autopay.vo.AcceptData;
 import com.taoke.autopay.vo.KeyOrderVO;
 import com.taoke.autopay.vo.OrderFilter;
+import net.sf.json.JSONArray;
 import net.sf.json.JSONObject;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -33,7 +34,12 @@
 
 import javax.annotation.Resource;
 import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @author hxh
@@ -78,6 +84,21 @@
     @Resource
     private WxUserSettingService wxUserSettingService;
 
+    @Resource
+    private SystemConfigService systemConfigService;
+
+    @Resource
+    private OrderPayFailProcessor orderPayFailProcessor;
+
+    @Resource
+    private PayMoneySettingService payMoneySettingService;
+
+    @Resource
+    private UserSettingService userSettingService;
+
+    @Resource
+    private PayCountVerifyManager payCountVerifyManager;
+
 
     @ResponseBody
     @RequestMapping("listOrder")
@@ -96,6 +117,7 @@
         clientInfoService.setActiveTime(filter.getUid(), new Date());
         query.start = (filter.getPage() - 1) * filter.getPageSize();
         query.count = filter.getPageSize();
+        query.minCreateTime = new Date(System.currentTimeMillis() - 1000 * 60 * 30L);
         if (filter.getState() != null) {
             switch (filter.getState()) {
                 case OrderFilter.STATE_NOT_PROCESS:
@@ -156,25 +178,15 @@
         return JsonUtil.loadTrueResult(data);
     }
 
-    /**
-     * @return java.lang.String 杩斿洖鏄惁鍙互鍘绘敮浠�
-     * @author hxh
-     * @description 璁剧疆璁㈠崟鍙�
-     * @date 23:08 2024/6/24
-     * @param: acceptData
-     * @param: id 璁㈠崟ID
-     * @param: orderNo 璁㈠崟鍙�
-     * @param: orderStatus 璁㈠崟鐘舵�侊細璁㈠崟宸插彇娑�/宸叉敮浠�
-     **/
     @ResponseBody
-    @RequestMapping("setOrderNo")
-    public String setOrderNo(AcceptData acceptData, String id, String orderNo, String orderStatus) {
-        loggerPay.info("setOrderNo: {}-{}-{}", id, orderNo, orderStatus);
+    @RequestMapping("setOrderNoV2")
+    public String setOrderNoV2(AcceptData acceptData, String id, String orderNoDesc, String orderStatus, String money) {
+        loggerPay.info("setOrderNo[{}]: {}-{}-{}-{}", acceptData.getUid(), id, orderNoDesc, orderStatus, money);
         if (StringUtil.isNullOrEmpty(id)) {
             return JsonUtil.loadFalseResult("璇蜂笂浼爄d");
         }
-        if (StringUtil.isNullOrEmpty(orderNo)) {
-            return JsonUtil.loadFalseResult("orderNo");
+        if (StringUtil.isNullOrEmpty(money)) {
+            return JsonUtil.loadFalseResult("璇蜂笂浼爉oney");
         }
 
         KeyOrder order = keyOrderService.selectById(id);
@@ -182,70 +194,82 @@
             return JsonUtil.loadFalseResult("鍙d护涓嶅瓨鍦�");
         }
 
-        try {
-            if (order.getOrderNo() != null && !order.getOrderNo().equalsIgnoreCase(orderNo)) {
-                throw new KeyOrderException("宸茬粡澶勭悊杩囷紝涓庝箣鍓嶅鐞嗙殑璁㈠崟鍙蜂笉涓�鑷�");
-            }
-        } catch (KeyOrderException e) {
-            return JsonUtil.loadFalseResult(e.getMessage());
+        money = money.replace("楼", "");
+
+        int orderType = Constant.ORDER_TYPE_UNKNOWN;
+
+        if (orderNoDesc.contains("鎶栭煶") || orderNoDesc.contains("涓婃捣鏍肩墿鑷村搧")) {
+            orderType = Constant.ORDER_TYPE_DY;
+        } else if (orderNoDesc.contains("蹇墜")) {
+            orderType = Constant.ORDER_TYPE_KS;
         }
 
+        String orderNo = "";
         try {
+            if (orderType == Constant.ORDER_TYPE_UNKNOWN) {
+                throw new KeyOrderException("鏈畾涔夌殑璁㈠崟绫诲瀷");
+            }
+
             if (!StringUtil.isNullOrEmpty(orderStatus)) {
                 throw new KeyOrderException(orderStatus);
             }
-            DYOrderDto dto = DYOrderApi.getOrderDetail(orderNo);
-//            dto.setOrder_status(1);
-            if (dto.getOrder_status() != DYOrderDto.ORDER_STATUS_NOT_PAY) {
-                // 璁㈠崟涓嶅浜庡皻鏈粯娆剧姸鎬�
-                KeyOrder orderUpdate = new KeyOrder();
-                orderUpdate.setId(id);
-                orderUpdate.setOrderState(dto.getOrder_status());
-                orderUpdate.setOrderType(1);
-                orderUpdate.setOrderNo(orderNo);
-                if (order.getState() == KeyOrder.STATE_NOT_PROCESS) {
-                    if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) {
-                        orderUpdate.setState(KeyOrder.STATE_PAY);
-                        orderUpdate.setStateDesc(dto.getOrder_status_desc());
-                    } else {
-                        orderUpdate.setState(KeyOrder.STATE_PAY);
-                        orderUpdate.setStateDesc(dto.getOrder_status_desc());
-                    }
-                }
-                keyOrderService.update(orderUpdate);
-                if (dto.getOrder_status() == DYOrderDto.ORDER_STATUS_CANCELED) {
-                    throw new Exception("璁㈠崟宸插彇娑�");
-                } else {
-                    throw new Exception("璁㈠崟宸叉敮浠�");
-                }
+
+            DYOrderDto dyOrderDto = null;
+            try {
+                // 楠岃瘉璁㈠崟鏄惁鍙互鏀粯
+                dyOrderDto = keyOrderService.verifyKey(orderNoDesc, orderStatus, money, null, null);
+            } catch (KeyVerifyException ve) {
+                throw new KeyOrderException("鍙d护楠岃瘉澶辫触锛�" + ve.getMessage());
+            }
+//            if(dyOrderDto!=null&&order.getOrderMoney()!=null){
+//                // 鍒ゆ柇璁㈠崟鏀粯閲戦涓庣敤鎴锋彁浜ょ殑閲戦鏄惁鍖归厤
+//                if(dyOrderDto.getPay_amount()!=order.getOrderMoney().multiply(new BigDecimal(100)).setScale(0, RoundingMode.FLOOR).intValue()){
+//                    throw new KeyOrderException(String.format("璁㈠崟鎺ュ彛閲戦涓嶅尮閰嶏細%s-%s",dyOrderDto.getPay_amount(),MoneyUtil.getMoneyStr(order.getOrderMoney())));
+//                }
+//            }
+            if (dyOrderDto != null) {
+                orderNo = dyOrderDto.getOrder_id();
             }
 
+            OrderChannelEnum orderChannel = null;
+            if (dyOrderDto != null) {
+                orderChannel = OrderChannelUtil.getChannelByKey(dyOrderDto.getOrderChannel());
+            } else {
+                orderChannel = OrderChannelEnum.unknown;
+            }
+
+            // 楠岃瘉娓犻亾鏀粯娆℃暟鏄惁杈惧埌涓婇檺
             if (order.getUid() != null) {
-                WxUserOrderCount countInfo = wxUserOrderCountService.get(order.getUid(), OrderCountTypeEnum.DY_ORDER_PAY, TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
-                if (countInfo != null) {
-                    WxUserSettings settings = wxUserSettingService.selectByUid(order.getUid());
-                    if (settings.getDyOrderCountPerDay() <= countInfo.getOrderCount()) {
-                        throw new Exception("浠婃棩宸茶揪鏀粯娆℃暟涓婇檺锛�" + settings.getDyOrderCountPerDay());
-                    }
-                }
+                payCountVerifyManager.verifyPayCount(order.getUid(), orderType, orderChannel);
             }
 
             // 璁剧疆杩涘叆
             KeyOrder orderUpdate = new KeyOrder();
             orderUpdate.setId(id);
-            orderUpdate.setOrderType(1);
-            orderUpdate.setOrderState(dto.getOrder_status());
+            orderUpdate.setOrderType(orderType);
             orderUpdate.setOrderNo(orderNo);
+            orderUpdate.setOrderMoney(new BigDecimal(money));
+            if (dyOrderDto != null) {
+                orderUpdate.setOrderState(dyOrderDto.getOrder_status());
+                orderUpdate.setOrderChannel(dyOrderDto.getOrderChannel());
+                orderUpdate.setPayType(Constant.PAY_TYPE_WITH_ORDER_NO);
+            } else {
+                orderUpdate.setPayType(Constant.PAY_TYPE_WITH_MONEY);
+                orderUpdate.setOrderChannel(OrderChannelEnum.unknown.getKey());
+            }
             orderUpdate.setExcutePayTime(new Date());
             keyOrderService.update(orderUpdate);
             order = keyOrderService.selectById(id);
+            order.setPayType(orderUpdate.getPayType());
             return JsonUtil.loadTrueResult(gson.toJson(OrderFactory.create(order)));
         } catch (KeyOrderException e) {
+            loggerPay.info(String.format("璁剧疆璁㈠崟鍙峰嚭閿欙細%s-%s", id, e.getMessage()));
             KeyOrder orderUpdate = new KeyOrder();
             orderUpdate.setId(id);
-            orderUpdate.setOrderType(1);
-            orderUpdate.setOrderState(0);
+            orderUpdate.setOrderType(orderType);
             orderUpdate.setOrderNo(orderNo);
+            orderUpdate.setOrderMoney(new BigDecimal(money));
+            orderUpdate.setOrderState(0);
             orderUpdate.setState(KeyOrder.STATE_REJECT_PAY);
             if (order.getExcutePayTime() == null) {
                 orderUpdate.setExcutePayTime(new Date());
@@ -259,10 +283,103 @@
         }
     }
 
+    /**
+     * @author hxh
+     * @description 璁剧疆鍟嗗鏄惁鍙敮浠�
+     * @date 1:26 2025/2/8
+     * @param: acceptData
+     * @param: id
+     * @param: merchant
+     * @return java.lang.String
+     **/
+
+    @ResponseBody
+    @RequestMapping("isMerchantCanPay")
+    public String isMerchantCanPay(AcceptData acceptData, String id, String merchant) {
+        loggerPay.info("isMerchantCanPay[{}]: {}-{}", acceptData.getUid(), id, merchant);
+        // 鍒ゆ柇鏄惁涓哄崱閲戦
+        KeyOrder keyOrder = keyOrderService.selectById(id);
+        if (keyOrder == null) {
+            return JsonUtil.loadFalseResult("璁㈠崟ID涓嶅瓨鍦�");
+        }
+        OrderChannelEnum orderChannel = OrderChannelUtil.getChannelByKey(keyOrder.getOrderChannel());
+        if (orderChannel != OrderChannelEnum.unknown) {
+            // 纭畾娓犻亾鐨勮鍗曞彲鐩存帴鏀粯
+            return JsonUtil.loadTrueResult("");
+        }
+
+        // 鑾峰彇鍗¢噾棰濈殑璁剧疆淇℃伅
+        PayMoneySetting payMoneySetting = payMoneySettingService.getSettingByMoney(keyOrder.getOrderMoney());
+        if (payMoneySetting == null) {
+            keyOrderService.rejectPay(keyOrder.getId(),"浠樻閲戦涓嶅睘浜庡崱閲戦鑼冨洿");
+            return JsonUtil.loadFalseResult("浠樻閲戦涓嶅睘浜庡崱閲戦鑼冨洿");
+        }
+        if (payMoneySetting.getVerifyMerchantChannel() == null || payMoneySetting.getVerifyMerchantChannel() == OrderChannelEnum.unknown) {
+            // 娌℃湁璁剧疆鏍¢獙娓犻亾
+            return JsonUtil.loadTrueResult("");
+        }
+
+        try {
+            // 鐩墠鍙垽鏂秴浜剑
+            boolean isCanPay = OrderChannelApiUtil.isMerchantCanPay(payMoneySetting.getVerifyMerchantChannel(), merchant, keyOrder.getOrderMoney());
+            if (isCanPay) {
+                // 閫氳繃鍟嗗鏍¢獙
+                try {
+                    payCountVerifyManager.verifyPayCount(keyOrder.getUid(), keyOrder.getOrderType(), payMoneySetting.getVerifyMerchantChannel());
+                }catch (KeyOrderException ee){
+                    // 鎷掔粷鏀粯
+                    keyOrderService.rejectPay(keyOrder.getId(), ee.getMessage());
+                    return JsonUtil.loadFalseResult(ee.getMessage());
+                }finally {
+                    // 鏇存柊娓犻亾
+                    KeyOrder update = new KeyOrder();
+                    update.setId(keyOrder.getId());
+                    update.setOrderChannel(payMoneySetting.getVerifyMerchantChannel().getKey());
+                    keyOrderService.update(update);
+                }
+                return JsonUtil.loadTrueResult("");
+            } else {
+                // 鏈�氳繃鍟嗗鏍¢獙
+                keyOrderService.rejectPay(keyOrder.getId(),"鍟嗗鏍¢獙鏈�氳繃");
+                return JsonUtil.loadFalseResult("鍟嗗鏍¢獙鏈�氳繃");
+            }
+        } catch (UnsupportedEncodingException e) {
+            return JsonUtil.loadFalseResult(e.getMessage());
+        }
+    }
+
+    /**
+     * @return java.lang.String
+     * @author hxh
+     * @description 鏄惁鍙互鎵ц鏀粯
+     * @date 0:22 2024/12/28
+     * @param: acceptData
+     * @param: id
+     **/
+    @ResponseBody
+    @RequestMapping("canExcutePay")
+    public String canExcutePay(AcceptData acceptData, String id) {
+        try {
+            KeyOrder keyOrder = keyOrderService.selectByIdForUpdate(id);
+            if (keyOrder == null) {
+                throw new Exception("璁㈠崟涓嶅瓨鍦�");
+            }
+            if (keyOrder.getState() == KeyOrder.STATE_PAY) {
+                throw new Exception("璁㈠崟宸叉敮浠�");
+            }
+            loggerPay.info("canExcutePay[{}]: {}-{}", acceptData.getUid(), id, "鍙互鏀粯");
+            return JsonUtil.loadTrueResult("");
+        } catch (Exception e) {
+            loggerPay.error("canExcutePay[{}]: {}-{}", acceptData.getUid(), id, "涓嶅彲浠ユ敮浠橈細" + e.getMessage());
+            return JsonUtil.loadFalseResult(e.getMessage());
+        }
+    }
+
+
     @ResponseBody
     @RequestMapping("setPayResult")
-    public String setPayResult(AcceptData acceptData, String id, boolean paySuccess, String msg) {
-        loggerPay.info("setPayResult: {}-{}", id, paySuccess);
+    public String setPayResult(AcceptData acceptData, String id, boolean paySuccess, String msg, String payMerchant) {
+        loggerPay.info("setPayResult[{}]: {}-{}-{}-{}", acceptData.getUid(), id, paySuccess, msg, payMerchant);
         if (StringUtil.isNullOrEmpty(id)) {
             return JsonUtil.loadFalseResult("璇蜂笂浼爄d");
         }
@@ -270,22 +387,31 @@
         if (order == null) {
             return JsonUtil.loadFalseResult("鍙d护涓嶅瓨鍦�");
         }
-        if (StringUtil.isNullOrEmpty(order.getOrderNo())) {
-            return JsonUtil.loadFalseResult("娌℃湁鍖归厤鍒拌鍗曞彿");
-        }
+//        if (StringUtil.isNullOrEmpty(order.getOrderNo())) {
+//            return JsonUtil.loadFalseResult("娌℃湁鍖归厤鍒拌鍗曞彿");
+//        }
 
         if (order.getState() == KeyOrder.STATE_NOT_PROCESS) {
             if (!paySuccess) {
                 // 鏀粯澶辫触
-                KeyOrder orderUpdate = new KeyOrder();
-                orderUpdate.setId(id);
-                orderUpdate.setState(KeyOrder.STATE_NOT_PAY);
-                orderUpdate.setStateDesc("鏀粯澶辫触");
-                keyOrderService.update(orderUpdate);
+                if (msg != null && msg.contains("瓒呮椂")) {
+                    loggerPay.info(String.format("鍥犱负瓒呮椂鏀粯澶辫触涓嶅鐞嗭細%s-%s", order.getId(), msg));
+                    orderPayFailProcessor.processPayFail(order.getId(), msg);
+                } else {
+                    KeyOrder orderUpdate = new KeyOrder();
+                    orderUpdate.setId(id);
+                    orderUpdate.setState(KeyOrder.STATE_NOT_PAY);
+                    orderUpdate.setStateDesc("鏀粯澶辫触锛�" + msg);
+                    orderUpdate.setPayMerchant(payMerchant);
+                    keyOrderService.update(orderUpdate);
+                }
+                loggerPay.info("澶勭悊鏀粯澶辫触瀹屾垚");
             } else {
                 try {
-                    keyOrderService.paySuccess(id, "鏀粯鎴愬姛", TimeUtil.getGernalTime(System.currentTimeMillis(), "yyyyMMdd"));
+                    keyOrderService.paySuccess(id, "鏀粯鎴愬姛", TimeUtil.getGernalTime(System.currentTimeMillis(), Constant.DB_DAY_FORMAT), payMerchant);
+                    loggerPay.info("澶勭悊鏀粯鎴愬姛瀹屾垚");
                 } catch (WxOrderCountException e) {
+                    loggerPay.error(e.getMessage());
                     e.printStackTrace();
                     return JsonUtil.loadFalseResult(e.getMessage());
                 }
@@ -297,8 +423,8 @@
 
     @ResponseBody
     @RequestMapping("rejectPay")
-    public String rejectPay(AcceptData acceptData, Long uid, String id) {
-        loggerPay.info("rejectPay: {}-{}", uid, id);
+    public String rejectPay(AcceptData acceptData, String id) {
+        loggerPay.info("rejectPay: {}-{}", acceptData.getUid(), id);
         if (StringUtil.isNullOrEmpty(id)) {
             return JsonUtil.loadFalseResult("璇蜂笂浼爄d");
         }
@@ -334,9 +460,9 @@
             return JsonUtil.loadFalseResult("鍙湁绠$悊鍛樻墠鑳藉垹闄�");
         }
 
-        // 鍒犻櫎24灏忔椂涔嬪墠鐨勬暟鎹�
-//        keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 24*60*60*1000L));
-        keyOrderService.deleteAll(new Date(System.currentTimeMillis()));
+        // 鍒犻櫎10澶╀箣鍓嶇殑鏁版嵁
+        keyOrderService.deleteAll(new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000L * 10));
+//        keyOrderService.deleteAll(new Date(System.currentTimeMillis()));
         // 鍒櫎鎵�鏈夋暩鎿�
         return JsonUtil.loadTrueResult("");
     }

--
Gitblit v1.8.0