1.
phpcjl
2024-12-06 8dd9330b2186ee83d372e23eb280466e4cef4ee4
1.
1个文件已删除
2个文件已修改
3个文件已添加
311 ■■■■ 已修改文件
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/VipGoodClientFallbackFactory.java 20 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/VipGoodClient.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenter.java 85 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java 163 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/vip/Level.java 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VipGoodController.java 18 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/factory/VipGoodClientFallbackFactory.java
New file
@@ -0,0 +1,20 @@
package com.ruoyi.other.api.factory;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.VipGood;
import com.ruoyi.other.api.feignClient.VipGoodClient;
import org.springframework.cloud.openfeign.FallbackFactory;
import java.util.List;
public class VipGoodClientFallbackFactory implements FallbackFactory<VipGoodClient> {
    @Override
    public VipGoodClient create(Throwable cause) {
        return new VipGoodClient() {
            @Override
            public R<List<VipGood>> getVipGoodsByVipId(Integer vipId) {
                return R.fail("根据会员id获取会员购买商品失败:" + cause.getMessage());
            }
        };
    }
}
ruoyi-api/ruoyi-api-other/src/main/java/com/ruoyi/other/api/feignClient/VipGoodClient.java
New file
@@ -0,0 +1,18 @@
package com.ruoyi.other.api.feignClient;
import com.ruoyi.common.core.constant.ServiceNameConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.other.api.domain.VipGood;
import com.ruoyi.other.api.factory.VipGoodClientFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
@FeignClient(contextId = "VipGoodClient", value = ServiceNameConstants.ORDER_SERVICE, fallbackFactory = VipGoodClientFallbackFactory.class)
public interface VipGoodClient {
    @GetMapping("/vip-good/getVipGoodsByVipId")
    public R<List<VipGood>> getVipGoodsByVipId(@RequestParam(value = "vipId") Integer vipId);
}
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenter.java
File was deleted
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
New file
@@ -0,0 +1,163 @@
package com.ruoyi.account.controller;
import com.alibaba.fastjson2.JSONObject;
import com.ruoyi.account.service.VipSettingService;
import com.ruoyi.account.vo.vip.Level;
import com.ruoyi.account.vo.vip.VipLevel;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.*;
import com.ruoyi.other.api.feignClient.BaseSettingClient;
import com.ruoyi.other.api.feignClient.GoodsVipClient;
import com.ruoyi.other.api.feignClient.RemoteVipSettingClient;
import com.ruoyi.other.api.feignClient.VipGoodClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/vipCenter")
@Api(tags = "小程序-会员中心")
@Log4j2
public class VipCenterController {
    @Resource
    private RemoteVipSettingClient remoteVipSettingClient;
    @Resource
    private BaseSettingClient baseSettingClient;
    @Resource
    private GoodsVipClient goodsVipClient;
    @Resource
    private VipSettingService vipSettingService;
    @Resource
    private TokenService tokenService;
    @Resource
    private VipGoodClient vipGoodClient;
    @GetMapping("getVipLevelList")
    @ApiOperation(value = "会员等级列表", tags = {"会员中心-小程序"})
    public R<VipLevel> vipLevelList() {
        try {
            R<List<VipSetting>> r = remoteVipSettingClient.list();
            if (!checkSuccess(r)) {
                return R.fail("会员等级获取失败");
            }
            List<VipSetting> vipSettingList = r.getData();
            if (vipSettingList == null || vipSettingList.isEmpty()) {
                return R.fail("会员等级获取失败");
            }
            R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(3);
            if (!checkSuccess(baseSettingR)) {
                log.error("【会员设置说明】获取失败:{}", baseSettingR.getMsg());
                return R.fail("会员等级获取失败");
            }
            BaseSetting baseSetting = baseSettingR.getData();
            if (baseSetting == null) {
                log.error("【会员设置说明】未设置");
                return R.fail("会员等级获取失败");
            }
            Long userid = tokenService.getLoginUserApplet().getUserid();
            VipSetting loginUserVipSetting = vipSettingService.getVipSettingByUserId(userid);
            VipLevel vipLevel = new VipLevel();
            List<Level> levelList = new ArrayList<>();
            // 批量获取 goodsVip 和 vipGoods
            List<Integer> vipIds = vipSettingList.stream().map(VipSetting::getId).collect(Collectors.toList());
            Map<Integer, R<GoodsVip>> goodsVipMap = getGoodsVips(vipIds);
            Map<Integer, R<List<VipGood>>> vipGoodsMap = getVipGoods(vipIds);
            vipSettingList.forEach(vipSetting -> {
                Level level = new Level();
                level.setId(vipSetting.getId());
                level.setName(vipSetting.getVipName());
                level.setVipInfo(vipSetting.getVipInfo());
                level.setVipDesc(baseSetting.getContent());
                level.setVipLevelUpShop(vipSetting.getVipLevelUpShop());
                level.setVipLevelUpShare(vipSetting.getVipLevelUpShare());
                level.setKeepBuyDay(vipSetting.getKeepBuyDay());
                level.setKeepBuyPoint(vipSetting.getKeepBuyPoint());
                level.setKeepShareDay(vipSetting.getKeepShareDay());
                level.setKeepSharePoint(vipSetting.getKeepSharePoint());
                level.setKeepShopDay(vipSetting.getKeepShopDay());
                level.setKeepShopPoint(vipSetting.getKeepShopPoint());
                R<GoodsVip> goodsVipR = goodsVipMap.get(vipSetting.getId());
                if (R.isSuccess(goodsVipR)) {
                    R<List<VipGood>> vipGoodR = vipGoodsMap.get(vipSetting.getId());
                    if (R.isSuccess(vipGoodR)) {
                        List<VipGood> vipGoodList = vipGoodR.getData();
                        if (vipGoodList != null && !vipGoodList.isEmpty()) {
                            List<String> goodsNames = new ArrayList<>();
                            vipGoodList.forEach(vipGood -> {
                                String goodJson = vipGood.getGoodJson();
                                if (isValidJson(goodJson)) {
                                    Goods goods = JSONObject.parseObject(goodJson, Goods.class);
                                    goodsNames.add(goods.getName());
                                } else {
                                    log.warn("JSON无效: " + goodJson);
                                }
                            });
                            level.setGoodsNames(goodsNames);
                        }
                    }
                }
                levelList.add(level);
            });
            vipLevel.setLevelList(levelList);
            vipLevel.setCurrentLevel(loginUserVipSetting.getId());
            return R.ok(vipLevel);
        } catch (Exception e) {
            log.error("会员等级获取失败", e);
            return R.fail("会员等级获取失败");
        }
    }
    private boolean checkSuccess(R<?> r) {
        if (!R.isSuccess(r)) {
            log.error("请求失败: " + r.getMsg());
        }
        return R.isSuccess(r);
    }
    private Map<Integer, R<GoodsVip>> getGoodsVips(List<Integer> vipIds) {
        Map<Integer, R<GoodsVip>> result = new HashMap<>();
        for (Integer vipId : vipIds) {
            R<GoodsVip> goodsVipR = goodsVipClient.getGoodsVip(vipId);
            result.put(vipId, goodsVipR);
        }
        return result;
    }
    private Map<Integer, R<List<VipGood>>> getVipGoods(List<Integer> vipIds) {
        Map<Integer, R<List<VipGood>>> result = new HashMap<>();
        for (Integer vipId : vipIds) {
            R<List<VipGood>> vipGoodR = vipGoodClient.getVipGoodsByVipId(vipId);
            result.put(vipId, vipGoodR);
        }
        return result;
    }
    private boolean isValidJson(String json) {
        try {
            JSONObject.parseObject(json);
            return true;
        } catch (Exception e) {
            return false;
        }
    }
}
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/vo/vip/Level.java
@@ -33,7 +33,7 @@
    @ApiModelProperty(value = "升级会员的直推用户人数要求")
    private Integer vipDirectNum;
    @ApiModelProperty(value = "升级会员的团队数要求")
    @ApiModelProperty(value = "升级会员的团队数要求/准代人数")
    private Integer vipTeamNum;
    @ApiModelProperty(value = "保级:消费x天")
@@ -54,6 +54,11 @@
    @ApiModelProperty(value = "保级:门店x分")
    private BigDecimal keepShopPoint;
    @ApiModelProperty(value = "指定购买商品")
    private List<String> goodsNames;
ruoyi-service/ruoyi-other/src/main/java/com/ruoyi/other/controller/VipGoodController.java
@@ -1,8 +1,17 @@
package com.ruoyi.other.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.other.api.domain.VipGood;
import com.ruoyi.other.service.VipGoodService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.List;
/**
 * <p>
@@ -14,7 +23,14 @@
 */
@RestController
@RequestMapping("/vip-good")
public class VipGoodController {
public class VipGoodController extends BaseController {
    @Resource
    private VipGoodService vipGoodService;
    @GetMapping("getVipGoodsByVipId")
    public R<List<VipGood>> getVipGoodsByVipId(Integer vipId){
        return R.ok(vipGoodService.list(new LambdaQueryWrapper<VipGood>()
                .eq(VipGood::getVipId, vipId)));
    }
}