From 794a2ec5fa219a0a87be0c72bd59602cb9f6c6dc Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期二, 05 三月 2024 14:19:08 +0800
Subject: [PATCH] 合并代码

---
 cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java |  177 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 168 insertions(+), 9 deletions(-)

diff --git a/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java b/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java
index 4daf04b..d327581 100644
--- a/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java
+++ b/cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java
@@ -3,6 +3,7 @@
 import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
+import com.alipay.api.AlipayApiException;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.dsh.communityWorldCup.entity.*;
@@ -14,8 +15,10 @@
 import com.dsh.communityWorldCup.feignclient.competition.model.Participant;
 import com.dsh.communityWorldCup.feignclient.course.CoursePackageOrderStudentClient;
 import com.dsh.communityWorldCup.feignclient.course.model.CoursePackageOrderStudent;
+import com.dsh.communityWorldCup.feignclient.other.GameClient;
 import com.dsh.communityWorldCup.feignclient.other.StoreClient;
 import com.dsh.communityWorldCup.feignclient.other.model.Store;
+import com.dsh.communityWorldCup.feignclient.other.model.TGame;
 import com.dsh.communityWorldCup.mapper.WorldCupMapper;
 import com.dsh.communityWorldCup.model.*;
 import com.dsh.communityWorldCup.service.*;
@@ -67,6 +70,9 @@
     @Resource
     private CoursePackageOrderStudentClient coursePackageOrderStudentClient;
 
+    @Resource
+    private GameClient gameClient;
+
 
 
 
@@ -100,8 +106,6 @@
      */
     @Override
     public ResultUtil startWorldCup(StartWorldCup startWorldCup) {
-        //先检测当前是否已经结束
-
         WorldCup worldCup = this.getById(startWorldCup.getWorldCupId());
         if(worldCup.getStartTime().getTime() > System.currentTimeMillis()){
             return ResultUtil.error("赛事还未开始");
@@ -112,9 +116,19 @@
         if(worldCup.getStatus() == 4){
             return ResultUtil.error("赛事已取消");
         }
+        //1、通过扫码获取的sutuid查询t_game表中的红蓝方sutuid
+        String code = startWorldCup.getCode();
+        JSONObject object = JSON.parseObject(code);
+        String sutu_id = object.getString("sutu_id");
+        TGame tGame = gameClient.getTGameBySutuId(sutu_id);
+        if(null == tGame){
+            return ResultUtil.error("无效的游戏二维码");
+        }
+
         String people = startWorldCup.getPeople();
         JSONArray jsonArray = JSON.parseArray(people);
         String timeStr = UUIDUtil.getTimeStr() + UUIDUtil.getNumberRandom(3);
+        List<Long> ids = new ArrayList<>();
         for (int i = 0; i < jsonArray.size(); i++) {
             JSONObject jsonObject = jsonArray.getJSONObject(i);
             Integer id = jsonObject.getInteger("id");
@@ -130,10 +144,29 @@
             worldCupCompetitor.setParticipant("blue".equals(type) ? 1 : 2);
             worldCupCompetitor.setStartTime(new Date());
             worldCupCompetitorService.save(worldCupCompetitor);
+            ids.add(worldCupCompetitor.getId());
+            //已参赛
+            worldCupPaymentParticipant.setAlreadyEntered(1);
+            worldCupPaymentParticipantService.updateById(worldCupPaymentParticipant);
         }
-        //调接口开启游戏
+        //2、调起开启游戏的接口。
+        HashMap<String, String> map = new HashMap<>();
+        map.put("sign", "0DB011836143EEE2C2E072967C9F4E4B");
+        map.put("space_id", tGame.getSiteId() + "");
+        map.put("red_sutu_id", tGame.getRed());
+        map.put("blue_sutu_id", tGame.getBlue());
+        map.put("api_url", "http://221.182.45.100:56666/communityWorldCup/base/worldCup/endWorldCupCallback");
+        map.put("custom", JSON.toJSONString(ids));
 
-        return ResultUtil.success();
+        String s = HttpRequestUtil.postRequest("https://try.daowepark.com/v7/user_api/general/batterGame", map);
+        JSONObject jsonObject = JSONObject.parseObject(s);
+        Integer code1 = jsonObject.getInteger("code");
+        String message = jsonObject.getString("message");
+        if (200 == code1) {
+            return ResultUtil.success();
+        } else {
+            return ResultUtil.error(message);
+        }
     }
 
 
@@ -384,6 +417,7 @@
             //微信
             if(payType == 1){
                 worldCupPayment.setAmount(new BigDecimal(num).multiply(worldCup.getCash()));
+                worldCupPayment.setUnitPrice(worldCupPayment.getAmount().divide(new BigDecimal(num)));
                 worldCupPaymentService.save(worldCupPayment);
                 return payMoneyUtil.weixinpay("社区世界杯报名", "", worldCupPayment.getCode(),
                         worldCup.getCash().toString(), "/base/worldCup/wxPayWorldCupCallback", "APP", "");
@@ -391,6 +425,7 @@
             //支付宝
             if(payType == 2){
                 worldCupPayment.setAmount(new BigDecimal(num).multiply(worldCup.getCash()));
+                worldCupPayment.setUnitPrice(worldCupPayment.getAmount().divide(new BigDecimal(num)));
                 worldCupPaymentService.save(worldCupPayment);
                 return payMoneyUtil.alipay("2088330203191220", "社区世界杯报名", "世界杯报名", "", worldCupPayment.getCode(),
                         worldCup.getCash().toString(), "/base/worldCup/aliPayWorldCupCallback");
@@ -405,6 +440,7 @@
                 worldCupPayment.setAmount(multiply);
                 worldCupPayment.setPayStatus(2);
                 worldCupPayment.setPayTime(new Date());
+                worldCupPayment.setUnitPrice(worldCupPayment.getAmount().divide(new BigDecimal(num)));
                 worldCupPaymentService.save(worldCupPayment);
 
                 appUser.setPlayPaiCoins(appUser.getPlayPaiCoins() - multiply.intValue());
@@ -426,6 +462,7 @@
                     worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
                     worldCupPaymentParticipant.setParticipantId(id);
                     worldCupPaymentParticipant.setAlreadyEntered(0);
+                    worldCupPaymentParticipant.setCreateTime(new Date());
                     worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
                 }
                 return ResultUtil.success();
@@ -474,16 +511,29 @@
                             break;
                         }
                     }
-                }
 
-                //扣减课时操作
-                DeductionClassHourList deductionClassHourList = new DeductionClassHourList();
-                deductionClassHourList.setDeductionClassHourList(list);
-                coursePackageOrderStudentClient.deductionClassHour(deductionClassHourList);
+                    //扣减课时操作
+                    DeductionClassHourList deductionClassHourList = new DeductionClassHourList();
+                    deductionClassHourList.setDeductionClassHourList(list);
+                    DeductionClassHourList deductionClassHourList1 = coursePackageOrderStudentClient.deductionClassHour(deductionClassHourList);
+                    List<DeductionClassHour> deductionClassHourList2 = deductionClassHourList1.getDeductionClassHourList();
+
+                    WorldCupPaymentParticipant worldCupPaymentParticipant = new WorldCupPaymentParticipant();
+                    worldCupPaymentParticipant.setWorldCupId(paymentWorldCup.getId());
+                    worldCupPaymentParticipant.setWorldCupPaymentId(worldCupPayment.getId());
+                    worldCupPaymentParticipant.setAppUserId(paymentWorldCup.getUid());
+                    worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
+                    worldCupPaymentParticipant.setParticipantId(id);
+                    worldCupPaymentParticipant.setAlreadyEntered(0);
+                    worldCupPaymentParticipant.setCreateTime(new Date());
+                    worldCupPaymentParticipant.setContent(JSON.toJSONString(deductionClassHourList2));
+                    worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
+                }
 
                 worldCupPayment.setAmount(multiply);
                 worldCupPayment.setPayStatus(2);
                 worldCupPayment.setPayTime(new Date());
+                worldCupPayment.setUnitPrice(worldCupPayment.getAmount().divide(new BigDecimal(num)));
                 worldCupPaymentService.save(worldCupPayment);
 
                 //添加报名明细
@@ -510,6 +560,7 @@
             worldCupPayment.setAmount(BigDecimal.ZERO);
             worldCupPayment.setPayStatus(2);
             worldCupPayment.setPayTime(new Date());
+            worldCupPayment.setUnitPrice(BigDecimal.ZERO);
             worldCupPaymentService.save(worldCupPayment);
 
             //添加报名明细
@@ -528,6 +579,7 @@
                 worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
                 worldCupPaymentParticipant.setParticipantId(id);
                 worldCupPaymentParticipant.setAlreadyEntered(0);
+                worldCupPaymentParticipant.setCreateTime(new Date());
                 worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
             }
             return ResultUtil.success();
@@ -565,6 +617,7 @@
             worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1);
             worldCupPaymentParticipant.setParticipantId(id);
             worldCupPaymentParticipant.setAlreadyEntered(0);
+            worldCupPaymentParticipant.setCreateTime(new Date());
             worldCupPaymentParticipantService.save(worldCupPaymentParticipant);
         }
         return ResultUtil.success();
@@ -596,4 +649,110 @@
         map.put("total", count);
         return map;
     }
+
+
+    /**
+     * 取消赛事后退还费用
+     * @param id
+     */
+    @Override
+    public void cancelWorldCupRefund(Integer id) {
+        List<WorldCupPaymentParticipant> list = worldCupPaymentParticipantService.list(new QueryWrapper<WorldCupPaymentParticipant>()
+                .eq("worldCupId", id).eq("alreadyEntered", 0));
+        Set<Long> collect = list.stream().map(WorldCupPaymentParticipant::getWorldCupPaymentId).collect(Collectors.toSet());
+        for (Long worldCupPaymentId : collect) {
+
+            List<WorldCupPaymentParticipant> list1 = worldCupPaymentParticipantService.list(new QueryWrapper<WorldCupPaymentParticipant>()
+                    .eq("worldCupPaymentId", worldCupPaymentId).eq("alreadyEntered", 0));
+            WorldCupPayment worldCupPayment = worldCupPaymentService.getById(worldCupPaymentId);
+            BigDecimal multiply = worldCupPayment.getUnitPrice().multiply(new BigDecimal(list1.size()));
+            //微信支付
+            if(worldCupPayment.getPayType() == 1){
+                Map<String, String> map = payMoneyUtil.wxRefund(worldCupPayment.getPayOrderNo(), worldCupPayment.getCode(),
+                        worldCupPayment.getAmount().toString(), multiply.toString(), "/base/worldCup/wxRefundWorldCupCallback");
+                if(!"SUCCESS".equals(map.get("return_code"))){
+                    System.err.println("-------------微信退款失败---------");
+                    System.err.println(map.get("return_msg"));
+                }
+            }
+            //支付宝支付
+            if(worldCupPayment.getPayType() == 2){
+                Map<String, String> map = null;
+                try {
+                    map = payMoneyUtil.aliRefund(worldCupPayment.getPayOrderNo(), multiply.toString());
+                } catch (AlipayApiException e) {
+                    throw new RuntimeException(e);
+                }
+                if("10000".equals(map.get("code"))){
+                    String trade_no = map.get("trade_no");
+                    worldCupPayment.setRefundTime(new Date());
+                    worldCupPayment.setRefundOrderNo(trade_no);
+                    worldCupPayment.setPayStatus(3);
+                    worldCupPaymentService.updateById(worldCupPayment);
+                }
+            }
+            //玩湃币支付
+            if(worldCupPayment.getPayType() == 3){
+                Integer appUserId = worldCupPayment.getAppUserId();
+                AppUser appUser = appUserClient.getAppUser(appUserId);
+                appUser.setPlayPaiCoins(appUser.getPlayPaiCoins() + multiply.intValue());
+                appUserClient.updateAppUser(appUser);
+                worldCupPayment.setRefundTime(new Date());
+                worldCupPayment.setRefundOrderNo("");
+                worldCupPayment.setPayStatus(3);
+                worldCupPaymentService.updateById(worldCupPayment);
+            }//课时支付
+            if(worldCupPayment.getPayType() == 4){
+                for (WorldCupPaymentParticipant worldCupPaymentParticipant : list1) {
+                    Integer studentId = worldCupPaymentParticipant.getParticipantId();//构建扣减课时数据
+                    String content = worldCupPaymentParticipant.getContent();
+                    List<DeductionClassHour> list2 = JSON.parseArray(content, DeductionClassHour.class);
+
+
+
+
+
+//                    Integer classHour = worldCup.getClassHour();
+//                    for (CoursePackageOrderStudent packageOrderStudent : coursePackageOrderStudent) {
+//                        Integer laveClassHours = packageOrderStudent.getLaveClassHours();
+//
+//                        DeductionClassHour deductionClassHour = new DeductionClassHour();
+//                        if(classHour.compareTo(laveClassHours) > 0){
+//                            //不够扣除,轮询直到扣除完
+//                            classHour = classHour - laveClassHours;
+//                            deductionClassHour.setId(packageOrderStudent.getId());
+//                            deductionClassHour.setClassHour(laveClassHours);
+//                            deductionClassHour.setStudentId(packageOrderStudent.getStudentId());
+//                            deductionClassHour.setCoursePackageId(packageOrderStudent.getCoursePackageId());
+//                            list.add(deductionClassHour);
+//                        }else{
+//                            //够扣除直接跳出进行下个学员
+//                            deductionClassHour.setId(packageOrderStudent.getId());
+//                            deductionClassHour.setClassHour(classHour);
+//                            deductionClassHour.setStudentId(packageOrderStudent.getStudentId());
+//                            deductionClassHour.setCoursePackageId(packageOrderStudent.getCoursePackageId());
+//                            list.add(deductionClassHour);
+//                            break;
+//                        }
+//                    }
+                }
+
+                //扣减课时操作
+                DeductionClassHourList deductionClassHourList = new DeductionClassHourList();
+//                deductionClassHourList.setDeductionClassHourList(list);
+                coursePackageOrderStudentClient.deductionClassHour(deductionClassHourList);
+            }
+
+
+        }
+
+
+        for (WorldCupPaymentParticipant worldCupPaymentParticipant : list) {
+
+
+
+
+        }
+
+    }
 }

--
Gitblit v1.7.1