From 88690664da8b603167b238bec92848dffec44e8d Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期日, 26 一月 2025 21:14:13 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java |   80 ++++++++++++++++++++++++++++++++++------
 1 files changed, 68 insertions(+), 12 deletions(-)

diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
index a6dc7ba..d60bfb5 100644
--- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
+++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/AppUserController.java
@@ -1,6 +1,7 @@
 package com.ruoyi.account.controller;
 
 
+import com.alibaba.fastjson2.JSONObject;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
 import com.baomidou.mybatisplus.core.metadata.IPage;
@@ -11,8 +12,11 @@
 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.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;
@@ -30,6 +34,7 @@
 import com.ruoyi.system.api.domain.SysUser;
 import com.ruoyi.system.api.feignClient.SysUserClient;
 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;
@@ -57,8 +62,7 @@
 @RestController
 @RequestMapping("/app-user")
 public class AppUserController extends BaseController {
-
-
+    
     @Resource
     private TokenService tokenService;
     @Resource
@@ -92,6 +96,14 @@
     private UserCancellationLogService userCancellationLogService;
     @Resource
     private BalanceChangeRecordService balanceChangeRecordService;
+    @Resource
+    private UserChangeLogService userChangeLogService;
+    
+    @Resource
+    private WeChatUtil weChatUtil;
+    
+    @Value("${file.upload.location}")
+    private String filePath;
 
 
     @ResponseBody
@@ -114,6 +126,17 @@
     public AppUser getAppUserById(@RequestParam("id") Long id) {
         return appUserService.getById(id);
     }
+
+    @PostMapping("/getBaseUserById")
+    public R<Map<String, Object>> getBaseUserById(@RequestParam("id") Long id) {
+        AppUser appUser = appUserService.getById(id);
+        Map<String, Object> map = new HashMap<>();
+        map.put("id", appUser.getId());
+        map.put("name", appUser.getName());
+        map.put("phone", appUser.getPhone());
+        return R.ok(map);
+    }
+
 
     @ResponseBody
     @PostMapping("/editAppUserById")
@@ -200,6 +223,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);
     }
 
@@ -531,7 +561,7 @@
         DangerInfoDto dangerInfoDto = new DangerInfoDto();
         BeanUtils.copyProperties(data, dangerInfoDto);
         List<UserPoint> list1 = userPointService.lambdaQuery().eq(UserPoint::getAppUserId,id).eq(UserPoint::getType, 1).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list();
-        List<UserPoint> list2 = userPointService.lambdaQuery().eq(UserPoint::getAppUserId,id).eq(UserPoint::getType, 9).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list();
+        List<UserPoint> list2 = userPointService.lambdaQuery().eq(UserPoint::getAppUserId,id).eq(UserPoint::getType, 2).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list();
         List<UserPoint> list3 = userPointService.lambdaQuery().eq(UserPoint::getAppUserId,id).eq(UserPoint::getType, 8).ge(UserPoint::getCreateTime, now.minusDays(data.getKeepBuyDay())).list();
         Integer userKeepBuyPoint = 0;
         for (UserPoint userPoint : list1) {
@@ -565,6 +595,27 @@
         userChangeLog.setChangeType(0);
         userChangeLogService.save(userChangeLog);
         appUser.setVipId(appUser.getVipId() - 1);
+        appUser.setIsDanger(0);
+        //检查是否达标,不达标继续标红
+        VipSetting vipSetting = vipSettingClient.getVipSetting(appUser.getVipId()).getData();
+        //消费积分
+        List<UserPoint> list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 1).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepBuyDay() + " DAY) <= create_time"));
+        int sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum();
+        if(sum < vipSetting.getKeepBuyPoint()){
+            appUser.setIsDanger(1);
+        }
+        //返佣积分
+        list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 2).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShareDay() + " DAY) <= create_time"));
+        sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum();
+        if(sum < vipSetting.getKeepSharePoint()){
+            appUser.setIsDanger(1);
+        }
+        //门店业绩
+        list1 = userPointService.list(new LambdaQueryWrapper<UserPoint>().eq(UserPoint::getAppUserId, appUser.getId()).eq(UserPoint::getType, 8).last(" and SUBDATE(now(), INTERVAL " + vipSetting.getKeepShopDay() + " DAY) <= create_time"));
+        sum = list1.stream().mapToInt(UserPoint::getVariablePoint).sum();
+        if(sum < vipSetting.getKeepShopPoint()){
+            appUser.setIsDanger(1);
+        }
         appUserService.updateById(appUser);
         return R.ok();
     }
@@ -631,8 +682,7 @@
 
     @GetMapping("/detail")
     @ApiOperation(value = "用户列表-详情", tags = {"管理后台"})
-    public R<AppUser> detail(Long id) {
-
+    public R<AppUser> detail(Long id, Integer shopId) {
         Long userid = tokenService.getLoginUser().getUserid();
         SysUser sysUser = sysUserClient.getSysUser(userid).getData();
         AppUser byId = appUserService.getById(id);
@@ -665,7 +715,13 @@
         List<AppUser> list = appUserService.lambdaQuery().eq(AppUser::getInviteUserId, id).list();
         byId.setBottomUsers(list);
         //消费总金额
-        R<List<Order>> orderR = remoteOrderGoodsClient.byShopIdAndUserId(id,byId.getShopId());
+        if(null == shopId || 1 == sysUser.getRoleType()){
+            shopId = -1;
+        }
+        if(null == shopId && 2 == sysUser.getRoleType()){
+            shopId = sysUser.getObjectId();
+        }
+        R<List<Order>> orderR = remoteOrderGoodsClient.byUserId(id, shopId);
         List<Order> orderList = orderR.getData();
         if (!CollectionUtils.isEmpty(orderList)){
             BigDecimal paymentAmount = orderList.stream().map(Order::getPaymentAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
@@ -676,8 +732,7 @@
         return R.ok(byId);
     }
 
-    @Resource
-    private UserChangeLogService userChangeLogService;
+    
 
     @GetMapping("/change/vip")
     @ApiOperation(value = "用户列表-修改会员等级", tags = {"管理后台"})
@@ -715,7 +770,10 @@
     public R<List<Order>> orders(Long id) {
         Long userid = tokenService.getLoginUser().getUserid();
         SysUser sysUser = sysUserClient.getSysUser(userid).getData();
-        Integer shopId = sysUser.getObjectId();
+        Integer shopId = -1;
+        if(sysUser.getRoleType() == 2){
+            shopId = sysUser.getObjectId();
+        }
         R<List<Order>> listR = remoteOrderGoodsClient.byUserId(id,shopId);
         return R.ok(listR.getData());
 
@@ -810,8 +868,6 @@
         if (cd.getStartTime().isAfter(cd.getEndTime())) {
             return R.fail("开始时间不能大于结束时间");
         }
-
-
         Map<String, Map<Integer, BigDecimal>> dailyVipCommissions = new TreeMap<>();
         getDatesBetween(cd.getStartTime(), cd.getEndTime()).forEach(date -> {
             for (int i = 1; i < 8; i++){
@@ -980,7 +1036,7 @@
      * 检查会员降级
      * @param appUserId
      */
-    @PostMapping("/app-user/vipDemotion")
+    @PostMapping("/vipDemotion")
     public void vipDemotion(@RequestParam("appUserId") Long appUserId){
         appUserService.vipDemotion(appUserId);
     }

--
Gitblit v1.7.1