会员充值/霸王餐支付 关联id问题
统一异常拦截 rootCause 值 CLIENT_LOGIC 与 USER_LOGIC 问题
This commit is contained in:
@@ -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("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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) {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 ;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 分销员中心-实名认证
|
* 分销员中心-实名认证
|
||||||
|
|||||||
@@ -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, "支付方式不能为空");
|
||||||
|
|||||||
@@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
@@ -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,43 +1098,23 @@ 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()));
|
|
||||||
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()
|
OrderInfo orderInfo = orderInfoService.getOne(new QueryWrapper()
|
||||||
.eq(OrderInfo::getPayOrderId, payment.getId())
|
.eq(OrderInfo::getPayOrderId, payment.getId())
|
||||||
.eq(OrderInfo::getPayType, PayEnums.VIP_PAY.getValue()));
|
.eq(OrderInfo::getPayType, PayEnums.VIP_PAY.getValue()));
|
||||||
if (orderInfo != null) {
|
if (orderInfo != null) {
|
||||||
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
ShopUserMoneyEditDTO shopUserMoneyEditDTO = new ShopUserMoneyEditDTO()
|
||||||
.setId(shopUser.getId())
|
.setId(shopUser.getId()).setType(0)
|
||||||
.setType(0)
|
|
||||||
.setBizEnum(ShopUserFlowBizEnum.ORDER_PAY)
|
.setBizEnum(ShopUserFlowBizEnum.ORDER_PAY)
|
||||||
.setRelationId(orderInfo.getId())
|
.setRelationId(orderInfo.getId())
|
||||||
.setMoney(orderInfo.getOrderAmount());
|
.setMoney(orderInfo.getOrderAmount());
|
||||||
shopUserService.updateMoney(shopUserMoneyEditDTO);
|
shopUserService.updateMoney(shopUserMoneyEditDTO);
|
||||||
upOrderInfo(orderInfo, orderInfo.getOrderAmount(),
|
upOrderInfo(orderInfo, orderInfo.getOrderAmount(), LocalDateTime.now(), null, PayEnums.VIP_PAY);
|
||||||
LocalDateTime.now(), null, PayEnums.VIP_PAY);
|
|
||||||
}
|
}
|
||||||
shopRechargeService.recharge(payment.getShopId(), payment.getSourceId(), payment.getRelatedId(),
|
shopRechargeService.recharge(payment.getShopId(), payment.getSourceId(), payment.getRelatedId(),
|
||||||
BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN),
|
BigDecimal.valueOf(notifyRespDTO.getAmount()).divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN),
|
||||||
payment.getId(), payment.getSourceType(), bizEnum, orderInfo == null);
|
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())) {
|
||||||
//购买会员
|
//购买会员
|
||||||
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
ShopUser shopUser = shopUserService.getById(payment.getSourceId());
|
||||||
|
|||||||
@@ -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()));
|
||||||
|
|||||||
@@ -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, "会员充值");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user