From acb1b57cdf0f160b802f31c4f41b4daf4d2e9ce6 Mon Sep 17 00:00:00 2001
From: puzhibing <393733352@qq.com>
Date: 星期四, 19 十二月 2024 10:30:08 +0800
Subject: [PATCH] 合并代码
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/VipCenterServiceImpl.java | 323 +++++++++++++++++++++++++++++++++++++++++++++++------
1 files changed, 284 insertions(+), 39 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/VipCenterServiceImpl.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/VipCenterServiceImpl.java
index 5071a86..c30b1d6 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/VipCenterServiceImpl.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/service/impl/VipCenterServiceImpl.java
@@ -8,16 +8,24 @@
import com.ruoyi.account.service.VipCenterService;
import com.ruoyi.account.service.VipSettingService;
import com.ruoyi.common.core.domain.R;
+import com.ruoyi.common.core.exception.ServiceException;
+import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.feignClient.RemoteOrderGoodsClient;
import com.ruoyi.order.model.Order;
import com.ruoyi.other.api.domain.Goods;
+import com.ruoyi.other.api.domain.Shop;
import com.ruoyi.other.api.domain.VipGood;
import com.ruoyi.other.api.domain.VipSetting;
+import com.ruoyi.other.api.feignClient.GoodsClient;
+import com.ruoyi.other.api.feignClient.ShopClient;
import com.ruoyi.other.api.feignClient.VipGoodClient;
+import com.ruoyi.system.api.model.LoginUser;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
+import java.util.Map;
+import java.util.Set;
import java.util.stream.Collectors;
@Service
@@ -30,50 +38,71 @@
private VipGoodClient vipGoodClient;
@Resource
private VipSettingService vipSettingService;
+ @Resource
+ private ShopClient shopClient;
+ @Resource
+ private TokenService tokenService;
+ @Resource
+ private GoodsClient goodsClient;
+
@Override
public Boolean checkReadyToBeProxy(Long userId,Integer vipId) {
AppUser appUser = appUserService.getById(userId);
- VipSetting vipSetting = vipSettingService.getVipSettingById(vipId);
- if (vipSetting.getVipLevelUpShopRole() == 0){
- return false;
- }
- Integer vipLevelUpShop = vipSetting.getVipLevelUpShop();
- if (appUser.getShopPoint() >= vipLevelUpShop){
- return true;
- }
- Integer vipLevelUpShare = vipSetting.getVipLevelUpShare();
- if (appUser.getSharePoint() >= vipLevelUpShare){
- return true;
- }
-
- // 当前用户的直推用户
- List<AppUser> bottomUsers = appUserService.list(new LambdaQueryWrapper<AppUser>()
- .eq(AppUser::getInviteUserId, userId)
- .eq(AppUser::getVipId,3));
- if (bottomUsers.size() >= 5){
- return true;
- }
-
- // 是否购买指定商品
- R<List<VipGood>> vipGoodsByVipId = vipGoodClient.getVipGoodsByVipId(4);
- if (R.isError(vipGoodsByVipId)){
- throw new RuntimeException("根据会员id获取会员购买商品失败:" + vipGoodsByVipId.getMsg());
- }
- List<VipGood> vipGoodList = vipGoodsByVipId.getData();
- if (CollectionUtil.isNotEmpty(vipGoodList)){
- List<String> goodJsonList = vipGoodList.stream().map(VipGood::getGoodJson).collect(Collectors.toList());
- for (String goodJson : goodJsonList) {
- Goods goods = JSONObject.parseObject(goodJson, Goods.class);
- R<List<Order>> orderR = remoteOrderGoodsClient.getOrderListByUserIdAndGoodsId(userId, goods.getId());
- if (R.isError(orderR)){
- throw new RuntimeException("根据用户id和商品id获取订单失败:" + orderR.getMsg());
- }
- if (CollectionUtil.isEmpty(orderR.getData())){
- return false;
- }
+ // 消费积分
+ Integer shopPoint = appUser.getShopPoint();
+ // 返佣积分
+ Integer sharePoint = appUser.getSharePoint();
+ // 准代理会员设置
+ VipSetting vipSetting = vipSettingService.getVipSettingById(4);
+ // 获取通过消费积分达成会员等级的开关
+ Integer vipLevelUpShopRole = vipSetting.getVipLevelUpShopRole();
+ if (vipLevelUpShopRole == 1){
+ // 消费积分阈值
+ Integer vipLevelUpShop = vipSetting.getVipLevelUpShop();
+ // 返佣积分阈值
+ Integer vipLevelUpShare = vipSetting.getVipLevelUpShare();
+ // 判断是否满足消费积分和返佣积分
+ if (shopPoint >=vipLevelUpShop && sharePoint >= vipLevelUpShare){
+ return true;
}
- return true;
+ }
+
+ Integer vipLevelUpNumRole = vipSetting.getVipLevelUpNumRole();
+ if (vipLevelUpNumRole == 1){
+ // 直推钻石用户数阈值
+ Integer vipDirectNum = vipSetting.getVipDirectNum();
+ // 获取用户直推钻石用户数量
+ long userDiamondsCount = appUserService.count(new LambdaQueryWrapper<AppUser>()
+ .eq(AppUser::getInviteUserId, userId)
+ .eq(AppUser::getVipId, 3));
+ // 判断是否满足直推钻石用户数量
+ if (userDiamondsCount >= vipDirectNum){
+ return true;
+ }
+ }
+ // 获取指定购买商品
+ R<List<VipGood>> vipGoodsByVipId = vipGoodClient.getVipGoodsByVipId(4);
+ if (R.isSuccess(vipGoodsByVipId)){
+ List<VipGood> vipGoods = vipGoodsByVipId.getData();
+ if (CollectionUtil.isNotEmpty(vipGoods)){
+ for (VipGood vipGood : vipGoods) {
+ Integer goodId = vipGood.getGoodId();
+ R<Goods> goodsR = goodsClient.getGoodsById(goodId);
+ if (R.isError(goodsR)){
+ throw new ServiceException("商品信息获取失败");
+ }
+ Goods goods = goodsR.getData();
+ R<List<Order>> orderListByUserIdAndGoodsId = remoteOrderGoodsClient.getOrderListByUserIdAndGoodsId(userId, goods.getId());
+ if (R.isSuccess(orderListByUserIdAndGoodsId)){
+ List<Order> orderList = orderListByUserIdAndGoodsId.getData();
+ if (CollectionUtil.isEmpty(orderList)){
+ return false;
+ }
+ }
+ }
+ return true;
+ }
}
return false;
@@ -81,16 +110,232 @@
@Override
public Boolean checkReadyToBeAgent(Long userId) {
+ AppUser appUser = appUserService.getById(userId);
+ // 消费积分
+ Integer shopPoint = appUser.getShopPoint();
+ // 返佣积分
+ Integer sharePoint = appUser.getSharePoint();
+ // 代理会员设置
+ VipSetting vipSetting = vipSettingService.getVipSettingById(5);
+ // 获取通过消费积分达成会员等级的开关
+ Integer vipLevelUpShopRole = vipSetting.getVipLevelUpShopRole();
+ if (vipLevelUpShopRole == 1){
+ // 消费积分阈值
+ Integer vipLevelUpShop = vipSetting.getVipLevelUpShop();
+ // 返佣积分阈值
+ Integer vipLevelUpShare = vipSetting.getVipLevelUpShare();
+ // 判断是否满足消费积分和返佣积分
+ if (shopPoint >=vipLevelUpShop && sharePoint >= vipLevelUpShare){
+ return true;
+ }
+ }
+
+ Integer vipLevelUpNumRole = vipSetting.getVipLevelUpNumRole();
+ if (vipLevelUpNumRole == 1){
+ // 直推钻石用户数阈值
+ Integer vipDirectNum = vipSetting.getVipDirectNum();
+ // 获取用户直推钻石用户数量
+ long userDiamondsCount = appUserService.count(new LambdaQueryWrapper<AppUser>()
+ .eq(AppUser::getInviteUserId, userId)
+ .eq(AppUser::getVipId, 3));
+ // 判断是否满足直推钻石用户数量
+ if (userDiamondsCount >= vipDirectNum){
+ return true;
+ }
+ }
+
+ R<List<VipGood>> vipGoodsByVipId = vipGoodClient.getVipGoodsByVipId(5);
+ if (R.isSuccess(vipGoodsByVipId)){
+ List<VipGood> vipGoods = vipGoodsByVipId.getData();
+ if (CollectionUtil.isNotEmpty(vipGoods)){
+ for (VipGood vipGood : vipGoods) {
+ R<Goods> goodsR = goodsClient.getGoodsById(vipGood.getGoodId());
+ if (R.isError(goodsR)){
+ throw new ServiceException("商品信息获取失败");
+ }
+
+ Goods goods = goodsR.getData();
+ R<List<Order>> orderListByUserIdAndGoodsId = remoteOrderGoodsClient.getOrderListByUserIdAndGoodsId(userId, goods.getId());
+ if (R.isSuccess(orderListByUserIdAndGoodsId)){
+ List<Order> orderList = orderListByUserIdAndGoodsId.getData();
+ if (CollectionUtil.isEmpty(orderList)){
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ }
+
return false;
}
@Override
public Boolean checkReadyToBeTotalAgent(Long userId) {
+ AppUser appUser = appUserService.getById(userId);
+ // 获取总代会员设置
+ VipSetting vipSetting = vipSettingService.getVipSettingById(6);
+ // 获取会员等级是否必须达到代理
+ Integer vipLevelUpProxyRole = vipSetting.getVipLevelUpProxyRole();
+ if (vipLevelUpProxyRole == 1 && appUser.getVipId() == 5){
+ return true;
+ }
+
+ // 消费积分
+ Integer shopPoint = appUser.getShopPoint();
+ // 返佣积分
+ Integer sharePoint = appUser.getSharePoint();
+ // 获取通过消费积分达成会员等级的开关
+ Integer vipLevelUpShopRole = vipSetting.getVipLevelUpShopRole();
+ if (vipLevelUpShopRole == 1){
+ // 消费积分阈值
+ Integer vipLevelUpShop = vipSetting.getVipLevelUpShop();
+ // 返佣积分阈值
+ Integer vipLevelUpShare = vipSetting.getVipLevelUpShare();
+ // 判断是否满足消费积分和返佣积分
+ if (shopPoint >=vipLevelUpShop && sharePoint >= vipLevelUpShare){
+ return true;
+ }
+ }
+
+ Integer vipLevelUpNumRole = vipSetting.getVipLevelUpNumRole();
+ if (vipLevelUpNumRole == 1){
+ // 直推代理用户数阈值
+ Integer vipDirectNum = vipSetting.getVipDirectNum();
+ // 准代理用户数阈值
+ Integer vipDirectVipNum = vipSetting.getVipDirectVipNum();
+ // 获取用户直推代理用户数量
+ List<AppUser> userAgentList = appUserService.list(new LambdaQueryWrapper<AppUser>()
+ .eq(AppUser::getInviteUserId, userId)
+ .eq(AppUser::getVipId, 5));
+
+ // 代理下的准代理数量
+ List<Long> userQuasiAgent = userAgentList.stream().map(AppUser::getId).collect(Collectors.toList());
+ long userQuasiAgentCount = appUserService.count(new LambdaQueryWrapper<AppUser>()
+ .in(AppUser::getInviteUserId, userQuasiAgent)
+ .eq(AppUser::getVipId, 4));
+
+ // 判断是否满足直推代理用户数量和准代理数量
+ if (userAgentList.size() >= vipDirectNum && userQuasiAgentCount >= vipDirectVipNum){
+ return true;
+ }
+ }
+ // 获取指定购买商品
+ R<List<VipGood>> vipGoodsByVipId = vipGoodClient.getVipGoodsByVipId(5);
+ if (R.isSuccess(vipGoodsByVipId)){
+ List<VipGood> vipGoods = vipGoodsByVipId.getData();
+ if (CollectionUtil.isNotEmpty(vipGoods)){
+ for (VipGood vipGood : vipGoods) {
+ R<Goods> goodsR = goodsClient.getGoodsById(vipGood.getGoodId());
+ if (R.isError(goodsR)){
+ throw new ServiceException("商品信息获取失败");
+ }
+ Goods goods = goodsR.getData();
+ R<List<Order>> orderListByUserIdAndGoodsId = remoteOrderGoodsClient.getOrderListByUserIdAndGoodsId(userId, goods.getId());
+ if (R.isSuccess(orderListByUserIdAndGoodsId)){
+ List<Order> orderList = orderListByUserIdAndGoodsId.getData();
+ if (CollectionUtil.isEmpty(orderList)){
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ }
+
return false;
}
@Override
public Boolean checkReadyToBePartner(Long userId) {
+ AppUser appUser = appUserService.getById(userId);
+ // 消费积分
+ Integer shopPoint = appUser.getShopPoint();
+ // 返佣积分
+ Integer sharePoint = appUser.getSharePoint();
+ // 合伙人会员设置
+ VipSetting vipSetting = vipSettingService.getVipSettingById(7);
+ // 获取通过消费积分达成会员等级的开关
+ Integer vipLevelUpShopRole = vipSetting.getVipLevelUpShopRole();
+ if (vipLevelUpShopRole == 1){
+ // 消费积分阈值
+ Integer vipLevelUpShop = vipSetting.getVipLevelUpShop();
+ // 返佣积分阈值
+ Integer vipLevelUpShare = vipSetting.getVipLevelUpShare();
+ // 判断是否满足消费积分和返佣积分
+ if (shopPoint >=vipLevelUpShop && sharePoint >= vipLevelUpShare){
+ return true;
+ }
+
+ Integer vipLevelUpNumRole = vipSetting.getVipLevelUpNumRole();
+ if (vipLevelUpNumRole == 1){
+ // 直推代理用户数阈值
+ Integer vipDirectNum = vipSetting.getVipDirectNum();
+ // 准代理用户数阈值
+ Integer vipDirectVipNum = vipSetting.getVipDirectVipNum();
+ // 总代用户数阈值
+ Integer vipTeamVipNum = vipSetting.getVipTeamVipNum();
+ // 获取开店数量阈值
+ Integer vipOpenShopNum = vipSetting.getVipOpenShopNum();
+
+ // 获取直推用户有超过指定门店数量的用户
+ List<Long> userShopList = appUserService.list(new LambdaQueryWrapper<AppUser>()
+ .eq(AppUser::getInviteUserId, userId))
+ .stream().map(AppUser::getId).collect(Collectors.toList());
+ if (CollectionUtil.isNotEmpty(userShopList)){
+ R<List<Shop>> r = shopClient.getShopByUserIds(userShopList);
+ List<Shop> shopList = r.getData();
+ if (CollectionUtil.isNotEmpty(shopList)){
+ Map<Long, List<Shop>> shopUserMap = shopList.stream().collect(Collectors.groupingBy(Shop::getAppUserId));
+
+ // 查找 list 长度大于 3 的 key
+ Set<Long> shopUserIdSet = shopUserMap.entrySet().stream()
+ .filter(entry -> entry.getValue().size() >= vipOpenShopNum)
+ .map(Map.Entry::getKey)
+ .collect(Collectors.toSet());
+
+ // 获取用户直推总代理数量
+ List<AppUser> userTotalAgentList = appUserService.list(new LambdaQueryWrapper<AppUser>()
+ .in(AppUser::getInviteUserId, shopUserIdSet)
+ .eq(AppUser::getVipId, 6));
+
+ // 获取用户直推代理用户数量
+ List<AppUser> userAgentList = appUserService.list(new LambdaQueryWrapper<AppUser>()
+ .in(AppUser::getInviteUserId, shopUserIdSet)
+ .eq(AppUser::getVipId, 5));
+
+ // 代理下的准代理数量
+ List<Long> userQuasiAgent = userAgentList.stream().map(AppUser::getId).collect(Collectors.toList());
+ long userQuasiAgentCount = appUserService.count(new LambdaQueryWrapper<AppUser>()
+ .in(AppUser::getInviteUserId, userQuasiAgent)
+ .eq(AppUser::getVipId, 4));
+
+ // 判断是否满足直推代理用户数量和准代理数量
+ return userTotalAgentList.size() >= vipTeamVipNum && userAgentList.size() >= vipDirectNum &&
+ userQuasiAgentCount >= vipDirectVipNum;
+
+ }
+
+ }
+ }
+ }
return false;
}
+
+ @Override
+ public Boolean check(Integer type) {
+ LoginUser loginUser = tokenService.getLoginUser();
+ Long userid = loginUser.getUserid();
+ if (type == 4){
+ return checkReadyToBeProxy(userid, type);
+ }else if (type == 5){
+ return checkReadyToBeAgent(userid);
+ }else if (type == 6){
+ return checkReadyToBeTotalAgent(userid);
+ }else if (type == 7){
+ return checkReadyToBePartner(userid);
+ }else {
+ throw new ServiceException("参数错误");
+ }
+ }
}
--
Gitblit v1.7.1