Commit f09d5aaba97967fb5d15a20ff8cf1a4c550c05be
1 parent
63ecec86
update:购物车判断
Showing
2 changed files
with
32 additions
and
1 deletions
etrade-order/src/main/java/com/diligrp/etrade/order/service/impl/ShopCartImpl.java
@@ -16,12 +16,15 @@ import com.diligrp.etrade.order.service.IShopCartMessageService; | @@ -16,12 +16,15 @@ import com.diligrp.etrade.order.service.IShopCartMessageService; | ||
16 | import com.diligrp.etrade.order.service.IShopCartService; | 16 | import com.diligrp.etrade.order.service.IShopCartService; |
17 | import com.diligrp.etrade.order.type.ShopCartMessageCheckFlag; | 17 | import com.diligrp.etrade.order.type.ShopCartMessageCheckFlag; |
18 | import com.diligrp.etrade.order.type.ShopCartMessageProductState; | 18 | import com.diligrp.etrade.order.type.ShopCartMessageProductState; |
19 | +import com.diligrp.etrade.order.util.NumberTransform; | ||
19 | import com.diligrp.etrade.shop.domain.response.ProductDetailVo; | 20 | import com.diligrp.etrade.shop.domain.response.ProductDetailVo; |
20 | import com.diligrp.etrade.shop.domain.response.ProductListVo; | 21 | import com.diligrp.etrade.shop.domain.response.ProductListVo; |
21 | import com.diligrp.etrade.shop.domain.response.ProductPresetVo; | 22 | import com.diligrp.etrade.shop.domain.response.ProductPresetVo; |
22 | import com.diligrp.etrade.shop.domain.response.ShopVo; | 23 | import com.diligrp.etrade.shop.domain.response.ShopVo; |
24 | +import com.diligrp.etrade.shop.model.Stock; | ||
23 | import com.diligrp.etrade.shop.service.ProductService; | 25 | import com.diligrp.etrade.shop.service.ProductService; |
24 | import com.diligrp.etrade.shop.service.ShopService; | 26 | import com.diligrp.etrade.shop.service.ShopService; |
27 | +import com.diligrp.etrade.shop.service.StockService; | ||
25 | import com.diligrp.etrade.shop.type.ProductAuditState; | 28 | import com.diligrp.etrade.shop.type.ProductAuditState; |
26 | import org.apache.commons.lang3.StringUtils; | 29 | import org.apache.commons.lang3.StringUtils; |
27 | import org.springframework.beans.BeanUtils; | 30 | import org.springframework.beans.BeanUtils; |
@@ -31,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; | @@ -31,6 +34,7 @@ import org.springframework.transaction.annotation.Transactional; | ||
31 | import org.springframework.util.Assert; | 34 | import org.springframework.util.Assert; |
32 | import org.springframework.util.CollectionUtils; | 35 | import org.springframework.util.CollectionUtils; |
33 | 36 | ||
37 | +import java.math.BigDecimal; | ||
34 | import java.time.LocalDateTime; | 38 | import java.time.LocalDateTime; |
35 | import java.util.*; | 39 | import java.util.*; |
36 | import java.util.stream.Collectors; | 40 | import java.util.stream.Collectors; |
@@ -56,6 +60,9 @@ public class ShopCartImpl implements IShopCartService { | @@ -56,6 +60,9 @@ public class ShopCartImpl implements IShopCartService { | ||
56 | @Autowired | 60 | @Autowired |
57 | private ProductService productService; | 61 | private ProductService productService; |
58 | 62 | ||
63 | + @Autowired | ||
64 | + private StockService stockService; | ||
65 | + | ||
59 | 66 | ||
60 | /** | 67 | /** |
61 | * 购物车列表 | 68 | * 购物车列表 |
@@ -229,6 +236,8 @@ public class ShopCartImpl implements IShopCartService { | @@ -229,6 +236,8 @@ public class ShopCartImpl implements IShopCartService { | ||
229 | List<ShopCartMessage> shopCartMessages = shopCartMessageService.findList(shopCartMessageDtoQuery); | 236 | List<ShopCartMessage> shopCartMessages = shopCartMessageService.findList(shopCartMessageDtoQuery); |
230 | //商品信息不存在,则新增商品信息 | 237 | //商品信息不存在,则新增商品信息 |
231 | if (CollectionUtils.isEmpty(shopCartMessages)) { | 238 | if (CollectionUtils.isEmpty(shopCartMessages)) { |
239 | + //效验最大最大数量 | ||
240 | + checkMaxProductWeight(shopCartMessageDto,null); | ||
232 | AssertUtils.isTrue(count < 50L, "购物车商品数量不能超过50"); | 241 | AssertUtils.isTrue(count < 50L, "购物车商品数量不能超过50"); |
233 | shopCartMessageDto.setShopCartId(shopCart.getId()); | 242 | shopCartMessageDto.setShopCartId(shopCart.getId()); |
234 | shopCartMessageService.saveShopCartMessage(shopCartMessageDto); | 243 | shopCartMessageService.saveShopCartMessage(shopCartMessageDto); |
@@ -236,9 +245,30 @@ public class ShopCartImpl implements IShopCartService { | @@ -236,9 +245,30 @@ public class ShopCartImpl implements IShopCartService { | ||
236 | } | 245 | } |
237 | //存在相同商品信息,对商品信息进行更新操作 | 246 | //存在相同商品信息,对商品信息进行更新操作 |
238 | ShopCartMessage shopCartMessageOld = shopCartMessages.get(0); | 247 | ShopCartMessage shopCartMessageOld = shopCartMessages.get(0); |
248 | + //效验最大数量 | ||
249 | + checkMaxProductWeight(shopCartMessageDto,shopCartMessageOld); | ||
239 | shopCartMessageService.updateByOld(shopCartMessageOld, shopCartDto.getShopCartMessageDto(),shopCartDto.getBo()); | 250 | shopCartMessageService.updateByOld(shopCartMessageOld, shopCartDto.getShopCartMessageDto(),shopCartDto.getBo()); |
240 | } | 251 | } |
241 | 252 | ||
253 | + private void checkMaxProductWeight(ShopCartMessageDto shopCartMessageDto, ShopCartMessage shopCartMessageOld) { | ||
254 | + if(shopCartMessageDto == null){ | ||
255 | + return ; | ||
256 | + } | ||
257 | + List<Stock> stocks = stockService.listByProductIds(Collections.singletonList(shopCartMessageDto.getProductId())); | ||
258 | + if(CollectionUtils.isEmpty(stocks)){ | ||
259 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"该商品暂无库存"); | ||
260 | + } | ||
261 | + if(shopCartMessageOld!=null){ | ||
262 | + if(stocks.get(0).getStock().multiply(NumberTransform.ONE_HUNDERD).compareTo(new BigDecimal(shopCartMessageOld.getWeight()+shopCartMessageDto.getWeight()))<0){ | ||
263 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"该宝贝不能购买更多哦~"); | ||
264 | + } | ||
265 | + }else{ | ||
266 | + if(stocks.get(0).getStock().compareTo(new BigDecimal(shopCartMessageDto.getWeight()))<0){ | ||
267 | + throw new OrderException(OrderErrorCode.PARAM_ERROR,"该宝贝不能购买更多哦~"); | ||
268 | + } | ||
269 | + } | ||
270 | + } | ||
271 | + | ||
242 | 272 | ||
243 | @Transactional(rollbackFor = Exception.class) | 273 | @Transactional(rollbackFor = Exception.class) |
244 | @Override | 274 | @Override |
etrade-order/src/main/resources/com/diligrp/etrade/dao/mapper/shopCart/ShopCartMapper.xml
@@ -63,7 +63,7 @@ | @@ -63,7 +63,7 @@ | ||
63 | scm.number, | 63 | scm.number, |
64 | scm.unit_amount, | 64 | scm.unit_amount, |
65 | scm.unit_amount as prePrice, | 65 | scm.unit_amount as prePrice, |
66 | - scm.unit_weight, | 66 | + case when scm.weight > st.stock*100 then st.stock*100 else scm.weight end as weight, |
67 | scm.weight, | 67 | scm.weight, |
68 | scm.amount, | 68 | scm.amount, |
69 | scm.type, | 69 | scm.type, |
@@ -75,6 +75,7 @@ | @@ -75,6 +75,7 @@ | ||
75 | scm.created_time as createdTime | 75 | scm.created_time as createdTime |
76 | from shop_cart s | 76 | from shop_cart s |
77 | left join shop_cart_message scm | 77 | left join shop_cart_message scm |
78 | + left join stock st | ||
78 | on s.id = scm.shop_cart_id | 79 | on s.id = scm.shop_cart_id |
79 | where s.customer_id = #{customerId,jdbcType=BIGINT} | 80 | where s.customer_id = #{customerId,jdbcType=BIGINT} |
80 | and s.market_id = #{marketId,jdbcType=BIGINT} | 81 | and s.market_id = #{marketId,jdbcType=BIGINT} |