1.
phpcjl
2024-12-09 08f4689b4727279b3fe34aef94beaab3426e11d3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package com.ruoyi.account.service.impl;
 
import cn.hutool.core.collection.CollectionUtil;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.service.AppUserService;
import com.ruoyi.account.service.VipCenterService;
import com.ruoyi.account.service.VipSettingService;
import com.ruoyi.common.core.domain.R;
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.VipGood;
import com.ruoyi.other.api.domain.VipSetting;
import com.ruoyi.other.api.feignClient.VipGoodClient;
import org.springframework.stereotype.Service;
 
import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
 
@Service
public class VipCenterServiceImpl implements VipCenterService {
    @Resource
    private AppUserService appUserService;
    @Resource
    private RemoteOrderGoodsClient remoteOrderGoodsClient;
    @Resource
    private VipGoodClient vipGoodClient;
    @Resource
    private VipSettingService vipSettingService;
 
    @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;
                }
            }
            return true;
        }
 
        return false;
    }
 
    @Override
    public Boolean checkReadyToBeAgent(Long userId) {
        return false;
    }
 
    @Override
    public Boolean checkReadyToBeTotalAgent(Long userId) {
        return false;
    }
 
    @Override
    public Boolean checkReadyToBePartner(Long userId) {
        return false;
    }
}