Merge remote-tracking branch 'origin/master'

This commit is contained in:
张松
2025-02-20 10:02:44 +08:00
14 changed files with 410 additions and 17 deletions

View File

@@ -1,6 +1,7 @@
package com.czg.service.product.mapper;
import com.czg.product.entity.Product;
import com.czg.product.vo.ShopProductInfoVo;
import com.czg.product.vo.ShopProductVo;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
@@ -20,4 +21,6 @@ public interface ProductMapper extends BaseMapper<Product> {
List<ShopProductVo> selectHotsProductList(@Param("shopId") Long shopId);
List<ShopProductVo> selectGroupProductList(@Param("shopId") Long shopId);
ShopProductInfoVo selectOneProductInfo(@Param("id") Long id, @Param("shopId") Long shopId);
}

View File

@@ -16,6 +16,7 @@ import com.czg.product.entity.Product;
import com.czg.product.enums.ProductIsSaleTypeEnum;
import com.czg.product.enums.ProductTypeEnum;
import com.czg.product.param.ProductIsSaleParam;
import com.czg.product.param.ProductIsSoldOutParam;
import com.czg.product.service.ProductService;
import com.czg.sa.StpKit;
import com.czg.service.product.mapper.ProdSkuMapper;
@@ -256,23 +257,38 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
String type = param.getType();
Long id = param.getId();
Integer isSale = param.getIsSale();
UpdateChain.of(ProdSku.class)
.set(ProdSku::getIsGrounding, isSale)
.eq(ProdSku::getId, id)
.update();
if (ProductIsSaleTypeEnum.PRODUCT.value().equals(type)) {
UpdateChain.of(Product.class)
.set(Product::getIsSale, isSale)
.eq(Product::getId, id)
.eq(Product::getShopId, shopId)
.update();
UpdateChain.of(ProdSku.class)
.set(ProdSku::getIsGrounding, isSale)
.eq(ProdSku::getProductId, id)
.update();
} else if (ProductIsSaleTypeEnum.SKU.value().equals(type)) {
UpdateChain.of(ProdSku.class)
.set(ProdSku::getIsGrounding, isSale)
.eq(ProdSku::getId, id)
.update();
}
return true;
}
@Override
@Transactional(rollbackFor = Exception.class)
public boolean markProductIsSoldOut(ProductIsSoldOutParam param) {
Long shopId = StpKit.USER.getLoginIdAsLong();
String type = param.getType();
Long id = param.getId();
Integer isSoldOut = param.getIsSoldOut();
UpdateChain.of(ProdSku.class)
.set(ProdSku::getIsPauseSale, isSoldOut)
.eq(ProdSku::getProductId, id)
.update();
if (ProductIsSaleTypeEnum.PRODUCT.value().equals(type)) {
UpdateChain.of(Product.class)
.set(Product::getIsSoldStock, isSoldOut)
.eq(Product::getId, id)
.eq(Product::getShopId, shopId)
.update();
}
return true;
}
}

View File

@@ -6,13 +6,16 @@ import cn.hutool.core.util.StrUtil;
import com.czg.enums.DeleteEnum;
import com.czg.enums.StatusEnum;
import com.czg.enums.YesNoEnum;
import com.czg.exception.CzgException;
import com.czg.product.dto.ProdSkuDTO;
import com.czg.product.dto.ProductDTO;
import com.czg.product.entity.ProdGroup;
import com.czg.product.entity.ProdGroupRelation;
import com.czg.product.entity.ProdSku;
import com.czg.product.entity.Product;
import com.czg.product.enums.ProductTypeEnum;
import com.czg.product.param.MiniHomeProductParam;
import com.czg.product.param.ShopProductSkuParam;
import com.czg.product.service.UProductService;
import com.czg.product.vo.*;
import com.czg.sa.StpKit;
@@ -197,6 +200,43 @@ public class UProductServiceImpl extends ServiceImpl<ProductMapper, Product> imp
return groupList.stream().filter(group -> CollUtil.isNotEmpty(group.getProductList())).toList();
}
@Override
public ShopProductInfoVo getProductInfo(Long id) {
Long shopId = StpKit.USER.getShopId(0L);
ShopProductInfoVo data = productMapper.selectOneProductInfo(id, shopId);
if (data == null) {
throw new CzgException("商品不可售");
}
return data;
}
@Override
public ShopProductSkuInfoVo getProductSkuInfo(ShopProductSkuParam param) {
Long shopId = StpKit.USER.getShopId(0L);
Product product = productMapper.selectOneById(param.getId());
if (product == null) {
throw new CzgException("商品信息不存在");
}
String specInfo = StrUtil.blankToDefault(param.getSpecInfo(), null);
ShopProductSkuInfoVo data = prodSkuMapper.selectOneByQueryAs(
query().eq(ProdSku::getProductId, param.getId())
.eq(ProdSku::getShopId, shopId)
.eq(ProdSku::getIsDel, DeleteEnum.NORMAL.value())
.eq(ProdSku::getIsGrounding, YesNoEnum.YES.value())
.eq(ProdSku::getSpecInfo, specInfo)
, ShopProductSkuInfoVo.class);
if (data == null) {
throw new CzgException("商品SKU不可售或不存在");
}
if (ProductTypeEnum.SINGLE.value().equals(product.getType())) {
data.setStockNumber(product.getStockNumber());
} else {
// TODO 临时数据,后续对接库存系统
data.setStockNumber(1000);
}
return data;
}
/**
* 计算是否在可售时间内
*

View File

@@ -5,10 +5,13 @@
<sql id="shopProductQuery">
select t1.id,
t1.name,
t1.short_title,
t2.sku_id,
t2.origin_price,
t2.sale_price,
t2.member_price,
t1.cover_img,
t1.images,
t3.name as unit_name,
t1.is_sold_stock,
t1.stock_number,
@@ -17,9 +20,11 @@
t1.days,
t1.start_time,
t1.end_time,
ifnull(t2.suit_num, 1) as suit_num
ifnull(t2.suit_num, 1) as suit_num,
t1.select_spec_info
from tb_product t1
left join (select x.product_id,
x.id as sku_id,
MIN(x.sale_price) as sale_price,
x.origin_price,
x.member_price,
@@ -53,4 +58,14 @@
</where>
order by t1.sort desc,t1.id desc
</select>
<select id="selectOneProductInfo" resultType="com.czg.product.vo.ShopProductInfoVo">
<include refid="shopProductQuery"/>
<where>
and t1.is_del = 0
and t1.is_sale = 1
and t2.sale_price is not null
and t1.shop_id = #{shopId}
and t1.id = #{id}
</where>
</select>
</mapper>