| | |
| | | |
| | | 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.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.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 javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.time.format.DateTimeFormatter; |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | |
| | | private VipSettingService vipSettingService; |
| | | @Resource |
| | | private PointSettingService pointSettingService; |
| | | @Resource |
| | | private UserPointService userPointService; |
| | | |
| | | |
| | | |
| | | |
| | | @Override |
| | | public UserPointVO getUserPoint(Long userId) { |
| | |
| | | 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(appUser.getTotalInvitePoint()); |
| | |
| | | } |
| | | |
| | | @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(); |
| | |
| | | |
| | | 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("用户未找到"); |
| | | } |
| | | |
| | | PointSetting pointSetting = pointSettingService.getPointSettingByAppUserId(userid); |
| | | if (pointSetting == null) { |
| | | throw new ServiceException("积分设置未找到"); |
| | | return R.fail("用户未找到"); |
| | | } |
| | | // 可转赠积分总数 |
| | | long adjustedPoint = appUser.getAvailablePoint(); |
| | | |
| | | if (point.compareTo(new BigDecimal(adjustedPoint)) > 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); |
| | | |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | appUser.setLavePoint(lavePoint - point.intValue()); |
| | | Integer totalPoint = appUser.getTotalPoint(); |
| | | appUser.setTotalPoint(totalPoint - point.intValue()); |
| | | appUser.setLavePoint(appUser.getLavePoint() - point); |
| | | appUser.setTransferablePoint(appUser.getTransferablePoint() - point); |
| | | appUser.setAvailablePoint(appUser.getAvailablePoint() - point); |
| | | appUserService.updateById(appUser); |
| | | log.info("积分转赠完成,用户ID: {}, 新积分: {}", appUserForPhoe.getId(), appUserForPhoe.getLavePoint()); |
| | | //构建积分流水记录 |
| | | 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(); |
| | | } |
| | | |
| | | |