feature(uniapp商品): 新增商品数据

pull/2/head
luowenfeng 2022-08-22 21:20:49 +08:00
parent 617573a59b
commit 8de29d302c
5 changed files with 28 additions and 18 deletions

View File

@ -19,8 +19,7 @@ public class ProductSkuBaseVO {
// TODO @franky类似这种字段有额外说明的。可以写成 @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]") // TODO @franky类似这种字段有额外说明的。可以写成 @ApiModelProperty(value = "规格值数组", required = true, notes = "json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]")
@ApiModelProperty(value = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]", required = true) @ApiModelProperty(value = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]")
@NotNull(message = "规格值数组-json格式 [{propertyId: , valueId: }, {propertyId: , valueId: }]不能为空")
private List<Property> properties; private List<Property> properties;
@ApiModelProperty(value = "销售价格,单位:分", required = true) @ApiModelProperty(value = "销售价格,单位:分", required = true)

View File

@ -91,7 +91,7 @@ public class ProductSkuServiceImpl implements ProductSkuService {
@Override @Override
public void validateSkus(List<ProductSkuCreateReqVO> list) { public void validateSkus(List<ProductSkuCreateReqVO> list) {
List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> p.getProperties().stream()).collect(Collectors.toList()); List<ProductSkuBaseVO.Property> skuPropertyList = list.stream().flatMap(p -> Optional.of(p.getProperties()).orElse(new ArrayList<>()).stream()).collect(Collectors.toList());
// 校验规格属性以及规格值是否存在 // 校验规格属性以及规格值是否存在
List<Long> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList()); List<Long> propertyIds = skuPropertyList.stream().map(ProductSkuBaseVO.Property::getPropertyId).collect(Collectors.toList());
List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds); List<ProductPropertyRespVO> propertyAndValueList = productPropertyService.selectByIds(propertyIds);

View File

@ -57,7 +57,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
categoryService.validateProductCategory(createReqVO.getCategoryId()); categoryService.validateProductCategory(createReqVO.getCategoryId());
// 校验SKU // 校验SKU
List<ProductSkuCreateReqVO> skuCreateReqList = createReqVO.getSkus(); List<ProductSkuCreateReqVO> skuCreateReqList = createReqVO.getSkus();
productSkuService.validateSkus(skuCreateReqList); if(createReqVO.getSpecType() == 1) {
productSkuService.validateSkus(skuCreateReqList);
}
// 插入SPU // 插入SPU
ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO); ProductSpuDO spu = ProductSpuConvert.INSTANCE.convert(createReqVO);
ProductSpuMapper.insert(spu); ProductSpuMapper.insert(spu);
@ -81,7 +83,9 @@ public class ProductSpuServiceImpl implements ProductSpuService {
categoryService.validateProductCategory(updateReqVO.getCategoryId()); categoryService.validateProductCategory(updateReqVO.getCategoryId());
// 校验SKU // 校验SKU
List<ProductSkuCreateReqVO> skuCreateReqList = updateReqVO.getSkus(); List<ProductSkuCreateReqVO> skuCreateReqList = updateReqVO.getSkus();
productSkuService.validateSkus(skuCreateReqList); if(updateReqVO.getSpecType() == 1) {
productSkuService.validateSkus(skuCreateReqList);
}
// 更新 // 更新
ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO); ProductSpuDO updateObj = ProductSpuConvert.INSTANCE.convert(updateReqVO);
ProductSpuMapper.updateById(updateObj); ProductSpuMapper.updateById(updateObj);

View File

@ -178,9 +178,9 @@
/> />
<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body > <el-dialog :title="title" :visible.sync="open" width="900px" append-to-body destroy-on-close>
<save @closeDialog="open = false"/> <save @closeDialog="open = false; getList()"/>
</el-dialog> </el-dialog>
</div> </div>
</template> </template>

View File

@ -309,26 +309,33 @@ export default {
if (this.ratesForm.spec == 1) { if (this.ratesForm.spec == 1) {
rates.forEach(r => { rates.forEach(r => {
let properties = [] let properties = []
r.spec.forEach((v, i) => { if(r.spec instanceof Array){
let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v); r.spec.forEach((v, i) => {
let propertie = {}; let specValue = this.dynamicSpec[i].specValue.find(o => o.name == v);
propertie.propertyId = this.dynamicSpec[i].specId; let propertie = {};
propertie.valueId = specValue.id; propertie.propertyId = this.dynamicSpec[i].specId;
properties.push(propertie); propertie.valueId = specValue.id;
}) properties.push(propertie);
})
}else{
let specValue = this.dynamicSpec[0].specValue.find(o => o.name == r.spec);
let propertie = {};
propertie.propertyId = this.dynamicSpec[0].specId;
propertie.valueId = specValue.id;
properties.push(propertie);
}
r.properties = properties; r.properties = properties;
}) })
} }
this.baseForm.skus = rates; this.baseForm.skus = rates;
this.baseForm.specType = this.ratesForm.spec; this.baseForm.specType = this.ratesForm.spec;
this.baseForm.categoryId = this.baseForm.categoryIds[this.baseForm.categoryIds.length - 1]; this.baseForm.categoryId = this.baseForm.categoryIds[this.baseForm.categoryIds.length - 1];
console.log(this.baseForm)
createSpu(this.baseForm).then((response) => { createSpu(this.baseForm).then((response) => {
console.log(response)
this.$modal.msgSuccess("新增成功"); this.$modal.msgSuccess("新增成功");
this.open = false;
this.getList();
this.$emit("closeDialog"); this.$emit("closeDialog");
}); });
}, },
/** 查询规格 */ /** 查询规格 */
getPropertyPageList() { getPropertyPageList() {