From a8f90f717c73d7ff4d2355649f9f161a6f89aa9b Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期二, 05 三月 2024 14:08:15 +0800 Subject: [PATCH] 新增加管理后台功能 --- cloud-server-communityWorldCup/src/main/java/com/dsh/communityWorldCup/service/impl/WorldCupServiceImpl.java | 170 ++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 files changed, 156 insertions(+), 14 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 5dbd7e5..30e792b 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; + @@ -110,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"); @@ -128,17 +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); } - //调接口开启游戏 - /** - * 1、通过扫码获取的sutuid查询t_game表中的红蓝方sutuid - * 2、调起开启游戏的接口。 - */ + //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); + } } @@ -432,6 +460,8 @@ worldCupPaymentParticipant.setAppUserId(paymentWorldCup.getUid()); worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1); worldCupPaymentParticipant.setParticipantId(id); + worldCupPaymentParticipant.setAlreadyEntered(0); + worldCupPaymentParticipant.setCreateTime(new Date()); worldCupPaymentParticipantService.save(worldCupPaymentParticipant); } return ResultUtil.success(); @@ -480,12 +510,24 @@ 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); @@ -517,6 +559,8 @@ worldCupPaymentParticipant.setAppUserId(paymentWorldCup.getUid()); worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1); worldCupPaymentParticipant.setParticipantId(id); + worldCupPaymentParticipant.setAlreadyEntered(0); + worldCupPaymentParticipant.setCreateTime(new Date()); worldCupPaymentParticipantService.save(worldCupPaymentParticipant); } return ResultUtil.success(); @@ -553,6 +597,8 @@ worldCupPaymentParticipant.setAppUserId(worldCupPayment.getAppUserId()); worldCupPaymentParticipant.setParticipantType(isStudent == 0 ? 2 : 1); worldCupPaymentParticipant.setParticipantId(id); + worldCupPaymentParticipant.setAlreadyEntered(0); + worldCupPaymentParticipant.setCreateTime(new Date()); worldCupPaymentParticipantService.save(worldCupPaymentParticipant); } return ResultUtil.success(); @@ -565,6 +611,102 @@ */ @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