rentaiming
2024-07-10 b29becf95484be48aa09e87fcc7cc19f94cf9c81
ruoyi-modules/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/inner/GoodsGroupPurchaseController.java
@@ -1,15 +1,14 @@
package com.ruoyi.goods.controller.inner;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.system.api.domain.GoodsGroupPurchase;
import com.ruoyi.goods.service.IGoodsGroupPurchaseService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
/**
 * <p>
@@ -27,6 +26,14 @@
    private final IGoodsGroupPurchaseService goodsGroupPurchaseService;
    @InnerAuth
    @PostMapping("/getGoodsSeckiGoodsGroupPurchaseOne")
    @ResponseBody
    public R<GoodsGroupPurchase> getGoodsSeckiGoodsGroupPurchaseOne(@RequestBody Long goodsSkuId) {
        GoodsGroupPurchase GoodsSeckillOne = goodsGroupPurchaseService.getById(goodsSkuId);
        return R.ok(GoodsSeckillOne);
    }
    /**
     * 团购商品开始团购
     *
@@ -35,9 +42,45 @@
    @InnerAuth
    @GetMapping("/start/{groupPurchaseId}")
    R<?> startGroupPurchase(@PathVariable("groupPurchaseId") Long groupPurchaseId) {
        goodsGroupPurchaseService.startGroupPurchase(groupPurchaseId);
        try {
            goodsGroupPurchaseService.startGroupPurchase(groupPurchaseId);
        } catch (JsonProcessingException e) {
            log.error("团购商品开始团购失败", e);
            return R.fail("团购商品开始团购失败");
        }
        return R.ok();
    }
    @InnerAuth
    @GetMapping("/num/{groupPurchaseId}")
    R<?> GroupPurchaseNum(@PathVariable("groupPurchaseId") Long groupPurchaseId) {
        try {
            GoodsGroupPurchase byId = goodsGroupPurchaseService.getById(groupPurchaseId);
           Integer m= byId.getCurrentNumber()+1;
            byId.setCurrentNumber(m);
            goodsGroupPurchaseService.updateById(byId);
        } catch (Exception e) {
            log.error("团购商品开始团购失败", e);
            return R.fail("团购商品开始团购失败");
        }
        return R.ok();
    }
    @InnerAuth
    @GetMapping("/num1/{groupPurchaseId}")
    R<?> GroupPurchaseNum1(@PathVariable("groupPurchaseId") Long groupPurchaseId) {
        try {
            GoodsGroupPurchase byId = goodsGroupPurchaseService.getById(groupPurchaseId);
            Integer m= byId.getCurrentNumber()-1;
            byId.setCurrentNumber(m);
            goodsGroupPurchaseService.updateById(byId);
        } catch (Exception e) {
            log.error("团购商品开始团购失败", e);
            return R.fail("团购商品开始团购失败");
        }
        return R.ok();
    }
    /**
     * 团购商品结束团购
@@ -47,7 +90,12 @@
    @InnerAuth
    @GetMapping("/end/{groupPurchaseId}")
    R<?> endGroupPurchase(@PathVariable("groupPurchaseId") Long groupPurchaseId) {
        goodsGroupPurchaseService.endGroupPurchase(groupPurchaseId);
        try {
            goodsGroupPurchaseService.endGroupPurchase(groupPurchaseId);
        } catch (JsonProcessingException e) {
            log.error("团购商品开始团购失败", e);
            return R.fail("团购商品结束团购失败");
        }
        return R.ok();
    }
}