会员充值/霸王餐支付 关联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 com.mybatisflex.core.paginate.Page;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@@ -114,7 +115,8 @@ public class UDistributionController {
try { try {
return CzgResult.success(distributionUserService.getInviteCode(shopId, shopUserId)); return CzgResult.success(distributionUserService.getInviteCode(shopId, shopUserId));
} catch (Exception e) { } catch (Exception e) {
log.error("获取邀请码失败用户:{}:{}", shopUserId, e.getMessage()); String rootMsg = NestedExceptionUtils.getMostSpecificCause(e).getMessage();
log.error("获取邀请码失败用户:{}:{}", shopUserId, rootMsg);
return CzgResult.success(""); return CzgResult.success("");
} }
} }

View File

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

View File

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

View File

@@ -27,7 +27,7 @@ import java.util.function.Consumer;
@Slf4j @Slf4j
@Getter @Getter
public class MyStpLogic { 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 static final StpLogic ADMIN_LOGIC = new StpLogic("admin");
public Object isPC() { public Object isPC() {
@@ -42,7 +42,7 @@ public class MyStpLogic {
private StpLogic getLogic() { private StpLogic getLogic() {
boolean hit = SaRouter.match("/user/**").isHit(); boolean hit = SaRouter.match("/user/**").isHit();
if (hit) { if (hit) {
return CLIENT_LOGIC; return USER_LOGIC;
} }
return ADMIN_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 支付回调向该内容进行回填 * 对应的记录Id 支付回调向该内容进行回填
* 积分商品为 mk_points_goods_record 主键id * 积分商品为 mk_points_goods_record 主键id
* 团购商品为 gb_order_detail 主键id * 团购商品为 gb_order_detail 主键id
*
*/ */
private Long recordId; private Long recordId;
/**
* 霸王餐充值为 订单id 会员充值为 活动id
*/
private Long relatedId;
public void checkPayInfo(){ public void checkPayInfo(){
AssertUtil.isBlank(payType, "支付方式不能为空"); AssertUtil.isBlank(payType, "支付方式不能为空");

View File

@@ -38,7 +38,7 @@ public class FunUtils {
func.run(); func.run();
} catch (Exception e) { } catch (Exception e) {
String message = NestedExceptionUtils.getMostSpecificCause(e).getMessage(); 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 @Override
@Transactional(rollbackFor = Exception.class) @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); ShopUser shopUser = shopUserService.getById(shopUserId);
AssertUtil.isNull(shopUser, "店铺用户不存在"); AssertUtil.isNull(shopUser, "店铺用户不存在");
MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId); MkDistributionConfigVO mkDistributionConfigVO = mkDistributionConfigService.detail(shopId);
@@ -732,7 +732,7 @@ public class MkDistributionUserServiceImpl extends ServiceImpl<MkDistributionUse
/** /**
* 分销金额修改 * 分销金额修改
* *
* @param pendingIncome 待入账金额 * @param pendingIncome 待入账金额
* @param receivedIncome 已入账 * @param receivedIncome 已入账
* @param withdrawIncome 已提现 * @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"); 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())) { } else if (PayTypeConstants.SourceType.FREE.equals(payment.getSourceType())) {
boolean isFree = 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()); ShopUser shopUser = shopUserService.getById(payment.getSourceId());
OrderInfo orderInfo;
if (shopUser == null) { if (shopUser == null) {
log.error("会员充值失败会员不存在会员id{}", payment.getSourceId()); log.error("会员充值失败会员不存在会员id{}", payment.getSourceId());
} else { } else {
@@ -1081,42 +1098,22 @@ public class OrderInfoCustomServiceImpl implements OrderInfoCustomService {
} else { } else {
bizEnum = ShopUserFlowBizEnum.CASH_IN; bizEnum = ShopUserFlowBizEnum.CASH_IN;
} }
if (isFree) { //充值并支付 ↓
orderInfo = orderInfoService.getOne(new QueryWrapper().eq(OrderInfo::getId, payment.getRelatedId())); OrderInfo orderInfo = orderInfoService.getOne(new QueryWrapper()
if (orderInfo == null) { .eq(OrderInfo::getPayOrderId, payment.getId())
log.error("霸王餐支付订单不存在支付记录Id,{}", payment.getId()); .eq(OrderInfo::getPayType, PayEnums.VIP_PAY.getValue()));
} else { if (orderInfo != null) {
//增加余额 ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO() .setId(shopUser.getId()).setType(0)
.setId(shopUser.getId()) .setBizEnum(ShopUserFlowBizEnum.ORDER_PAY)
.setType(1) .setRelationId(orderInfo.getId())
.setBizEnum(ShopUserFlowBizEnum.FREE_IN) .setMoney(orderInfo.getOrderAmount());
.setRelationId(orderInfo.getId()) shopUserService.updateMoney(shopUserMoneyEditDTO);
.setMoney(BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN)); upOrderInfo(orderInfo, orderInfo.getOrderAmount(), LocalDateTime.now(), null, PayEnums.VIP_PAY);
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);
} }
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())) { } else if (PayTypeConstants.SourceType.MEMBER_PAY.equals(payment.getSourceType())) {
//购买会员 //购买会员

View File

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

View File

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