liujie
2023-07-26 57a7c48cc4c81f7e9719c414e4abae942c93a21b
cloud-server-competition/src/main/java/com/dsh/competition/service/impl/CompetitionServiceImpl.java
@@ -83,7 +83,7 @@
     * @return
     */
    @Override
    public List<CompetitionListVo> queryCompetitionList(String cityCode, String content, Integer registerCondition, Integer heat) throws Exception {
    public List<CompetitionListVo> queryCompetitionList(String cityCode, String content, Integer registerCondition, String heat) throws Exception {
        return this.baseMapper.queryCompetitionList(cityCode, content, registerCondition, heat);
    }
@@ -104,16 +104,18 @@
        competitionInfo.setImgs(competition.getImgs());
        competitionInfo.setName(competition.getName());
        competitionInfo.setRegisterCondition(competition.getRegisterCondition());
        Store store = storeClient.queryStoreById(competition.getStoreId());
        competitionInfo.setStoreName(store.getName());
        competitionInfo.setStoreAddress(store.getAddress());
        competitionInfo.setStoreLon(store.getLon());
        competitionInfo.setStoreLat(store.getLat());
        competitionInfo.setStoreCoverDrawing(store.getCoverDrawing());
        if(ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)){
            Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
            double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
            competitionInfo.setDistance(wgs84);
        if(null != competition.getStoreId()){
            Store store = storeClient.queryStoreById(competition.getStoreId());
            competitionInfo.setStoreName(store.getName());
            competitionInfo.setStoreAddress(store.getAddress());
            competitionInfo.setStoreLon(store.getLon());
            competitionInfo.setStoreLat(store.getLat());
            competitionInfo.setStoreCoverDrawing(store.getCoverDrawing());
            if(ToolUtil.isNotEmpty(lon) && ToolUtil.isNotEmpty(lat)){
                Map<String, Double> distance = GeodesyUtil.getDistance(lon + "," + lat, store.getLon() + "," + store.getLat());
                double wgs84 = new BigDecimal(distance.get("WGS84")).divide(new BigDecimal(1000)).setScale(2, RoundingMode.HALF_EVEN).doubleValue();
                competitionInfo.setDistance(wgs84);
            }
        }
        competitionInfo.setRegisterEndTime(sdf.format(competition.getRegisterEndTime()));
        competitionInfo.setStartTime(sdf.format(competition.getStartTime()));
@@ -122,16 +124,18 @@
        competitionInfo.setProvince(competition.getEntryProvince());
        competitionInfo.setCity(competition.getEntryCity());
        competitionInfo.setAddress(competition.getEntryAddress());
        competitionInfo.setPayType(competition.getPayType());
        competitionInfo.setPrice(competition.getPrice().doubleValue());
        competitionInfo.setCashPrice(competition.getCashPrice());
        competitionInfo.setPlayPaiCoin(competition.getPlayPaiCoin());
        competitionInfo.setClassPrice(competition.getClassPrice());
        competitionInfo.setIntroduction(competition.getIntroduction());
        competitionInfo.setRegistrationNotes(competition.getRegistrationNotes());
        competitionInfo.setApply(0);
        PaymentCompetition one = paymentCompetitionService.getOne(new QueryWrapper<PaymentCompetition>().eq("competitionId", id).eq("appUserId", uid).eq("payStatus", 2));
        competitionInfo.setStatus(competition.getStatus());
        PaymentCompetition one = paymentCompetitionService.getOne(new QueryWrapper<PaymentCompetition>().eq("competitionId", id).eq("appUserId", uid).ne("payStatus", 1).orderByDesc("insertTime").last(" limit 1"));
        if(null != one){
            competitionInfo.setApply(1);
            List<ParticipantVo> participant = new ArrayList<>();
            List<UserCompetition> list = userCompetitionService.list(new QueryWrapper<UserCompetition>().eq("competitionId", id).eq("appUserId", uid));
            List<UserCompetition> list = userCompetitionService.list(new QueryWrapper<UserCompetition>().eq("paymentCompetitionId", one.getId()));
            List<Integer> collect = list.stream().map(UserCompetition::getParticipantId).collect(Collectors.toList());
            List<Participant> participants = participantService.listByIds(collect);
            SimpleDateFormat sdf_year = new SimpleDateFormat("yyyy");
@@ -145,6 +149,9 @@
                participant.add(participantVo);
            }
            competitionInfo.setParticipant(participant);
            if(one.getPayStatus() == 3){
                competitionInfo.setStatus(4);
            }
        }
        return competitionInfo;
    }
@@ -162,13 +169,18 @@
        AppUser appUser = appUserClient.queryAppUser(uid);
        String[] split = paymentCompetitionVo.getIds().split(";");
        Competition competition = this.getById(paymentCompetitionVo.getId());
        BigDecimal money = competition.getPrice().multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN);
        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);
        }
        if(paymentCompetitionVo.getPayType() == 3){//玩湃币
            money = new BigDecimal(competition.getPlayPaiCoin()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN);
            if(money.compareTo(new BigDecimal(appUser.getPlayPaiCoins())) > 0){
                return ResultUtil.error("报名失败,玩湃币不足,请充值");
            }
        }
        if(paymentCompetitionVo.getPayType() == 4){//课程
            money = new BigDecimal(competition.getClassPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN);
            for (String s : split) {
                Participant participant = participantService.getById(s);
                Student student = studentClient.queryStudentByPhone(participant.getPhone());
@@ -176,7 +188,7 @@
                    return ResultUtil.error(participant.getName() + "不是学员,无法使用课时支付。");
                }
                Integer integer = coursePackagePaymentClient.queryResidueClassHour(student.getId());
                if(new BigDecimal(integer).compareTo(competition.getPrice()) < 0){
                if(new BigDecimal(integer).compareTo(new BigDecimal(competition.getClassPrice())) < 0){
                    return ResultUtil.error(participant.getName() + "剩余课时不足,无法完成支付。");
                }
            }
@@ -189,7 +201,7 @@
        paymentCompetition.setCompetitionId(paymentCompetitionVo.getId());
        paymentCompetition.setAppUserId(uid);
        paymentCompetition.setPayType(paymentCompetitionVo.getPayType());
        paymentCompetition.setAmount(competition.getPrice().multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue());
        paymentCompetition.setAmount(money.doubleValue());
        paymentCompetition.setPayStatus(1);
        paymentCompetition.setInsertTime(new Date());
        paymentCompetitionService.save(paymentCompetition);
@@ -228,7 +240,7 @@
                Student student = studentClient.queryStudentByPhone(participant.getPhone());
                PaymentDeductionClassHour paymentDeductionClassHour = new PaymentDeductionClassHour();
                paymentDeductionClassHour.setId(student.getId());
                paymentDeductionClassHour.setClassHour(competition.getPrice().intValue());
                paymentDeductionClassHour.setClassHour(competition.getClassPrice());
                paymentDeductionClassHour.setCode(code);
                coursePackagePaymentClient.paymentDeductionClassHour(paymentDeductionClassHour);
            }
@@ -369,4 +381,14 @@
        }
        return alipay;
    }
    /**
     * 定时任务修改赛事状态
     */
    @Override
    public void taskSetStatus() {
        this.baseMapper.taskSetStatusStart();
        this.baseMapper.taskSetStatusEnd();
    }
}