From bf3385c9330a8f334b9bc4f775b8e8b597d9fe11 Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Sat, 28 May 2022 09:42:07 +0800
Subject: [PATCH] fix news

---
 src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java |  182 ++++++++++++++++++++++++++++++--------------
 1 files changed, 123 insertions(+), 59 deletions(-)

diff --git a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
index 0ebb028..5ed4b73 100644
--- a/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
+++ b/src/main/java/cc/mrbird/febs/mall/service/impl/AdminMallGoodsService.java
@@ -73,34 +73,36 @@
                 return new FebsResponse().fail().message("商品分类不能为空");
             }
 
-            List<AddMallGoodsSkuDto> addSkus = addMallGoodsDto.getAddMallGoodsSkuDtos();
-            if (CollUtil.isEmpty(addSkus)) {
-                return new FebsResponse().fail().message("商品规格不能为空");
-            }
-            for (AddMallGoodsSkuDto addSku : addSkus) {
-                String skuName = addSku.getSkuName();
-                if (StrUtil.isEmpty(skuName)) {
-                    return new FebsResponse().fail().message("商品规格名称不能为空");
+            if (addMallGoodsDto.getIsSku() == 1) {
+                List<AddMallGoodsSkuDto> addSkus = addMallGoodsDto.getAddMallGoodsSkuDtos();
+                if (CollUtil.isEmpty(addSkus)) {
+                    return new FebsResponse().fail().message("商品规格不能为空");
                 }
-                String skuImage = addSku.getSkuImage();
-                if (StrUtil.isEmpty(skuImage)) {
-                    return new FebsResponse().fail().message("商品规格图片不能为空");
-                }
-                Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
-                if (skuVolume < 0) {
-                    return new FebsResponse().fail().message("商品规格销售数量不能小于0");
-                }
-                Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
-                if (stock < 0) {
-                    return new FebsResponse().fail().message("商品规格库存必须大于0");
-                }
-                String originalPrice = addSku.getOriginalPrice();
-                if (StrUtil.isEmpty(originalPrice)) {
-                    return new FebsResponse().fail().message("商品规格原价不能为空");
-                }
-                String presentPrice = addSku.getPresentPrice();
-                if (StrUtil.isEmpty(presentPrice)) {
-                    return new FebsResponse().fail().message("商品规格现价不能为空");
+                for (AddMallGoodsSkuDto addSku : addSkus) {
+                    String skuName = addSku.getSkuName();
+                    if (StrUtil.isEmpty(skuName)) {
+                        return new FebsResponse().fail().message("商品规格名称不能为空");
+                    }
+                    String skuImage = addSku.getSkuImage();
+                    if (StrUtil.isEmpty(skuImage)) {
+                        return new FebsResponse().fail().message("商品规格图片不能为空");
+                    }
+                    Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
+                    if (skuVolume < 0) {
+                        return new FebsResponse().fail().message("商品规格销售数量不能小于0");
+                    }
+                    Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
+                    if (stock < 0) {
+                        return new FebsResponse().fail().message("商品规格库存必须大于0");
+                    }
+                    String originalPrice = addSku.getOriginalPrice();
+                    if (StrUtil.isEmpty(originalPrice)) {
+                        return new FebsResponse().fail().message("商品规格原价不能为空");
+                    }
+                    String presentPrice = addSku.getPresentPrice();
+                    if (StrUtil.isEmpty(presentPrice)) {
+                        return new FebsResponse().fail().message("商品规格现价不能为空");
+                    }
                 }
             }
         }
@@ -126,6 +128,27 @@
         }
 
         if (addMallGoodsDto.getGoodsType() == 2) {
+            return new FebsResponse().success().message("添加成功");
+        }
+
+        // 单规格
+        if (addMallGoodsDto.getIsSku() == 2) {
+            MallGoodsStyle style = new MallGoodsStyle();
+            style.setGoodsId(mallGoods.getId());
+            style.setName(mallGoods.getGoodsName());
+            mallGoodsStyleMapper.insert(style);
+
+            MallGoodsSku sku = new MallGoodsSku();
+            sku.setGoodsId(mallGoods.getId());
+            sku.setSkuImage(mallGoods.getThumb());
+            sku.setSkuName(mallGoods.getGoodsName());
+            sku.setCostPrice(mallGoods.getCostPrice());
+            sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
+            sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
+            sku.setSkuVolume(mallGoods.getVolume());
+            sku.setStock(mallGoods.getStock());
+            sku.setStyleId(style.getId());
+            mallGoodsSkuMapper.insert(sku);
             return new FebsResponse().success().message("添加成功");
         }
 
@@ -262,43 +285,57 @@
         if (mallGoodsByGoodsNo > 0) {
             return new FebsResponse().fail().message("商品编号不能重复");
         }
-        Long categoryId = mallGoodsUpdateDto.getCategoryId();
-        if (ObjectUtil.isEmpty(categoryId)) {
-            return new FebsResponse().fail().message("商品分类不能为空");
-        }
-        List<MailGoodsSkuDto> addSkus = mallGoodsUpdateDto.getMailGoodsSkuDto();
-        if (CollUtil.isEmpty(addSkus)) {
-            return new FebsResponse().fail().message("商品规格不能为空");
-        }
-        for (MailGoodsSkuDto addSku : addSkus) {
-            String skuName = addSku.getSkuName();
-            if (StrUtil.isEmpty(skuName)) {
-                return new FebsResponse().fail().message("商品规格名称不能为空");
-            }
-            String skuImage = addSku.getSkuImage();
-            if (StrUtil.isEmpty(skuImage)) {
-                return new FebsResponse().fail().message("商品规格图片不能为空");
-            }
-            Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
-            if (skuVolume < 0) {
-                return new FebsResponse().fail().message("商品规格销售数量不能小于0");
-            }
-            Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
-            if (stock < 0) {
-                return new FebsResponse().fail().message("商品规格库存必须大于0");
-            }
-            BigDecimal originalPrice = addSku.getOriginalPrice();
-            if (originalPrice.compareTo(BigDecimal.ZERO) <= 0) {
-                return new FebsResponse().fail().message("商品规格原价不能小于0");
-            }
-            BigDecimal presentPrice = addSku.getPresentPrice();
-            if (presentPrice.compareTo(BigDecimal.ZERO) <= 0) {
-                return new FebsResponse().fail().message("商品规格现价不能小于0");
+
+        if (mallGoodsUpdateDto.getGoodsType() != 2) {
+            Long categoryId = mallGoodsUpdateDto.getCategoryId();
+            if (ObjectUtil.isEmpty(categoryId)) {
+                return new FebsResponse().fail().message("商品分类不能为空");
             }
 
+            if (mallGoodsUpdateDto.getIsSku() == 1) {
+                List<MailGoodsSkuDto> addSkus = mallGoodsUpdateDto.getMailGoodsSkuDto();
+                if (CollUtil.isEmpty(addSkus)) {
+                    return new FebsResponse().fail().message("商品规格不能为空");
+                }
+                for (MailGoodsSkuDto addSku : addSkus) {
+                    String skuName = addSku.getSkuName();
+                    if (StrUtil.isEmpty(skuName)) {
+                        return new FebsResponse().fail().message("商品规格名称不能为空");
+                    }
+                    String skuImage = addSku.getSkuImage();
+                    if (StrUtil.isEmpty(skuImage)) {
+                        return new FebsResponse().fail().message("商品规格图片不能为空");
+                    }
+                    Integer skuVolume = addSku.getSkuVolume() == null ? 0 : addSku.getSkuVolume();
+                    if (skuVolume < 0) {
+                        return new FebsResponse().fail().message("商品规格销售数量不能小于0");
+                    }
+                    Integer stock = addSku.getStock() == null ? 0 : addSku.getStock();
+                    if (stock < 0) {
+                        return new FebsResponse().fail().message("商品规格库存必须大于0");
+                    }
+                    BigDecimal originalPrice = addSku.getOriginalPrice();
+                    if (originalPrice.compareTo(BigDecimal.ZERO) <= 0) {
+                        return new FebsResponse().fail().message("商品规格原价不能小于0");
+                    }
+                    BigDecimal presentPrice = addSku.getPresentPrice();
+                    if (presentPrice.compareTo(BigDecimal.ZERO) <= 0) {
+                        return new FebsResponse().fail().message("商品规格现价不能小于0");
+                    }
+
+                }
+            }
         }
+
         //新增商品
         MallGoods mallGoods = mallGoodsMapper.selectById(mallGoodsUpdateDto.getId());
+
+        // 若原来不为多规格或编辑后也不为多规格,则清空样式和规格
+        if (mallGoods.getIsSku() == 2 || mallGoodsUpdateDto.getIsSku() == 2) {
+            mallGoodsSkuMapper.deleteByGoodsId(mallGoods.getId());
+            mallGoodsStyleMapper.deleteByGoodsId(mallGoods.getId());
+        }
+
         BeanUtil.copyProperties(mallGoodsUpdateDto, mallGoods);
         mallGoodsMapper.updateById(mallGoods);
 
@@ -319,6 +356,33 @@
             }
         }
 
+        if (mallGoodsUpdateDto.getGoodsType() == 2) {
+            return new FebsResponse().success().message("编辑成功");
+        }
+
+        // 单规格
+        if (mallGoodsUpdateDto.getIsSku() == 2) {
+            MallGoodsStyle style = new MallGoodsStyle();
+            style.setGoodsId(mallGoods.getId());
+            style.setName(mallGoods.getGoodsName());
+            mallGoodsStyleMapper.insert(style);
+
+            MallGoodsSku sku = new MallGoodsSku();
+            sku.setGoodsId(mallGoods.getId());
+            sku.setSkuImage(mallGoods.getThumb());
+            sku.setSkuName(mallGoods.getGoodsName());
+            sku.setCostPrice(mallGoods.getCostPrice());
+            sku.setPresentPrice(new BigDecimal(mallGoods.getPresentPrice()));
+            sku.setOriginalPrice(new BigDecimal(mallGoods.getOriginalPrice()));
+            sku.setSkuVolume(mallGoods.getVolume());
+            sku.setStock(mallGoods.getStock());
+            sku.setStyleId(style.getId());
+            mallGoodsSkuMapper.insert(sku);
+            return new FebsResponse().success().message("添加成功");
+        }
+
+
+
         // 删除已存在sku
         List<Long> delSkuIds = mallGoodsUpdateDto.getDelSkuId();
         if (CollUtil.isNotEmpty(delSkuIds)) {

--
Gitblit v1.9.1