From 61bbd595ee2bc3c67b40878894dcc07174c6eea6 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期二, 24 九月 2024 10:15:30 +0800 Subject: [PATCH] 玩湃微信商户分账 --- cloud-server-account/src/main/java/com/dsh/account/service/impl/TAppUserServiceImpl.java | 150 ++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 139 insertions(+), 11 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 55afd69..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 @@ -157,6 +157,7 @@ @Resource private IntroduceRewardsClient introduceRewardsClient; + private String aliAppid = "2021004105665036";//支付宝appid private String appPrivateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCi5i9nW/hGLJ3A06cZxTQdviFC7THpdSihoTYGLr9q006hu0V26ecBMY/o4w5bvIX0Ok/yofmZsVcCJpAPvbXL/uqVrIjnRRxXiaeBFThlxoBUTdunvbUSDYfzlEhJr5NvUKI6H6lz2niXlQGx4qy8Hau4ccWit9kM8jwUvsBVQoFgJA+xrjMvooA7YLopQtpOD+UJr5thApTSf1xrnr1W12yolTLEH15JmNV372cqXrYUuqnY0QsaPtxeqJUGAOcGdVLllQ7easEznP8DFBvDdHATcmp2SHNQDUEWN6MCVPbMgY06NQVqAXxqjTAYSVh+6TRu6bofPmpYC3TZB003AgMBAAECggEBAJAcR2+PA3NBYUYHeFrqBRMS8uX8ZR19kjZ7IgoSLTFaQsP9opRylPSPXhrPVBKAE5leRQAHn4MCSlESwHvMfxo7KFjFTFAc6dffZZpipYQUOc9bGampwJh58/3e/pyBgVMG6J23CPf/HJQtNFSkjd/V9+ayb/9l2dUEL3bC0fAZ/dbx8Hsxd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ymentClient.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); @@ -1417,8 +1423,6 @@ } } } - - System.out.println(exchangeType); try { SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS"); @@ -1629,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(); @@ -1651,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(); @@ -1692,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() { @@ -1707,6 +1717,7 @@ Thread.sleep(wait); UserCouponPayment userCouponPayment1 = userCouponPaymentClient.getUserCouponPayment(code); if (userCouponPayment1.getStatus() == 2) { + break; } ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(code, ""); @@ -1747,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; } @@ -2080,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() { @@ -2097,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, ""); @@ -2147,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