From 1f09f6daaf73bc83cceb4ae22b862b7b365635cf Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期四, 03 四月 2025 19:59:17 +0800
Subject: [PATCH] 修改反馈文档bug

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/AppUserServiceImpl.java |  202 ++++++++++++++++++++++++++++++--------------------
 1 files changed, 122 insertions(+), 80 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 60b63e3..abd5d56 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
@@ -30,6 +30,7 @@
 import com.ruoyi.system.api.feignClient.SysUserClient;
 import com.ruoyi.system.api.model.LoginUser;
 import lombok.extern.slf4j.Slf4j;
+import org.redisson.RedissonLock;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.data.redis.core.RedisTemplate;
 import org.springframework.stereotype.Service;
@@ -111,6 +112,9 @@
 	
 	@Resource
 	private OrderClient orderClient;
+	
+	@Resource
+	private IAppUserGiveawayTemporaryService appUserGiveawayTemporaryService;
 
 
 	/**
@@ -128,39 +132,52 @@
 		}
 		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);
-			loginVo.setPhone(purePhoneNumber);
-			return R.ok(loginVo);
-		}
-		//账户被冻结,给出提示
-		if(2 == appUser.getStatus()){
-			return R.fail("账户已被冻结,请联系管理员!");
-		}
 		LoginVo loginVo = new LoginVo();
-		loginVo.setSkipPage(1);
-		loginVo.setFirstTime(false);
-		loginVo.setPhone(appUser.getPhone());
-		//构建token
-		LoginUser loginUser = new LoginUser();
-		loginUser.setUserid(appUser.getId());
-		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()));
 		
-		appUser.setLastLoginTime(LocalDateTime.now());
-		this.updateById(appUser);
-		return R.ok(loginVo);
+		String key = "login:" + openid;
+		Boolean hasKey = redisService.lock(key);
+		if(hasKey){
+			try {
+				//查询用户是否注册,没有注册则跳转到注册页面
+				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.setSkipPage(2);
+					loginVo.setPhone(purePhoneNumber);
+					return R.ok(loginVo);
+				}
+				//账户被冻结,给出提示
+				if(2 == appUser.getStatus()){
+					return R.fail("账户已被冻结,请联系管理员!");
+				}
+				loginVo.setSkipPage(1);
+				loginVo.setFirstTime(false);
+				loginVo.setPhone(appUser.getPhone());
+				//构建token
+				LoginUser loginUser = new LoginUser();
+				loginUser.setUserid(appUser.getId());
+				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()));
+				
+				appUser.setLastLoginTime(LocalDateTime.now());
+				this.updateById(appUser);
+				return R.ok(loginVo);
+			}catch (Exception e){
+				e.printStackTrace();
+			}finally {
+				redisService.unlock(key);
+			}
+		}else{
+			return R.fail("请稍后重试");
+		}
+		return R.fail("登录失败");
 	}
 	
 	
@@ -382,11 +399,10 @@
 				//构建积分流水记录
 				UserPoint userPoint = new UserPoint();
 				userPoint.setType(7);
-				userPoint.setHistoricalPoint(0);
 				userPoint.setVariablePoint(regisPoint);
-				userPoint.setBalance(appUser.getLavePoint());
 				userPoint.setCreateTime(LocalDateTime.now());
 				userPoint.setAppUserId(appUser.getId());
+				userPoint.setChangeDirection(1);
 				userPointService.save(userPoint);
 			}
 			//获取优惠券
@@ -433,11 +449,10 @@
 				if(newPoint > 0){
 					UserPoint userPoint = new UserPoint();
 					userPoint.setType(3);
-					userPoint.setHistoricalPoint(appUser2.getLavePoint() - newPoint);
 					userPoint.setVariablePoint(newPoint);
-					userPoint.setBalance(appUser2.getLavePoint());
 					userPoint.setCreateTime(LocalDateTime.now());
 					userPoint.setAppUserId(appUser2.getId());
+					userPoint.setChangeDirection(1);
 					userPointService.save(userPoint);
 				}
 				//变更等级
@@ -457,11 +472,10 @@
 					if(newPoint > 0){
 						UserPoint userPoint = new UserPoint();
 						userPoint.setType(3);
-						userPoint.setHistoricalPoint(appUser3.getLavePoint() - newPoint);
 						userPoint.setVariablePoint(newPoint);
-						userPoint.setBalance(appUser3.getLavePoint());
 						userPoint.setCreateTime(LocalDateTime.now());
 						userPoint.setAppUserId(appUser3.getId());
+						userPoint.setChangeDirection(1);
 						userPointService.save(userPoint);
 					}
 					//变更等级
@@ -501,7 +515,7 @@
 		//钻石会员
 		VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData();
 		//消费积分满足升级
-		if(1 == vipSetting3.getVipLevelUpShopRole() && appUser.getShopPoint() >= vipSetting3.getVipLevelUpShop() && appUser.getVipId() < 3){
+		if(1 == vipSetting3.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting3.getVipLevelUpShop()) >= 0 && appUser.getVipId() < 3){
 			appUser.setVipId(3);
 			this.updateById(appUser);
 			//添加等级变化记录
@@ -516,7 +530,10 @@
 			return;
 		}
 		//返佣积分满足升级
-		if(1 == vipSetting3.getVipLevelUpShareRole() && appUser.getSharePoint() >= vipSetting3.getVipLevelUpShare() && appUser.getVipId() < 3){
+		List<AppUserGiveawayTemporary> list = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>().eq(AppUserGiveawayTemporary::getAppUserId, appUser.getId()));
+		int sum = list.stream().mapToInt(AppUserGiveawayTemporary::getSharePoint).sum();
+		int sharePoin = appUser.getSharePoint() + sum;
+		if(1 == vipSetting3.getVipLevelUpShareRole() && sharePoin >= vipSetting3.getVipLevelUpShare() && appUser.getVipId() < 3){
 			appUser.setVipId(3);
 			this.updateById(appUser);
 			//添加等级变化记录
@@ -559,7 +576,7 @@
 		//黄金会员
 		VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData();
 		//消费积分满足升级
-		if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint() >= vipSetting2.getVipLevelUpShop() && appUser.getVipId() < 2){
+		if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting2.getVipLevelUpShop()) >= 0 && appUser.getVipId() < 2){
 			appUser.setVipId(2);
 			this.updateById(appUser);
 			//添加等级变化记录
@@ -574,7 +591,7 @@
 			return;
 		}
 		//返佣积分满足升级
-		if(1 == vipSetting2.getVipLevelUpShareRole() && appUser.getSharePoint() >= vipSetting2.getVipLevelUpShare() && appUser.getVipId() < 2){
+		if(1 == vipSetting2.getVipLevelUpShareRole() && appUser.getSharePoint().compareTo(vipSetting2.getVipLevelUpShare()) >= 0 && appUser.getVipId() < 2){
 			appUser.setVipId(2);
 			this.updateById(appUser);
 			//添加等级变化记录
@@ -610,7 +627,6 @@
 				userChangeLog.setAfterVipId(appUser.getVipId());
 				userChangeLog.setChangeType(1);
 				userChangeLogService.save(userChangeLog);
-				return;
 			}
 		}
 	}
@@ -747,10 +763,38 @@
 	public void vipDemotion(Long appUserId) {
 		AppUser appUser = this.getById(appUserId);
 		Integer vipId = appUser.getVipId();
+		//钻石会员
+		VipSetting vipSetting3 = vipSettingClient.getVipSetting(3).getData();
+		if(1 == vipSetting3.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting3.getVipLevelUpShop()) >= 0 && appUser.getVipId() == 3){
+			return;
+		}
+		//返佣积分满足升级
+		List<AppUserGiveawayTemporary> list = appUserGiveawayTemporaryService.list(new LambdaQueryWrapper<AppUserGiveawayTemporary>().eq(AppUserGiveawayTemporary::getAppUserId, appUser.getId()));
+		int sum = list.stream().mapToInt(AppUserGiveawayTemporary::getSharePoint).sum();
+		int sharePoin = appUser.getSharePoint() + sum;
+		if(1 == vipSetting3.getVipLevelUpShareRole() && sharePoin >= vipSetting3.getVipLevelUpShare() && appUser.getVipId() == 3){
+			return;
+		}
+		//下级人数满足升级
+		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, appUserId));
+			//团队用户数
+			List<AppUser> subordinate = getSubordinate(appUserId);
+			if(vipDirectNum <= count || vipTeamNum <= subordinate.size()){
+				return;
+			}
+		}
+		
+		
 		//黄金会员
 		VipSetting vipSetting2 = vipSettingClient.getVipSetting(2).getData();
 		//消费积分满足升级
-		if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint() >= vipSetting2.getVipLevelUpShop() && appUser.getVipId() > 2){
+		if(1 == vipSetting2.getVipLevelUpShopRole() && appUser.getShopPoint().compareTo(vipSetting2.getVipLevelUpShop()) >= 0 && appUser.getVipId() >= 2){
 			appUser.setVipId(2);
 			this.updateById(appUser);
 			//添加等级变化记录
@@ -765,7 +809,7 @@
 			return;
 		}
 		//返佣积分满足升级
-		if(1 == vipSetting2.getVipLevelUpShareRole() && appUser.getSharePoint() >= vipSetting2.getVipLevelUpShare() && appUser.getVipId() > 2){
+		if(1 == vipSetting2.getVipLevelUpShareRole() && sharePoin >= vipSetting2.getVipLevelUpShare() && appUser.getVipId() >= 2){
 			appUser.setVipId(2);
 			this.updateById(appUser);
 			//添加等级变化记录
@@ -780,10 +824,10 @@
 			return;
 		}
 		//下级人数满足升级
-		Integer vipLevelUpNumRole = vipSetting2.getVipLevelUpNumRole();
-		Integer vipDirectNum = vipSetting2.getVipDirectNum();
-		Integer vipTeamNum = vipSetting2.getVipTeamNum();
-		if(1 == vipLevelUpNumRole && appUser.getVipId() > 2){
+		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, appUserId));
@@ -804,19 +848,17 @@
 				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);
-		}
+		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);
 	}
 	
 	/**
@@ -1041,9 +1083,9 @@
 			JSONObject jsonObject = (JSONObject) cacheObject;
 			long time = System.currentTimeMillis() - jsonObject.getInteger("time");
 			Integer online = jsonObject.getInteger("online");
-			online += 10;
-			//满足一个小时,开始发放积分,计时归0
-			if(time >= 3600000L && 60 <= online){
+			online++;
+			//时间满足1小时,并且次数记录满足6次(10分钟记录一次)
+			if(time >= 3600000 && 6 <= online){
 				jsonObject.put("time", System.currentTimeMillis());
 				jsonObject.put("online", 0);
 				redisService.setCacheObject("ONLINE_" + userid, jsonObject, 1L, TimeUnit.HOURS);
@@ -1055,29 +1097,29 @@
 					if(1 == pointSetting.getWorkPointOpen()){
 						hourPoint1 = new BigDecimal(hourPoint).multiply(pointSetting.getWorkPoint().divide(new BigDecimal(100))).intValue();
 					}
-					Integer lavePoint = appUser.getLavePoint();
-					appUser.setTotalPoint(appUser.getTotalPoint() + hourPoint);
-					appUser.setLavePoint(appUser.getLavePoint() + hourPoint);
-					appUser.setAvailablePoint(appUser.getAvailablePoint() + hourPoint1);
-					appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + hourPoint1);
-					if(null != pointSetting && 1 == pointSetting.getWorkPointGift()){
-						appUser.setTransferablePoint(appUser.getTransferablePoint() + hourPoint1);
-					}
-					appUser.setTotalHourPoint(appUser.getTotalHourPoint() + hourPoint);
-					this.updateById(appUser);
 					//添加积分变动记录
 					if(hourPoint > 0){
+						Integer lavePoint = appUser.getLavePoint();
+						appUser.setTotalPoint(appUser.getTotalPoint() + hourPoint);
+						appUser.setLavePoint(appUser.getLavePoint() + hourPoint);
+						appUser.setAvailablePoint(appUser.getAvailablePoint() + hourPoint1);
+						appUser.setTotalAvailablePoint(appUser.getTotalAvailablePoint() + hourPoint1);
+						if(null != pointSetting && 1 == pointSetting.getWorkPointGift()){
+							appUser.setTransferablePoint(appUser.getTransferablePoint() + hourPoint1);
+						}
+						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());
+						userPoint.setChangeDirection(1);
 						userPointService.save(userPoint);
+						//变更等级
+						vipUpgrade(appUser.getId());
 					}
-					//变更等级
-					vipUpgrade(appUser.getId());
 				}
 			}else{
 				jsonObject.put("online", online);
@@ -1102,8 +1144,8 @@
 		return appUserMapper.getAppuserPage(new Page<>(pageNum, pageSize), appUser, shopId, userId);
 	}
 	@Override
-	public IPage<AppUser> getAppuserPage1(Integer pageNum, Integer pageSize, AppUser appUser,Integer objectId,List<Long> userIds) {
-		return appUserMapper.getAppuserPage1(new Page<>(pageNum, pageSize), appUser,objectId,userIds);
+	public IPage<AppUser> getAppuserPage1(Integer pageNum, Integer pageSize, AppUser appUser,List<Long> userIds) {
+		return appUserMapper.getAppuserPage1(new Page<>(pageNum, pageSize), appUser,userIds);
 	}
 	
 	

--
Gitblit v1.7.1