会员充值/霸王餐支付 关联id问题

统一异常拦截 rootCause 值
CLIENT_LOGIC 与 USER_LOGIC 问题
This commit is contained in:
2026-01-21 10:17:09 +08:00
parent 45965fb426
commit 0549a077b2
11 changed files with 73 additions and 65 deletions

View File

@@ -19,6 +19,7 @@ import com.czg.utils.FunUtils;
import com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
@@ -114,7 +115,8 @@ public class UDistributionController {
try {
return CzgResult.success(distributionUserService.getInviteCode(shopId, shopUserId));
} catch (Exception e) {
log.error("获取邀请码失败用户:{}:{}", shopUserId, e.getMessage());
String rootMsg = NestedExceptionUtils.getMostSpecificCause(e).getMessage();
log.error("获取邀请码失败用户:{}:{}", shopUserId, rootMsg);
return CzgResult.success("");
}
}

View File

@@ -8,6 +8,7 @@ import com.czg.resp.CzgRespCode;
import com.czg.resp.CzgResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.support.DefaultMessageSourceResolvable;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.http.HttpStatus;
import org.springframework.http.converter.HttpMessageNotReadableException;
@@ -164,20 +165,23 @@ public class CzgControllerAdvice {
@ResponseStatus(HttpStatus.OK)
public CzgResult<Object> errorHandler(Exception ex) {
log.error("系统未处理异常", ex);
Throwable rootCause = ex;
while (rootCause.getCause() != null && !(rootCause instanceof CzgException)) {
rootCause = rootCause.getCause();
}
String rootMsg = NestedExceptionUtils.getMostSpecificCause(ex).getMessage();
return CzgResult.failure(CzgRespCode.FAILURE.getCode(), rootMsg);
// 2. 如果根因是CzgException直接抛出/返回该异常
if (rootCause instanceof CzgException exception) {
return CzgResult.failure(exception.getCode(), exception.getMsg());
}else if (rootCause instanceof ValidateException exception) {
return CzgResult.failure(exception.getStatus(), exception.getMessage());
}
// Throwable rootCause = ex;
// while (rootCause.getCause() != null && !(rootCause instanceof CzgException)) {
// rootCause = rootCause.getCause();
// }
//
// // 2. 如果根因是CzgException直接抛出/返回该异常
// if (rootCause instanceof CzgException exception) {
// return CzgResult.failure(exception.getCode(), exception.getMsg());
// }else if (rootCause instanceof ValidateException exception) {
// return CzgResult.failure(exception.getStatus(), exception.getMessage());
// }
// 3. 非业务异常,按原有逻辑处理
return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统错误,请联系管理员");
// return CzgResult.failure(CzgRespCode.SYSTEM_ERROR.getCode(), "系统错误,请联系管理员");
}
private void setErrorLog(Exception ex) {

View File

@@ -43,7 +43,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
userConfig.setIsShare(true);
// config2.setTimeout(2000);
userConfig.setTokenStyle("simple-uuid");
MyStpLogic.CLIENT_LOGIC.setConfig(userConfig);
MyStpLogic.USER_LOGIC.setConfig(userConfig);
}
@PostConstruct
@@ -62,18 +62,15 @@ public class SaTokenConfigure implements WebMvcConfigurer {
// 重置根路径防止satoken切割根路径导致匹配不到路径
ApplicationInfo.routePrefix = "";
SaRouter.match("/user/**").notMatch("/user/login", "/user/test", "/user/geo/**", "/user/home/**", "/user/home/**", "/user/dict/**", "/user/openId")
.notMatch("/pay/**")
.notMatch("/notify/**")
.check(r -> MyStpLogic.CLIENT_LOGIC.checkLogin())
SaRouter
.match("/user/**")
.notMatch("/user/login", "/user/geo/**", "/user/home/**", "/user/dict/**", "/user/openId")
.check(r -> MyStpLogic.USER_LOGIC.checkLogin())
.setHit(true)
// .match("/**")
.notMatch("/user/**")
.notMatch("/pay/**")
.notMatch("/notify/**")
.notMatch("/admin/auth/**")
.notMatch("/admin/shopMsgPush/subscribe/**")
.notMatch("/admin/coupon/grant")
.check(r -> {
ServletRequestAttributes attributes =
(ServletRequestAttributes) RequestContextHolder.getRequestAttributes();

View File

@@ -27,7 +27,7 @@ import java.util.function.Consumer;
@Slf4j
@Getter
public class MyStpLogic {
public static final StpLogic CLIENT_LOGIC = new StpLogic("client");
public static final StpLogic USER_LOGIC = new StpLogic("user");
public static final StpLogic ADMIN_LOGIC = new StpLogic("admin");
public Object isPC() {
@@ -42,7 +42,7 @@ public class MyStpLogic {
private StpLogic getLogic() {
boolean hit = SaRouter.match("/user/**").isHit();
if (hit) {
return CLIENT_LOGIC;
return USER_LOGIC;
}
return ADMIN_LOGIC;
}

View File

@@ -51,7 +51,7 @@ public interface MkDistributionUserService extends IService<MkDistributionUser>
/**
* 分销员中心-获取邀请码
*/
String getInviteCode(Long shopId, Long shopUserId) throws CzgException;
String getInviteCode(Long shopId, Long shopUserId) throws CzgException, ValidateException ;
/**
* 分销员中心-实名认证

View File

@@ -58,8 +58,13 @@ public class LtPayOtherDTO {
* 对应的记录Id 支付回调向该内容进行回填
* 积分商品为 mk_points_goods_record 主键id
* 团购商品为 gb_order_detail 主键id
*
*/
private Long recordId;
/**
* 霸王餐充值为 订单id 会员充值为 活动id
*/
private Long relatedId;
public void checkPayInfo(){
AssertUtil.isBlank(payType, "支付方式不能为空");

View File

@@ -38,7 +38,7 @@ public class FunUtils {
func.run();
} catch (Exception e) {
String message = NestedExceptionUtils.getMostSpecificCause(e).getMessage();
log.warn(msg.length > 0 ? msg[0] : "方法执行失败: {}", message);
log.warn((msg.length > 0 ? msg[0] : "方法执行失败") + ": " + message);
}
}

View File

@@ -198,7 +198,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
@Override
@Transactional(rollbackFor = Exception.class)
public String getInviteCode(Long shopId, Long shopUserId) {
public String getInviteCode(Long shopId, Long shopUserId) throws CzgException, ValidateException {
ShopUser shopUser = shopUserService.getById(shopUserId);
AssertUtil.isNull(shopUser, "店铺用户不存在");
MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId);
@@ -732,7 +732,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
/**
* 分销金额修改
*
* @param pendingIncome 待入账金额
* @param pendingIncome 待入账金额
* @param receivedIncome 已入账
* @param withdrawIncome 已提现
*/

View File

@@ -1066,10 +1066,27 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
// 分销奖励
distributionUserService.distribute(orderInfo.getId(), orderInfo.getOrderNo(), payment.getAmount(), orderInfo.getUserId(), orderInfo.getShopId(), "order");
}
} else if (PayTypeConstants.SourceType.MEMBER_IN.equals(payment.getSourceType()) || PayTypeConstants.SourceType.FREE.equals(payment.getSourceType())) {
boolean isFree = PayTypeConstants.SourceType.FREE.equals(payment.getSourceType());
} else if (PayTypeConstants.SourceType.FREE.equals(payment.getSourceType())) {
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
if (shopUser == null) {
log.error("霸王餐回调失败会员不存在会员id{}", payment.getSourceId());
} else {
OrderInfo orderInfo = orderInfoService.getOne(new QueryWrapper().eq(OrderInfo::getId, payment.getRelatedId()));
if (orderInfo == null) {
log.error("霸王餐支付订单不存在支付记录Id,{}", payment.getId());
} else {
//增加余额
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
.setId(shopUser.getId()).setType(1)
.setBizEnum(ShopUserFlowBizEnum.FREE_IN)
.setRelationId(orderInfo.getId())
.setMoney(BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN));
shopUserService.updateMoney(shopUserMoneyEditDTO);
upOrderInfo(orderInfo, BigDecimal.ZERO, LocalDateTime.now(), null, PayEnums.FREE_PAY);
}
}
} else if (PayTypeConstants.SourceType.MEMBER_IN.equals(payment.getSourceType())) {
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
OrderInfo orderInfo;
if (shopUser == null) {
log.error("会员充值失败会员不存在会员id{}", payment.getSourceId());
} else {
@@ -1081,42 +1098,22 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
} else {
bizEnum = ShopUserFlowBizEnum.CASH_IN;
}
if (isFree) {
orderInfo = orderInfoService.getOne(new QueryWrapper().eq(OrderInfo::getId, payment.getRelatedId()));
if (orderInfo == null) {
log.error("霸王餐支付订单不存在支付记录Id,{}", payment.getId());
} else {
//增加余额
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
.setId(shopUser.getId())
.setType(1)
.setBizEnum(ShopUserFlowBizEnum.FREE_IN)
.setRelationId(orderInfo.getId())
.setMoney(BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN));
shopUserService.updateMoney(shopUserMoneyEditDTO);
upOrderInfo(orderInfo, BigDecimal.ZERO,
LocalDateTime.now(), null, PayEnums.FREE_PAY);
}
} else {
//充值并支付 ↓
orderInfo = orderInfoService.getOne(new QueryWrapper()
.eq(OrderInfo::getPayOrderId, payment.getId())
.eq(OrderInfo::getPayType, PayEnums.VIP_PAY.getValue()));
if (orderInfo != null) {
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
.setId(shopUser.getId())
.setType(0)
.setBizEnum(ShopUserFlowBizEnum.ORDER_PAY)
.setRelationId(orderInfo.getId())
.setMoney(orderInfo.getOrderAmount());
shopUserService.updateMoney(shopUserMoneyEditDTO);
upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
LocalDateTime.now(), null, PayEnums.VIP_PAY);
}
shopRechargeService.recharge(payment.getShopId(), payment.getSourceId(), payment.getRelatedId(),
BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN),
payment.getId(), payment.getSourceType(), bizEnum, orderInfo == null);
//充值并支付 ↓
OrderInfo orderInfo = orderInfoService.getOne(new QueryWrapper()
.eq(OrderInfo::getPayOrderId, payment.getId())
.eq(OrderInfo::getPayType, PayEnums.VIP_PAY.getValue()));
if (orderInfo != null) {
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
.setId(shopUser.getId()).setType(0)
.setBizEnum(ShopUserFlowBizEnum.ORDER_PAY)
.setRelationId(orderInfo.getId())
.setMoney(orderInfo.getOrderAmount());
shopUserService.updateMoney(shopUserMoneyEditDTO);
upOrderInfo(orderInfo, orderInfo.getOrderAmount(), LocalDateTime.now(), null, PayEnums.VIP_PAY);
}
shopRechargeService.recharge(payment.getShopId(), payment.getSourceId(), payment.getRelatedId(),
BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN),
payment.getId(), payment.getSourceType(), bizEnum, orderInfo == null);
}
} else if (PayTypeConstants.SourceType.MEMBER_PAY.equals(payment.getSourceType())) {
//购买会员

View File

@@ -81,7 +81,7 @@ public class PayServiceImpl implements PayService {
AssertUtil.isBlank(param.getPayType(), "支付方式不能为空");
String payOrderNo = "LT" + IdUtil.getSnowflakeNextId();
initPayment(OrderPayment.pay(param.getShopId(), param.getRecordId(), payType, payOrderNo,
param.getPrice(), "", null));
param.getPrice(), "", param.getRelatedId()));
return pay(param.getShopId(), CzgPayEnum.LT_PAY,
CzgPayBaseReq.ltPayReq(payOrderNo, detail, param.getPrice().multiply(MONEY_RATE).longValue(),
param.getPayType(), param.getOpenId(), param.getIp()));

View File

@@ -159,6 +159,7 @@ public class ShopUserServiceImpl implements ShopUserPayService {
.setRecordId(shopUser.getId())
.setPrice(memberOrder.getAmount())
.setIp(clientIp);
payParam1.setRelatedId(memberOrder.getId());
return payService.ltPayOther(payParam1, PayTypeConstants.SourceType.MEMBER_PAY, "会员充值");
}
@@ -190,6 +191,7 @@ public class ShopUserServiceImpl implements ShopUserPayService {
.setRecordId(shopUser.getId())
.setPrice(payParam.getAmount())
.setIp(clintIp);
payParam1.setRelatedId(isFree ? payParam.getOrderId() : payParam.getRechargeDetailId());
return payService.ltPayOther(payParam1, payType, "会员充值");
}
@@ -216,6 +218,7 @@ public class ShopUserServiceImpl implements ShopUserPayService {
.setRecordId(shopUser.getId())
.setPrice(amount)
.setIp(clientIp);
payParam.setRelatedId(isFree ? rechargeDTO.getOrderId() : rechargeDTO.getRechargeDetailId());
return payService.ltPayOther(payParam, payType, "会员充值");
}