1. update user-point
This commit is contained in:
2026-02-14 14:17:20 +08:00
parent 5ef97c4da7
commit a3752fe7b9
21 changed files with 300 additions and 182 deletions

View File

@@ -0,0 +1,80 @@
package org.springblade.job.processor;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.AllArgsConstructor;
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
import org.springblade.modules.common.service.ICommonUserPointService;
import org.springblade.modules.market.pojo.entity.MarketBenefitPointEntity;
import org.springblade.modules.market.pojo.entity.MarketCashCouponEntity;
import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
import org.springblade.modules.market.pojo.entity.MarketUserCommissionEntity;
import org.springblade.modules.market.service.IMarketBenefitPointService;
import org.springblade.modules.market.service.IMarketCashCouponService;
import org.springblade.modules.market.service.IMarketInfoService;
import org.springblade.modules.market.service.IMarketUserCommissionService;
import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Component;
import tech.powerjob.worker.core.processor.ProcessResult;
import tech.powerjob.worker.core.processor.TaskContext;
import tech.powerjob.worker.core.processor.sdk.BasicProcessor;
import java.util.List;
@Component
@AllArgsConstructor
public class InitUserAssetsProcessor implements BasicProcessor {
private final IUserService userService;
private final IMarketInfoService marketInfoService;
private final ICommonUserPointService userPointService;
private final IMarketCashCouponService cashCouponService;
private final IMarketBenefitPointService benefitPointService;
private final IMarketUserCommissionService commissionService;
@Override
public ProcessResult process(TaskContext taskContext) throws Exception {
List<User> userList = userService.list(Wrappers.<User>lambdaQuery().eq(User::getUserType, 2).eq(User::getIsDeleted, 0));
userList.forEach(user -> {
MarketInfoEntity marketInfo = marketInfoService.getById(user.getId());
if (marketInfo == null) {
marketInfo = new MarketInfoEntity();
marketInfo.setId(user.getId());
marketInfoService.save(marketInfo);
}
CommonUserPointEntity userPoint = userPointService.getById(user.getId());
if (userPoint == null) {
userPoint = new CommonUserPointEntity();
userPoint.setId(user.getId());
userPointService.save(userPoint);
}
MarketCashCouponEntity cashCoupon = cashCouponService.getById(user.getId());
if (cashCoupon == null) {
cashCoupon = new MarketCashCouponEntity();
cashCoupon.setId(user.getId());
cashCouponService.save(cashCoupon);
}
MarketBenefitPointEntity benefitPoint = benefitPointService.getById(user.getId());
if (benefitPoint == null) {
benefitPoint = new MarketBenefitPointEntity();
benefitPoint.setId(user.getId());
benefitPointService.save(benefitPoint);
}
MarketUserCommissionEntity commission = commissionService.getById(user.getId());
if (commission == null) {
commission = new MarketUserCommissionEntity();
commission.setId(user.getId());
commissionService.save(commission);
}
});
return new ProcessResult(true, "result is success");
}
}

View File

@@ -107,5 +107,11 @@ public class MarketUserController {
return R.status(marketUserManager.acquireBenefitPackage(request));
}
@GetMapping("/user-assets")
@ApiOperationSupport(order = 9)
@Operation(summary = "用户资产查询")
public R<UserAssetsApiVO> userAssets() {
return R.data(marketUserManager.userAssets());
}
}

View File

@@ -38,7 +38,7 @@ public class CommonUserNoticeApiVO implements Serializable {
private Long id;
private Integer moduleType;
private String moduleType;
/**
* 是否已读 0-否 1-是
*/

View File

@@ -0,0 +1,17 @@
package org.springblade.modules.api.vo;
import lombok.Data;
import java.io.Serializable;
import java.math.BigDecimal;
@Data
public class UserAssetsApiVO implements Serializable {
private BigDecimal withdrawableBalance; // 可提现余额
private BigDecimal benefitPoints; // 福利积分
private BigDecimal cashCouponAmount; // 现金券数量(或 List<CashCoupon>)
}

View File

@@ -6,15 +6,10 @@ import org.mapstruct.factory.Mappers;
import org.springblade.modules.api.request.AddressSubmitRequest;
import org.springblade.modules.api.request.CreateOrderRequest;
import org.springblade.modules.api.vo.*;
import org.springblade.modules.market.pojo.dto.MarketBenefitPointApiDTO;
import org.springblade.modules.market.pojo.dto.MarketCashCouponApiDTO;
import org.springblade.modules.common.pojo.dto.CommonUserPointApiDTO;
import org.springblade.modules.common.pojo.entity.*;
import org.springblade.modules.common.pojo.vo.AppCommonRegionsInfoVO;
import org.springblade.modules.common.pojo.vo.CommonUserOrderVO;
import org.springblade.modules.mall.pojo.entity.MallProductEntity;
import org.springblade.modules.market.pojo.entity.MarketBenefitPointLogEntity;
import org.springblade.modules.market.pojo.entity.MarketCashCouponLogEntity;
import java.util.List;
@@ -67,7 +62,4 @@ public interface AppCommonConvert {
CommonUserAddressEntity convertRequestToPo(AddressSubmitRequest request);
CommonUserPointLogEntity convertUserPointDTOToEntity(CommonUserPointApiDTO dto);
}

View File

@@ -0,0 +1,52 @@
package org.springblade.modules.common.eums;
import lombok.Getter;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Getter
public enum UserPointFlowType {
GRANT(1, "🎉 恭喜!您通过【订单 %s】成功获得 %s 积分,已存入您的账户,快去兑换好礼吧!") {
@Override
public String formatUserMessage(String orderId, String points) {
return String.format(this.getUserMessageTemplate(), orderId, points);
}
},
SPEND(2, "🎰 您已使用 %s 积分 参与幸运大抽奖,祝您好运连连,大奖抱回家!") {
@Override
public String formatUserMessage(String orderId, String points) {
// 注意:SPEND 不使用 orderId,但为了统一接口保留参数
return String.format(this.getUserMessageTemplate(), points);
}
};
private final int code;
private final String userMessageTemplate;
private UserPointFlowType(int code, String userMessageTemplate) {
this.code = code;
this.userMessageTemplate = userMessageTemplate;
}
public abstract String formatUserMessage(String orderId, String points);
private static final Map<Integer, UserPointFlowType> BY_CODE = Stream.of(values())
.collect(Collectors.toUnmodifiableMap(UserPointFlowType::getCode, Function.identity()));
public static UserPointFlowType fromCode(int code) {
UserPointFlowType status = BY_CODE.get(code);
if (status == null) {
throw new IllegalArgumentException("无效的订单状态码: " + code);
}
return status;
}
public static UserPointFlowType fromCodeOrNull(int code) {
return BY_CODE.get(code);
}
}

View File

@@ -0,0 +1,21 @@
package org.springblade.modules.common.event;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.springblade.modules.common.eums.BusinessModule;
import java.math.BigDecimal;
@AllArgsConstructor
@Getter
public class GrantUserPointEvent {
private final Long orderId;
private final Long userId;
private final BigDecimal point;
private final BusinessModule businessModule;
}

View File

@@ -4,6 +4,8 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.modules.common.eums.NoticeType;
import org.springblade.modules.common.eums.OrderStatus;
import org.springblade.modules.common.eums.UserPointFlowType;
import org.springblade.modules.common.event.GrantUserPointEvent;
import org.springblade.modules.common.event.PaymentSuccessEvent;
import org.springblade.modules.common.pojo.entity.CommonUserNoticeEntity;
import org.springblade.modules.common.service.ICommonUserNoticeService;
@@ -36,4 +38,22 @@ public class NoticeListener {
log.warn("支付事务回滚,orderId={}", event.getOrderId());
}
@Async
@TransactionalEventListener(phase = TransactionPhase.AFTER_COMMIT)
public void onGrantUserPoint(GrantUserPointEvent event) {
CommonUserNoticeEntity notice = new CommonUserNoticeEntity();
notice.setUserId(event.getUserId());
notice.setNoticeType(NoticeType.APP_USER.getCode());
notice.setModuleType(event.getBusinessModule().getCode());
notice.setTitle(event.getBusinessModule().getDisplayName());
notice.setContent(UserPointFlowType.GRANT.formatUserMessage(String.valueOf(event.getOrderId()), String.valueOf(event.getPoint())));
noticeService.save(notice);
}
@TransactionalEventListener(phase = TransactionPhase.AFTER_ROLLBACK)
public void onGrantUserPointFailure(GrantUserPointEvent event) {
log.warn("用户获取积分事务回滚,orderId={}", event.getOrderId());
}
}

View File

@@ -6,7 +6,7 @@
<resultMap id="userAddressResultMap" type="org.springblade.modules.common.pojo.entity.CommonUserAddressEntity">
<result column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="regions_info_id" property="regionsInfoId"/>
<result column="regions_id" property="regionsId"/>
<result column="province" property="province"/>
<result column="city" property="city"/>
<result column="district" property="district"/>

View File

@@ -1,41 +0,0 @@
package org.springblade.modules.common.pojo.dto;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springblade.modules.common.eums.BusinessModule;
import java.math.BigDecimal;
@Data
@Accessors(chain = true)
public class CommonUserPointApiDTO {
/**
* 用户id
*/
private Long userId;
/**
* 金额
*/
private BigDecimal amount;
/**
* 来源类型 0-商城订单 1-商城抽奖
*/
private BusinessModule sourceType;
/**
* 来源id
*/
private Long sourceId;
/**
* 来源详情
*/
private String sourceDetail;
/**
* 备注
*/
private String remark;
}

View File

@@ -34,6 +34,8 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springblade.core.mp.base.BaseEntity;
import java.io.Serializable;
import java.io.Serial;
@@ -46,18 +48,11 @@ import java.io.Serial;
@Data
@TableName("user_order")
@Schema(description = "Order对象")
public class CommonUserOrderEntity implements Serializable {
public class CommonUserOrderEntity extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@JsonSerialize(using = ToStringSerializer.class)
@Schema(description = "主键")
@TableId(value = "id", type = IdType.ASSIGN_ID)
private Long id;
/**
* 用户id
@@ -149,40 +144,5 @@ public class CommonUserOrderEntity implements Serializable {
*/
@Schema(description = "支付凭证编号")
private String paymentTrack;
/**
* 创建人
*/
@Schema(description = "创建人")
private Long createUser;
/**
* 创建部门
*/
@Schema(description = "创建部门")
private Long createDept;
/**
* 创建时间
*/
@Schema(description = "创建时间")
private Date createTime;
/**
* 修改人
*/
@Schema(description = "修改人")
private Long updateUser;
/**
* 修改时间
*/
@Schema(description = "修改时间")
private Date updateTime;
/**
* 状态
*/
@Schema(description = "状态")
private Integer status;
/**
*
*/
@Schema(description = "")
private Integer isDeleted;
}

View File

@@ -45,6 +45,7 @@ public class CommonUserPointLogEntity extends BaseEntity {
@Schema(description = "上一笔金额")
private BigDecimal lastAmount;
/**
*
* 来源类型
*/
@Schema(description = "来源类型")

View File

@@ -25,11 +25,14 @@
*/
package org.springblade.modules.common.service;
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
import org.springblade.modules.common.pojo.entity.CommonUserPointLogEntity;
import org.springblade.modules.common.pojo.vo.CommonUserPointLogVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import java.math.BigDecimal;
/**
* 用户商城积分流水表 服务类
*
@@ -40,11 +43,12 @@ public interface ICommonUserPointLogService extends BaseService<CommonUserPointL
/**
* 自定义分页
*
* @param page 分页参数
* @param page 分页参数
* @param commonUserPointLog 查询参数
* @return IPage<CommonUserPointLogVO>
*/
IPage<CommonUserPointLogVO> selectCommonUserPointLogPage(IPage<CommonUserPointLogVO> page, CommonUserPointLogVO commonUserPointLog);
Boolean recordPointChangeLog(CommonUserPointEntity commonUserPoint, BigDecimal lastAmount, String sourceType, BigDecimal amount, Integer type, Long sourceId, String sourceDetail);
}

View File

@@ -1,7 +1,7 @@
package org.springblade.modules.common.service;
import org.springblade.modules.common.pojo.dto.CommonUserPointApiDTO;
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
import org.springblade.modules.common.pojo.vo.CommonUserPointVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -25,23 +25,7 @@ public interface ICommonUserPointService extends BaseService<CommonUserPointEnti
*/
IPage<CommonUserPointVO> selectCommonUserPointPage(IPage<CommonUserPointVO> page, CommonUserPointVO commonUserPoint);
/**
* 添加商城积分
*
* @param dto 添加参数
* @return 操作结果
*/
Boolean addUserPoint(CommonUserPointApiDTO dto);
/**`
* 扣减商城积分
*
* @param dto 扣减参数
* @return 操作结果
*/
Boolean deductUserPoint(CommonUserPointApiDTO dto);
BigDecimal queryPoint();
void grantPointsByUserOrder(CommonUserOrderEntity order);
}

View File

@@ -47,6 +47,7 @@ import org.springblade.modules.common.pojo.vo.CommonUserOrderVO;
import org.springblade.modules.common.excel.CommonUserOrderExcel;
import org.springblade.modules.common.mapper.CommonUserOrderMapper;
import org.springblade.modules.common.service.ICommonUserOrderService;
import org.springblade.modules.common.service.ICommonUserPointService;
import org.springblade.modules.mall.pojo.entity.MallProductEntity;
import org.springblade.modules.mall.service.IMallProductService;
import org.springframework.context.ApplicationEventPublisher;
@@ -77,6 +78,8 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
private final ApplicationEventPublisher eventPublisher;
private final ICommonUserPointService userPointService;
@Override
public IPage<CommonUserOrderVO> selectOrderPage(IPage<CommonUserOrderVO> page, CommonUserOrderVO order) {
@@ -113,7 +116,7 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
order.setActualAmount(actualAmount);
order.setOrderType(orderType);
order.setPaymentType(request.getIsOfflinePayment() ? request.getPaymentType() : null);
save(order);
this.save(order);
yield new CreateOrderResponse(String.valueOf(order.getId()), actualAmount, totalAmount, discount);
}
case TRAVEL_GROUP -> {
@@ -125,10 +128,10 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
@Override
public PaymentResponse pay(PaymentRequest request) {
//todo先判断是否为线下支付,如果是线下支付则立即返回
CommonUserOrderEntity order = getById(Long.valueOf(request.getOrderId()));
Assert.notNull(order, "无效订单");
Assert.isTrue(order.getPaymentType() != 99, "线下订单不能重复支付");
//todo: 继续支付逻辑
return null;
}
@@ -152,12 +155,6 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
@Transactional(rollbackFor = Exception.class)
@RedisDebounce(key = "order:confirm", param = "#id", interval = 20, includeRemainingTime = true, message = "操作过于频繁")
public boolean confirmPayment(Long id) {
CommonUserOrderEntity order = getById(id);
if (order == null || order.getIsDeleted() == 1) {
return false;
}
boolean updated = update(Wrappers.<CommonUserOrderEntity>lambdaUpdate()
.set(CommonUserOrderEntity::getOrderStatus, OrderStatus.PAID.getCode())
.set(CommonUserOrderEntity::getPaymentStatus, PaymentStatus.PAID.getCode())
@@ -169,10 +166,18 @@ public class CommonUserOrderServiceImpl extends ServiceImpl<CommonUserOrderMappe
.eq(CommonUserOrderEntity::getIsDeleted, 0)
);
if (!updated) {
return false;
// 可能已被处理过,或状态不符 → 幂等返回 true(避免报错)
log.warn("订单 {} 无需处理或已处理", id);
return true; // ⭐ 幂等:已成功过就不要再失败
}
//todo:增加用户积分
CommonUserOrderEntity order = getById(id);
if (order == null) {
throw new IllegalStateException("订单更新成功但查询不到,id=" + id);
}
userPointService.grantPointsByUserOrder(order);
eventPublisher.publishEvent(new PaymentSuccessEvent(id, order.getUserId(), BusinessModule.SELF_OPERATED_MALL));
return true;
}

View File

@@ -1,5 +1,7 @@
package org.springblade.modules.common.service.impl;
import org.springblade.common.utils.date.DateUtil;
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
import org.springblade.modules.common.pojo.entity.CommonUserPointLogEntity;
import org.springblade.modules.common.pojo.vo.CommonUserPointLogVO;
import org.springblade.modules.common.mapper.CommonUserPointLogMapper;
@@ -8,6 +10,8 @@ import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import java.math.BigDecimal;
/**
* 用户商城积分流水表 服务实现类
*
@@ -22,6 +26,20 @@ public class CommonUserPointLogServiceImpl extends BaseServiceImpl<CommonUserPoi
return page.setRecords(baseMapper.selectCommonUserPointLogPage(page, commonUserPointLog));
}
@Override
public Boolean recordPointChangeLog(CommonUserPointEntity commonUserPoint, BigDecimal lastAmount, String sourceType, BigDecimal amount, Integer type, Long sourceId, String sourceDetail) {
CommonUserPointLogEntity userPointLog = new CommonUserPointLogEntity();
userPointLog.setType(type);
userPointLog.setUserId(commonUserPoint.getId());
userPointLog.setAmount(amount);
userPointLog.setSourceType(sourceType);
userPointLog.setSourceId(sourceId);
userPointLog.setSourceDetail(sourceDetail);
userPointLog.setIsComplete(1);
userPointLog.setStatisticalDate(DateUtil.getToday());
userPointLog.setLastAmount(lastAmount);
return save(userPointLog);
}
}

View File

@@ -1,24 +1,28 @@
package org.springblade.modules.common.service.impl;
import com.alibaba.fastjson2.JSON;
import io.jsonwebtoken.lang.Assert;
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.eums.BusinessModule;
import org.springblade.modules.common.eums.UserPointFlowType;
import org.springblade.modules.common.event.GrantUserPointEvent;
import org.springblade.modules.common.pojo.entity.CommonUserOrderEntity;
import org.springblade.modules.common.pojo.entity.CommonUserPointEntity;
import org.springblade.modules.common.pojo.entity.CommonUserPointLogEntity;
import org.springblade.modules.common.pojo.vo.CommonUserPointVO;
import org.springblade.modules.common.mapper.CommonUserPointMapper;
import org.springblade.modules.common.service.ICommonUserPointLogService;
import org.springblade.modules.common.service.ICommonUserPointService;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal;
import java.util.Date;
import static org.springblade.modules.common.eums.BusinessModule.SELF_OPERATED_MALL;
/**
* 用户积分表 服务实现类
@@ -33,66 +37,44 @@ public class CommonUserPointServiceImpl extends BaseServiceImpl<CommonUserPointM
private final ICommonUserPointLogService userPointLogService;
private final ApplicationEventPublisher eventPublisher;
@Override
public IPage<CommonUserPointVO> selectCommonUserPointPage(IPage<CommonUserPointVO> page, CommonUserPointVO commonUserPoint) {
return page.setRecords(baseMapper.selectCommonUserPointPage(page, commonUserPoint));
}
@Override
@Transactional(rollbackFor = Exception.class)
public Boolean addUserPoint(CommonUserPointApiDTO dto) {
CommonUserPointLogEntity userPointLog = AppCommonConvert.INSTANCE.convertUserPointDTOToEntity(dto);
userPointLog.setSourceType(dto.getSourceType().getCode());
userPointLog.setType(1);
userPointLog.setStatisticalDate(DateUtil.getToday());
userPointLog.setIsComplete(0);
if (!userPointLogService.save(userPointLog)) {
throw new RuntimeException("用户积分流水记录失败");
}
CommonUserPointEntity userPoint = getById(dto.getUserId());
if (baseMapper.addUserPoint(dto.getUserId(), dto.getAmount(), userPoint.getVersion()) <= 0
|| !userPointLogService.updateById(userPointLog.setIsComplete(1).setLastAmount(userPoint.getAmount()))
) {
log.error("增加用户积分失败, dto: [{}]", dto);
throw new RuntimeException("增加用户积分失败");
}
return Boolean.TRUE;
}
@Transactional(rollbackFor = RuntimeException.class)
@Override
public Boolean deductUserPoint(CommonUserPointApiDTO dto) {
CommonUserPointLogEntity userPointLog = AppCommonConvert.INSTANCE.convertUserPointDTOToEntity(dto);
userPointLog.setSourceType(dto.getSourceType().getCode());
userPointLog.setType(2);
userPointLog.setStatisticalDate(DateUtil.getToday());
userPointLog.setAmount(dto.getAmount().negate());
userPointLog.setIsComplete(0);
if (!userPointLogService.save(userPointLog)) {
throw new RuntimeException("用户积分流水记录失败");
}
CommonUserPointEntity userPoint = getById(dto.getUserId());
if (baseMapper.deductUserPoint(dto.getUserId(), dto.getAmount(), userPoint.getVersion()) <= 0
|| !userPointLogService.updateById(userPointLog.setIsComplete(1).setLastAmount(userPoint.getAmount()))
) {
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();
return userPoint.getAmount();
}
@Override
@Transactional(rollbackFor = Exception.class)
public void grantPointsByUserOrder(CommonUserOrderEntity order) {
Assert.notNull(order, "无效订单");
Assert.isTrue(order.getId() != null && order.getUserId() != null && order.getActualAmount() != null && order.getActualAmount().compareTo(BigDecimal.ZERO) > 0, "无效订单");
BigDecimal pointsAmount;
String sourceType;
switch (BusinessModule.fromCodeIgnoreCaseOrNull(order.getOrderType())) {
case SELF_OPERATED_MALL -> {
pointsAmount = order.getActualAmount().multiply(BigDecimal.valueOf(0.3));
sourceType = SELF_OPERATED_MALL.getCode();
}
default -> throw new RuntimeException("无效订单类型");
}
CommonUserPointEntity userPoint = getById(order.getUserId());
BigDecimal lastAmount = userPoint.getAmount();
int i = baseMapper.addUserPoint(order.getUserId(), pointsAmount, userPoint.getVersion());
if (i > 0) {
if (userPointLogService.recordPointChangeLog(userPoint, lastAmount, sourceType.toUpperCase(), pointsAmount, UserPointFlowType.GRANT.getCode(), order.getId(), JSON.toJSONString(order))) {
eventPublisher.publishEvent(new GrantUserPointEvent(order.getId(), order.getUserId(), pointsAmount, BusinessModule.fromCodeIgnoreCaseOrNull(sourceType)));
return;
}
}
throw new RuntimeException("奖励积分失败");
}
}

View File

@@ -9,7 +9,9 @@ import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.sensitive.SensitiveUtil;
import org.springblade.modules.api.request.AcquireBenefitPackageRequest;
import org.springblade.modules.api.vo.MarketDirectInfoApiVO;
import org.springblade.modules.api.vo.MarketPackageTemplateVO;
import org.springblade.modules.api.vo.UserAssetsApiVO;
import org.springblade.modules.market.convert.MarketUserMarketBenefitPackageConvert;
import org.springblade.modules.market.eums.MarketBusinessModule;
import org.springblade.modules.market.pojo.dto.MarketBenefitPointApiDTO;
@@ -40,6 +42,7 @@ public class MarketUserManager {
private final IMarketBenefitPointService marketBenefitPointService;
private final IMarketCashCouponService marketCashCouponService;
private final IMarketUserCommissionService commissionService;
public List<MarketDirectInfoApiVO> findUserPackList() {
Long userId = AuthUtil.getUserId();
@@ -250,5 +253,13 @@ public class MarketUserManager {
}
public UserAssetsApiVO userAssets() {
Long userId = AuthUtil.getUserId();
UserAssetsApiVO result= new UserAssetsApiVO();
result.setBenefitPoints(marketBenefitPointService.getById(userId).getAmount());
result.setCashCouponAmount(marketCashCouponService.getById(userId).getAmount());
result.setWithdrawableBalance(commissionService.getById(userId).getAmount());
return result;
}
}

View File

@@ -31,7 +31,7 @@ import com.baomidou.mybatisplus.annotation.TableName;
import java.math.BigDecimal;
import lombok.EqualsAndHashCode;
import org.springblade.core.tenant.mp.TenantEntity;
import org.springblade.core.mp.base.BaseEntity;
import java.io.Serial;
/**
@@ -44,7 +44,7 @@ import java.io.Serial;
@TableName("user_commission")
@Schema(description = "UserCommission对象")
@EqualsAndHashCode(callSuper = true)
public class MarketUserCommissionEntity extends TenantEntity {
public class MarketUserCommissionEntity extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;

View File

@@ -39,11 +39,13 @@ import org.springblade.modules.common.service.ICommonUserPointService;
import org.springblade.modules.market.pojo.entity.MarketBenefitPointEntity;
import org.springblade.modules.market.pojo.entity.MarketCashCouponEntity;
import org.springblade.modules.market.pojo.entity.MarketInfoEntity;
import org.springblade.modules.market.pojo.entity.MarketUserCommissionEntity;
import org.springblade.modules.market.pojo.vo.MarketInfoVO;
import org.springblade.modules.market.mapper.MarketInfoMapper;
import org.springblade.modules.market.service.IMarketBenefitPointService;
import org.springblade.modules.market.service.IMarketCashCouponService;
import org.springblade.modules.market.service.IMarketInfoService;
import org.springblade.modules.market.service.IMarketUserCommissionService;
import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service;
@@ -74,6 +76,8 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
private final IMarketBenefitPointService benefitPointService;
private final IMarketUserCommissionService commissionService;
@Override
public IPage<MarketInfoVO> selectMarketInfoPage(IPage<MarketInfoVO> page, MarketInfoVO marketInfo) {
@@ -92,7 +96,9 @@ public class MarketInfoServiceImpl extends BaseServiceImpl<MarketInfoMapper, Mar
cashCoupon.setId(user.getId());
MarketBenefitPointEntity benefitPoint = new MarketBenefitPointEntity();
benefitPoint.setId(user.getId());
if (save(info) && userPointService.save(userPoint) && cashCouponService.save(cashCoupon) && benefitPointService.save(benefitPoint)) {
MarketUserCommissionEntity commission = new MarketUserCommissionEntity();
commission.setId(user.getId());
if (save(info) && userPointService.save(userPoint) && cashCouponService.save(cashCoupon) && benefitPointService.save(benefitPoint) && commissionService.save(commission)) {
return true;
}
log.error("用户信息初始化失败,id: {}", user.getId());