1
phpcjl
2024-12-19 b98363420db796eec5ea884f2b42a7b6a8868924
1
6个文件已修改
143 ■■■■■ 已修改文件
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/AppUser.java 16 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/PointSettingService.java 2 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/PointSettingServiceImpl.java 9 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java 104 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/AppUser.java
@@ -179,6 +179,14 @@
    @TableField("total_register_point")
    private Integer totalRegisterPoint;
    @ApiModelProperty(value = "门店业绩积分")
    @TableField("shop_achievement_point")
    private Integer shopAchievementPoint;
    @ApiModelProperty(value = "门店返佣积分")
    @TableField("shop_share_point")
    private Integer shopSharePoint;
//    @ApiModelProperty(value = "做工积分总数")
//    @TableField("total_work_point")
//    private Integer totalWorkPoint;
@@ -200,13 +208,13 @@
    private Integer totalPerformancePoint;
    @ApiModelProperty(value = "剩余积分")
    @TableField("lave_point")
    private Integer lavePoint;
    @ApiModelProperty(value = "总积分")
    @TableField("total_point")
    private Integer totalPoint;
    @ApiModelProperty(value = "剩余积分(可用于消费的积分)")
    @TableField("lave_point")
    private Integer lavePoint;
    
    @ApiModelProperty(value = "是否可更换推广人(0=否,1=是)")
    @TableField("change_promoter")
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java
@@ -17,8 +17,6 @@
 */
public interface UserPointMapper extends BaseMapper<UserPoint> {
    List<UserPoint> findLatestUserPointByTypeForUser(Long userId);
    IPage<UserPoint> queryUserPointPage(@Param("page") IPage<UserPoint> page,@Param("userPoint") UserPoint userPoint);
    List<UserPoint> selectUserPoint(@Param("userPoint") UserPoint userPoint);
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/PointSettingService.java
@@ -5,4 +5,6 @@
public interface PointSettingService {
    PointSetting getPointSettingByAppUserId(Long appUserId);
    PointSetting getPointSettingById(Integer id);
}
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/PointSettingServiceImpl.java
@@ -26,4 +26,13 @@
        }
        return r.getData();
    }
    @Override
    public PointSetting getPointSettingById(Integer id) {
        R<PointSetting> r = pointSettingClient.getPointSetting(id);
        if (!R.isSuccess(r)){
            throw new RuntimeException("获取积分设置失败");
        }
        return r.getData();
    }
}
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
@@ -7,7 +7,6 @@
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.other.api.enums.PointChangeType;
import com.ruoyi.account.mapper.UserPointMapper;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.PointSettingService;
@@ -16,24 +15,24 @@
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.security.service.TokenService;
import com.ruoyi.other.api.domain.PointSetting;
import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.api.enums.PointChangeType;
import com.ruoyi.other.api.feignClient.ShopClient;
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.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
@@ -56,16 +55,11 @@
    @Resource
    private PointSettingService pointSettingService;
    @Resource
    private UserPointMapper userPointMapper;
    @Resource
    private ShopClient shopClient;
    @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();
@@ -73,10 +67,10 @@
        userPointVO.setConsumePoint(appUser.getLavePoint());
        userPointVO.setShopPoint(appUser.getShopPoint());
        userPointVO.setSharePoint(appUser.getSharePoint());
        userPointVO.setPullNewPoint(userBalanceMap.get(PointChangeType.PULL_NEW.getCode()));
        userPointVO.setShopAchievementPoint(userBalanceMap.get(PointChangeType.SHOP_ACHIEVEMENT.getCode()));
        userPointVO.setShopSharePoint(userBalanceMap.get(PointChangeType.SHOP_REBATE.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;
    }
@@ -127,7 +121,7 @@
            throw new ServiceException("积分设置未找到");
        }
        // 可转赠积分总数
        int adjustedPoint = getAdjustedPoint(pointSetting, appUser);
        long adjustedPoint = getAdjustedPoint(pointSetting, appUser);
        if (point.compareTo(new BigDecimal(adjustedPoint)) > 0) {
            throw new ServiceException("转赠积分不足");
@@ -143,6 +137,11 @@
        appUserForPhoe.setTotalPoint(appUserForPhoe.getTotalPoint() + point.intValue());
        appUserService.updateById(appUserForPhoe);
        Integer lavePoint = appUser.getLavePoint();
        appUser.setLavePoint(lavePoint - point.intValue());
        Integer totalPoint = appUser.getTotalPoint();
        appUser.setTotalPoint(totalPoint - point.intValue());
        appUserService.updateById(appUser);
        log.info("积分转赠完成,用户ID: {}, 新积分: {}", appUserForPhoe.getId(), appUserForPhoe.getLavePoint());
    }
@@ -152,63 +151,38 @@
     * @param appUser 用户
     * @return
     */
    private int getAdjustedPoint(PointSetting pointSetting, AppUser appUser) {
        int transferPoint = 0;
        // 消费积分数
        Integer buyPointGift = pointSetting.getBuyPointGift();
        if (buyPointGift == 1){
            transferPoint += appUser.getShopPoint();
    private long getAdjustedPoint(PointSetting pointSetting, AppUser appUser) {
        if (pointSetting == null || appUser == null) {
            throw new ServiceException("pointSetting和appUser不能为空");
        }
        // 返佣积分
        Integer sharePointOpen = pointSetting.getSharePointGift();
        if (sharePointOpen == 1){
            transferPoint += appUser.getSharePoint();
        }
        long transferPoint = 0;
        // 门店返佣积分
        Integer shopSharePointGift = pointSetting.getShopSharePointGift();
        R<List<Shop>> shops = shopClient.getShopByUserIds(Collections.singletonList(appUser.getId()));
        List<Shop> shopList = shops.getData();
        if (CollectionUtils.isEmpty(shopList)) {
            throw new ServiceException("未找到门店");
        }
        if (shopSharePointGift == 1){
            transferPoint += shopList.stream().mapToInt(Shop::getSharePoint).sum();
        }
        // 门店业绩积分
        Integer shopPointOpen = pointSetting.getShopPointGift();
        if (shopPointOpen == 1){
            transferPoint += shopList.stream().mapToInt(Shop::getShopPoint).sum();
        }
        transferPoint += calculatePoint(pointSetting.getBuyPointGift(), appUser.getShopPoint(), pointSetting.getBuyPoint());
        transferPoint += calculatePoint(pointSetting.getSharePointGift(), appUser.getSharePoint(), pointSetting.getSharePoint());
        transferPoint += calculatePoint(pointSetting.getShopSharePointGift(), appUser.getShopSharePoint(), pointSetting.getShopSharePoint());
        transferPoint += calculatePoint(pointSetting.getShopPointGift(), appUser.getShopAchievementPoint(), pointSetting.getShopPoint());
        transferPoint += calculatePoint(pointSetting.getPersonPointGift(), appUser.getTotalPerformancePoint(), pointSetting.getPersonPoint());
        transferPoint += calculatePoint(pointSetting.getGetNewPointGift(), appUser.getTotalInvitePoint(), pointSetting.getGetNewPoint());
        transferPoint += calculatePoint(pointSetting.getGetRegisPointGift(), appUser.getTotalRegisterPoint(), pointSetting.getRegisPoint());
        transferPoint += calculatePoint(pointSetting.getWorkPointGift(), appUser.getTotalSharePoint() + appUser.getTotalSignPoint() + appUser.getTotalHourPoint(), pointSetting.getWorkPoint());
        // 技师业绩积分
        Integer personPointOpen = pointSetting.getPersonPointGift();
        if (personPointOpen == 1){
            transferPoint += appUser.getTotalPerformancePoint();
        }
        // 拉新积分
        Integer getNewPointOpen = pointSetting.getGetNewPointGift();
        if (getNewPointOpen == 1){
            transferPoint += appUser.getTotalInvitePoint();
        }
        // 注册积分
        Integer getRegisPointGift = pointSetting.getGetRegisPointGift();
        if (getRegisPointGift == 1){
            transferPoint += appUser.getTotalRegisterPoint();
        }
        // 做工积分
        Integer workPointOpen = pointSetting.getWorkPointGift();
        if (workPointOpen == 1){
            transferPoint += appUser.getTotalSharePoint() + appUser.getTotalSignPoint() + appUser.getTotalHourPoint();
        }
        return transferPoint;
    }
    private long calculatePoint(Integer settingValue, double userValue, double pointValue) {
        if (settingValue == 1) {
            try {
                double result = userValue * (pointValue / 100.0);
                return Math.round(result);
            } catch (ArithmeticException e) {
                return 0;
            }
        }
        return 0;
    }
    @Override
    public UserPointStatistics getStatistics(UserPoint userPoint) {
ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
@@ -17,16 +17,6 @@
    <sql id="Base_Column_List">
        id, type, historical_point, variable_point, create_time, app_user_id, object_id
    </sql>
    <select id="findLatestUserPointByTypeForUser" resultType="com.ruoyi.account.api.model.UserPoint">
        SELECT
            t1.*
        FROM
            t_user_point t1
                INNER JOIN ( SELECT type, MAX( create_time ) AS max_create_time FROM t_user_point WHERE app_user_id = #{userId} GROUP BY type ) t2 ON t1.type = t2.type
                AND t1.create_time = t2.max_create_time
        WHERE
            t1.app_user_id = #{userId}
    </select>
    <sql id="userPointList">
        SELECT