From 65aaf1c05bd06cefa82ebc40cc3e01cf4ac233c0 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期六, 27 七月 2024 13:52:08 +0800
Subject: [PATCH] 代理新功能完善

---
 src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java |  106 +++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 95 insertions(+), 11 deletions(-)

diff --git a/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java b/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java
index 182e135..7ef1ea8 100644
--- a/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java
+++ b/src/main/java/com/taoke/autopay/service/impl/KeyOrderServiceImpl.java
@@ -2,22 +2,28 @@
 
 import com.taoke.autopay.dao.KeyOrderMapper;
 import com.taoke.autopay.dao.WxUserSettingsMapper;
-import com.taoke.autopay.entity.KeyOrder;
-import com.taoke.autopay.entity.OrderCountTypeEnum;
-import com.taoke.autopay.entity.OrderDistributeCountInfo;
-import com.taoke.autopay.entity.WxUserSettings;
+import com.taoke.autopay.dto.DYOrderDto;
+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.KeyOrderService;
+import com.taoke.autopay.service.SystemConfigService;
 import com.taoke.autopay.service.WxUserOrderCountService;
 import com.taoke.autopay.service.WxUserSettingService;
-import com.taoke.autopay.utils.TimeUtil;
+import com.taoke.autopay.utils.*;
+import com.taoke.autopay.utils.order.DYOrderApi;
+import com.taoke.autopay.vo.SubmitKeyInfo;
+import net.sf.json.JSONArray;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 /**
  * @author hxh
@@ -37,6 +43,9 @@
     @Resource
     private WxUserOrderCountService wxUserOrderCountService;
 
+    @Resource
+    private SystemConfigService systemConfigService;
+
 
     @Override
     public KeyOrder selectById(String id) {
@@ -45,20 +54,23 @@
 
     @Transactional(rollbackFor = Exception.class)
     @Override
-    public KeyOrder addKeyOrder(String key, Long uid, String day) throws KeyOrderException, WxOrderCountException {
+    public KeyOrder addKeyOrder(SubmitKeyInfo keyInfo, Long uid, String day) throws KeyOrderException, WxOrderCountException {
         // 鍒ゆ柇鎻愪氦娆℃暟鏄惁杩囬噺
         if (uid != null) {
-            WxUserSettings settings = wxUserSettingService.selectByUid(uid);
+            WxUserSettings settings = wxUserSettingService.getUserSettings(uid);
             wxUserOrderCountService.addOrderCount(uid, OrderCountTypeEnum.SUBMIT_TOKEN_COUNT, day, 1, settings.getTotalOrderCountPerDay());
         }
-        String id = OrderFactory.createId(key);
+        String id = OrderFactory.createId(keyInfo.getKey());
         KeyOrder order = keyOrderMapper.selectById(id);
         if (order != null) {
             throw new KeyOrderException("璇峰嬁閲嶅鎻愪氦鍙d护");
         }
         order = new KeyOrder();
         order.setId(id);
-        order.setKey(key);
+        order.setKey(keyInfo.getKey());
+        if(!StringUtil.isNullOrEmpty(keyInfo.getMoney())){
+            order.setOrderMoney(new BigDecimal(keyInfo.getMoney()));
+        }
         order.setUid(uid);
         order.setState(KeyOrder.STATE_NOT_PROCESS);
         order.setStateDesc("灏氭湭澶勭悊");
@@ -102,6 +114,9 @@
         orderUpdate.setId(id);
         orderUpdate.setState(KeyOrder.STATE_PAY);
         orderUpdate.setStateDesc(stateDesc);
+        if(old.getPayTime()==null){
+            orderUpdate.setPayTime(new Date());
+        }
         update(orderUpdate);
     }
 
@@ -136,8 +151,8 @@
 
     @Override
     public Long getCanDistributeUid() {
-        // 鏈�杩�1灏忔椂鏈夋椿璺�
-        List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 60L));
+        // 鏈�杩�1灏忔椂鏈夋椿璺�,涓斾笉绠�12浠ヤ笂鏈墽琛岀殑鏁版嵁
+        List<OrderDistributeCountInfo> list = keyOrderMapper.listDistributeUids(new Date(System.currentTimeMillis() - 1000 * 60 * 60L),new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 12L));
         if (list == null || list.size() == 0) {
             return null;
         }
@@ -185,4 +200,73 @@
     public void deleteAll(Date maxCreateTime) {
         keyOrderMapper.deleteAll(maxCreateTime);
     }
+
+    @Override
+    public DYOrderDto verifyKey(String orderNoDesc, String orderStatus, String money) throws  KeyVerifyException {
+        int orderType= Constant.ORDER_TYPE_UNKNOWN;
+        if(orderNoDesc.contains("鎶栭煶")){
+            orderType = Constant.ORDER_TYPE_DY;
+        }else  if(orderNoDesc.contains("蹇墜")){
+            orderType = Constant.ORDER_TYPE_KS;
+        }
+
+        String orderNo= "";
+        // 鍖归厤杩炵画鐨勬暟瀛�
+        Pattern pattern = Pattern.compile("\\d+");
+        Matcher matcher = pattern.matcher(orderNoDesc);
+        while (matcher.find()) {
+            // 鑾峰彇鍖归厤鍒扮殑鏁板瓧瀛楃涓�
+            String number = matcher.group();
+            if (number.length() > 10) {
+                orderNo = number;
+                break;
+            }
+        }
+
+            if(orderType==Constant.ORDER_TYPE_UNKNOWN){
+                throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_TYPE_ERROR, "鏈畾涔夌殑璁㈠崟绫诲瀷");
+            }
+
+            if (!StringUtil.isNullOrEmpty(orderStatus)&&!orderStatus.contains("鏈敮浠�")) {
+                throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_STATUS_ERROR, "璁㈠崟鐘舵�侊細"+orderStatus);
+            }
+            DYOrderDto dyOrderDto=null;
+            // 鍏堝尮閰嶈鍗�
+            try {
+                if(orderType == Constant.ORDER_TYPE_DY&&!StringUtil.isNullOrEmpty(orderNo)){
+                    dyOrderDto = DYOrderApi.getOrderDetail(orderNo);
+                    if(dyOrderDto!=null){
+                        // 楠岃瘉閲戦
+                        if( dyOrderDto.getPay_amount().intValue()!= new BigDecimal(money).multiply(new BigDecimal(100)).setScale(0).intValue()){
+                            throw new KeyVerifyException(KeyVerifyException.CODE_ORDER_MONEY_NOT_MATCH ,String.format("鏀粯閲戦涓庤鍗曢噾棰濅笉涓�鑷达細%s-%d",money,dyOrderDto.getPay_amount() ));
+                        }
+                    }
+                }else{
+                    throw new KeyOrderException("鎶栭煶璁㈠崟鑾峰彇澶辫触");
+                }
+            }catch(KeyOrderException e){
+                // 鎶栭煶璁㈠崟鏈獙璇侀�氳繃锛屽尮閰嶉噾棰�
+                // 楠岃瘉鎻愪氦鐨勯噾棰濇槸鍚︽纭�
+                String moneyStr =  systemConfigService.getValueCache(SystemConfigKeyEnum.PAY_MONEY_LIST);
+                if(StringUtil.isNullOrEmpty(moneyStr)){
+                    throw new KeyVerifyException(KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH ,"灏氭湭閰嶇疆閲戦");
+                }
+                JSONArray array=JSONArray.fromObject(moneyStr);
+                Set<String> moneySet=new HashSet<>();
+                for(int i=0;i<array.size();i++){
+                    moneySet.add(MoneyUtil.getMoneyStr(new BigDecimal(array.optString(i))));
+                }
+                // 鍖归厤閲戦
+                if(!moneySet.contains(money)){
+                    throw new KeyVerifyException(KeyVerifyException.CODE_KEY_MONEY_NOT_MATCH, String.format("閲戦鏈湪绯荤粺璁剧疆涓細%s",money));
+                }
+            }
+
+            return dyOrderDto;
+    }
+
+    @Override
+    public void removeDistributedClient(String id) {
+        keyOrderMapper.removeDistributedClient(id);
+    }
 }

--
Gitblit v1.8.0