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.StringUtils;
|
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.*;
|
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.*;
|
|
import javax.annotation.Resource;
|
import java.time.LocalDateTime;
|
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 VipCenterService vipCenterService;
|
@Resource
|
private VipGoodClient vipGoodClient;
|
@Resource
|
private GoodsClient goodsClient;
|
@Resource
|
private AppUserService appUserService;
|
@Resource
|
private UserClickLogService userClickLogService;
|
|
|
@GetMapping("getVipLevelList")
|
@ApiOperation(value = "会员等级列表", tags = {"会员中心-小程序"})
|
public R<VipLevel> vipLevelList() {
|
try {
|
R<List<VipSetting>> r = remoteVipSettingClient.list();
|
if (R.isError(r)) {
|
return R.fail("会员等级获取失败");
|
}
|
List<VipSetting> vipSettingList = r.getData();
|
if (vipSettingList == null || vipSettingList.isEmpty()) {
|
return R.fail("会员等级获取失败");
|
}
|
|
R<BaseSetting> baseSettingR = baseSettingClient.getBaseSetting(3);
|
if (R.isError(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<>();
|
|
vipSettingList.forEach(vipSetting -> {
|
Level level = new Level();
|
level.setName(vipSetting.getVipName());
|
BeanUtils.copyBeanProp(level, vipSetting);
|
level.setVipDesc(baseSetting.getContent());
|
|
|
List<String> goodsNames = new ArrayList<>();
|
if (StringUtils.isNotEmpty(vipSetting.getGoodIds())){
|
String[] goodsIds = vipSetting.getGoodIds().split(",");
|
List<Goods> goodsList = goodsClient.getGoodsById(goodsIds).getData();
|
if (goodsList != null) {
|
for (Goods goods : goodsList) {
|
if (goods.getDelFlag().equals(0)){
|
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);
|
return R.fail("会员等级获取失败");
|
}
|
}
|
|
|
@GetMapping("/check")
|
@ApiOperation(value = "会员申请检查", tags = {"会员中心-小程序"})
|
public R<Boolean> check(@ApiParam("4:准代理,5:代理,6:总代理,7:合伙人") @RequestParam Integer type) {
|
return R.ok(vipCenterService.check(type));
|
}
|
|
|
|
|
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;
|
}
|
|
|
|
}
|