feature(uniapp商品): 新增商品

This commit is contained in:
luowenfeng
2022-08-23 20:27:39 +08:00
parent 81666e3b62
commit 8ad1439fda
6 changed files with 156 additions and 93 deletions

View File

@ -21,10 +21,7 @@ public class ProductSkuBaseVO {
@NotEmpty(message = "商品 SKU 名字不能为空")
private String name;
/**
* 规格值数组
*/
@NotNull(message = "规格值数组不能为空")
@ApiModelProperty(value = "规格值数组-json格式 单规格中无此列表, [{propertyId: , valueId: }, {propertyId: , valueId: }]")
private List<Property> properties;
@ApiModelProperty(value = "销售价格,单位:分", required = true, example = "1024", notes = "单位:分")
@ -32,7 +29,7 @@ public class ProductSkuBaseVO {
private Integer price;
@ApiModelProperty(value = "市场价", example = "1024", notes = "单位:分")
private Integer originalPrice;
private Integer marketPrice;
@ApiModelProperty(value = "成本价", example = "1024", notes = "单位:分")
private Integer costPrice;

View File

@ -36,7 +36,7 @@ public class ProductSpuBaseVO {
private Long categoryId;
@ApiModelProperty(value = "商品品牌编号", required = true, example = "1")
@NotNull(message = "商品品牌编号不能为空")
// @NotNull(message = "商品品牌编号不能为空")
private Long brandId;
@ApiModelProperty(value = "商品图片的数组", required = true)
@ -44,7 +44,6 @@ public class ProductSpuBaseVO {
private List<String> picUrls;
@ApiModelProperty(value = "商品视频", required = true)
@NotEmpty(message = "商品视频不能为空")
private String videoUrl;
@ApiModelProperty(value = "排序字段", required = true, example = "1")

View File

@ -15,6 +15,7 @@ import cn.iocoder.yudao.module.product.convert.spu.ProductSpuConvert;
import cn.iocoder.yudao.module.product.dal.dataobject.sku.ProductSkuDO;
import cn.iocoder.yudao.module.product.dal.dataobject.spu.ProductSpuDO;
import cn.iocoder.yudao.module.product.dal.mysql.spu.ProductSpuMapper;
import cn.iocoder.yudao.module.product.enums.spu.ProductSpuSpecTypeEnum;
import cn.iocoder.yudao.module.product.service.category.ProductCategoryService;
import cn.iocoder.yudao.module.product.service.property.ProductPropertyService;
import cn.iocoder.yudao.module.product.service.sku.ProductSkuService;
@ -57,13 +58,18 @@ public class ProductSpuServiceImpl implements ProductSpuService {
categoryService.validateProductCategory(createReqVO.getCategoryId());
// 校验SKU
List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = createReqVO.getSkus();
if(createReqVO.getSpecType() == 1) {
// 多规格才需校验
if(Objects.equals(createReqVO.getSpecType(), ProductSpuSpecTypeEnum.DISABLE.getType())) {
productSkuService.validateSkus(skuCreateReqList);
}
// 插入SPU
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
spu.setMarketPrice(skuCreateReqList.stream().map(ProductSkuCreateOrUpdateReqVO::getMarketPrice).max(Integer::compare).orElse(0));
spu.setMaxPrice(skuCreateReqList.stream().map(ProductSkuCreateOrUpdateReqVO::getPrice).max(Integer::compare).orElse(0));
spu.setMinPrice(skuCreateReqList.stream().map(ProductSkuCreateOrUpdateReqVO::getPrice).min(Integer::compare).orElse(0));
ProductSpuMapper.insert(spu);
List<ProductSkuDO> skuDOList = ProductSkuConvert.INSTANCE.convertSkuDOList(skuCreateReqList);
skuDOList.forEach(v->v.setSpuId(spu.getId()));
// 批量插入sku
productSkuService.createSkus(skuDOList);
// 返回
@ -79,7 +85,8 @@ public class ProductSpuServiceImpl implements ProductSpuService {
categoryService.validateProductCategory(updateReqVO.getCategoryId());
// 校验SKU
List<ProductSkuCreateOrUpdateReqVO> skuCreateReqList = updateReqVO.getSkus();
if(updateReqVO.getSpecType() == 1) {
// 多规格才需校验
if(updateReqVO.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) {
productSkuService.validateSkus(skuCreateReqList);
}
// 更新