From 64f7ccb9ef8b5a0618e65cddc14b981c1f108ba3 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期一, 04 十一月 2024 09:01:59 +0800
Subject: [PATCH] 代码提交

---
 xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java |  244 +++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 226 insertions(+), 18 deletions(-)

diff --git a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java
index 0392d88..b8f3b23 100644
--- a/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java
+++ b/xinquan-modules/xinquan-user/src/main/java/com/xinquan/user/controller/client/ClientAppUserWithdrawController.java
@@ -1,32 +1,48 @@
 package com.xinquan.user.controller.client;
 
 
-import com.alibaba.fastjson2.util.UUIDUtils;
+import cn.afterturn.easypoi.excel.ExcelExportUtil;
+import cn.afterturn.easypoi.excel.entity.ExportParams;
 import com.alibaba.nacos.common.utils.UuidUtils;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.xinquan.common.core.domain.R;
-import com.xinquan.common.datascope.annotation.DataScope;
-import com.xinquan.common.security.utils.SecurityUtils;
+import com.xinquan.common.core.utils.WebUtils;
+import com.xinquan.common.core.utils.page.CollUtils;
+import com.xinquan.common.core.utils.page.PageDTO;
+import com.xinquan.common.log.enums.BusinessType;
+import com.xinquan.common.security.service.TokenService;
+import com.xinquan.course.api.domain.Course;
+import com.xinquan.order.api.domain.Order;
+import com.xinquan.user.api.domain.dto.OrderListDTO;
 import com.xinquan.system.api.domain.AppUser;
 import com.xinquan.system.api.domain.AppUserBank;
 import com.xinquan.system.api.domain.AppUserWithdraw;
-import com.xinquan.system.api.domain.vo.UpdateAppUserDTO;
-import com.xinquan.system.api.domain.vo.WalletVO;
+import com.xinquan.system.api.model.LoginUser;
+import com.xinquan.user.domain.export.WithdrawExport;
 import com.xinquan.user.service.AppUserBankService;
 import com.xinquan.user.service.AppUserService;
 import com.xinquan.user.service.AppUserWithdrawService;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiImplicitParams;
 import io.swagger.annotations.ApiOperation;
-import org.springframework.web.bind.annotation.PostMapping;
-import org.springframework.web.bind.annotation.RequestBody;
-import org.springframework.web.bind.annotation.RequestMapping;
-
-import org.springframework.web.bind.annotation.RestController;
+import org.apache.poi.ss.usermodel.Workbook;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
+import javax.servlet.ServletOutputStream;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
 import java.math.BigDecimal;
+import java.net.URLEncoder;
 import java.time.LocalDateTime;
+import java.time.format.DateTimeFormatter;
+import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /**
  * <p>
@@ -45,6 +61,181 @@
     private AppUserWithdrawService withdrawService;
     @Resource
     private AppUserBankService appUserBankService;
+    @Autowired
+    private TokenService tokenService;
+
+    @PostMapping("/withdrawList")
+    @ApiOperation(value = "提现列表-分页", tags = {"管理后台=提现管理"})
+    public R<PageDTO<AppUserWithdraw>> withdrawList(@RequestBody OrderListDTO courseDTO) {
+        LambdaQueryWrapper<AppUserWithdraw> wrapper = new LambdaQueryWrapper<>();
+        if (StringUtils.hasLength(courseDTO.getBuyContent())){
+                wrapper.like(AppUserWithdraw::getCode,courseDTO.getBuyContent());
+        }
+        if (StringUtils.hasLength(courseDTO.getUserNameOrPhone())){
+            List<Long> collect = appUserService.lambdaQuery().like(AppUser::getCellPhone, courseDTO.getUserNameOrPhone())
+                    .list().stream().map(AppUser::getId)
+                    .collect(Collectors.toList());
+            if (collect.isEmpty())collect.add(-1L);
+            wrapper.in(AppUserWithdraw::getAppUserId,collect);
+        }
+        if (courseDTO.getPaymentStatus()!=null && courseDTO.getPaymentStatus()==1){
+            wrapper.eq(AppUserWithdraw::getId,0);
+        }else if (courseDTO.getPaymentStatus()!=null &&(courseDTO.getPaymentStatus()==2 || courseDTO.getPaymentStatus()==3)){
+            List<Integer> integers = new ArrayList<>();
+            integers.add(1);
+            integers.add(2);
+            wrapper.in(AppUserWithdraw::getWithdrawStatus,integers);
+        }
+        if (StringUtils.hasLength(courseDTO.getTime())){
+            String startTime =null;
+            String endTime =null;
+            String[] split = courseDTO.getTime().split(" - ");
+            startTime = split[0]+"00:00:00";
+            endTime = split[1]+"23:59:59";
+            wrapper.between(AppUserWithdraw::getWithdrawTime,startTime,endTime);
+        }
+        Page<AppUserWithdraw> list = withdrawService.page(new Page<>(courseDTO.getPageCurr(), courseDTO.getPageSize()), wrapper);
+        if (CollUtils.isEmpty(list.getRecords())) {
+            return R.ok(PageDTO.empty(list));
+        }
+        for (AppUserWithdraw record : list.getRecords()) {
+            record.setUid(record.getId()+"");
+            AppUser byId = appUserService.getById(record.getAppUserId());
+            if(byId!=null){
+                record.setUserName(byId.getNickname());
+                record.setCellPhone(byId.getCellPhone());
+                record.setAvatar(byId.getAvatar());
+            }
+        }
+        return R.ok(PageDTO.of(list, AppUserWithdraw.class));
+    }
+    @ApiOperation(value = "提现管理导出", tags = {"管理后台-提现管理"})
+    @PutMapping("/export")
+    public void export(@RequestBody OrderListDTO courseDTO)
+    {
+        LambdaQueryWrapper<AppUserWithdraw> wrapper = new LambdaQueryWrapper<>();
+        if (StringUtils.hasLength(courseDTO.getIds())){
+            wrapper.in(AppUserWithdraw::getId, Arrays.asList(courseDTO.getIds().split(",")));
+        }
+        if (StringUtils.hasLength(courseDTO.getBuyContent())){
+            wrapper.like(AppUserWithdraw::getCode,courseDTO.getBuyContent());
+        }
+        if (StringUtils.hasLength(courseDTO.getUserNameOrPhone())){
+            List<Long> collect = appUserService.lambdaQuery().like(AppUser::getCellPhone, courseDTO.getUserNameOrPhone())
+                    .list().stream().map(AppUser::getId)
+                    .collect(Collectors.toList());
+            if (collect.isEmpty())collect.add(-1L);
+            wrapper.in(AppUserWithdraw::getAppUserId,collect);
+        }
+        if (courseDTO.getPaymentStatus()!=null && courseDTO.getPaymentStatus()==1){
+            wrapper.eq(AppUserWithdraw::getId,0);
+        }else if (courseDTO.getPaymentStatus()!=null &&(courseDTO.getPaymentStatus()==2 || courseDTO.getPaymentStatus()==3)){
+            List<Integer> integers = new ArrayList<>();
+            integers.add(1);
+            integers.add(2);
+            wrapper.in(AppUserWithdraw::getWithdrawStatus,integers);
+        }
+        if (StringUtils.hasLength(courseDTO.getTime())){
+            String startTime =null;
+            String endTime =null;
+            String[] split = courseDTO.getTime().split(" - ");
+            startTime = split[0]+"00:00:00";
+            endTime = split[1]+"23:59:59";
+            wrapper.between(AppUserWithdraw::getWithdrawTime,startTime,endTime);
+        }
+        List<AppUserWithdraw> list = withdrawService.list(wrapper);
+        List<WithdrawExport> withdrawExports = new ArrayList<>();
+
+        for (AppUserWithdraw record : list) {
+            WithdrawExport withdrawExport = new WithdrawExport();
+            record.setUid(record.getId()+"");
+            AppUser byId = appUserService.getById(record.getAppUserId());
+            if(byId!=null){
+                withdrawExport.setUserName(byId.getNickname());
+                withdrawExport.setCellphone(byId.getCellPhone());
+            }
+            withdrawExport.setCode(record.getCode());
+
+            withdrawExport.setAmount("¥"+record.getAmount()+"");
+            withdrawExport.setWithdrawType("1");
+            withdrawExport.setWithdrawStatus(record.getWithdrawStatus()+"");
+            DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
+            String format = df.format(record.getCreateTime());
+            withdrawExport.setCreateTime(format);
+            withdrawExports.add(withdrawExport);
+        }
+        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), WithdrawExport.class, withdrawExports);
+        HttpServletResponse response = WebUtils.response();
+        response.setContentType("application/vnd.ms-excel");
+        response.setCharacterEncoding("utf-8");
+        ServletOutputStream outputStream = null;
+        try {
+            String fileName = URLEncoder.encode("提现管理导出.xls", "utf-8");
+            response.setHeader("Content-Disposition", "attachment;filename=" + fileName);
+            response.setContentType("application/vnd.ms-excel;charset=UTF-8");
+            response.setHeader("Pragma", "no-cache");
+            response.setHeader("Cache-Control", "no-cache");
+            outputStream = response.getOutputStream();
+            workbook.write(outputStream);
+        } catch (IOException e) {
+            e.printStackTrace();
+        } finally {
+            try {
+                outputStream.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+    @PostMapping("/withdrawInfo")
+    @ApiOperation(value = "提现列表-查看详情", tags = {"管理后台-提现管理"})
+    public R<AppUserWithdraw> withdrawList(String uid){
+        AppUserWithdraw byId = withdrawService.getById(uid);
+        return R.ok(byId);
+    }
+    /**
+     * 远程调用获取提现记录
+     */
+    @PostMapping("/getWithdrawList")
+    public R<List<AppUserWithdraw>> getWithdraw(@RequestBody OrderListDTO courseDTO) {
+        LambdaQueryWrapper<AppUserWithdraw> wrapper = new LambdaQueryWrapper<>();
+        if (StringUtils.hasLength(courseDTO.getBuyContent())){
+            if (!courseDTO.getBuyContent().contains("提现")){
+                wrapper.like(AppUserWithdraw::getCode,courseDTO.getBuyContent());
+            }
+        }
+        if (StringUtils.hasLength(courseDTO.getUserNameOrPhone())){
+            List<Long> collect = appUserService.lambdaQuery().like(AppUser::getCellPhone, courseDTO.getUserNameOrPhone())
+                    .list().stream().map(AppUser::getId)
+                    .collect(Collectors.toList());
+            if (collect.isEmpty())collect.add(-1L);
+            wrapper.in(AppUserWithdraw::getAppUserId,collect);
+        }
+        if (courseDTO.getOrderFrom()!=null && courseDTO.getOrderFrom()!=5){
+            wrapper.eq(AppUserWithdraw::getId,0);
+        }
+        if (courseDTO.getPayType()!=null && courseDTO.getPayType()!=4){
+            wrapper.eq(AppUserWithdraw::getId,0);
+        }
+        if (courseDTO.getPaymentStatus()!=null && courseDTO.getPaymentStatus()==1){
+            wrapper.eq(AppUserWithdraw::getId,0);
+        }else if (courseDTO.getPaymentStatus()!=null &&(courseDTO.getPaymentStatus()==2 || courseDTO.getPaymentStatus()==3)){
+            List<Integer> integers = new ArrayList<>();
+            integers.add(1);
+            integers.add(2);
+            wrapper.in(AppUserWithdraw::getWithdrawStatus,integers);
+        }
+        if (StringUtils.hasLength(courseDTO.getTime())){
+            String startTime =null;
+            String endTime =null;
+            String[] split = courseDTO.getTime().split(" - ");
+            startTime = split[0]+"00:00:00";
+            endTime = split[1]+"23:59:59";
+            wrapper.between(AppUserWithdraw::getWithdrawTime,startTime,endTime);
+        }
+        List<AppUserWithdraw> list = withdrawService.list(wrapper);
+        return R.ok(list);
+    }
     @PostMapping("/withdraw")
     @ApiOperation(value = "提现", tags = {"钱包"})
     @ApiImplicitParams({
@@ -52,8 +243,12 @@
             @ApiImplicitParam(name = "money", value = "提现金额", dataType = "String", required = true)
     })
     public R withdraw(Long bankId,String money) {
-        Long userId = SecurityUtils.getUserId();
-        if (userId==0)return R.tokenError("登录失效");
+
+        LoginUser loginUser = tokenService.getLoginUser();
+        if (loginUser==null){
+            return R.tokenError("登录失效");
+        }
+        Long userId = loginUser.getUserid();
         BigDecimal bigDecimal = new BigDecimal(money);
         AppUserWithdraw appUserWithdraw = new AppUserWithdraw();
         appUserWithdraw.setAppUserId(userId);
@@ -63,6 +258,7 @@
         appUserWithdraw.setWithdrawStatus(0);
         // todo 提现流水号
         appUserWithdraw.setSerialNo(UuidUtils.generateUuid());
+        appUserWithdraw.setCode(UuidUtils.generateUuid());
         appUserWithdraw.setWithdrawTime(LocalDateTime.now());
         appUserWithdraw.setCreateTime(LocalDateTime.now());
         withdrawService.save(appUserWithdraw);
@@ -71,8 +267,12 @@
     @PostMapping("/addBank")
     @ApiOperation(value = "提现-添加银行卡", tags = {"钱包"})
     public R wallet(@RequestBody AppUserBank appUserWithdraw) {
-        Long userId = SecurityUtils.getUserId();
-        if (userId==0)return R.tokenError("登录失效");
+        LoginUser loginUser = tokenService.getLoginUser();
+        if (loginUser==null){
+            return R.tokenError("登录失效");
+        }
+        Long userId = loginUser.getUserid();
+
         appUserWithdraw.setAppUserId(userId);
         appUserBankService.save(appUserWithdraw);
         return R.ok();
@@ -80,16 +280,24 @@
     @PostMapping("/deleteBank")
     @ApiOperation(value = "提现-删除银行卡", tags = {"钱包"})
     public R deleteBank(Long id) {
-        Long userId = SecurityUtils.getUserId();
-        if (userId==0)return R.tokenError("登录失效");
+        LoginUser loginUser = tokenService.getLoginUser();
+        if (loginUser==null){
+            return R.tokenError("登录失效");
+        }
+        Long userId = loginUser.getUserid();
+        if(userId ==null || userId == 0)return R.tokenError("登录失效");
         appUserBankService.removeById(id);
         return R.ok();
     }
     @PostMapping("/bankList")
     @ApiOperation(value = "提现-获取银行卡列表", tags = {"钱包"})
     public R<List<AppUserBank>> bankList() {
-        Long userId = SecurityUtils.getUserId();
-        if (userId==0)return R.tokenError("登录失效");
+        LoginUser loginUser = tokenService.getLoginUser();
+        if (loginUser==null){
+            return R.tokenError("登录失效");
+        }
+        Long userId = loginUser.getUserid();
+        if(userId ==null || userId == 0)return R.tokenError("登录失效");
         List<AppUserBank> list = appUserBankService.lambdaQuery()
                 .eq(AppUserBank::getAppUserId, userId).list();
         return R.ok(list);

--
Gitblit v1.7.1