未开启库存不校验库存数量
This commit is contained in:
parent
f041c983a5
commit
c88b085a4e
|
|
@ -40,4 +40,7 @@ public interface TbProductMapper {
|
|||
|
||||
@Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id} and stock_number-#{num} > 0")
|
||||
int decrStock(@Param("id") String id, @Param("num") Integer num);
|
||||
|
||||
@Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id}")
|
||||
int decrStockUnCheck(@Param("id") String id, @Param("num") Integer num);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,4 +43,7 @@ public interface TbProductSkuMapper {
|
|||
|
||||
@Update("update tb_product_sku set stock_number=stock_number-#{num} WHERE id=#{id} and stock_number-#{num} > 0")
|
||||
int decrStock(@Param("id") String id, @Param("num") Integer num);
|
||||
|
||||
@Update("update tb_product_sku set stock_number=stock_number-#{num} WHERE id=#{id}")
|
||||
int decrStockUnCheck(@Param("id") String id, @Param("num") Integer num);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -301,6 +301,8 @@ public class CartService {
|
|||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品不存在");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
log.error("该商品不存在 productId:{}", productId);
|
||||
throw new MsgException("该商品不存在");
|
||||
|
|
@ -314,6 +316,8 @@ public class CartService {
|
|||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品已售罄");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
log.error("该商品已售罄 productId:{}", productId);
|
||||
throw new MsgException("该商品已售罄");
|
||||
|
|
@ -325,6 +329,8 @@ public class CartService {
|
|||
jsonObject1.put("status", "fail");
|
||||
jsonObject1.put("msg", "该商品已售罄");
|
||||
jsonObject1.put("data", new ArrayList<>());
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), key, jsonObject.getString("userId"), true);
|
||||
log.error("该商品已售罄 productId:{}", productId);
|
||||
throw new MsgException("该商品已售罄");
|
||||
|
|
@ -387,6 +393,8 @@ public class CartService {
|
|||
jsonObject1.put("type", jsonObject.getString("type"));
|
||||
jsonObject1.put("data", jsonArray);
|
||||
jsonObject1.put("amount", amount);
|
||||
jsonObject1.put("reqData", jsonObject);
|
||||
|
||||
PushToAppChannelHandlerAdapter.getInstance().AppSendInfo(jsonObject1.toString(), jsonObject.getString("tableId").concat("-").concat(shopId), "", false);
|
||||
} catch (Exception e) {
|
||||
log.error("长链接错误 createCart{}", e.getMessage());
|
||||
|
|
@ -553,7 +561,11 @@ public class CartService {
|
|||
log.info("开始修改库存,商品id:{},商品名:{}", tbProduct1.getId(), tbProduct1.getName());
|
||||
// 修改库存
|
||||
try {
|
||||
productService.updateStock(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
|
||||
if (tbProduct1.getIsStock() == 1) {
|
||||
productService.updateStock(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
|
||||
}else {
|
||||
productService.updateStockAndNoCheck(tbProduct.getProductId(), tbProduct.getId(), cashierCart.getNumber(), tbProduct1.getIsDistribute() == 1);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
JSONObject jsonObject1 = new JSONObject();
|
||||
jsonObject1.put("status", "fail");
|
||||
|
|
@ -565,6 +577,12 @@ public class CartService {
|
|||
return;
|
||||
}
|
||||
|
||||
// 发送判断耗材是否耗尽消息
|
||||
JSONObject objectMsg=new JSONObject();
|
||||
objectMsg.put("skuId",Integer.valueOf(cashierCart.getSkuId()));
|
||||
objectMsg.put("shopId",Integer.valueOf(cashierCart.getShopId()));
|
||||
producer.con_msg(objectMsg.toString());
|
||||
|
||||
totalAmount = totalAmount.add(cashierCart.getTotalAmount());
|
||||
packAMount = packAMount.add(cashierCart.getPackFee());
|
||||
originAmount = originAmount.add(cashierCart.getTotalAmount());
|
||||
|
|
@ -759,7 +777,7 @@ public class CartService {
|
|||
jsonObject2.put("orderId", orderInfo.getId());
|
||||
jsonObject2.put("type", "create");
|
||||
jsonObject2.put("cartId", cashierCart.getId());
|
||||
log.info("开始发送mq消息,消耗库存,消息内容:{}", jsonObject2);
|
||||
log.info("开始发送mq消息,消耗耗材,消息内容:{}", jsonObject2);
|
||||
producer.cons(jsonObject2.toString());
|
||||
}
|
||||
redisUtil.saveMessage(RedisCst.TABLE_CART.concat(jsonObject.getString("tableId")).concat("-").concat(shopId), array.toJSONString());
|
||||
|
|
|
|||
|
|
@ -465,4 +465,16 @@ public class ProductService {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateStockAndNoCheck(String id, Integer skuId, Integer buyNum, boolean isDistribute) {
|
||||
if (isDistribute) {
|
||||
if (tbProductMapper.decrStockUnCheck(String.valueOf(id), buyNum) < 1) {
|
||||
throw new MsgException("库存不足,下单失败");
|
||||
}
|
||||
}else {
|
||||
if (tbProductSkuMapper.decrStockUnCheck(String.valueOf(skuId), buyNum) < 1) {
|
||||
throw new MsgException("库存不足,下单失败");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue