|
|
@@ -91,6 +91,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
private final WashOrderService washOrderService;
|
|
|
private final MpMsgTemplateService mpMsgTemplateService;
|
|
|
private final RechargePromotionService rechargePromotionService;
|
|
|
+ private final UserService userService;
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -105,7 +106,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
ActivityService activityService,
|
|
|
RechargeConfigService rechargeConfigService, SplitRecordService splitRecordService,
|
|
|
WashOrderService washOrderService, MpMsgTemplateService mpMsgTemplateService,
|
|
|
- RechargePromotionService rechargePromotionService) {
|
|
|
+ RechargePromotionService rechargePromotionService,
|
|
|
+ UserService userService) {
|
|
|
this.conf = conf;
|
|
|
this.walletDetailService = walletDetailService;
|
|
|
this.payLogService = payLogService;
|
|
|
@@ -116,6 +118,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
this.washOrderService = washOrderService;
|
|
|
this.mpMsgTemplateService = mpMsgTemplateService;
|
|
|
this.rechargePromotionService = rechargePromotionService;
|
|
|
+ this.userService = userService;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -214,7 +217,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public PrepayWithRequestPaymentResponse wxPay(Long rechargeConfigId, String stationId) {
|
|
|
+ public PrepayWithRequestPaymentResponse wxPay(Long rechargeConfigId) {
|
|
|
// 充值配置
|
|
|
var rechargeConfig = rechargeConfigService.getById(rechargeConfigId);
|
|
|
|
|
|
@@ -225,6 +228,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
var rechargeAmount = rechargeConfig.getRechargeAmount();
|
|
|
var openid = StpUtil.getSession().getString("openid");
|
|
|
var userId = StpUtil.getLoginIdAsLong();
|
|
|
+ // 充值归属站点以服务端用户归属为准,不信任客户端传值(防止分账归属被篡改)
|
|
|
+ var stationId = getUserStationId(userId);
|
|
|
// 生成订单号
|
|
|
String outTradeNo = OrderUtils.getOrderNo();
|
|
|
// 创建钱包流水
|
|
|
@@ -262,7 +267,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
*/
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public PrepayWithRequestPaymentResponse promotionPay(String promotionToken, String stationId) {
|
|
|
+ public PrepayWithRequestPaymentResponse promotionPay(String promotionToken) {
|
|
|
var promotion = rechargePromotionService.getByToken(promotionToken);
|
|
|
if (promotion == null) {
|
|
|
throw new BusinessException("优惠活动不存在或已过期");
|
|
|
@@ -274,6 +279,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
}
|
|
|
|
|
|
var openid = StpUtil.getSession().getString("openid");
|
|
|
+ // 充值归属站点以服务端用户归属为准,不信任客户端传值(防止分账归属被篡改)
|
|
|
+ var stationId = getUserStationId(userId);
|
|
|
var outTradeNo = OrderUtils.getOrderNo();
|
|
|
|
|
|
var walletDetail = new WalletDetail()
|
|
|
@@ -315,6 +322,18 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
return jsapiService.queryOrderById(request);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 服务端获取用户归属站点(KymCache 优先,未命中查库兜底),用于充值分账归属
|
|
|
+ */
|
|
|
+ private String getUserStationId(Long userId) {
|
|
|
+ var stationId = KymCache.INSTANCE.getUserStationId(userId);
|
|
|
+ if (stationId == null) {
|
|
|
+ var user = userService.getById(userId);
|
|
|
+ stationId = user != null ? user.getStationId() : null;
|
|
|
+ }
|
|
|
+ return stationId;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 关闭订单
|
|
|
*
|