| | |
| | | throw new RestException(-3, "商品不存在或已下架"); |
| | | } |
| | | |
| | | if (ScoreGoods.ISQG_YES.equals(goods.getIsQg())) { |
| | | if (new Date().before(goods.getQgStartTime())) { |
| | | throw new RestException(-3, "抢购未开始"); |
| | | } |
| | | |
| | | if (new Date().after(goods.getQgEndTime())) { |
| | | throw new RestException(-3, "抢购已结束"); |
| | | } |
| | | } |
| | | // if (ScoreGoods.ISQG_YES.equals(goods.getIsQg())) { |
| | | // if (new Date().before(goods.getQgStartTime())) { |
| | | // throw new RestException(-3, "抢购未开始"); |
| | | // } |
| | | // |
| | | // if (new Date().after(goods.getQgEndTime())) { |
| | | // throw new RestException(-3, "抢购已结束"); |
| | | // } |
| | | // } |
| | | |
| | | if (addGoodsOrderDto.getCnt() > sku.getStock()) { |
| | | throw new RestException(-3, "库存不足"); |
| | |
| | | throw new RestException(-3, "积分不足"); |
| | | } |
| | | |
| | | BigDecimal totalPrice = sku.getPresentPrice().multiply(BigDecimal.valueOf(addGoodsOrderDto.getCnt())); |
| | | BigDecimal totalPrice = BigDecimal.ZERO; |
| | | if (ScoreGoods.ISQG_YES.equals(goods.getIsQg())) { |
| | | //限购数量 |
| | | Integer quotaTime = goods.getQuotaTime() == null ? 0:goods.getQuotaTime(); |
| | | //抢购时间内,用户购买该商品的数量 |
| | | Integer sumCnt = scoreOrderMapper.selectGoodsQuotaTime(addGoodsOrderDto.getUserId(),goods.getId(),goods.getQgStartTime(),goods.getQgEndTime()); |
| | | //剩余限购数量 |
| | | quotaTime = quotaTime-sumCnt; |
| | | if(goods.getQgStartTime().before(new Date()) && goods.getQgEndTime().after(new Date())){ |
| | | if(addGoodsOrderDto.getCnt() <= quotaTime){ |
| | | totalPrice = sku.getPresentPrice().multiply(BigDecimal.valueOf(quotaTime)); |
| | | }else{ |
| | | if(quotaTime > 0){ |
| | | totalPrice = sku.getPresentPrice().multiply(BigDecimal.valueOf(quotaTime)).add( |
| | | sku.getOriginalPrice().multiply(BigDecimal.valueOf(addGoodsOrderDto.getCnt()-quotaTime))); |
| | | }else{ |
| | | totalPrice = sku.getOriginalPrice().multiply(BigDecimal.valueOf(addGoodsOrderDto.getCnt())); |
| | | } |
| | | } |
| | | }else{ |
| | | //开启抢购,不再时间内,直接原价* 数量 |
| | | totalPrice = sku.getOriginalPrice().multiply(BigDecimal.valueOf(addGoodsOrderDto.getCnt())); |
| | | } |
| | | }else{ |
| | | //没有开启抢购,直接现价* 数量 |
| | | totalPrice = sku.getPresentPrice().multiply(BigDecimal.valueOf(addGoodsOrderDto.getCnt())); |
| | | } |
| | | BigDecimal score = new BigDecimal(accountInfo.getCollectScore()); |
| | | if (score.compareTo(totalPrice) < 0) { |
| | | throw new RestException(-3, "积分不足"); |