1. 用户积分查询
This commit is contained in:
2026-02-13 15:35:04 +08:00
parent b2839ed1d5
commit eddfc26a45
3 changed files with 36 additions and 14 deletions

View File

@@ -20,9 +20,11 @@ import org.springblade.modules.api.vo.*;
import org.springblade.modules.common.service.ICommonUserAddressService;
import org.springblade.modules.common.service.ICommonUserOrderService;
import org.springblade.modules.common.service.ICommonUserNoticeService;
import org.springblade.modules.common.service.ICommonUserPointService;
import org.springblade.modules.system.service.IUserService;
import org.springframework.web.bind.annotation.*;
import java.math.BigDecimal;
import java.util.List;
@Hidden
@@ -40,6 +42,8 @@ public class APPUserController {
private final ICommonUserAddressService addressService;
private final ICommonUserPointService pointService;
/**
* 是否修改过密码
@@ -158,7 +162,7 @@ public class APPUserController {
@ApiOperationSupport(order = 12)
@Operation(summary = "提交用户收货地址", description = "传入AddressSubmitRequest")
public R<Boolean> submitAddress(@Valid @RequestBody AddressSubmitRequest request) {
return R.status( addressService.submitAddress(request));
return R.status(addressService.submitAddress(request));
}
@@ -166,9 +170,15 @@ public class APPUserController {
@ApiOperationSupport(order = 13)
@Operation(summary = "删除用户收货地址", description = "传入id")
public R<Boolean> removeAddress(@Valid @RequestBody AddressRemoveRequest request) {
return R.status( addressService.removeAddress(request.getIds()));
return R.status(addressService.removeAddress(request.getIds()));
}
@GetMapping("/user-points")
@ApiOperationSupport(order = 14)
@Operation(summary = "用户积分查询")
public R<BigDecimal> userPoints() {
return R.data(pointService.queryPoint());
}
}

View File

@@ -7,6 +7,8 @@ import org.springblade.modules.common.pojo.vo.CommonUserPointVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import java.math.BigDecimal;
/**
* 用户商城积分表 服务类
*
@@ -39,4 +41,7 @@ public interface ICommonUserPointService extends BaseService<CommonUserPointEnti
* @return 操作结果
*/
Boolean deductUserPoint(CommonUserPointApiDTO dto);
BigDecimal queryPoint();
}

View File

@@ -3,6 +3,7 @@ package org.springblade.modules.common.service.impl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.utils.date.DateUtil;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.modules.common.convert.AppCommonConvert;
import org.springblade.modules.common.pojo.dto.CommonUserPointApiDTO;
import org.springblade.modules.common.pojo.entity.CommonCashCouponEntity;
@@ -43,7 +44,7 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
public Boolean addUserPoint(CommonUserPointApiDTO dto) {
CommonUserPointLogEntity userPointLog = saveBenefitPointLog(dto, 1);
CommonUserPointEntity userPoint = getById(dto.getUserId());
if (userPoint == null){
if (userPoint == null) {
userPoint = new CommonUserPointEntity();
userPoint.setId(dto.getUserId());
userPoint.setAmount(BigDecimal.ZERO);
@@ -52,10 +53,10 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
save(userPoint);
}
if (baseMapper.addUserPoint(dto.getUserId(), dto.getAmount() ,userPoint.getVersion()) <= 0
if (baseMapper.addUserPoint(dto.getUserId(), dto.getAmount(), userPoint.getVersion()) <= 0
|| !userPointLogService.updateById(userPointLog.setIsComplete(1).setLastAmount(userPoint.getAmount()))
){
log.error("增加商城积分失败, dto: [{}]" , dto);
) {
log.error("增加商城积分失败, dto: [{}]", dto);
throw new RuntimeException("增加商城积分失败");
}
@@ -67,7 +68,7 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
public Boolean deductUserPoint(CommonUserPointApiDTO dto) {
CommonUserPointLogEntity userPointLog = saveBenefitPointLog(dto, 2);
CommonUserPointEntity userPoint = getById(dto.getUserId());
if (userPoint == null){
if (userPoint == null) {
userPoint = new CommonUserPointEntity();
userPoint.setId(dto.getUserId());
userPoint.setAmount(BigDecimal.ZERO);
@@ -75,26 +76,32 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
userPoint.setCreateTime(new Date());
save(userPoint);
}
if (baseMapper.deductUserPoint(dto.getUserId(), dto.getAmount() ,userPoint.getVersion()) <= 0
if (baseMapper.deductUserPoint(dto.getUserId(), dto.getAmount(), userPoint.getVersion()) <= 0
|| !userPointLogService.updateById(userPointLog.setIsComplete(1).setLastAmount(userPoint.getAmount()))
){
log.error("扣除商城积分失败, dto: [{}]" , dto);
) {
log.error("扣除商城积分失败, dto: [{}]", dto);
throw new RuntimeException("扣除商城积分失败");
}
return Boolean.TRUE;
}
@Override
public BigDecimal queryPoint() {
CommonUserPointEntity userPoint = getById(AuthUtil.getUserId());
return userPoint == null ? BigDecimal.ZERO : userPoint.getAmount();
}
private CommonUserPointLogEntity saveBenefitPointLog(CommonUserPointApiDTO dto , Integer type){
CommonUserPointLogEntity userPointLog = AppCommonConvert.INSTANCE.convertUserPointDTOToEntity(dto);
private CommonUserPointLogEntity saveBenefitPointLog(CommonUserPointApiDTO dto, Integer type) {
CommonUserPointLogEntity userPointLog = AppCommonConvert.INSTANCE.convertUserPointDTOToEntity(dto);
userPointLog.setSourceType(dto.getSourceType().getCode());
userPointLog.setType(type);
userPointLog.setStatisticalDate(DateUtil.getToday());
if (type == 2){
if (type == 2) {
userPointLog.setAmount(dto.getAmount().negate());
}
if (!userPointLogService.save(userPointLog)){
if (!userPointLogService.save(userPointLog)) {
throw new RuntimeException("商城积分流水记录失败");
}