| | |
| | | import com.dsh.competition.entity.UserCompetition; |
| | | import com.dsh.competition.feignclient.account.AppUserClient; |
| | | import com.dsh.competition.feignclient.account.StudentClient; |
| | | import com.dsh.competition.feignclient.account.StudentHonorClient; |
| | | import com.dsh.competition.feignclient.account.model.AppUser; |
| | | import com.dsh.competition.feignclient.account.model.StudentHonor; |
| | | import com.dsh.competition.feignclient.account.model.TStudent; |
| | | import com.dsh.competition.feignclient.course.CoursePackagePaymentClient; |
| | | import com.dsh.competition.feignclient.course.model.PaymentDeductionClassHour; |
| | |
| | | import com.dsh.competition.service.IParticipantService; |
| | | import com.dsh.competition.service.IPaymentCompetitionService; |
| | | import com.dsh.competition.service.UserCompetitionService; |
| | | import com.dsh.competition.util.PayMoneyUtil; |
| | | import com.dsh.competition.util.ResultUtil; |
| | | import com.dsh.competition.util.TokenUtil; |
| | | import com.dsh.competition.util.ToolUtil; |
| | | import com.dsh.competition.util.*; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | |
| | | import lombok.Synchronized; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.util.StringUtils; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.OutputStream; |
| | | import java.io.PrintWriter; |
| | | import java.math.BigDecimal; |
| | | import java.text.DateFormat; |
| | | import java.text.SimpleDateFormat; |
| | | import java.util.*; |
| | |
| | | @Autowired |
| | | private AppUserClient appUserClient; |
| | | |
| | | @Resource |
| | | private StudentHonorClient studentHonorClient; |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | | * 根据门店ids 获取对应的赛事 根据赛事支付记录获取用户ids |
| | | */ |
| | |
| | | // 获取到赛事id集合 去重 |
| | | List<Integer> collect = comIds.stream().distinct().collect(Collectors.toList()); |
| | | // 根据赛事id 查询赛事支付记录 获取用户ids |
| | | if (collect.size() == 0) { |
| | | if (collect.isEmpty()) { |
| | | return new ArrayList<>(); |
| | | } else { |
| | | List<Integer> userIds = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>() |
| | | .in("competitionId", collect)).stream() |
| | | .in("competitionId", collect) |
| | | .eq("payStatus",2)).stream() |
| | | .map(PaymentCompetition::getAppUserId).collect(Collectors.toList()); |
| | | return userIds; |
| | | } |
| | |
| | | List<Integer> operatorId = cttService.list(new QueryWrapper<Competition>() |
| | | .eq("operatorId", operatorId1)).stream().map(Competition::getId).collect(Collectors.toList()); |
| | | query.setUserIds(operatorId); |
| | | } else if (query.getStoreId() != null) { |
| | | List<Competition> list = cttService.list(new QueryWrapper<Competition>()); |
| | | List<Integer> integers = new ArrayList<>(); |
| | | for (Competition competition : list) { |
| | | for (String s : competition.getStoreId().split(",")) { |
| | | if (s.equals(""+query.getStoreId())){ |
| | | integers.add(competition.getId()); |
| | | } |
| | | } |
| | | } |
| | | if (integers.isEmpty()){ |
| | | integers.add(-1); |
| | | } |
| | | query.setUserIds(integers); |
| | | } |
| | | List<PaymentCompetition> paymentCompetitions = paymentCompetitionService.listAll(query); |
| | | List<PaymentCompetition> result = new ArrayList<>(); |
| | |
| | | @ApiImplicitParam(name = "Authorization", value = "用户token(Bearer +token)", required = true, dataType = "String", paramType = "header", defaultValue = "Bearer eyJhbGciOiJIUzUxMiJ9.....") |
| | | |
| | | }) |
| | | |
| | | public synchronized ResultUtil paymentCompetition(PaymentCompetitionVo paymentCompetitionVo) { |
| | | try { |
| | | Competition byId = competitionService.getById(paymentCompetitionVo.getId()); |
| | | Date date = byId.getEndTime(); |
| | | // Assuming you have a Date object |
| | | // Check if the date is past the current time |
| | | boolean isPast = date.after(new Date()); |
| | | if (!isPast) { |
| | | return new ResultUtil(0, "已超过截至报名时间"); |
| | |
| | | Competition competition = cttService.getById(paymentCompetition.getCompetitionId()); |
| | | competition.setApplicantsNumber(competition.getApplicantsNumber() + 1); |
| | | cttService.updateById(competition); |
| | | if (competition.getOperatorId()!=null && competition.getOperatorId()!=0){ |
| | | // 休眠两分钟后再调用分账接口 避免提示订单正在处理中 |
| | | Thread.sleep(120000); |
| | | // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 |
| | | String proportionByOperatorId = storeClient.getProportionByOperatorId(competition.getOperatorId()); |
| | | String[] split = proportionByOperatorId.split(","); |
| | | String s1 = split[0]; |
| | | if (!s1.equals("未设置")){ |
| | | BigDecimal bigDecimal = new BigDecimal(s1); |
| | | // 分账比例 |
| | | BigDecimal bigDecimal1 = bigDecimal.divide(new BigDecimal(100)).setScale(2); |
| | | // 微信商户号 |
| | | String s2 = storeClient.getmerchantNumberByOperatorId(competition.getOperatorId()); |
| | | String nonce_str = UUIDUtil.getRandomCode(16); |
| | | paymentCompetition.setFenzhangOrderNo(nonce_str); |
| | | BigDecimal bigDecimal2 = new BigDecimal(paymentCompetition.getAmount()); |
| | | ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, bigDecimal2.multiply(bigDecimal1), s2,nonce_str,"报名赛事分账"); |
| | | if (!fenzhang.getCode().equals(200)){ |
| | | System.err.println("分账失败 原因是:"+fenzhang.getData()+"-"+fenzhang.getMsg()); |
| | | }else{ |
| | | paymentCompetition.setFenzhangNo(fenzhang.getData().toString()); |
| | | paymentCompetition.setFenzhangAmount(bigDecimal2.multiply(bigDecimal1)); |
| | | paymentCompetitionService.updateById(paymentCompetition); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | PrintWriter out = response.getWriter(); |
| | | out.write(result); |
| | |
| | | String code = map.get("out_refund_no"); |
| | | String refund_id = map.get("refund_id"); |
| | | String result = map.get("result"); |
| | | PaymentCompetition paymentCompetition = paymentCompetitionService.getOne(new QueryWrapper<PaymentCompetition>().eq("code", code).eq("payType", 1)); |
| | | if (paymentCompetition.getPayStatus() == 1) { |
| | | PaymentCompetition paymentCompetition = paymentCompetitionService.getOne(new QueryWrapper<PaymentCompetition>() |
| | | .eq("code", code).eq("payType", 1)); |
| | | if (paymentCompetition.getPayStatus() == 2) { |
| | | paymentCompetition.setPayStatus(3); |
| | | paymentCompetition.setRefundTime(new Date()); |
| | | paymentCompetition.setRefundOrderNo(refund_id); |
| | |
| | | Competition competition = cttService.getById(paymentCompetition.getCompetitionId()); |
| | | competition.setApplicantsNumber(competition.getApplicantsNumber() - 1); |
| | | cttService.updateById(competition); |
| | | |
| | | PrintWriter out = response.getWriter(); |
| | | out.write(result); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | PrintWriter out = response.getWriter(); |
| | | out.write(result); |
| | | out.flush(); |
| | | out.close(); |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | } else { |
| | | competition.setStatus(3); |
| | | } |
| | | |
| | | if(competition.getStatus() == 2){ |
| | | //添加勋章数据 |
| | | List<PaymentCompetition> list = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>() |
| | | .eq("competitionId", competition.getId()).eq("payStatus", 2).eq("state", 1)); |
| | | Set<Integer> collect = list.stream().map(PaymentCompetition::getAppUserId).collect(Collectors.toSet()); |
| | | for (Integer integer : collect) { |
| | | int count = paymentCompetitionService.count(new QueryWrapper<PaymentCompetition>() |
| | | .eq("appUserId", integer).eq("payStatus", 2).eq("state", 1)); |
| | | StudentHonor studentHonor = new StudentHonor(); |
| | | studentHonor.setAppUserId(integer); |
| | | studentHonor.setHonorType(2); |
| | | studentHonor.setNumber(count); |
| | | studentHonorClient.saveStudentHonor(studentHonor); |
| | | } |
| | | } |
| | | } |
| | | competition.setInsertTime(new Date()); |
| | | cttService.save(competition); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | } else { |
| | | competition.setStatus(3); |
| | | } |
| | | |
| | | if(competition.getStatus() == 2){ |
| | | //添加勋章数据 |
| | | List<PaymentCompetition> list = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>() |
| | | .eq("competitionId", competition.getId()).eq("payStatus", 2).eq("state", 1)); |
| | | Set<Integer> collect = list.stream().map(PaymentCompetition::getAppUserId).collect(Collectors.toSet()); |
| | | for (Integer integer : collect) { |
| | | int count = paymentCompetitionService.count(new QueryWrapper<PaymentCompetition>() |
| | | .eq("appUserId", integer).eq("payStatus", 2).eq("state", 1)); |
| | | StudentHonor studentHonor = new StudentHonor(); |
| | | studentHonor.setAppUserId(integer); |
| | | studentHonor.setHonorType(2); |
| | | studentHonor.setNumber(count); |
| | | studentHonorClient.saveStudentHonor(studentHonor); |
| | | } |
| | | } |
| | | } |
| | | cttService.updateById(competition); |
| | | |
| | | |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | |
| | | String payOrderNo = paymentCompetition.getPayOrderNo(); |
| | | if (paymentCompetition.getPayType() == 1) {//微信支付 |
| | | Map<String, String> map = payMoneyUtil.wxRefund(payOrderNo, code, amount.toString(), amount.toString(), "/base/competition/weChatCancelPaymentCompetitionCallback"); |
| | | if (StringUtils.hasLength(paymentCompetition.getFenzhangNo())){ |
| | | // 是分账订单 如果分账金额不为0 那么回退分账金额 |
| | | if (paymentCompetition.getFenzhangAmount()!=null && paymentCompetition.getFenzhangAmount().compareTo(BigDecimal.ZERO)>0){ |
| | | String randomCode = UUIDUtil.getRandomCode(16); |
| | | String randomCode1 = UUIDUtil.getRandomCode(16); |
| | | if (competition.getOperatorId()!=null && competition.getOperatorId()!=0){ |
| | | // 微信商户号 |
| | | String s2 =storeClient.getmerchantNumberByOperatorId(competition.getOperatorId()); |
| | | ResultUtil resultUtil = payMoneyUtil.fenzhangRefund(paymentCompetition.getFenzhangNo(), paymentCompetition.getFenzhangAmount(), s2, randomCode, randomCode1); |
| | | if (!resultUtil.getCode().equals(200)){ |
| | | System.err.println("分账回退失败 原因是:"+resultUtil.getMsg()); |
| | | }else{ |
| | | paymentCompetition.setFenzhangRefundNo(resultUtil.getData().toString()); |
| | | paymentCompetitionService.updateById(paymentCompetition); |
| | | } |
| | | |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | Map<String, String> map = payMoneyUtil.wxRefund(payOrderNo, code, amount.toString(), amount.toString(), |
| | | "/base/competition/weChatCancelPaymentCompetitionCallback"); |
| | | String return_code = map.get("return_code"); |
| | | if (!"SUCCESS".equals(return_code)) { |
| | | // return ResultUtil.error(map.get("return_msg")); |
| | |
| | | } |
| | | String refund_id = map.get("refund_id"); |
| | | paymentCompetition.setRefundOrderNo(refund_id); |
| | | paymentCompetition.setAppUserId(null); |
| | | paymentCompetitionService.updateById(paymentCompetition); |
| | | |
| | | storeClient.addBackRecord(paymentCompetition.getAmount() + "_" + paymentCompetition.getAppUserId()); |
| | | |
| | | |
| | | } |
| | | if (paymentCompetition.getPayType() == 2) {//支付宝支付 |
| | |
| | | @Resource |
| | | private StudentClient studentClient; |
| | | @PostMapping("/base/competition/getPeopleFromId1") |
| | | public List<CompetitionUser> getPeopleFromId1(@RequestBody GetPeopleQuery getPeopleQuery) { |
| | | public Page<CompetitionUser> getPeopleFromId1(@RequestBody GetPeopleQuery getPeopleQuery) { |
| | | try { |
| | | Page<UserCompetition> participantPage = new Page<>(getPeopleQuery.getOffset(), getPeopleQuery.getLimit()); |
| | | List<CompetitionUser> page = participantService.getPeopleFromId1(participantPage, getPeopleQuery.getId(), getPeopleQuery.getState()); |
| | | |
| | | List<CompetitionUser> users = new ArrayList<>(); |
| | | List<UserCompetition> coms = userCompetitionService.list(new QueryWrapper<UserCompetition>().eq("competitionId", getPeopleQuery.getId())); |
| | | for (UserCompetition com : coms) { |
| | | int number = com.getParticipantId(); |
| | | String numberString = Integer.toString(number); |
| | | int digitCount = numberString.length(); |
| | | if (digitCount!=9){ |
| | | TStudent tStudent = studentClient.queryById(number); |
| | | CompetitionUser competitionUser = new CompetitionUser(); |
| | | competitionUser.setName(tStudent.getName()); |
| | | competitionUser.setPhone(tStudent.getPhone()); |
| | | competitionUser.setSex(tStudent.getSex()); |
| | | competitionUser.setIdCard(tStudent.getIdCard()); |
| | | competitionUser.setState(tStudent.getState()); |
| | | users.add(competitionUser); |
| | | } |
| | | } |
| | | page.addAll(users); |
| | | |
| | | Page<CompetitionUser> page = participantService.getPeopleFromId1(getPeopleQuery.getOffset(), getPeopleQuery.getLimit(), getPeopleQuery.getId(), getPeopleQuery.getState()); |
| | | return page; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | public List<Integer> queryAppUserId(@RequestBody List<Integer> storeIds){ |
| | | List<Competition> list = competitionService.list(new QueryWrapper<Competition>().in("storeId", storeIds).eq("auditStatus", 2).eq("state", 1)); |
| | | List<Integer> collect = list.stream().map(Competition::getId).collect(Collectors.toList()); |
| | | if(collect.size() == 0){ |
| | | return new ArrayList<>(); |
| | | } |
| | | List<PaymentCompetition> list1 = paymentCompetitionService.list(new QueryWrapper<PaymentCompetition>().eq("payStatus", 2).eq("state", 1).in("competitionId", collect)); |
| | | return list1.stream().map(PaymentCompetition::getAppUserId).collect(Collectors.toList()); |
| | | } |