rentaiming
2024-07-24 b3526a4d0113bca15728f904322a6b501fa7b467
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package com.ruoyi.goods.controller.inner;
 
 
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.ruoyi.common.core.constant.SecurityConstants;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.security.annotation.InnerAuth;
import com.ruoyi.system.api.domain.GoodsGroupPurchaseInfo;
import com.ruoyi.goods.service.impl.GoodsGroupPurchaseInfoServiceImpl;
import com.ruoyi.system.api.domain.GoodsGroupPurchase;
import com.ruoyi.goods.service.IGoodsGroupPurchaseService;
import com.ruoyi.system.api.feignClient.OrderClient;
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;
 
    private final GoodsGroupPurchaseInfoServiceImpl goodsGroupPurchaseInfoServiceImpl;
 
    private final OrderClient orderClient;
 
    @InnerAuth
    @PostMapping("/getGoodsSeckiGoodsGroupPurchaseOne")
    public R<GoodsGroupPurchase> getGoodsSeckiGoodsGroupPurchaseOne(@RequestBody Long goodsSkuId) {
        GoodsGroupPurchase GoodsSeckillOne = goodsGroupPurchaseService.getById(goodsSkuId);
        return R.ok(GoodsSeckillOne);
    }
 
 
    @InnerAuth
    @PostMapping("/getGoodsSeckiGoodsGroupPurchaseInfo")
    public R<GoodsGroupPurchaseInfo> getGoodsSeckiGoodsGroupPurchaseInfo(@RequestBody Long goodsSkuId) {
        LambdaQueryWrapper<GoodsGroupPurchaseInfo> wrapper6= Wrappers.lambdaQuery();
        wrapper6.eq(GoodsGroupPurchaseInfo::getDelFlag,0);
        wrapper6.eq(GoodsGroupPurchaseInfo::getGroupStatus,0);
        wrapper6.eq(GoodsGroupPurchaseInfo::getGroupPurchaseId,goodsSkuId);
        GoodsGroupPurchaseInfo one1 = goodsGroupPurchaseInfoServiceImpl.getOne(wrapper6);
 
        return R.ok(one1);
    }
 
    @InnerAuth
    @PostMapping("/getGoodsSeckiGoodsGroupPurchaseInfo1")
    public R<GoodsGroupPurchaseInfo> getGoodsSeckiGoodsGroupPurchaseInfo1(@RequestBody GoodsGroupPurchaseInfo goodsGroupPurchaseInfo) {
        LambdaQueryWrapper<GoodsGroupPurchaseInfo> wrapper6= Wrappers.lambdaQuery();
        wrapper6.eq(GoodsGroupPurchaseInfo::getDelFlag,0);
        wrapper6.eq(GoodsGroupPurchaseInfo::getMubre,goodsGroupPurchaseInfo.getMubre());
        GoodsGroupPurchaseInfo one1 = goodsGroupPurchaseInfoServiceImpl.getOne(wrapper6);
       int i=one1.getCurrentNumber()-1;
       if (i==0){
           one1.setCurrentNumber(0);
           one1.setGroupStatus(0);
           goodsGroupPurchaseInfoServiceImpl.updateById(one1);
           goodsGroupPurchaseInfoServiceImpl.removeById(one1);
       }else{
           one1.setCurrentNumber(i);
           if (one1.getGroupSize()>one1.getCurrentNumber()){
               one1.setGroupStatus(0);
           }
           goodsGroupPurchaseInfoServiceImpl.updateById(one1);
       }
 
        return R.ok(one1);
    }
 
    @InnerAuth
    @PostMapping("/updgoodsGroupPurchaseInfo")
    public R getGoodsSeckiGoodsGroupPurchaseInfo(@RequestBody GoodsGroupPurchaseInfo goodsGroupPurchaseInfo) {
             if (goodsGroupPurchaseInfo.getId()!=null){
                 GoodsGroupPurchaseInfo byId = goodsGroupPurchaseInfoServiceImpl.getById(goodsGroupPurchaseInfo.getId());
                 Integer num= byId.getCurrentNumber()+1;
                 byId.setCurrentNumber(num);
                 if (num==byId.getGroupSize()){
                     byId.setGroupStatus(1);
                     orderClient.updateOrderStatusByMubres1(byId.getMubre(), SecurityConstants.INNER);
                 }
                 goodsGroupPurchaseInfoServiceImpl.updateById(byId);
             }else{
                 goodsGroupPurchaseInfoServiceImpl.save(goodsGroupPurchaseInfo);
             }
 
        return R.ok();
    }
 
 
    /**
     * 团购商品开始团购
     *
     * @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();
    }
}