From 1b8ad0cc6a79f84fb32fdffae39742afa964748e Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期二, 24 九月 2024 16:09:50 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/2.0' into 2.0 --- cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java | 199 ++++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 177 insertions(+), 22 deletions(-) diff --git a/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java b/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java index 1214233..d964181 100644 --- a/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java +++ b/cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java @@ -29,13 +29,8 @@ import com.dsh.account.feignclient.course.CoursePaymentClient; import com.dsh.account.feignclient.course.VideoOfCourseListClient; import com.dsh.account.feignclient.course.model.*; -import com.dsh.account.feignclient.other.ImgConfigClient; -import com.dsh.account.feignclient.other.RechargeConfigClient; -import com.dsh.account.feignclient.other.SiteClient; -import com.dsh.account.feignclient.other.StoreClient; -import com.dsh.account.feignclient.other.model.Store; -import com.dsh.account.feignclient.other.model.StoreDetailOfCourse; -import com.dsh.account.feignclient.other.model.TImgConfig; +import com.dsh.account.feignclient.other.*; +import com.dsh.account.feignclient.other.model.*; import com.dsh.account.mapper.*; import com.dsh.account.model.*; import com.dsh.account.model.AppUserByNameAndPhoneDTO; @@ -162,6 +157,7 @@ @Resource private IntroduceRewardsClient introduceRewardsClient; + private String aliAppid = "2021004105665036";//支付宝appid private String appPrivateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCi5i9nW/hGLJ3A06cZxTQdviFC7THpdSihoTYGLr9q006hu0V26ecBMY/o4w5bvIX0Ok/yofmZsVcCJpAPvbXL/uqVrIjnRRxXiaeBFThlxoBUTdunvbUSDYfzlEhJr5N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gYBZZgzx/k9rtHC8LAqIj1CYhHejT92G53c6Gkl3vyOqN4sgKhfGmSEySfrDGPRBPZxr8ZtbIPCd5mUdberH0osWGMYFaJI1UsCy7aQwvGpniz7MhZeN7dweaOjwDs8mgtjHQ96mL4XGCDhR0BZ/wIURvZ/6iaGdhbbu9unlsWj3uQKBgQCmZYdsbbZkd3ev6f8rwyvMz+DrCQyYpY44cegBYuJgrZiQnL2fJioeN7ixX0UM48SfwsZEIrzshP/LGAwnc2MdjxKUl4jLN8SEe0NAjXOnz9Zaw740+aOmLpXcLWdP4uM2gIhWsvW1tEkQZCXmm7c9s/RsU8Pmzv+YL3+fSijOzA==";//支付宝开发者应用私钥 @@ -190,6 +186,9 @@ @Autowired private UserIntegralChangesService userIntegralChangesService; + + @Resource + private GameRecordClient gameRecordClient; @@ -883,6 +882,21 @@ } // 5.智慧球场 + GetTGameRecord getTGameRecord = new GetTGameRecord(); + getTGameRecord.setAppUserId(appUserId); + getTGameRecord.setStartTiem(monthStart); + getTGameRecord.setEndTime(monthEnd); + List<TGameRecord> tGameRecord = gameRecordClient.getTGameRecord(getTGameRecord); + for (TGameRecord gameRecord : tGameRecord) { + ConsumeDetail consumeDetail = new ConsumeDetail(); + consumeDetail.setConsumeName(RechargeRecordEnum.SMART_STADIUM.getMsg()); + consumeDetail.setConsumeTime(simpleDateFormat.format(gameRecord.getTime())); + consumeDetail.setConsumeAmount("-" + gameRecord.getMoney()); + consumeDetail.setType(2); + consumeDetail.setDateTime(gameRecord.getTime().getTime()); + details.add(consumeDetail); + } + // 6.年度会员 List<VipPayment> vipPayments = vipPaymentMapper.selectList(new QueryWrapper<VipPayment>() .eq("payStatus", 2) @@ -956,6 +970,7 @@ details.add(consumeDetail); } } + if (details.size() > 0) { Collections.sort(details, new Comparator<ConsumeDetail>() { @@ -1393,7 +1408,12 @@ userCouponPaymentClient.addUserCouponPayment(userCouponPayment); try { if(exchangeType.getPayType() == 1){ - return weChatPaymentCoupon("购买优惠券", userCouponPayment); + String temp = "0"; + if (coupon.getPublisherType()!=null && coupon.getPublisherType() != 2){ + // 做分账 + temp = "1"; + } + return weChatPaymentCoupon("购买优惠券-"+temp, userCouponPayment); } if(exchangeType.getPayType() == 2){ return aliPaymentCoupon("购买优惠券", userCouponPayment); @@ -1403,8 +1423,6 @@ } } } - - System.out.println(exchangeType); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); @@ -1503,13 +1521,24 @@ pointsMerchandise.setCode(code); pointsMerchandise.setInsertTime(new Date()); pointsMerchandise.setPayType(exchangeType.getExchangeType()); - pointsMerchandise.setIntegral(merchandise.getIntegral() * goodsNums); + if(null != merchandise.getIntegral()){ + pointsMerchandise.setIntegral(merchandise.getIntegral() * goodsNums); + } if(exchangeType.getExchangeType() == 2){ pointsMerchandise.setCash(merchandise.getCash()); pointsMerchandise.setCashPayType(exchangeType.getPayType()); } + + Double m = new BigDecimal((merchandise.getIntegral() == null ? 0 : merchandise.getIntegral())).add((merchandise.getCash() == null ? BigDecimal.ZERO : merchandise.getCash())).doubleValue(); + if((m * goodsNums) == 0) { + pointsMerchandise.setPayStatus(2); + pointsMerchandise.setPaymentTime(new Date()); + } returnId = mcClient.saveDetailsUserPointMercase(pointsMerchandise); - + if((m * goodsNums) == 0 && pointsMerchandise.getPayStatus() == 2){ + returnModel.setReturnId(returnId); + return ResultUtil.success(returnModel); + } switch (exchangeType.getExchangeType()) { // 积分 @@ -1604,9 +1633,9 @@ coursePackageOrder.setInsertTime(new Date()); coursePackageOrder.setOrderType(2); paymentClient.savePaymentCoursePackage(coursePackageOrder); - return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code); - } else { - return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code); + return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code,merchandise.getId()); + } else if (merchandise.getType() == 1){ + return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId()); } } catch (Exception e) { return ResultUtil.runErr(); @@ -1626,9 +1655,9 @@ case 1: try { if (merchandise.getType() == 2) { - return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code); + return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(exchangeType.getStuIds().size())), code,merchandise.getId()); } else { - return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code); + return WechatPayment(merchandise.getType(), merchandise.getCash().multiply(new BigDecimal(goodsNums)), code,merchandise.getId()); } } catch (Exception e) { return ResultUtil.runErr(); @@ -1667,7 +1696,13 @@ public ResultUtil weChatPaymentCoupon(String body, UserCouponPayment userCouponPayment) throws Exception { String code = userCouponPayment.getCode(); Double cash = userCouponPayment.getCash(); - ResultUtil weixinpay = payMoneyUtil.weixinpay(body, "", code, cash.toString(), + Integer couponId = userCouponPayment.getCouponId(); + Coupon coupon = userConponClient.queryCouponById(couponId); + String temp ="0"; + if (coupon.getPublisherType()!=null&&coupon.getPublisherType()!=2){ + temp = "1"; + } + ResultUtil weixinpay = payMoneyUtil.weixinpay(body+"-"+temp, "", code, cash.toString(), "/base/coupon/weChatPaymentCouponCallback", "APP", ""); if (weixinpay.getCode() == 200) { new Thread(new Runnable() { @@ -1682,6 +1717,7 @@ Thread.sleep(wait); UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code); if (userCouponPayment1.getStatus() == 2) { + break; } ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); @@ -1722,6 +1758,38 @@ TAppUser user = appUserService.getById(userCouponPayment1.getUserId()); user.setIntegral(user.getIntegral() - userCouponPayment1.getIntegral().intValue()); appUserService.updateById(user); + } + // 休眠两分钟后再调用分账接口 避免提示订单正在处理中 + Thread.sleep(120000); + if (coupon!=null){ + if (coupon.getPublisherType()!=null&&coupon.getPublisherType()!=2){ + if (coupon.getPublisherType() == 3){ + // 门店 向上查询运营商 + Store store = storeClient.queryStoreById(coupon.getCityManagerId()); + if (store.getOperatorId()==null || store.getOperatorId()==0){ + // 平台不分账 + break; + }else{ + // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 + String proportionByOperatorId = storeClient.getProportionByOperatorId(store.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(store.getOperatorId()); + BigDecimal bigDecimal2 = new BigDecimal(cash); + ResultUtil fenzhang = payMoneyUtil.fenzhang(userCouponPayment1.getOrderNumber(), bigDecimal2.multiply(bigDecimal1), s2); + if (!fenzhang.getCode().equals(500)){ + System.err.println("分账失败 原因是:"+fenzhang.getMsg()); + } + + } + } + } + } } break; } @@ -1928,8 +1996,9 @@ if ("TRADE_SUCCESS".equals(tradeStatus)) { for (UserPointsMerchandise userPointsMerchandise : userPointsMerchandises) { userPointsMerchandise.setPayStatus(2); + userPointsMerchandise.setPaymentTime(new Date()); userPointsMerchandise.setOrderNumber(tradeNo); - userPointsMerchandise.setPayType(2); + userPointsMerchandise.setCashPayType(2); userPointsMerchandise.setInsertTime(null); userPointsMerchandise.setUserId(null); mcClient.updateDetailsUserPointMercase(userPointsMerchandise); @@ -2054,9 +2123,39 @@ } - private ResultUtil WechatPayment(Integer type, BigDecimal cash, String code) throws Exception { + private ResultUtil WechatPayment(Integer type, BigDecimal cash, String code,Integer id) throws Exception { String name = (type == 1 ? "购买实体商品" : type == 2 ? "报名运动营": type == 3 ? "购买门票" : "购买优惠券"); - ResultUtil weixinpay = payMoneyUtil.weixinpay(name, "", code, cash.toString(), + PointsMerchandise pointsMerchandise = mcClient.selectPointsMerchandiseById(id); + // 分账表示 0否1是 + String temp = "0"; + switch (type){ + case 1: + temp = "0"; + break; + case 2: + // 判断课包属于平台还是运营商 + CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId()); + Store store = storeClient.queryStoreById(coursePackage.getStoreId()); + if (store.getOperatorId() ==null || store.getOperatorId() == 0){ + // 平台课包 不分账 + }else{ + temp = "1"; + } + break; + case 3: + List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); + if (!integers.isEmpty()){ + Store store1 = storeClient.queryStoreById(integers.get(0)); + if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){ + // 平台门票 不分账 + }else{ + temp = "1"; + } + } + // 查询门票指定的门店 属于平台还是运营商 + break; + } + ResultUtil weixinpay = payMoneyUtil.weixinpay(name+"-"+temp, "", code, cash.toString(), "/base/pointMer/exchangeGoodPaymentWeChatCallback", "APP", ""); if (weixinpay.getCode() == 200) { new Thread(new Runnable() { @@ -2071,6 +2170,8 @@ Thread.sleep(wait); UserPointsMerchandise userPointsMerchandise = mcClient.queryUserPointMerchaseByCode(code).get(0); if (userPointsMerchandise.getPayStatus() == 2) { + + break; } ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); @@ -2093,8 +2194,9 @@ } if ("SUCCESS".equals(s)) { userPointsMerchandise.setPayStatus(2); + userPointsMerchandise.setPaymentTime(new Date()); userPointsMerchandise.setOrderNumber(transaction_id); - userPointsMerchandise.setPayType(1); + userPointsMerchandise.setCashPayType(1); mcClient.updateDetailsUserPointMercase(userPointsMerchandise); TAppUser tAppUser = baseMapper.selectById(userPointsMerchandise.getUserId()); @@ -2120,6 +2222,59 @@ paymentClient.addCoursePackageOrderStudent(addCoursePackageOrderStudent); } } + // 休眠两分钟后再调用分账接口 避免提示订单正在处理中 + Thread.sleep(120000); + // 分账表示 0否1是 + String temp = "0"; + // 运营商id + Integer operatorId = 0; + switch (type){ + case 1: + temp = "0"; + break; + case 2: + // 判断课包属于平台还是运营商 + CoursePackage coursePackage = cpageClient.queryCoursePackageById(pointsMerchandise.getCoursePackageId()); + Store store = storeClient.queryStoreById(coursePackage.getStoreId()); + if (store.getOperatorId() ==null || store.getOperatorId() == 0){ + // 平台课包 不分账 + }else{ + temp = "1"; + operatorId = store.getOperatorId(); + } + break; + case 3: + List<Integer> integers = mcsClient.queryPointMerStoreIds(pointsMerchandise.getId()); + if (!integers.isEmpty()){ + Store store1 = storeClient.queryStoreById(integers.get(0)); + if (store1.getOperatorId() ==null || store1.getOperatorId() == 0){ + // 平台门票 不分账 + }else{ + temp = "1"; + operatorId = store1.getOperatorId(); + } + } + // 查询门票指定的门店 属于平台还是运营商 + break; + } + if (operatorId != 0) { + // 根据运营商id获取对应运营商分账比例 返回格式: 微信分账比例,支付宝分账比例 + String proportionByOperatorId = storeClient.getProportionByOperatorId(operatorId); + 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(operatorId); + + ResultUtil fenzhang = payMoneyUtil.fenzhang(transaction_id, cash.multiply(bigDecimal1), s2); + if (!fenzhang.getCode().equals(500)){ + System.err.println("分账失败 原因是:"+fenzhang.getMsg()); + } + } + } break; } if ("USERPAYING".equals(s) || "NOTPAY".equals(s)) { -- Gitblit v1.7.1