From 3a03018efa6374619e6e90dcfb5ed4d3995963aa Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期一, 18 八月 2025 11:21:39 +0800
Subject: [PATCH] 会员协议
---
cloud-server-other/src/main/java/com/dsh/other/service/impl/SiteServiceImpl.java | 235 +++++++++++++++++++++++++++++++++++++---------------------
1 files changed, 148 insertions(+), 87 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 ade018d..f0ca39a 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;
@@ -59,6 +65,7 @@
@Resource
private UserCouponClient userCouponClient;
+
@Resource
private CouponClient couponClient;
@@ -69,6 +76,12 @@
@Autowired
private TBackRecordService backRecordService;
+
+ @Autowired
+ private ISiteBookingService iSiteBookingService;
+
+ @Autowired
+ private ISiteService siteService;
/**
@@ -155,10 +168,7 @@
}
- @Autowired
- private ISiteBookingService iSiteBookingService;
- @Autowired
- private ISiteService siteService;
+
/**
* 获取场地预约日期数据
@@ -174,9 +184,7 @@
System.out.println("=======date======" + day);
List<String> strings = new ArrayList<>();
-// List<SiteBooking> siteBookings = siteClient.listBooks(id);
List<SiteBooking> siteBookings = iSiteBookingService.list(new QueryWrapper<SiteBooking>().eq("siteId", id).ne("status", 5).eq("nextName", siteName).like("times", day));
-
if (siteName == null || siteName.equals("")) {
siteBookings = iSiteBookingService.list(new QueryWrapper<SiteBooking>().eq("siteId", id).ne("status", 5).like("times", day));
@@ -329,7 +337,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(";");
@@ -360,7 +367,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 {
@@ -368,18 +374,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("优惠券已被核销");
}
@@ -389,7 +391,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");
@@ -434,7 +435,6 @@
siteBooking.setState(1);
siteBooking.setInsertTime(new Date());
- // 2.0
siteBooking.setNextName(reservationSite.getNextName());
siteBooking.setIsHalf(reservationSite.getIsHalf());
siteBooking.setHalfName(reservationSite.getHalfName());
@@ -443,7 +443,6 @@
if (reservationSite.getPayType() == 1) {//微信支付
ResultUtil resultUtil = weChatPaymentSite(payMoney, siteBooking);
-
return resultUtil;
}
if (reservationSite.getPayType() == 2) {//支付宝支付
@@ -459,7 +458,7 @@
return ResultUtil.success();
}
-
+ private String smidVx = "2088330203191220";//平台微信商户号
/**
* 课程微信支付
*
@@ -470,61 +469,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;
/**
* 课程支付宝支付
*
@@ -535,9 +504,24 @@
public ResultUtil aliPaymentSite(Double paymentPrice, SiteBooking siteBooking) throws Exception {
String code = siteBooking.getOrderNo();
Integer id = siteBooking.getId();
- ResultUtil alipay = payMoneyUtil.alipay("预约场地", "预约场地", id.toString(), code, paymentPrice.toString(), "/base/site/aliPaymentSiteCallback");
+ // 判断预约的门店 属于哪个运营商
+ Integer storeId = siteBooking.getStoreId();
+ Store byId = storeService.getById(storeId);
+ Integer operatorId = byId.getOperatorId();
+ String smid1 = "";
+ if (operatorId == null ){
+ // 平台的门店
+ smid1 = smid;
+ }else if (operatorId == 0){
+ smid1 = smid;
+ }else{
+ smid1 = siteService.getmerchantNumberAliByOperatorId(operatorId);
+
+ }
+ ResultUtil alipay = payMoneyUtil.alipay(smid1,"预约场地", "预约场地", id.toString(), code, paymentPrice.toString(), "/base/site/aliPaymentSiteCallback");
System.out.println("预约场地----" + alipay.getCode());
if (alipay.getCode() == 200) {
+ String finalSmid = smid1;
new Thread(new Runnable() {
@Override
public void run() {
@@ -574,6 +558,8 @@
siteBooking.setPayOrderNo(tradeNo);
siteBookingService.updateById(siteBooking);
System.err.println("======完成支付");
+ Thread.sleep(30000);
+ payMoneyUtil.confirm(finalSmid, code, tradeNo, paymentPrice.toString());
break;
}
if ("WAIT_BUYER_PAY".equals(s)) {
@@ -590,7 +576,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/hGLJ3A06cZxTQdviFC7THpdSihoTYGLr9q006hu0V26ecBMY/o4w5bvIX0Ok/yofmZsVcCJpAPvbXL/uqVrIjnRRxXiaeBFThlxoBUTdunvbUSDYfzlEhJr5NvUKI6H6lz2niXlQGx4qy8Hau4ccWit9kM8jwUvsBVQoFgJA+xrjMvooA7YLopQtpOD+UJr5thApTSf1xrnr1W12yolTLEH15JmNV372cqXrYUuqnY0QsaPtxeqJUGAOcGdVLllQ7easEznP8DFBvDdHATcmp2SHNQDUEWN6MCVPbMgY06NQVqAXxqjTAYSVh+6TRu6bofPmpYC3TZB003AgMBAAECggEBAJAcR2+PA3NBYUYHeFrqBRMS8uX8ZR19kjZ7IgoSLTFaQsP9opRylPSPXhrPVBKAE5leRQAHn4MCSlESwHvMfxo7KFjFTFA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IhWsvW1tEkQZCXmm7c9s/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("调用失败");
+ }
+ }
/**
* 玩湃币支付
*
@@ -654,7 +686,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) {
@@ -662,7 +694,6 @@
}
if (siteBooking.getStatus() == 0) {
-// return ResultUtil.error("请先进行支付");
siteBooking.setStatus(5);
siteBookingService.updateById(siteBooking);
AppUser appUser = appUserClient.queryAppUser(siteBooking.getAppUserId());
@@ -678,23 +709,39 @@
if (siteBooking.getStatus() != 1 && siteBooking.getStatus() != 2) {
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 (null == map) {
- return ResultUtil.error("取消退款异常");
- }
- String result_code = map.get("result_code");
- if (!"SUCCESS".equals(result_code)) {
- return ResultUtil.error(map.get("return_msg"));
- }
- siteBooking.setCancelUserId(uid);
- siteBookingService.updateById(siteBooking);
+ Integer storeId = siteBooking.getStoreId();
+ Store store = storeService.getById(storeId);
- TBackRecord tBackRecord = new TBackRecord();
- tBackRecord.setMoney(siteBooking.getPayMoney());
- tBackRecord.setUserId(siteBooking.getAppUserId());
- tBackRecord.setTime(new Date());
- backRecordService.save(tBackRecord);
+ if (siteBooking.getPayType() == 1) {//微信支付
+ if (store.getOperatorId()!=null && store.getOperatorId()!=0){
+ String smidVx= operatorUserService.getmerchantNumberByOperatorId(store.getOperatorId());
+ if (!StringUtils.hasLength(smidVx)){
+ return ResultUtil.error("运营商未配置微信商户号,获取支付失败!");
+ }
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
+ String code = sdf.format(new Date()) + UUIDUtil.getNumberRandom(5);// 退款单号
+ // 运营商退款
+ payMoneyUtil.weixinRefundV3(smidVx, code, siteBooking.getPayOrderNo(), siteBooking.getPayMoney().toString(), "/base/site/cancelMySiteCallback1");
+ }else{
+ 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 return_code = map.get("return_code");
+ if (!"SUCCESS".equals(return_code)) {
+ return ResultUtil.error(map.get("return_msg"));
+ }
+ siteBooking.setCancelUserId(uid);
+ siteBookingService.updateById(siteBooking);
+
+ TBackRecord tBackRecord = new TBackRecord();
+ tBackRecord.setMoney(siteBooking.getPayMoney());
+ tBackRecord.setUserId(siteBooking.getAppUserId());
+ tBackRecord.setTime(new Date());
+ backRecordService.save(tBackRecord);
+ }
+
}
if (siteBooking.getPayType() == 2) {//支付宝
@@ -894,4 +941,18 @@
return siteMapper.changeState(siteIds, type);
}
+
+ @Override
+ 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