From 53e7558400dcacecdce70e39ebfe1727740f9296 Mon Sep 17 00:00:00 2001 From: puzhibing <393733352@qq.com> Date: 星期六, 25 十一月 2023 17:20:06 +0800 Subject: [PATCH] 重写课包支付和排课逻辑 --- cloud-server-account/src/main/java/com/dsh/account/service/impl/RechargeRecordsServiceImpl.java | 104 +++++++++++++++++++++++++--------------------------- 1 files changed, 50 insertions(+), 54 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 0100c27..39e2c5b 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 @@ -78,7 +78,7 @@ @Override - public List<RechargesDetail> getAppUserRechargeRecord(String yearMonth, Integer recordId, Integer appUserId,Integer pageNum,Integer pageSize) { + public List<RechargesDetail> getAppUserRechargeRecord(String yearMonth, Integer recordId, Integer appUserId, Integer pageNum, Integer pageSize) { List<RechargesDetail> details = new ArrayList<>(); SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); @@ -94,16 +94,16 @@ // 1.赛事报名 List<PaymentCompetition> playPaiFGoldPayRecord = deducClient.getPlayPaiFGoldPayRecord(appUserId); - if (playPaiFGoldPayRecord.size() > 0 ){ + if (playPaiFGoldPayRecord.size() > 0) { for (PaymentCompetition competition : playPaiFGoldPayRecord) { - if (competition.getPayStatus()==2) { + if (competition.getPayStatus() == 2) { RechargesDetail consumeDetail = new RechargesDetail(); consumeDetail.setConsumeName(RechargeRecordEnum.EVENT_REGISTRATION.getMsg()); consumeDetail.setConsumeTime(simpleDateFormat.format(competition.getInsertTime())); consumeDetail.setConsumeAmount("-" + competition.getAmount()); consumeDetail.setRecordId(2); details.add(consumeDetail); - }else { + } else { RechargesDetail consumeDetail1 = new RechargesDetail(); @@ -126,10 +126,10 @@ } // 2.课包购买 List<CouponPaymentVo> appuserCourseList = cpClient.getAppuserCourseList(appUserId); - if (appuserCourseList.size() > 0){ + if (appuserCourseList.size() > 0) { for (CouponPaymentVo tCoursePackagePayment : appuserCourseList) { RechargesDetail consumeDetail = new RechargesDetail(); - consumeDetail.setConsumeName(RechargeRecordEnum.COURSE_PACKAGE_PURCHASE.getMsg() ); + consumeDetail.setConsumeName(RechargeRecordEnum.COURSE_PACKAGE_PURCHASE.getMsg()); consumeDetail.setConsumeTime(tCoursePackagePayment.getTime()); consumeDetail.setConsumeAmount("-" + tCoursePackagePayment.getAmount()); consumeDetail.setRecordId(2); @@ -138,16 +138,16 @@ } // 3.场地预约 List<SiteBooking> siteBookings = stClient.wanpaiGoldSiteBookingList(appUserId); - if (siteBookings.size() > 0 ){ + if (siteBookings.size() > 0) { for (SiteBooking booking : siteBookings) { - if (booking.getStatus()!=5) { + if (booking.getStatus() != 5) { RechargesDetail consumeDetail = new RechargesDetail(); consumeDetail.setConsumeName(RechargeRecordEnum.VENUE_RESERVATION.getMsg()); consumeDetail.setConsumeTime(simpleDateFormat.format(booking.getInsertTime())); consumeDetail.setConsumeAmount("-" + booking.getPayMoney()); consumeDetail.setRecordId(2); details.add(consumeDetail); - }else { + } else { RechargesDetail consumeDetail1 = new RechargesDetail(); consumeDetail1.setConsumeName(RechargeRecordEnum.CANCEL_VENUE_RESERVATION.getMsg()); consumeDetail1.setConsumeTime(simpleDateFormat.format(booking.getCancelTime())); @@ -163,25 +163,24 @@ details.add(consumeDetail); - } } } // 4.智慧球场 - List<Map<String,Object>> list = stClient.game(appUserId); - if (list.size() > 0 ){ - for (Map<String,Object> booking : list) { + List<Map<String, Object>> list = stClient.game(appUserId); + if (list.size() > 0) { + for (Map<String, Object> booking : list) { RechargesDetail consumeDetail = new RechargesDetail(); consumeDetail.setConsumeName("激战游戏"); consumeDetail.setConsumeTime(simpleDateFormat.format(new Date(Long.valueOf(booking.get("time").toString())))); - consumeDetail.setConsumeAmount("-"+String.valueOf(booking.get("money"))); + consumeDetail.setConsumeAmount("-" + String.valueOf(booking.get("money"))); consumeDetail.setRecordId(2); details.add(consumeDetail); } } - // 5.充值 + // 5.充值 List<RechargeRecords> rechargeRecords = this.baseMapper.selectList(new QueryWrapper<RechargeRecords>() .eq("payStatus", 2) .eq("appUserId", appUserId) @@ -196,12 +195,12 @@ details.add(consumeDetail); } } - if (ToolUtil.isNotEmpty(recordId)){ + if (ToolUtil.isNotEmpty(recordId)) { details = details.stream() .filter(record -> record.getRecordId().equals(recordId)) .collect(Collectors.toList()); } - if (details.size() > 0 ){ + if (details.size() > 0) { Collections.sort(details, new Comparator<RechargesDetail>() { @Override public int compare(RechargesDetail o1, RechargesDetail o2) { @@ -238,7 +237,6 @@ } - //分页 filteredList = filteredList.stream().skip((pageNo - 1) * size).limit(size). collect(Collectors.toList()); @@ -257,7 +255,7 @@ List<Map<String, Object>> rechargeConfig = reconMapper.getRechargeConfig(); BigDecimal amount = BigDecimal.ZERO; - if (rechargeConfig.size() > 0){ + if (rechargeConfig.size() > 0) { for (Map<String, Object> stringObjectMap : rechargeConfig) { double o = (double) stringObjectMap.get("money"); if (BigDecimal.valueOf(o).compareTo(request.getAmount()) == 0) { @@ -276,45 +274,44 @@ rechargeRecords.setInsertTime(new Date()); this.baseMapper.insert(rechargeRecords); try { - switch (request.getPayType()){ + switch (request.getPayType()) { case 1: - return WeChatPayment(code,amount); + return WeChatPayment(code, amount); case 2: - return AlipayPayment(code,amount); + return AlipayPayment(code, amount); default: break; } - }catch (Exception e){ + } catch (Exception e) { ResultUtil.runErr(); } return ResultUtil.success(); } - - private ResultUtil AlipayPayment(String code,BigDecimal amount) { + private ResultUtil AlipayPayment(String code, BigDecimal amount) { ResultUtil alipay = payMoneyUtil.alipay("玩湃币充值", "玩湃币充值", "", code, amount.toString(), "/base/recharge/alipayRechargeCallback"); - if(alipay.getCode() == 200){ + if (alipay.getCode() == 200) { new Thread(new Runnable() { @Override public void run() { try { int num = 1; int wait = 0; - while (num <= 10){ + 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){ + .eq("code", code)); + if (records.getPayStatus() == 2) { break; } AlipayTradeQueryResponse resultUtil = payMoneyUtil.queryALIOrder(code); - if(resultUtil.getCode().equals("10000")&& records.getPayStatus() == 1){ + if (resultUtil.getCode().equals("10000") && records.getPayStatus() == 1) { /** * WAIT_BUYER_PAY(交易创建,等待买家付款)、 * TRADE_CLOSED(未付款交易超时关闭,或支付完成后全额退款)、 @@ -327,13 +324,13 @@ String tradeNo = resultUtil.getTradeNo(); String tradeStatus = resultUtil.getTradeStatus(); - System.out.println("ssssss"+tradeStatus); - if("TRADE_CLOSED".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus) || num == 10){ + System.out.println("ssssss" + tradeStatus); + if ("TRADE_CLOSED".equals(tradeStatus) || "TRADE_FINISHED".equals(tradeStatus) || num == 10) { records.setState(3); rereMapper.deleteById(records.getId()); break; } - if("TRADE_SUCCESS".equals(tradeStatus)){ + if ("TRADE_SUCCESS".equals(tradeStatus)) { records.setAppUserId(null); records.setPayStatus(2); records.setPayTime(new Date()); @@ -342,24 +339,22 @@ RechargeRecords rechargeRecords = rereMapper.selectOne(new QueryWrapper<RechargeRecords>() .eq("code", code)); - if (rechargeRecords.getPayStatus() == 2){ + if (rechargeRecords.getPayStatus() == 2) { TAppUser tAppUser = tappMapper.selectById(rechargeRecords.getAppUserId()); - tAppUser.setPlayPaiCoins(null == tAppUser.getPlayPaiCoins()? rechargeRecords.getPlayPaiCoins(): tAppUser.getPlayPaiCoins() +rechargeRecords.getPlayPaiCoins() ); + tAppUser.setPlayPaiCoins(null == tAppUser.getPlayPaiCoins() ? rechargeRecords.getPlayPaiCoins() : tAppUser.getPlayPaiCoins() + rechargeRecords.getPlayPaiCoins()); tappMapper.updateById(tAppUser); break; } - - break; } - if("WAIT_BUYER_PAY".equals(tradeStatus)){ + if ("WAIT_BUYER_PAY".equals(tradeStatus)) { num++; } } } - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } @@ -368,27 +363,27 @@ return alipay; } - private ResultUtil WeChatPayment(String code,BigDecimal amount) throws Exception { + private ResultUtil WeChatPayment(String code, BigDecimal amount) throws Exception { ResultUtil weixinpay = payMoneyUtil.weixinpay("玩湃币充值", "", code, amount.toString(), "/base/recharge/wechatRechargeCallback", "APP", ""); - if(weixinpay.getCode() == 200){ + if (weixinpay.getCode() == 200) { new Thread(new Runnable() { @Override public void run() { try { int num = 1; int wait = 0; - while (num <= 10){ + 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){ + .eq("code", code)); + if (records.getPayStatus() == 2) { break; } ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); - if(resultUtil.getCode() == 200 && records.getPayStatus() == 1){ + if (resultUtil.getCode() == 200 && records.getPayStatus() == 1) { /** * SUCCESS—支付成功, * REFUND—转入退款, @@ -401,23 +396,23 @@ 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){ + 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)){ + if ("SUCCESS".equals(s)) { records.setPayStatus(2); records.setOrderNumber(transaction_id); rereMapper.updateById(records); break; } - if("USERPAYING".equals(s)){ + if ("USERPAYING".equals(s)) { num++; } } } - }catch (Exception e){ + } catch (Exception e) { e.printStackTrace(); } } @@ -431,8 +426,8 @@ 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(); + if (rechargeRecords.getPayStatus() == 2) { + return ResultUtil.success(); } rechargeRecords.setAppUserId(null); rechargeRecords.setPayStatus(2); @@ -441,7 +436,7 @@ this.baseMapper.updateById(rechargeRecords); TAppUser tAppUser = tappMapper.selectById(rechargeRecords.getAppUserId()); - tAppUser.setPlayPaiCoins(null == tAppUser.getPlayPaiCoins()? rechargeRecords.getPlayPaiCoins(): tAppUser.getPlayPaiCoins() +rechargeRecords.getPlayPaiCoins() ); + tAppUser.setPlayPaiCoins(null == tAppUser.getPlayPaiCoins() ? rechargeRecords.getPlayPaiCoins() : tAppUser.getPlayPaiCoins() + rechargeRecords.getPlayPaiCoins()); tappMapper.updateById(tAppUser); return null; } @@ -455,7 +450,7 @@ ETime = query.getTime().split(" - ")[1] + " 23:59:59"; } - return rechargeRecordsMapper.rechargeList(query,STime,ETime); + return rechargeRecordsMapper.rechargeList(query, STime, ETime); } @@ -467,8 +462,9 @@ STime = query.getTime().split(" - ")[0] + " 00:00:00"; ETime = query.getTime().split(" - ")[1] + " 23:59:59"; } - return rechargeRecordsMapper.listAll(query,STime,ETime,query.getAmount(),query.getInsertType()); + return rechargeRecordsMapper.listAll(query, STime, ETime, query.getAmount(), query.getInsertType()); } + public static <T> List<T> pageList(List<T> list, int pageNum, int pageSize) { //计算总页数 int page = list.size() % pageSize == 0 ? list.size() / pageSize : list.size() / pageSize + 1; -- Gitblit v1.7.1