diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java index 6a5d63b..a2590cd 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/controller/ProductController.java @@ -1,13 +1,17 @@ package com.chaozhanggui.system.cashierservice.controller; +import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO; +import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO; import com.chaozhanggui.system.cashierservice.service.ProductService; +import com.chaozhanggui.system.cashierservice.sign.CodeEnum; import com.chaozhanggui.system.cashierservice.sign.Result; import lombok.extern.slf4j.Slf4j; import org.apache.ibatis.annotations.Param; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; +import javax.validation.Valid; import java.util.Map; @CrossOrigin(origins = "*") @@ -21,6 +25,23 @@ public class ProductController { private ProductService productService; + @PutMapping("/productStatus") + public Result productStatus( + @Valid @RequestBody ProductStatusDTO productStatusDTO + ) { + productService.updateState(productStatusDTO); + return Result.success(CodeEnum.SUCCESS); + } + + @PutMapping("/productStock") + public Result productStock( + @Valid @RequestBody ProductStockDTO productStockDTO + ) { + productService.updateStock(productStockDTO); + return Result.success(CodeEnum.SUCCESS); + } + + @GetMapping(value = "queryCommodityInfo") public Result queryCommodityInfo( @RequestHeader("token") String token, diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java index b23f44f..588da37 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductMapper.java @@ -5,6 +5,7 @@ import com.chaozhanggui.system.cashierservice.entity.TbProductWithBLOBs; import com.chaozhanggui.system.cashierservice.entity.po.ProConsSkuInfo; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; import org.apache.ibatis.annotations.Update; import org.springframework.stereotype.Component; @@ -53,4 +54,24 @@ public interface TbProductMapper { @Update("update tb_product set stock_number=stock_number-#{num} WHERE id=#{id}") int decrStockUnCheck(String id, int num); + + @Select("select * from tb_product product where product.id=#{productId} and product.shop_id=#{shopId} and product.is_del=0") + TbProduct selectByShopIdAndId(@Param("productId") Integer productId, @Param("shopId") Integer shopId); + + @Update("update tb_product_sku set is_grounding=#{isGrounding} where product_id=#{productId}") + int updateGroundingByProId(@Param("productId") Integer productId, @Param("isGrounding") int isGrounding); + + @Update("update tb_product_sku set is_grounding=#{status} where id=#{skuId}") + int updateGrounding(@Param("skuId") Integer skuId, @Param("status") int status); + + @Update("update tb_product set is_pause_sale=#{state} where id=#{id} and shop_id=#{shopId}") + int pauseSale(@Param("id") Integer id, @Param("shopId") Integer shopId, @Param("state") Integer state); + + @Update("update tb_product_sku set is_pause_sale=#{state} where product_id=#{id} and shop_id=#{shopId}") + int pauseSkuSale(@Param("id") Integer proId, @Param("shopId") Integer shopId, @Param("state") Integer state); + + + + @Update("update tb_product set stock_number=#{stock} where id=#{productId} and shop_id=#{shopId}") + int updateStock(@Param("shopId") Integer shopId, @Param("productId") Integer productId, @Param("stock") Integer stock); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java index 5a1698c..b0e030f 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/dao/TbProductSkuMapper.java @@ -55,5 +55,11 @@ public interface TbProductSkuMapper { List selectByProductCheckGrounding(@Param("id") Integer id); @Select("select * from tb_product_sku where is_grounding=1 and is_del=0 and product_id=#{id}") - List selectGroundingByProId(Integer id); + List selectGroundingByProId(@Param("id") Integer id); + + @Update("update tb_product_sku set is_pause_sale=#{state} where id=#{skuId} and shop_id=#{shopId}") + int pauseSale(@Param("skuId") Integer skuId, @Param("shopId") Integer shopId, @Param("state") Integer state); + + @Update("update tb_product_sku set stock_number=#{stock} where product_id=#{skuId} and shop_id=#{shopId}") + int updateStock(@Param("skuId") Integer skuId, @Param("shopId") Integer shopId, @Param("stock") Integer stock); } diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ProductStatusDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ProductStatusDTO.java new file mode 100644 index 0000000..53db36a --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ProductStatusDTO.java @@ -0,0 +1,22 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + + +import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.NotNull; + +@Data +public class ProductStatusDTO { + @NotNull + private Integer productId; + @NotNull + private Integer shopId; + @NotNull + @Range(min = 0, max = 1) + private Integer state; + // 0上下架 1售罄 + @Range(min = 0, max = 1) + @NotNull + private Integer type; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ProductStockDTO.java b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ProductStockDTO.java new file mode 100644 index 0000000..2d5fafa --- /dev/null +++ b/src/main/java/com/chaozhanggui/system/cashierservice/entity/dto/ProductStockDTO.java @@ -0,0 +1,18 @@ +package com.chaozhanggui.system.cashierservice.entity.dto; + +import lombok.Data; +import org.hibernate.validator.constraints.Range; + +import javax.validation.constraints.Min; +import javax.validation.constraints.NotNull; + +@Data +public class ProductStockDTO { + @NotNull + private Integer shopId; + @NotNull + private Integer productId; + @NotNull + @Min(0) + private Integer stock; +} diff --git a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java index 799be39..b155777 100644 --- a/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java +++ b/src/main/java/com/chaozhanggui/system/cashierservice/service/ProductService.java @@ -7,6 +7,8 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.chaozhanggui.system.cashierservice.dao.*; import com.chaozhanggui.system.cashierservice.entity.*; +import com.chaozhanggui.system.cashierservice.entity.dto.ProductStatusDTO; +import com.chaozhanggui.system.cashierservice.entity.dto.ProductStockDTO; import com.chaozhanggui.system.cashierservice.entity.vo.ShopCategoryVo; import com.chaozhanggui.system.cashierservice.exception.MsgException; import com.chaozhanggui.system.cashierservice.interceptor.LimitSubmitAspect; @@ -222,4 +224,28 @@ public class ProductService { } } } + + public void updateState(ProductStatusDTO productStatusDTO) { + TbProduct product = tbProductMapper.selectByShopIdAndId(productStatusDTO.getProductId(), productStatusDTO.getShopId()); + if (productStatusDTO.getType().equals(0)) { + tbProductMapper.updateGroundingByProId(product.getId(), productStatusDTO.getState()); + }else { + tbProductMapper.pauseSale(productStatusDTO.getProductId(), productStatusDTO.getShopId(), productStatusDTO.getState()); + tbProductMapper.pauseSkuSale(productStatusDTO.getProductId(), productStatusDTO.getShopId(), productStatusDTO.getState()); + + } + } + + public void updateStock(ProductStockDTO productStockDTO) { + TbProduct product = tbProductMapper.selectByShopIdAndId(productStockDTO.getProductId(), productStockDTO.getShopId()); + if (product == null) { + throw new MsgException("商品不存在"); + } + + if (product.getIsDistribute() != 1 && product.getTypeEnum().equals("sku")) { + throw new MsgException("多规格非共享商品暂不支持修改库存"); + }else { + tbProductSkuMapper.updateStock(productStockDTO.getProductId(), productStockDTO.getShopId(), productStockDTO.getStock()); + } + } }