he2802 1 năm trước cách đây
mục cha
commit
3e58f2baba

+ 3 - 0
zhongzheng-api/src/main/java/com/zhongzheng/ZhongZhengApiApplication.java

@@ -2,11 +2,14 @@ package com.zhongzheng;
 
 
 import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure;
+import com.zhongzheng.common.utils.DateUtils;
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.scheduling.annotation.EnableScheduling;
 
+import java.util.Date;
+
 
 @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class })
 @EnableScheduling

+ 39 - 0
zhongzheng-common/src/main/java/com/zhongzheng/common/utils/DateUtils.java

@@ -3,8 +3,10 @@ package com.zhongzheng.common.utils;
 import cn.hutool.core.lang.Validator;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.apache.commons.lang3.time.DateFormatUtils;
+import org.apache.http.util.Args;
 
 import java.lang.management.ManagementFactory;
+import java.lang.ref.SoftReference;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.time.*;
@@ -35,6 +37,43 @@ public class DateUtils extends org.apache.commons.lang3.time.DateUtils
             "yyyy/MM/dd", "yyyy/MM/dd HH:mm:ss", "yyyy/MM/dd HH:mm", "yyyy/MM",
             "yyyy.MM.dd", "yyyy.MM.dd HH:mm:ss", "yyyy.MM.dd HH:mm", "yyyy.MM"};
 
+    static final class DateFormatHolder {
+        private static final ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>> THREADLOCAL_FORMATS = new ThreadLocal<SoftReference<Map<String, SimpleDateFormat>>>();
+
+        DateFormatHolder() {
+        }
+
+        public static SimpleDateFormat formatFor(String pattern) {
+            SoftReference<Map<String, SimpleDateFormat>> ref = THREADLOCAL_FORMATS.get();
+            Map<String, SimpleDateFormat> formats = ref == null ? null : ref.get();
+            if (formats == null) {
+                formats = new HashMap<String, SimpleDateFormat>();
+                THREADLOCAL_FORMATS.set(new SoftReference(formats));
+            }
+
+            SimpleDateFormat format = formats.get(pattern);
+
+            if (format == null) {
+                format = new SimpleDateFormat(pattern);
+                format.setTimeZone(TimeZone.getTimeZone("GMT+8"));
+                ((Map) formats).put(pattern, format);
+            }
+
+            return format;
+        }
+
+        public static void clearThreadLocal() {
+            THREADLOCAL_FORMATS.remove();
+        }
+    }
+
+    public static String formatDateV3(Date date, String pattern) {
+        Args.notNull(date, "Date");
+        Args.notNull(pattern, "Pattern");
+        SimpleDateFormat formatFor = DateFormatHolder.formatFor(pattern);
+        return formatFor.format(date);
+    }
+
     /**
      * 获取当前Date型日期
      *

+ 1 - 0
zhongzheng-system/src/main/java/com/zhongzheng/modules/order/service/impl/OrderHandleServiceImpl.java

@@ -188,6 +188,7 @@ public class OrderHandleServiceImpl extends ServiceImpl<OrderHandleMapper, Order
                 payAddBo.setOrderFrom(2);
                 iOrderPayService.insertByAddBo(payAddBo);
                 String body = "中正云-订单:"+orderHandle.getHandleOrderSn();
+                System.out.println(orderHandle.getPayPrice());
                 payResult = iWxPayService.paymentPc(pay_no, userVo.getOpenId(), body, orderHandle.getPayPrice());
                 payResult.put("orderSn", orderHandle.getHandleOrderSn());
                 return payResult;

+ 47 - 15
zhongzheng-system/src/main/java/com/zhongzheng/modules/wx/service/impl/WxPayServiceImpl.java

@@ -6,8 +6,10 @@ import cn.hutool.core.lang.Validator;
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.google.zxing.BarcodeFormat;
 import com.google.zxing.client.j2se.MatrixToImageWriter;
 import com.google.zxing.common.BitMatrix;
@@ -37,6 +39,7 @@ import com.zhongzheng.modules.course.service.ICourseProjectTypeService;
 import com.zhongzheng.modules.course.service.ICourseService;
 import com.zhongzheng.modules.distribution.domain.*;
 import com.zhongzheng.modules.distribution.service.*;
+import com.zhongzheng.modules.exam.domain.ExamApplyUser;
 import com.zhongzheng.modules.goods.domain.Goods;
 import com.zhongzheng.modules.goods.domain.GoodsQuestionRel;
 import com.zhongzheng.modules.goods.domain.QuestionMerchant;
@@ -52,11 +55,9 @@ import com.zhongzheng.modules.grade.service.IStudyCountLogService;
 import com.zhongzheng.modules.order.bo.OrderShareMoneyAddBo;
 import com.zhongzheng.modules.order.domain.Order;
 import com.zhongzheng.modules.order.domain.OrderGoods;
+import com.zhongzheng.modules.order.domain.OrderHandle;
 import com.zhongzheng.modules.order.domain.OrderPay;
-import com.zhongzheng.modules.order.service.IOrderGoodsService;
-import com.zhongzheng.modules.order.service.IOrderPayService;
-import com.zhongzheng.modules.order.service.IOrderService;
-import com.zhongzheng.modules.order.service.IOrderShareMoneyService;
+import com.zhongzheng.modules.order.service.*;
 import com.zhongzheng.modules.order.vo.OrderShareGoodsVo;
 import com.zhongzheng.modules.order.vo.OrderShareToOldVo;
 import com.zhongzheng.modules.system.domain.SysTenant;
@@ -89,6 +90,7 @@ import org.springframework.transaction.annotation.Transactional;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.math.BigDecimal;
+import java.text.SimpleDateFormat;
 import java.util.*;
 import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
@@ -131,6 +133,9 @@ public class WxPayServiceImpl implements IWxPayService {
     @Autowired
     private RedisCache redisCache;
 
+    @Autowired
+    private IOrderHandleService iOrderHandleService;
+
     @Autowired
     private IUserExamGoodsService userExamGoodsService;
 
@@ -312,17 +317,14 @@ public class WxPayServiceImpl implements IWxPayService {
             data.put("out_trade_no", out_trade_no);
             data.put("device_info", "");
             data.put("fee_type", "CNY");
-            data.put("total_fee", price.intValue() + "");
+            data.put("total_fee", price.longValue() + "");
        //     data.put("openid", openid);
             data.put("spbill_create_ip", IpUtils.getIpAddr(ServletUtils.getRequest()));
             data.put("notify_url", notifyUrl);
             data.put("trade_type", "NATIVE");
-            Calendar calendar = Calendar .getInstance();
-            calendar.setTime(new Date());
-            calendar.add(calendar.MINUTE, 10);
-            Date date = calendar.getTime();
-            String time_expire = DateUtil.format(date,"yyyy-MM-dd'T' HH:mm:ssXXX");
-            data.put("time_expire", time_expire);
+            Date date = new Date();
+            Date newDate = new Date(date.getTime() + 60000*30);
+    //        data.put("time_expire", DateUtils.formatDateV3(newDate ,"yyyy-MM-dd'T'HH:mm:ssXXX"));
             String TenantId = ServletUtils.getRequest().getHeader("TenantId");
             data.put("attach", TenantId);
             Map<String, String> resp = wxpay.unifiedOrder(data);
@@ -342,7 +344,7 @@ public class WxPayServiceImpl implements IWxPayService {
             String urlBase64 = "data:image/jpeg;base64,"
                     + encoder1.encodeToString(outputStream.toByteArray());
             result.put("urlBase64", urlBase64);
-            Integer overTime = (int)calendar.getTimeInMillis()/1000;
+            Long overTime = (long)(newDate.getTime()/1000);
             result.put("overTime", overTime.toString());
             return result;
         } catch (Exception e) {
@@ -440,9 +442,16 @@ public class WxPayServiceImpl implements IWxPayService {
                         orderPay.setStatus(1);
                         orderPay.setUpdateTime(DateUtils.getNowTime());
                         iOrderPayService.updateById(orderPay);
-                        if (dealOrder(orderSn, transaction_id)) {
-                            xmlBack = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
-                            return xmlBack;
+                        if(orderPay.getOrderFrom()==2){
+                            if (dealHandleOrder(orderSn, transaction_id)) {
+                                xmlBack = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
+                                return xmlBack;
+                            }
+                        }else{
+                            if (dealOrder(orderSn, transaction_id)) {
+                                xmlBack = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>";
+                                return xmlBack;
+                            }
                         }
                     }
                 }
@@ -494,6 +503,29 @@ public class WxPayServiceImpl implements IWxPayService {
         return access_token;
     }
 
+    @Transactional(rollbackFor = Exception.class)
+    public boolean dealHandleOrder(String out_trade_no, String transaction_id) {
+        String key = out_trade_no;
+        String ticket = redisCache.getCacheObject(key);
+        if (Validator.isNotEmpty(ticket)) {
+            return false;
+        }
+        redisCache.setCacheObject(key, "dealing", 30, TimeUnit.SECONDS);//30秒
+        OrderHandle orderHandle = iOrderHandleService.queryBySn(out_trade_no);
+        if (orderHandle != null && orderHandle.getPayStauts() == 0) {
+            orderHandle.setPayTime(DateUtils.getNowTime());
+            orderHandle.setPayStauts(1);
+            orderHandle.setUpdateTime(DateUtils.getNowTime());
+            if (iOrderHandleService.updateById(orderHandle)) {
+                List<Order> list = iOrderService.list(new LambdaQueryWrapper<Order>().eq(Order::getHandleOrderSn, out_trade_no));
+                for(Order order : list){
+                    dealOrder(order.getOrderSn(),transaction_id);
+                }
+            }
+        }
+        return true;
+    }
+
     @Transactional(rollbackFor = Exception.class)
     public boolean dealOrder(String out_trade_no, String transaction_id) {
         String key = out_trade_no;