| | |
| | | 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; |
| | |
| | | import com.dsh.competition.service.IPaymentCompetitionService; |
| | | import com.dsh.competition.service.UserCompetitionService; |
| | | import com.dsh.competition.util.*; |
| | | import org.checkerframework.checker.units.qual.A; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | |
| | | private String alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAouYvZ1v4RiydwNOnGcU0Hb4hQu0x6XUooaE2Bi6/atNOobtFdunnATGP6OMOW7yF9DpP8qH5mbFXAiaQD721y/7qlayI50UcV4mngRU4ZcaAVE3bp721Eg2H85RISa+Tb1CiOh+pc9p4l5UBseKsvB2ruHHForfZDPI8FL7AVUKBYCQPsa4zL6KAO2C6KULaTg/lCa+bYQKU0n9ca569VtdsqJUyxB9eSZjVd+9nKl62FLqp2NELGj7cXqiVBgDnBnVS5ZUO3mrBM5z/AxQbw3RwE3JqdkhzUA1BFjejAlT2zIGNOjUFagF8ao0wGElYfuk0bum6Hz5qWAt02QdNNwIDAQAB";//支付宝应用公钥 |
| | | |
| | | private String alipay_public_key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmu8n/4yTHWbn7VOrNc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB";//支付宝支付公钥 |
| | | |
| | | private String smid = "2088330203191220";//平台支付宝商户号 |
| | | |
| | | /** |
| | | * 获取赛事列表 |
| | |
| | | @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)); |
| | |
| | | } |
| | | |
| | | |
| | | // int competitionId = userCompetitionService.count(new QueryWrapper<UserCompetition>().eq("competitionId", paymentCompetitionVo.getId())); |
| | | 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) { |
| | | // Participant participant = participantService.getById(s); |
| | | // Student student = studentClient.queryStudentByPhone(participant.getPhone()); |
| | | // if(null == student){ |
| | | // return ResultUtil.error(participant.getName() + "不是学员,无法使用课时支付。"); |
| | | // } |
| | | // 2.0 |
| | | Integer integer = coursePackagePaymentClient.queryResidueClassHourById(paymentCompetitionVo.getCoursePaymentId()); |
| | | if (new BigDecimal(integer).compareTo(new BigDecimal(competition.getClassPrice())) < 0) { |
| | | return new ResultUtil(3, "剩余课时不足,无法完成支付。"); |
| | | |
| | | } |
| | | money = new BigDecimal(competition.getClassPrice()).multiply(new BigDecimal(jsonArray.size())).setScale(2, RoundingMode.HALF_EVEN); |
| | | Integer integer = coursePackagePaymentClient.queryResidueClassHourById(paymentCompetitionVo.getCoursePaymentId()); |
| | | if (new BigDecimal(integer).compareTo(money) < 0) { |
| | | return new ResultUtil(3, "剩余课时不足,无法完成支付。"); |
| | | } |
| | | } |
| | | |
| | |
| | | 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.setParticipantId(id); |
| | | userCompetition.setParticipantType(isStudent == 0 ? 2 : 1); |
| | | userCompetition.setPaymentCompetitionId(paymentCompetition.getId()); |
| | | userCompetition.setInsertTime(new Date()); |
| | | userCompetitionService.save(userCompetition); |
| | |
| | | } |
| | | |
| | | if (paymentCompetitionVo.getPayType() == 2) {//支付宝 |
| | | return aliPaymentCompetition(code, money); |
| | | // 判断当前赛事属于哪个运营商 |
| | | Competition byId = competitionService.getById(paymentCompetitionVo.getId()); |
| | | Integer operatorId = byId.getOperatorId(); |
| | | if (operatorId == null ){ |
| | | // 说明是平台 |
| | | return aliPaymentCompetition(smid,code, money); |
| | | } |
| | | // 获取该运营商的商户号 |
| | | String smid = storeClient.getSMIDByOperatorId(operatorId); |
| | | return aliPaymentCompetition(smid,code, money); |
| | | } |
| | | if (paymentCompetitionVo.getPayType() == 3) {//玩湃币 |
| | | appUser.setPlayPaiCoins(appUser.getPlayPaiCoins() - money.intValue()); |
| | |
| | | paymentCompetition.setPayOrderNo(""); |
| | | paymentCompetitionService.updateById(paymentCompetition); |
| | | |
| | | // competition.setApplicantsNumber(competition.getApplicantsNumber() + 1); |
| | | 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()); |
| | | paymentDeductionClassHour.setUid(uid); |
| | | coursePackagePaymentClient.paymentDeductionClassHour(paymentDeductionClassHour); |
| | | } |
| | | |
| | | paymentCompetition = paymentCompetitionService.getById(paymentCompetition.getId()); |
| | | paymentCompetition.setAppUserId(null); |
| | | paymentCompetition.setPayStatus(2); |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public ResultUtil aliPaymentCompetition(String code, BigDecimal money) throws Exception { |
| | | ResultUtil alipay = payMoneyUtil.alipay("报名赛事", "", "", code, money.toString(), "/base/competition/aliPaymentCompetitionCallback"); |
| | | public ResultUtil aliPaymentCompetition(String smid,String code, BigDecimal money) throws Exception { |
| | | ResultUtil alipay = payMoneyUtil.alipay |
| | | (smid,"报名赛事", "", "", code, money.toString(), "/base/competition/aliPaymentCompetitionCallback"); |
| | | if (alipay.getCode() == 200) { |
| | | new Thread(new Runnable() { |
| | | @Override |
| | |
| | | paymentCompetition.setAppUserId(null); |
| | | paymentCompetition.setState(3); |
| | | userCompetitionService.remove(new QueryWrapper<UserCompetition>().eq("paymentCompetitionId", paymentCompetition.getId())); |
| | | |
| | | break; |
| | | } |
| | | if ("TRADE_SUCCESS".equals(s)) { |
| | |
| | | paymentCompetition.setPayTime(new Date()); |
| | | paymentCompetition.setPayOrderNo(tradeNo); |
| | | paymentCompetitionService.updateById(paymentCompetition); |
| | | |
| | | // 结算资金到商户账号 |
| | | payMoneyUtil.confirm(smid,code,tradeNo,money.toString()); |
| | | //分账 |
| | | |
| | | |
| | | // moneyOut(tradeNo, tradeNo,code); |
| | | |
| | | break; |
| | | } |
| | | if ("WAIT_BUYER_PAY".equals(s)) { |