From 17efd8f0d5008e2f0958df31042ed769776074d9 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期三, 15 一月 2025 15:57:16 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java | 113 +++++++++++++++++++++-----------------------------------
1 files changed, 42 insertions(+), 71 deletions(-)
diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
index 6f20e70..1be9a3f 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/VipCenterController.java
@@ -1,30 +1,29 @@
package com.ruoyi.account.controller;
+import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject;
+import com.ruoyi.account.api.model.AppUser;
+import com.ruoyi.account.api.model.UserClickLog;
import com.ruoyi.account.service.AppUserService;
+import com.ruoyi.account.service.UserClickLogService;
import com.ruoyi.account.service.VipCenterService;
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.core.exception.ServiceException;
import com.ruoyi.common.core.utils.bean.BeanUtils;
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 com.ruoyi.system.api.model.LoginUser;
+import com.ruoyi.other.api.feignClient.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
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.RequestParam;
-import org.springframework.web.bind.annotation.RestController;
+import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
+import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -47,11 +46,15 @@
@Resource
private TokenService tokenService;
@Resource
+ private VipCenterService vipCenterService;
+ @Resource
private VipGoodClient vipGoodClient;
+ @Resource
+ private GoodsClient goodsClient;
@Resource
private AppUserService appUserService;
@Resource
- private VipCenterService vipCenterService;
+ private UserClickLogService userClickLogService;
@GetMapping("getVipLevelList")
@@ -59,7 +62,7 @@
public R<VipLevel> vipLevelList() {
try {
R<List<VipSetting>> r = remoteVipSettingClient.list();
- if (checkSuccess(r)) {
+ if (R.isError(r)) {
return R.fail("会员等级获取失败");
}
List<VipSetting> vipSettingList = r.getData();
@@ -68,7 +71,7 @@
}
R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(3);
- if (checkSuccess(baseSettingR)) {
+ if (R.isError(baseSettingR)) {
log.error("【会员设置说明】获取失败:{}", baseSettingR.getMsg());
return R.fail("会员等级获取失败");
}
@@ -86,39 +89,42 @@
// 批量获取 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.setName(vipSetting.getVipName());
BeanUtils.copyBeanProp(level, vipSetting);
level.setVipDesc(baseSetting.getContent());
- 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);
- }
- }
+ R<List<VipGood>> vipGoodR = vipGoodsMap.get(vipSetting.getId());
+ if (R.isError(vipGoodR)) {
+ throw new ServiceException("会员商品获取失败");
+ }
+ List<VipGood> vipGoodList = vipGoodR.getData();
+ if (vipGoodList != null && !vipGoodList.isEmpty()) {
+ List<String> goodsNames = new ArrayList<>();
+ vipGoodList.forEach(vipGood -> {
+ Goods goods = JSON.parseObject(vipGood.getGood_json(), Goods.class);
+ goodsNames.add(goods.getName());
+ });
+ level.setGoodsNames(goodsNames);
}
levelList.add(level);
});
vipLevel.setLevelList(levelList);
vipLevel.setCurrentLevel(loginUserVipSetting.getId());
+
+ //添加操作记录
+ AppUser appUser = appUserService.getById(userid);
+ UserClickLog userClickLog = new UserClickLog();
+ userClickLog.setDelFlag(0);
+ userClickLog.setCreateTime(LocalDateTime.now());
+ userClickLog.setAppUserId(userid);
+ userClickLog.setVipId(appUser.getVipId());
+ userClickLogService.save(userClickLog);
+
return R.ok(vipLevel);
} catch (Exception e) {
log.error("会员等级获取失败", e);
@@ -130,56 +136,21 @@
@GetMapping("/check")
@ApiOperation(value = "会员申请检查", tags = {"会员中心-小程序"})
public R<Boolean> check(@ApiParam("4:准代理,5:代理,6:总代理,7:合伙人") @RequestParam Integer type) {
- LoginUser loginUser = tokenService.getLoginUser();
- Long userid = loginUser.getUserid();
- if (type == 4){
- return R.ok(vipCenterService.checkReadyToBeProxy(userid, type));
- }else if (type == 5){
- return R.ok(vipCenterService.checkReadyToBeAgent(userid));
- }else if (type == 6){
- return R.ok(vipCenterService.checkReadyToBeTotalAgent(userid));
- }else if (type == 7){
- return R.ok(vipCenterService.checkReadyToBePartner(userid));
- }else {
- return R.fail("参数错误");
- }
+ return R.ok(vipCenterService.check(type));
}
-
- 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);
+ 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;
- }
- }
+
}
--
Gitblit v1.7.1