库存不足提示

This commit is contained in:
2025-04-16 15:26:11 +08:00
parent 954f2329bc
commit 5e9382b68e

View File

@@ -19,6 +19,7 @@ import com.czg.entity.notify.CzgPayNotifyDTO;
import com.czg.entity.notify.CzgRefundNotifyDTO;
import com.czg.enums.ShopUserFlowBizEnum;
import com.czg.exception.ApiNotPrintException;
import com.czg.exception.CzgException;
import com.czg.exception.OrderCancelException;
import com.czg.order.dto.*;
import com.czg.order.entity.CashierCart;
@@ -31,6 +32,8 @@ import com.czg.order.service.OrderDetailService;
import com.czg.order.service.OrderInfoService;
import com.czg.order.service.OrderPaymentService;
import com.czg.order.vo.*;
import com.czg.product.entity.Product;
import com.czg.product.service.ProductService;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.service.RedisService;
@@ -84,6 +87,8 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
@DubboReference
private MemberPointsService pointsService;
@DubboReference
private ProductService productService;
@DubboReference
private ShopInfoService shopInfoService;
@DubboReference
private UserInfoService userInfoService;
@@ -452,6 +457,16 @@ public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo
*/
private void processOrderDetails(List<OrderDetail> orderDetails) {
for (OrderDetail detail : orderDetails) {
if (!detail.getIsTemporary().equals(1) && detail.getProductId() > 0) {
Product product = productService.getOne(QueryWrapper.create()
.eq(Product::getId, detail.getProductId())
.eq(Product::getShopId, detail.getShopId())
.eq(Product::getIsDel, 0)
.eq(Product::getIsStock, 1));
if (product != null && detail.getNum().compareTo(new BigDecimal(product.getStockNumber())) < 0) {
throw new CzgException("下单失败" + product.getName() + "库存不足");
}
}
if (detail.getDiscountSaleAmount() != null && detail.getDiscountSaleAmount().compareTo(BigDecimal.ZERO) > 0) {
detail.setUnitPrice(detail.getDiscountSaleAmount());
} else {