From a37f794b26efb8a091d603363afe81eb20d6d580 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期三, 31 一月 2024 09:24:20 +0800
Subject: [PATCH] 更新bug修改

---
 cloud-server-competition/src/main/java/com/dsh/competition/service/impl/CompetitionServiceImpl.java |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/cloud-server-competition/src/main/java/com/dsh/competition/service/impl/CompetitionServiceImpl.java b/cloud-server-competition/src/main/java/com/dsh/competition/service/impl/CompetitionServiceImpl.java
index 9b1b269..8e71751 100644
--- a/cloud-server-competition/src/main/java/com/dsh/competition/service/impl/CompetitionServiceImpl.java
+++ b/cloud-server-competition/src/main/java/com/dsh/competition/service/impl/CompetitionServiceImpl.java
@@ -1,5 +1,8 @@
 package com.dsh.competition.service.impl;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
 import com.alibaba.nacos.common.utils.UuidUtils;
 import com.alipay.api.AlipayApiException;
 import com.alipay.api.AlipayClient;
@@ -226,7 +229,7 @@
     @Override
     public ResultUtil paymentCompetition(Integer uid, PaymentCompetitionVo paymentCompetitionVo) throws Exception {
         AppUser appUser = appUserClient.queryAppUser(uid);
-        String[] split = paymentCompetitionVo.getIds().split(";");
+        JSONArray jsonArray = JSON.parseArray(paymentCompetitionVo.getIds());
         Competition competition = this.getById(paymentCompetitionVo.getId());
 
         List<PaymentCompetition> list = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>().eq("competitionId", paymentCompetitionVo.getId()).ne("payStatus", 3));
@@ -241,22 +244,22 @@
         }
 
 
-        if ((competitionId + split.length) > competition.getApplicantsNumber()) {
+        if ((competitionId + jsonArray.size()) > competition.getApplicantsNumber()) {
             return ResultUtil.error("报名人数超过最大限制");
         }
         BigDecimal money = null;
         if (paymentCompetitionVo.getPayType() == 1 || paymentCompetitionVo.getPayType() == 2) {
-            money = new BigDecimal(competition.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN);
+            money = new BigDecimal(competition.getCashPrice()).multiply(new BigDecimal(jsonArray.size())).setScale(2, RoundingMode.HALF_EVEN);
         }
         if (paymentCompetitionVo.getPayType() == 3) {//玩湃币
-            money = new BigDecimal(competition.getPlayPaiCoin()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN);
+            money = new BigDecimal(competition.getPlayPaiCoin()).multiply(new BigDecimal(jsonArray.size())).setScale(2, RoundingMode.HALF_EVEN);
             if (money.compareTo(new BigDecimal(appUser.getPlayPaiCoins())) > 0) {
                 return new ResultUtil(2, "报名失败,玩湃币不足,请充值");
             }
         }
         if (paymentCompetitionVo.getPayType() == 4) {//课程
-            money = new BigDecimal(competition.getClassPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN);
-            for (String s : split) {
+            money = new BigDecimal(competition.getClassPrice()).multiply(new BigDecimal(jsonArray.size())).setScale(2, RoundingMode.HALF_EVEN);
+            for (int i = 0; i < jsonArray.size(); i++) {
 //                Participant participant = participantService.getById(s);
 //                Student student = studentClient.queryStudentByPhone(participant.getPhone());
 //                if(null == student){
@@ -284,12 +287,15 @@
         paymentCompetition.setInsertTime(new Date());
         paymentCompetitionService.save(paymentCompetition);
 
-        for (String s : split) {
+        for (int i = 0; i < jsonArray.size(); i++) {
+            JSONObject jsonObject = jsonArray.getJSONObject(i);
+            Integer id = jsonObject.getInteger("id");
+            Integer isStudent = jsonObject.getInteger("isStudent");
             UserCompetition userCompetition = new UserCompetition();
             userCompetition.setAppUserId(uid);
             userCompetition.setCompetitionId(paymentCompetitionVo.getId());
-            userCompetition.setParticipantId(Integer.valueOf(s));
-//            userCompetition.setParticipantType();
+            userCompetition.setParticipantId(id);
+            userCompetition.setParticipantType(isStudent == 0 ? 2 : 1);
             userCompetition.setPaymentCompetitionId(paymentCompetition.getId());
             userCompetition.setInsertTime(new Date());
             userCompetitionService.save(userCompetition);
@@ -325,11 +331,15 @@
             this.updateById(competition);
         }
         if (paymentCompetitionVo.getPayType() == 4) {//课程
-            for (String s : split) {
-//                Participant participant = participantService.getById(s);
-//                Student student = studentClient.queryStudentByPhone(participant.getPhone());
+            for (int i = 0; i < jsonArray.size(); i++) {
+                JSONObject jsonObject = jsonArray.getJSONObject(i);
+                Integer id = jsonObject.getInteger("id");
+                Integer isStudent = jsonObject.getInteger("isStudent");
+                if(isStudent == 0){
+                    continue;
+                }
                 PaymentDeductionClassHour paymentDeductionClassHour = new PaymentDeductionClassHour();
-                paymentDeductionClassHour.setId(Integer.valueOf(s));
+                paymentDeductionClassHour.setId(id);
                 paymentDeductionClassHour.setClassHour(competition.getClassPrice());
                 paymentDeductionClassHour.setCode(code);
                 paymentDeductionClassHour.setCourseId(paymentCompetitionVo.getCoursePaymentId());

--
Gitblit v1.7.1