luodangjia
2025-02-06 4ea15c3e2a3f0434df79a1b49fe4e90f7337b025
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
@@ -12,11 +12,16 @@
import com.ruoyi.account.mapper.AppUserMapper;
import com.ruoyi.account.service.*;
import com.ruoyi.account.util.ObsUploadUtil;
import com.ruoyi.account.util.weChat.EnvVersion;
import com.ruoyi.account.util.weChat.WeChatUtil;
import com.ruoyi.account.vo.*;
import com.ruoyi.common.core.constant.CacheConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.utils.StringUtils;
import com.ruoyi.common.core.utils.bean.BeanUtils;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.PageInfo;
import com.ruoyi.common.redis.service.RedisService;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.order.feignClient.OrderClient;
import com.ruoyi.order.feignClient.RemoteOrderGoodsClient;
@@ -30,7 +35,9 @@
import com.ruoyi.other.api.feignClient.VipSettingClient;
import com.ruoyi.system.api.domain.SysUser;
import com.ruoyi.system.api.feignClient.SysUserClient;
import com.ruoyi.system.api.model.LoginUser;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@@ -94,6 +101,14 @@
    private BalanceChangeRecordService balanceChangeRecordService;
    @Resource
    private UserChangeLogService userChangeLogService;
    @Resource
    private RedisService redisService;
    @Resource
    private WeChatUtil weChatUtil;
    @Value("${file.upload.location}")
    private String filePath;
    @ResponseBody
@@ -213,6 +228,13 @@
    public R<AppUser> info() {
        Long userId = tokenService.getLoginUserApplet().getUserid();
        AppUser user = appUserService.getById(userId);
        if(StringUtils.isEmpty(user.getQrCode())){
            //获取微信推广二维码
            String fileName = UUID.randomUUID() + ".jpg";
            String getwxacodeunlimit = weChatUtil.getwxacodeunlimit("pages/login/login", "id=" + user.getId(), EnvVersion.RELEASE, filePath + fileName);
            user.setQrCode(getwxacodeunlimit);
            appUserService.updateById(user);
        }
        return R.ok(user);
    }
@@ -653,7 +675,21 @@
        AppUser byId = appUserService.getById(id);
        byId.setStatus(status);
        appUserService.updateById(byId);
        loginout(id);
        return R.ok();
    }
    private void loginout(Long userId) {
        Collection<String> keys = redisService.keys(CacheConstants.LOGIN_TOKEN_KEY + "*");
        if (!CollectionUtils.isEmpty(keys)) {
            for (String key : keys) {
                LoginUser user = redisService.getCacheObject(key);
                if (user.getUserid().equals(userId)) {
                    redisService.deleteObject(key);
                    break;
                }
            }
        }
    }
    @GetMapping("/select")
@@ -759,6 +795,20 @@
        return R.ok(byId);
    }
    /**
     * 获取指定用户的下级用户
     */
    @GetMapping("/bottom/list")
    @ApiOperation(value = "用户列表-下级用户", tags = {"管理后台"})
    public R<Page<AppUser>> bottom(Integer pageNum, Integer pageSize, Long userId){
        Page<AppUser> page = appUserService.page(Page.of(pageNum, pageSize), new LambdaQueryWrapper<AppUser>()
                .eq(AppUser::getInviteUserId, userId));
        return R.ok(page);
    }
    
    @GetMapping("/change/vip")
@@ -780,7 +830,6 @@
        byId.setVipId(vipId);
        appUserService.updateById(byId);
        return R.ok();
    }
    @GetMapping("/bottom")
@@ -794,7 +843,7 @@
    @GetMapping("/orders")
    @ApiOperation(value = "用户列表-订单列表", tags = {"管理后台"})
    public R<List<Order>> orders(Long id) {
    public R<JSONObject> orders(Long id,Integer pageNum, Integer pageSize) {
        Long userid = tokenService.getLoginUser().getUserid();
        SysUser sysUser = sysUserClient.getSysUser(userid).getData();
        Integer shopId = -1;
@@ -802,8 +851,27 @@
            shopId = sysUser.getObjectId();
        }
        R<List<Order>> listR = remoteOrderGoodsClient.byUserId(id,shopId);
        return R.ok(listR.getData());
        List<Order> data = listR.getData();
        Integer total = data.size();
        // 手动分页
        if (data != null && data.size() > 0) {
            if (pageNum == null || pageNum == 0) {
                pageNum = 1;
            }
            if (pageSize == null || pageSize == 0) {
                pageSize = 10;
            }
            data = data.stream()
                    .skip((pageNum - 1) * pageSize)
                    .limit(pageSize)
                    .collect(Collectors.toList());
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("records", data);
        jsonObject.put("total", total);
        jsonObject.put("size", pageSize);
        jsonObject.put("current", pageNum);
        return R.ok(jsonObject);
    }