Compare commits

9 Commits

Author SHA1 Message Date
0549a077b2 会员充值/霸王餐支付 关联id问题
统一异常拦截 rootCause 值
CLIENT_LOGIC 与 USER_LOGIC 问题
2026-01-21 10:17:09 +08:00
45965fb426 异常信息尝试获取 2026-01-20 18:25:02 +08:00
034a8c4650 报错 2026-01-20 17:51:39 +08:00
4cd71ad35a 兼容 2026-01-20 17:43:36 +08:00
64830203f3 详细日志 2026-01-20 17:39:39 +08:00
c542f18938 获取邀请码 失败的问题日志 2026-01-20 15:44:08 +08:00
cc40a8a7f0 不报错 获取邀请码 2026-01-20 15:13:22 +08:00
f10bafce52 Merge branch 'prod' into test 2026-01-20 14:49:54 +08:00
3e42b534e0 台桌排序
分享绑定
2026-01-20 10:19:33 +08:00
12 changed files with 113 additions and 76 deletions

View File

@@ -15,8 +15,11 @@ import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.task.DistributionTask;
import com.czg.utils.AssertUtil;
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.*;
@@ -27,6 +30,7 @@ import java.util.Map;
*
* @author Administrator
*/
@Slf4j
@RestController
@RequestMapping("/user/distribution")
public class UDistributionController {
@@ -103,6 +107,20 @@ public class UDistributionController {
return CzgResult.success(distributionUserService.getInviteCode(shopId, shopUserId));
}
/**
* 分销员中心-获取邀请码
*/
@GetMapping("/autoGetInviteCode")
public CzgResult<String> autoGetInviteCode(@RequestParam Long shopId, @RequestParam Long shopUserId) {
try {
return CzgResult.success(distributionUserService.getInviteCode(shopId, shopUserId));
} catch (Exception e) {
String rootMsg = NestedExceptionUtils.getMostSpecificCause(e).getMessage();
log.error("获取邀请码失败用户:{}:{}", shopUserId, rootMsg);
return CzgResult.success("");
}
}
/**
* 分销员中心-实名认证
*/
@@ -115,6 +133,19 @@ public class UDistributionController {
return CzgResult.success();
}
/**
* 分销员中心-无感-绑定邀请人
*/
@PostMapping("/autoBindInviteUser")
public CzgResult<Map<String, Object>> autoBindInviteUser(@RequestBody MkDistributionUserDTO param) {
AssertUtil.isNull(param.getId(), "店铺用户ID不能为空");
AssertUtil.isNull(param.getShopId(), "店铺ID不能为空");
AssertUtil.isNull(param.getInviteCode(), "邀请码不能为空");
FunUtils.asyncSafeRunVoid(() -> distributionUserService.bindInviteUser(param), "无感绑定上级");
return CzgResult.success();
}
/**
* 分销员中心-绑定邀请人
*/
@@ -172,10 +203,7 @@ public class UDistributionController {
/**
* 收益明细
*
* @param startTime
* @param endTime
* @param shopId
* @param status pending待入账 success已入账
* @param status pending待入账 success已入账
*/
@GetMapping("/distributionFlow")
public CzgResult<Map<String, Object>> distributionFlow(@RequestParam(required = false) String startTime, @RequestParam(required = false) String endTime,

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);
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

@@ -3,6 +3,7 @@ package com.czg.utils;
import cn.hutool.core.lang.func.Func0;
import cn.hutool.core.thread.ThreadUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.NestedExceptionUtils;
import org.springframework.transaction.support.TransactionSynchronization;
import org.springframework.transaction.support.TransactionSynchronizationManager;
@@ -27,11 +28,17 @@ public class FunUtils {
return value;
}
public static void asyncSafeRunVoid(Runnable func, String... msg) {
ThreadUtil.execAsync(() -> safeRunVoid(func, msg));
}
public static void safeRunVoid(Runnable func, String... msg) {
try {
func.run();
} catch (Exception e) {
log.warn(msg.length > 0 ? msg[0] : "方法执行失败: {}", e.getMessage());
String message = NestedExceptionUtils.getMostSpecificCause(e).getMessage();
log.warn((msg.length > 0 ? msg[0] : "方法执行失败") + ": " + message);
}
}
@@ -43,10 +50,6 @@ public class FunUtils {
}
}
public static void asyncSafeRunVoid(Runnable func, String... msg) {
ThreadUtil.execAsync(() -> safeRunVoid(func, msg));
}
/**
* 在事务提交后执行方法
* 异步 执行

View File

@@ -27,7 +27,7 @@
and a.table_code is not null
</if>
group by a.id
ORDER BY a.create_time
ORDER BY a.area_id,a.id
</select>
</mapper>

View File

@@ -198,18 +198,18 @@ 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);
if (mkDistributionConfigVO == null || mkDistributionConfigVO.getIsEnable() == 0) {
throw new CzgException("店铺分销功能未开启");
}
if (!"auto".equals(mkDistributionConfigVO.getOpenType())) {
throw new CzgException("该店铺不可自行成为分销员");
}
MkDistributionUser mkDistributionUser = getMkDistributionUserByIdAndShopId(shopUser.getId(), shopId);
if (mkDistributionUser == null) {
if (!"auto".equals(mkDistributionConfigVO.getOpenType())) {
throw new CzgException("该店铺不可自行成为分销员");
}
mkDistributionUser = new MkDistributionUser();
mkDistributionUser.setId(shopUser.getId());
mkDistributionUser.setShopId(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, "会员充值");
}