商品sukitem价格和库存修改

This commit is contained in:
liyj 2025-07-25 15:49:45 +08:00
parent 8be7b6f273
commit 8848abc18e
4 changed files with 68 additions and 0 deletions

View File

@ -83,5 +83,18 @@ public class ShopProductItemController {
.orderByAsc("item_id");
return CommonResult.success(shopProductItemService.find(queryWrapper));
}
/**
* 编辑库存和价格
* @param shopProductItem
* @return
*/
@ApiOperation(value = "商品表-SKU表 商品名称(产品名称+颜色规格名称) =shop_product_item-编辑", notes = "商品表-SKU表 商品名称(产品名称+颜色规格名称) =shop_product_item-编辑")
@RequestMapping(value = "/editQuantity", method = RequestMethod.POST)
public CommonResult editQuantity(ShopProductItem shopProductItem) {
return shopProductItemService.editQuantity(shopProductItem);
}
}

View File

@ -1,6 +1,7 @@
package com.suisung.mall.shop.product.service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.modules.edu.vo.EduCourseDetailVO;
import com.suisung.mall.common.modules.product.ShopProductItem;
import com.suisung.mall.common.pojo.dto.EduCourseDetailDTO;
@ -84,4 +85,11 @@ public interface ShopProductItemService extends IBaseService<ShopProductItem> {
* @return
*/
void batchUpdateByCondition(List<ShopProductItem> shopProductItemList);
/**
* 功能描述:
* 修改item的价格和库存
* @param: ShopProductItem
*/
CommonResult editQuantity(ShopProductItem shopProductItem);
}

View File

@ -17,6 +17,7 @@ import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.suisung.mall.common.api.CommonResult;
import com.suisung.mall.common.api.ResultCode;
import com.suisung.mall.common.api.StateCode;
import com.suisung.mall.common.constant.ConfigConstant;
@ -61,6 +62,7 @@ import com.suisung.mall.shop.user.service.ShopUserProductBrowseService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.multipart.MultipartFile;
@ -2290,4 +2292,48 @@ public class ShopProductItemServiceImpl extends BaseServiceImpl<ShopProductItemM
shopProductItemMapper.updateBatchByProductId(shopProductItemList,shopProductItemList.get(0).getItem_enable());
}
@Override
@Transactional(rollbackFor = Exception.class)
public CommonResult editQuantity(ShopProductItem shopProductItem) {
QueryWrapper<ShopProductItem> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("product_id",shopProductItem.getProduct_id());
List<ShopProductItem> oldShopProductItems= shopProductItemService.list(queryWrapper);
List<ShopProductItem> oldShopProductItemList= oldShopProductItems.stream().filter(s -> s.getItem_id().equals(shopProductItem.getItem_id())).collect(Collectors.toList());
if(CollUtil.isEmpty(oldShopProductItemList)){
return CommonResult.failed("不存在商品sku");
}
ShopProductItem oldShopProductItem=oldShopProductItemList.get(0);
if(ObjectUtil.isEmpty(shopProductItem.getItem_quantity())){
return CommonResult.failed("库存不能为空");
}
if(ObjectUtil.isEmpty(shopProductItem.getItem_unit_price())){
return CommonResult.failed("价格不能为空");
}
BigDecimal item_unit_price =shopProductItem.getItem_unit_price();
BigDecimal item_unit_price_max =shopProductItem.getItem_unit_price();
BigDecimal item_unit_price_old = oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).min(BigDecimal::compareTo).get();
ShopProductIndex shopProductIndex=new ShopProductIndex();
if(item_unit_price_old.compareTo(item_unit_price)>0){
ShopProductBase shopProductBase=new ShopProductBase();
shopProductBase.setProduct_id(shopProductItem.getProduct_id());
shopProductBase.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_unit_price(item_unit_price);
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
shopProductBaseService.updateById(shopProductBase);
}
BigDecimal item_unit_price_max_old=oldShopProductItems.stream().map(ShopProductItem::getItem_unit_price).max(BigDecimal::compareTo).get();
if(item_unit_price_max.compareTo(item_unit_price_max_old)>0){
shopProductIndex.setProduct_id(shopProductItem.getProduct_id());
shopProductIndex.setProduct_unit_price_max(item_unit_price_max);
}
if(ObjectUtil.isNotEmpty(shopProductIndex.getProduct_id())){
shopProductIndexService.updateById(shopProductIndex);
}
oldShopProductItem.setItem_quantity(shopProductItem.getItem_quantity());
oldShopProductItem.setItem_unit_price(shopProductItem.getItem_unit_price());
shopProductItemService.updateById(oldShopProductItem);
return CommonResult.success();
}
}

View File

@ -0,0 +1 @@
INSERT INTO `admin_base_protocol` (`ctl`, `met`, `db`, `rights_id`, `log`, `path`) VALUES ('/admin/shop/shop-product-item/editQuantity', 'index', 'master', '', '0', '/admin/shop/shop-product-item/editQuantity');