1
phpcjl
2024-12-18 07882a44365a0621640fdc646ffb8df55c46d80c
1
6个文件已修改
201 ■■■■ 已修改文件
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/AppUser.java 20 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/UserPoint.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/enums/PointChangeType.java 25 ●●●●● 补丁 | 查看 | 原始文档 | 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/impl/UserPointServiceImpl.java 127 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml 24 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/AppUser.java
@@ -179,11 +179,23 @@
    @TableField("total_register_point")
    private Integer totalRegisterPoint;
    @ApiModelProperty(value = "做工积分总数")
    @TableField("total_work_point")
    private Integer totalWorkPoint;
//    @ApiModelProperty(value = "做工积分总数")
//    @TableField("total_work_point")
//    private Integer totalWorkPoint;
    @ApiModelProperty(value = "业绩积分总数")
    @ApiModelProperty(value = "每日分享积分")
    @TableField("total_share_point")
    private Integer totalSharePoint;
    @ApiModelProperty(value = "每日签到积分")
    @TableField("total_sign_point")
    private Integer totalSignPoint;
    @ApiModelProperty(value = "使用时长积分")
    @TableField("total_hour_point")
    private Integer totalHourPoint;
    @ApiModelProperty(value = "技师业绩积分总数")
    @TableField("total_performance_point")
    private Integer totalPerformancePoint;
ruoyi-api/ruoyi-api-account/src/main/java/com/ruoyi/account/api/model/UserPoint.java
@@ -37,7 +37,8 @@
    @TableId("id")
    private Long id;
    @ApiModelProperty(value = "变动类型(1=消费积分,2=返佣积分,3=拉新人积分,4=兑换商品 5 = 门店业绩积分 6 =门店返佣积分7=技师业绩积分8 =转赠积分 9 =做工积分 10 =注册积分)")
    @ApiModelProperty(value = "变动类型(1-消费,2-返佣,3-拉新,4-每日分享,5-每日签到,6-使用时长, 7-注册积分, 8-门店业绩," +
            "9-门店返佣,10-技师业绩,11-兑换商品,12-他人赠送,13-赠与他人)")
    @TableField("type")
    private Integer type;
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/enums/PointChangeType.java
@@ -4,17 +4,20 @@
@Getter
public enum PointChangeType {
    CONSUME(1, "消费积分"),
    COMMISSION_RETURN(2, "返佣积分"),
    NEW_USER_REFERRAL(3, "拉新人积分"),
    EXCHANGE_GOODS(4, "兑换商品"),
    STORE_PERFORMANCE(5, "门店业绩积分"),
    STORE_COMMISSION_RETURN(6, "门店返佣积分"),
    TECHNICIAN_PERFORMANCE(7, "技师业绩积分"),
    TRANSFER_POINTS(8, "转赠积分"),
    WORK_PERFORMANCE(9, "做工积分"),
    REGISTRATION(10, "注册积分");
// 1-消费,2-返佣,3-拉新,4-每日分享,5-每日签到,6-使用时长, 7-注册积分, 8-门店业绩,9-门店返佣,10-技师业绩,11-兑换商品,12-他人赠送,13-赠与他人
    CONSUME(1, "消费"),
    REBATE(2, "返佣"),
    PULL_NEW(3, "拉新"),
    SHARE(4, "每日分享"),
    SIGN_IN(5, "每日签到"),
    USE_TIME(6, "使用时长"),
    REGISTER(7, "注册积分"),
    SHOP_ACHIEVEMENT(8, "门店业绩"),
    SHOP_REBATE(9, "门店返佣"),
    TECHNICIAN_ACHIEVEMENT(10, "技师业绩"),
    EXCHANGE_GOODS(11, "兑换商品"),
    OTHER_GIFT(12, "他人赠送"),
    GIFT(13, "赠与他人");
    private final int code;
    private final String description;
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/mapper/UserPointMapper.java
@@ -19,4 +19,6 @@
    List<UserPoint> findLatestUserPointByTypeForUser(Long userId);
    IPage<UserPoint> queryUserPointPage(IPage<UserPoint> page, UserPoint userPoint);
    List<UserPoint> selectUserPoint(UserPoint userPoint);
}
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/UserPointServiceImpl.java
@@ -16,12 +16,15 @@
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.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.feignClient.ShopClient;
import com.ruoyi.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
@@ -55,6 +58,8 @@
    private PointSettingService pointSettingService;
    @Resource
    private UserPointMapper userPointMapper;
    @Resource
    private ShopClient shopClient;
    @Override
    public UserPointVO getUserPoint(Long userId) {
@@ -69,9 +74,9 @@
        userPointVO.setConsumePoint(appUser.getLavePoint());
        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.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);
        return userPointVO;
    }
@@ -117,30 +122,15 @@
        if (appUser == null) {
            throw new ServiceException("用户未找到");
        }
        Integer totalPoint = appUser.getLavePoint();
        PointSetting pointSetting = pointSettingService.getPointSettingByAppUserId(userid);
        if (pointSetting == null) {
            throw new ServiceException("积分设置未找到");
        }
        Integer buyPointOpen = pointSetting.getBuyPointOpen();
        // 可转赠积分总数
        int adjustedPoint = getAdjustedPoint(pointSetting, appUser);
        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) {
        if (point.compareTo(new BigDecimal(adjustedPoint)) > 0) {
            throw new ServiceException("转赠积分不足");
        }
@@ -157,13 +147,102 @@
        log.info("积分转赠完成,用户ID: {}, 新积分: {}", appUserForPhoe.getId(), appUserForPhoe.getLavePoint());
    }
    private int getAdjustedPoint(Map<Integer, Integer> userBalanceMap, int pointTypeCode, boolean isOpen) {
        return isOpen ? 0 : Optional.ofNullable(userBalanceMap.get(pointTypeCode)).orElse(0);
    /**
     * 获取可转赠积分
     * @param pointSetting 积分设置
     * @param appUser 用户
     * @return
     */
    private int getAdjustedPoint(PointSetting pointSetting, AppUser appUser) {
        int transferPoint = 0;
        // 消费积分数
        Integer buyPointGift = pointSetting.getBuyPointGift();
        if (buyPointGift == 1){
            transferPoint += appUser.getShopPoint();
        }
        // 返佣积分
        Integer sharePointOpen = pointSetting.getSharePointGift();
        if (sharePointOpen == 1){
            transferPoint += appUser.getSharePoint();
        }
        // 门店返佣积分
        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();
        }
        // 技师业绩积分
        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;
    }
    @Override
    public UserPointStatistics getStatistics(UserPoint userPoint) {
        return null;
        List<UserPoint> userPointList = this.baseMapper.selectUserPoint(userPoint);
        Map<Integer, Integer> userBalanceMap = userPointList.stream()
                .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);
        // 做工积分:签到积分 + 每日分享积分 + 每日签到积分 + 每日使用时长积分
        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);
        userPointStatistics.setSharePoint(sharePoint);
        userPointStatistics.setPullNewPoint(pullNewPoint);
        userPointStatistics.setRegisterPoint(registerPoint);
        userPointStatistics.setWorkPoint(workPoint);
        userPointStatistics.setShopAchievementPoint(shopAchievementPoint);
        return userPointStatistics;
    }
ruoyi-service/ruoyi-account/src/main/resources/mapper/account/UserPointMapper.xml
@@ -27,16 +27,17 @@
        WHERE
            t1.app_user_id = #{userId}
    </select>
    <select id="queryUserPointPage" resultType="com.ruoyi.account.api.model.UserPoint">
    <sql id="userPointList">
        SELECT
            tau.`name` userName,
            tau.phone,
            tup.type,
            tup.create_time,
            tup.variable_point
        tau.`name` userName,
        tau.phone,
        tup.type,
        tup.create_time,
        tup.variable_point
        FROM
            t_user_point tup
                LEFT JOIN t_app_user tau ON tup.app_user_id = tau.id
        t_user_point tup
        LEFT JOIN t_app_user tau ON tup.app_user_id = tau.id
        <where>
            <if test="userName != null and userName != ''">
                AND tau.`name` LIKE concat('%',#{userName},'%')
@@ -51,6 +52,13 @@
                AND tup.create_time BETWEEN #{startTime} AND #{endTime}
            </if>
        </where>
    </sql>
    <select id="queryUserPointPage" resultType="com.ruoyi.account.api.model.UserPoint">
        <include refid="userPointList"/>
    </select>
    <select id="selectUserPoint" resultType="com.ruoyi.account.api.model.UserPoint">
        <include refid="userPointList"/>
    </select>
</mapper>