| | |
| | | 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.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.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.AppUserGoldImport; |
| | | import com.ruoyi.system.export.AppUserImport; |
| | | import com.ruoyi.system.export.BigGiftPackageImport; |
| | | import com.ruoyi.system.mapper.SysUserMapper; |
| | | import com.ruoyi.system.model.*; |
| | | import com.ruoyi.system.query.AppUserListQuery; |
| | | import com.ruoyi.system.query.BigGiftPackageQuery; |
| | | import com.ruoyi.system.service.TAppUserService; |
| | | import com.ruoyi.system.service.TCompanyService; |
| | | import com.ruoyi.system.service.TGoldChangeRecordService; |
| | | import com.ruoyi.system.service.TIntegralChangeRecordService; |
| | | import com.ruoyi.system.query.*; |
| | | import com.ruoyi.system.service.*; |
| | | import com.ruoyi.system.vo.IntegralChangeRecordVo; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.apache.poi.ss.usermodel.Workbook; |
| | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | import java.util.stream.Collectors; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | |
| | | @Autowired |
| | | private TIntegralChangeRecordService integralChangeRecordService; |
| | | |
| | | @Autowired |
| | | private SysUserMapper sysUserMapper; |
| | | |
| | | @Autowired |
| | | private TBigGiftPackageOrderService bigGiftPackageOrderService; |
| | | |
| | | |
| | | @ApiOperation(value = "用户管理分页列表") |
| | |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | @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(), 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 = "金币记录") |
| | | @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); |
| | | } |
| | | |
| | | } |
| | | |