From 9b8f055699c673d03d03349273502263e9732578 Mon Sep 17 00:00:00 2001
From: liujie <1793218484@qq.com>
Date: 星期一, 05 一月 2026 16:38:38 +0800
Subject: [PATCH] 修改bug

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java |  149 ++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 115 insertions(+), 34 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
index 3daff40..1e26a44 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
@@ -72,7 +72,7 @@
 
     private final TAppUserService appUserService;
 
-    private  final RedisTemplate redisTemplate;
+    private final RedisTemplate redisTemplate;
 
     private final TokenService tokenService;
 
@@ -132,10 +132,14 @@
         }
         TAppUser appUser = appUserService.getById(dto.getId());
         String code = appUser.getCode();
-        if (dto.getCode() != null && !dto.getCode().isEmpty() && !code.equals(dto.getCode())) {
+        if (code == null) {
             appUser.setCode(dto.getCode());
-            // 移除之前的二维码
-            redisTemplate.delete("USER_WX_IMG" + appUser.getId());
+        } else {
+            if (dto.getCode() != null && !dto.getCode().isEmpty() && !dto.getCode().equals(code)) {
+                appUser.setCode(dto.getCode());
+                // 移除之前的二维码
+                redisTemplate.delete("USER_WX_IMG" + appUser.getId());
+            }
         }
         if (dto.getPromotionStatus() != null) {
             appUser.setPromotionStatus(dto.getPromotionStatus());
@@ -160,13 +164,42 @@
         TAppUser appUser = appUserService.getById(id);
         TAppUserVo tAppUserVo = new TAppUserVo();
         BeanUtils.copyProperties(appUser, tAppUserVo);
-        if(appUser.getCompanyId()!=null){
+        if (appUser.getCompanyId() != null) {
             tAppUserVo.setReferrerCompany(companyService.getById(appUser.getCompanyId()));
         }
-        if(appUser.getReferrerUserId()!=null && appUser.getReferrerStatus()==2){
+        if (appUser.getReferrerUserId() != null && appUser.getReferrerStatus() == 2) {
             tAppUserVo.setReferrerUser(appUserService.getById(appUser.getReferrerUserId()));
         }
         return R.ok(tAppUserVo);
+    }
+
+    @ApiOperation(value = "小程序用户金币导入模板下载")
+    @GetMapping("/import-template_gold")
+    public void importTemplateGold() {
+        List<AppUserGoldImport> imports = new ArrayList<>();
+        AppUserGoldImport goldImport = new AppUserGoldImport();
+        imports.add(goldImport);
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), AppUserGoldImport.class, imports);
+        HttpServletResponse response = WebUtils.response();
+        ServletOutputStream outputStream = null;
+        try {
+            String fileName = URLEncoder.encode("金币导入模板.xls", "utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setHeader("content-Type", "application/vnd.ms-excel");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+            System.out.println("金币导入模板下载失败!");
+        } finally {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
     }
 
 
@@ -244,6 +277,35 @@
     }
 
 
+    @ApiOperation(value = "小程序用户导入模板下载")
+    @GetMapping("/import-template_user")
+    public void importTemplate() {
+        List<AppUserImport> imports = new ArrayList<>();
+        AppUserImport appUserImport = new AppUserImport();
+        imports.add(appUserImport);
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), AppUserImport.class, imports);
+        HttpServletResponse response = WebUtils.response();
+        ServletOutputStream outputStream = null;
+        try {
+            String fileName = URLEncoder.encode("小程序用户导入模板.xls", "utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setHeader("content-Type", "application/vnd.ms-excel");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+            System.out.println("小程序用户导入模板下载失败!");
+        } finally {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+
     @Log(title = "小程序用户-用户导入", businessType = BusinessType.IMPORT)
     @ApiOperation(value = "小程序用户-用户导入")
     @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
@@ -290,6 +352,10 @@
                 result.append("第" + i + "行:[", "出生日期" + "]不能为空");
                 continue;
             }
+            if (!StringUtils.hasLength(appUserImport.getPromotion())) {
+                result.append("第" + i + "行:[", "推广权限" + "]不能为空");
+                continue;
+            }
             if (!StringUtils.hasLength(appUserImport.getRole())) {
                 result.append("第" + i + "行:[", "角色" + "]不能为空");
                 continue;
@@ -317,6 +383,13 @@
                 continue;
             }
 
+            String promotion = appUserImport.getPromotion();
+            Integer promotionType = "是".equals(promotion) ? 1 : "否".equals(promotion) ? 0 : null;
+            if (promotionType == null) {
+                result.append("第" + i + "行:[", "推广权限" + "]格式错误");
+                continue;
+            }
+
             String birth = appUserImport.getBirth();
             LocalDate birthday = null;
             try {
@@ -340,24 +413,34 @@
             tAppUser.setGender(gender);
             tAppUser.setBirthday(birthday);
             tAppUser.setUserType(userType);
+            tAppUser.setPromotionStatus(promotionType);
 
+
+            if (appUserImport.getDealerCode() != null) {
+                TCompany one = companyService.getOne(new LambdaQueryWrapper<TCompany>().eq(TCompany::getCode, appUserImport.getDealerCode()).ne(TCompany::getStatus, 3).last("LIMIT 1"));
+                if (one != null) {
+                    tAppUser.setCompanyId(one.getId());
+                }
+            }
+            appUserService.save(tAppUser);
+            i++;
+        }
+
+
+        for (AppUserImport appUserImport : imports) {
+
+            TAppUser one = appUserService.getOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, appUserImport.getPhone()).ne(TAppUser::getStatus, 3).last("LIMIT 1"));
             if (appUserImport.getReferrerCode() != null) {
                 TAppUser referrerUser = appUserService.getOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getCode, appUserImport.getReferrerCode()).ne(TAppUser::getStatus, 3).last("LIMIT 1"));
                 if (referrerUser != null) {
-                    tAppUser.setReferrerUserId(referrerUser.getId());
-                    tAppUser.setReferrerStatus(1);
-                    tAppUser.setReferrerTime(LocalDateTime.now());
+                    one.setReferrerUserId(referrerUser.getId());
+                    one.setReferrerStatus(2);
+                    one.setReferrerTime(LocalDateTime.now());
                 }
             }
-            if (appUserImport.getDealerCode() != null) {
-            }
-            TCompany one = companyService.getOne(new LambdaQueryWrapper<TCompany>().eq(TCompany::getCode, appUserImport.getDealerCode()).ne(TCompany::getStatus, 3).last("LIMIT 1"));
-            if (one != null) {
-                tAppUser.setCompanyId(one.getId());
-            }
-            appUserService.save(user);
-            i++;
+            appUserService.updateById(one);
         }
+
         if (!result.isEmpty()) {
             return R.fail(result.toString());
         }
@@ -466,7 +549,7 @@
 
         List<IntegralChangeRecordVo> list = integralChangeRecordService.integralChangeRecordExport(query);
 
-        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TAppUser.class, list);
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), IntegralChangeRecordVo.class, list);
         HttpServletResponse response = WebUtils.response();
         assert response != null;
         response.setContentType("application/vnd.ms-excel");
@@ -501,18 +584,18 @@
                 .orderByDesc(TGoldChangeRecord::getCreateTime));
 
         List<TGoldChangeRecord> records = page.getRecords();
-        if(!records.isEmpty()){
+        if (!records.isEmpty()) {
             records.forEach(record -> {
                 Long createUserId = record.getCreateUserId();
-                if(createUserId!=null){
+                if (createUserId != null) {
                     SysUser sysUser = sysUserMapper.selectUserById(createUserId);
-                    if(sysUser!=null){
+                    if (sysUser != null) {
                         record.setCreateUserName(sysUser.getUserName());
                     }
                 }
             });
         }
-        page.setRecords( records);
+        page.setRecords(records);
         return R.ok(page);
     }
 
@@ -524,7 +607,7 @@
     public R goldChange(@RequestBody GoldChangeDto dto) {
         Long userId = tokenService.getLoginUser().getUserId();
 
-        if(dto.getChangeNum()<=0){
+        if (dto.getChangeNum() <= 0) {
             return R.fail("充值数不能小于等于0");
         }
 
@@ -551,11 +634,11 @@
     @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
     public R goldSub(@RequestBody GoldChangeDto dto) {
         Long userId = tokenService.getLoginUser().getUserId();
-        if(dto.getChangeNum()<=0){
+        if (dto.getChangeNum() <= 0) {
             return R.fail("扣除数不能小于等于0");
         }
         TAppUser appUser = appUserService.getById(dto.getUserId());
-        if(appUser.getGoldBalance().compareTo(new BigDecimal(dto.getChangeNum()))<0){
+        if (appUser.getGoldBalance().compareTo(new BigDecimal(dto.getChangeNum())) < 0) {
             return R.fail("用户金币不足");
         }
         TGoldChangeRecord tGoldChangeRecord = new TGoldChangeRecord();
@@ -575,7 +658,7 @@
     @PostMapping(value = "/pageOrderList")
     public R<Page<TBigGiftPackageOrder>> pageOrderList(@RequestBody GoldChangeRecordQuery query) {
         Page<TBigGiftPackageOrder> tBigGiftPackageOrderPage = new Page<>(query.getPageNum(), query.getPageSize());
-        List<TBigGiftPackageOrder> list = bigGiftPackageOrderService.pageOrderList(tBigGiftPackageOrderPage,query);
+        List<TBigGiftPackageOrder> list = bigGiftPackageOrderService.pageOrderList(tBigGiftPackageOrderPage, query);
         tBigGiftPackageOrderPage.setRecords(list);
         return R.ok(tBigGiftPackageOrderPage);
     }
@@ -584,7 +667,7 @@
     @ApiOperation(value = "用户-购买记录导出")
     @PostMapping(value = "/pageOrderListExport")
     @Log(title = "购买记录-导出", businessType = BusinessType.EXPORT)
-    public void pageOrderListExport(@RequestBody @Valid GoldChangeRecordQuery query){
+    public void pageOrderListExport(@RequestBody @Valid GoldChangeRecordQuery query) {
         List<TBigGiftPackageOrder> list = bigGiftPackageOrderService.pageOrderListExport(query);
         ArrayList<TBigGiftPackageOrderUserExport> tBigGiftPackageOrderUserExports = new ArrayList<>();
         for (TBigGiftPackageOrder order : list) {
@@ -628,13 +711,11 @@
     }
 
 
-
-
     @ApiOperation(value = "用户- 推广记录")
     @PostMapping("/promotionPageList")
     public R<Page<UserPromotionPageListVo>> promotionPageList(@RequestBody @Valid UserPromotionPageListQuery query) {
         Page<UserPromotionPageListVo> page = new Page<>(query.getPageNum(), query.getPageSize());
-        List<UserPromotionPageListVo> list = appUserService.userPromotionPageList(page,query);
+        List<UserPromotionPageListVo> list = appUserService.userPromotionPageList(page, query);
         page.setRecords(list);
         return R.ok(page);
     }
@@ -643,7 +724,7 @@
     @ApiOperation(value = "用户-推广记录导出")
     @PostMapping(value = "/exportUserPromotion")
     @Log(title = "推广记录-导出", businessType = BusinessType.EXPORT)
-    public void exportUserPromotion(@RequestBody @Valid UserPromotionPageListQuery query){
+    public void exportUserPromotion(@RequestBody @Valid UserPromotionPageListQuery query) {
 
         List<UserPromotionPageListVo> list = appUserService.userPromotionPageListExport(query);
         Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), UserPromotionPageListVo.class, list);
@@ -676,7 +757,7 @@
     @PostMapping("/profitUserPageList")
     public R<Page<UserProfitPageListVo>> profitUserPageList(@RequestBody @Valid UserProfitPageListQuery query) {
         Page<UserProfitPageListVo> page = new Page<>(query.getPageNum(), query.getPageSize());
-        List<UserProfitPageListVo> list = bigGiftPackageOrderService.profitUserPageList(page,query);
+        List<UserProfitPageListVo> list = bigGiftPackageOrderService.profitUserPageList(page, query);
 
         page.setRecords(list);
         return R.ok(page);
@@ -686,7 +767,7 @@
     @ApiOperation(value = "用户收益明细导出")
     @PostMapping(value = "/exportUserProfit")
     @Log(title = "收益明细-导出", businessType = BusinessType.EXPORT)
-    public void exportUserProfit(@RequestBody @Valid UserProfitPageListQuery query){
+    public void exportUserProfit(@RequestBody @Valid UserProfitPageListQuery query) {
 
         List<UserProfitPageListVo> list = bigGiftPackageOrderService.profitUserPageListExport(query);
         Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), UserProfitPageListVo.class, list);
@@ -728,7 +809,7 @@
     @ApiOperation(value = "用户结算记录导出")
     @PostMapping(value = "/exportSettlementPageList")
     @Log(title = "结算记录-导出", businessType = BusinessType.EXPORT)
-    public void exportSettlementPageList(@RequestBody @Valid GoldChangeRecordQuery query){
+    public void exportSettlementPageList(@RequestBody @Valid GoldChangeRecordQuery query) {
 
         List<TIntegralSettlement> list = integralSettlementService.list(new LambdaQueryWrapper<TIntegralSettlement>().eq(TIntegralSettlement::getAppUserId, query.getUserId()).orderByDesc(TIntegralSettlement::getCreateTime));
         Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TIntegralSettlement.class, list);

--
Gitblit v1.7.1