| | |
| | | package com.ruoyi.account.service.impl; |
| | | |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.ruoyi.account.api.model.AppUserShop; |
| | | import com.ruoyi.account.api.model.UserChangeLog; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | | import com.ruoyi.account.mapper.AppUserMapper; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.service.AppUserService; |
| | | import com.ruoyi.account.service.AppUserShopService; |
| | | import com.ruoyi.account.service.UserChangeLogService; |
| | | import com.ruoyi.account.service.UserPointService; |
| | | import com.ruoyi.account.util.weChat.EnvVersion; |
| | | import com.ruoyi.account.util.weChat.WXCore; |
| | | import com.ruoyi.account.util.weChat.WeChatUtil; |
| | | import com.ruoyi.account.vo.*; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.StringUtils; |
| | | import com.ruoyi.common.redis.service.RedisService; |
| | | 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.PointSettingClient; |
| | | import com.ruoyi.other.api.feignClient.ShopClient; |
| | | import com.ruoyi.other.api.feignClient.VipSettingClient; |
| | | import com.ruoyi.system.api.domain.SysUser; |
| | | import com.ruoyi.system.api.feignClient.SysUserClient; |
| | | import com.ruoyi.system.api.model.LoginUser; |
| | | import org.apache.logging.log4j.core.util.UuidUtil; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.beans.factory.annotation.Value; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.util.CollectionUtils; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.*; |
| | | import java.util.concurrent.TimeUnit; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation.ANONYMOUS.optional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @Resource |
| | | private RedisService redisService; |
| | | |
| | | @Resource |
| | | private ShopClient shopClient; |
| | | |
| | | @Resource |
| | | private AppUserShopService appUserShopService; |
| | | |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | @Resource |
| | | private VipSettingClient vipSettingClient; |
| | | |
| | | @Resource |
| | | private PointSettingClient pointSettingClient; |
| | | |
| | | @Resource |
| | | private UserChangeLogService userChangeLogService; |
| | | |
| | | @Value("${file.upload.location}") |
| | | private String filePath; |
| | | |
| | | @Value("${file.upload.accessPath}") |
| | | private String accessPath; |
| | | |
| | | @Resource |
| | | private UserPointService userPointService; |
| | | @Autowired |
| | | private AppUserMapper appUserMapper; |
| | | |
| | | |
| | | /** |
| | | * 小程序一键登录 |
| | | * @param appletLogin |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult appletLogin(AppletLogin appletLogin) { |
| | | public R appletLogin(AppletLogin appletLogin) { |
| | | //使用jscode获取微信openid |
| | | Map<String, Object> map = weChatUtil.code2Session(appletLogin.getJscode()); |
| | | Integer errcode = Integer.valueOf(map.get("errcode").toString()); |
| | | if(0 != errcode){ |
| | | return AjaxResult.error(map.get("msg").toString()); |
| | | return R.fail(map.get("msg").toString()); |
| | | } |
| | | String openid = map.get("openid").toString(); |
| | | String sessionKey = map.get("sessionKey").toString(); |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getWxOpenid, openid).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null == appUser){ |
| | | String decrypt = WXCore.decrypt(appletLogin.getEncryptedData_phone(), sessionKey, appletLogin.getIv_phone()); |
| | | if (StringUtils.isEmpty(decrypt)) { |
| | | return R.fail("获取手机信息失败"); |
| | | } |
| | | JSONObject phone = JSON.parseObject(decrypt); |
| | | String purePhoneNumber = phone.getString("purePhoneNumber"); |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(2); |
| | | return AjaxResult.success(loginVo); |
| | | loginVo.setPhone(purePhoneNumber); |
| | | return R.ok(loginVo); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | if(2 == appUser.getStatus()){ |
| | | return AjaxResult.error("账户已被冻结,请联系管理员!"); |
| | | return R.fail("账户已被冻结,请联系管理员!"); |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | return AjaxResult.success(loginVo); |
| | | |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | this.updateById(appUser); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult<LoginVo> mobileLogin(MobileLogin mobileLogin) { |
| | | //校验验证码 |
| | | String code = redisService.getCacheObject(mobileLogin.getPhone()); |
| | | if(null == code || !code.equals(mobileLogin.getCode())){ |
| | | return AjaxResult.error("验证码错误"); |
| | | } |
| | | public R<LoginVo> mobileLogin(MobileLogin mobileLogin) { |
| | | //校验验证码 TODO 待完善 |
| | | // String code = redisService.getCacheObject(mobileLogin.getPhone()); |
| | | // if(null == code || !code.equals(mobileLogin.getCode())){ |
| | | // return R.fail("验证码错误"); |
| | | // } |
| | | |
| | | //查询用户是否注册,没有注册则跳转到注册页面 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, mobileLogin.getPhone()).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null == appUser){ |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(2); |
| | | return AjaxResult.success(loginVo); |
| | | loginVo.setPhone(mobileLogin.getPhone()); |
| | | return R.ok(loginVo); |
| | | } |
| | | //账户被冻结,给出提示 |
| | | if(2 == appUser.getStatus()){ |
| | | return AjaxResult.error("账户已被冻结,请联系管理员!"); |
| | | return R.fail("账户已被冻结,请联系管理员!"); |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | return AjaxResult.success(loginVo); |
| | | |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | this.updateById(appUser); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult getSMSCode(SMSCode smsCode) { |
| | | public R getSMSCode(SMSCode smsCode) { |
| | | //校验验证码获取评率(1分钟5次) |
| | | String key = smsCode.getType() + "&" + smsCode.getPhone(); |
| | | Map<String, Object> cacheMap = redisService.getCacheMap(key); |
| | |
| | | Integer number = Integer.valueOf(cacheMap.get("number").toString()) + 1; |
| | | Long startTime = Long.valueOf(cacheMap.get("startTime").toString()); |
| | | if(number > 5 && (System.currentTimeMillis() - startTime) < 60000){ |
| | | return AjaxResult.error("获取验证码太频繁,请稍后重试!"); |
| | | return R.fail("获取验证码太频繁,请稍后重试!"); |
| | | } |
| | | if(number <= 5){ |
| | | cacheMap.put("number", number); |
| | |
| | | code += Double.valueOf(Math.random() * 10).intValue(); |
| | | } |
| | | //发送短信 todo 待对接短信 |
| | | return AjaxResult.success(); |
| | | return R.ok(); |
| | | } |
| | | |
| | | |
| | |
| | | * @return |
| | | */ |
| | | @Override |
| | | public AjaxResult<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | public R<LoginVo> registerAccount(RegisterAccount registerAccount) { |
| | | // TODO 待完善 |
| | | //校验验证码 |
| | | String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | if(null == code || !code.equals(registerAccount.getCode())){ |
| | | return AjaxResult.error("验证码错误"); |
| | | } |
| | | // String code = redisService.getCacheObject(registerAccount.getPhone()); |
| | | // if(null == code || !code.equals(registerAccount.getCode())){ |
| | | // return R.fail("验证码错误"); |
| | | // } |
| | | //使用jscode获取微信openid |
| | | Map<String, Object> map = weChatUtil.code2Session(registerAccount.getJscode()); |
| | | Integer errcode = Integer.valueOf(map.get("errcode").toString()); |
| | | if(0 != errcode){ |
| | | return AjaxResult.error(map.get("msg").toString()); |
| | | return R.fail(map.get("msg").toString()); |
| | | } |
| | | String openid = map.get("openid").toString(); |
| | | //查询用户是否注册 |
| | | AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getWxOpenid, openid).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null != appUser){ |
| | | return AjaxResult.error("此微信号已注册,请直接登录!"); |
| | | return R.fail("此微信号已注册,请直接登录!"); |
| | | } |
| | | AppUser appUser1 = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, registerAccount.getPhone()).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0)); |
| | | if(null != appUser1){ |
| | | return AjaxResult.error("手机号已注册,请直接登录!"); |
| | | if(null != appUser1 && StringUtils.isNotEmpty(appUser1.getWxOpenid())){ |
| | | return R.fail("手机号已注册,请直接登录!"); |
| | | } |
| | | if(null == appUser){ |
| | | if(null != appUser1 && appUser1.getStatus() == 2){ |
| | | return R.fail("手机号已注册,请直接登录!"); |
| | | } |
| | | //如果手机号已注册,但是没有微信号,则将微信号添加到已有账户上 |
| | | if(null != appUser1 && StringUtils.isEmpty(appUser1.getWxOpenid())){ |
| | | appUser1.setWxOpenid(openid); |
| | | this.updateById(appUser1); |
| | | appUser = appUser1; |
| | | }else if(null == appUser){ |
| | | appUser = new AppUser(); |
| | | appUser.setName(registerAccount.getName()); |
| | | appUser.setPhone(registerAccount.getPhone()); |
| | |
| | | AppUser appUser2 = this.getById(registerAccount.getPromoter()); |
| | | appUser.setInviteUserId(registerAccount.getPromoter()); |
| | | appUser.setShopId(appUser2.getShopId()); |
| | | appUser.setPartPoint(BigDecimal.ZERO); |
| | | appUser.setPartGrowPoint(BigDecimal.ZERO); |
| | | appUser.setShopPoint(BigDecimal.ZERO); |
| | | appUser.setSharePoint(BigDecimal.ZERO); |
| | | appUser.setPartPoint(0); |
| | | appUser.setPartGrowPoint(0); |
| | | appUser.setShopPoint(0); |
| | | appUser.setSharePoint(0); |
| | | appUser.setShopAmount(BigDecimal.ZERO); |
| | | appUser.setWithdrawableAmount(BigDecimal.ZERO); |
| | | appUser.setWithdrawnAmount(BigDecimal.ZERO); |
| | | appUser.setTotalRechargeAmount(BigDecimal.ZERO); |
| | | appUser.setTotalRedPacketAmount(BigDecimal.ZERO); |
| | | appUser.setTotalDistributionAmount(BigDecimal.ZERO); |
| | | appUser.setLavePoint(BigDecimal.ZERO); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | R<PointSetting> pointSettingR = pointSettingClient.getPointSetting(1); |
| | | if (R.isError(pointSettingR)){ |
| | | throw new RuntimeException("获取积分设置失败"); |
| | | } |
| | | PointSetting pointSetting = pointSettingR.getData(); |
| | | if (pointSetting == null){ |
| | | throw new RuntimeException("积分设置不存在"); |
| | | } |
| | | appUser.setLavePoint(pointSetting.getGetRegisPoint()); |
| | | appUser.setTotalPoint(0); |
| | | //根据平台的配置未达标,则标注为可修改推广人 |
| | | appUser.setChangePromoter(0); |
| | | appUser.setLongitude(registerAccount.getLongitude()); |
| | | appUser.setLatitude(registerAccount.getLatitude()); |
| | | //调用地图获取省市区数据 |
| | | //调用地图获取省市区数据 TODO 待完善 |
| | | // appUser.setProvince(); |
| | | // appUser.setProvinceCode(); |
| | | // appUser.setCity(); |
| | |
| | | // appUser.setDistrict(); |
| | | // appUser.setDistrictCode(); |
| | | this.save(appUser); |
| | | //获取微信推广二维码 |
| | | String fileName = UUID.randomUUID() + ".jpg"; |
| | | weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + appUser.getId(), EnvVersion.DEVELOP, filePath + fileName); |
| | | appUser.setQrCode(accessPath + fileName); |
| | | this.updateById(appUser); |
| | | //直推用户检查是否满足升级条件 |
| | | if(null != appUser.getInviteUserId()){ |
| | | vipUpgrade(appUser.getInviteUserId()); |
| | | } |
| | | |
| | | //查询当前注册的手机号是都和门店管理员手机号相同 |
| | | Shop shop = shopClient.getShopByPhone(registerAccount.getPhone()).getData(); |
| | | if(null != shop){ |
| | | //添加门店用户关系数据 |
| | | AppUserShop appUserShop = appUserShopService.getOne(new LambdaQueryWrapper<AppUserShop>().eq(AppUserShop::getAppUserId, appUser.getId()).eq(AppUserShop::getShopId, shop.getId())); |
| | | if(null == appUserShop){ |
| | | appUserShop = new AppUserShop(); |
| | | appUserShop.setShopId(shop.getId()); |
| | | appUserShop.setAppUserId(appUser.getId()); |
| | | appUserShopService.save(appUserShop); |
| | | //添加管理后台账号 |
| | | SysUser user = new SysUser(); |
| | | user.setDeptId(1L); |
| | | user.setUserName(appUser.getName()); |
| | | user.setNickName(appUser.getName()); |
| | | user.setPhonenumber(appUser.getPhone()); |
| | | user.setAvatar(appUser.getAvatar()); |
| | | user.setStatus("0"); |
| | | user.setDelFlag("0"); |
| | | user.setRoleType(2); |
| | | user.setObjectId(shop.getId()); |
| | | user.setAppUserId(appUser.getId()); |
| | | sysUserClient.saveShopUser(user); |
| | | } |
| | | } |
| | | } |
| | | LoginVo loginVo = new LoginVo(); |
| | | loginVo.setSkipPage(1); |
| | | loginVo.setFirstTime(false); |
| | | loginVo.setFirstTime(null == appUser1); |
| | | loginVo.setPhone(appUser.getPhone()); |
| | | //构建token |
| | | LoginUser loginUser = new LoginUser(); |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | return AjaxResult.success(loginVo); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 会员等级变化 |
| | | */ |
| | | public void vipUpgrade(Long id){ |
| | | AppUser appUser = this.getById(id); |
| | | Integer vipId = appUser.getVipId(); |
| | | //钻石会员 |
| | | VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData(); |
| | | Integer vipLevelUpNumRole = vipSetting3.getVipLevelUpNumRole(); |
| | | Integer vipDirectNum = vipSetting3.getVipDirectNum(); |
| | | Integer vipTeamNum = vipSetting3.getVipTeamNum(); |
| | | if(1 == vipLevelUpNumRole && appUser.getVipId() < 3){ |
| | | //查询直推用户达到X人或者团队人数达到X人后,可升级 |
| | | //直推用户数 |
| | | long count = this.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1).eq(AppUser::getInviteUserId, id)); |
| | | //团队用户数 |
| | | List<AppUser> subordinate = getSubordinate(id); |
| | | if(vipDirectNum <= count || vipTeamNum <= subordinate.size()){ |
| | | appUser.setVipId(3); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | return; |
| | | } |
| | | } |
| | | //黄金会员 |
| | | VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData(); |
| | | vipLevelUpNumRole = vipSetting2.getVipLevelUpNumRole(); |
| | | vipDirectNum = vipSetting2.getVipDirectNum(); |
| | | vipTeamNum = vipSetting2.getVipTeamNum(); |
| | | if(1 == vipLevelUpNumRole && appUser.getVipId() < 2){ |
| | | //查询直推用户达到X人或者团队人数达到X人后,可升级 |
| | | //直推用户数 |
| | | long count = this.count(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0).eq(AppUser::getStatus, 1).eq(AppUser::getInviteUserId, id)); |
| | | //团队用户数 |
| | | List<AppUser> subordinate = getSubordinate(id); |
| | | if(vipDirectNum <= count || vipTeamNum <= subordinate.size()){ |
| | | appUser.setVipId(2); |
| | | this.updateById(appUser); |
| | | //添加等级变化记录 |
| | | UserChangeLog userChangeLog = new UserChangeLog(); |
| | | userChangeLog.setDelFlag(0); |
| | | userChangeLog.setCreateTime(LocalDateTime.now()); |
| | | userChangeLog.setAppUserId(appUser.getId()); |
| | | userChangeLog.setBeforeVipId(vipId); |
| | | userChangeLog.setAfterVipId(appUser.getVipId()); |
| | | userChangeLog.setChangeType(1); |
| | | userChangeLogService.save(userChangeLog); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | public AppUser getTopAppUser(List<AppUser> list, Long id){ |
| | | AppUser appUser = list.stream().filter(s -> s.getInviteUserId().equals(id)).findFirst().get(); |
| | | AppUser appUser = list.stream().filter(s -> s.getId().equals(id)).findFirst().get(); |
| | | if(null == appUser.getInviteUserId()){ |
| | | return appUser; |
| | | } |
| | | return getTopAppUser(list, appUser.getId()); |
| | | return getTopAppUser(list, appUser.getInviteUserId()); |
| | | } |
| | | |
| | | /** |
| | | * 获取所有下级数据 |
| | | * @param id |
| | | * @return |
| | | */ |
| | | public List<AppUser> getSubordinate(Long id){ |
| | | List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getDelFlag, 0)); |
| | | List<AppUser> result = new ArrayList<>(); |
| | | List<Long> ids = new ArrayList<>(); |
| | | ids.add(id); |
| | | return getSubordinate(list, ids, result); |
| | | } |
| | | |
| | | public List<AppUser> getSubordinate(List<AppUser> list, List<Long> ids, List<AppUser> result){ |
| | | List<Long> idss = new ArrayList<>(); |
| | | for (Long id : ids) { |
| | | List<AppUser> collect = list.stream().filter(s -> s.getInviteUserId().equals(id)).collect(Collectors.toList()); |
| | | if(collect.size() == 0){ |
| | | return result; |
| | | }else{ |
| | | result.addAll(collect); |
| | | List<Long> collect1 = collect.stream().map(AppUser::getId).collect(Collectors.toList()); |
| | | idss.addAll(collect1); |
| | | } |
| | | } |
| | | return getSubordinate(list, idss, result); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | //使用地图获取省市区数据 |
| | | String longitude = nearbyReferrer.getLongitude(); |
| | | String latitude = nearbyReferrer.getLatitude(); |
| | | String cityCode = ""; |
| | | String cityCode = "510100"; // TODO 待完善 |
| | | List<NearbyReferrerVo> list = this.baseMapper.getNearbyReferrer(cityCode, nearbyReferrer); |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public List<AppUser> getUserAncestorList(Long id, List<AppUser> list) { |
| | | if (list == null) { |
| | | list = new ArrayList<>(); |
| | | } |
| | | |
| | | Set<Long> visitedIds = new HashSet<>(); |
| | | Long currentId = id; |
| | | |
| | | while (currentId != null && !visitedIds.contains(currentId)) { |
| | | AppUser appUser = getById(currentId); |
| | | if (appUser == null) { |
| | | break; // 如果用户不存在,终止循环 |
| | | } |
| | | |
| | | Long inviteUserId = appUser.getInviteUserId(); |
| | | if (inviteUserId != null) { |
| | | AppUser invitedUser = getById(inviteUserId); |
| | | if (invitedUser != null) { |
| | | list.add(invitedUser); |
| | | visitedIds.add(currentId); |
| | | currentId = inviteUserId; |
| | | } else { |
| | | break; // 如果邀请用户不存在,终止循环 |
| | | } |
| | | } else { |
| | | break; // 如果没有邀请用户,终止循环 |
| | | } |
| | | } |
| | | |
| | | return list; |
| | | } |
| | | |
| | | @Override |
| | | public AppUser getSuperiorLeader(Long id) { |
| | | AppUser appUser = getById(id); |
| | | Long inviteUserId = appUser.getInviteUserId(); |
| | | AppUser inviteUser = getById(inviteUserId); |
| | | if (inviteUser == null){ |
| | | return null; |
| | | } |
| | | if (inviteUser.getVipId() > 3) { |
| | | return inviteUser; |
| | | }else { |
| | | getSuperiorLeader(inviteUserId); |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 定时解绑推广人 |
| | | */ |
| | | @Override |
| | | public void unbindThePromoter() { |
| | | //注册X天后没有升级成黄金会员则自动解绑推广人 |
| | | VipSetting vipSetting = vipSettingClient.getVipSetting(1).getData(); |
| | | Integer vipCancelDay = vipSetting.getVipCancelDay(); |
| | | Integer vipChangeDay = vipSetting.getVipChangeDay(); |
| | | List<AppUser> list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getVipId, 1).eq(AppUser::getDelFlag, 0).isNotNull(AppUser::getInviteUserId) |
| | | .eq(AppUser::getStatus, 1).last(" and (UNIX_TIMESTAMP(create_time) + " + vipCancelDay + ") <= UNIX_TIMESTAMP()")); |
| | | for (AppUser appUser : list) { |
| | | appUser.setInviteUserId(null); |
| | | appUser.setShopId(null); |
| | | this.updateById(appUser); |
| | | } |
| | | |
| | | //可更换推广人 |
| | | list = this.list(new LambdaQueryWrapper<AppUser>().eq(AppUser::getVipId, 1).eq(AppUser::getDelFlag, 0).eq(AppUser::getChangePromoter, 0) |
| | | .isNull(AppUser::getLastShopTime).eq(AppUser::getStatus, 1).last(" and (UNIX_TIMESTAMP(create_time) + " + vipCancelDay + ") <= UNIX_TIMESTAMP()")); |
| | | for (AppUser appUser : list) { |
| | | appUser.setChangePromoter(1); |
| | | this.updateById(appUser); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 在线记录操作,用于赠送积分 |
| | | */ |
| | | @Override |
| | | public void onlineRecord() { |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | Object cacheObject = redisService.getCacheObject("ONLINE_" + userid); |
| | | if(null == cacheObject){ |
| | | redisService.setCacheObject("ONLINE_" + userid, 0, 15L, TimeUnit.MINUTES); |
| | | }else{ |
| | | Long duration = (Long) cacheObject; |
| | | duration += 10; |
| | | //满足一个小时,开始发放积分,计时归0 |
| | | if(60 >= duration){ |
| | | redisService.setCacheObject("ONLINE_" + userid, 0, 15L, TimeUnit.MINUTES); |
| | | AppUser appUser = this.getById(userid); |
| | | PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData(); |
| | | if(null != pointSetting){ |
| | | int hourPoint = pointSetting.getHourPoint().intValue(); |
| | | Integer lavePoint = appUser.getLavePoint(); |
| | | appUser.setTotalPoint(appUser.getTotalPoint() + hourPoint); |
| | | appUser.setLavePoint(appUser.getLavePoint() + hourPoint); |
| | | this.updateById(appUser); |
| | | //添加积分变动记录 |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(9); |
| | | userPoint.setHistoricalPoint(lavePoint); |
| | | userPoint.setVariablePoint(hourPoint); |
| | | userPoint.setBalance(appUser.getLavePoint()); |
| | | userPoint.setCreateTime(LocalDateTime.now()); |
| | | userPoint.setAppUserId(appUser.getId()); |
| | | userPointService.save(userPoint); |
| | | } |
| | | }else{ |
| | | redisService.setCacheObject("ONLINE_" + userid, duration, 15L, TimeUnit.MINUTES); |
| | | } |
| | | } |
| | | } |
| | | |
| | | @Override |
| | | public IPage<AppUser> getAppuserPage(Integer pageNum, Integer pageSize, AppUser appUser) { |
| | | if (StringUtils.isNotEmpty(appUser.getShopName())){ |
| | | R<Set<Integer>> shopR = shopClient.getShopIdByName(appUser.getShopName()); |
| | | if (R.isSuccess(shopR)){ |
| | | Set<Integer> shopIds = shopR.getData(); |
| | | if (!CollectionUtils.isEmpty(shopIds)){ |
| | | appUser.setShopIds(shopIds); |
| | | } |
| | | } |
| | | } |
| | | return appUserMapper.getAppuserPage(new Page<>(pageNum, pageSize), appUser); |
| | | } |
| | | } |