From 134d13688e4b6677133ba2d362d2978d8bda2b87 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 12 七月 2023 11:46:30 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 cloud-server-account/src/main/java/com/dsh/account/service/impl/RechargeRecordsServiceImpl.java |  206 +++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 191 insertions(+), 15 deletions(-)

diff --git a/cloud-server-account/src/main/java/com/dsh/account/service/impl/RechargeRecordsServiceImpl.java b/cloud-server-account/src/main/java/com/dsh/account/service/impl/RechargeRecordsServiceImpl.java
index 511f7f2..0c946de 100644
--- a/cloud-server-account/src/main/java/com/dsh/account/service/impl/RechargeRecordsServiceImpl.java
+++ b/cloud-server-account/src/main/java/com/dsh/account/service/impl/RechargeRecordsServiceImpl.java
@@ -5,15 +5,20 @@
 import com.dsh.account.entity.RechargeRecords;
 import com.dsh.account.entity.TAppUser;
 import com.dsh.account.enums.RechargeRecordEnum;
+import com.dsh.account.feignclient.competition.DeductionCompetitionsClient;
+import com.dsh.account.feignclient.competition.model.PaymentCompetition;
 import com.dsh.account.feignclient.course.CoursePaymentClient;
 import com.dsh.account.feignclient.course.model.TCoursePackagePayment;
+import com.dsh.account.feignclient.other.RechargeConfigClient;
 import com.dsh.account.mapper.RechargeRecordsMapper;
 import com.dsh.account.mapper.TAppUserMapper;
 import com.dsh.account.model.vo.userBenefitDetail.RechargeDetailsVo;
 import com.dsh.account.model.vo.userBenefitDetail.RechargePayRequest;
 import com.dsh.account.service.RechargeRecordsService;
 import com.dsh.account.util.DateTimeHelper;
+import com.dsh.account.util.PayMoneyUtil;
 import com.dsh.account.util.ResultUtil;
+import com.dsh.account.util.UUIDUtil;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.util.StringUtils;
@@ -24,6 +29,7 @@
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 /**
  * <p>
@@ -45,6 +51,16 @@
 
     @Autowired
     private CoursePaymentClient cpClient;
+
+    @Autowired
+    private DeductionCompetitionsClient deducClient;
+
+    @Autowired
+    private PayMoneyUtil payMoneyUtil;
+
+
+    @Resource
+    private RechargeConfigClient reconMapper;
 
 
     @Override
@@ -70,7 +86,16 @@
             vo.setWpGold(0);
         }
 //            1.赛事报名
-
+        List<PaymentCompetition> playPaiFGoldPayRecord = deducClient.getPlayPaiFGoldPayRecord(appUserId);
+        if (playPaiFGoldPayRecord.size() > 0 ){
+            for (PaymentCompetition competition : playPaiFGoldPayRecord) {
+                RechargeDetailsVo.RechargesDetail consumeDetail = new RechargeDetailsVo.RechargesDetail();
+                consumeDetail.setConsumeName(RechargeRecordEnum.EVENT_REGISTRATION.getMsg() );
+                consumeDetail.setConsumeTime(simpleDateFormat.format(competition.getInsertTime()));
+                consumeDetail.setConsumeAmount("-" + competition.getAmount());
+                details.add(consumeDetail);
+            }
+        }
 //            2.课包购买
         List<TCoursePackagePayment> appuserCourseList = cpClient.getAppuserCourseList(appUserId);
         if (appuserCourseList.size() > 0){
@@ -86,7 +111,7 @@
 //            4.智慧球场
 
 //            5.充值
-        List<RechargeRecords> rechargeRecords = rereMapper.selectList(new QueryWrapper<RechargeRecords>()
+        List<RechargeRecords> rechargeRecords = this.baseMapper.selectList(new QueryWrapper<RechargeRecords>()
                 .eq("payStatus", 2)
                 .eq("appUserId", appUserId)
                 .between("insertTime", monthStart, monthEnd));
@@ -105,27 +130,178 @@
 
     @Override
     public ResultUtil rechargeCenPayment(Integer userIdFormRedis, RechargePayRequest request) {
-        // TODO: 2023/7/10 充值支付
-        switch (request.getPayType()){
-            case 1:
-                WeChatPayment(request.getPayAmount());
-                break;
-            case 2:
-                AlipayPayment(request.getPayAmount());
-                break;
-            default:
-                break;
+        TAppUser tAppUser = tappMapper.selectById(userIdFormRedis);
+        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+        String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);
+        RechargeRecords rechargeRecords = new RechargeRecords();
+        rechargeRecords.setCode(code);
+        rechargeRecords.setAppUserId(userIdFormRedis);
+        rechargeRecords.setAmount(request.getPayAmount());
+        List<Map<String, Object>> rechargeConfig = reconMapper.getRechargeConfig();
+        if (rechargeConfig.size() > 0){
+            for (Map<String, Object> stringObjectMap : rechargeConfig) {
+                Object o = stringObjectMap.get("money");
+                if (o.equals(request.getPayAmount())){
+                    if (tAppUser.getIsVip() == 1){
+                        rechargeRecords.setPlayPaiCoins((Integer) stringObjectMap.get("MemberCoins"));
+                    }else {
+                        rechargeRecords.setPlayPaiCoins((Integer) stringObjectMap.get("usersCoins"));
+                    }
+                }
+            }
+        }
+        rechargeRecords.setPayStatus(1);
+        rechargeRecords.setState(1);
+        rechargeRecords.setInsertTime(new Date());
+        this.baseMapper.insert(rechargeRecords);
+        try {
+            switch (request.getPayType()){
+                case 1:
+                    return WeChatPayment(code,request.getPayAmount());
+                case 2:
+                    return AlipayPayment(code,request.getPayAmount());
+                default:
+                    break;
+            }
+        }catch (Exception e){
+            ResultUtil.runErr();
         }
         return ResultUtil.success();
     }
 
-    private void AlipayPayment(BigDecimal payAmount) {
 
+
+    private ResultUtil AlipayPayment(String code,BigDecimal amount) {
+        ResultUtil alipay = payMoneyUtil.alipay("玩湃币充值", "", "", code, amount.toString(),
+                "/base/recharge/alipayRechargeCallback");
+        if(alipay.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);
+
+                            RechargeRecords records = rereMapper.selectOne(new QueryWrapper<RechargeRecords>()
+                                    .eq("code",code));
+                            if(records.getPayStatus() == 2){
+                                break;
+                            }
+                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryALIOrder(code);
+                            if(resultUtil.getCode() == 200 && records.getPayStatus() == 1){
+                                /**
+                                 * WAIT_BUYER_PAY(交易创建,等待买家付款)、
+                                 * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、
+                                 * TRADE_SUCCESS(交易支付成功)、
+                                 * TRADE_FINISHED(交易结束,不可退款)
+                                 */
+                                Map<String, String> data1 = resultUtil.getData();
+                                String s = data1.get("tradeStatus");
+                                String tradeNo = data1.get("tradeNo");
+                                if("TRADE_CLOSED".equals(s) || "TRADE_FINISHED".equals(s) || num == 10){
+                                    records.setState(3);
+                                    rereMapper.deleteById(records.getId());
+                                    break;
+                                }
+                                if("TRADE_SUCCESS".equals(s)){
+                                    records.setPayStatus(2);
+                                    records.setOrderNumber(tradeNo);
+                                    rereMapper.updateById(records);
+                                    break;
+                                }
+                                if("WAIT_BUYER_PAY".equals(s)){
+                                    num++;
+                                }
+                            }
+                        }
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+        }
+        return alipay;
+    }
+
+    private ResultUtil WeChatPayment(String code,BigDecimal amount) throws Exception {
+        ResultUtil weixinpay = payMoneyUtil.weixinpay("玩湃币充值", "", code, amount.toString(),
+                "/base/recharge/wechatRechargeCallback", "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);
+                            RechargeRecords records = rereMapper.selectOne(new QueryWrapper<RechargeRecords>()
+                                    .eq("code",code));
+                            if(records.getPayStatus() == 2){
+                                break;
+                            }
+                            ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, "");
+                            if(resultUtil.getCode() == 200 && records.getPayStatus() == 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){
+                                    records.setState(3);
+                                    rereMapper.deleteById(records.getId());
+                                    break;
+                                }
+                                if("SUCCESS".equals(s)){
+                                    records.setPayStatus(2);
+                                    records.setOrderNumber(transaction_id);
+                                    rereMapper.updateById(records);
+                                    break;
+                                }
+                                if("USERPAYING".equals(s)){
+                                    num++;
+                                }
+                            }
+                        }
+                    }catch (Exception e){
+                        e.printStackTrace();
+                    }
+                }
+            }).start();
+        }
+        return weixinpay;
 
     }
 
-    private void WeChatPayment(BigDecimal payAmount) {
+    @Override
+    public ResultUtil addRechargeCallbackPay(String code, String orderNumber) {
+        RechargeRecords rechargeRecords = this.baseMapper.selectOne(new QueryWrapper<RechargeRecords>()
+                .eq("code", code));
+        if (rechargeRecords.getPayStatus() == 2){
+            return  ResultUtil.success();
+        }
+        rechargeRecords.setPayStatus(2);
+        rechargeRecords.setPayTime(new Date());
+        rechargeRecords.setOrderNumber(orderNumber);
+        this.baseMapper.updateById(rechargeRecords);
 
-
+        TAppUser tAppUser = tappMapper.selectById(rechargeRecords.getAppUserId());
+        tAppUser.setPlayPaiCoins(null == tAppUser.getPlayPaiCoins()? rechargeRecords.getPlayPaiCoins(): tAppUser.getPlayPaiCoins() +rechargeRecords.getPlayPaiCoins() );
+        tappMapper.updateById(tAppUser);
+        return null;
     }
+
 }

--
Gitblit v1.7.1