会员积分代码提交

This commit is contained in:
Tankaikai
2025-03-05 17:14:36 +08:00
parent e5d6bd058d
commit a0bc070395
4 changed files with 26 additions and 35 deletions

View File

@@ -13,7 +13,6 @@ import com.czg.account.service.MemberPointsService;
import com.czg.enums.YesNoEnum;
import com.czg.exception.CzgException;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderInfoService;
import com.czg.sa.StpKit;
import com.czg.service.account.mapper.MemberPointsLogMapper;
import com.czg.service.account.mapper.MemberPointsMapper;
@@ -23,7 +22,6 @@ import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -44,8 +42,6 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
private PointsBasicSettingMapper pointsBasicSettingMapper;
@Resource
private MemberPointsLogMapper memberPointsLogMapper;
@DubboReference
private OrderInfoService orderInfoService;
private QueryWrapper buildQueryWrapper(MemberPointsParam param) {
QueryWrapper queryWrapper = PageUtil.buildSortQueryWrapper();
@@ -190,7 +186,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
}
@Override
public boolean deductPoints(Long userId, int points, String content, Long orderId) {
public boolean deductPoints(Long userId, int points, String content, OrderInfo orderInfo) {
MemberPoints entity = initMemberPoints(userId);
// 扣除账户积分
entity.setAccountPoints(entity.getAccountPoints() - points);
@@ -205,12 +201,9 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
log.setFloatType("subtract");
log.setFloatPoints(-points);
// 有关联订单的需要回置订单表的相关积分使用字段
if (orderId != null) {
OrderInfo orderInfo = orderInfoService.getById(orderId);
if (orderInfo != null) {
log.setOrderNo(orderInfo.getOrderNo());
// TODO 是否需要回执“使用的积分数量(points_num)”和“积分抵扣金额(points_discount_amount)”,目前不清楚是创建订单的时候置入还是支付完成后回调时置入需要商议后决定
}
if (orderInfo != null) {
log.setOrderNo(orderInfo.getOrderNo());
// TODO 是否需要回执“使用的积分数量(points_num)”和“积分抵扣金额(points_discount_amount)”,目前不清楚是创建订单的时候置入还是支付完成后回调时置入需要商议后决定
}
super.updateById(entity);
memberPointsLogMapper.insert(log);
@@ -219,7 +212,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
@Override
@Transactional(rollbackFor = Exception.class)
public boolean addPoints(Long userId, int points, String content, Long orderId) {
public boolean addPoints(Long userId, int points, String content, OrderInfo orderInfo) {
MemberPoints entity = initMemberPoints(userId);
// 增加账户积分
entity.setAccountPoints(entity.getAccountPoints() + points);
@@ -233,11 +226,8 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
log.setFloatType("add");
log.setFloatPoints(points);
// 有关联订单的需要回置订单表的相关积分使用字段
if (orderId != null) {
OrderInfo orderInfo = orderInfoService.getById(orderId);
if (orderInfo != null) {
log.setOrderNo(orderInfo.getOrderNo());
}
if (orderInfo != null) {
log.setOrderNo(orderInfo.getOrderNo());
}
super.updateById(entity);
memberPointsLogMapper.insert(log);
@@ -246,8 +236,7 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
@Override
@Transactional(rollbackFor = Exception.class)
public void consumeAwardPoints(Long userId, Long orderId) {
OrderInfo orderInfo = orderInfoService.getById(orderId);
public void consumeAwardPoints(Long userId, OrderInfo orderInfo) {
if (orderInfo == null) {
throw new CzgException("订单不存在");
}
@@ -282,6 +271,6 @@ public class MemberPointsServiceImpl extends ServiceImpl<MemberPointsMapper, Mem
return;
}
BigDecimal awardPoints = NumberUtil.roundDown(NumberUtil.div(payAmount, consumeAmount), 0);
addPoints(userId, awardPoints.intValue(), StrUtil.format("消费¥{}送{}积分", payAmount, awardPoints.intValue()), orderId);
addPoints(userId, awardPoints.intValue(), StrUtil.format("消费¥{}送{}积分", payAmount, awardPoints.intValue()), orderInfo);
}
}