| | |
| | | import com.ruoyi.other.api.dto.ExchangeCodeBindDTO; |
| | | import com.ruoyi.other.api.dto.ExchangeCodeConsumeDTO; |
| | | import com.ruoyi.other.api.dto.ExchangeCodePackageSaveDTO; |
| | | import com.ruoyi.other.api.dto.ExchangeCodeUseRecordQuery; |
| | | import com.ruoyi.other.api.domain.TExchangeCodeUseRecord; |
| | | import com.ruoyi.other.api.vo.ExchangeCodeBindResultVO; |
| | | import com.ruoyi.other.api.vo.ExchangeCodeConsumeResultVO; |
| | | import com.ruoyi.other.api.vo.ExchangeCodePackageDetailVO; |
| | |
| | | import java.util.Map; |
| | | import java.util.zip.ZipEntry; |
| | | import java.util.zip.ZipOutputStream; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | |
| | | @RestController |
| | | @RequestMapping("/exchange-code-package") |
| | |
| | | @Resource |
| | | private TExchangeCodePackageService exchangeCodePackageService; |
| | | |
| | | /** |
| | | * 分页查询兑换码卡包列表。 |
| | | * |
| | | * @param query 查询条件 |
| | | * @return 卡包分页结果 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode"}, logical = Logical.OR) |
| | | @PostMapping("/pageList") |
| | | @ApiOperation(value = "兑换码卡包分页", tags = {"管理后台-兑换码管理"}) |
| | |
| | | return AjaxResult.ok(exchangeCodePackageService.pageList(query)); |
| | | } |
| | | |
| | | /** |
| | | * 新增兑换码卡包。 |
| | | * |
| | | * @param dto 卡包保存参数 |
| | | * @return 操作结果 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/add"}, logical = Logical.OR) |
| | | @PostMapping("/save") |
| | | @ApiOperation(value = "新增兑换码卡包", tags = {"管理后台-兑换码管理"}) |
| | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 编辑兑换码卡包。 |
| | | * |
| | | * @param dto 卡包保存参数 |
| | | * @return 操作结果 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/update"}, logical = Logical.OR) |
| | | @PostMapping("/update") |
| | | @ApiOperation(value = "编辑兑换码卡包", tags = {"管理后台-兑换码管理"}) |
| | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 更新兑换码卡包启用状态。 |
| | | * |
| | | * @param dto 卡包ID及状态参数 |
| | | * @return 操作结果 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/update"}, logical = Logical.OR) |
| | | @PostMapping("/updateStatus") |
| | | @ApiOperation(value = "更新兑换码卡包启用状态", tags = {"管理后台-兑换码管理"}) |
| | | @Log(title = "【兑换码管理】更新启用状态", businessType = BusinessType.UPDATE, operatorType = OperatorType.MANAGE) |
| | | public AjaxResult<Void> updateStatus(@RequestBody ExchangeCodePackageSaveDTO dto) { |
| | | exchangeCodePackageService.updatePackageStatus(dto.getId(), dto.getStatus()); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 删除兑换码卡包。 |
| | | * |
| | | * @param ids 卡包ID,多个ID用英文逗号分隔 |
| | | * @return 操作结果 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/del"}, logical = Logical.OR) |
| | | @GetMapping("/delete") |
| | | @ApiOperation(value = "删除兑换码卡包", tags = {"管理后台-兑换码管理"}) |
| | |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | | /** |
| | | * 查询兑换码卡包详情。 |
| | | * |
| | | * @param id 卡包ID |
| | | * @return 卡包详情 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/select"}, logical = Logical.OR) |
| | | @GetMapping("/detail") |
| | | @ApiOperation(value = "兑换码卡包详情", tags = {"管理后台-兑换码管理"}) |
| | |
| | | return AjaxResult.ok(exchangeCodePackageService.getDetail(id)); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询兑换码明细。 |
| | | * |
| | | * @param query 查询条件 |
| | | * @return 兑换码明细分页结果 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/select"}, logical = Logical.OR) |
| | | @PostMapping("/codePage") |
| | | @ApiOperation(value = "兑换码明细分页", tags = {"管理后台-兑换码管理"}) |
| | |
| | | return AjaxResult.ok(exchangeCodePackageService.codePage(query)); |
| | | } |
| | | |
| | | /** |
| | | * 批量失效兑换码。 |
| | | * |
| | | * @param dto 失效参数 |
| | | * @return 失效结果 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/del"}, logical = Logical.OR) |
| | | @PostMapping("/batchInvalidate") |
| | | @ApiOperation(value = "批量失效兑换码", tags = {"管理后台-兑换码管理"}) |
| | |
| | | return AjaxResult.ok(result).put("msg", "已失效" + result.getSuccessCount() + "条,跳过" + result.getSkipCount() + "条"); |
| | | } |
| | | |
| | | /** |
| | | * 导出兑换码明细。 |
| | | * |
| | | * @param query 查询条件 |
| | | * @throws IOException 输出流写出异常 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/select"}, logical = Logical.OR) |
| | | @PutMapping("/export") |
| | | @ApiOperation(value = "导出兑换码明细", tags = {"管理后台-兑换码管理"}) |
| | |
| | | outputStream.close(); |
| | | } |
| | | |
| | | /** |
| | | * 下载单个兑换码二维码。 |
| | | * |
| | | * @param id 兑换码明细ID |
| | | * @throws Exception 二维码生成或输出异常 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/select"}, logical = Logical.OR) |
| | | @GetMapping("/downloadQRCode/{id}") |
| | | @ApiOperation(value = "下载单个兑换码二维码", tags = {"管理后台-兑换码管理"}) |
| | |
| | | QRCodeUtils.encode(buildQrPayload(detail), response.getOutputStream()); |
| | | } |
| | | |
| | | /** |
| | | * 批量下载未绑定兑换码二维码。 |
| | | * |
| | | * @param query 查询条件 |
| | | * @throws Exception 二维码生成或压缩输出异常 |
| | | */ |
| | | @RequiresPermissions(value = {"/exchangeCode/select"}, logical = Logical.OR) |
| | | @PutMapping("/downloadUnboundQRCodes") |
| | | @ApiOperation(value = "批量下载未绑定二维码", tags = {"管理后台-兑换码管理"}) |
| | |
| | | zipOutputStream.close(); |
| | | } |
| | | |
| | | /** |
| | | * 小程序兑换码绑定。 |
| | | * |
| | | * @param dto 绑定参数 |
| | | * @param userId 用户ID |
| | | * @param phone 手机号 |
| | | * @return 绑定结果 |
| | | */ |
| | | @PostMapping("/bind") |
| | | @ApiOperation(value = "小程序兑换码绑定", tags = {"小程序-兑换码"}) |
| | | public R<ExchangeCodeBindResultVO> bind(@RequestBody ExchangeCodeBindDTO dto, |
| | |
| | | return R.ok(exchangeCodePackageService.bindExchangeCode(dto, userId, phone)); |
| | | } |
| | | |
| | | /** |
| | | * 查询用户兑换码余额映射。 |
| | | * |
| | | * @param userIds 用户ID集合 |
| | | * @return 用户余额映射 |
| | | */ |
| | | @PostMapping("/balanceMap") |
| | | @ApiOperation(value = "查询用户兑换码余额Map", tags = {"内部-兑换码"}) |
| | | public R<Map<Long, BigDecimal>> balanceMap(@RequestBody List<Long> userIds) { |
| | | return R.ok(exchangeCodePackageService.getUserExchangeCodeBalanceMap(userIds)); |
| | | } |
| | | |
| | | /** |
| | | * 扣减用户兑换码余额。 |
| | | * |
| | | * @param dto 扣减参数 |
| | | * @return 扣减结果 |
| | | */ |
| | | @PostMapping("/consumeBalance") |
| | | @ApiOperation(value = "扣减用户兑换码余额", tags = {"内部-兑换码"}) |
| | | public R<ExchangeCodeConsumeResultVO> consumeBalance(@RequestBody ExchangeCodeConsumeDTO dto) { |
| | | return R.ok(exchangeCodePackageService.consumeBalance(dto)); |
| | | } |
| | | |
| | | /** |
| | | * 退款返还用户兑换码余额。 |
| | | * |
| | | * @param dto 退款参数 |
| | | * @return 退款结果 |
| | | */ |
| | | @PostMapping("/refundBalance") |
| | | @ApiOperation(value = "退还兑换码余额", tags = {"小程序-兑换码"}) |
| | | public R<ExchangeCodeConsumeResultVO> refundBalance(@RequestBody ExchangeCodeConsumeDTO dto) { |
| | | return R.ok(exchangeCodePackageService.refundBalance(dto)); |
| | | } |
| | | |
| | | /** |
| | | * 分页查询兑换码余额流水。 |
| | | * |
| | | * @param query 查询条件 |
| | | * @return 流水分页结果 |
| | | */ |
| | | @PostMapping("/useRecord/page") |
| | | @ApiOperation(value = "兑换码余额流水分页", tags = {"小程序-兑换码"}) |
| | | public R<Page<TExchangeCodeUseRecord>> useRecordPage(@RequestBody ExchangeCodeUseRecordQuery query) { |
| | | return R.ok(exchangeCodePackageService.useRecordPage(query)); |
| | | } |
| | | |
| | | /** |
| | | * 查询兑换码余额流水详情。 |
| | | * |
| | | * @param id 流水ID |
| | | * @param userId 用户ID |
| | | * @return 流水详情 |
| | | */ |
| | | @GetMapping("/useRecord/detail") |
| | | @ApiOperation(value = "兑换码余额流水详情", tags = {"小程序-兑换码"}) |
| | | public R<TExchangeCodeUseRecord> useRecordDetail(@RequestParam("id") Long id, |
| | | @RequestParam("userId") Long userId) { |
| | | return R.ok(exchangeCodePackageService.useRecordDetail(id, userId)); |
| | | } |
| | | |
| | | /** |
| | | * 构建二维码内容。 |
| | | * |
| | | * @param detail 兑换码明细 |
| | | * @return 二维码载荷内容 |
| | | */ |
| | | private String buildQrPayload(ExchangeCodeDetailVO detail) { |
| | | return "code=" + detail.getCode() + "&password=" + detail.getPassword(); |
| | | } |