商品模块代码提交

This commit is contained in:
Tankaikai
2025-03-01 15:16:58 +08:00
parent fd257f1b3b
commit 3f823919bf
9 changed files with 192 additions and 18 deletions

View File

@@ -36,5 +36,5 @@ public interface ProductMapper extends BaseMapper<Product> {
List<Product> selectCouponProBySaleNum();
void updateProductStockNum(@Param("id") Long id, @Param("shopId") Long shopId, @Param("subtractNum") BigDecimal subtractNum);
void updateProductStockNum(@Param("id") Long id, @Param("shopId") Long shopId, @Param("num") String type, @Param("num") BigDecimal num);
}

View File

@@ -56,7 +56,7 @@ public class ProductRpcServiceImpl implements ProductRpcService {
return;
}
for (ProductStockSubtractDTO dto : list) {
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), dto.getNum());
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "sub", dto.getNum());
// 查询商品绑定耗材信息
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
if (CollUtil.isEmpty(relationList)) {
@@ -83,7 +83,6 @@ public class ProductRpcServiceImpl implements ProductRpcService {
// 插入耗材流水记录
Long shopId = consInfo.getShopId();
ConsStockFlow consStockFlow = new ConsStockFlow();
consStockFlow.setId(0L);
consStockFlow.setShopId(shopId);
consStockFlow.setVendorId(null);
consStockFlow.setInOutType(InOutTypeEnum.OUT.value());
@@ -107,4 +106,62 @@ public class ProductRpcServiceImpl implements ProductRpcService {
}
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void orderCancelRecoverStock(Long orderId, List<Map<String, Object>> dataList) {
List<ProductStockSubtractDTO> list = BeanUtil.copyToList(dataList, ProductStockSubtractDTO.class);
if (CollUtil.isEmpty(list)) {
return;
}
for (ProductStockSubtractDTO dto : list) {
productMapper.updateProductStockNum(dto.getProductId(), dto.getShopId(), "add", dto.getNum());
// 查询商品绑定耗材信息
List<ProdConsRelation> relationList = prodConsRelationMapper.selectListByQuery(QueryWrapper.create().eq(ProdConsRelation::getProductId, dto.getProductId()));
if (CollUtil.isEmpty(relationList)) {
continue;
}
for (ProdConsRelation prodConsRelation : relationList) {
// 耗材id
Long consInfoId = prodConsRelation.getConsInfoId();
// 耗材消耗数量
BigDecimal surplusStock = prodConsRelation.getSurplusStock();
if (surplusStock == null) {
continue;
}
// 实际消耗数量 = 耗材消耗数量 * 商品购买数量
surplusStock = NumberUtil.mul(surplusStock, dto.getNum());
ConsInfo consInfo = consInfoMapper.selectOneById(consInfoId);
if (consInfo == null) {
continue;
}
BigDecimal stockNumber = consInfo.getStockNumber();
consInfo.setStockNumber(NumberUtil.add(stockNumber, surplusStock));
// 更新耗材库存数量
consInfoMapper.update(consInfo);
// 插入耗材流水记录
Long shopId = consInfo.getShopId();
ConsStockFlow consStockFlow = new ConsStockFlow();
consStockFlow.setShopId(shopId);
consStockFlow.setInOutType(InOutTypeEnum.IN.value());
consStockFlow.setInOutItem(InOutItemEnum.ORDER_IN.value());
consStockFlow.setInOutDate(LocalDate.now());
consStockFlow.setConId(consInfo.getId());
consStockFlow.setConName(consInfo.getConName());
consStockFlow.setUnitName(consInfo.getConUnit());
consStockFlow.setBeforeNumber(stockNumber);
consStockFlow.setInOutNumber(surplusStock);
consStockFlow.setAfterNumber(consInfo.getStockNumber());
consStockFlow.setSubTotal(NumberUtil.mul(surplusStock, consInfo.getPrice()));
consStockFlow.setProductId(dto.getProductId());
//consStockFlow.setSkuId(0L);
consStockFlow.setOrderId(orderId);
Long createUserId = StpKit.USER.getLoginIdAsLong();
String createUserName = StpKit.USER.getAccount();
consStockFlow.setCreateUserId(createUserId);
consStockFlow.setCreateUserName(createUserName);
consStockFlowMapper.insert(consStockFlow);
}
}
}
}

View File

@@ -161,7 +161,12 @@
</select>
<update id="updateProductStockNum">
update tb_product
set stock_number = stock_number - #{subtractNum}
<if test="type == 'add">
set stock_number = stock_number + #{num}
</if>
<if test="type == 'sub">
set stock_number = stock_number - #{num}
</if>
where id = #{id}
and is_stock = 1
and shop_id = #{shopId}