|
|
@@ -23,6 +23,7 @@ import com.yami.shop.bean.model.*;
|
|
|
import com.yami.shop.common.exception.GlobalException;
|
|
|
import com.yami.shop.common.util.Arith;
|
|
|
import com.yami.shop.dao.PointsRecordMapper;
|
|
|
+import com.yami.shop.dao.ShopSkuMapper;
|
|
|
import com.yami.shop.security.api.util.SecurityUtils;
|
|
|
import com.yami.shop.service.*;
|
|
|
import com.yami.shop.service.hb.IHBOrderService;
|
|
|
@@ -68,7 +69,7 @@ public class OrderController {
|
|
|
@Autowired
|
|
|
private IHBOrderService hbOrderService;
|
|
|
@Autowired
|
|
|
- private UserService userService;
|
|
|
+ private ShopSkuMapper shopSkuMapper;
|
|
|
|
|
|
/**
|
|
|
* 生成订单
|
|
|
@@ -76,32 +77,52 @@ public class OrderController {
|
|
|
@PostMapping("/confirm")
|
|
|
@ApiOperation(value = "结算,生成订单信息", notes = "传入下单所需要的参数进行下单")
|
|
|
public ResponseEntity<ShopCartOrderMergerDto> confirm(@Valid @RequestBody OrderParam orderParam) {
|
|
|
+ if (orderParam.getShopId() == null){
|
|
|
+ throw new GlobalException("请选择店铺!");
|
|
|
+ }
|
|
|
String userId = SecurityUtils.getUser().getUserId();
|
|
|
|
|
|
if (orderParam.getOrderItem() == null) {
|
|
|
orderParam.getBasketIds().forEach(basketId -> {
|
|
|
Basket byId = basketService.getById(basketId);
|
|
|
Sku byIdss = skuService.getById(byId);
|
|
|
- boolean skuStock = qnhService.getSkuStock(byIdss.getSkuCode(), byId.getProdId(), orderParam.getPlatform());
|
|
|
- Product byId1 = productService.getById(byId.getProdId(), orderParam.getPlatform());
|
|
|
-
|
|
|
- if(byId1.getIsDelete() == 1 || byId1.getStatus() != 1){
|
|
|
- throw new GlobalException("当前选择的商品"+byId1.getProdName() + "已下架!请重新选择商品!");
|
|
|
+ ShopSku shopSku = shopSkuMapper.selectByShopAndSku(byIdss.getSkuId(), orderParam.getShopId());
|
|
|
+ if (shopSku.getShopSkuStocks()==null || shopSku.getShopSkuStocks()==0){
|
|
|
+ throw new GlobalException("当前选择的商品库存为空!请重新选择商品!");
|
|
|
}
|
|
|
-
|
|
|
- productService.updateById(byId1);
|
|
|
- if (skuStock && byId1.getTotalStocks() < byId.getBasketCount()) {
|
|
|
- throw new GlobalException("当前选择的规格库存不足!");
|
|
|
+ if (shopSku.getShopSkuStocks() < byId.getBasketCount()) {
|
|
|
+ throw new GlobalException("当前选择的商品库存不足!");
|
|
|
}
|
|
|
+
|
|
|
+// boolean skuStock = qnhService.getSkuStock(byIdss.getSkuCode(), byId.getProdId(), orderParam.getPlatform());
|
|
|
+// Product byId1 = productService.getById(byId.getProdId(), orderParam.getPlatform());
|
|
|
+//
|
|
|
+// if(byId1.getIsDelete() == 1 || byId1.getStatus() != 1){
|
|
|
+// throw new GlobalException("当前选择的商品"+byId1.getProdName() + "已下架!请重新选择商品!");
|
|
|
+// }
|
|
|
+//
|
|
|
+// productService.updateById(byId1);
|
|
|
+// if (skuStock && byId1.getTotalStocks() < byId.getBasketCount()) {
|
|
|
+// throw new GlobalException("当前选择的规格库存不足!");
|
|
|
+// }
|
|
|
});
|
|
|
- } else {
|
|
|
- Sku byId = skuService.getById(orderParam.getOrderItem().getSkuId());
|
|
|
- boolean skuStock = qnhService.getSkuStock(byId.getSkuCode(), orderParam.getOrderItem().getProdId(), orderParam.getPlatform());
|
|
|
- Product byId1 = productService.getById(byId.getProdId(), orderParam.getPlatform());
|
|
|
- productService.updateById(byId1);
|
|
|
- if (skuStock && byId1.getTotalStocks() < orderParam.getOrderItem().getProdCount()) {
|
|
|
- throw new GlobalException("当前选择的规格库存不足!");
|
|
|
+ } else {
|
|
|
+
|
|
|
+ ShopSku shopSku = shopSkuMapper.selectByShopAndSku(orderParam.getOrderItem().getSkuId(), orderParam.getShopId());
|
|
|
+ if (shopSku.getShopSkuStocks()==null || shopSku.getShopSkuStocks()==0){
|
|
|
+ throw new GlobalException("当前选择的商品库存为空!请重新选择商品!");
|
|
|
+ }
|
|
|
+ if (shopSku.getShopSkuStocks() < orderParam.getOrderItem().getProdCount()) {
|
|
|
+ throw new GlobalException("当前选择的商品库存不足!");
|
|
|
}
|
|
|
+
|
|
|
+// Sku byId = skuService.getById(orderParam.getOrderItem().getSkuId());
|
|
|
+// boolean skuStock = qnhService.getSkuStock(byId.getSkuCode(), orderParam.getOrderItem().getProdId(), orderParam.getPlatform());
|
|
|
+// Product byId1 = productService.getById(byId.getProdId(), orderParam.getPlatform());
|
|
|
+// productService.updateById(byId1);
|
|
|
+// if (skuStock && byId1.getTotalStocks() < orderParam.getOrderItem().getProdCount()) {
|
|
|
+// throw new GlobalException("当前选择的规格库存不足!");
|
|
|
+// }
|
|
|
}
|
|
|
|
|
|
// 订单的地址信息
|