rentaiming
2024-07-04 fcd4954fc859440df4b04b4a8153c54a824c78b7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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.*;
 
/**
 * <p>
 * 商品团购表 前端控制器
 * </p>
 *
 * @author mitao
 * @since 2024-05-16
 */
@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/goods-group-purchase")
public class GoodsGroupPurchaseController {
 
    private final IGoodsGroupPurchaseService goodsGroupPurchaseService;
 
    @InnerAuth
    @PostMapping("/getGoodsSeckiGoodsGroupPurchaseOne")
    @ResponseBody
    public R<GoodsGroupPurchase> getGoodsSeckiGoodsGroupPurchaseOne(@RequestBody Long goodsSkuId) {
        GoodsGroupPurchase GoodsSeckillOne = goodsGroupPurchaseService.getById(goodsSkuId);
        return R.ok(GoodsSeckillOne);
    }
 
    /**
     * 团购商品开始团购
     *
     * @param groupPurchaseId 团购商品id
     */
    @InnerAuth
    @GetMapping("/start/{groupPurchaseId}")
    R<?> startGroupPurchase(@PathVariable("groupPurchaseId") Long 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();
    }
 
 
    /**
     * 团购商品结束团购
     *
     * @param groupPurchaseId 团购商品id
     */
    @InnerAuth
    @GetMapping("/end/{groupPurchaseId}")
    R<?> endGroupPurchase(@PathVariable("groupPurchaseId") Long groupPurchaseId) {
        try {
            goodsGroupPurchaseService.endGroupPurchase(groupPurchaseId);
        } catch (JsonProcessingException e) {
            log.error("团购商品开始团购失败", e);
            return R.fail("团购商品结束团购失败");
        }
        return R.ok();
    }
}