diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/approval/ReturnApprovalApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/approval/ReturnApprovalApplicationService.java index 46b16bd..65b041a 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/approval/ReturnApprovalApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/approval/ReturnApprovalApplicationService.java @@ -2,6 +2,8 @@ package com.agileboot.domain.shop.approval; import com.agileboot.common.constant.PayApiConstants; import com.agileboot.common.core.page.PageDTO; +import com.agileboot.domain.cabinet.cell.model.CabinetCellModel; +import com.agileboot.domain.cabinet.cell.model.CabinetCellModelFactory; import com.agileboot.domain.common.command.BulkOperationCommand; import com.agileboot.domain.qywx.accessToken.AccessTokenApplicationService; import com.agileboot.domain.qywx.accessToken.db.QyAccessTokenEntity; @@ -59,6 +61,7 @@ public class ReturnApprovalApplicationService { private final AuthCorpInfoApplicationService authCorpInfoApplicationService; private final AccessTokenApplicationService accessTokenApplicationService; private final QyUserService qyUserService; + private final CabinetCellModelFactory cabinetCellModelFactory; /** * 获取退货审批列表 @@ -167,6 +170,11 @@ public class ReturnApprovalApplicationService { GoodsModel goodsModel = goodsModelFactory.loadById(orderGoodsModel.getGoodsId()); goodsModel.setStock(goodsModel.getStock() + orderGoodsModel.getQuantity()); goodsModel.updateById(); + + // 更新格口库存 + CabinetCellModel cabinetCellModel = cabinetCellModelFactory.loadById(orderGoodsModel.getCellId()); + cabinetCellModel.setStock(cabinetCellModel.getStock() + orderGoodsModel.getQuantity()); + cabinetCellModel.updateById(); } /** diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java index 7a43c3f..3d4f156 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/goods/db/ShopGoodsMapper.java @@ -63,7 +63,10 @@ public interface ShopGoodsMapper extends BaseMapper { * 查询商品及其关联的柜机格口信息 * @return 商品列表 */ - @Select("SELECT g.*, sc.cabinet_id, sc.cabinet_name, cc.cell_id " + + @Select("SELECT g.goods_id, g.goods_name, g.category_id, g.price, " + + "g.status, g.cover_img, g.goods_detail, " + + "g.creator_id, g.create_time, g.updater_id, g.update_time, g.remark, g.deleted, " + + "sc.cabinet_id, sc.cabinet_name, cc.stock, cc.cell_id " + "FROM shop_goods g " + "LEFT JOIN cabinet_cell cc ON g.goods_id = cc.goods_id " + "LEFT JOIN smart_cabinet sc ON cc.cabinet_id = sc.cabinet_id " + diff --git a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java index e62b9e7..1ddd67b 100644 --- a/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java +++ b/agileboot-domain/src/main/java/com/agileboot/domain/shop/order/OrderApplicationService.java @@ -197,7 +197,7 @@ public class OrderApplicationService { goodsModel.insert(); // 扣减库存 - deductGoodsStock(goodsModel.getGoodsId(), goodsModel.getQuantity()); + deductGoodsStock(goodsModel.getGoodsId(), goodsModel.getQuantity(), goodsModel.getCellId()); totalAmount = totalAmount.add(goodsModel.getTotalAmount()); } @@ -208,11 +208,20 @@ public class OrderApplicationService { orderModel.updateById(); } - private void deductGoodsStock(Long goodsId, Integer quantity) { + private void deductGoodsStock(Long goodsId, Integer quantity, Long cellId) { + CabinetCellEntity cabinetCellEntity = cabinetCellService.getById(cellId); + if (cabinetCellEntity == null || cabinetCellEntity.getStock() < quantity) { + throw new ApiException(ErrorCode.FAILED, "柜子库存不足"); + } + ShopGoodsEntity goods = goodsService.getById(goodsId); if (goods == null || goods.getStock() < quantity) { throw new ApiException(ErrorCode.FAILED, "商品库存不足"); } + + // 扣减库存 + cabinetCellEntity.setStock(cabinetCellEntity.getStock() - quantity); + cabinetCellService.updateById(cabinetCellEntity); goods.setStock(goods.getStock() - quantity); goodsService.updateById(goods); }