无关风月
2025-01-10 2c258c39133435fa0e6e6da85d503982fd5a967d
manage/src/main/java/com/jilongda/manage/controller/TCouponController.java
@@ -15,6 +15,7 @@
import com.jilongda.manage.service.TAppUserService;
import com.jilongda.manage.service.TCouponReceiveService;
import com.jilongda.manage.service.TCouponService;
import com.jilongda.manage.utils.OssUploadUtil;
import com.jilongda.manage.utils.QRCodeUtil;
import com.jilongda.manage.vo.TAppUserVO;
import com.jilongda.manage.vo.TCouponInfoVO;
@@ -72,6 +73,7 @@
    @ApiOperation(value = "添加优惠券")
    @PostMapping(value = "/add")
    public ApiResult<String> add( @RequestBody TCoupon dto) throws Exception {
        if (dto.getType()==1||dto.getType()==4)dto.setGrantStatus(1);
        couponService.save(dto);
        switch (dto.getType()){
            case 2:
@@ -91,6 +93,7 @@
                    }
                    tCouponReceive.setAmountCondition(dto.getAmountCondition());
                    tCouponReceive.setStatus(1);
                    tCouponReceive.setCouponName(dto.getName());
                    tCouponReceives.add(tCouponReceive);
                }
                couponReceiveService.saveBatch(tCouponReceives);
@@ -102,7 +105,7 @@
                    TCouponReceive tCouponReceive = new TCouponReceive();
                    tCouponReceive.setCouponId(dto.getId());
                    tCouponReceive.setUserId(userId);
                    tCouponReceive.setType(2);
                    tCouponReceive.setType(3);
                    tCouponReceive.setAmount(dto.getAmount());
                    tCouponReceive.setStoreId(dto.getStoreId());
                    if (dto.getTime()!=0){
@@ -110,6 +113,7 @@
                    }
                    tCouponReceive.setAmountCondition(dto.getAmountCondition());
                    tCouponReceive.setStatus(1);
                    tCouponReceive.setCouponName(dto.getName());
                    tCouponReceives1.add(tCouponReceive);
                }
                couponReceiveService.saveBatch(tCouponReceives1);
@@ -118,10 +122,20 @@
                String code = "{\"id\": "+dto.getId()+ "}";
                BufferedImage blueImage = QRCodeUtil.createImage(code);
                MultipartFile blueFile = convert(blueImage, new Date().getTime() + UUIDUtil.getRandomCode(3) + ".PNG");
                // todo 没有云存储
//                String s = OssUploadUtil.ossUpload("img/", blueFile);
                break;
                String s = OssUploadUtil.ossUpload("eyes/", blueFile);
                dto.setQrCode(s);
                couponService.updateById(dto);
                return ApiResult.success(s);
        }
        return ApiResult.success();
    }
    @ApiOperation(value = "暂停发放 只有type为1和4的时候")
    @PostMapping(value = "/stop")
    public ApiResult stop(Integer id) throws Exception {
        TCoupon byId = couponService.getById(id);
        byId.setGrantStatus(2);
        couponService.updateById(byId);
        return ApiResult.success();
    }
    @ApiOperation(value = "修改优惠券")
@@ -143,9 +157,18 @@
                .eq(TCouponReceive::getCouponId, id)
                .eq(TCouponReceive::getStatus, 2)).size();
        tCouponInfoVO.setUseCount(size1);
        if (byId.getType()==3){
            // 查询领取人
            List<Integer> collect = couponReceiveService.lambdaQuery()
                    .eq(TCouponReceive::getCouponId, id).list()
                    .stream().map(TCouponReceive::getUserId)
                    .distinct()
                    .collect(Collectors.toList());
            tCouponInfoVO.setUserIds(collect);
        }
        return ApiResult.success(tCouponInfoVO);
    }
    public static MultipartFile convert(BufferedImage bufferedImage, String fileName) throws IOException {
        // 将 BufferedImage 转换为字节数组
        ByteArrayOutputStream baos = new ByteArrayOutputStream();