wzy
2021-01-10 16da0ad1fda1dffa3019425a6887d38ed4217f44
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
package com.matrix.system.shopXcx.api.action;
 
import com.matrix.core.pojo.AjaxResult;
import com.matrix.system.shopXcx.api.service.WXShopOrderService;
import com.matrix.system.shopXcx.api.service.WxShopActivitiesSecKillService;
import com.matrix.system.shopXcx.api.vo.SecKillVO;
import com.matrix.system.shopXcx.bean.*;
import com.matrix.system.shopXcx.dao.*;
import com.matrix.system.shopXcx.dto.CreateSecKillDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
 
import java.math.BigDecimal;
import java.util.List;
 
/**
 * @author wzy
 */
@RestController
@CrossOrigin(origins = "*")
@RequestMapping(value = "/wxapi/seckill")
public class WxShopActivitiesSecKillAction {
 
    @Autowired
    private ShopActivitiesDao shopActivitiesDao;
 
    @Autowired
    private ShopActivitiesSeckillInfoDao shopActivitiesSeckillInfoDao;
    @Autowired
    private ShopProductAttrRefDao shopProductAttrRefDao;
    @Autowired
    private ShopProductImgDao shopProductImgDao;
    @Autowired
    private ShopSkuDao shopSkuDao;
    @Autowired
    private ShopProductParamRefDao shopProductParamRefDao;
    @Autowired
    private WXShopOrderService wxShopOrderService;
    @Autowired
    private WxShopActivitiesSecKillService wxShopActivitiesSecKillService;
 
 
    /**
     * 获取正在进行的秒杀活动列表
     *
     * @return
     */
    @GetMapping(value = "/findSecKillActList/{shopId}")
    public AjaxResult findSecKillActList(@PathVariable("shopId") Long shopId) {
        List<ShopActivities> list = shopActivitiesDao.selectSecKillActivitiesForIng(shopId);
        return new AjaxResult(AjaxResult.STATUS_SUCCESS, list);
    }
 
    /**
     * 根据活动Id查询该秒杀活动下的产品列表
     *
     * @param secKillVO
     * @return
     */
    @PostMapping(value = "/findSecKillGoodsListById")
    public AjaxResult findSecKillGoodsListById(@RequestBody SecKillVO secKillVO) {
        List<ShopActivitiesSeckillInfo> list = shopActivitiesSeckillInfoDao.selectSecKillGoodsListForWx(secKillVO);
        AjaxResult ajaxResult = AjaxResult.buildSuccessInstance(list);
        return ajaxResult;
    }
 
    /**
     * 查询秒杀产品详情
     *
     * @param siId 秒杀信息id
     * @return
     */
    @GetMapping(value = "/findSecKillGoodsInfo/{siId}")
    public AjaxResult findSecKillGoodsInfo(@PathVariable("siId") Long siId) {
        ShopActivitiesSeckillInfo seckillInfo = shopActivitiesSeckillInfoDao.selectById(siId);
        if (seckillInfo == null) {
            return AjaxResult.buildFailInstance("参数异常");
        }
 
        ShopActivities shopActivities = shopActivitiesDao.selectById(seckillInfo.getActId());
 
        int goodsId = seckillInfo.getGoods().getId();
        List<ShopProductAttrRef> shopProductAttrRefs = shopProductAttrRefDao.selectByPid(goodsId);
        List<ShopProductImg> shopProductImgs = shopProductImgDao.selectByPid(goodsId);
        List<ShopSku> shopSkus = shopSkuDao.selectByPid(goodsId);
        List<ShopProductParamRef> shopProductParamRefs = shopProductParamRefDao.selectByPid(goodsId);
        seckillInfo.getGoods().setAttrRefs(shopProductAttrRefs);
        seckillInfo.getGoods().setProductImgs(shopProductImgs);
        seckillInfo.getGoods().setSkus(shopSkus);
        seckillInfo.getGoods().setParams(shopProductParamRefs);
 
        AjaxResult ajaxResult = AjaxResult.buildSuccessInstance("获取成功");
        if (shopActivities.getActEndTime().getTime() < System.currentTimeMillis()) {
            shopActivities.setActStatus(ShopActivities.ACTIVITIES_STATUS_CLOSE);
        }
        ajaxResult.putInMap("goodsInfo", seckillInfo);
        ajaxResult.putInMap("activity", shopActivities);
        return ajaxResult;
    }
 
    /**
     * 计算秒杀价格
     *
     * @param secKillVO
     * @return
     */
    @PostMapping(value = "/calSecKillPrice")
    public AjaxResult calSecKillPrice(@RequestBody SecKillVO secKillVO) {
        ShopActivitiesSeckillInfo seckillInfo = shopActivitiesSeckillInfoDao.selectById(secKillVO.getId());
        if (seckillInfo == null) {
            return AjaxResult.buildFailInstance("参数有误");
        }
 
        BigDecimal postage = wxShopOrderService.calculationPostage(secKillVO.getAddressId(), seckillInfo.getSiPrice());
        BigDecimal payPrice = seckillInfo.getSiPrice().multiply(BigDecimal.valueOf(secKillVO.getCount())).add(postage);
        AjaxResult ajaxResult = new AjaxResult(AjaxResult.STATUS_SUCCESS, null);
        ajaxResult.putInMap("totalPrice", payPrice);
        ajaxResult.putInMap("postage", postage);
        return ajaxResult;
    }
 
    /**
     * 创建秒杀订单
     *
     * @param secKillDTO id,addressId,count,shopId,shippingMethod
     * @return
     * @throws Exception
     */
    @PostMapping(value = "/createSecKill")
    public AjaxResult createSecKill(@RequestBody CreateSecKillDTO secKillDTO) throws Exception {
        return wxShopActivitiesSecKillService.createSecKillOrder(secKillDTO);
    }
}