From eb6b6dbb35a9f029e0b7d269773685c19fd40976 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期四, 11 七月 2024 10:47:51 +0800
Subject: [PATCH] 玩湃微信商户认证代码

---
 cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java |  414 +++++++++++++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 344 insertions(+), 70 deletions(-)

diff --git a/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java b/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
index e5a6145..7409473 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
+++ b/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java
@@ -1,7 +1,6 @@
 package com.dsh.account.service.impl;
 
 
-import com.alibaba.fastjson.JSONObject;
 import com.alipay.api.AlipayApiException;
 import com.alipay.api.AlipayClient;
 import com.alipay.api.DefaultAlipayClient;
@@ -19,15 +18,10 @@
 import com.dsh.account.dto.*;
 import com.dsh.account.entity.*;
 import com.dsh.account.enums.RechargeRecordEnum;
-import com.dsh.account.feignclient.activity.IntroduceRewardsClient;
-import com.dsh.account.feignclient.activity.MerChandiseClient;
-import com.dsh.account.feignclient.activity.MerChandiseStoreClient;
-import com.dsh.account.feignclient.activity.UserConponClient;
+import com.dsh.account.feignclient.activity.*;
 import com.dsh.account.feignclient.activity.model.*;
 import com.dsh.account.feignclient.competition.DeductionCompetitionsClient;
 import com.dsh.account.feignclient.competition.model.BillingDataRequestVo;
-import com.dsh.account.feignclient.competition.model.PaymentCompetition;
-import com.dsh.account.feignclient.competition.model.PurchaseRecordVo;
 import com.dsh.account.feignclient.course.CoursePackageClient;
 import com.dsh.account.feignclient.course.CoursePackageConfigClient;
 import com.dsh.account.feignclient.course.CoursePaymentClient;
@@ -37,7 +31,6 @@
 import com.dsh.account.feignclient.other.RechargeConfigClient;
 import com.dsh.account.feignclient.other.SiteClient;
 import com.dsh.account.feignclient.other.StoreClient;
-import com.dsh.account.feignclient.other.model.SiteBooking;
 import com.dsh.account.feignclient.other.model.Store;
 import com.dsh.account.feignclient.other.model.StoreDetailOfCourse;
 import com.dsh.account.feignclient.other.model.TImgConfig;
@@ -46,7 +39,6 @@
 import com.dsh.account.model.AppUserByNameAndPhoneDTO;
 import com.dsh.account.model.dto.Coupon;
 import com.dsh.account.model.query.appUserQuery.QueryAppUser;
-import com.dsh.account.model.vo.DetailsListVo;
 import com.dsh.account.model.vo.QueryAppUserVO;
 import com.dsh.account.model.vo.classDetails.CourseVenue;
 import com.dsh.account.model.vo.classDetails.ExerciseVideo;
@@ -156,9 +148,6 @@
     private CoursePackageConfigClient cpconClient;
 
     @Resource
-    private PayMoneyUtil payMoneyUtil;
-
-    @Resource
     private SiteClient stClient;
     @Autowired
     private TAppUserMapper appUserMapper;
@@ -182,6 +171,16 @@
     private TAppUserService appUserService;
     @Resource
     private MerChandiseClient merChandiseClient;
+
+    @Autowired
+    private PayMoneyUtil payMoneyUtil;
+
+    @Resource
+    private UserCouponPaymentClient userCouponPaymentClient;
+
+
+
+
 
     // 对数据进行分页处理的方法
     private static Page<Goods> getPage(List<Goods> dataList, Pageable pageable) {
@@ -304,6 +303,7 @@
                 ;
             }
         }
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
         if (tStudents.size() > 0) {
             TStudent tStudent = tStudents.get(0);
             classInfoVo.setStuId(tStudent.getId());
@@ -329,7 +329,7 @@
                     course.setTotalNums(ToolUtil.isEmpty(tCoursePackagePayment.getTotalCourseNums()) ? 0 : tCoursePackagePayment.getTotalCourseNums());
                     course.setDeductedNums(ToolUtil.isEmpty(tCoursePackagePayment.getDeductionNums()) ? 0 : tCoursePackagePayment.getDeductionNums());
                     course.setRemainingNums(ToolUtil.isEmpty(tCoursePackagePayment.getResidueNums()) ? 0 : tCoursePackagePayment.getResidueNums());
-                    course.setPeriodOfValidity(tCoursePackagePayment.getPeriodOfValidity());
+                    course.setPeriodOfValidity(sdf.format(tStudent.getValidity()));
                     course.setIsAble(tCoursePackagePayment.getIsAble());
                     course.setCourseType(tCoursePackagePayment.getCourseType());
                     courseList.add(course);
@@ -447,6 +447,10 @@
         tAppUser.setIsVip(0);
         tAppUser.setState(1);
         tAppUser.setInsertTime(new Date());
+        tAppUser.setProvince("");
+        tAppUser.setProvinceCode("");
+        tAppUser.setCity("");
+        tAppUser.setCityCode("");
         // 注册用户
         int insert = this.baseMapper.insert(tAppUser);
         // 介绍有礼
@@ -546,6 +550,7 @@
             tAppUser.setPassword(Md5Util.MD5Encode("111111", null));
             tAppUser.setIsVip(0);
             tAppUser.setState(1);
+            tAppUser.setInsertTime(new Date());
             this.baseMapper.insert(tAppUser);
         }
         if (tAppUser.getState() == 2) {
@@ -579,6 +584,10 @@
                 tAppUser.setGender(loginWechatVo.getSex());
                 tAppUser.setState(1);
                 tAppUser.setInsertTime(new Date());
+                tAppUser.setProvince("");
+                tAppUser.setProvinceCode("");
+                tAppUser.setCity("");
+                tAppUser.setCityCode("");
                 this.baseMapper.insert(tAppUser);
             }
         }
@@ -632,6 +641,27 @@
      */
     @Override
     public ResultUtil updatePassword(String phone, String code, String password) throws Exception {
+        String value = redisUtil.getValue(phone);
+        if (!"123456".equals(code) && (ToolUtil.isEmpty(value) || !value.equals(code))) {
+            return ResultUtil.error("验证码无效");
+        }
+        TAppUser tAppUser = this.baseMapper.selectOne(new QueryWrapper<TAppUser>().eq("phone", phone).ne("state", 3));
+        if (tAppUser == null) {
+            return ResultUtil.error("该账号未注册", "");
+        }
+        if (tAppUser.getState() == 2) {
+            return ResultUtil.error("您的账号已被冻结", "");
+        }
+        if (tAppUser.getCode() == null) {
+            tAppUser.setCode(UUIDUtil.getNumberRandom(16));
+        }
+        tAppUser.setPassword(password);
+        this.updateById(tAppUser);
+        return ResultUtil.success();
+    }
+
+    @Override
+    public ResultUtil updatePassword1(String phone, String code, String password) throws Exception {
         String value = redisUtil.getValue(phone);
         if (!"123456".equals(code) && (ToolUtil.isEmpty(value) || !value.equals(code))) {
             return ResultUtil.error("验证码无效");
@@ -1025,6 +1055,7 @@
                 goods.add(commodity);
             }
         }
+
         List<Coupon> allCoupons = ucponClient.getAllCoupons(commodityRequest);
         if (allCoupons.size() > 0) {
             for (Coupon allCoupon : allCoupons) {
@@ -1281,9 +1312,6 @@
     @Override
     @Transactional
     public synchronized ResultUtil productRedemptionOperation(Integer userIdFormRedis, GoodsExchangeVo exchangeType) {
-        System.out.println("exchangeType:--->");
-
-
         ReturnModel returnModel = new ReturnModel();
         Long returnId = null;
         //如果是兑换优惠卷
@@ -1295,7 +1323,7 @@
             queryIds.add(coupon.getId());
             queryIds.add(userIdFormRedis);
             Integer counts = userConponClient.queryCounts(queryIds);
-            if (coupon.getQuantityIssued() - counts == 0) {
+            if (coupon.getQuantityIssued().compareTo(counts) == 0) {
                 return new ResultUtil(0, "当前数量不足");
             }
             //查询该用户是否超出限领数量
@@ -1304,40 +1332,56 @@
             if (usercounts == coupon.getPickUpQuantity()) {
                 return new ResultUtil<>(0, "限领数量已达最大");
             }
-//            userConponClient.queryCouponById(exchangeType.getGoodId());
-            UserCoupon userCoupon = new UserCoupon();
-            userCoupon.setCouponId(exchangeType.getGoodId());
-            userCoupon.setUserId(userIdFormRedis);
-            userCoupon.setStatus(1);
-            userCoupon.setInsertTime(new Date());
-            userConponClient.insertToAppuserCoupon(userCoupon);
-            //扣积分
-            TAppUser user = appUserService.getById(userIdFormRedis);
-            if (user.getIntegral() < coupon.getIntegral().intValue()) {
-                return new ResultUtil<>(0, "当前用户积分不足");
+
+            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+            String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
+            //生成支付订单
+            UserCouponPayment userCouponPayment = new UserCouponPayment();
+            userCouponPayment.setCouponId(exchangeType.getGoodId());
+            userCouponPayment.setUserId(userIdFormRedis);
+            userCouponPayment.setStatus(1);
+            userCouponPayment.setCode(code);
+            userCouponPayment.setPayType(coupon.getRedemptionMethod());
+            userCouponPayment.setIntegral(coupon.getIntegral().intValue());
+            userCouponPayment.setCash(null == coupon.getCash() ? 0D : coupon.getCash().doubleValue());
+            userCouponPayment.setCashPayType(exchangeType.getPayType());
+            userCouponPayment.setInsertTime(new Date());
+
+            //积分兑换
+            if(coupon.getRedemptionMethod() == 1){
+                UserCoupon userCoupon = new UserCoupon();
+                userCoupon.setCouponId(exchangeType.getGoodId());
+                userCoupon.setUserId(userIdFormRedis);
+                userCoupon.setStatus(1);
+                userCoupon.setInsertTime(new Date());
+                userConponClient.insertToAppuserCoupon(userCoupon);
+                //扣积分
+                TAppUser user = appUserService.getById(userIdFormRedis);
+                if (user.getIntegral() < coupon.getIntegral().intValue()) {
+                    return new ResultUtil<>(0, "当前用户积分不足");
+                }
+                user.setIntegral(user.getIntegral() - coupon.getIntegral().intValue());
+                appUserService.updateById(user);
+
+                userCouponPayment.setStatus(2);
+                userCouponPayment.setPaymentTime(new Date());
+                userCouponPaymentClient.addUserCouponPayment(userCouponPayment);
+                return ResultUtil.success(returnId);
             }
-            user.setIntegral(user.getIntegral() - coupon.getIntegral().intValue());
-            appUserService.updateById(user);
-
-            //记录
-//            UserPointsMerchandise pointsMerchandise = new UserPointsMerchandise();
-//            pointsMerchandise.setPointsMerchandiseId(exchangeType.getGoodId());
-//            pointsMerchandise.setUserId(userIdFormRedis);
-//            pointsMerchandise.setStatus(1);
-//            pointsMerchandise.setState(1);
-//            pointsMerchandise.setPayStatus(1);
-////            if (merchandise.getUseScope() == 3){
-////                if (exchangeType.getGoodsType() == 2){
-////                    CoursePackage coursePackage = cpageClient.queryCoursePackageById(merchandise.getCoursePackageId());
-////                    pointsMerchandise.setStoreId(coursePackage.getStoreId());
-////                }else {
-////                    pointsMerchandise.setStoreId(exchangeType.getStoreId());
-////                }
-////            }
-////            pointsMerchandise.setCode(code);
-//            returnId = mcClient.saveDetailsUserPointMercase(pointsMerchandise);
-
-            return ResultUtil.success(returnId);
+            //积分+现金
+            if(coupon.getRedemptionMethod() == 2){
+                userCouponPaymentClient.addUserCouponPayment(userCouponPayment);
+                try {
+                    if(exchangeType.getPayType() == 1){
+                        return weChatPaymentCoupon("购买优惠券", userCouponPayment);
+                    }
+                    if(exchangeType.getPayType() == 2){
+                        return aliPaymentCoupon("购买优惠券", userCouponPayment);
+                    }
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
         }
 
 
@@ -1345,7 +1389,20 @@
         try {
             SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
             String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
-            PointsMerchandise merchandise = mcClient.selectPointsMerchandiseById(exchangeType.getGoodId());
+            PointsMerchandise merchandise = new PointsMerchandise();
+            if(exchangeType.getGoodsType() != 4){
+                merchandise = mcClient.selectPointsMerchandiseById(exchangeType.getGoodId());
+            }else{
+                Coupon coupon = ucponClient.queryCouponById(exchangeType.getGoodId());
+                merchandise.setId(coupon.getId());
+                merchandise.setUserPopulation(coupon.getUserPopulation());
+                merchandise.setIntegral(coupon.getIntegral().intValue());
+                merchandise.setQuantityIssued(coupon.getQuantityIssued());
+                merchandise.setPickUpQuantity(coupon.getPickUpQuantity());
+                merchandise.setUseScope(coupon.getUseScope());
+                merchandise.setCash(coupon.getCash());
+                merchandise.setType(4);
+            }
 
 
             if (ToolUtil.isEmpty(merchandise)) {
@@ -1424,6 +1481,7 @@
                     }
                 }
                 pointsMerchandise.setCode(code);
+                pointsMerchandise.setInsertTime(new Date());
                 returnId = mcClient.saveDetailsUserPointMercase(pointsMerchandise);
             }
 
@@ -1466,6 +1524,7 @@
                                     packagePayment.setStatus(1);
                                     packagePayment.setState(1);
                                     packagePayment.setCode(code);
+                                    packagePayment.setInsertTime(new Date());
 //                                    paymentClient.savePaymentCoursePackage(packagePayment);
 
                                     OrderDto orderDto = new OrderDto();
@@ -1485,6 +1544,7 @@
                                     coupon.setCouponId(exchangeType.getGoodId());
                                     coupon.setUserId(userIdFormRedis);
                                     coupon.setStatus(1);
+                                    coupon.setInsertTime(new Date());
                                     ucponClient.insertToAppuserCoupon(coupon);
                                 }
                                 break;
@@ -1558,6 +1618,209 @@
 
     }
 
+
+    /**
+     * 优惠券微信支付
+     * @param body
+     * @param userCouponPayment
+     * @return
+     * @throws Exception
+     */
+    public ResultUtil weChatPaymentCoupon(String body, UserCouponPayment userCouponPayment) throws Exception {
+        String code = userCouponPayment.getCode();
+        Double cash = userCouponPayment.getCash();
+        ResultUtil weixinpay = payMoneyUtil.weixinpay(body, "", code, cash.toString(), "/base/coupon/weChatPaymentCouponCallback", "APP", "");
+        if (weixinpay.getCode() == 200) {
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        int num = 1;
+                        int wait = 0;
+                        while (num <= 10) {
+                            int min = 5000;
+                            wait += (min * num);
+                            Thread.sleep(wait);
+                            UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code);
+                            if (userCouponPayment1.getStatus() == 2) {
+                                break;
+                            }
+                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, "");
+                            if (resultUtil.getCode() == 200 && userCouponPayment1.getStatus() == 1) {
+                                /**
+                                 * SUCCESS—支付成功,
+                                 * REFUND—转入退款,
+                                 * NOTPAY—未支付,
+                                 * CLOSED—已关闭,
+                                 * REVOKED—已撤销(刷卡支付),
+                                 * USERPAYING--用户支付中,
+                                 * PAYERROR--支付失败(其他原因,如银行返回失败)
+                                 */
+                                Map<String, String> data1 = resultUtil.getData();
+                                String s = data1.get("trade_state");
+                                String transaction_id = data1.get("transaction_id");
+                                if ("REFUND".equals(s) || "NOTPAY".equals(s) || "CLOSED".equals(s) || "REVOKED".equals(s) || "PAYERROR".equals(s) || num == 10) {
+                                    //有待支付的订单,这里不处理
+                                    userCouponPayment1.setStatus(-1);
+                                    userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1);
+                                    break;
+                                }
+                                if ("SUCCESS".equals(s)) {
+                                    userCouponPayment1.setStatus(2);
+                                    userCouponPayment1.setPaymentTime(new Date());
+                                    userCouponPayment1.setOrderNumber(transaction_id);
+                                    userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1);
+
+                                    UserCoupon userCoupon = new UserCoupon();
+                                    userCoupon.setCouponId(userCouponPayment1.getCouponId());
+                                    userCoupon.setUserId(userCouponPayment1.getUserId());
+                                    userCoupon.setStatus(1);
+                                    userCoupon.setInsertTime(new Date());
+                                    userConponClient.insertToAppuserCoupon(userCoupon);
+
+                                    if(null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()){
+                                        //扣积分
+                                        TAppUser user = appUserService.getById(userCouponPayment1.getUserId());
+                                        user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue());
+                                        appUserService.updateById(user);
+                                    }
+                                    break;
+                                }
+                                if ("USERPAYING".equals(s)) {
+                                    num++;
+                                }
+                            }
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+        }
+        return weixinpay;
+    }
+
+
+    /**
+     * 优惠券支付宝支付
+     *
+     * @return
+     * @throws Exception
+     */
+    private String smid = "2088330203191220";//平台支付宝商户号
+    public ResultUtil aliPaymentCoupon(String body, UserCouponPayment userCouponPayment) throws Exception {
+        String code = userCouponPayment.getCode();
+        Double cash = userCouponPayment.getCash();
+
+        ResultUtil alipay = payMoneyUtil.alipay(smid, body, "",String.valueOf(userCouponPayment.getId()), code, cash.toString(), "/base/coupon/aliPaymentCouponCallback");
+        if (alipay.getCode() == 200) {
+            new Thread(new Runnable() {
+                @Override
+                public void run() {
+                    try {
+                        Thread.sleep(1000);
+
+                        int num = 1;
+                        int wait = 0;
+                        while (num <= 10) {
+                            int min = 5000;
+                            wait += (min * num);
+                            Thread.sleep(wait);
+                            UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code);
+                            if (userCouponPayment1.getStatus() == 2) {
+                                break;
+                            }
+                            AlipayTradeQueryResponse alipayTradeQueryResponse = payMoneyUtil.queryALIOrder(code);
+                            if (null != alipayTradeQueryResponse) {
+                                /**
+                                 * WAIT_BUYER_PAY(交易创建,等待买家付款)、
+                                 * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、
+                                 * TRADE_SUCCESS(交易支付成功)、
+                                 * TRADE_FINISHED(交易结束,不可退款)
+                                 */
+                                String s = alipayTradeQueryResponse.getTradeStatus();
+
+                                String tradeNo = alipayTradeQueryResponse.getTradeNo();
+                                if ("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10) {
+                                    //有待支付的订单,这里不处理
+                                    userCouponPayment1.setStatus(-1);
+                                    userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1);
+                                    if ("TRADE_FINISHED".equals(s)) {
+                                        // todo 资金结算
+
+                                    }
+                                    break;
+                                }
+                                if ("TRADE_SUCCESS".equals(s)) {
+                                    userCouponPayment1.setStatus(2);
+                                    userCouponPayment1.setPaymentTime(new Date());
+                                    userCouponPayment1.setOrderNumber(tradeNo);
+                                    userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1);
+                                    UserCoupon userCoupon = new UserCoupon();
+                                    userCoupon.setCouponId(userCouponPayment1.getCouponId());
+                                    userCoupon.setUserId(userCouponPayment1.getUserId());
+                                    userCoupon.setStatus(1);
+                                    userCoupon.setInsertTime(new Date());
+                                    userConponClient.insertToAppuserCoupon(userCoupon);
+                                    if(null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()){
+                                        //扣积分
+                                        TAppUser user = appUserService.getById(userCouponPayment1.getUserId());
+                                        user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue());
+                                        appUserService.updateById(user);
+                                    }
+
+                                    payMoneyUtil.confirm(smid,code,tradeNo,cash.toString());
+                                    break;
+
+                                }
+
+                                if ("WAIT_BUYER_PAY".equals(s)) {
+                                    num++;
+                                }
+                            }
+                        }
+                    } catch (Exception e) {
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+        }
+        return alipay;
+    }
+
+    /**
+     * 支付回调
+     * @param code
+     * @param orderNumber
+     * @return
+     */
+    @Override
+    public ResultUtil paymentCouponCallback(String code, String orderNumber) {
+        UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code);
+        if (userCouponPayment1.getStatus() == 2) {
+            return ResultUtil.success();
+        }
+        userCouponPayment1.setStatus(2);
+        userCouponPayment1.setPaymentTime(new Date());
+        userCouponPayment1.setOrderNumber(orderNumber);
+        userCouponPaymentClient.updateUserCouponPayment(userCouponPayment1);
+
+        UserCoupon userCoupon = new UserCoupon();
+        userCoupon.setCouponId(userCouponPayment1.getCouponId());
+        userCoupon.setUserId(userCouponPayment1.getUserId());
+        userCoupon.setStatus(1);
+        userCoupon.setInsertTime(new Date());
+        userConponClient.insertToAppuserCoupon(userCoupon);
+
+        if(null != userCouponPayment1.getIntegral() && 0 != userCouponPayment1.getIntegral()){
+            //扣积分
+            TAppUser user = appUserService.getById(userCouponPayment1.getUserId());
+            user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue());
+            appUserService.updateById(user);
+        }
+        return ResultUtil.success();
+    }
+
     public boolean dealAppUserIntegral(Integer appUserId, TAppUser appUser, Integer points) {
         try {
             if (ToolUtil.isEmpty(appUser.getIntegral()) || (ToolUtil.isNotEmpty(appUser.getIntegral()) && appUser.getIntegral() < points)) {
@@ -1582,8 +1845,7 @@
     }
 
     private ResultUtil AlipayPayment(BigDecimal cash, String code, Long returnId) {
-        System.out.println("金额:" + cash);
-        ResultUtil alipay = payMoneyUtil.alipay("优惠卷", "优惠卷", String.valueOf(returnId), code, cash.toString(),
+        ResultUtil alipay = payMoneyUtil.alipay(smid,"优惠卷", "优惠卷", String.valueOf(returnId), code, cash.toString(),
                 "/base/pointMer/exchangeGoodPaymentAliCallback");
         if (alipay.getCode() == 200) {
             new Thread(new Runnable() {
@@ -1627,8 +1889,15 @@
                                         userPointsMerchandise.setInsertTime(null);
                                         userPointsMerchandise.setUserId(null);
                                         mcClient.updateDetailsUserPointMercase(userPointsMerchandise);
+                                        // todo 资金结算
+                                        payMoneyUtil.confirm(smid,code,tradeNo,cash.toString());
                                     }
                                     moneyOut(tradeNo, tradeNo);
+                                    break;
+                                }
+                                if ("TRADE_FINISHED".equals(tradeStatus)) {
+                                    // todo 资金结算
+                                    payMoneyUtil.confirm(smid,code,tradeNo,cash.toString());
                                     break;
                                 }
 //                                if("REFUND".equals(tradeStatus) || "NOTPAY".equals(tradeStatus) || "CLOSED".equals(tradeStatus) || "REVOKED".equals(tradeStatus) || "PAYERROR".equals(tradeStatus) || num == 10){
@@ -1697,7 +1966,8 @@
 
         List<UserPointsMerchandise> userPointsMerchandises = merChandiseClient.queryUserPointMerchaseByCode(outNum);
 //        PaymentCompetition code = paymentCompetitionService.getOne(new QueryWrapper<PaymentCompetition>().eq("code", outNum));
-        Integer storeId = userPointsMerchandises.get(0).getStoreId();
+        if(userPointsMerchandises.size() > 0){
+            Integer storeId = userPointsMerchandises.get(0).getStoreId();
 
 //        Competition byId1 = competitionService.getById(code.getCompetitionId());
 
@@ -1705,7 +1975,7 @@
 //        TCoursePackage byId = coursePackageService.getById(one.getCoursePackageId());
 
 
-        OperatorUser operatorUser = storeClient.queryByStoreId(storeId);
+            OperatorUser operatorUser = storeClient.queryByStoreId(storeId);
 
 
 //        Integer paymentCompetitions = competitionsClient.queryByCode(outTradeNo);
@@ -1717,26 +1987,28 @@
 //        OperatorUser operatorUser = siteClient.queryOperator(stores);
 
 
-        OpenApiRoyaltyDetailInfoPojo op = new OpenApiRoyaltyDetailInfoPojo();
-        op.setTransOutType("loginName");
-        op.setTransOut("happysports@weparklife.com");
-        op.setTransInType("userId");
-        op.setTransIn(operatorUser.getAlipayNum());
-        op.setAmountPercentage(Long.valueOf(operatorUser.getAlipayProportion()));
+            OpenApiRoyaltyDetailInfoPojo op = new OpenApiRoyaltyDetailInfoPojo();
+            op.setTransOutType("loginName");
+            op.setTransOut("happysports@weparklife.com");
+            op.setTransInType("userId");
+            op.setTransIn(operatorUser.getAlipayNum());
+            op.setAmountPercentage(Long.valueOf(operatorUser.getAlipayProportion()));
 
-        List<OpenApiRoyaltyDetailInfoPojo> ops = new ArrayList<>();
-        ops.add(op);
-        model.setRoyaltyParameters(ops);
+            List<OpenApiRoyaltyDetailInfoPojo> ops = new ArrayList<>();
+            ops.add(op);
+            model.setRoyaltyParameters(ops);
 
-        request.setBizModel(model);
+            request.setBizModel(model);
 
 
-        AlipayTradeOrderSettleResponse response1 = alipayClient.execute(request);
-        if (response1.isSuccess()) {
-            System.out.println("调用成功");
-        } else {
-            System.out.println("调用失败");
+            AlipayTradeOrderSettleResponse response1 = alipayClient.execute(request);
+            if (response1.isSuccess()) {
+                System.out.println("调用成功");
+            } else {
+                System.out.println("调用失败");
+            }
         }
+
     }
 
 
@@ -1830,6 +2102,7 @@
                         coupon.setCouponId(userPointsMerchandises.get(0).getPointsMerchandiseId());
                         coupon.setUserId(userPointsMerchandises.get(0).getUserId());
                         coupon.setStatus(1);
+                        coupon.setInsertTime(new Date());
                         ucponClient.insertToAppuserCoupon(coupon);
                         break;
                     default:
@@ -1860,6 +2133,7 @@
                     coupon.setCouponId(userPointsMerchandises.get(0).getPointsMerchandiseId());
                     coupon.setUserId(userPointsMerchandises.get(0).getUserId());
                     coupon.setStatus(1);
+                    coupon.setInsertTime(new Date());
                     ucponClient.insertToAppuserCoupon(coupon);
                     break;
                 default:

--
Gitblit v1.7.1