From 8ad1439fda6e05f59a710fca7b24df5887a0639c Mon Sep 17 00:00:00 2001 From: luowenfeng <1092164058@qq.com> Date: Tue, 23 Aug 2022 20:27:39 +0800 Subject: [PATCH] =?UTF-8?q?feature(uniapp=E5=95=86=E5=93=81):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=E5=95=86=E5=93=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/sku/vo/ProductSkuBaseVO.java | 7 +- .../admin/spu/vo/ProductSpuBaseVO.java | 3 +- .../service/spu/ProductSpuServiceImpl.java | 11 +- .../src/components/ImageUpload/index.vue | 4 +- .../src/views/mall/product/spu/index.vue | 2 +- .../src/views/mall/product/spu/save.vue | 222 +++++++++++------- 6 files changed, 156 insertions(+), 93 deletions(-) diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java index 38bdd61bf..07fddc9ac 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/sku/vo/ProductSkuBaseVO.java @@ -21,10 +21,7 @@ public class ProductSkuBaseVO { @NotEmpty(message = "商品 SKU 名字不能为空") private String name; - /** - * 规格值数组 - */ - @NotNull(message = "规格值数组不能为空") + @ApiModelProperty(value = "规格值数组-json格式 单规格中无此列表, [{propertyId: , valueId: }, {propertyId: , valueId: }]") private List 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; diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java index 0fde8d976..c320f902f 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/controller/admin/spu/vo/ProductSpuBaseVO.java @@ -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 picUrls; @ApiModelProperty(value = "商品视频", required = true) - @NotEmpty(message = "商品视频不能为空") private String videoUrl; @ApiModelProperty(value = "排序字段", required = true, example = "1") diff --git a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java index 4fad20bbd..988f8e1df 100755 --- a/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java +++ b/yudao-module-mall/yudao-module-product-biz/src/main/java/cn/iocoder/yudao/module/product/service/spu/ProductSpuServiceImpl.java @@ -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 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 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 skuCreateReqList = updateReqVO.getSkus(); - if(updateReqVO.getSpecType() == 1) { + // 多规格才需校验 + if(updateReqVO.getSpecType().equals(ProductSpuSpecTypeEnum.DISABLE.getType())) { productSkuService.validateSkus(skuCreateReqList); } // 更新 diff --git a/yudao-ui-admin/src/components/ImageUpload/index.vue b/yudao-ui-admin/src/components/ImageUpload/index.vue index 3f2bda7cc..08ff0f8fe 100644 --- a/yudao-ui-admin/src/components/ImageUpload/index.vue +++ b/yudao-ui-admin/src/components/ImageUpload/index.vue @@ -85,8 +85,8 @@ export default { value: { handler(val) { if (val) { - // 首先将值转为数组 - const list = Array.isArray(val) ? val : this.value.split(','); + // 首先将值转为数组, 当只穿了一个图片时,会报map方法错误 + const list = Array.isArray(val) ? val : Array.isArray(this.value.split(',')) ? this.value.split(','): Array.of(this.value); // 然后将数组转为对象数组 this.fileList = list.map(item => { if (typeof item === "string") { diff --git a/yudao-ui-admin/src/views/mall/product/spu/index.vue b/yudao-ui-admin/src/views/mall/product/spu/index.vue index 00ee1ed3f..e9f59febc 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/index.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/index.vue @@ -178,7 +178,7 @@ /> - + diff --git a/yudao-ui-admin/src/views/mall/product/spu/save.vue b/yudao-ui-admin/src/views/mall/product/spu/save.vue index 556bd816b..632c00744 100644 --- a/yudao-ui-admin/src/views/mall/product/spu/save.vue +++ b/yudao-ui-admin/src/views/mall/product/spu/save.vue @@ -1,13 +1,13 @@