| | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | 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.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.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.redis.service.RedisService; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import com.ruoyi.other.api.domain.Shop; |
| | | import com.ruoyi.other.api.domain.VipSetting; |
| | | 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.Value; |
| | | import org.springframework.stereotype.Service; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | import java.util.*; |
| | | import java.util.stream.Collectors; |
| | | |
| | | import static com.sun.xml.internal.ws.api.model.wsdl.WSDLBoundOperation.ANONYMOUS.optional; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Resource |
| | | private SysUserClient sysUserClient; |
| | | |
| | | @Resource |
| | | private VipSettingClient vipSettingClient; |
| | | |
| | | @Resource |
| | | private UserChangeLogService userChangeLogService; |
| | | |
| | | @Value("${file.upload.location}") |
| | | private String filePath; |
| | | |
| | | @Value("${file.upload.accessPath}") |
| | | private String accessPath; |
| | | |
| | | |
| | | |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | this.updateById(appUser); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | |
| | | Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser); |
| | | loginVo.setToken(tokenApplet.get("access_token").toString()); |
| | | loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString())); |
| | | |
| | | appUser.setLastLoginTime(LocalDateTime.now()); |
| | | this.updateById(appUser); |
| | | return R.ok(loginVo); |
| | | } |
| | | |
| | |
| | | appUser.setTotalDistributionAmount(BigDecimal.ZERO); |
| | | appUser.setBalance(BigDecimal.ZERO); |
| | | appUser.setLavePoint(0); |
| | | appUser.setTotalPoint(0); |
| | | //根据平台的配置未达标,则标注为可修改推广人 |
| | | appUser.setChangePromoter(0); |
| | | appUser.setLongitude(registerAccount.getLongitude()); |
| | |
| | | // 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(); |
| | |
| | | |
| | | |
| | | /** |
| | | * 会员等级变化 |
| | | */ |
| | | 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); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 递归查询顶级推广人 |
| | | * @param id |
| | | * @return |
| | |
| | | } |
| | | 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); |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | /** |
| | |
| | | } |
| | | 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); |
| | | } |
| | | } |
| | | } |