From a23f0ba99b7e3c1ad270dd5a263a6b48b4b8fb6f Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 16 一月 2025 20:48:43 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java |  121 +++++++++++++++++++++++++++++++++-------
 1 files changed, 100 insertions(+), 21 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java
index 0475c35..bb4bdf1 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java
@@ -22,6 +22,7 @@
 import com.ruoyi.common.core.domain.R;
 import com.ruoyi.common.core.utils.StringUtils;
 import com.ruoyi.common.core.web.page.PageInfo;
+import com.ruoyi.common.redis.annotation.DistributedLock;
 import com.ruoyi.common.redis.service.RedisService;
 import com.ruoyi.common.security.service.TokenService;
 import com.ruoyi.other.api.domain.*;
@@ -178,7 +179,8 @@
 		}
 		
 		//查询用户是否注册,没有注册则跳转到注册页面
-		AppUser appUser = this.getOne(new LambdaQueryWrapper<AppUser>().eq(AppUser::getPhone, mobileLogin.getPhone()).ne(AppUser::getStatus, 3).eq(AppUser::getDelFlag, 0));
+		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);
@@ -199,8 +201,7 @@
 		loginUser.setUsername(appUser.getName());
 		Map<String, Object> tokenApplet = tokenService.createTokenApplet(loginUser);
 		loginVo.setToken(tokenApplet.get("access_token").toString());
-			loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString()));
-		
+		loginVo.setFailureTime(Long.valueOf(tokenApplet.get("expires_in").toString()));
 		appUser.setLastLoginTime(LocalDateTime.now());
 		this.updateById(appUser);
 		return R.ok(loginVo);
@@ -246,8 +247,8 @@
 		redisService.setCacheObject(smsCode.getPhone(), code, 300L, TimeUnit.SECONDS);
 		return R.ok();
 	}
-	
-	
+
+
 	/**
 	 * 注册账号
 	 * @param registerAccount
@@ -607,7 +608,85 @@
 		}
 	}
 	
-	
+	/**
+	 * 处理会员降级
+	 * @param appUserId
+	 */
+	@Override
+	public void vipDemotion(Long appUserId) {
+		AppUser appUser = this.getById(appUserId);
+		Integer vipId = appUser.getVipId();
+		//黄金会员
+		VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData();
+		//消费积分满足升级
+		if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint() >= vipSetting2.getVipLevelUpShop() && appUser.getVipId() > 2){
+			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(0);
+			userChangeLogService.save(userChangeLog);
+			return;
+		}
+		//返佣积分满足升级
+		if(1 == vipSetting2.getVipLevelUpShareRole() && appUser.getSharePoint() >= vipSetting2.getVipLevelUpShare() && appUser.getVipId() > 2){
+			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(0);
+			userChangeLogService.save(userChangeLog);
+			return;
+		}
+		//下级人数满足升级
+		Integer vipLevelUpNumRole = vipSetting2.getVipLevelUpNumRole();
+		Integer vipDirectNum = vipSetting2.getVipDirectNum();
+		Integer 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, appUserId));
+			//团队用户数
+			List<AppUser> subordinate = getSubordinate(appUserId);
+			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(0);
+				userChangeLogService.save(userChangeLog);
+				return;
+			}
+		}
+		if(appUser.getVipId() > 2){
+			appUser.setVipId(1);
+			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(0);
+			userChangeLogService.save(userChangeLog);
+		}
+	}
 	
 	/**
 	 * 递归查询顶级推广人
@@ -819,13 +898,13 @@
 		Long userid = tokenService.getLoginUserApplet().getUserid();
 		Object cacheObject = redisService.getCacheObject("ONLINE_" + userid);
 		if(null == cacheObject){
-			redisService.setCacheObject("ONLINE_" + userid, 0, 15L, TimeUnit.MINUTES);
+			redisService.setCacheObject("ONLINE_" + userid, System.currentTimeMillis(), 1L, TimeUnit.HOURS);
 		}else{
-			Integer duration = (Integer) cacheObject;
-			duration += 10;
+			Long duration = (Long) cacheObject;
+			long time = (System.currentTimeMillis() - duration) / 3600000;
 			//满足一个小时,开始发放积分,计时归0
-			if(60 >= duration){
-				redisService.setCacheObject("ONLINE_" + userid, 0, 15L, TimeUnit.MINUTES);
+			if(1 >= time){
+				redisService.setCacheObject("ONLINE_" + userid, System.currentTimeMillis(), 1L, TimeUnit.HOURS);
 				AppUser appUser = this.getById(userid);
 				PointSetting pointSetting = pointSettingClient.getPointSetting(appUser.getVipId()).getData();
 				if(null != pointSetting){
@@ -845,19 +924,19 @@
 					appUser.setTotalHourPoint(appUser.getTotalHourPoint() + hourPoint);
 					this.updateById(appUser);
 					//添加积分变动记录
-					UserPoint userPoint = new UserPoint();
-					userPoint.setType(6);
-					userPoint.setHistoricalPoint(lavePoint);
-					userPoint.setVariablePoint(hourPoint);
-					userPoint.setBalance(appUser.getLavePoint());
-					userPoint.setCreateTime(LocalDateTime.now());
-					userPoint.setAppUserId(appUser.getId());
-					userPointService.save(userPoint);
+					if(hourPoint > 0){
+						UserPoint userPoint = new UserPoint();
+						userPoint.setType(6);
+						userPoint.setHistoricalPoint(lavePoint);
+						userPoint.setVariablePoint(hourPoint);
+						userPoint.setBalance(appUser.getLavePoint());
+						userPoint.setCreateTime(LocalDateTime.now());
+						userPoint.setAppUserId(appUser.getId());
+						userPointService.save(userPoint);
+					}
 					//变更等级
 					vipUpgrade(appUser.getId());
 				}
-			}else{
-				redisService.setCacheObject("ONLINE_" + userid, duration, 15L, TimeUnit.MINUTES);
 			}
 		}
 	}

--
Gitblit v1.7.1