liujie
2025-12-26 9197cc8e3ef4d0f8f2b178a657c2fe823a809fb6
ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TAppUserController.java
@@ -1,18 +1,61 @@
package com.ruoyi.web.controller.api;
import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.ExcelImportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.excel.entity.ImportParams;
import cn.hutool.json.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.basic.PageInfo;
import com.ruoyi.common.core.domain.BasePage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.exception.ServiceException;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.model.TAppUser;
import com.ruoyi.system.query.AppUserListQuery;
import com.ruoyi.system.service.TAppUserService;
import com.ruoyi.common.utils.WebUtils;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.dto.BatchUpdateIntegralDto;
import com.ruoyi.system.dto.GoldChangeDto;
import com.ruoyi.system.dto.UpdateAppUserDto;
import com.ruoyi.system.export.*;
import com.ruoyi.system.mapper.SysUserMapper;
import com.ruoyi.system.model.*;
import com.ruoyi.system.query.*;
import com.ruoyi.system.service.*;
import com.ruoyi.system.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.URLEncoder;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
/**
 * <p>
@@ -24,29 +67,695 @@
 */
@RestController
@RequestMapping("/t-app-user")
@Api(tags = "用户管理")
@Api(tags = "(嘉视达)用户管理")
public class TAppUserController {
    @Resource
    private TAppUserService  appUserService;
    private final TAppUserService appUserService;
    private  final RedisTemplate redisTemplate;
    private final TokenService tokenService;
    private final TCompanyService companyService;
    private final TGoldChangeRecordService goldChangeRecordService;
    private final TIntegralChangeRecordService integralChangeRecordService;
    private final SysUserMapper sysUserMapper;
    private final TBigGiftPackageOrderService bigGiftPackageOrderService;
    private final TIntegralSettlementService integralSettlementService;
    public TAppUserController(TAppUserService appUserService, RedisTemplate redisTemplate, TokenService tokenService, TCompanyService companyService, TGoldChangeRecordService goldChangeRecordService, TIntegralChangeRecordService integralChangeRecordService, SysUserMapper sysUserMapper, TBigGiftPackageOrderService bigGiftPackageOrderService, TIntegralSettlementService integralSettlementService) {
        this.appUserService = appUserService;
        this.redisTemplate = redisTemplate;
        this.tokenService = tokenService;
        this.companyService = companyService;
        this.goldChangeRecordService = goldChangeRecordService;
        this.integralChangeRecordService = integralChangeRecordService;
        this.sysUserMapper = sysUserMapper;
        this.bigGiftPackageOrderService = bigGiftPackageOrderService;
        this.integralSettlementService = integralSettlementService;
    }
    @ApiOperation(value = "用户管理分页列表")
    @PostMapping(value = "/pageList")
    public R<PageInfo<TAppUser>> pageList(@RequestBody AppUserListQuery query) {
        return R.ok(appUserService.pageList(query));
    }
    @ApiOperation(value = "修改状态")
    @GetMapping(value = "/changeStatus")
    @Log(title = "小程序用户-修改状态", businessType = BusinessType.UPDATE)
    public R pageList(@RequestParam String id) {
    public R pageList(@RequestParam Integer id) {
        TAppUser appUser = appUserService.getById(id);
        appUser.setStatus(appUser.getStatus()==1?2:1);
        appUser.setStatus(appUser.getStatus() == 1 ? 2 : 1);
        appUserService.updateById(appUser);
        return R.ok();
    }
    @ApiOperation(value = "修改用户信息")
    @PostMapping(value = "/updateAppUser")
    @Log(title = "小程序用户-修改用户信息", businessType = BusinessType.UPDATE)
    public R updateAppUser(@RequestBody UpdateAppUserDto dto) {
        if (dto.getCode() != null && !dto.getCode().isEmpty()) {
            long count = appUserService.count(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getCode, dto.getCode()).ne(TAppUser::getId, dto.getId()));
            if (count > 0) {
                return R.fail("推广号已存在");
            }
        }
        TAppUser appUser = appUserService.getById(dto.getId());
        String code = appUser.getCode();
        if (dto.getCode() != null && !dto.getCode().isEmpty() && code!=null && !code.equals(dto.getCode())) {
            appUser.setCode(dto.getCode());
            // 移除之前的二维码
            redisTemplate.delete("USER_WX_IMG" + appUser.getId());
        }
        if (dto.getPromotionStatus() != null) {
            appUser.setPromotionStatus(dto.getPromotionStatus());
        }
        if (dto.getUserType() != null) {
            appUser.setUserType(dto.getUserType());
        }
        if (dto.getReferrerUserId() != null) {
            appUser.setReferrerUserId(dto.getReferrerUserId());
        }
        if (dto.getCompanyId() != null) {
            appUser.setCompanyId(dto.getCompanyId());
        }
        appUserService.updateById(appUser);
        return R.ok();
    }
    @ApiOperation(value = "查看详情")
    @GetMapping(value = "/detail")
    public R<TAppUser> detail(@RequestParam String id) {
        return R.ok(appUserService.getById( id));
    public R<TAppUserVo> detail(@RequestParam String id) {
        TAppUser appUser = appUserService.getById(id);
        TAppUserVo tAppUserVo = new TAppUserVo();
        BeanUtils.copyProperties(appUser, tAppUserVo);
        if(appUser.getCompanyId()!=null){
            tAppUserVo.setReferrerCompany(companyService.getById(appUser.getCompanyId()));
        }
        if(appUser.getReferrerUserId()!=null && appUser.getReferrerStatus()==2){
            tAppUserVo.setReferrerUser(appUserService.getById(appUser.getReferrerUserId()));
        }
        return R.ok(tAppUserVo);
    }
    @Log(title = "小程序用户-金币导入", businessType = BusinessType.IMPORT)
    @ApiOperation(value = "小程序用户-金币导入")
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    @PostMapping("/importGold")
    public R<String> importGold(@RequestPart("file") MultipartFile file) {
        Long userId = tokenService.getLoginUser().getUserId();
        List<AppUserGoldImport> imports = new ArrayList<>();
        ImportParams params = new ImportParams();
        params.setHeadRows(1); //表头行数
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
            imports = ExcelImportUtil.importExcel(inputStream,
                    AppUserGoldImport.class, params);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("金币导入失败!");
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new ServiceException(e.getMessage());
            }
        }
        if (CollectionUtils.isEmpty(imports)) {
            throw new ServiceException("金币导入数据为空!");
        }
        JSONObject result = new JSONObject();
        int i = 1;
        for (AppUserGoldImport appUserGoldImport : imports) {
            if (!StringUtils.hasLength(appUserGoldImport.getUserPhone())) {
                result.append("第" + i + "行:[", "用户手机号" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserGoldImport.getGold())) {
                result.append("第" + i + "行:[", "金币" + "]不能为空");
                continue;
            }
            TAppUser user = appUserService.getOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, appUserGoldImport.getUserPhone()).ne(TAppUser::getStatus, 3).last("LIMIT 1"));
            if (user == null) {
                result.append("第" + i + "行:[", "用户不存在" + "]");
                continue;
            }
            BigDecimal totalPrice = BigDecimal.ZERO;
            try {
                totalPrice = new BigDecimal(appUserGoldImport.getGold());
                user.setGoldBalance(user.getGoldBalance().add(totalPrice).setScale(2, RoundingMode.HALF_UP));
            } catch (Exception e) {
                result.append("第" + i + "行:[", "金币" + "]格式错误");
                continue;
            }
            // 添加变更记录
            TGoldChangeRecord goldChangeRecord = new TGoldChangeRecord();
            goldChangeRecord.setAppUserId(user.getId());
            goldChangeRecord.setType(1);
            goldChangeRecord.setPrice(totalPrice);
            goldChangeRecord.setBalance(user.getGoldBalance());
            goldChangeRecord.setCreateUserId(userId);
            goldChangeRecordService.save(goldChangeRecord);
            appUserService.updateById(user);
            i++;
        }
        if (!result.isEmpty()) {
            return R.fail(result.toString());
        }
        return R.ok();
    }
    @Log(title = "小程序用户-用户导入", businessType = BusinessType.IMPORT)
    @ApiOperation(value = "小程序用户-用户导入")
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    @PostMapping("/importUser")
    public R<String> importUser(@RequestPart("file") MultipartFile file) {
        List<AppUserImport> imports = new ArrayList<>();
        ImportParams params = new ImportParams();
        params.setHeadRows(1); //表头行数
        InputStream inputStream = null;
        try {
            inputStream = file.getInputStream();
            imports = ExcelImportUtil.importExcel(inputStream,
                    AppUserImport.class, params);
        } catch (Exception e) {
            e.printStackTrace();
            throw new ServiceException("小程序用户导入失败!");
        } finally {
            try {
                inputStream.close();
            } catch (IOException e) {
                throw new ServiceException(e.getMessage());
            }
        }
        if (CollectionUtils.isEmpty(imports)) {
            throw new ServiceException("小程序用户导入数据为空!");
        }
        JSONObject result = new JSONObject();
        int i = 1;
        for (AppUserImport appUserImport : imports) {
            if (!StringUtils.hasLength(appUserImport.getUsername())) {
                result.append("第" + i + "行:[", "用户名" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserImport.getPhone())) {
                result.append("第" + i + "行:[", "联系电话" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserImport.getSex())) {
                result.append("第" + i + "行:[", "性别" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserImport.getBirth())) {
                result.append("第" + i + "行:[", "出生日期" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserImport.getRole())) {
                result.append("第" + i + "行:[", "角色" + "]不能为空");
                continue;
            }
            if (!StringUtils.hasLength(appUserImport.getCode())) {
                result.append("第" + i + "行:[", "推广号" + "]不能为空");
                continue;
            }
            TAppUser user = appUserService.getOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getPhone, appUserImport.getPhone()).ne(TAppUser::getStatus, 3).last("LIMIT 1"));
            if (user != null) {
                result.append("第" + i + "行:[", "联系电话已存在" + "]");
                continue;
            }
            TAppUser user1 = appUserService.getOne(new LambdaQueryWrapper<TAppUser>().eq(TAppUser::getCode, appUserImport.getCode()).ne(TAppUser::getStatus, 3).last("LIMIT 1"));
            if (user1 != null) {
                result.append("第" + i + "行:[", "推广号已存在" + "]");
                continue;
            }
            String sex = appUserImport.getSex();
            Integer gender = "男".equals(sex) ? 1 : "女".equals(sex) ? 2 : null;
            if (gender == null) {
                result.append("第" + i + "行:[", "性别" + "]格式错误");
                continue;
            }
            String birth = appUserImport.getBirth();
            LocalDate birthday = null;
            try {
                birthday = LocalDate.parse(birth);
            } catch (Exception e) {
                result.append("第" + i + "行:[", "出生日期" + "]格式错误");
                continue;
            }
            String role = appUserImport.getRole();
            Integer userType = "游客".equals(role) ? 1 : "营销员".equals(role) ? 2 : "合伙人".equals(role) ? 3 : null;
            if (userType == null) {
                result.append("第" + i + "行:[", "角色" + "]格式错误");
                continue;
            }
            TAppUser tAppUser = new TAppUser();
            tAppUser.setName(appUserImport.getUsername());
            tAppUser.setCode(appUserImport.getCode());
            tAppUser.setPhone(appUserImport.getPhone());
            tAppUser.setGender(gender);
            tAppUser.setBirthday(birthday);
            tAppUser.setUserType(userType);
            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());
                }
            }
            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++;
        }
        if (!result.isEmpty()) {
            return R.fail(result.toString());
        }
        return R.ok();
    }
    @ApiOperation(value = "小程序用户导出")
    @PostMapping(value = "/exportAppUser")
    @Log(title = "小程序用户-导出", businessType = BusinessType.EXPORT)
    public void exportAppUser(@RequestBody AppUserListQuery query) {
        List<TAppUser> list = appUserService.exportAppUser(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TAppUser.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        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();
            }
        }
    }
    @ApiOperation(value = "一键清空金币")
    @GetMapping(value = "/clearGold")
    @Log(title = "小程序用户-一键清空金币", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public R clearGold() {
        Long userId = tokenService.getLoginUser().getUserId();
        List<TAppUser> list = appUserService.list();
        ArrayList<TGoldChangeRecord> tGoldChangeRecords = new ArrayList<>();
        for (TAppUser user : list) {
            TGoldChangeRecord tGoldChangeRecord = new TGoldChangeRecord();
            tGoldChangeRecord.setAppUserId(user.getId());
            tGoldChangeRecord.setPrice(user.getGoldBalance());
            tGoldChangeRecord.setBalance(BigDecimal.ZERO);
            tGoldChangeRecord.setType(2);
            tGoldChangeRecord.setCreateUserId(userId);
            tGoldChangeRecords.add(tGoldChangeRecord);
        }
        goldChangeRecordService.saveBatch(tGoldChangeRecords);
        appUserService.update(new LambdaUpdateWrapper<TAppUser>().set(TAppUser::getGoldBalance, 0));
        return R.ok();
    }
    @ApiOperation(value = "批量修改积分")
    @PostMapping(value = "/batchUpdateGold")
    @Log(title = "小程序用户-批量修改积分", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public R batchUpdateGold(@RequestBody BatchUpdateIntegralDto dto) {
        Long userId = tokenService.getLoginUser().getUserId();
        List<Integer> userIds = dto.getUserIds();
        List<TAppUser> tAppUsers = appUserService.listByIds(userIds);
        List<TIntegralChangeRecord> tIntegralChangeRecords = new ArrayList<>();
        for (TAppUser tAppUser : tAppUsers) {
            TIntegralChangeRecord tIntegralChangeRecord = new TIntegralChangeRecord();
            tIntegralChangeRecord.setAppUserId(tAppUser.getId());
            tIntegralChangeRecord.setOldBalance(new BigDecimal(tAppUser.getAccumulativeIntegral()));
            tIntegralChangeRecord.setPrice(new BigDecimal(dto.getIntegral()));
            tIntegralChangeRecord.setCreateUserId(userId);
            tIntegralChangeRecords.add(tIntegralChangeRecord);
            tAppUser.setAccumulativeIntegral(dto.getIntegral());
        }
        integralChangeRecordService.saveBatch(tIntegralChangeRecords);
        appUserService.updateBatchById(tAppUsers);
        return R.ok();
    }
    @ApiOperation(value = "积分修改记录")
    @PostMapping(value = "/integralChangeRecord")
    public R<PageInfo<IntegralChangeRecordVo>> integralChangeRecord(@RequestBody IntegralChangeRecordQuery query) {
        return R.ok(integralChangeRecordService.integralChangeRecord(query));
    }
    @ApiOperation(value = "积分修改记录导出")
    @PostMapping(value = "/exportIntegralChangeRecord")
    @Log(title = "积分修改记录-导出", businessType = BusinessType.EXPORT)
    public void exportIntegralChangeRecord(@RequestBody IntegralChangeRecordQuery query) {
        List<IntegralChangeRecordVo> list = integralChangeRecordService.integralChangeRecordExport(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), IntegralChangeRecordVo.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        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();
            }
        }
    }
    @ApiOperation(value = "金币记录")
    @PostMapping(value = "/goldChangeRecord")
    public R<Page<TGoldChangeRecord>> goldChangeRecord(@RequestBody GoldChangeRecordQuery query) {
        Page<TGoldChangeRecord> tGoldChangeRecordPage = new Page<>(query.getPageNum(), query.getPageSize());
        Page<TGoldChangeRecord> page = goldChangeRecordService.page(tGoldChangeRecordPage, new LambdaQueryWrapper<TGoldChangeRecord>()
                .eq(TGoldChangeRecord::getAppUserId, query.getUserId())
                .orderByDesc(TGoldChangeRecord::getCreateTime));
        List<TGoldChangeRecord> records = page.getRecords();
        if(!records.isEmpty()){
            records.forEach(record -> {
                Long createUserId = record.getCreateUserId();
                if(createUserId!=null){
                    SysUser sysUser = sysUserMapper.selectUserById(createUserId);
                    if(sysUser!=null){
                        record.setCreateUserName(sysUser.getUserName());
                    }
                }
            });
        }
        page.setRecords( records);
        return R.ok(page);
    }
    @ApiOperation(value = "金币充值")
    @PostMapping(value = "/goldAdd")
    @Log(title = "小程序用户-金币充值", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public R goldChange(@RequestBody GoldChangeDto dto) {
        Long userId = tokenService.getLoginUser().getUserId();
        if(dto.getChangeNum()<=0){
            return R.fail("充值数不能小于等于0");
        }
        TAppUser appUser = appUserService.getById(dto.getUserId());
        TGoldChangeRecord tGoldChangeRecord = new TGoldChangeRecord();
        tGoldChangeRecord.setAppUserId(appUser.getId());
        tGoldChangeRecord.setType(1);
        tGoldChangeRecord.setPrice(new BigDecimal(dto.getChangeNum()));
        tGoldChangeRecord.setBalance(appUser.getGoldBalance().add(new BigDecimal(dto.getChangeNum())).setScale(0, BigDecimal.ROUND_HALF_UP));
        tGoldChangeRecord.setCreateUserId(userId);
        appUser.setGoldBalance(tGoldChangeRecord.getBalance());
        goldChangeRecordService.save(tGoldChangeRecord);
        appUserService.updateById(appUser);
        return R.ok();
    }
    @ApiOperation(value = "金币扣除")
    @PostMapping(value = "/goldSub")
    @Log(title = "小程序用户-金币扣除", businessType = BusinessType.UPDATE)
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public R goldSub(@RequestBody GoldChangeDto dto) {
        Long userId = tokenService.getLoginUser().getUserId();
        if(dto.getChangeNum()<=0){
            return R.fail("扣除数不能小于等于0");
        }
        TAppUser appUser = appUserService.getById(dto.getUserId());
        if(appUser.getGoldBalance().compareTo(new BigDecimal(dto.getChangeNum()))<0){
            return R.fail("用户金币不足");
        }
        TGoldChangeRecord tGoldChangeRecord = new TGoldChangeRecord();
        tGoldChangeRecord.setAppUserId(appUser.getId());
        tGoldChangeRecord.setType(2);
        tGoldChangeRecord.setPrice(new BigDecimal(dto.getChangeNum()));
        tGoldChangeRecord.setBalance(appUser.getGoldBalance().subtract(new BigDecimal(dto.getChangeNum())).setScale(0, BigDecimal.ROUND_HALF_UP));
        tGoldChangeRecord.setCreateUserId(userId);
        appUser.setGoldBalance(tGoldChangeRecord.getBalance());
        goldChangeRecordService.save(tGoldChangeRecord);
        appUserService.updateById(appUser);
        return R.ok();
    }
    @ApiOperation(value = "购买记录")
    @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);
        tBigGiftPackageOrderPage.setRecords(list);
        return R.ok(tBigGiftPackageOrderPage);
    }
    @ApiOperation(value = "用户-购买记录导出")
    @PostMapping(value = "/pageOrderListExport")
    @Log(title = "购买记录-导出", businessType = BusinessType.EXPORT)
    public void pageOrderListExport(@RequestBody @Valid GoldChangeRecordQuery query){
        List<TBigGiftPackageOrder> list = bigGiftPackageOrderService.pageOrderListExport(query);
        ArrayList<TBigGiftPackageOrderUserExport> tBigGiftPackageOrderUserExports = new ArrayList<>();
        for (TBigGiftPackageOrder order : list) {
            TBigGiftPackageOrderUserExport export = new TBigGiftPackageOrderUserExport();
            export.setOrderNo(order.getCode());
            export.setCreateTime(order.getCreateTime());
            export.setUsername(order.getUserName());
            export.setUserPhone(order.getPhone());
            export.setOrderAmount(order.getOrderPrice());
            export.setGoodsName(order.getBigGiftPackageName());
            export.setPayMethod("微信支付");
            export.setDeposit(order.getDeposit());
            export.setBalance(order.getFinalPayment());
            export.setOrderStatus(order.getStatus());
            tBigGiftPackageOrderUserExports.add(export);
        }
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), TBigGiftPackageOrderUserExport.class, tBigGiftPackageOrderUserExports);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        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();
            }
        }
    }
    @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);
        page.setRecords(list);
        return R.ok(page);
    }
    @ApiOperation(value = "用户-推广记录导出")
    @PostMapping(value = "/exportUserPromotion")
    @Log(title = "推广记录-导出", businessType = BusinessType.EXPORT)
    public void exportUserPromotion(@RequestBody @Valid UserPromotionPageListQuery query){
        List<UserPromotionPageListVo> list = appUserService.userPromotionPageListExport(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), UserPromotionPageListVo.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        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();
            }
        }
    }
    @ApiOperation(value = "用户收益明细")
    @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);
        page.setRecords(list);
        return R.ok(page);
    }
    @ApiOperation(value = "用户收益明细导出")
    @PostMapping(value = "/exportUserProfit")
    @Log(title = "收益明细-导出", businessType = BusinessType.EXPORT)
    public void exportUserProfit(@RequestBody @Valid UserProfitPageListQuery query){
        List<UserProfitPageListVo> list = bigGiftPackageOrderService.profitUserPageListExport(query);
        Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), UserProfitPageListVo.class, list);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        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();
            }
        }
    }
    @ApiOperation(value = "用户- 结算记录")
    @PostMapping("/settlementPageList")
    public R<Page<TIntegralSettlement>> settlementPageList(@RequestBody @Valid GoldChangeRecordQuery query) {
        Page<TIntegralSettlement> page = new Page<>(query.getPageNum(), query.getPageSize());
        LambdaQueryWrapper<TIntegralSettlement> queryWrapper = new LambdaQueryWrapper<TIntegralSettlement>().eq(TIntegralSettlement::getAppUserId, query.getUserId()).orderByDesc(TIntegralSettlement::getCreateTime);
        Page<TIntegralSettlement> integralSettlementPage = integralSettlementService.page(page, queryWrapper);
        return R.ok(integralSettlementPage);
    }
    @ApiOperation(value = "用户结算记录导出")
    @PostMapping(value = "/exportSettlementPageList")
    @Log(title = "结算记录-导出", businessType = BusinessType.EXPORT)
    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);
        HttpServletResponse response = WebUtils.response();
        assert response != null;
        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();
            }
        }
    }
}