From b716afd262ff60ff1db0b1e7c95800e7ad2b7202 Mon Sep 17 00:00:00 2001 From: 无关风月 <443237572@qq.com> Date: 星期一, 07 七月 2025 11:07:37 +0800 Subject: [PATCH] 支付版本更新 根据资金流向使用V2或V3服务商版本支付 --- cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java | 200 ++++++++++++++++++++++++++++--------------------- 1 files changed, 115 insertions(+), 85 deletions(-) diff --git a/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java b/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java index 61a4e05..91d6eb5 100644 --- a/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java +++ b/cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java @@ -4,11 +4,16 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayClient; +import com.alipay.api.DefaultAlipayClient; +import com.alipay.api.request.AlipayTradeOrderSettleRequest; +import com.alipay.api.response.AlipayTradeOrderSettleResponse; import com.alipay.api.response.AlipayTradeQueryResponse; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.dsh.other.entity.*; +import com.dsh.other.feignclient.StoreClient; import com.dsh.other.feignclient.account.AppUserClient; import com.dsh.other.feignclient.account.model.AppUser; import com.dsh.other.feignclient.activity.CouponClient; @@ -25,6 +30,7 @@ import org.aspectj.weaver.ast.Var; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import org.springframework.util.StringUtils; import javax.annotation.Resource; import java.math.BigDecimal; @@ -69,6 +75,12 @@ @Autowired private TBackRecordService backRecordService; + + @Autowired + private ISiteBookingService iSiteBookingService; + + @Autowired + private ISiteService siteService; /** @@ -155,10 +167,7 @@ } - @Autowired - private ISiteBookingService iSiteBookingService; - @Autowired - private ISiteService siteService; + /** * 获取场地预约日期数据 @@ -327,7 +336,6 @@ */ @Override public ResultUtil reservationSite(Integer uid, ReservationSite reservationSite) throws Exception { - Site site = this.getById(reservationSite.getId()); AppUser appUser = appUserClient.queryAppUser(uid); String[] split = reservationSite.getTimes().split(";"); @@ -358,7 +366,6 @@ payMoney = new BigDecimal(site.getPlayPaiCoinOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); } if (appUser.getPlayPaiCoins().compareTo(payMoney.intValue()) < 0) { - return new ResultUtil(3, "玩湃币不足"); } } else { @@ -366,18 +373,14 @@ payMoney = new BigDecimal(site.getCashPrice()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); } else { payMoney = new BigDecimal(site.getCashPriceOne()).multiply(new BigDecimal(split.length)).setScale(2, RoundingMode.HALF_EVEN).doubleValue(); - } } //校验优惠券 Long couponId = reservationSite.getCouponId(); if (couponId != null && couponId != 0) { - if (null != couponId && reservationSite.getPayType() != 3) { UserCoupon userCoupon = userCouponClient.queryUserCouponById(new QueryUserCouponByIdAndUserId(reservationSite.getCouponId(), uid)); - - if (userCoupon != null && userCoupon.getStatus() == 2) { return ResultUtil.error("优惠券已被核销"); } @@ -387,7 +390,6 @@ return ResultUtil.error("优惠券已过期"); } if (userCoupon != null && coupon.getType() == 1) {//满减 -// {"conditionalAmount":50,"deductionAmount":10,"experienceName":""} JSONObject jsonObject = JSON.parseObject(coupon.getContent()); Double num1 = jsonObject.getDouble("conditionalAmount"); Double num2 = jsonObject.getDouble("deductionAmount"); @@ -432,7 +434,6 @@ siteBooking.setState(1); siteBooking.setInsertTime(new Date()); - // 2.0 siteBooking.setNextName(reservationSite.getNextName()); siteBooking.setIsHalf(reservationSite.getIsHalf()); siteBooking.setHalfName(reservationSite.getHalfName()); @@ -441,7 +442,6 @@ if (reservationSite.getPayType() == 1) {//微信支付 ResultUtil resultUtil = weChatPaymentSite(payMoney, siteBooking); - return resultUtil; } if (reservationSite.getPayType() == 2) {//支付宝支付 @@ -457,7 +457,7 @@ return ResultUtil.success(); } - + private String smidVx = "2088330203191220";//平台微信商户号 /** * 课程微信支付 * @@ -468,61 +468,31 @@ public ResultUtil weChatPaymentSite(Double paymentPrice, SiteBooking siteBooking) throws Exception { String code = siteBooking.getOrderNo(); Integer id = siteBooking.getId(); - ResultUtil weixinpay = payMoneyUtil.weixinpay("预约场地", id.toString(), code, paymentPrice.toString(), "/base/site/weChatPaymentSiteCallback", "APP", ""); - if (weixinpay.getCode() == 200) { - new Thread(new Runnable() { - @Override - public void run() { - try { - int num = 1; - int wait = 0; - while (num <= 10) { - int min = 5000; - wait += (min * num); - Thread.sleep(wait); - SiteBooking siteBooking = siteBookingService.getById(id); - if (siteBooking.getStatus() != 0) { - break; - } - ResultUtil<Map<String, String>> resultUtil = payMoneyUtil.queryWXOrder(siteBooking.getOrderNo(), ""); - if (resultUtil.getCode() == 200 && siteBooking.getStatus() == 0) { - /** - * SUCCESS—支付成功, - * REFUND—转入退款, - * NOTPAY—未支付, - * CLOSED—已关闭, - * REVOKED—已撤销(刷卡支付), - * USERPAYING--用户支付中, - * PAYERROR--支付失败(其他原因,如银行返回失败) - */ - 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) { - break; - } - if ("SUCCESS".equals(s)) { - siteBooking.setPayTime(new Date()); - siteBooking.setStatus(1); - siteBooking.setPayOrderNo(transaction_id); - siteBookingService.updateById(siteBooking); - break; - } - if ("USERPAYING".equals(s)) { - num++; - } - } - } - } catch (Exception e) { - e.printStackTrace(); - } - } - }).start(); + Site byId = siteService.getById(siteBooking.getSiteId()); + Store store = storeService.getById(byId.getStoreId()); + if (store.getOperatorId()==null || store.getOperatorId()==0){ + // 平台 + ResultUtil weixinpay = payMoneyUtil.weixinpay("预约场地", id.toString(), code, paymentPrice.toString(), + "/base/site/weChatPaymentSiteCallback", "APP", ""); + return weixinpay; + }else{ + String smidVx= operatorUserService.getmerchantNumberByOperatorId(store.getOperatorId()); + if (!StringUtils.hasLength(smidVx)){ + return ResultUtil.error("运营商未配置微信商户号,获取支付失败!"); + } + return payMoneyUtil.weixinpayV3(smidVx,"预约场地" + ,code,"/base/site/weChatPaymentSiteCallback1", + paymentPrice.toString(),id.toString()); } - return weixinpay; + + } private String smid = "2088330203191220";//平台支付宝商户号 + @Autowired + private IOperatorUserService operatorUserService; + @Autowired + private StoreClient storeClient; /** * 课程支付宝支付 * @@ -544,7 +514,7 @@ }else if (operatorId == 0){ smid1 = smid; }else{ - smid1 = siteService.getSMIDByOperatorId(operatorId); + smid1 = siteService.getmerchantNumberAliByOperatorId(operatorId); } ResultUtil alipay = payMoneyUtil.alipay(smid1,"预约场地", "预约场地", id.toString(), code, paymentPrice.toString(), "/base/site/aliPaymentSiteCallback"); @@ -586,20 +556,6 @@ siteBooking.setPayOrderNo(tradeNo); siteBookingService.updateById(siteBooking); System.err.println("======完成支付"); - // 判断预约的门店 属于哪个运营商 - Integer storeId = siteBooking.getStoreId(); - Store byId = storeService.getById(storeId); - Integer operatorId = byId.getOperatorId(); - String smid1 = ""; - if (operatorId == null ){ - // 平台的门店 - }else if (operatorId == 0){ - smid1 = smid; - }else{ - smid1 = siteService.getSMIDByOperatorId(operatorId); - - } - payMoneyUtil.confirm(smid1,code,tradeNo,paymentPrice.toString()); break; } if ("WAIT_BUYER_PAY".equals(s)) { @@ -616,7 +572,53 @@ return alipay; } + private void extracted(Integer operatorId, BigDecimal coursePackageOrder1, String tradeNo) throws Exception { + // 分账 + AlipayClient alipayClient = new DefaultAlipayClient("https://openapi.alipay.com/gateway.do", + "2021004105665036", + "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCi5i9nW/hGLJ3A06cZxTQdviFC7THpd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ZFrv7gsD+XkgKG7PwimehRlkwmCX5ilxtLiVgJRzRt6+5U5AMVD90a0tHzXYP0z2yjj73fBJF5KtGl0a10KZxaYrQdm1UhB00CgYBZZgzx/k9rtHC8LAqIj1CYhHejT92G53c6Gkl3vyOqN4sgKhfGmSEySfrDGPRBPZxr8ZtbIPCd5mUdberH0osWGMYFaJI1UsCy7aQwvGpniz7MhZeN7dweaOjwDs8mgtjHQ96mL4XGCDhR0BZ/wIURvZ/6iaGdhbbu9unlsWj3uQKBgQCmZYdsbbZkd3ev6f8rwyvMz+DrCQyYpY44cegBYuJgrZiQnL2fJioeN7ixX0UM48SfwsZEIrzshP/LGAwnc2MdjxKUl4jLN8SEe0NAjXOnz9Zaw740+aOmLpXcLWdP4uM2gIhWsvW1tEkQZCXmm7c9s/RsU8Pmzv+YL3+fSijOzA==", + "json", "GBK", + "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmu8n/4yTHWbn7VOrNc9OsLtDL1bEQ8gC1dHkj8Wy5z0mkaOsjJRIG/28ze12M0V8jdCKuuDr5Z1OPKiqf+XO3ypguEh+mYUVMBM/cZodDFQfTY1TKLWjvQCuaqlA+QUTCK6f7T7stsgyQ1o9Jj0rXZDz6PM4QHSTzjrLIBaeqM5WIBvH+fy/X+QG5Utd+/UT0kc0JyvuKhZ65yVUd/C9VcwJJAPliRsAQNrqYterwAJ9zvw9tF11wj9W0XgJ8Ccu4x3gR1vrlLRJJo/OA97RmxPQ+5hSacWQZCUd1dwiBq+YCrKVHGTj14izRHXrLc0yBlRXo7tBOIqcy3IsvKVthQIDAQAB", + "RSA2"); + AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest(); + String randomCode = UUIDUtil.getRandomCode(16); + String proportionByOperatorId = operatorUserService.getOne(new QueryWrapper<OperatorUser>() + .eq("operatorId",operatorId)).getAlipayProportion(); + // 支付宝分账比例 + String s1 = proportionByOperatorId.split(",")[1]; + double i = Double.parseDouble(s1); + double v = i * 0.01; + BigDecimal bigDecimal1 = new BigDecimal(String.valueOf(v)); + // 分账金额 + BigDecimal bigDecimal2 = coursePackageOrder1.multiply(bigDecimal1).setScale(2, RoundingMode.DOWN); + request.setBizContent("{" + + " \"out_request_no\":\"" + randomCode + "\"," + + " \"trade_no\":\"" + tradeNo + "\"," + + " \"royalty_parameters\":[" + + " {" + + " \"royalty_type\":\"transfer\"," + + " \"trans_out\":\"" + storeClient.getSMIDByOperatorId(operatorId)+ "\"," + + " \"trans_out_type\":\"userId\"," + + " \"trans_in_type\":\"userId\"," + + " \"trans_in\":\"" + smid + "\"," + + " \"amount\":" + bigDecimal2 + "," + + " \"desc\":\"平台服务费\"," + + " \"royalty_scene\":\"平台服务费\"," + + " }" + + " ]," + + " \"extend_params\":{" + + " \"royalty_finish\":\"true\"" + + " }," + + " \"royalty_mode\":\"async\"" + + "}"); + AlipayTradeOrderSettleResponse response = alipayClient.execute(request); + if (response.isSuccess()) { + System.out.println("调用成功"); + } else { + System.out.println("调用失败"); + } + } /** * 玩湃币支付 * @@ -680,7 +682,7 @@ @Override public ResultUtil cancelMySite(Integer uid, Integer id) throws Exception { SiteBooking siteBooking = siteBookingService.getById(id); - + Site byId = siteService.getById(siteBooking.getSiteId()); SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd"); Date startTime = siteBooking.getStartTime(); if (format.format(new Date()).equals(format.format(startTime)) && siteBooking.getStatus() != 0) { @@ -688,7 +690,6 @@ } if (siteBooking.getStatus() == 0) { -// return ResultUtil.error("请先进行支付"); siteBooking.setStatus(5); siteBookingService.updateById(siteBooking); AppUser appUser = appUserClient.queryAppUser(siteBooking.getAppUserId()); @@ -705,12 +706,32 @@ return ResultUtil.error("不能进行取消操作"); } if (siteBooking.getPayType() == 1) {//微信支付 - Map<String, String> map = payMoneyUtil.wxRefund(siteBooking.getPayOrderNo(), siteBooking.getOrderNo(), siteBooking.getPayMoney().toString(), siteBooking.getPayMoney().toString(), "/base/site/cancelMySiteCallback"); + if (StringUtils.hasLength(siteBooking.getFenzhangNo())){ + // 是分账订单 如果分账金额不为0 那么回退分账金额 + if (siteBooking.getFenzhangAmount()!=null && siteBooking.getFenzhangAmount().compareTo(BigDecimal.ZERO)>0){ + String randomCode = UUIDUtil.getRandomCode(16); + String randomCode1 = UUIDUtil.getRandomCode(16); + if (byId.getOperatorId()!=null && byId.getOperatorId()!=0){ + // 微信商户号 + String s2 =siteService.getmerchantNumberByOperatorId(byId.getOperatorId()); + ResultUtil resultUtil = payMoneyUtil.fenzhangRefund(siteBooking.getFenzhangNo(), siteBooking.getFenzhangAmount().multiply(new BigDecimal("100")), s2, randomCode, randomCode1); + if (!resultUtil.getCode().equals(200)){ + System.err.println("分账回退失败 原因是:"+resultUtil.getMsg()+resultUtil.getData()); + }else{ + siteBooking.setFenzhangRefundNo(resultUtil.getMsg()); + siteBookingService.updateById(siteBooking); + } + + } + } + } + Map<String, String> map = payMoneyUtil.wxRefund(siteBooking.getPayOrderNo(), siteBooking.getOrderNo(), siteBooking.getPayMoney().toString(), + siteBooking.getPayMoney().toString(), "/base/site/cancelMySiteCallback"); if (null == map) { return ResultUtil.error("取消退款异常"); } - String result_code = map.get("result_code"); - if (!"SUCCESS".equals(result_code)) { + String return_code = map.get("return_code"); + if (!"SUCCESS".equals(return_code)) { return ResultUtil.error(map.get("return_msg")); } siteBooking.setCancelUserId(uid); @@ -925,4 +946,13 @@ public String getSMIDByOperatorId(Integer id) { return siteMapper.getSMIDByOperatorId(id); } + @Override + public String getmerchantNumberByOperatorId(Integer id) { + return siteMapper.getmerchantNumberByOperatorId(id); + } + + @Override + public String getmerchantNumberAliByOperatorId(Integer id) { + return siteMapper.getmerchantNumberAliByOperatorId(id); + } } -- Gitblit v1.7.1