From 22be02314dae32d2fcfa2f3f31e7213cbbca5260 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 15 一月 2025 15:34:49 +0800
Subject: [PATCH] 修改bug
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java | 217 +++++++++++++++++++++++++++--------------------------
1 files changed, 110 insertions(+), 107 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
index 2e58044..b56c623 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
@@ -2,12 +2,14 @@
import cn.hutool.core.collection.CollectionUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
+import com.baomidou.mybatisplus.extension.conditions.query.QueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.api.model.UserPoint;
-import com.ruoyi.account.enums.PointChangeType;
import com.ruoyi.account.mapper.UserPointMapper;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.PointSettingService;
@@ -16,22 +18,26 @@
import com.ruoyi.account.vo.UserPointDetailVO;
import com.ruoyi.account.vo.UserPointStatistics;
import com.ruoyi.account.vo.UserPointVO;
+import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.core.utils.PhoneNumberValidator;
-import com.ruoyi.common.core.utils.StringUtils;
+import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.PointSetting;
import com.ruoyi.other.api.domain.VipSetting;
+import com.ruoyi.other.api.enums.PointChangeType;
import com.ruoyi.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
-import java.util.*;
+import java.time.format.DateTimeFormatter;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -54,52 +60,66 @@
@Resource
private PointSettingService pointSettingService;
@Resource
- private UserPointMapper userPointMapper;
+ private UserPointService userPointService;
+
+
+
@Override
public UserPointVO getUserPoint(Long userId) {
AppUser appUser = appUserService.getById(userId);
- List<UserPoint> userPointList = this.baseMapper.findLatestUserPointByTypeForUser(userId);
- Map<Integer, Integer> userBalanceMap = userPointList.stream()
- .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance));
VipSetting vipSetting = vipSettingService.getVipSettingByUserId(userId);
UserPointVO userPointVO = new UserPointVO();
- userPointVO.setTotalPoint(appUser.getTotalPoint());
- userPointVO.setConsumePoint(appUser.getLavePoint());
+ // todo bug说取剩余积分
+ userPointVO.setTotalPoint(appUser.getLavePoint());
+ userPointVO.setConsumePoint(appUser.getAvailablePoint());
userPointVO.setShopPoint(appUser.getShopPoint());
userPointVO.setSharePoint(appUser.getSharePoint());
- userPointVO.setPullNewPoint(userBalanceMap.get(PointChangeType.NEW_USER_REFERRAL.getCode()));
- userPointVO.setShopAchievementPoint(userBalanceMap.get(PointChangeType.STORE_PERFORMANCE.getCode()));
- userPointVO.setShopSharePoint(userBalanceMap.get(PointChangeType.STORE_COMMISSION_RETURN.getCode()));
- userPointVO.setGiftPoint(vipSetting.getVipGiftRole() == 1 && vipSetting.getId() == 1 ? 1 : 0);
+ userPointVO.setPullNewPoint(appUser.getTotalInvitePoint());
+ userPointVO.setShopAchievementPoint(appUser.getShopAchievementPoint());
+ userPointVO.setShopSharePoint(appUser.getShopSharePoint());
+ userPointVO.setGiftPoint(vipSetting.getVipGiftRole() == 1 ? 1 : 0);
return userPointVO;
}
@Override
- public List<UserPointDetailVO> getUserPointDetail(Long userId, LocalDateTime startTime, LocalDateTime endTime, Integer type) {
- List<UserPoint> userPointList = list(new LambdaQueryWrapper<UserPoint>()
- .between(startTime != null, UserPoint::getCreateTime, startTime, endTime)
- .eq(type != null, UserPoint::getType, type)
- .eq(UserPoint::getAppUserId, userId));
- if (CollectionUtil.isNotEmpty(userPointList)) {
- return userPointList.stream().map(p -> {
+ public PageInfo<UserPointDetailVO> getUserPointDetail(Long userId, LocalDateTime startTime, LocalDateTime endTime, Integer type, Integer pageCurr, Integer pageSize) {
+ PageInfo<UserPoint> pageInfo = new PageInfo<>(pageCurr, pageSize);
+ PageInfo<UserPoint> page = this.page(pageInfo, new QueryWrapper<UserPoint>()
+ .between(startTime != null, "create_time", startTime, endTime)
+ .eq(type != null, "type", type)
+ .eq("app_user_id", userId).orderByDesc("create_time"));
+ if (CollectionUtil.isNotEmpty(page.getRecords())) {
+ List<UserPointDetailVO> collect = page.getRecords().stream().map(p -> {
UserPointDetailVO userPointDetailVO = new UserPointDetailVO();
userPointDetailVO.setType(p.getType());
userPointDetailVO.setVariablePoint(p.getVariablePoint());
- userPointDetailVO.setCreateTime(p.getCreateTime());
+ String format = p.getCreateTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
+ userPointDetailVO.setCreateTime(format);
+ Integer historicalPoint = p.getHistoricalPoint();
+ Integer balance = p.getBalance();
+ if (historicalPoint != null && balance != null) {
+ userPointDetailVO.setFlag(historicalPoint > balance ? 2 : 1);
+ }
return userPointDetailVO;
}).collect(Collectors.toList());
+ PageInfo<UserPointDetailVO> pageInfo1 = new PageInfo<>(pageCurr, pageSize);
+ pageInfo1.setRecords(collect);
+ pageInfo1.setTotal(page.getTotal());
+ pageInfo1.setCurrent(page.getCurrent());
+ pageInfo1.setSize(page.getSize());
+ return pageInfo1;
}
- return Collections.emptyList();
+ return null;
}
@Override
@Transactional
- public void transferPoint(BigDecimal point, String phone) {
+ public R transferPoint(Integer point, String phone) {
if (!PhoneNumberValidator.isValidChinaPhoneNumber(phone)) {
- throw new ServiceException("无效的电话号码");
+ return R.fail("无效的电话号码");
}
LoginUser loginUserApplet = tokenService.getLoginUserApplet();
@@ -107,92 +127,91 @@
VipSetting vipSetting = vipSettingService.getVipSettingByUserId(userid);
if (vipSetting == null) {
- throw new ServiceException("VIP 设置未找到");
+ return R.fail("VIP 设置未找到");
}
- if (vipSetting.getId() == 0 && vipSetting.getVipGiftRole() == 0) {
- throw new ServiceException("转赠积分权限未开启");
+ if (vipSetting.getVipGiftRole() == 0) {
+ return R.fail("转赠积分权限未开启");
}
AppUser appUser = appUserService.getById(userid);
if (appUser == null) {
- throw new ServiceException("用户未找到");
+ return R.fail("用户未找到");
}
- Integer totalPoint = appUser.getLavePoint();
-
- PointSetting pointSetting = pointSettingService.getPointSettingByAppUserId(userid);
- if (pointSetting == null) {
- throw new ServiceException("积分设置未找到");
- }
- Integer buyPointOpen = pointSetting.getBuyPointOpen();
-
- UserPoint userPoint = new UserPoint();
- userPoint.setAppUserId(userid);
- List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint);
- Map<Integer, Integer> userBalanceMap = userPointList.stream()
- .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance));
-
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.CONSUME.getCode(), buyPointOpen == 0);
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.COMMISSION_RETURN.getCode(), pointSetting.getSharePointOpen() == 0);
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.STORE_COMMISSION_RETURN.getCode(), pointSetting.getShopSharePointOpen() == 0);
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.STORE_PERFORMANCE.getCode(), pointSetting.getShopPointOpen() == 0);
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.TECHNICIAN_PERFORMANCE.getCode(), pointSetting.getPersonPointOpen() == 0);
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.NEW_USER_REFERRAL.getCode(), pointSetting.getGetNewPointOpen() == 0);
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.REGISTRATION.getCode(), pointSetting.getGetRegisPointOpen() == 0);
- totalPoint -= getAdjustedPoint(userBalanceMap, PointChangeType.WORK_PERFORMANCE.getCode(), pointSetting.getWorkPointOpen() == 0);
-
- if (point.compareTo(new BigDecimal(totalPoint)) > 0) {
- throw new ServiceException("转赠积分不足");
+ // 可转赠积分总数
+ Integer transferablePoint = appUser.getTransferablePoint();
+ if (point > transferablePoint) {
+ return R.fail("可转赠积分不足");
}
AppUser appUserForPhoe = appUserService.getOne(new LambdaQueryWrapper<AppUser>()
- .eq(AppUser::getPhone, phone));
+ .eq(AppUser::getPhone, phone).eq(AppUser::getDelFlag, 0).ne(AppUser::getStatus, 3));
if (appUserForPhoe == null) {
- throw new ServiceException("目标用户未找到");
+ return R.fail("目标用户不存在");
}
-
- appUserForPhoe.setLavePoint(appUserForPhoe.getLavePoint() + point.intValue());
- appUserForPhoe.setTotalPoint(appUserForPhoe.getTotalPoint() + point.intValue());
+ if(appUserForPhoe.getStatus() == 2){
+ return R.fail("目标用户已被冻结");
+ }
+ if(appUserForPhoe.getId().equals(userid)){
+ return R.fail("不能转增给自己");
+ }
+ Integer lavePoint1 = appUserForPhoe.getLavePoint();
+ appUserForPhoe.setLavePoint(appUserForPhoe.getLavePoint() + point);
+ appUserForPhoe.setTotalPoint(appUserForPhoe.getTotalPoint() + point);
+ appUserForPhoe.setTransferablePoint(transferablePoint + point);
+ appUserForPhoe.setAvailablePoint(appUserForPhoe.getAvailablePoint() + point);
+ appUserForPhoe.setTotalAvailablePoint(appUserForPhoe.getTotalAvailablePoint() + point);
appUserService.updateById(appUserForPhoe);
+ //构建积分流水记录
+ UserPoint userPoint = new UserPoint();
+ userPoint.setType(12);
+ userPoint.setHistoricalPoint(lavePoint1);
+ userPoint.setVariablePoint(point);
+ userPoint.setBalance(appUserForPhoe.getLavePoint());
+ userPoint.setCreateTime(LocalDateTime.now());
+ userPoint.setAppUserId(appUserForPhoe.getId());
+ userPointService.save(userPoint);
- log.info("积分转赠完成,用户ID: {}, 新积分: {}", appUserForPhoe.getId(), appUserForPhoe.getLavePoint());
+ Integer lavePoint = appUser.getLavePoint();
+ appUser.setLavePoint(appUser.getLavePoint() - point);
+ appUser.setTransferablePoint(appUser.getTransferablePoint() - point);
+ appUser.setAvailablePoint(appUser.getAvailablePoint() - point);
+ appUserService.updateById(appUser);
+ //构建积分流水记录
+ userPoint = new UserPoint();
+ userPoint.setType(13);
+ userPoint.setHistoricalPoint(lavePoint);
+ userPoint.setVariablePoint(point);
+ userPoint.setBalance(appUser.getLavePoint());
+ userPoint.setCreateTime(LocalDateTime.now());
+ userPoint.setAppUserId(appUser.getId());
+ userPointService.save(userPoint);
+ return R.ok();
}
- private int getAdjustedPoint(Map<Integer, Integer> userBalanceMap, int pointTypeCode, boolean isOpen) {
- return isOpen ? 0 : Optional.ofNullable(userBalanceMap.get(pointTypeCode)).orElse(0);
- }
@Override
public UserPointStatistics getStatistics(UserPoint userPoint) {
-
- if (StringUtils.isNotEmpty(userPoint.getUserName()) || StringUtils.isNotEmpty(userPoint.getPhone())) {
- List<Long> userIds = appUserService.listObjs(new LambdaQueryWrapper<AppUser>()
- .select(AppUser::getId)
- .like(StringUtils.isNotEmpty(userPoint.getUserName()),AppUser::getName, userPoint.getUserName())
- .like(StringUtils.isNotEmpty(userPoint.getPhone()),AppUser::getPhone, userPoint.getPhone()))
- .stream()
- .map(appUserId -> (Long) appUserId)
- .collect(Collectors.toList());
- userPoint.setUserIds(userIds);
- }
-
- List<UserPoint> userPointList = userPointMapper.findLatestChangeByType(userPoint);
+ List<UserPoint> userPointList = this.baseMapper.selectUserPoint(userPoint);
Map<Integer, Integer> userBalanceMap = userPointList.stream()
- .collect(Collectors.toMap(UserPoint::getType, UserPoint::getBalance));
+ .collect(Collectors.groupingBy(
+ UserPoint::getType,
+ Collectors.summingInt(UserPoint::getVariablePoint)
+ ));
+ int consumePoint = userBalanceMap.getOrDefault(PointChangeType.CONSUME.getCode(), 0);
+ int sharePoint = userBalanceMap.getOrDefault(PointChangeType.REBATE.getCode(), 0);
+ int pullNewPoint = userBalanceMap.getOrDefault(PointChangeType.PULL_NEW.getCode(), 0);
+ int registerPoint = userBalanceMap.getOrDefault(PointChangeType.REGISTER.getCode(), 0);
- Integer consumePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.CONSUME.getCode())).orElse(0);
- Integer sharePoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.COMMISSION_RETURN.getCode())).orElse(0);
- Integer pullNewPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.NEW_USER_REFERRAL.getCode())).orElse(0);
- Integer registerPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.REGISTRATION.getCode())).orElse(0);
- Integer workPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.WORK_PERFORMANCE.getCode())).orElse(0);
- Integer shopAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TECHNICIAN_PERFORMANCE.getCode())).orElse(0);
- Integer exchangeGoodsPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.EXCHANGE_GOODS.getCode())).orElse(0);
- Integer storeAchievementPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_PERFORMANCE.getCode())).orElse(0);
- Integer storeCommissionPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.STORE_COMMISSION_RETURN.getCode())).orElse(0);
- Integer transferPoint = Optional.ofNullable(userBalanceMap.get(PointChangeType.TRANSFER_POINTS.getCode())).orElse(0);
- Integer totalPoint = consumePoint + sharePoint + pullNewPoint + registerPoint + workPoint + shopAchievementPoint + exchangeGoodsPoint + storeAchievementPoint + storeCommissionPoint + transferPoint;
+ // 做工积分:签到积分 + 每日分享积分 + 每日签到积分 + 每日使用时长积分
+ int share = userBalanceMap.getOrDefault(PointChangeType.SHARE.getCode(), 0);
+ int signIn = userBalanceMap.getOrDefault(PointChangeType.SIGN_IN.getCode(), 0);
+ int useTime = userBalanceMap.getOrDefault(PointChangeType.USE_TIME.getCode(), 0);
+ int workPoint = share + signIn + useTime;
-
+ int shopAchievementPoint = userBalanceMap.getOrDefault(PointChangeType.TECHNICIAN_ACHIEVEMENT.getCode(), 0);
+ //总积分
+ int totalPoint = consumePoint+sharePoint+pullNewPoint+registerPoint+workPoint+shopAchievementPoint;
UserPointStatistics userPointStatistics = new UserPointStatistics();
userPointStatistics.setTotalPoint(totalPoint);
userPointStatistics.setConsumePoint(consumePoint);
@@ -204,25 +223,9 @@
return userPointStatistics;
}
+
@Override
public IPage<UserPoint> getUserPointPage(Page<UserPoint> page, UserPoint userPoint) {
- List<AppUser> appUserList = appUserService.list(new LambdaQueryWrapper<AppUser>()
- .eq(AppUser::getPhone, userPoint.getPhone())
- .like(AppUser::getName, userPoint.getUserName()));
- List<Long> userIds = appUserList.stream().map(AppUser::getId).collect(Collectors.toList());
-
- Page<UserPoint> userPointPage = page(page, new LambdaQueryWrapper<UserPoint>()
- .in(!CollectionUtils.isEmpty(userIds), UserPoint::getAppUserId, userIds)
- .eq(userPoint.getType() != null, UserPoint::getType, userPoint.getType())
- .between( userPoint.getStartTime()!= null && userPoint.getEndTime() !=null,UserPoint::getCreateTime, userPoint.getStartTime(), userPoint.getEndTime())
- .orderByDesc(UserPoint::getCreateTime));
-
- userPointPage.getRecords().forEach(userPoint1 -> appUserList.stream()
- .filter(appUser -> appUser.getId().equals(userPoint1.getAppUserId()))
- .findFirst().ifPresent(appUser -> {
- userPoint1.setUserName(appUser.getName());
- userPoint1.setPhone(appUser.getPhone());
- }));
- return userPointPage;
+ return this.baseMapper.queryUserPointPage(page, userPoint);
}
}
--
Gitblit v1.7.1