Browse Source

Merge branch 'developer' into developerB

# Conflicts:
#	src/main/java/com/caimei365/commodity/mapper/PageMapper.java
#	src/main/java/com/caimei365/commodity/service/PageService.java
JiangChongBo 2 years ago
parent
commit
c9af7fb7ae
41 changed files with 1398 additions and 1089 deletions
  1. 115 58
      src/main/java/com/caimei365/commodity/components/PriceUtilService.java
  2. 1 0
      src/main/java/com/caimei365/commodity/controller/HeheApi.java
  3. 6 0
      src/main/java/com/caimei365/commodity/controller/ProductPageApi.java
  4. 1 1
      src/main/java/com/caimei365/commodity/controller/ProductPriceApi.java
  5. 36 32
      src/main/java/com/caimei365/commodity/controller/ProductShopApi.java
  6. 12 3
      src/main/java/com/caimei365/commodity/mapper/HeheMapper.java
  7. 2 0
      src/main/java/com/caimei365/commodity/mapper/PageMapper.java
  8. 28 10
      src/main/java/com/caimei365/commodity/mapper/PriceMapper.java
  9. 4 0
      src/main/java/com/caimei365/commodity/mapper/ShopMapper.java
  10. 133 0
      src/main/java/com/caimei365/commodity/model/dto/HeHeSku.java
  11. 6 31
      src/main/java/com/caimei365/commodity/model/dto/ProductDto.java
  12. 91 0
      src/main/java/com/caimei365/commodity/model/dto/Sku.java
  13. 2 0
      src/main/java/com/caimei365/commodity/model/po/HeheCollageProductPo.java
  14. 7 24
      src/main/java/com/caimei365/commodity/model/po/ProductPo.java
  15. 8 0
      src/main/java/com/caimei365/commodity/model/vo/HeheProductVo.java
  16. 7 0
      src/main/java/com/caimei365/commodity/model/vo/LadderPriceVo.java
  17. 27 37
      src/main/java/com/caimei365/commodity/model/vo/PriceVo.java
  18. 29 29
      src/main/java/com/caimei365/commodity/model/vo/ProductDetailVo.java
  19. 14 6
      src/main/java/com/caimei365/commodity/model/vo/ProductFormVo.java
  20. 43 116
      src/main/java/com/caimei365/commodity/model/vo/ProductItemVo.java
  21. 10 0
      src/main/java/com/caimei365/commodity/model/vo/UserLikeProductVo.java
  22. 2 0
      src/main/java/com/caimei365/commodity/service/PageService.java
  23. 2 8
      src/main/java/com/caimei365/commodity/service/impl/CouponServiceImpl.java
  24. 55 57
      src/main/java/com/caimei365/commodity/service/impl/HeheServiceImpl.java
  25. 27 72
      src/main/java/com/caimei365/commodity/service/impl/PageServiceImpl.java
  26. 2 2
      src/main/java/com/caimei365/commodity/service/impl/PriceServiceImpl.java
  27. 0 10
      src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java
  28. 15 8
      src/main/java/com/caimei365/commodity/service/impl/SecondHandServiceImpl.java
  29. 6 3
      src/main/java/com/caimei365/commodity/service/impl/SellerServiceImpl.java
  30. 76 102
      src/main/java/com/caimei365/commodity/service/impl/ShopServiceImpl.java
  31. 1 1
      src/main/java/com/caimei365/commodity/service/impl/UserLikeServiceImpl.java
  32. 7 8
      src/main/resources/mapper/CouponMapper.xml
  33. 127 78
      src/main/resources/mapper/HeheMapper.xml
  34. 47 50
      src/main/resources/mapper/PageMapper.xml
  35. 171 88
      src/main/resources/mapper/PriceMapper.xml
  36. 7 5
      src/main/resources/mapper/PromotionsMapper.xml
  37. 33 20
      src/main/resources/mapper/SearchMapper.xml
  38. 163 143
      src/main/resources/mapper/SecondHandMapper.xml
  39. 5 18
      src/main/resources/mapper/SellerMapper.xml
  40. 69 62
      src/main/resources/mapper/ShopMapper.xml
  41. 1 7
      src/main/resources/mapper/UserLikeMapper.xml

+ 115 - 58
src/main/java/com/caimei365/commodity/components/PriceUtilService.java

@@ -3,9 +3,11 @@ package com.caimei365.commodity.components;
 
 import com.caimei365.commodity.mapper.PriceMapper;
 import com.caimei365.commodity.mapper.PromotionsMapper;
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.utils.ImageUtils;
 import com.caimei365.commodity.utils.MathUtil;
+import com.google.common.util.concurrent.AtomicDouble;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -13,7 +15,12 @@ import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.atomic.AtomicReference;
+import java.util.stream.Collectors;
 import java.util.stream.IntStream;
 
 /**
@@ -81,21 +88,25 @@ public class PriceUtilService {
 
     /**
      * 根据用户id设置详细价格
-     *
+     * ind=1不屏蔽价格
      * @param price  商品价格类
      * @param userId 用户Id
      */
-    public void setPriceByUserId(PriceVo price, Integer userId) {
+    public void setPriceByUserId(PriceVo price, Integer userId, Integer ind) {
         // 根据用户Id查询用户身份: 0个人,1协销,2会员机构,3供应商,4普通机构
         Integer identity = priceMapper.getIdentityByUserId(userId);
-        if (null == identity) {identity = 0;}
+        if (null == identity) {
+            identity = 0;
+        }
         // priceFlag: 0公开价格,1不公开价格,2仅对会员机构公开,3仅对医美机构公开
         Integer priceFlag = null != price.getPriceFlag() ? price.getPriceFlag() : 0;
         // 会员机构类型:1医美,2生美
         Integer clubType = 0;
         if (identity == 2) {
             clubType = priceMapper.getClubTypeById(userId);
-            if (null == clubType) {clubType = 0;}
+            if (null == clubType) {
+                clubType = 0;
+            }
         }
         // 根据用户Id查询超级会员id
         Integer svipUserId = priceMapper.getSvipUserIdByUserId(userId);
@@ -103,29 +114,39 @@ public class PriceUtilService {
         boolean isSuperVip = null != svipUserId;
         // 根据商品id,用户身份 查询商品活动
         PromotionsVo promotions = promotionsMapper.getPricePromotions(price.getProductId(), identity);
-        price.setRepurchaseFlag(0);
         price.setActStatus(0);
         // 用户身份: 2-会员机构, 4-普通机构
         price.setUserIdentity(identity);
         //是否是供应商自己的商品
         boolean isShopOwn = false;
-        if (identity == 3){
+        if (identity == 3) {
             // 根据用户Id查询供应商Id
             Integer shopId = priceMapper.getShopIdByUserId(userId);
-            if (null != shopId && shopId.equals(price.getShopId())){
+            if (null != shopId && shopId.equals(price.getShopId())) {
                 isShopOwn = true;
             }
         }
         // 设置价格标志(协销|价格公开|仅对医美机构公开|仅对会员机构公开|供应商自己的商品)
         boolean setFlag = identity == 1 || priceFlag == 0 || (priceFlag == 3 && clubType == 1) || (priceFlag == 2 && (identity == 2 || isSuperVip)) || isShopOwn;
-        if (setFlag) {
-            // 设置划线价
-            price.setOriginalPrice(price.getPrice());
-            //税费标志
-            boolean taxFlag = "0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()));
+
+        List<Sku> skus = priceMapper.findSkus(price.getProductId());
+        AtomicDouble atomicDouble = new AtomicDouble();
+        atomicDouble.set(skus.get(0).getPrice());
+        int size = skus.size();
+        //税费标志
+        boolean taxFlag = "0".equals(price.getIncludedTax()) && ("1".equals(price.getInvoiceType()) || "2".equals(price.getInvoiceType()));
+        //未设置价格
+        price.setLadderPriceFlag(0);
+        price.setPrice(skus.get(0).getPrice());
+        price.setSkuId(skus.get(0).getSkuId());
+        price.setMinBuyNumber(skus.get(0).getMinBuyNumber());
+        price.setUnit(skus.get(0).getUnit());
+        price.setStock(skus.get(0).getStock());
+        skus.forEach(s -> {
+            s.setPriceGrade(getPriceGrade(s.getPrice()));
             if (1 == price.getSvipProductFlag()) {
                 // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
-                price.setLadderPriceFlag(0);
+                s.setLadderPriceFlag(0);
                 // 超级会员优惠价
                 BigDecimal svipDiscountPrice = price.getSvipDiscountPrice();
                 if (1 == price.getSvipPriceType()) {
@@ -133,13 +154,17 @@ public class PriceUtilService {
                     price.setSvipPriceTag(MathUtil.div(price.getSvipDiscount(), 10, 1) + "折");
                     if (isSuperVip) {
                         // 超级会员用户设置优惠价
-                        svipDiscountPrice = MathUtil.div(MathUtil.mul(price.getPrice(), price.getSvipDiscount()), 100, 2);
+                        price.setOriginalPrice(atomicDouble.get());
+                        s.setOriginalPrice(s.getPrice());
+                        svipDiscountPrice = MathUtil.div(MathUtil.mul(s.getPrice(), price.getSvipDiscount()), 100, 2);
+                        s.setPrice(svipDiscountPrice.doubleValue());
                         price.setPrice(svipDiscountPrice.doubleValue());
                     }
                 } else if (2 == price.getSvipPriceType()) {
                     // 直接优惠价
                     if (isSuperVip) {
                         // 超级会员用户设置优惠价
+                        s.setPrice(svipDiscountPrice.doubleValue());
                         price.setPrice(svipDiscountPrice.doubleValue());
                     }
                     if (taxFlag) {
@@ -152,53 +177,94 @@ public class PriceUtilService {
             } else if (null != promotions) {
                 // 促销活动
                 price.setActStatus(1);
-                price.setLadderPriceFlag(0);
+                s.setLadderPriceFlag(0);
                 if (promotions.getMode() == 3) {
                     // 获取赠品
                     List<ProductItemVo> giftList = promotionsMapper.getPromotionGifts(promotions.getId());
                     promotions.setGiftList(giftList);
                 }
                 if (promotions.getType() == 1 && promotions.getMode() == 1 && null != promotions.getTouchPrice()) {
+                    s.setOriginalPrice(s.getPrice());
+                    price.setOriginalPrice(atomicDouble.get());
+                    s.setPrice(promotions.getTouchPrice());
                     price.setPrice(promotions.getTouchPrice());
                 }
                 price.setPromotions(promotions);
             } else {
                 if (null != userId) {
-                    if (1 == price.getLadderPriceFlag()) {
-                        // 阶梯价
-                        LadderPriceVo lowerPrice = priceMapper.findLowerLadderPrice(price.getProductId());
-                        LadderPriceVo lowerBuyNum = priceMapper.findMaxLadderPrice(price.getProductId());
-                        if (null != lowerPrice) {
-                            price.setMaxBuyNumber(lowerPrice.getBuyNum());
-                            if (null != lowerBuyNum) {
-                                price.setMinBuyNumber(lowerBuyNum.getBuyNum());
-                                price.setPrice(lowerBuyNum.getBuyPrice());
-                            }
+                    if (1 == s.getLadderPriceFlag()) {
+                        // sku的阶梯价
+                        LadderPriceVo lowerBuyNum = priceMapper.findMaxLadderPrice(s.getSkuId());
+                        s.setMinBuyNumber(lowerBuyNum.getBuyNum());
+                        s.setPrice(lowerBuyNum.getBuyPrice());
+                        s.setStock(lowerBuyNum.getStock());
+                        s.setUnit(lowerBuyNum.getUnit());
+                        List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(s.getSkuId());
+                        TaxVo tax = priceMapper.getTaxByProductId(price.getProductId());
+                        if (!CollectionUtils.isEmpty(ladderPrices)) {
+                            setLadderPriceList(ladderPrices, tax);
+                        }
+                        s.setLadderPriceList(ladderPrices);
+                        price.setLadderPriceFlag(1);
+                        if (1 == size) {
+                            //1.对于只有一个SKU的商品,各个商品列表直接显示机构价即可:若是阶梯价,则显示第一级阶梯的价格:
+                            price.setSkuId(ladderPrices.get(0).getSkuId());
+                            price.setPrice(ladderPrices.get(0).getBuyPrice());
+                            price.setMinBuyNumber(ladderPrices.get(0).getBuyNum());
+                            price.setStock(ladderPrices.get(0).getStock());
+                            price.setUnit(ladderPrices.get(0).getUnit());
                         } else {
-                            price.setLadderPriceFlag(0);
+                            //2.对于有多个SKU的商品,各个商品列表显示所有SKU中最低的价格:
+                            // 若SKU中,全部都是阶梯价,则显示所有SKU中第一级阶梯的价格中的最低价,
+                            // 若SKU中,使用阶梯价和不使用阶梯价(只是用机构价》并存,则用机构价和第一级阶梯价比大小,展示最小的价格
+                            // skuid分组取第一阶梯中最便宜的
+                            ProductItemVo lowLadderPrice = priceMapper.findLowPriceOfAll(price.getProductId());
+                            ProductItemVo lowAllPrice = priceMapper.findLowPriceOfPrice(price.getProductId());
+                            if (null != lowLadderPrice) {
+                                ProductItemVo productItemVo = lowLadderPrice.getPrice() > lowAllPrice.getPrice() ? lowAllPrice : lowLadderPrice;
+                                price.setPrice(productItemVo.getPrice());
+                                price.setSkuId(productItemVo.getSkuId());
+                                price.setMinBuyNumber(productItemVo.getMinBuyNumber());
+                                price.setUnit(productItemVo.getUnit());
+                                price.setStock(productItemVo.getStock());
+                            } else {
+                                price.setPrice(lowAllPrice.getPrice());
+                                price.setSkuId(lowAllPrice.getSkuId());
+                                price.setMinBuyNumber(lowAllPrice.getMinBuyNumber());
+                                price.setUnit(lowAllPrice.getUnit());
+                                price.setStock(lowAllPrice.getStock());
+                            }
                         }
                     } else {
                         // 复购价
-                        Double repurchase = priceMapper.getRepurchasePrice(price.getProductId(), userId);
+                        Double repurchase = priceMapper.getRepurchasePrice(s.getSkuId(), userId);
                         if (null != repurchase && repurchase > 0) {
-                            price.setPrice(repurchase);
-                            price.setRepurchaseFlag(1);
-                            price.setLadderPriceFlag(0);
+                            s.setPrice(repurchase);
+                            s.setRepurchaseFlag(1);
+                            s.setLadderPriceFlag(0);
                         }
                     }
                 }
             }
             //添加税费
             if (taxFlag) {
-                BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(price.getPrice(), price.getTaxRate()), 100, 2);
-                price.setPrice(MathUtil.add(price.getPrice(), thisTaxFee).doubleValue());
-                BigDecimal originalTaxFee = MathUtil.div(MathUtil.mul(price.getOriginalPrice(), price.getTaxRate()), 100, 2);
-                price.setOriginalPrice(MathUtil.add(price.getOriginalPrice(), originalTaxFee).doubleValue());
+                BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(s.getPrice(), price.getTaxRate()), 100, 2);
+                s.setPrice(MathUtil.add(s.getPrice(), thisTaxFee).doubleValue());
+                BigDecimal originalTaxFee = MathUtil.div(MathUtil.mul(s.getOriginalPrice(), price.getTaxRate()), 100, 2);
+                s.setOriginalPrice(MathUtil.add(s.getOriginalPrice(), originalTaxFee).doubleValue());
             }
-        } else {
-            price.setPrice(0d);
-            price.setOriginalPrice(0d);
-            price.setNormalPrice(0d);
+        });
+        // price添加税费
+        if (taxFlag) {
+            BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(price.getPrice(), price.getTaxRate()), 100, 2);
+            price.setPrice(MathUtil.add(price.getPrice(), thisTaxFee).doubleValue());
+            BigDecimal originalTaxFee = MathUtil.div(MathUtil.mul(price.getOriginalPrice(), price.getTaxRate()), 100, 2);
+            price.setOriginalPrice(MathUtil.add(price.getOriginalPrice(), originalTaxFee).doubleValue());
+        }
+        price.setSkus(skus);
+        // 身份不对
+        if (!setFlag && 1 != ind) {
+            price.setSkus(priceMapper.findSkusOutOfPrice(price.getProductId()));
             price.setUserIdentity(0);
             if (null != promotions) {
                 price.setActStatus(1);
@@ -210,45 +276,36 @@ public class PriceUtilService {
                 price.setActStatus(0);
             }
         }
-        // 屏蔽成本价
-        price.setCostProportional(0d);
-        price.setCostPrice(0d);
     }
 
     /**
      * 设置商品主图及价格
+     * ind=1不屏蔽价格
      *
      * @param userId  用户Id
      * @param product ProductItemVo
      */
-    public void setProductDetails(Integer userId, ProductItemVo product) {
+    public void setProductDetails(Integer userId, ProductItemVo product, Integer ind) {
         // 设置图片
         product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
-        // 设置价格等级
-        product.setPriceGrade(getPriceGrade(product.getPrice()));
         // 数据库获取基本价格信息
         PriceVo price = priceMapper.getDetailPrice(product.getProductId());
         // 根据用户id设置详细价格
-        setPriceByUserId(price, userId);
+        setPriceByUserId(price, userId, ind);
         // 设置价格
         product.setActStatus(price.getActStatus());
-        product.setPrice(price.getPrice());
-        product.setOriginalPrice(price.getOriginalPrice());
-        product.setNormalPrice(price.getNormalPrice());
-        product.setLadderPriceFlag(price.getLadderPriceFlag());
         product.setPromotions(price.getPromotions());
-        product.setMinBuyNumber(price.getMinBuyNumber());
         product.setUserIdentity(price.getUserIdentity());
-        product.setRepurchaseFlag(price.getRepurchaseFlag());
-        product.setMaxBuyNumber(price.getMaxBuyNumber());
         product.setSvipProductFlag(price.getSvipProductFlag());
         product.setSvipPriceTag(price.getSvipPriceTag());
-        List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(product.getProductId());
-        TaxVo tax = priceMapper.getTaxByProductId(product.getProductId());
-        if (!CollectionUtils.isEmpty(ladderPrices)) {
-            setLadderPriceList(ladderPrices, tax);
-        }
-        product.setLadderPrices(ladderPrices);
+        product.setPrice(price.getPrice());
+        product.setSkuId(price.getSkuId());
+        product.setOriginalPrice(price.getPrice());
+        product.setPriceGrade(getPriceGrade(price.getPrice()));
+        product.setMinBuyNumber(price.getMinBuyNumber());
+        product.setUnit(price.getUnit());
+        product.setStock(price.getStock());
+        product.setSkus(price.getSkus());
     }
 
 }

+ 1 - 0
src/main/java/com/caimei365/commodity/controller/HeheApi.java

@@ -107,6 +107,7 @@ public class HeheApi {
     public ResponseJson<Map<String, Object>> getHomeData(Integer userId) {
         return heheService.getHomeData(userId);
     }
+
     @ApiOperation("活动专区")
     @ApiImplicitParams({
             @ApiImplicitParam(name = "userId", value = "分销者用户id", required = true),

+ 6 - 0
src/main/java/com/caimei365/commodity/controller/ProductPageApi.java

@@ -41,6 +41,12 @@ public class ProductPageApi {
 
     private final PageService pageService;
 
+    @ApiOperation("删除sku")
+    @ApiImplicitParam(required = true, name = "skuId", value = "skuId")
+    @GetMapping("/del/sku")
+    public ResponseJson delSku(Integer skuId) {
+        return pageService.delSku(skuId);
+    }
     /**
      * 获取分类列表
      *

+ 1 - 1
src/main/java/com/caimei365/commodity/controller/ProductPriceApi.java

@@ -87,7 +87,7 @@ public class ProductPriceApi {
      * 更新商品销量
      *
      * @param productSalesDto {productInfo: [ // 商品id,数量
-     *                        {"productId": 2789, "productCount": 1},
+     *                        {"skuId": 2789, "productCount": 1},
      *                        {"productId": 2790, "productCount": 2}
      *                        ]
      *                        }

+ 36 - 32
src/main/java/com/caimei365/commodity/controller/ProductShopApi.java

@@ -24,7 +24,7 @@ import java.util.Map;
  * @author : Charles
  * @date : 2021/4/16
  */
-@Api(tags="供应商商品API")
+@Api(tags = "供应商商品API")
 @RestController
 @RequiredArgsConstructor
 @RequestMapping("/commodity/shop")
@@ -36,8 +36,8 @@ public class ProductShopApi {
      */
     @ApiOperation("供应商-主推商品(旧:/supplier/home/products)")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = true, name = "shopId", value = "供应商Id(旧:supplierId)"),
-        @ApiImplicitParam(required = false, name = "identity", value = "用户身份:1协销,2会员机构,3供应商,4普通机构,5医美机构")
+            @ApiImplicitParam(required = true, name = "shopId", value = "供应商Id(旧:supplierId)"),
+            @ApiImplicitParam(required = false, name = "identity", value = "用户身份:1协销,2会员机构,3供应商,4普通机构,5医美机构")
     })
     @GetMapping("/product/main")
     public ResponseJson<List<ProductListVo>> getSupplierMainProducts(Integer shopId, @RequestParam(value = "identity", defaultValue = "0") Integer identity) {
@@ -49,25 +49,25 @@ public class ProductShopApi {
      */
     @ApiOperation("供应商-我的商品(旧:/supplier/myProduct)")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = true, name = "shopId", value = "供应商Id"),
-        @ApiImplicitParam(required = false, name = "name", value = "商品名称"),
+            @ApiImplicitParam(required = true, name = "shopId", value = "供应商Id"),
+            @ApiImplicitParam(required = false, name = "name", value = "商品名称"),
             @ApiImplicitParam(required = false, name = "newvalidFlag", value = "新品商品状态  0.参与 , 1.审核通过, 2.未参与 ,3.审核未通过,4.时间过期"),
-        @ApiImplicitParam(required = false, name = "productCode", value = "货号"),
-        @ApiImplicitParam(required = false, name = "validFlag", value = "状态:0逻辑删除,1待审核,2已上架,3已下架,8审核未通过,9已隐身,10已冻结"),
-        @ApiImplicitParam(required = false, name = "featuredFlag", value = "是否主推:0否,1是"),
-        @ApiImplicitParam(required = false, name = "commodityType", value = "商品属性:1产品,2仪器"),
-        @ApiImplicitParam(required = false, name = "bigTypeId", value = "一级分类Id"),
-        @ApiImplicitParam(required = false, name = "smallTypeId", value = "二级分类Id"),
-        @ApiImplicitParam(required = false, name = "tinyTypeId", value = "三级级分类Id"),
-        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
-        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+            @ApiImplicitParam(required = false, name = "productCode", value = "货号"),
+            @ApiImplicitParam(required = false, name = "validFlag", value = "状态:0逻辑删除,1待审核,2已上架,3已下架,8审核未通过,9已隐身,10已冻结"),
+            @ApiImplicitParam(required = false, name = "featuredFlag", value = "是否主推:0否,1是"),
+            @ApiImplicitParam(required = false, name = "commodityType", value = "商品属性:1产品,2仪器"),
+            @ApiImplicitParam(required = false, name = "bigTypeId", value = "一级分类Id"),
+            @ApiImplicitParam(required = false, name = "smallTypeId", value = "二级分类Id"),
+            @ApiImplicitParam(required = false, name = "tinyTypeId", value = "三级级分类Id"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
     })
     @GetMapping("/product/list")
-    public ResponseJson<Map<String, Object>> getShopProducts(Integer showFlag,Integer shopId, String name, String productCode,
-                                                             Integer validFlag, Integer featuredFlag, Integer commodityType, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId,Integer newvalidFlag,
+    public ResponseJson<Map<String, Object>> getShopProducts(Integer showFlag, Integer shopId, String name, String productCode,
+                                                             Integer validFlag, Integer featuredFlag, Integer commodityType, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, Integer newvalidFlag,
                                                              @RequestParam(value = "pageNum", defaultValue = "1") int pageNum,
                                                              @RequestParam(value = "pageSize", defaultValue = "20") int pageSize) {
-        return shopService.getShopProducts(showFlag,shopId, name, productCode, validFlag, featuredFlag, commodityType, bigTypeId, smallTypeId, tinyTypeId,newvalidFlag, pageNum, pageSize);
+        return shopService.getShopProducts(showFlag, shopId, name, productCode, validFlag, featuredFlag, commodityType, bigTypeId, smallTypeId, tinyTypeId, newvalidFlag, pageNum, pageSize);
     }
 
     /**
@@ -80,16 +80,12 @@ public class ProductShopApi {
      *                   brandId	    品牌id
      *                   brandName	    品牌名称
      *                   commodityType	商品属性:1产品,2仪器
-     *                   costPrice	    成本价
      *                   detailInfo	    商品详情信息
      *                   includedTax	是否含税:0不含税,1含税,2未知
      *                   invoiceType	发票类型
      *                   machineType	械字号类型
-     *                   minBuyNumber	最小购买量
      *                   name	        商品名称
-     *                   normalPrice	市场价
      *                   orderInfo	    订购方案
-     *                   price	        机构价格
      *                   productCode	商品货号
      *                   productType	商品类型:0其它,1妆字号,2械字号
      *                   provinceIds	指定的销售区域
@@ -99,16 +95,24 @@ public class ProductShopApi {
      *                   shopId	         供应商id
      *                   smallTypeId	 二级分类id
      *                   step	         购买数量
-     *                   stock	         库存
      *                   tags	         商品标签,逗号隔开
      *                   taxPoint	     开票税点
      *                   tinyTypeId	     三级分类id
-     *                   unit	         包装规格
+     *
+     *                   skus[
+     *                     {id              skuId
+     *                      minBuyNumber	最小购买量
+     *                      costPrice	    成本价
+     *                      stock	        库存
+     *                      price	        机构价格
+     *                      normalPrice	    市场价
+     *                      unit            包装规格},{sku}
+     *                      ]
      *                   }
      */
     @ApiOperation("供应商-发布商品(旧:/supplier/releaseProduct)")
     @PostMapping("/product/release")
-    public ResponseJson releaseProduct(ProductDto productDto){
+    public ResponseJson releaseProduct(ProductDto productDto) {
         return shopService.releaseProduct(productDto);
     }
 
@@ -129,8 +133,8 @@ public class ProductShopApi {
      */
     @ApiOperation("供应商-商品编辑-品牌联想(旧:/supplier/brandAssociation)")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = true, name = "userId", value = "用户Id"),
-        @ApiImplicitParam(required = true, name = "name", value = "关键词")
+            @ApiImplicitParam(required = true, name = "userId", value = "用户Id"),
+            @ApiImplicitParam(required = true, name = "name", value = "关键词")
     })
     @GetMapping("/brand/select")
     public ResponseJson<List<BrandVo>> brandAssociation(Integer userId, String name) {
@@ -156,7 +160,7 @@ public class ProductShopApi {
      *                 userId      添加用户ID,后台则为后台用户ID,供应商则为供应商用户ID
      *                 logo        品牌logo
      *                 description 品牌描述
-     * }
+     *                 }
      */
     @ApiOperation("供应商-提交新品牌(旧:/supplier/addBrand)")
     @PostMapping("/brand/add")
@@ -169,11 +173,11 @@ public class ProductShopApi {
      */
     @ApiOperation("供应商-品牌管理(旧:/supplier/brandManagement)")
     @ApiImplicitParams({
-        @ApiImplicitParam(required = false, name = "name", value = "品牌名称"),
-        @ApiImplicitParam(required = false, name = "status", value = "品牌状态 0:待审核,1:审核通过,2:审核失败"),
-        @ApiImplicitParam(required = false, name = "userId", value = "用户Id"),
-        @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
-        @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
+            @ApiImplicitParam(required = false, name = "name", value = "品牌名称"),
+            @ApiImplicitParam(required = false, name = "status", value = "品牌状态 0:待审核,1:审核通过,2:审核失败"),
+            @ApiImplicitParam(required = false, name = "userId", value = "用户Id"),
+            @ApiImplicitParam(required = false, name = "pageNum", value = "页码"),
+            @ApiImplicitParam(required = false, name = "pageSize", value = "每页数量")
     })
     @GetMapping("/brand/list")
     public ResponseJson<PaginationVo<BrandVo>> brandManagement(String name, Integer status, Integer userId,

+ 12 - 3
src/main/java/com/caimei365/commodity/mapper/HeheMapper.java

@@ -1,5 +1,7 @@
 package com.caimei365.commodity.mapper;
 
+import com.caimei365.commodity.model.dto.HeHeSku;
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.HeheCollageProductPo;
 import com.caimei365.commodity.model.po.HeheDiscountPricePo;
 import com.caimei365.commodity.model.vo.*;
@@ -24,9 +26,9 @@ public interface HeheMapper {
 
     Integer getActivityIdByProductId(Integer productId);
 
-    HeheCollageProductPo getCollageProduct(Integer productId);
+    HeheCollageProductPo getCollageProduct(Integer skuId);
 
-    List<LadderPriceVo> getActivityLadderList(Integer activityId, Integer productId);
+    List<LadderPriceVo> getActivityLadderList(Integer activityId, Integer skuId);
 
     HeHeDiscountVo getProductDiscount(Integer productId, Integer userId);
 
@@ -34,10 +36,11 @@ public interface HeheMapper {
 
     Integer getPartProductCounponCount(Integer productId);
 
-    HeheDiscountPricePo getDiscountPrice(Integer productId);
+    HeheDiscountPricePo getDiscountPrice(Integer skuId);
 
     /**
      * 查询可领取的优惠券列表
+     *
      * @return
      */
     List<HeheCouponVo> getCouponList(@Param("userId") Integer userId, @Param("productIdArr") String[] productIdArr, @Param("registerTime") Date registerTime, @Param("couponType") Integer couponType);
@@ -56,6 +59,7 @@ public interface HeheMapper {
 
     /**
      * 根据分销者用户id查询活动列表
+     *
      * @param userId
      * @return
      */
@@ -68,7 +72,12 @@ public interface HeheMapper {
 
     /**
      * 查询首页轮播图
+     *
      * @return
      */
     List<HeHeImageVo> getHomeCarousel();
+
+    List<HeHeSku> findHeheSkus(Integer productId);
+
+    List<LadderPriceVo> getActivityLadderListBySkuId(@Param("activityId") Integer activityId, @Param("skuId") Integer skuId);
 }

+ 2 - 0
src/main/java/com/caimei365/commodity/mapper/PageMapper.java

@@ -415,6 +415,8 @@ public interface PageMapper {
 
     String findLink(Integer productId);
 
+    void delSku(Integer skuId);
+
     List<BaikeProductVo> getAuthUserList(BaikeProductVo baikeProductVo);
 
     void upEntryStatusById(Integer id,Integer status,Date publishTime);

+ 28 - 10
src/main/java/com/caimei365/commodity/mapper/PriceMapper.java

@@ -1,9 +1,7 @@
 package com.caimei365.commodity.mapper;
 
-import com.caimei365.commodity.model.vo.ProductSalesVo;
-import com.caimei365.commodity.model.vo.LadderPriceVo;
-import com.caimei365.commodity.model.vo.PriceVo;
-import com.caimei365.commodity.model.vo.TaxVo;
+import com.caimei365.commodity.model.dto.Sku;
+import com.caimei365.commodity.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -30,21 +28,21 @@ public interface PriceMapper {
      */
     List<PriceVo> getListPriceByProductIds(@Param("productIds") List<Integer> productIds);
     /**
-     * 根据商品ID查询阶梯价列表
+     * 根据skuId查询阶梯价列表
      */
-    List<LadderPriceVo> getLadderPricesByProductId(Integer productId);
+    List<LadderPriceVo> getLadderPricesByProductId(Integer skuId);
     /**
      * 获取最低阶梯价(价格最低,阶梯数最大)
      */
-    LadderPriceVo findLowerLadderPrice(Integer productId);
+    LadderPriceVo findLowerLadderPrice(Integer skuId);
     /**
      * 获取最高阶梯价(价格最高,阶梯数最小)
      */
-    LadderPriceVo findMaxLadderPrice(Integer productId);
+    LadderPriceVo findMaxLadderPrice(Integer skuId);
     /**
      * 根据商品ID和用户ID 查询复购价
      */
-    Double getRepurchasePrice(@Param("productId") Integer productId, @Param("userId") Integer userId);
+    Double getRepurchasePrice(@Param("skuId") Integer skuId, @Param("userId") Integer userId);
     /**
      * 根据商品ID含税和发票信息
      */
@@ -76,5 +74,25 @@ public interface PriceMapper {
      */
     void insertProductSalesRecord(Integer productId, Integer sales);
 
-    void newFlag();
+    /**
+     * skus
+     * @param productId
+     * @return
+     */
+    List<Sku> findSkus(Integer productId);
+
+    /**
+     * 查找所有阶梯价中最低价
+     * @param productId
+     * @return
+     */
+    ProductItemVo findLowPrice(Integer productId);
+
+    Integer getSaleOutFlag(Integer productId);
+
+    List<Sku> findSkusOutOfPrice(Integer productId);
+
+    ProductItemVo findLowPriceOfAll(Integer productId);
+
+    ProductItemVo findLowPriceOfPrice(Integer productId);
 }

+ 4 - 0
src/main/java/com/caimei365/commodity/mapper/ShopMapper.java

@@ -1,5 +1,6 @@
 package com.caimei365.commodity.mapper;
 
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.*;
 import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.BrandVo;
@@ -206,4 +207,7 @@ public interface ShopMapper {
      */
     String getShopNameByShopId(Integer shopId);
 
+    void insertSku(Sku s);
+
+    void updateSku(Sku s);
 }

+ 133 - 0
src/main/java/com/caimei365/commodity/model/dto/HeHeSku.java

@@ -0,0 +1,133 @@
+package com.caimei365.commodity.model.dto;
+
+import com.caimei365.commodity.model.po.HeheCollageProductPo;
+import com.caimei365.commodity.model.vo.LadderPriceVo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author zzj
+ */
+@ApiModel("呵呵sku")
+@Data
+public class HeHeSku {
+
+    private Integer productId;
+    /**
+     * 比例成本百分比
+     */
+    @ApiModelProperty("比例成本百分比")
+    private Double costProportional;
+    /**
+     * 成本价选中标志:1固定成本 2比例成
+     */
+    @ApiModelProperty("成本价选中标志")
+    private Integer costCheckFlag;
+
+    @ApiModelProperty("skuId")
+    private Integer skuId;
+    /**
+     * 起订量
+     */
+    @ApiModelProperty("最小购买量")
+    private Integer minBuyNumber;
+    /**
+     * 成本价
+     */
+    @ApiModelProperty("成本价")
+    private BigDecimal costPrice;
+    /**
+     * 库存
+     */
+    @ApiModelProperty("库存")
+    private Integer stock;
+    /**
+     * 机构价格
+     */
+    @ApiModelProperty("机构价格")
+    private BigDecimal price;
+    /**
+     * 市场价
+     */
+    @ApiModelProperty("市场价")
+    private BigDecimal normalPrice;
+    /**
+     * 包装规格
+     */
+    @ApiModelProperty("包装规格")
+    private String unit;
+    /**
+     * 阶梯价格
+     */
+    @ApiModelProperty("活动价")
+    private List<LadderPriceVo> ladderPriceList;
+    /**
+     * 拼团状态:0没有拼团价,1拼团价
+     */
+    @ApiModelProperty("拼团价状态")
+    private Integer collageStatus = 0;
+
+    /**
+     * 限时特价状态:0没有限时特价,1限时特价
+     */
+    @ApiModelProperty("限时特价状态")
+    private Integer discountStatus = 0;
+
+    /**
+     * 券后价对应优惠券id
+     */
+    @ApiModelProperty("券后价对应优惠券id")
+    private Integer couponId;
+
+    /**
+     * 单价未满足优惠条件,显示最小优惠条件的优惠券信息
+     */
+    @ApiModelProperty("优惠券信息")
+    private String couponInfo;
+
+    /**
+     * 限时特价结束时间
+     */
+    @ApiModelProperty("限时特价结束时间")
+    private Date discountEndTime;
+
+    /**
+     * 拼团商品
+     */
+    @ApiModelProperty("拼团商品")
+    private HeheCollageProductPo collageProduct;
+
+    /**
+     * 活动状态:0没有活动,1活动价
+     */
+    @ApiModelProperty("活动价状态")
+    private Integer activeStatus;
+    /**
+     * 优惠券标签状态:0无可用优惠券,1券后价,2优惠券信息
+     */
+    @ApiModelProperty("优惠券标签状态")
+    private Integer couponStatus;
+
+    /**
+     * 券后价
+     */
+    @ApiModelProperty("券后价")
+    private BigDecimal couponPrice = BigDecimal.ZERO;
+
+    /**
+     * 原价券后价
+     */
+    @ApiModelProperty("原价券后价")
+    private BigDecimal normalCouponPrice = BigDecimal.ZERO;
+
+    /**
+     * 商品名称
+     */
+    @ApiModelProperty("商品名称")
+    private String name;
+}

+ 6 - 31
src/main/java/com/caimei365/commodity/model/dto/ProductDto.java

@@ -7,6 +7,7 @@ import lombok.Data;
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 /**
  * Description
@@ -73,36 +74,11 @@ public class ProductDto implements Serializable {
      */
     @ApiModelProperty("商品标签,逗号隔开")
     private String tags;
-    /**
-     * 包装规格
-     */
-    @ApiModelProperty("包装规格")
-    private String unit;
-    /**
-     * 机构价格
-     */
-    @ApiModelProperty("机构价格")
-    private Double price;
-    /**
-     * 市场价
-     */
-    @ApiModelProperty("市场价")
-    private Double normalPrice;
     /**
      * 是否含税:0不含税,1含税,2未知
      */
     @ApiModelProperty("是否含税:0不含税,1含税,2未知")
     private Integer includedTax;
-    /**
-     * 最小购买量
-     */
-    @ApiModelProperty("最小购买量")
-    private Integer minBuyNumber;
-    /**
-     * 库存
-     */
-    @ApiModelProperty("库存")
-    private Integer stock;
     /**
      * 品牌名称
      */
@@ -133,11 +109,6 @@ public class ProductDto implements Serializable {
      */
     @ApiModelProperty("械字号资质证书图")
     private String qualificationImg;
-    /**
-     * 成本价
-     */
-    @ApiModelProperty("成本价")
-    private Double costPrice;
     /**
      * 发票类型(基于是否含税基础)   1增值税票,2普通票, 3不能开票
      */
@@ -230,5 +201,9 @@ public class ProductDto implements Serializable {
     @ApiModelProperty("证书有效链接")
     public String qualificationLink;
 
-
+    /**
+     * 库存skus
+     */
+    @ApiModelProperty("sku参数json")
+    public String skus;
 }

+ 91 - 0
src/main/java/com/caimei365/commodity/model/dto/Sku.java

@@ -0,0 +1,91 @@
+package com.caimei365.commodity.model.dto;
+
+import com.caimei365.commodity.model.vo.LadderPriceVo;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.util.List;
+
+/**
+ * @author zzj
+ */
+@ApiModel("商品sku")
+@Data
+public class Sku {
+
+    private Integer productId;
+    /**
+     * 划线价格
+     */
+    @ApiModelProperty("划线价格")
+    private Double originalPrice;
+    /**
+     * 最大购买量
+     */
+    @ApiModelProperty("最大购买量")
+    private Integer maxBuyNumber;
+    /**
+     * 计算后价格等级
+     */
+    @ApiModelProperty("计算后价格等级")
+    private Integer priceGrade;
+    /**
+     * 是否复购 0否 1是
+     */
+    @ApiModelProperty("是否复购")
+    private Integer repurchaseFlag;
+    /**
+     * 启用阶梯价格标识 0否 1是
+     */
+    @ApiModelProperty("阶梯价标志")
+    private Integer ladderPriceFlag;
+    /**
+     * 比例成本百分比
+     */
+    @ApiModelProperty("比例成本百分比")
+    private Double costProportional;
+    /**
+     * 成本价选中标志:1固定成本 2比例成
+     */
+    @ApiModelProperty("成本价选中标志")
+    private Integer costCheckFlag;
+
+    @ApiModelProperty("skuId")
+    private Integer skuId;
+    /**
+     * 起订量
+     */
+    @ApiModelProperty("最小购买量")
+    private Integer minBuyNumber;
+    /**
+     * 成本价
+     */
+    @ApiModelProperty("成本价")
+    private Double costPrice;
+    /**
+     * 库存
+     */
+    @ApiModelProperty("库存")
+    private Integer stock;
+    /**
+     * 机构价格
+     */
+    @ApiModelProperty("机构价格")
+    private Double price;
+    /**
+     * 市场价
+     */
+    @ApiModelProperty("市场价")
+    private Double normalPrice;
+    /**
+     * 包装规格
+     */
+    @ApiModelProperty("包装规格")
+    private String unit;
+    /**
+     * 阶梯价格
+     */
+    @ApiModelProperty("阶梯价格")
+    private List<LadderPriceVo> ladderPriceList;
+}

+ 2 - 0
src/main/java/com/caimei365/commodity/model/po/HeheCollageProductPo.java

@@ -13,6 +13,8 @@ import java.math.BigDecimal;
  */
 @Data
 public class HeheCollageProductPo implements Serializable {
+
+    private Integer skuId;
     /**
      * 呵呵商城商品id
      */

+ 7 - 24
src/main/java/com/caimei365/commodity/model/po/ProductPo.java

@@ -1,10 +1,13 @@
 package com.caimei365.commodity.model.po;
 
+import com.caimei365.commodity.model.dto.Sku;
+import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
 import java.util.Date;
+import java.util.List;
 
 /**
  * Description
@@ -27,10 +30,6 @@ public class ProductPo implements Serializable {
      * 商品名称
      */
     private String name;
-    /**
-     * 商品价格
-     */
-    private Double price;
     /**
      * 价格可见度:0公开价格 1不公开价格 2仅对会员机构公开 price1TextFlag
      */
@@ -39,10 +38,6 @@ public class ProductPo implements Serializable {
      * 商品货号
      */
     private String productCode;
-    /**
-     * 库存
-     */
-    private Integer stock;
     /**
      * 内部商品名称
      */
@@ -59,10 +54,6 @@ public class ProductPo implements Serializable {
      * 指定的销售区域
      */
     private String provinceIds;
-    /**
-     * 市场价
-     */
-    private Double normalPrice;
     /**
      * 主图
      */
@@ -99,10 +90,6 @@ public class ProductPo implements Serializable {
      * 销量
      */
     private Integer sellNumber;
-    /**
-     * 成本价
-     */
-    private Double costPrice;
     /**
      * 成本价选中标志:1固定成本 2比例成
      */
@@ -175,14 +162,6 @@ public class ProductPo implements Serializable {
      * 商品标签用英文逗号隔开,中文逗号或其它一律不作切割
      */
     private String tags;
-    /**
-     * 包装规格
-     */
-    private String unit;
-    /**
-     * 最小购买量
-     */
-    private Integer minBuyNumber;
     /**
      * 服务起订量
      */
@@ -287,4 +266,8 @@ public class ProductPo implements Serializable {
      */
     public String qualificationLink;
 
+    /**
+     * 库存skus
+     */
+    public List<Sku> skus;
 }

+ 8 - 0
src/main/java/com/caimei365/commodity/model/vo/HeheProductVo.java

@@ -1,5 +1,7 @@
 package com.caimei365.commodity.model.vo;
 
+import com.caimei365.commodity.model.dto.HeHeSku;
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.HeheCollageProductPo;
 import com.caimei365.commodity.model.po.ProductDetailInfoPo;
 import com.caimei365.commodity.model.po.ProductParameterPo;
@@ -18,6 +20,12 @@ import java.util.List;
  */
 @Data
 public class HeheProductVo implements Serializable {
+
+    private List<HeHeSku> skus;
+    /**
+     * 展示的skuId
+     */
+    private Integer skuId;
     /**
      * 对应采美商品id
      */

+ 7 - 0
src/main/java/com/caimei365/commodity/model/vo/LadderPriceVo.java

@@ -13,7 +13,14 @@ import java.io.Serializable;
 @Data
 public class LadderPriceVo implements Serializable {
     private static final long serialVersionUID = 1L;
+
+    private Integer stock;
+
+    private String unit;
+
     private Integer id;
+
+    private Integer skuId;
     /**
      * 商品id
      */

+ 27 - 37
src/main/java/com/caimei365/commodity/model/vo/PriceVo.java

@@ -1,9 +1,11 @@
 package com.caimei365.commodity.model.vo;
 
+import com.caimei365.commodity.model.dto.Sku;
 import lombok.Data;
 
 import java.io.Serializable;
 import java.math.BigDecimal;
+import java.util.List;
 
 /**
  * 商品价格
@@ -14,62 +16,50 @@ import java.math.BigDecimal;
 @Data
 public class PriceVo implements Serializable {
     private static final long serialVersionUID = 1L;
-    /**
-     * 促销活动可见性 0所有人,1仅对机构
-     */
-    private Integer seen;
-    /**
-     * 商品productID
-     */
-    private Integer productId;
-    /**
-     * 供应商ID
-     */
-    private Integer shopId;
-    /**
-     * 价格(计算后)
-     */
-    private Double price;
-    /**
-     * 划线价格
-     */
+
     private Double originalPrice;
+
+    private Integer stock;
+
+    private String unit;
+
+    private List<Sku> skus;
     /**
-     * 最小购买量
+     * 展示的最低市场价
      */
-    private Integer minBuyNumber;
+    private Double normalPrice;
     /**
-     * 最大购买量
+     * 展示的sku的skuId
      */
-    private Integer maxBuyNumber;
+    private Integer skuId;
     /**
-     * 是否公开机构价: 0公开价格,1不公开价格,2仅对会员机构公开,3仅对医美机构公开
+     * 展示的阶梯价格标识 0否 1是
      */
-    private Integer priceFlag;
+    private Integer ladderPriceFlag;
     /**
-     * 是否复购 0否 1是
+     * 默认展示的最低起订量
      */
-    private Integer repurchaseFlag;
+    private Integer minBuyNumber;
     /**
-     * 阶梯价标志
+     * 默认展示的最低价格
      */
-    private Integer ladderPriceFlag;
+    private Double price;
     /**
-     * 市场价
+     * 促销活动可见性 0所有人,1仅对机构
      */
-    private Double normalPrice;
+    private Integer seen;
     /**
-     * 成本价
+     * 商品productID
      */
-    private Double costPrice;
+    private Integer productId;
     /**
-     * 比例成本百分比
+     * 供应商ID
      */
-    private Double costProportional;
+    private Integer shopId;
     /**
-     * 成本价选中标志:1固定成本 2比例成
+     * 是否公开机构价: 0公开价格,1不公开价格,2仅对会员机构公开,3仅对医美机构公开
      */
-    private Integer costCheckFlag;
+    private Integer priceFlag;
     /**
      * 用户身份: 2-会员机构, 4-普通机构
      */

+ 29 - 29
src/main/java/com/caimei365/commodity/model/vo/ProductDetailVo.java

@@ -1,5 +1,6 @@
 package com.caimei365.commodity.model.vo;
 
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.ProductDetailInfoPo;
 import com.caimei365.commodity.model.po.ProductImagePo;
 import com.caimei365.commodity.model.po.ProductParameterPo;
@@ -23,6 +24,33 @@ import java.util.List;
 public class ProductDetailVo implements Serializable {
     private static final long serialVersionUID = 1L;
 
+    private Integer minBuyNumber;
+
+    private Integer stock;
+    /**
+     * 售罄标记 0否1是
+     */
+    private Integer saleOutFlag;
+    /**
+     * 展示的最低市场价
+     */
+    private Double normalPrice;
+    /**
+     * 展示的sku的skuId
+     */
+    private Integer skuId;
+    /**
+     * skus
+     */
+    private List<Sku> skus;
+    /**
+     * 展示的最低价的规格
+     */
+    private String unit;
+    /**
+     * 默认显示的最低价
+     */
+    private Double price;
     /**
      * 用户收藏标记(1收藏,0未收藏)
      */
@@ -87,18 +115,6 @@ public class ProductDetailVo implements Serializable {
      * 商品货号
      */
     private String productCode;
-    /**
-     * 包装规格
-     */
-    private String unit;
-    /**
-     * 市场价
-     */
-    private Double normalPrice;
-    /**
-     * 商品价格
-     */
-    private Double price;
     /**
      * 价格可见度:0公开价格 1不公开价格 2仅对会员机构公开 price1TextFlag
      */
@@ -111,10 +127,6 @@ public class ProductDetailVo implements Serializable {
      * 阶梯价格列表
      */
     private List<LadderPriceVo> ladderPriceList;
-    /**
-     * 成本价
-     */
-    private Double costPrice;
     /**
      * 商品可见度:(3:所有人可见,2:普通机构可见,1:会员机构可见)
      */
@@ -139,18 +151,10 @@ public class ProductDetailVo implements Serializable {
      * 供应商税率:增值专用发票默认13%,增值税普通发票6%取值范围[0-100]
      */
     private Double supplierTaxPoint;
-    /**
-     * 最小购买量
-     */
-    private Integer minBuyNumber;
     /**
      * 服务起订量
      */
     private Integer serviceNumber;
-    /**
-     * 库存
-     */
-    private Integer stock;
     /**
      * 商品的类别:1正常商品(默认),2二手商品
      */
@@ -289,10 +293,6 @@ public class ProductDetailVo implements Serializable {
      * 用户身份: 2-会员机构, 4-普通机构
      */
     private Integer userIdentity;
-    /**
-     * 最大购买量
-     */
-    private Integer maxBuyNumber;
     /**
      * 是否复购 0否 1是
      */
@@ -347,7 +347,7 @@ public class ProductDetailVo implements Serializable {
      *产品名称
      */
     public String productName;
-    /*
+    /**
      *证书有效日期
      */
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm", timezone = "GMT+8")

+ 14 - 6
src/main/java/com/caimei365/commodity/model/vo/ProductFormVo.java

@@ -1,5 +1,6 @@
 package com.caimei365.commodity.model.vo;
 
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.ProductDetailInfoPo;
 import com.caimei365.commodity.model.po.ProductImagePo;
 import com.caimei365.commodity.model.po.ProductParameterPo;
@@ -261,29 +262,36 @@ public class ProductFormVo implements Serializable {
      */
     private BigDecimal trainingFee;
 
-    //新品参与状态1.参与2.未参与
+    /**
+     * 新品参与状态1.参与2.未参与
+     */
     private Integer newProductType;
 
-//新品审核状态 1,审核通过2,审核未通过3,待审核
+    /**
+     * 新品审核状态 1,审核通过2,审核未通过3,待审核
+     */
     private Integer newvalidFlag;
     /**
      * 证书编号
+     *
      * @return
      */
     public String qualificationNo;
 
     /**
-     *产品名称
+     * 产品名称
      */
     public String productName;
-    /*
-     *证书有效日期
+    /**
+     * 证书有效日期
      */
     @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
     public Date qualificationTime;
 
     /**
-     *证书有效链接
+     * 证书有效链接
      */
     public String qualificationLink;
+
+    public List<Sku> skus;
 }

+ 43 - 116
src/main/java/com/caimei365/commodity/model/vo/ProductItemVo.java

@@ -1,5 +1,6 @@
 package com.caimei365.commodity.model.vo;
 
+import com.caimei365.commodity.model.dto.Sku;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -15,10 +16,52 @@ import java.util.List;
 @Data
 public class ProductItemVo implements Serializable {
     private static final long serialVersionUID = 1L;
+
+    private Integer stock;
+    /**
+     * 展示的sku的价格等级
+     */
+    private Integer priceGrade;
+    /**
+     * 组合商品列表默认的起订量
+     */
+    private Integer minBuyNumber;
+    /**
+     * 展示的sku的skuId
+     */
+    private Integer skuId;
+    /**
+     * skus
+     */
+    private List<Sku> skus;
+    /**
+     * 赠品skuId
+     */
+    private Integer giftSkuId;
+    /**
+     * 再次购买中的成本
+     */
+    private Double costPrice;
+    /**
+     * 再次购买中的成本标记
+     */
+    private Integer costCheckFlag;
     /**
      * itemId
      */
     private Integer id;
+    /**
+     * 展示的最低价的规格
+     */
+    private String unit;
+    /**
+     * 展示的最低价
+     */
+    private Double price;
+    /**
+     * 默认的最低市场价(列表显示)
+     */
+    private Double normalPrice;
     /**
      * 商品productID
      */
@@ -37,26 +80,14 @@ public class ProductItemVo implements Serializable {
      * 品牌
      */
     private String brandName;
-    /**
-     * 包装规格
-     */
-    private String unit;
     /**
      * 商品货号
      */
     private String code;
-    /**
-     * 机构价
-     */
-    private Double price;
     /**
      * 是否公开机构价 0公开价格 1不公开价格
      */
     private Integer priceFlag;
-    /**
-     * 计算后价格等级
-     */
-    private Integer priceGrade;
     /**
      * 商品可见度:3:所有人可见,2:普通机构可见,1:会员机构可见,4:仅医美机构可见
      */
@@ -77,15 +108,6 @@ public class ProductItemVo implements Serializable {
      * 商品原价
      */
     private Double originalPrice;
-    /**
-     * 成本价选中标志:1固定成本 2比例成
-     */
-    private Integer costCheckFlag;
-
-    /**
-     * 固定成本价
-     */
-    private Double costPrice;
     /**
      * 购买数量
      */
@@ -98,10 +120,6 @@ public class ProductItemVo implements Serializable {
      * 增量
      */
     private Integer step;
-    /**
-     * 起订量
-     */
-    private Integer minBuyNumber;
     /**
      * 最大购买量
      */
@@ -114,22 +132,10 @@ public class ProductItemVo implements Serializable {
      * 活动状态:1有效,0失效
      */
     private Integer actStatus;
-    /**
-     * 启用阶梯价格标识:1是,0否
-     */
-    private Integer ladderPriceFlag;
-    /**
-     * 库存
-     */
-    private Integer stock;
     /**
      * 购物车失效状态:0有效,1后台删除的,2冻结的,3下架,4售罄 >7库存不足,5价格仅会员可见,6未公开价格
      */
     private Integer status;
-    /**
-     * 阶梯价
-     */
-    List<LadderPriceVo> ladderPrices;
     /**
      * 促销活动
      */
@@ -174,10 +180,6 @@ public class ProductItemVo implements Serializable {
      * 内部商品名称
      */
     private String aliasName;
-    /**
-     * 市场价
-     */
-    private Double normalPrice;
     /**
      * 所在分类名称
      */
@@ -214,10 +216,6 @@ public class ProductItemVo implements Serializable {
      * 再次购买价格
      */
     private Double discountPrice;
-    /**
-     * 是否复购 0否 1是
-     */
-    private Integer repurchaseFlag;
     /**
      * 判断是否勾选(前端使用)
      */
@@ -280,75 +278,4 @@ public class ProductItemVo implements Serializable {
      * 楼层相关商品图片3
      */
     private List<FloorImageVo> floorImageList3;
-
-    @Override
-    public String toString() {
-        return "ProductItemVo{" +
-                "id=" + id +
-                ", productId=" + productId +
-                ", brandID=" + brandID +
-                ", name='" + name + '\'' +
-                ", image='" + image + '\'' +
-                ", brandName='" + brandName + '\'' +
-                ", unit='" + unit + '\'' +
-                ", code='" + code + '\'' +
-                ", price=" + price +
-                ", priceFlag=" + priceFlag +
-                ", priceGrade=" + priceGrade +
-                ", visibility='" + visibility + '\'' +
-                ", shopId=" + shopId +
-                ", keyword='" + keyword + '\'' +
-                ", originalPrice=" + originalPrice +
-                ", costCheckFlag=" + costCheckFlag +
-                ", costPrice=" + costPrice +
-                ", number=" + number +
-                ", productType=" + productType +
-                ", step=" + step +
-                ", minBuyNumber=" + minBuyNumber +
-                ", maxBuyNumber=" + maxBuyNumber +
-                ", validFlag=" + validFlag +
-                ", actStatus=" + actStatus +
-                ", ladderPriceFlag=" + ladderPriceFlag +
-                ", stock=" + stock +
-                ", status=" + status +
-                ", ladderPrices=" + ladderPrices +
-                ", promotions=" + promotions +
-                ", productCategory=" + productCategory +
-                ", productCode='" + productCode + '\'' +
-                ", productsChecked=" + productsChecked +
-                ", repurchasePriceState=" + repurchasePriceState +
-                ", includedTax='" + includedTax + '\'' +
-                ", invoiceType='" + invoiceType + '\'' +
-                ", taxRate=" + taxRate +
-                ", userIdentity=" + userIdentity +
-                ", detailTalkFlag=" + detailTalkFlag +
-                ", aliasName='" + aliasName + '\'' +
-                ", normalPrice=" + normalPrice +
-                ", typeName='" + typeName + '\'' +
-                ", featuredFlag=" + featuredFlag +
-                ", commodityType=" + commodityType +
-                ", bigTypeId=" + bigTypeId +
-                ", smallTypeId=" + smallTypeId +
-                ", tinyTypeId=" + tinyTypeId +
-                ", initProductNum=" + initProductNum +
-                ", totalPrice=" + totalPrice +
-                ", discountPrice=" + discountPrice +
-                ", repurchaseFlag=" + repurchaseFlag +
-                ", isChecked=" + isChecked +
-                ", couponsLogo=" + couponsLogo +
-                ", svipProductFlag=" + svipProductFlag +
-                ", svipPriceTag='" + svipPriceTag + '\'' +
-                ", announType=" + announType +
-                ", newvalidFlag=" + newvalidFlag +
-                ", showFlag=" + showFlag +
-                ", showTime='" + showTime + '\'' +
-                ", recommend=" + recommend +
-                ", newshowTime='" + newshowTime + '\'' +
-                ", newProductType=" + newProductType +
-                ", BrandName='" + BrandName + '\'' +
-                ", floorImageList=" + floorImageList +
-                ", floorImageList2=" + floorImageList2 +
-                ", floorImageList3=" + floorImageList3 +
-                '}';
-    }
 }

+ 10 - 0
src/main/java/com/caimei365/commodity/model/vo/UserLikeProductVo.java

@@ -0,0 +1,10 @@
+package com.caimei365.commodity.model.vo;
+
+import java.io.Serializable;
+
+/**
+ * @author zzj
+ */
+public class UserLikeProductVo implements Serializable {
+    private static final long serialVersionUID = 1L;
+}

+ 2 - 0
src/main/java/com/caimei365/commodity/service/PageService.java

@@ -241,6 +241,8 @@ public interface PageService {
      * @param floorContent
      */
     void setFloorLinkType(FloorContentVo floorContent);
+
+    ResponseJson delSku(Integer skuId);
  //--------------------------------- 1.3.3采美百科词条----------------------------------------------------------------------------------------
     /**
      * 获取供应商词条信息

+ 2 - 8
src/main/java/com/caimei365/commodity/service/impl/CouponServiceImpl.java

@@ -125,7 +125,7 @@ public class CouponServiceImpl implements CouponService {
         List<ProductItemVo> productList = couponMapper.findCouponProduct(couponId, source, identity);
         productList.forEach(p -> {
             p.setCouponsLogo(true);
-            priceUtilService.setProductDetails(userId, p);
+            priceUtilService.setProductDetails(userId, p, 0);
         });
         PageInfo<ProductItemVo> pageInfo = new PageInfo<>(productList);
         map.put("coupon", coupon);
@@ -167,12 +167,6 @@ public class CouponServiceImpl implements CouponService {
     }
 
 
-
-
-
-
-
-
     @Transactional(rollbackFor = Exception.class)
     @Override
     public ResponseJson<CouponVo> redeemCoupons(RedeemCouponsDto redeemCouponsDto) {
@@ -374,7 +368,7 @@ public class CouponServiceImpl implements CouponService {
                         // 调用 ToolsFeign 发送短信
                         String jsonStr = toolsFeign.getSendSms(mobile, content);
                         JSONObject parseObject = JSONObject.parseObject(jsonStr);
-                        if (0 == parseObject.getInteger("code")){
+                        if (0 == parseObject.getInteger("code")) {
                             returnValue.set(true);
                         }
                     }

+ 55 - 57
src/main/java/com/caimei365/commodity/service/impl/HeheServiceImpl.java

@@ -2,6 +2,8 @@ package com.caimei365.commodity.service.impl;
 
 import com.caimei365.commodity.mapper.*;
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.dto.HeHeSku;
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.*;
 import com.caimei365.commodity.model.vo.*;
 import com.caimei365.commodity.service.HeheService;
@@ -12,6 +14,7 @@ import com.caimei365.commodity.utils.MathUtil;
 import com.github.pagehelper.PageHelper;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang.StringUtils;
+import org.aspectj.weaver.ast.Var;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
@@ -20,7 +23,6 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.*;
 
-import static com.alibaba.fastjson.JSON.parseArray;
 
 /**
  * Description
@@ -43,8 +45,6 @@ public class HeheServiceImpl implements HeheService {
     private ShopMapper shopMapper;
     @Resource
     private SecondHandMapper secondHandMapper;
-    @Autowired
-    private PageService pageService;
 
 
     @Override
@@ -169,23 +169,6 @@ public class HeheServiceImpl implements HeheService {
         //相关参数
         List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
         product.setParametersList(parametersList);
-        // 商城活动id
-        Integer activityId = heheMapper.getActivityIdByProductId(product.getProductId());
-        //税费
-        boolean addTaxFlag = ("0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType())));
-        if (activityId != null && activityId > 0) {
-            //活动阶梯
-            List<LadderPriceVo> ladderList = heheMapper.getActivityLadderList(activityId, product.getProductId());
-            if (addTaxFlag && null != ladderList && ladderList.size() > 0) {
-                ladderList.forEach(ladder->{
-                    BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
-                    BigDecimal price = MathUtil.add(ladder.getBuyPrice(), addedValueTax);
-                    ladder.setBuyPrice(price.doubleValue());
-                });
-            }
-            // 设置阶梯列表
-            product.setLadderList(ladderList);
-        }
         setProductInfo(product, userId);
         return ResponseJson.success(product);
     }
@@ -198,57 +181,81 @@ public class HeheServiceImpl implements HeheService {
 
     private void setProductInfo(HeheProductVo product, Integer userId) {
         product.setMainImage(ImageUtils.getImageURL("product", product.getMainImage(), 0, domain));
+        //设置sku
+        List<HeHeSku> heheSkus = heheMapper.findHeheSkus(product.getProductId());
+        heheSkus.forEach(s -> setProductInfoBySku(product, userId, s));
+        //选最低价作为展示
+        heheSkus.sort(Comparator.comparing(HeHeSku::getPrice));
+        //product设值
+        product.setSkus(heheSkus);
+        HeHeSku heHeSku = heheSkus.get(0);
+        product.setPrice(heHeSku.getPrice());
+        product.setSkuId(heHeSku.getSkuId());
+        product.setActiveStatus(null != heHeSku.getActiveStatus() ? heHeSku.getActiveStatus() : null);
+        product.setCollageStatus(null != heHeSku.getCollageStatus() ? heHeSku.getCollageStatus() : null);
+        product.setCollageProduct(null != heHeSku.getCollageProduct() ? heHeSku.getCollageProduct() : null);
+        product.setDiscountStatus(null != heHeSku.getDiscountStatus() ? heHeSku.getDiscountStatus() : null);
+        product.setDiscountEndTime(null != heHeSku.getDiscountEndTime() ? heHeSku.getDiscountEndTime() : null);
+        product.setCouponStatus(null != heHeSku.getCouponStatus() ? heHeSku.getCouponStatus() : null);
+        product.setCouponPrice(null != heHeSku.getCouponPrice() ? heHeSku.getCouponPrice() : null);
+        product.setNormalPrice(null != heHeSku.getNormalPrice() ? heHeSku.getNormalPrice() : null);
+        product.setNormalCouponPrice(null != heHeSku.getNormalCouponPrice() ? heHeSku.getNormalCouponPrice() : null);
+        product.setCouponId(null != heHeSku.getCouponId() ? heHeSku.getCouponId() : null);
+        product.setCouponInfo(null != heHeSku.getCouponInfo() ? heHeSku.getCouponInfo() : null);
+    }
+
+    private void setProductInfoBySku(HeheProductVo product, Integer userId, HeHeSku sku) {
         // 活动id
         Integer activityId = heheMapper.getActivityIdByProductId(product.getProductId());
         // 拼团商品
-        HeheCollageProductPo collageProduct = heheMapper.getCollageProduct(product.getProductId());
+        HeheCollageProductPo collageProduct = heheMapper.getCollageProduct(sku.getSkuId());
         // 限时特价
-        HeheDiscountPricePo discountPrice = heheMapper.getDiscountPrice(product.getProductId());
+        HeheDiscountPricePo discountPrice = heheMapper.getDiscountPrice(sku.getSkuId());
         // 内部优惠折扣
         HeHeDiscountVo discount = heheMapper.getProductDiscount(product.getProductId(), userId);
         if (activityId != null && activityId > 0) {
-            product.setActiveStatus(1);
+            sku.setActiveStatus(1);
             //活动阶梯
-            List<LadderPriceVo> ladderList = heheMapper.getActivityLadderList(activityId, product.getProductId());
+            List<LadderPriceVo> ladderList = heheMapper.getActivityLadderList(activityId, sku.getSkuId());
             if (ladderList != null && ladderList.size() > 0) {
                 LadderPriceVo ladder = ladderList.get(0);
                 // 没有起订量概念,默认显示购买1个商品的价格,若第一阶梯为一个商品,则取第一阶梯价格
-                product.setPrice(1 == ladder.getBuyNum() ? new BigDecimal(ladder.getBuyPrice()) : product.getPrice());
+                sku.setPrice(1 == ladder.getBuyNum() ? new BigDecimal(ladder.getBuyPrice()) : product.getPrice());
             }
         } else if (collageProduct != null) {
             // 拼团价
-            product.setPrice(collageProduct.getPrice());
-            product.setCollageStatus(1);
-            product.setCollageProduct(collageProduct);
+            sku.setPrice(collageProduct.getPrice());
+            sku.setCollageStatus(1);
+            sku.setCollageProduct(collageProduct);
         } else if (discountPrice != null) {
             // 限时特价
-            product.setPrice(discountPrice.getDiscountPrice());
-            product.setDiscountStatus(1);
-            product.setDiscountEndTime(discountPrice.getOfflineTime());
+            sku.setPrice(discountPrice.getDiscountPrice());
+            sku.setDiscountStatus(1);
+            sku.setDiscountEndTime(discountPrice.getOfflineTime());
         } else if (discount != null) {
             BigDecimal price = product.getPrice();
             // 折扣价
             BigDecimal disPrice = discount.getDiscountPrice();
             // 折扣率
             Integer dis = discount.getDiscount();
-            if (null != disPrice && disPrice.compareTo(BigDecimal.ZERO)>0) {
+            if (null != disPrice && disPrice.compareTo(BigDecimal.ZERO) > 0) {
                 price = disPrice;
             } else if (null != dis && dis > 0) {
                 price = MathUtil.div(MathUtil.mul(product.getPrice(), dis), 100);
             }
-            product.setPrice(price);
+            sku.setPrice(price);
         }
         //税费
         boolean addTaxFlag = ("0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType())));
         if (addTaxFlag) {
             // 售价税费
-            BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
-            BigDecimal price = MathUtil.add(product.getPrice(), addedValueTax);
-            product.setPrice(price);
+            BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(sku.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
+            BigDecimal price = MathUtil.add(sku.getPrice(), addedValueTax);
+            sku.setPrice(price);
             // 原价税费
-            addedValueTax = MathUtil.div(MathUtil.mul(product.getNormalPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
-            price = MathUtil.add(product.getNormalPrice(), addedValueTax);
-            product.setNormalPrice(price);
+            addedValueTax = MathUtil.div(MathUtil.mul(sku.getNormalPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
+            price = MathUtil.add(sku.getNormalPrice(), addedValueTax);
+            sku.setNormalPrice(price);
         }
         // 查询用户的注册时间
         Date registerTime = heheMapper.getUserRegisterTime(userId);
@@ -267,8 +274,8 @@ public class HeheServiceImpl implements HeheService {
         List<HeheCouponVo> unableCouponList = new ArrayList<>();
         if (couponList.size() > 0) {
             // 有可用优惠券
-            couponList.forEach(coupon->{
-                if (1 == coupon.getNoThresholdFlag() || MathUtil.compare(product.getPrice(), coupon.getTouchPrice()) >= 0) {
+            couponList.forEach(coupon -> {
+                if (1 == coupon.getNoThresholdFlag() || MathUtil.compare(sku.getPrice(), coupon.getTouchPrice()) >= 0) {
                     ableCouponList.add(coupon);
                 } else {
                     unableCouponList.add(coupon);
@@ -279,36 +286,26 @@ public class HeheServiceImpl implements HeheService {
                 ableCouponList.sort((o1, o2) -> o2.getCouponAmount().compareTo(o1.getCouponAmount()));
                 HeheCouponVo biggestCoupon = ableCouponList.get(0);
                 // 现价-最大优惠金额=券后价
-                product.setCouponPrice(MathUtil.sub(product.getPrice(), biggestCoupon.getCouponAmount()));
+                sku.setCouponPrice(MathUtil.sub(sku.getPrice(), biggestCoupon.getCouponAmount()));
                 // 原价-最大优惠金额=原价券后价
-                product.setNormalCouponPrice(MathUtil.sub(product.getNormalPrice(), biggestCoupon.getCouponAmount()));
+                sku.setNormalCouponPrice(MathUtil.sub(sku.getNormalPrice(), biggestCoupon.getCouponAmount()));
                 //这张优惠券未领取才返回优惠券id显示领券购买
                 if (null != biggestCoupon.getUseStatus() && 0 == biggestCoupon.getUseStatus()) {
-                    product.setCouponId(biggestCoupon.getCouponId());
+                    sku.setCouponId(biggestCoupon.getCouponId());
                 }
                 // 券后价标签
-                product.setCouponStatus(1);
+                sku.setCouponStatus(1);
             } else {
                 // 根据优惠条件排序,条件小的排前面
                 unableCouponList.sort(Comparator.comparing(HeheCouponVo::getTouchPrice));
                 // 优惠券信息
-                product.setCouponStatus(2);
+                sku.setCouponStatus(2);
                 HeheCouponVo smallestCoupon = unableCouponList.get(0);
-                product.setCouponInfo("券|满" + smallestCoupon.getTouchPrice() + "元减" + smallestCoupon.getCouponAmount());
+                sku.setCouponInfo("券|满" + smallestCoupon.getTouchPrice() + "元减" + smallestCoupon.getCouponAmount());
             }
         }
-        if (1 == product.getActiveStatus() || 1 == product.getCollageStatus() || 1 == product.getDiscountStatus()) {
-            if (1 != product.getCollageStatus() && product.getPrice().compareTo(product.getNormalPrice()) == 0) {
-                // 原价与售价相同,不显示原价
-                product.setNormalPrice(BigDecimal.ZERO);
-            }
-        } else if (product.getCouponPrice().compareTo(BigDecimal.ZERO) == 0) {
-            // 不参与任何活动且未使用优惠券,不显示原价
-            product.setNormalPrice(BigDecimal.ZERO);
-        }
     }
 
-
     /**
      * 设置楼层相关图片的商品信息
      */
@@ -333,6 +330,7 @@ public class HeheServiceImpl implements HeheService {
 
     /**
      * 设置跳转参数
+     *
      * @param floorContent
      */
     private void setFloorLinkType(FloorContentVo floorContent) {

+ 27 - 72
src/main/java/com/caimei365/commodity/service/impl/PageServiceImpl.java

@@ -5,6 +5,7 @@ import com.aliyun.oss.OSSClientBuilder;
 import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.mapper.*;
 import com.caimei365.commodity.model.ResponseJson;
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.*;
 import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.*;
@@ -26,6 +27,7 @@ import javax.annotation.Resource;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.stream.Collectors;
 
 /**
@@ -127,7 +129,7 @@ public class PageServiceImpl implements PageService {
             floor.setFloorImageList(floorImageList);
         }
         map.put("typeSort", typeSort);
-        log.info("仪器页面数据userId================================》"+userId+"====="+contentLabel);
+        log.info("仪器页面数据userId================================》" + userId + "=====" + contentLabel);
         map.put("contentLabel", contentLabel);
         map.put("hotSearchList", hotSearchList);
         map.put("floorList", floorList);
@@ -173,7 +175,7 @@ public class PageServiceImpl implements PageService {
             floors.setFloorContent(floorContent);
 
             List<ProductItemVo> newFloorList = pageMapper.getNewFloorList(null, 1);
-            newFloorList.forEach(n -> priceUtilService.setProductDetails(userId, n));
+            newFloorList.forEach(n -> priceUtilService.setProductDetails(userId, n, 0));
             List<FloorImageVo> floorImageLists = new ArrayList<>();
             for (int i = 0; i < newFloorList.size(); i++) {
                 //优惠券标识
@@ -549,18 +551,11 @@ public class PageServiceImpl implements PageService {
     @Override
     public ResponseJson<ProductDetailVo> getProductDetails(Integer productId, Integer userId) {
         ProductDetailVo product = pageMapper.getProductDetails(productId);
-        // 用户身份:0个人,1协销,2会员机构,3供应商,4普通机构
-        Integer identity = shopMapper.getUserIdentityById(userId);
         if (product == null) {
             //商品不存在
             product = new ProductDetailVo();
             product.setValidFlag(0);
         }
-        boolean validFlag = 2 != product.getProductCategory() && 2 == product.getValidFlag() && (product.getStock() == null || product.getStock() == 0);
-        if (validFlag) {
-            //已上架但库存为0的正常商品,设置为已售罄商品
-            product.setValidFlag(4);
-        }
         String[] split = null;
         // 品牌名称
         String brandName = shopMapper.getBrandNameById(product.getBrandId());
@@ -590,18 +585,6 @@ public class PageServiceImpl implements PageService {
         product.setImageList(imageList);
         // 商品详情
         ProductDetailInfoPo productDetail = shopMapper.getProductDetailInfo(productId);
-        //非资质机构商品详情展示普通机构商品详情,游客和普通机构要进判断
-//        if (null == identity || 4 == identity) {
-//            String chose = product.getProductDetailChose();
-//            log.info("身份identity===================>"+identity+"ProductDetail===================》"+chose);
-//            if (StringUtils.isNotEmpty(chose) && "2".equals(chose)) {
-//                //将商品详情展示为普通机构商品详情
-//                String info = null == productDetail.getDetailInfo2() ? "若要查看更多产品信息,请注册机构会员,如有疑问请联系客服。" : productDetail.getDetailInfo2();
-//                log.info("DetailInfo2参数================================》"+info);
-//                productDetail.setDetailInfo(info);
-//            }
-//        }
-//        log.info("-------------------》productDetail参数"+productDetail.toString());
         product.setProductDetail(productDetail);
         // 相关参数
         List<ProductParameterPo> parametersList = shopMapper.getProductParameters(productId);
@@ -613,8 +596,6 @@ public class PageServiceImpl implements PageService {
         product.setBigTypeName(list.size() > 0 ? list.get(0) : null);
         product.setSmallTypeName(list.size() > 1 ? list.get(1) : null);
         product.setTinyTypeName(list.size() > 2 ? list.get(2) : null);
-        //价格等级
-        product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
         // 商品云上美博会活动状态
         Integer pcBeautyStatus = shopMapper.getPcBeautyStatusById(product.getProductId());
         Integer appletsBeautyStatus = shopMapper.getAppletsBeautyStatusById(product.getProductId());
@@ -636,65 +617,35 @@ public class PageServiceImpl implements PageService {
             shop.setBusinessLicense(ImageUtils.getImageURL("shopLogo", shop.getBusinessLicense(), 0, domain));
             product.setShop(shop);
         }
-        // 商品可见度:3:所有人可见,2:普通机构可见,1:会员机构可见,4:仅医美机构可见
-        /*Integer visibility = product.getVisibility();
-        if (null != userId && userId > 0) {
-            // 会员机构类型:1医美,2生美
-            Integer clubType = 0;
-            if (null != identity && identity == 2) {
-                clubType = priceMapper.getClubTypeById(userId);
-            }
-            // 超级会员用户id
-            Integer superVipId = priceMapper.getSvipUserIdByUserId(userId);
-            // 所有人可见
-            boolean pass1 = visibility == 3;
-            // 协销
-            boolean pass2 = null != identity && identity == 1;
-            // 医美机构
-            boolean pass3 = visibility == 4 && (null != clubType && clubType == 1);
-            // 会员机构 | 超级会员
-            boolean pass4 = visibility == 1 && (null != superVipId || (null != identity && identity == 2));
-            // 普通机构
-            boolean pass5 = visibility == 2 && (null != identity && (identity == 4 || identity == 2));
-            // 没有权限查看该商品
-            if (!(pass1 || pass2 || pass3 || pass4 || pass5)) {
-                return ResponseJson.success(0, "没有权限查看该商品", product);
-            }
-        } else if (2 == visibility || 1 == visibility || 4 == visibility) {
-            return ResponseJson.success(0, "没有权限查看该商品,userId为空", product);
-        }*/
         // 商品不处于已删除/待审核/审核未通过的状态
         if (0 != product.getValidFlag()) {
             // 数据库获取基本价格信息
             PriceVo price = priceMapper.getDetailPrice(productId);
             // 根据用户id设置详细价格
-            priceUtilService.setPriceByUserId(price, userId);
+            priceUtilService.setPriceByUserId(price, userId, 0);
             // 设置价格
-            product.setActStatus(price.getActStatus());
             product.setPrice(price.getPrice());
-            product.setOriginalPrice(price.getOriginalPrice());
-            product.setNormalPrice(price.getNormalPrice());
-            product.setLadderPriceFlag(price.getLadderPriceFlag());
-            product.setPromotions(price.getPromotions());
+            product.setOriginalPrice(price.getPrice());
             product.setMinBuyNumber(price.getMinBuyNumber());
+            product.setUnit(price.getUnit());
+            product.setStock(price.getStock());
+            product.setSkus(price.getSkus());
+            product.setSkuId(price.getSkuId());
+            product.setActStatus(price.getActStatus());
+            product.setPromotions(price.getPromotions());
             product.setUserIdentity(price.getUserIdentity());
-            product.setRepurchaseFlag(price.getRepurchaseFlag());
-            product.setMaxBuyNumber(price.getMaxBuyNumber());
             product.setSvipProductFlag(price.getSvipProductFlag());
             product.setSvipPriceTag(price.getSvipPriceTag());
-            // 设置阶梯价格详情
-            if (1 == price.getLadderPriceFlag()) {
-                List<LadderPriceVo> ladderPrices = priceMapper.getLadderPricesByProductId(product.getProductId());
-                TaxVo tax = priceMapper.getTaxByProductId(product.getProductId());
-                if (!CollectionUtils.isEmpty(ladderPrices)) {
-                    priceUtilService.setLadderPriceList(ladderPrices, tax);
-                }
-                product.setLadderPriceList(ladderPrices);
-            }
+            AtomicBoolean lowPrice = new AtomicBoolean(false);
+            //设置展示的价格等级
+            product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
             //查询商品收藏情况,1未收藏,0未收藏,未收藏过该商品用户是null
             Integer like = likeMapper.findLike(userId, productId);
             product.setUserLike(like);
         }
+        // 设置售罄标记
+        Integer flag = priceMapper.getSaleOutFlag(product.getProductId()) > 0 ? 0 : 1;
+        product.setSaleOutFlag(flag);
         return ResponseJson.success(product);
     }
 
@@ -721,7 +672,7 @@ public class PageServiceImpl implements PageService {
             boolean state = (costFlag == 1 && MathUtil.compare(costPrice, discountPrice) >= 0) || MathUtil.compare(discountPrice, price) > 0;
             product.setRepurchasePriceState(state);
             // 设置商品主图及价格
-            priceUtilService.setProductDetails(userId, product);
+            priceUtilService.setProductDetails(userId, product, 0);
             //优惠券标识
             Boolean couponsLogo = pageService.setCouponsLogo(userId, product.getProductId(), 2);
             product.setCouponsLogo(couponsLogo);
@@ -1000,6 +951,12 @@ public class PageServiceImpl implements PageService {
         }
     }
 
+    @Override
+    public ResponseJson delSku(Integer skuId) {
+        pageMapper.delSku(skuId);
+        return ResponseJson.success();
+    }
+
     /**
      * 设置楼层相关图片的商品信息
      */
@@ -1042,7 +999,7 @@ public class PageServiceImpl implements PageService {
                         iterator.remove();
                     } else {
                         // 商品价格
-                        priceUtilService.setProductDetails(userId, product);
+                        priceUtilService.setProductDetails(userId, product, 0);
                         // 设置商品主图
                         image.setListType(1);
                         image.setName(product.getName());
@@ -1050,7 +1007,6 @@ public class PageServiceImpl implements PageService {
                         //优惠券标识
                         Boolean couponsLogo = setCouponsLogo(userId, image.getProductId(), source);
                         product.setCouponsLogo(couponsLogo);
-
                         image.setProduct(product);
                     }
                 } else {
@@ -1274,7 +1230,7 @@ public class PageServiceImpl implements PageService {
         PageHelper.startPage(pageNum, pageSize);
         List<ProductItemVo> svipProductList = pageMapper.getSvipProductList();
         svipProductList.forEach(svipProduct -> {
-            priceUtilService.setProductDetails(userId, svipProduct);
+            priceUtilService.setProductDetails(userId, svipProduct, 0);
             svipProduct.setImage(ImageUtils.getImageURL("product", svipProduct.getImage(), 0, domain));
         });
         PaginationVo<ProductItemVo> svipProductPage = new PaginationVo<>(svipProductList);
@@ -1387,7 +1343,6 @@ public class PageServiceImpl implements PageService {
                     }
                 }
             }
-            product.setPriceGrade(priceUtilService.getPriceGrade(product.getPrice()));
             product.setImage(ImageUtils.getImageURL("product", product.getImage(), 0, domain));
         });
         PaginationVo<ProductItemVo> pageData = new PaginationVo(list);

+ 2 - 2
src/main/java/com/caimei365/commodity/service/impl/PriceServiceImpl.java

@@ -56,7 +56,7 @@ public class PriceServiceImpl implements PriceService {
         // 数据库获取基本价格信息
         PriceVo price = priceMapper.getDetailPrice(productId);
         // 根据用户id设置详细价格
-        priceUtilService.setPriceByUserId(price, userId);
+        priceUtilService.setPriceByUserId(price, userId, 0);
         log.info(">>>读取商品价格,商品ID:" + productId + ",用户ID:" + userId);
         return ResponseJson.success(price);
     }
@@ -86,7 +86,7 @@ public class PriceServiceImpl implements PriceService {
         List<PriceVo> priceList = priceMapper.getListPriceByProductIds(productIdList);
         for (PriceVo price : priceList) {
             // 根据用户id设置详细价格
-            priceUtilService.setPriceByUserId(price, userId);
+            priceUtilService.setPriceByUserId(price, userId, 0);
             Boolean couponsLogo = pageService.setCouponsLogo(userId, price.getProductId(), source);
             price.setCouponsLogo(couponsLogo);
         }

+ 0 - 10
src/main/java/com/caimei365/commodity/service/impl/SearchProductServiceImpl.java

@@ -83,11 +83,6 @@ public class SearchProductServiceImpl implements SearchProductService {
         }
         List<String> filterList = new ArrayList<>();
         if (newFlag == 1) {
-//            Calendar c = Calendar.getInstance();
-//            c.setTime(new Date());
-//            c.add(Calendar.YEAR, -1);
-//            String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
-//            filterList.add("p_time > " + time);
             filterList.add("p_newvalidflag = 1");
         }
         if (promotionFlag == 1) {
@@ -266,11 +261,6 @@ public class SearchProductServiceImpl implements SearchProductService {
         }
         List<String> filterList = new ArrayList<>();
         if (newFlag == 1) {
-//            Calendar c = Calendar.getInstance();
-//            c.setTime(new Date());
-//            c.add(Calendar.YEAR, -1);
-//            String time = new SimpleDateFormat("yyyyMMdd").format(c.getTime());
-//            filterList.add("p_time > " + time);
             filterList.add("p_newvalidflag = 1");
         }
         if (promotionFlag == 1) {

+ 15 - 8
src/main/java/com/caimei365/commodity/service/impl/SecondHandServiceImpl.java

@@ -3,8 +3,10 @@ package com.caimei365.commodity.service.impl;
 import com.caimei365.commodity.components.RedisService;
 import com.caimei365.commodity.mapper.PriceMapper;
 import com.caimei365.commodity.mapper.SecondHandMapper;
+import com.caimei365.commodity.mapper.ShopMapper;
 import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.dto.SecondDto;
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.ProductImagePo;
 import com.caimei365.commodity.model.po.ProductPo;
 import com.caimei365.commodity.model.po.ProductSecondPo;
@@ -46,7 +48,8 @@ public class SecondHandServiceImpl implements SecondHandService {
     private PriceMapper priceMapper;
     @Value("${spring.cloud.config.profile}")
     private String profile;
-
+    @Resource
+    private ShopMapper shopMapper;
     /**
      * 二手商品列表
      *
@@ -427,10 +430,7 @@ public class SecondHandServiceImpl implements SecondHandService {
         ProductPo product = new ProductPo();
         product.setBrandId(secondDto.getBrandId());
         product.setName(secondDto.getName());
-        product.setPrice(secondDto.getPrice());
-        product.setStock(secondDto.getStock());
         product.setAliasName(secondDto.getName());
-        product.setNormalPrice(secondDto.getNormalPrice());
         product.setMainImage(images[0]);
         // 二手商品类型
         product.setProductCategory(2);
@@ -438,13 +438,9 @@ public class SecondHandServiceImpl implements SecondHandService {
         // 默认发布到二手供应商
         product.setShopId(shopId);
         product.setSellNumber(secondDto.getStock());
-        product.setCostPrice(0d);
-        product.setCostCheckFlag(2);
-        product.setCostProportional(95d);
         product.setHasSkuFlag(1);
         // 商品状态默认待审核
         product.setValidFlag(1);
-        product.setLadderPriceFlag(0);
         product.setSortIndex(1);
         product.setFeaturedFlag(0);
         product.setByFlag(0);
@@ -465,6 +461,17 @@ public class SecondHandServiceImpl implements SecondHandService {
         product.setAnnounType(secondDto.getAnnounType());
         /* 保存商品表 */
         secondHandMapper.insertProduct(product);
+        /*保存sku数据*/
+        Sku sku = new Sku();
+        sku.setPrice(secondDto.getPrice());
+        sku.setStock(secondDto.getStock());
+        sku.setNormalPrice(secondDto.getNormalPrice());
+        sku.setLadderPriceFlag(0);
+        sku.setCostPrice(0d);
+        sku.setCostCheckFlag(2);
+        sku.setCostProportional(95d);
+        sku.setProductId(product.getProductId());
+        shopMapper.insertSku(sku);
         /* 保存商品图片信息*/
         for (int i = 0; i < images.length; i++) {
             ProductImagePo imagePo = new ProductImagePo();

+ 6 - 3
src/main/java/com/caimei365/commodity/service/impl/SellerServiceImpl.java

@@ -11,6 +11,7 @@ import com.caimei365.commodity.model.vo.ProductItemVo;
 import com.caimei365.commodity.service.PageService;
 import com.caimei365.commodity.service.SellerService;
 import com.github.pagehelper.PageHelper;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
@@ -18,6 +19,7 @@ import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicReference;
 
 /**
  * Description
@@ -26,6 +28,7 @@ import java.util.List;
  * @date : 2021/4/23
  */
 @Service
+@Slf4j
 public class SellerServiceImpl implements SellerService {
     @Value("${caimei.wwwDomain}")
     private String domain;
@@ -57,7 +60,7 @@ public class SellerServiceImpl implements SellerService {
         List<ProductItemVo> productList = sellerMapper.getSingleProductList(searchWord);
         productList.forEach(product -> {
             // 设置商品主图及价格
-            priceUtilService.setProductDetails(clubUserId, product);
+            priceUtilService.setProductDetails(clubUserId, product, 0);
         });
         PaginationVo<ProductItemVo> pageData = new PaginationVo<>(productList);
         return ResponseJson.success(pageData);
@@ -90,7 +93,7 @@ public class SellerServiceImpl implements SellerService {
                 product.setInitProductNum(0);
                 product.setTotalPrice(0d);
                 // 设置商品主图及价格
-                priceUtilService.setProductDetails(clubUserId, product);
+                priceUtilService.setProductDetails(clubUserId, product, 1);
                 //优惠券标识
                 Boolean couponsLogo = pageService.setCouponsLogo(clubUserId, product.getProductId(), 2);
                 product.setCouponsLogo(couponsLogo);
@@ -129,7 +132,7 @@ public class SellerServiceImpl implements SellerService {
             }
             productList.forEach(product -> {
                 // 设置商品主图及价格
-                priceUtilService.setProductDetails(userId, product);
+                priceUtilService.setProductDetails(userId, product, 0);
                 //优惠券标识
                 Boolean couponsLogo = pageService.setCouponsLogo(userId, product.getProductId(), source);
                 product.setCouponsLogo(couponsLogo);

+ 76 - 102
src/main/java/com/caimei365/commodity/service/impl/ShopServiceImpl.java

@@ -1,6 +1,7 @@
 package com.caimei365.commodity.service.impl;
 
 import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei365.commodity.components.PriceUtilService;
 import com.caimei365.commodity.mapper.PriceMapper;
@@ -10,6 +11,7 @@ import com.caimei365.commodity.model.ResponseJson;
 import com.caimei365.commodity.model.dto.BrandDto;
 import com.caimei365.commodity.model.dto.FeaturedDto;
 import com.caimei365.commodity.model.dto.ProductDto;
+import com.caimei365.commodity.model.dto.Sku;
 import com.caimei365.commodity.model.po.*;
 import com.caimei365.commodity.model.search.ProductListVo;
 import com.caimei365.commodity.model.vo.*;
@@ -21,6 +23,8 @@ import org.apache.commons.lang.StringUtils;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.Assert;
 
 import javax.annotation.Resource;
 import java.text.SimpleDateFormat;
@@ -63,13 +67,13 @@ public class ShopServiceImpl implements ShopService {
         List<Integer> visibilityList = new ArrayList<>();
         if (identity == 1 || identity == 5) {
             // 协销 | 医美机构 | 综合供应商
-            visibilityList.addAll(Arrays.asList(1,2,3,4));
+            visibilityList.addAll(Arrays.asList(1, 2, 3, 4));
         } else if (identity == 2) {
             // 会员机构
-            visibilityList.addAll(Arrays.asList(1,2,3));
+            visibilityList.addAll(Arrays.asList(1, 2, 3));
         } else if (identity == 4) {
             // 普通机构
-            visibilityList.addAll(Arrays.asList(2,3));
+            visibilityList.addAll(Arrays.asList(2, 3));
         } else {
             // 游客|所有人
             visibilityList.add(3);
@@ -101,13 +105,13 @@ public class ShopServiceImpl implements ShopService {
      * @return Map<String, Object>
      */
     @Override
-    public ResponseJson<Map<String, Object>> getShopProducts(Integer showFlag,Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer commodityType, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId,Integer newvalidFlag, int pageNum, int pageSize) {
+    public ResponseJson<Map<String, Object>> getShopProducts(Integer showFlag, Integer shopId, String name, String productCode, Integer validFlag, Integer featuredFlag, Integer commodityType, Integer bigTypeId, Integer smallTypeId, Integer tinyTypeId, Integer newvalidFlag, int pageNum, int pageSize) {
         if (null == shopId) {
             return ResponseJson.error("参数异常:缺少供应商Id", null);
         }
         Map<String, Object> map = new HashMap<>();
         PageHelper.startPage(pageNum, pageSize);
-        List<ProductItemVo> productList = shopMapper.getShopProductsSelect(showFlag,newvalidFlag,shopId, name, productCode, validFlag, featuredFlag, commodityType, bigTypeId, smallTypeId, tinyTypeId);
+        List<ProductItemVo> productList = shopMapper.getShopProductsSelect(showFlag, newvalidFlag, shopId, name, productCode, validFlag, featuredFlag, commodityType, bigTypeId, smallTypeId, tinyTypeId);
         if (null != productList && productList.size() > 0) {
             for (ProductItemVo product : productList) {
                 String typeName = shopMapper.getTypeName(product.getBigTypeId(), product.getSmallTypeId(), product.getTinyTypeId());
@@ -115,20 +119,20 @@ public class ShopServiceImpl implements ShopService {
                 product.setIsChecked(false);
                 // 设置商品主图及价格
                 Integer userId = shopMapper.getUserIdByshopId(shopId);
-                priceUtilService.setProductDetails(userId, product);
+                priceUtilService.setProductDetails(userId, product, 0);
             }
         }
         PaginationVo<ProductItemVo> productPage = new PaginationVo<>(productList);
         map.put("productPage", productPage);
         int featuredNum = shopMapper.getMainProductsCount(shopId);
         map.put("featuredNum", featuredNum);
-       Integer listingFeeCount= shopMapper.listingFee(shopId);
-        Integer listingfeeExpireCount= shopMapper.listingfeeExpire(shopId);
-        Integer receStatctCount=shopMapper.receStatct(shopId);
-        Integer listingFee=0;
-        if(listingFeeCount>0 && listingfeeExpireCount>0){
-                if(receStatctCount<=0){
-                listingFee=1;//1是有上架费或者过期并且没有免除上架费
+        Integer listingFeeCount = shopMapper.listingFee(shopId);
+        Integer listingfeeExpireCount = shopMapper.listingfeeExpire(shopId);
+        Integer receStatctCount = shopMapper.receStatct(shopId);
+        Integer listingFee = 0;
+        if (listingFeeCount > 0 && listingfeeExpireCount > 0) {
+            if (receStatctCount <= 0) {
+                listingFee = 1;//1是有上架费或者过期并且没有免除上架费
             }
         }
         map.put("listingFee", listingFee);
@@ -172,6 +176,7 @@ public class ShopServiceImpl implements ShopService {
      *                   }
      */
     @Override
+    @Transactional(rollbackFor = Exception.class)
     public ResponseJson releaseProduct(ProductDto productDto) {
         // 参数校验
         if (null == productDto.getShopId()) {
@@ -198,27 +203,25 @@ public class ShopServiceImpl implements ShopService {
         if (StringUtils.isBlank(productDto.getTags())) {
             return ResponseJson.error("参数异常:商品标签不能为空!", null);
         }
-        if (StringUtils.isBlank(productDto.getUnit())) {
-            return ResponseJson.error("参数异常:包装规格不能为空!", null);
-        }
-        if (null == productDto.getNormalPrice()) {
-            return ResponseJson.error("参数异常:市场价不能为空!", null);
-        }
-        if (null == productDto.getPrice()) {
-            return ResponseJson.error("参数异常:机构价格不能为空!", null);
-        }
         if (null == productDto.getIncludedTax()) {
             return ResponseJson.error("参数异常:是否含税不能为空!", null);
         }
-        if (null == productDto.getMinBuyNumber()) {
-            return ResponseJson.error("参数异常:最小购买量不能为空!", null);
-        }
-        if (null == productDto.getStock()) {
-            return ResponseJson.error("参数异常:库存不能为空!", null);
-        }
         if (StringUtils.isBlank(productDto.getDetailInfo())) {
             return ResponseJson.error("参数异常:商品详情信息不能为空!", null);
         }
+        if (StringUtils.isBlank(productDto.getSkus())) {
+            return ResponseJson.error("参数异常:商品sku不能为空!", null);
+        }
+        List<Sku> skus = JSON.parseArray(productDto.getSkus(), Sku.class);
+        skus.forEach(s -> {
+            Assert.notNull(s.getCostPrice(), "结算价不能为空!");
+            Assert.notNull(s.getNormalPrice(), "市场价不能为空!");
+            Assert.notNull(s.getPrice(), "售价不能为空!");
+            Assert.notNull(s.getUnit(), "规格不能为空!");
+            Assert.notNull(s.getMinBuyNumber(), "起订量不能为空!");
+        });
+
+
         JSONObject parseObject = JSON.parseObject(productDto.getParams());
         //图片
         List<Map<String, String>> imageList = (List<Map<String, String>>) parseObject.get("image");
@@ -231,85 +234,29 @@ public class ShopServiceImpl implements ShopService {
         String current = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date());
         //保存或修改商品
         ProductPo product = new ProductPo();
-        product.setNewProductType(productDto.getNewProductType());
-        log.info("打印日志__________>"+productDto.getNewProductType());
-        if(productDto.getNewProductType()==1){
-            product.setShowFlag(0);
-        }else {
-            product.setShowFlag(3);
-        }
-
-/*        if (null != productDto.getProductId()) {
-            product.setProductId(productDto.getProductId());
-        }
-        product.setShopId(productDto.getShopId());
-        product.setName(productDto.getName());
-        product.setAliasName(productDto.getAliasName());
-        product.setCommodityType(productDto.getCommodityType());
-        product.setBigTypeId(productDto.getBigTypeId());
-        product.setSmallTypeId(productDto.getSmallTypeId());
-        product.setTinyTypeId(productDto.getTinyTypeId());
-        product.setBrandId(productDto.getBrandId());
-        product.setProductType(productDto.getProductType());
-        product.setTags(productDto.getTags());
-        product.setUnit(productDto.getUnit());
-        product.setNormalPrice(productDto.getNormalPrice());
-        product.setPrice(productDto.getPrice());
-        product.setIncludedTax(productDto.getIncludedTax());
-        product.setMinBuyNumber(productDto.getMinBuyNumber());
-        product.setStock(productDto.getStock());
-        product.setSearchKey(productDto.getSearchKey());
-        product.setCostPrice(productDto.getCostPrice());
-        product.setStep(productDto.getStep());
-        product.setAllAreaFlag(productDto.getAllAreaFlag());
-        product.setProvinceIds(productDto.getProvinceIds());
-        product.setProductCode(productDto.getProductCode());
-        product.setServiceNumber(productDto.getMinBuyNumber());
-        product.setSupplierTaxPoint(productDto.getTaxPoint());
-        product.setMachineType(productDto.getMachineType());
-        product.setStep(productDto.getStep());
-        product.setQualificationImg(productDto.getQualificationImg());
-        product.setInvoiceType(productDto.getInvoiceType());
-        product.setTaxPoint(productDto.getTaxPoint());
-        product.setAllAreaFlag(productDto.getAllAreaFlag());
-        product.setProvinceIds(productDto.getProvinceIds());*/
+//        product.setNewProductType(productDto.getNewProductType());
+        Integer showFlag = 1 == productDto.getNewProductType() ? 0 : 3;
+        product.setShowFlag(showFlag);
         BeanUtils.copyProperties(productDto, product);
         product.setUpdateTime(current);
         product.setValidFlag(1);
         product.setProductCategory(1);
-        product.setQualificationNo(productDto.getQualificationNo());
-        product.setProductName(productDto.getProductName());
-        product.setQualificationTime(productDto.getQualificationTime());
+//        product.setQualificationNo(productDto.getQualificationNo());
+//        product.setProductName(productDto.getProductName());
+//        product.setQualificationTime(productDto.getQualificationTime());
         //根据商品类型给价格可见度、商品可见度、商品内容可见度赋值
-        //械字号
-        if (productDto.getProductType() == 2) {
-            //一类
-            if (productDto.getMachineType() == 1) {
-                product.setPriceFlag(0);
-                product.setVisibility(3);
-                product.setCommodityDetailsFlag(1);
-                //二类
-            } else if (productDto.getMachineType() == 2) {
-                product.setPriceFlag(3);
-                product.setVisibility(3);
-                product.setCommodityDetailsFlag(4);
-                //三类
-            } else if (productDto.getMachineType() == 3) {
-                product.setPriceFlag(3);
-                product.setVisibility(3);
-                product.setCommodityDetailsFlag(4);
-                //异常情况赋值
-            } else {
-                product.setPriceFlag(0);
-                product.setVisibility(3);
-                product.setCommodityDetailsFlag(1);
-            }
-            //其他字号商品
+        product.setVisibility(3);
+        Integer priceFlag;
+        Integer commodityDetailsFlag;
+        if (2 == productDto.getProductType()) {
+            priceFlag = 2 == productDto.getMachineType() || 3 == productDto.getMachineType() ? 3 : 0;
+            commodityDetailsFlag = 2 == productDto.getMachineType() || 3 == productDto.getMachineType() ? 4 : 1;
         } else {
-            product.setPriceFlag(2);
-            product.setVisibility(3);
-            product.setCommodityDetailsFlag(1);
+            priceFlag = 2;
+            commodityDetailsFlag = 1;
         }
+        product.setPriceFlag(priceFlag);
+        product.setCommodityDetailsFlag(commodityDetailsFlag);
         //设置主图
         for (Map<String, String> map : imageList) {
             String mainFlag = map.get("mainFlag");
@@ -328,8 +275,10 @@ public class ShopServiceImpl implements ShopService {
             product.setRecommendType(0);
             product.setActFlag(0);
             product.setLadderPriceFlag(0);
-            log.info("+++++++++++++++++++++++++"+product);
+            log.info("---------------------------------->" + product);
             shopMapper.insertProduct(product);
+            //插入sku
+            addSkus(skus, product.getProductId());
             if (StringUtils.isBlank(productDto.getProductCode())) {
                 String productCode = shopMapper.getCodeByTypeId(productDto.getBigTypeId(), productDto.getSmallTypeId(), productDto.getTinyTypeId());
                 productCode = productCode + product.getProductId();
@@ -337,8 +286,10 @@ public class ShopServiceImpl implements ShopService {
                 shopMapper.updateProductCode(productCode, product.getProductId());
             }
         } else {
-            log.info(">>>>>>>>>>>>>>>>>>"+product);
+            log.info("---------------------------------->" + product);
             shopMapper.updateProduct(product);
+            //修改sku
+            updateSkus(skus, product.getProductId());
         }
         //保存或修改商品图片
         List<ProductImagePo> productImageList = shopMapper.getImageByProductId(product.getProductId());
@@ -396,6 +347,27 @@ public class ShopServiceImpl implements ShopService {
         return ResponseJson.success();
     }
 
+    public void addSkus(List<Sku> skus, Integer productId) {
+        //保存sku
+        if (null != skus && skus.size() > 0) {
+            skus.forEach(s -> {
+                s.setProductId(productId);
+                shopMapper.insertSku(s);
+            });
+        }
+    }
+
+    public void updateSkus(List<Sku> skus, Integer productId) {
+        skus.forEach(s -> {
+            s.setProductId(productId);
+            if (null != s.getSkuId()) {
+                shopMapper.updateSku(s);
+            } else {
+                shopMapper.insertSku(s);
+            }
+        });
+    }
+
     /**
      * 供应商-商品编辑回显
      *
@@ -406,7 +378,9 @@ public class ShopServiceImpl implements ShopService {
         if (null == productId) {
             return ResponseJson.error("参数异常:商品Id不能为空!", null);
         }
+        List<Sku> skus = priceMapper.findSkus(productId);
         ProductFormVo product = shopMapper.getProductForm(productId);
+        product.setSkus(skus);
         if (null == product) {
             return ResponseJson.error("商品信息异常,productId:" + productId, null);
         }

+ 1 - 1
src/main/java/com/caimei365/commodity/service/impl/UserLikeServiceImpl.java

@@ -58,7 +58,7 @@ public class UserLikeServiceImpl implements UserLikeService {
         List<ProductItemVo> productList = likeMapper.findLikeList(userId);
         productList.forEach(product -> {
             // 设置商品主图及价格
-            priceUtilService.setProductDetails(userId, product);
+            priceUtilService.setProductDetails(userId, product, 0);
             //优惠券标识
             Boolean couponsLogo = pageService.setCouponsLogo(userId, product.getProductId(), 2);
             product.setCouponsLogo(couponsLogo);

+ 7 - 8
src/main/resources/mapper/CouponMapper.xml

@@ -69,18 +69,17 @@
         p.name,
         p.aliasName,
         p.mainImage AS image,
-        p.unit,
+        (select unit from cm_sku where productId=p.productID order by price asc limit 1)as unit,
         p.productCode AS CODE,
         p.priceFlag,
-        p.price,
-        p.costPrice,
-        p.costCheckFlag,
+        (select price from cm_sku where productId=p.productID order by price asc limit 1)as price,
+        (select costPrice from cm_sku where productId=p.productID order by price asc limit 1)as costPrice,
+        (select costCheckFlag from cm_sku where productId=p.productID order by price asc limit 1)as costCheckFlag,
         p.shopID AS shopId,
         p.searchKey AS keyword,
-        p.minBuyNumber AS minBuyNumber,
-        p.maxBuyNumber AS maxBuyNumber,
-        p.ladderPriceFlag,
-        p.normalPrice,
+        (select minBuyNumber from cm_sku where productId=p.productID order by price asc limit 1) AS minBuyNumber,
+        (select ladderPriceFlag from cm_sku where productId=p.productID order by price asc limit 1)as ladderPriceFlag,
+        (select normalPrice from cm_sku where productId=p.productID order by price asc limit 1)as normalPrice,
         p.step,
         p.shopID AS shopId,
         p.taxPoint AS taxRate,

+ 127 - 78
src/main/resources/mapper/HeheMapper.xml

@@ -6,22 +6,22 @@
         select id as bigTypeId, name, icon as crmIcon
         from hehe_home_type
         where status = 1
-        order by -sort desc,addTime desc
+        order by -sort desc, addTime desc
         limit 8
     </select>
     <select id="getProductList" resultType="com.caimei365.commodity.model.vo.HeheProductVo">
         SELECT
         chp.productId,
-        chp.price,
-        chp.price as normalPrice,
+        (select price from cm_hehe_sku where productId=chp.productId order by price asc limit 1) as price,
+        (select price from cm_hehe_sku where productId=chp.productId order by price asc limit 1) as normalPrice,
         chp.includedTax,
         chp.invoiceType,
         chp.clubTaxPoint,
         p.name,
-        P.unit,
+        (select unit from cm_sku cs left join cm_hehe_sku chs on cs.skuId=chs.skuId where chs.productId=chp.productId
+        order by chs.price asc limit 1) as unit,
         p.mainImage
-        FROM
-        cm_hehe_product chp
+        FROM cm_hehe_product chp
         LEFT JOIN product p ON chp.productId = p.productID
         <if test="listType == 2">
             LEFT JOIN hehe_home_type_product hhtp on chp.productId = hhtp.productId
@@ -64,69 +64,83 @@
             order by rand()
         </if>
         <if test="sortType == 2">
-            order by chp.price
+            order by price
         </if>
         <if test="sortType == 3">
-            order by chp.price desc
+            order by price desc
         </if>
         <if test="sortType == 4">
             order by chp.id desc
         </if>
     </select>
+
     <select id="getProduct" resultType="com.caimei365.commodity.model.vo.HeheProductVo">
-        SELECT
-            chp.productId,
-            chp.price,
-            chp.price as normalPrice,
-            chp.includedTax,
-            chp.invoiceType,
-            chp.clubTaxPoint,
-            p.name,
-            P.unit,
-            p.mainImage,
-            cb.name as "brandName",
-            P.unit,
-            P.stock,
-            p.tags
-        FROM
-            cm_hehe_product chp
-                LEFT JOIN product p ON chp.productId = p.productID
-                LEFT JOIN cm_brand cb on p.brandID = cb.id
-        WHERE
-            chp.validFlag = 1
-            and chp.productId = #{productId}
+        SELECT chp.productId,
+               (select price from cm_hehe_sku where productId = chp.productId order by price asc limit 1) as price,
+               (select price
+                from cm_hehe_sku
+                where productId = chp.productId
+                order by price asc
+                limit 1)                                                                                  as normalPrice,
+               (select unit
+                from cm_sku cs
+                         left join cm_hehe_sku chs on cs.skuId = chs.skuId
+                where cs.productId = chp.productId
+                order by chs.price asc
+                limit 1)                                                                                  as unit,
+               (select stock
+                from cm_sku cs
+                         left join cm_hehe_sku chs on cs.skuId = chs.skuId
+                where cs.productId = chp.productId
+                order by chs.price asc
+                limit 1)                                                                                  as stock,
+               chp.includedTax,
+               chp.invoiceType,
+               chp.clubTaxPoint,
+               p.name,
+               p.mainImage,
+               cb.name                                                                                    as "brandName",
+               p.tags
+        FROM cm_hehe_product chp
+                 LEFT JOIN product p ON chp.productId = p.productID
+                 LEFT JOIN cm_brand cb on p.brandID = cb.id
+        WHERE chp.validFlag = 1
+          and chp.productId = #{productId}
     </select>
     <select id="getActivityIdByProductId" resultType="java.lang.Integer">
-        SELECT
-            activityId
-        FROM
-            cm_hehe_activity_product a
-                LEFT JOIN cm_hehe_activity cha ON a.activityId = cha.id
-        WHERE
-            cha.delFlag = 0
+        SELECT activityId
+        FROM cm_hehe_activity_product a
+                 LEFT JOIN cm_hehe_activity cha ON a.activityId = cha.id
+        WHERE cha.delFlag = 0
           AND a.delFlag = 0
           AND NOW() BETWEEN cha.beginTime AND cha.endTime
           AND a.productId = #{productId}
     </select>
     <select id="getCollageProduct" resultType="com.caimei365.commodity.model.po.HeheCollageProductPo">
-        select chcp.productId, chcp.price, chcp.limitedNum, chcp.unlimitedFlag, chcp.memberNum
+        select chcs.skuId,
+               chcp.productId,
+               chcs.collagePrice as price,
+               chcp.limitedNum,
+               chcp.unlimitedFlag,
+               chcp.memberNum
         from cm_hehe_collage_product chcp
-        where chcp.productId = #{productID} and chcp.status = 1
+                 left join cm_hehe_collage_sku chcs on chcp.productId = chcs.productId
+        where chcs.skuId = #{skuId}
+          and chcp.status = 1
+        ORDER BY price ASC
+        LIMIT 1
     </select>
     <select id="getActivityLadderList" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
-        SELECT
-            buyNum,
-            buyPrice
-        FROM
-            cm_hehe_activity_ladder
-        WHERE
-            activityId = #{activityId}
-          AND productId = #{productId}
-        ORDER BY
-            ladderNum
+        SELECT skuId,
+               buyNum,
+               buyPrice
+        FROM cm_hehe_activity_ladder
+        WHERE activityId = #{activityId}
+          AND skuId = #{skuId}
+        ORDER BY buyPrice ASC
     </select>
     <select id="getProductDiscount" resultType="com.caimei365.commodity.model.vo.HeHeDiscountVo">
-        select chd.id as discountId, chd.discount,if(chd.productType = 2,chdp.discountPrice,null) as discountPrice
+        select chd.id as discountId, chd.discount, if(chd.productType = 2, chdp.discountPrice, null) as discountPrice
         from cm_hehe_discount chd
                  left join cm_hehe_discount_product chdp on chd.id = chdp.discountId
                  left join cm_hehe_discount_user chdu on chd.id = chdu.discountId
@@ -138,7 +152,8 @@
     <select id="getAllProductCouponCount" resultType="java.lang.Integer">
         select count(*)
         from cm_hehe_coupon chc
-        where chc.delFlag = 0 and chc.productType = 1
+        where chc.delFlag = 0
+          and chc.productType = 1
           and if(startNowFlag = 1, true, NOW() <![CDATA[  >=  ]]> startTime)
           and if(permanentFlag = 1, true, NOW() <![CDATA[  <=  ]]> endTime)
     </select>
@@ -147,17 +162,22 @@
         from cm_hehe_coupon chc
                  left join cm_hehe_coupon_product chcp on chc.id = chcp.couponId
                  left join cm_hehe_product chp on chcp.productId = chp.id
-        where chc.delFlag = 0 and chc.productType = 2 and chp.productId = #{productId}
+        where chc.delFlag = 0
+          and chc.productType = 2
+          and chp.productId = #{productId}
           and if(startNowFlag = 1, true, NOW() <![CDATA[  >=  ]]> startTime)
           and if(permanentFlag = 1, true, NOW() <![CDATA[  <=  ]]> endTime)
     </select>
     <select id="getDiscountPrice" resultType="com.caimei365.commodity.model.po.HeheDiscountPricePo">
-        select a.discountPrice, a.productId, chda.offlineTime
+        select chds.discountPrice, a.productId, chda.offlineTime
         from hehe_discount_activity_product a
+                 left join cm_hehe_discount_activity_sku chds on a.productId = chds.productId
                  left join cm_hehe_discount_activity chda on a.activityId = chda.id
-        where a.productId = #{productId}
+        where chds.skuId = #{skuId}
           and a.status = 1
           and NOW() between chda.onlineTime and chda.offlineTime
+        order by discountPrice asc
+        limit 1
     </select>
     <select id="getCouponList" resultType="com.caimei365.commodity.model.vo.HeheCouponVo">
         select chc.id as couponId,
@@ -177,7 +197,8 @@
         <if test="userId > 0">
             date_add(
             if(couponType <![CDATA[ <= ]]> 3,
-            if(#{registerTime} <![CDATA[ >= ]]> startTime and if(permanentFlag = 1,true,#{registerTime} <![CDATA[ < ]]> endTime),
+            if(#{registerTime} <![CDATA[ >= ]]> startTime and if(permanentFlag = 1,true,#{registerTime} <![CDATA[ < ]]>
+            endTime),
             #{registerTime},startTime),
             chcs.createTime
             )
@@ -191,7 +212,7 @@
         left join (select couponId as couponId, group_concat(productId) as productIds
         from cm_hehe_coupon_product
         group by couponId
-        ) as  chcp on chc.id = chcp.couponId
+        ) as chcp on chc.id = chcp.couponId
         where chc.delFlag = 0
         and if(startNowFlag = 1, true, NOW() <![CDATA[  >=  ]]> startTime)
         <if test="productIdArr != null and productIdArr.length > 0">
@@ -208,13 +229,17 @@
         </if>
         <if test="userId > 0">
             and if(couponType <![CDATA[ <= ]]> 3,
-            chc.id not in (select couponId from cm_hehe_receive_coupon where userId = #{userId} and couponId is not null),
-            chcs.id not in (select couponShareId from cm_hehe_receive_coupon where userId = #{userId} and couponShareId is not null)
+            chc.id not in (select couponId from cm_hehe_receive_coupon where userId = #{userId} and couponId is not
+            null),
+            chcs.id not in (select couponShareId from cm_hehe_receive_coupon where userId = #{userId} and couponShareId
+            is not null)
             )
             and (
             (couponType = 1
-            or (couponType = 2 and chc.id in (select distinct couponId from cm_hehe_coupon_user where userId = #{userId} and couponId is not null))
-            or (couponType = 3 and #{registerTime} <![CDATA[ >= ]]> startTime and if(permanentFlag = 1,true,#{registerTime} <![CDATA[ < ]]> endTime))
+            or (couponType = 2 and chc.id in (select distinct couponId from cm_hehe_coupon_user where userId = #{userId}
+            and couponId is not null))
+            or (couponType = 3 and #{registerTime} <![CDATA[ >= ]]> startTime and if(permanentFlag =
+            1,true,#{registerTime} <![CDATA[ < ]]> endTime))
             or (couponType = 4 and chcs.shareUserId = #{userId})
             or (couponType = 5 and chcs.shareUserId = #{userId})
             or (couponType = 6 and chcs.shareUserId = #{userId})
@@ -223,7 +248,8 @@
             if(permanentFlag = 1,true,NOW() <![CDATA[ < ]]> endTime),
             NOW() <![CDATA[ < ]]> date_add(
             if(couponType <![CDATA[ <= ]]> 3,
-            if(#{registerTime} <![CDATA[ >= ]]> startTime and if(permanentFlag = 1,true,#{registerTime} <![CDATA[ < ]]> endTime),
+            if(#{registerTime} <![CDATA[ >= ]]> startTime and if(permanentFlag = 1,true,#{registerTime} <![CDATA[ < ]]>
+            endTime),
             #{registerTime},startTime),
             chcs.createTime
             )
@@ -236,7 +262,9 @@
         order by chc.createDate desc
     </select>
     <select id="getUserRegisterTime" resultType="java.util.Date">
-        select registerTime from user where userID = #{userId}
+        select registerTime
+        from user
+        where userID = #{userId}
     </select>
     <select id="getReceiveCouponList" resultType="com.caimei365.commodity.model.vo.HeheCouponVo">
         select distinct
@@ -281,29 +309,26 @@
         </if>
     </select>
     <select id="getActivityList" resultType="com.caimei365.commodity.model.vo.HeHeActivityVo">
-        SELECT
-            cha.id AS activityId,
-            cha.name,
-            cha.listImage,
-            cha.beginTime,
-            cha.endTime,
-            COUNT(chua.id) AS productCount
-        FROM
-            cm_hehe_user_activity chua
-                LEFT JOIN cm_hehe_activity cha ON chua.activityId = cha.id
-        WHERE
-            chua.userId = #{userId}
+        SELECT cha.id         AS activityId,
+               cha.name,
+               cha.listImage,
+               cha.beginTime,
+               cha.endTime,
+               COUNT(chua.id) AS productCount
+        FROM cm_hehe_user_activity chua
+                 LEFT JOIN cm_hehe_activity cha ON chua.activityId = cha.id
+        WHERE chua.userId = #{userId}
           AND cha.delFlag = 0
           AND cha.status = 1
           AND cha.beginTime <![CDATA[ <= ]]> NOW()
           AND cha.endTime <![CDATA[ >= ]]> NOW()
-        GROUP BY
-            cha.id
-        ORDER BY
-            cha.addTime DESC
+        GROUP BY cha.id
+        ORDER BY cha.addTime DESC
     </select>
     <select id="getActivityImageById" resultType="java.lang.String">
-        SELECT detailsImage FROM cm_hehe_activity WHERE id = #{activityId}
+        SELECT detailsImage
+        FROM cm_hehe_activity
+        WHERE id = #{activityId}
     </select>
     <select id="getHomeCarousel" resultType="com.caimei365.commodity.model.vo.HeHeImageVo">
         SELECT topic,
@@ -316,5 +341,29 @@
         WHERE status = 1
         ORDER BY - sort DESC
     </select>
+    <select id="findHeheSkus" resultType="com.caimei365.commodity.model.dto.HeHeSku">
+        select cs.skuId,
+               cs.unit,
+               cs.productId,
+               cs.costCheckFlag,
+               cs.costPrice,
+               cs.costProportional,
+               cs.stock,
+               chs.price,
+               chs.price as normalPrice
+        from cm_hehe_sku chs
+                 left join cm_sku cs on cs.skuId = chs.skuId
+        where chs.productId = #{productId}
+        order by chs.price asc
+    </select>
+    <select id="getActivityLadderListBySkuId" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
+        SELECT skuId,
+               buyNum,
+               buyPrice
+        FROM cm_hehe_activity_ladder
+        WHERE activityId = #{activityId}
+          AND skuId = #{skuId}
+        ORDER BY buyPrice ASC
+    </select>
 
 </mapper>

+ 47 - 50
src/main/resources/mapper/PageMapper.xml

@@ -1,6 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.commodity.mapper.PageMapper">
+    <delete id="delSku">
+        delete from cm_sku
+        where skuId=#{skuId}
+    </delete>
     <select id="getPageTypeSort" resultType="java.lang.Integer">
         select typeSort
         from cm_page
@@ -157,16 +161,16 @@
                p.name,
                p.aliasName,
                p.mainImage         as image,
-               p.unit,
                p.productCode       as code,
                p.priceFlag,
-               p.price,
+               (select unit from cm_sku where productID=#{productId} order by price asc LIMIT 1) as unit,
+               (select price from cm_sku where productID=#{productId} order by price asc LIMIT 1) as price,
+               (select price from cm_sku where productID=#{productId} order by price asc LIMIT 1) as originalPrice,
                p.shopID            as shopId,
                p.searchKey         as keyword,
-               p.minBuyNumber      as minBuyNumber,
-               p.maxBuyNumber      as maxBuyNumber,
-               p.ladderPriceFlag,
-               p.normalPrice,
+               (select minBuyNumber from cm_sku where productID=#{productId} order by price asc LIMIT 1) as minBuyNumber,
+               (select ladderPriceFlag from cm_sku where productID=#{productId} order by price asc LIMIT 1) as ladderPriceFlag,
+               (select normalPrice from cm_sku where productID=#{productId} order by price asc LIMIT 1) as normalPrice,
                p.step,
                p.shopID            as shopId,
                p.taxPoint          as taxRate,
@@ -183,7 +187,7 @@
                cshd.detailTalkFlag as detailTalkFlag,
                p.productType
         from product p
-                 left join cm_second_hand_detail cshd on p.productID = cshd.productID
+        left join cm_second_hand_detail cshd on p.productID = cshd.productID
         where p.productID = #{productId}
           and p.validFlag = 2
     </select>
@@ -211,11 +215,14 @@
     <select id="getProductDetails" resultType="com.caimei365.commodity.model.vo.ProductDetailVo">
         select p.productID         as productId,
                p.shopID            as shopId,
+               (select normalPrice from cm_sku where productId=#{productId} order by price asc limit 1) as normalPrice,
+               ifnull((select stock from cm_sku where productId=#{productId} order by price asc limit 1),0) as stock,
+               (select minBuyNumber from cm_sku where productId=#{productId} order by price asc limit 1) as minBuyNumber,
+               (select unit from cm_sku where productId=#{productId} order by price asc limit 1) as unit,
                p.name,
                p.aliasName,
                p.commodityType,
                p.mainImage,
-               p.stock,
                p.invoiceType,
                p.bigTypeID         as bigTypeId,
                p.smallTypeID       as smallTypeId,
@@ -226,24 +233,18 @@
                p.brandID           as brandId,
                p.productType,
                p.tags,
-               p.unit,
-               p.normalPrice,
-               p.price,
                p.includedTax,
-               p.minBuyNumber,
                p.productCategory,
                p.serviceNumber,
                p.taxPoint,
                p.supplierTaxPoint,
                p.priceFlag,
                p.actFlag,
-               p.ladderPriceFlag,
                p.addTime,
                p.hasSkuFlag,
                p.sellNumber,
                p.sortIndex,
                p.featuredFlag,
-               p.costCheckFlag,
                p.recommendType,
                p.machineType,
                p.productCode,
@@ -252,7 +253,6 @@
                p.searchKey,
                p.allAreaFlag,
                p.step,
-               p.costPrice,
                p.provinceIds,
                p.qualificationImg,
                p.trainingMethod,
@@ -275,17 +275,17 @@
                p.name,
                p.aliasName,
                p.mainImage                as image,
-               p.unit,
+               rpp.skuId,
+               cs.unit,
                p.productCode              as code,
                p.priceFlag,
-               p.price,
-               p.costPrice,
-               ifnull(p.costCheckFlag, 1) as costCheckFlag,
+               cs.price,
+               cs.costPrice,
+               ifnull(cs.costCheckFlag, 1) as costCheckFlag,
                p.searchKey                as keyword,
-               p.minBuyNumber             as minBuyNumber,
-               p.maxBuyNumber             as maxBuyNumber,
-               p.ladderPriceFlag,
-               p.normalPrice,
+               cs.minBuyNumber             as minBuyNumber,
+               cs.ladderPriceFlag,
+               cs.normalPrice,
                p.step,
                p.shopID                   as shopId,
                p.taxPoint                 as taxRate,
@@ -301,7 +301,8 @@
                rpp.currentPrice           as discountPrice,
                p.productType
         from repeat_purchase_price rpp
-                 left join product p on rpp.productId = p.productID
+        left join product p on rpp.productId = p.productID
+        left join cm_sku cs on rpp.skuId = cs.skuId
         where rpp.delFlag = '0'
           and p.validFlag = '2'
           and rpp.userId = #{userId}
@@ -632,16 +633,15 @@
                p.name,
                p.aliasName,
                p.mainImage       as image,
-               p.unit,
+               (select unit from cm_sku where productId=csp.productId order by price asc limit 1)as unit,
                p.productCode     as code,
                p.priceFlag,
-               p.price,
+               (select price from cm_sku where productId=csp.productId order by price asc limit 1)as price,
                p.shopID          as shopId,
                p.searchKey       as keyword,
-               p.minBuyNumber    as minBuyNumber,
-               p.maxBuyNumber    as maxBuyNumber,
-               p.ladderPriceFlag,
-               p.normalPrice,
+               (select minBuyNumber from cm_sku where productId=csp.productId order by price asc limit 1)as minBuyNumber,
+               (select ladderPriceFlag from cm_sku where productId=csp.productId order by price asc limit 1)as ladderPriceFlag,
+               (select normalPrice from cm_sku where productId=csp.productId order by price asc limit 1)as normalPrice,
                p.step,
                p.shopID          as shopId,
                p.taxPoint        as taxRate,
@@ -905,15 +905,14 @@
         p.aliasName,
         p.visibility,
         p.mainImage,
-        p.unit,
+        (select unit from cm_sku where productId=p.productID order by price asc limit 1)as unit,
         p.productCode as code,
         p.priceFlag,
         p.shopID as shopId,
         p.searchKey as keyword,
-        p.minBuyNumber as minBuyNumber,
-        p.maxBuyNumber as maxBuyNumber,
-        p.ladderPriceFlag,
-        p.normalPrice,
+        (select minBuyNumber from cm_sku where productId=p.productID order by price asc limit 1)as minBuyNumber,
+        (select ladderPriceFlag from cm_sku where productId=p.productID order by price asc limit 1)as ladderPriceFlag,
+        (select normalPrice from cm_sku where productId=p.productID order by price asc limit 1)as normalPrice,
         p.step,
         p.taxPoint as taxRate,
         p.includedTax,
@@ -927,7 +926,7 @@
         p.tinyTypeID as tinyTypeId,
         p.productType,
         p.brandID,
-        p.price
+        (select price from cm_sku where productId=p.productID order by price asc limit 1)as price
         from product p
         <where>
             and p.showFlag!=5
@@ -942,21 +941,21 @@
     </select>
     <select id="getNewFloorList" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
         SELECT DISTINCT
+        (select price from cm_sku where productID=p.productID order by price asc limit 1)as price,
+        (select unit from cm_sku where productID=p.productID order by price asc limit 1)as unit,
+        (select normalPrice from cm_sku where productID=p.productID order by price asc limit 1)as normalPrice,
+        (select minBuyNumber from cm_sku where productID=p.productID order by price asc limit 1)as minBuyNumber,
+        (select ladderPriceFlag from cm_sku where productID=p.productID order by price asc limit 1)as ladderPriceFlag,
         p.productID,
         p.actStatus,
         p.name,
         p.aliasName,
         p.visibility,
         p.mainImage as image,
-        p.unit,
         p.productCode as code,
         p.priceFlag,
         p.shopID as shopId,
         p.searchKey as keyword,
-        p.minBuyNumber as minBuyNumber,
-        p.maxBuyNumber as maxBuyNumber,
-        p.ladderPriceFlag,
-        p.normalPrice,
         p.step,
         p.taxPoint as taxRate,
         p.includedTax,
@@ -969,8 +968,7 @@
         p.smallTypeID as smallTypeId,
         p.tinyTypeID as tinyTypeId,
         p.productType,
-        p.brandID,
-        p.price
+        p.brandID
         from product p
         <where>
             and p.showFlag!=5
@@ -999,16 +997,15 @@
         p.aliasName,
         p.visibility,
         p.mainImage as image,
-        p.unit,
+        (select unit from cm_sku where productId=p.productID order by price asc limit 1)as unit,
         p.productCode as code,
         p.priceFlag,
-        p.price,
+        (select price from cm_sku where productId=p.productID order by price asc limit 1)as price,
         p.shopID as shopId,
         p.searchKey as keyword,
-        p.minBuyNumber as minBuyNumber,
-        p.maxBuyNumber as maxBuyNumber,
-        p.ladderPriceFlag,
-        p.normalPrice,
+        (select minBuyNumber from cm_sku where productId=p.productID order by price asc limit 1)as minBuyNumber,
+        (select ladderPriceFlag from cm_sku where productId=p.productID order by price asc limit 1)as ladderPriceFlag,
+        (select normalPrice from cm_sku where productId=p.productID order by price asc limit 1)as normalPrice,
         p.step,
         p.taxPoint as taxRate,
         p.includedTax,
@@ -1022,7 +1019,7 @@
         p.tinyTypeID as tinyTypeId,
         p.productType,
         p.brandID,
-        p.price
+        (select price from cm_sku where productId=p.productID order by price asc limit 1)as price
         from product p
         <where>
 

+ 171 - 88
src/main/resources/mapper/PriceMapper.xml

@@ -2,105 +2,118 @@
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.commodity.mapper.PriceMapper">
     <select id="getIdentityByUserId" resultType="java.lang.Integer">
-        select userIdentity from user where userID = #{userId}
+        select userIdentity
+        from user
+        where userID = #{userId}
     </select>
     <select id="getDetailPrice" resultType="com.caimei365.commodity.model.vo.PriceVo">
-        select
-            p.productID as productId,
-            p.actStatus,
-            p.price,
-            p.minBuyNumber,
-            p.maxBuyNumber,
-            p.priceFlag,
-            p.ladderPriceFlag,
-            p.normalPrice,
-            p.costPrice,
-            p.costProportional,
-            p.costCheckFlag,
-            p.step,
-            p.shopID as shopId,
-            p.taxPoint as taxRate,
-            p.includedTax,
-            p.invoiceType,
-            if(csp.id is not null,1,0) as svipProductFlag,
-            csp.priceType as svipPriceType,
-            csp.discount as svipDiscount,
-            csp.discountPrice as svipDiscountPrice,
-            p.productType
+        select p.productID                  as productId,
+               p.actStatus,
+               (select normalPrice
+                from cm_sku
+                where productId = #{productId}
+                order by price asc
+                limit 1)                    as normalPrice,
+               p.priceFlag,
+               p.step,
+               p.shopID                     as shopId,
+               p.taxPoint                   as taxRate,
+               p.includedTax,
+               p.invoiceType,
+               if(csp.id is not null, 1, 0) as svipProductFlag,
+               csp.priceType                as svipPriceType,
+               csp.discount                 as svipDiscount,
+               csp.discountPrice            as svipDiscountPrice,
+               p.productType
         from product p
-        left join cm_svip_product csp on p.productID = csp.productId
+                 left join cm_svip_product csp on p.productID = csp.productId
         where p.productID = #{productId}
     </select>
     <select id="getListPriceByProductIds" resultType="com.caimei365.commodity.model.vo.PriceVo">
         select
-            p.productID as productId,
-            p.actStatus,
-            p.price,
-            p.minBuyNumber,
-            p.maxBuyNumber,
-            p.priceFlag,
-            p.ladderPriceFlag,
-            p.normalPrice,
-            p.costPrice,
-            p.costProportional,
-            p.costCheckFlag,
-            p.step,
-            p.shopID as shopId,
-            p.includedTax,
-            p.invoiceType,
-            p.taxPoint as taxRate,
-            if(csp.id is not null,1,0) as svipProductFlag,
-            csp.priceType as svipPriceType,
-            csp.discount as svipDiscount,
-            csp.discountPrice as svipDiscountPrice,
-            p.productType,
-            p.newvalidFlag
+        p.productID as productId,
+        p.actStatus,
+        p.priceFlag,
+        p.step,
+        p.shopID as shopId,
+        p.includedTax,
+        p.invoiceType,
+        p.taxPoint as taxRate,
+        if(csp.id is not null,1,0) as svipProductFlag,
+        csp.priceType as svipPriceType,
+        csp.discount as svipDiscount,
+        csp.discountPrice as svipDiscountPrice,
+        p.productType,
+        p.newvalidFlag
         from product p
         left join cm_svip_product csp on p.productID = csp.productId
         where p.productID in
-          <foreach collection="productIds" open="(" separator="," close=")" item="productId">
-              #{productId}
-          </foreach>
+        <foreach collection="productIds" open="(" separator="," close=")" item="productId">
+            #{productId}
+        </foreach>
     </select>
     <select id="getLadderPricesByProductId" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
-        select
-        	id, productId, ladderNum, buyNum, buyPrice
-        from product_ladder_price
-        where productId = #{productId} and userType = 3 and delFlag = 0
-        order by ladderNum asc
+        select plp.skuId,
+               plp.productId,
+               buyNum,
+               stock,
+               buyPrice,
+               unit
+        from product_ladder_price plp
+                 left join cm_sku cs on plp.skuId = cs.skuId
+        where plp.skuId = #{skuId}
+          and userType = 3
+          and delFlag = 0
+        order by buynum asc
     </select>
     <select id="findLowerLadderPrice" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
-        select
-        	id, productId, ladderNum, buyNum, buyPrice
+        select id,
+               skuId,
+               productId,
+               ladderNum,
+               buyNum,
+               buyPrice
         from product_ladder_price
-        where productId = #{productId} and userType = 3 and delFlag = 0
-        order by ladderNum DESC
+        where skuId = #{skuId}
+          and userType = 3
+          and delFlag = 0
+        order by buyPrice asc
         limit 1
     </select>
     <select id="findMaxLadderPrice" resultType="com.caimei365.commodity.model.vo.LadderPriceVo">
-        select
-        	id, productId, ladderNum, buyNum, buyPrice
-        from product_ladder_price
-        where productId = #{productId} and userType = 3 and delFlag = 0
-        order by ladderNum asc
+        select id,
+               plp.skuId,
+               plp.productId,
+               ladderNum,
+               cs.unit,
+               cs.stock,
+               buyNum,
+               buyPrice
+        from product_ladder_price plp
+                 left join cm_sku cs on cs.skuId = plp.skuId
+        where plp.skuId = #{skuId}
+          and userType = 3
+          and delFlag = 0
+        order by buyprice desc
         limit 1
     </select>
     <select id="getRepurchasePrice" resultType="java.lang.Double">
-        select
-          r.currentPrice,p.productType
+        select r.currentPrice,
+               p.productType
         from repeat_purchase_price r
-        left join product p on p.productID = r.productId
-        where r.productId = #{productId} and userId = #{userId}
-        and ((p.costCheckFlag=1 and r.currentPrice <![CDATA[ >= ]]> p.costPrice) or p.costCheckFlag=2)
-        and p.price <![CDATA[ >= ]]> r.currentPrice
-        and r.delFlag = 0
+                 left join product p on p.productID = r.productId
+                 left join cm_sku cs on r.skuId = cs.skuId
+        where r.skuId = #{skuId}
+          and userId = #{userId}
+          and ((cs.costCheckFlag = 1 and r.currentPrice <![CDATA[ >= ]]> cs.costPrice) or cs.costCheckFlag = 2)
+          and cs.price <![CDATA[ >= ]]> r.currentPrice
+          and r.delFlag = 0
     </select>
     <select id="getTaxByProductId" resultType="com.caimei365.commodity.model.vo.TaxVo">
-        select
-        p.includedTax as includedTax,
-        p.invoiceType as invoiceType,
-        p.taxPoint as taxPoint,
-        p.productType
+        select p.includedTax as includedTax,
+               p.invoiceType as invoiceType,
+               p.taxPoint    as taxPoint,
+               p.productType
         from product p
         where productID = #{productId}
     </select>
@@ -114,21 +127,21 @@
     </select>
 
     <select id="getProductSalesInfo" resultType="com.caimei365.commodity.model.vo.ProductSalesVo">
-        select p.productID AS productId,
-               p.name AS productName,
-               p.shopID AS shopId,
+        select p.productID    AS productId,
+               p.name         AS productName,
+               p.shopID       AS shopId,
                p.commodityType,
-               p.bigTypeID as bigTypeId,
-               p.smallTypeID as smallTypeId,
-               p.tinyTypeID as tinyTypeId,
-               s.productId AS id,
-               s.shop AS shopName,
+               p.bigTypeID    as bigTypeId,
+               p.smallTypeID  as smallTypeId,
+               p.tinyTypeID   as tinyTypeId,
+               s.productId    AS id,
+               s.shop         AS shopName,
                s.productCount AS productCount,
-               s.property AS property,
+               s.property     AS property,
                p.productType
         FROM product p
-        LEFT JOIN cm_product_sales s ON p.productID = s.productId
-        where p.productId=#{productId}
+                 LEFT JOIN cm_product_sales s ON p.productID = s.productId
+        where p.productId = #{productId}
     </select>
     <insert id="insertProductSales" parameterType="com.caimei365.commodity.model.vo.ProductSalesVo">
         INSERT INTO cm_product_sales(productId, product, shop, productCount, property)
@@ -147,9 +160,79 @@
         WHERE productId = #{productId}
     </update>
     <select id="getClubTypeById" resultType="java.lang.Integer">
-        SELECT firstClubType FROM club WHERE userID = #{userId}
+        SELECT firstClubType
+        FROM club
+        WHERE userID = #{userId}
     </select>
     <select id="getShopIdByUserId" resultType="java.lang.Integer">
-        SELECT shopID FROM shop WHERE userID = #{userId}
+        SELECT shopID
+        FROM shop
+        WHERE userID = #{userId}
+    </select>
+    <select id="findSkus" resultType="com.caimei365.commodity.model.dto.Sku">
+        select skuId,
+               price,
+               normalPrice,
+               costPrice,
+               ifnull(ladderPriceFlag, 0)                                                                           as ladderPriceFlag,
+               costCheckFlag,
+               costProportional,
+               ifnull(stock, 0)                                                                                     as stock,
+               unit,
+               ifnull(minBuyNumber, (SELECT buyNum
+                                     FROM product_ladder_price
+                                     WHERE skuId = cs.skuId
+                                     ORDER BY buyNum asc
+                                     LIMIT 1))                                                                      AS minBuyNumber
+        from cm_sku cs
+        where productId = #{productId}
+        ORDER BY price ASC
+    </select>
+    <select id="findLowPrice" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
+        select plp.buyPrice as price, cs.unit as unit, plp.buyNum as minBuyNumber, cs.skuId as skuId, cs.stock
+        from product_ladder_price plp
+                 left join cm_sku cs on plp.skuId = cs.skuId
+        where plp.productId = #{productId}
+        order by buynum asc
+        limit 1
+    </select>
+    <select id="getSaleOutFlag" resultType="java.lang.Integer">
+        SELECT COUNT(*)
+        FROM cm_sku
+        WHERE stock > 0
+          AND productId = #{productId}
+    </select>
+    <select id="findSkusOutOfPrice" resultType="com.caimei365.commodity.model.dto.Sku">
+        select skuId,
+               ifnull(ladderPriceFlag, 0)                                                                           as ladderPriceFlag,
+               costCheckFlag,
+               costProportional,
+               ifnull(stock, 0)                                                                                     as stock,
+               unit,
+               ifnull(minBuyNumber, (SELECT buyNum
+                                     FROM product_ladder_price
+                                     WHERE skuId = cs.skuId
+                                     ORDER BY buyNum asc
+                                     LIMIT 1))                                                                      AS minBuyNumber
+        from cm_sku cs
+        where productId = #{productId}
+        ORDER BY price ASC
+    </select>
+    <select id="findLowPriceOfAll" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
+        select plp.buyPrice as price, cs.unit as unit, plp.buyNum as minBuyNumber, cs.skuId as skuId, cs.stock
+        from product_ladder_price plp
+                 left join cm_sku cs on plp.skuId = cs.skuId
+        where plp.productId = #{productId}
+        GROUP BY plp.skuId
+        order by plp.buyPrice asc
+        limit 1
+    </select>
+    <select id="findLowPriceOfPrice" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
+        SELECT price, unit, skuId, stock,
+        ifnull(minBuyNumber, (SELECT buyNum FROM product_ladder_price WHERE skuId = cm_sku.skuId ORDER BY buyNum asc LIMIT 1)) AS minBuyNumber
+        FROM cm_sku
+        WHERE productId = #{productId}
+        ORDER BY price ASC
+        LIMIT 1
     </select>
 </mapper>

+ 7 - 5
src/main/resources/mapper/PromotionsMapper.xml

@@ -70,6 +70,7 @@
     </select>
     <select id="getPromotionGifts" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
         select cpg.id      as id,
+               cpg.skuId   as giftSkuId,
                p.productID as productId,
                p.actStatus,
                p.shopID    as shopId,
@@ -78,13 +79,14 @@
                cpg.number  as number,
                0           as price,
                2           as productType,
-               p.price    as originalPrice,
-               p.unit      as unit,
+               cs.price    as originalPrice,
+               cs.unit      as unit,
                p.validFlag as validFlag,
-               p.stock     as stock,
+               cs.stock     as stock,
                p.productType
         from product p
                  left join cm_promotions_gift cpg on cpg.productId = p.productID
+        left join cm_sku cs on cpg.skuId=cs.skuId
         where cpg.promotionsId = #{promotionsId}
         order by cpg.addTime desc
     </select>
@@ -124,8 +126,8 @@
         p.productID as productId,
         p.`name` as `name`,
         p.mainImage as image,
-        p.price,
-        p.unit as unit,
+        (select price from cm_sku where productID=p.productID order by price asc limit 1)as price,
+        (select unit from cm_sku where productID=p.productID order by price asc limit 1)as unit,
         p.priceFlag,
         IFNULL(p.visibility,3) as visibility,
         p.productType

+ 33 - 20
src/main/resources/mapper/SearchMapper.xml

@@ -7,10 +7,8 @@
         p.searchKey as p_keyword,
         p.tags as p_tags,
         p.mainImage as p_image,
-        p.price as p_price,
         p.priceFlag as p_price_flag,
         p.productCode as p_code,
-        p.unit as p_unit,
         br.id as p_brand_id,
         br.name as p_brand_name,
         p.shopID as p_supplier_id,
@@ -28,7 +26,9 @@
         DATE_FORMAT(p.ADDTIME,'%Y%m%d') as p_time,
         IFNULL(p.visibility,3) as p_visibility,
         ifnull(p.newvalidflag,0) as p_newvalidflag,
-        p.productType as p_product_type
+        p.productType as p_product_type,
+        (select unit from cm_sku where productID=#{productId} order by price asc LIMIT 1) as p_unit,
+        (select price from cm_sku where productID=#{productId} order by price asc LIMIT 1) as p_price
     </sql>
     <sql id="Product_Joins">
         left join tinytype as t on p.tinyTypeID = t.tinyTypeID
@@ -38,7 +38,8 @@
         left join shop as sh on p.shopID = sh.shopID
     </sql>
     <select id="searchProductById" resultType="com.caimei365.commodity.model.search.ProductDO">
-        select<include refid="Search_Product_List"/>
+        select
+        <include refid="Search_Product_List"/>
         from product p
         <include refid="Product_Joins"/>
         where p.validFlag in (2,3,9) and p.productCategory = 1
@@ -233,17 +234,23 @@
     <select id="findArticleCount" resultType="java.lang.Integer">
         select count(*)
         from info
-        where enabledStatus = 1 and auditStatus = 2 and onlineStatus = 2
+        where enabledStatus = 1
+          and auditStatus = 2
+          and onlineStatus = 2
     </select>
     <select id="findArticleInvalidCount" resultType="java.lang.Integer">
         select count(*)
         from info
-        where enabledStatus != 1 or auditStatus != 2 or onlineStatus != 2
+        where enabledStatus != 1
+           or auditStatus != 2
+           or onlineStatus != 2
     </select>
     <select id="findArticleInvalidIds" resultType="java.lang.Integer">
         select id
         from info
-        where enabledStatus != 1 or auditStatus != 2 or onlineStatus != 2
+        where enabledStatus != 1
+           or auditStatus != 2
+           or onlineStatus != 2
     </select>
     <select id="searchArticleList" resultType="com.caimei365.commodity.model.search.ArticleDO">
         select
@@ -289,10 +296,10 @@
         p.`name` as name,
         p.mainImage as image,
         br.name as brandName,
-        p.unit as unit,
+        (select unit from cm_sku where productID=p.productID order by price asc limit 1) as unit,
         p.productCode as code,
         p.priceFlag,
-        p.price,
+        (select price from cm_sku where productID=p.productID order by price asc limit 1)as price,
         p.shopID as shopId,
         p.productType,
         p.searchKey as keyword
@@ -338,7 +345,7 @@
             <when test="sortField != null and sortField != ''">
                 <choose>
                     <when test="sortField == 'price'">
-                        order by p.price
+                        order by price
                     </when>
                     <when test="sortField == 'sales'">
                         order by p.sellNumber
@@ -468,7 +475,7 @@
             </if>
         </where>
 
-         order by a.pubdate desc
+        order by a.pubdate desc
 
     </select>
     <select id="getHistoryList" resultType="com.caimei365.commodity.model.po.SearchHistoryPo">
@@ -480,7 +487,8 @@
     <select id="getHistoryIdByWord" resultType="java.lang.Integer">
         select id
         from user_search_history
-        where searchWord = #{keyword} and userId = #{userId}
+        where searchWord = #{keyword}
+          and userId = #{userId}
         limit 1
     </select>
     <select id="getHistoryCount" resultType="java.lang.Integer">
@@ -576,7 +584,7 @@
     <select id="findPromotionId" resultType="java.lang.Integer">
         select pr.id
         from cm_promotions pr
-        left join cm_promotions_product prp on pr.id = prp.promotionsId
+                 left join cm_promotions_product prp on pr.id = prp.promotionsId
         where (prp.productId = #{p_id} or
                prp.supplierId = (select p.shopID from product p where p.productID = #{p_id})
             )
@@ -586,17 +594,22 @@
         limit 1
     </select>
     <select id="countViewsByDate" resultType="java.lang.Integer">
-        select IFNULL(sum(views),0) from cm_product_views_record where productId = #{productId} and viewTime > #{date}
+        select IFNULL(sum(views), 0)
+        from cm_product_views_record
+        where productId = #{productId}
+          and viewTime > #{date}
     </select>
     <select id="countSalesByDate" resultType="java.lang.Integer">
-        select IFNULL(sum(sales),0) from cm_product_sales_record where productId = #{productId} and saleTime > #{date}
+        select IFNULL(sum(sales), 0)
+        from cm_product_sales_record
+        where productId = #{productId}
+          and saleTime > #{date}
     </select>
     <select id="findPromotions" resultType="java.lang.Integer">
-        SELECT DISTINCT
-        cpp.productId
+        SELECT DISTINCT cpp.productId
         FROM cm_promotions cp
-        LEFT JOIN cm_promotions_product cpp ON cp.id=cpp.promotionsId
-        WHERE (cp.status=1 OR (cp.status=2 AND cp.endTime>NOW()))
-        AND cp.delFlag=0
+                 LEFT JOIN cm_promotions_product cpp ON cp.id = cpp.promotionsId
+        WHERE (cp.status = 1 OR (cp.status = 2 AND cp.endTime > NOW()))
+          AND cp.delFlag = 0
     </select>
 </mapper>

+ 163 - 143
src/main/resources/mapper/SecondHandMapper.xml

@@ -1,73 +1,84 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.commodity.mapper.SecondHandMapper">
-    <insert id="saveSencondHandProduct" parameterType="com.caimei365.commodity.model.po.ProductSecondPo" keyProperty="id" useGeneratedKeys="true">
-        insert into cm_second_hand_detail(
-			productID, sold, secondHandType, instrumentType, fixedYears, maturityYears, companyName, detailTalkFlag,
-			originalPrice, contactName, contactMobile, dockingPeopleName, dockingPeopleMobile, secondProductType,
-			townId, brandName, provinceCityDistrict, address, productQuality, productDetails, viewingNum, payStatus,
-			payAmount, payFormData, payType, payDate, submitDate, reviewedDate, onLineDate, source, publisher, authenticationImage,
-			fileName, ossName, commitmentImage,publishIdentity,licenseImage,authenticationBackImage
-		) values (
-			#{productId}, #{sold}, #{secondHandType}, #{instrumentType}, #{fixedYears}, #{maturityYears}, #{companyName},
-			#{detailTalkFlag}, #{originalPrice}, #{contactName}, #{contactMobile}, #{dockingPeopleName}, #{dockingPeopleMobile},
-			#{secondProductType}, #{townId}, #{brandName}, #{provinceCityDistrict}, #{address}, #{productQuality}, #{productDetails},
-			#{viewingNum}, #{payStatus}, #{payAmount}, #{payFormData}, #{payType}, #{payDate}, #{submitDate}, #{reviewedDate},
-			#{onLineDate}, #{source}, #{publisher}, #{authenticationImage}, #{fileName}, #{ossName}, #{commitmentImage},#{publishIdentity},
-			#{licenseImage},#{authenticationBackImage}
-		)
+    <insert id="saveSencondHandProduct" parameterType="com.caimei365.commodity.model.po.ProductSecondPo"
+            keyProperty="id" useGeneratedKeys="true">
+        insert into cm_second_hand_detail(productID, sold, secondHandType, instrumentType, fixedYears, maturityYears,
+                                          companyName, detailTalkFlag,
+                                          originalPrice, contactName, contactMobile, dockingPeopleName,
+                                          dockingPeopleMobile, secondProductType,
+                                          townId, brandName, provinceCityDistrict, address, productQuality,
+                                          productDetails, viewingNum, payStatus,
+                                          payAmount, payFormData, payType, payDate, submitDate, reviewedDate,
+                                          onLineDate, source, publisher, authenticationImage,
+                                          fileName, ossName, commitmentImage, publishIdentity, licenseImage,
+                                          authenticationBackImage)
+        values (#{productId}, #{sold}, #{secondHandType}, #{instrumentType}, #{fixedYears}, #{maturityYears},
+                #{companyName},
+                #{detailTalkFlag}, #{originalPrice}, #{contactName}, #{contactMobile}, #{dockingPeopleName},
+                #{dockingPeopleMobile},
+                #{secondProductType}, #{townId}, #{brandName}, #{provinceCityDistrict}, #{address}, #{productQuality},
+                #{productDetails},
+                #{viewingNum}, #{payStatus}, #{payAmount}, #{payFormData}, #{payType}, #{payDate}, #{submitDate},
+                #{reviewedDate},
+                #{onLineDate}, #{source}, #{publisher}, #{authenticationImage}, #{fileName}, #{ossName},
+                #{commitmentImage}, #{publishIdentity},
+                #{licenseImage}, #{authenticationBackImage})
     </insert>
     <insert id="insertProductImage" parameterType="com.caimei365.commodity.model.po.ProductImagePo">
         insert into productimage (productID, shopID, addTime, image, mainFlag, sortIndex)
         values (#{productId}, #{shopId}, #{addTime}, #{image}, #{mainFlag}, #{sortIndex})
     </insert>
-    <insert id="insertProduct" keyColumn="productID" keyProperty="productId" parameterType="com.caimei365.commodity.model.po.ProductPo" useGeneratedKeys="true">
-        insert into product (
-            brandId, name, price, stock, aliasName, normalPrice, mainImage, productCategory, preferredFlag, shopId,
-            sellNumber, costPrice, costCheckFlag, costProportional, hasSkuFlag, validFlag, ladderPriceFlag, sortIndex, featuredFlag, byFlag,
-            step, actFlag, actStatus, freePostFlag, productType, machineType, includedTax, recommendType, invoiceType,
-            visibility, addTime, updateTime, onlineTime, downlineTime,announType
-        ) values (
-            #{brandId}, #{name}, #{price}, #{stock}, #{aliasName}, #{normalPrice}, #{mainImage}, #{productCategory},
-            #{preferredFlag}, #{shopId}, #{sellNumber}, #{costPrice}, #{costCheckFlag}, #{costProportional}, #{hasSkuFlag}, #{validFlag},
-            #{ladderPriceFlag}, #{sortIndex}, #{featuredFlag}, #{byFlag}, #{step}, #{actFlag}, #{actStatus},
-            #{freePostFlag}, #{productType}, #{machineType}, #{includedTax}, #{recommendType}, #{invoiceType},
-            #{visibility}, #{addTime}, #{updateTime}, #{onlineTime}, #{offlineTime},#{announType}
-        )
+    <insert id="insertProduct" keyColumn="productID" keyProperty="productId"
+            parameterType="com.caimei365.commodity.model.po.ProductPo" useGeneratedKeys="true">
+        insert into product (brandId, name, aliasName, mainImage, productCategory, preferredFlag, shopId,
+                             sellNumber, hasSkuFlag, validFlag, sortIndex, featuredFlag, byFlag,
+                             step, actFlag, actStatus, freePostFlag, productType, machineType, includedTax,
+                             recommendType, invoiceType,
+                             visibility, addTime, updateTime, onlineTime, downlineTime, announType)
+        values (#{brandId}, #{name}, #{aliasName}, #{mainImage}, #{productCategory},
+                #{preferredFlag}, #{shopId}, #{sellNumber}, #{hasSkuFlag}, #{validFlag},
+                #{sortIndex}, #{featuredFlag}, #{byFlag}, #{step}, #{actFlag}, #{actStatus},
+                #{freePostFlag}, #{productType}, #{machineType}, #{includedTax}, #{recommendType}, #{invoiceType},
+                #{visibility}, #{addTime}, #{updateTime}, #{onlineTime}, #{offlineTime}, #{announType})
     </insert>
     <insert id="insertSecondFileType">
         insert into cm_second_file_type
-        (fileType,secondId,productId)
-        values (#{fileType},#{secondId},#{productId})
+            (fileType, secondId, productId)
+        values (#{fileType}, #{secondId}, #{productId})
     </insert>
-    <insert id="insertShop" keyColumn="shopID" keyProperty="shopId" parameterType="com.caimei365.commodity.model.vo.ShopVo" useGeneratedKeys="true">
-        insert into shop (name,linkMan,contractMobile,cardNumber,accountType,banOfDeposit,accountName,addTime,status,shopType)
-        values (#{name},#{linkMan},#{contractMobile},#{cardNumber},#{accountType},#{banOfDeposit},#{accountName},now(),90,0)
+    <insert id="insertShop" keyColumn="shopID" keyProperty="shopId"
+            parameterType="com.caimei365.commodity.model.vo.ShopVo" useGeneratedKeys="true">
+        insert into shop (name, linkMan, contractMobile, cardNumber, accountType, banOfDeposit, accountName, addTime,
+                          status, shopType)
+        values (#{name}, #{linkMan}, #{contractMobile}, #{cardNumber}, #{accountType}, #{banOfDeposit}, #{accountName},
+                now(), 90, 0)
     </insert>
     <update id="updateSecondHandViews">
-        UPDATE cm_second_hand_detail SET viewingNum = #{viewingNum}
+        UPDATE cm_second_hand_detail
+        SET viewingNum = #{viewingNum}
         WHERE productID = #{productId}
     </update>
     <select id="getSeconHandList" resultType="com.caimei365.commodity.model.vo.SecondListVo">
         select
-            p.productID as productId,
-            p.actStatus,
-            p.`name` as name,
-            p.mainImage as image,
-            p.price,
-            p.brandID as brandId,
-	        IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",
-	        cshd.sold as "sold",
-	        cshd.detailTalkFlag as "detailTalkFlag",
-	        cshd.onLineDate as "onLineDate",
-	        cshd.viewingNum as "viewingNum",
-	        cshd.provinceCityDistrict as "provinceCityDistrict"
-        from
-            product p
+        p.productID as productId,
+        p.actStatus,
+        p.`name` as name,
+        p.mainImage as image,
+        cs.price,
+        p.brandID as brandId,
+        IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",
+        cshd.sold as "sold",
+        cshd.detailTalkFlag as "detailTalkFlag",
+        cshd.onLineDate as "onLineDate",
+        cshd.viewingNum as "viewingNum",
+        cshd.provinceCityDistrict as "provinceCityDistrict"
+        from product p
+        left join cm_sku cs on p.productID=cs.productId
         left join cm_second_hand_detail cshd on p.productID = cshd.productID
         left join cm_brand cb on cb.id = p.brandID
         where
-            p.productCategory = 2 and p.validFlag = 2
+        p.productCategory = 2 and p.validFlag = 2
         <if test="secondHandType != null and secondHandType != ''">
             and cshd.secondHandType = #{secondHandType}
         </if>
@@ -89,103 +100,106 @@
         order by cshd.sold, cshd.onLineDate desc
     </select>
     <select id="getSecondHandDetail" resultType="com.caimei365.commodity.model.vo.SecondDetailVo">
-        select
-            p.productID as productId,
-            p.actStatus,
-            p.`name` as name,
-            p.mainImage as image,
-            p.price,
-            p.normalPrice,
-            p.productType,
-            p.stock,
-            p.brandID as brandId,
-            p.visibility as visibility,
-	        IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",
-	        cb.description as "brandInfo",
-	        cshd.originalPrice,
-	        cshd.sold,
-	        cshd.detailTalkFlag,
-	        cshd.onLineDate,
-	        cshd.viewingNum,
-	        cshd.provinceCityDistrict,
-            cshd.productDetails,
-            cshd.productQuality,
-            cshd.secondHandType,
-            ifnull(cshd.instrumentType,0) as instrumentType,
-            cshd.showContactFlag,
-            cshd.contactMobile,
-            cshd.contactName,
-            cshd.fixedYears,
-            cshd.maturityYears,
-            cshd.publishIdentity,
-            cshd.companyName
+        select p.productID                                   as productId,
+               p.actStatus,
+               p.`name`                                      as name,
+               p.mainImage                                   as image,
+               cs.price,
+               cs.normalPrice,
+               p.productType,
+               cs.stock,
+               p.brandID                                     as brandId,
+               p.visibility                                  as visibility,
+               IF(p.brandID != 161, cb.name, cshd.brandName) as "brandName",
+               cb.description                                as "brandInfo",
+               cshd.originalPrice,
+               cshd.sold,
+               cshd.detailTalkFlag,
+               cshd.onLineDate,
+               cshd.viewingNum,
+               cshd.provinceCityDistrict,
+               cshd.productDetails,
+               cshd.productQuality,
+               cshd.secondHandType,
+               ifnull(cshd.instrumentType, 0)                as instrumentType,
+               cshd.showContactFlag,
+               cshd.contactMobile,
+               cshd.contactName,
+               cshd.fixedYears,
+               cshd.maturityYears,
+               cshd.publishIdentity,
+               cshd.companyName
         from product p
-        left join cm_second_hand_detail cshd on p.productID = cshd.productID
-        left join cm_brand cb on cb.id = p.brandID
-        where p.productCategory = 2 and p.productID = #{productId}
+                 left join cm_sku cs on p.productID = cs.productId
+                 left join cm_second_hand_detail cshd on p.productID = cshd.productID
+                 left join cm_brand cb on cb.id = p.brandID
+        where p.productCategory = 2
+          and p.productID = #{productId}
     </select>
     <select id="getImageByProductId" resultType="java.lang.String">
-        select image from productimage
+        select image
+        from productimage
         where productID = #{productId}
         order by mainFlag desc
     </select>
     <select id="getAddressInfo" resultType="com.caimei365.commodity.model.vo.AddressVo">
-        select a.name as "province"
-        ,b.name as "city"
-        ,c.name as "town"
-        ,c.townId as "townID"
+        select a.name   as "province"
+             , b.name   as "city"
+             , c.name   as "town"
+             , c.townId as "townID"
         from province a
-        right join city b on a.provinceId = b.provinceId
-        right join town c on b.cityId = c.cityId where c.townId = #{townId}
+                 right join city b on a.provinceId = b.provinceId
+                 right join town c on b.cityId = c.cityId
+        where c.townId = #{townId}
     </select>
     <select id="getOrderPageSecondList" resultType="com.caimei365.commodity.model.vo.SecondListVo">
         select
-            p.productID as productId,
-            p.actStatus,
-            p.`name` as name,
-            p.mainImage as image,
-            p.price,
-            p.brandID as brandId,
-	        IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",
-	        cshd.sold as "sold",
-	        cshd.detailTalkFlag as "detailTalkFlag",
-	        cshd.onLineDate as "onLineDate",
-	        cshd.viewingNum as "viewingNum",
-	        cshd.provinceCityDistrict as "provinceCityDistrict"
-        from
-            product p
+        p.productID as productId,
+        p.actStatus,
+        p.`name` as name,
+        p.mainImage as image,
+        cs.price,
+        p.brandID as brandId,
+        IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",
+        cshd.sold as "sold",
+        cshd.detailTalkFlag as "detailTalkFlag",
+        cshd.onLineDate as "onLineDate",
+        cshd.viewingNum as "viewingNum",
+        cshd.provinceCityDistrict as "provinceCityDistrict"
+        from product p
+        left join cm_sku cs on p.productID=cs.productId
         left join cm_second_hand_detail cshd on p.productID = cshd.productID
         left join cm_brand cb on cb.id = p.brandID
         where
-            p.productCategory = 2 and p.validFlag = 2
-            <if test="secondHandType != null and secondHandType != ''">
+        p.productCategory = 2 and p.validFlag = 2
+        <if test="secondHandType != null and secondHandType != ''">
             and cshd.secondHandType = #{secondHandType}
-            </if>
-            <if test="instrumentType != null and instrumentType != ''">
-            and cshd.instrumentType  like CONCAT('%',#{instrumentType},'%')
-            </if>
-            <if test="searchKeyword != null and searchKeyword != ''">
+        </if>
+        <if test="instrumentType != null and instrumentType != ''">
+            and cshd.instrumentType like CONCAT('%',#{instrumentType},'%')
+        </if>
+        <if test="searchKeyword != null and searchKeyword != ''">
             and p.name like CONCAT('%',#{searchKeyword},'%')
-            </if>
-            and cshd.sold != 1
-            order by cshd.onLineDate desc
+        </if>
+        and cshd.sold != 1
+        order by cshd.onLineDate desc
     </select>
     <select id="getSecondListByLimit" resultType="com.caimei365.commodity.model.vo.SecondListVo">
         select
-            p.productID as productId,
-            p.actStatus,
-            p.`name` as name,
-            p.mainImage as image,
-            p.price,
-            p.brandID as brandId,
-	        IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",
-	        cshd.sold as "sold",
-	        cshd.detailTalkFlag as "detailTalkFlag",
-	        cshd.onLineDate as "onLineDate",
-	        cshd.viewingNum as "viewingNum",
-	        cshd.provinceCityDistrict as "provinceCityDistrict"
-        from
-            product p
+        p.productID as productId,
+        p.actStatus,
+        p.`name` as name,
+        p.mainImage as image,
+        cs.price,
+        p.brandID as brandId,
+        IF(p.brandID != 161,cb.name ,cshd.brandName) as "brandName",
+        cshd.sold as "sold",
+        cshd.detailTalkFlag as "detailTalkFlag",
+        cshd.onLineDate as "onLineDate",
+        cshd.viewingNum as "viewingNum",
+        cshd.provinceCityDistrict as "provinceCityDistrict"
+        from product p
+        left join cm_sku cs on p.productID=cs.productId
         left join cm_second_hand_detail cshd on p.productID = cshd.productID
         left join cm_brand cb on cb.id = p.brandID
         where p.productCategory = 2 and p.validFlag = 2
@@ -198,28 +212,34 @@
     <select id="getBrandList" resultType="com.caimei365.commodity.model.vo.BrandVo">
         select id, name
         from cm_brand
-		where status = '1' and delFlag = '0' and description is not null and description != '' and id not in (161)
-		order by sort
+        where status = '1'
+          and delFlag = '0'
+          and description is not null
+          and description != ''
+          and id not in (161)
+        order by sort
     </select>
     <select id="getSecondRecommends" resultType="com.caimei365.commodity.model.vo.SecondListVo">
-        select
-        p.productID as productId,
-        p.actStatus,
-        p.`name` as name,
-        p.mainImage as image,
-        p.price,
-        p.brandID as brandId,
-        cb.name as "brandName"
+        select p.productID as productId,
+               p.actStatus,
+               p.`name`    as name,
+               p.mainImage as image,
+               cs.price,
+               p.brandID   as brandId,
+               cb.name     as "brandName"
         from product p
-        left join cm_second_hand_recommend cshr on p.productID = cshr.recommendProductID
-        left join cm_brand cb on cb.id = p.brandID
-        where p.validFlag = 2 and cshr.delFlag = 0
-        and cshr.secondHandProductID = #{productId}
+                 left join cm_sku cs on p.productID = cs.productId
+                 left join cm_second_hand_recommend cshr on p.productID = cshr.recommendProductID
+                 left join cm_brand cb on cb.id = p.brandID
+        where p.validFlag = 2
+          and cshr.delFlag = 0
+          and cshr.secondHandProductID = #{productId}
         order by cshr.sort desc
     </select>
     <select id="findSecondShop" resultType="java.lang.Integer">
-        select shopId from shop
+        select shopId
+        from shop
         where shopType = 3
-        AND cardNumber = #{cardNumber}
+          AND cardNumber = #{cardNumber}
     </select>
 </mapper>

+ 5 - 18
src/main/resources/mapper/SellerMapper.xml

@@ -7,16 +7,15 @@
                p.name,
                p.aliasName,
                p.mainImage       as image,
-               p.unit,
+               (select unit from cm_sku where productID=p.productID order by price asc limit 1)as unit,
                p.productCode     as code,
                p.priceFlag,
-               p.price,
+               (select price from cm_sku where productID=p.productID order by price asc limit 1)as price,
                p.shopID          as shopId,
                p.searchKey       as keyword,
-               p.minBuyNumber    as minBuyNumber,
-               p.maxBuyNumber    as maxBuyNumber,
-               p.ladderPriceFlag,
-               p.normalPrice,
+               (select minBuyNumber from cm_sku where productID=p.productID order by price asc limit 1) as minBuyNumber,
+               (select ladderPriceFlag from cm_sku where productID=p.productID order by price asc limit 1) as ladderPriceFlag,
+               (select normalPrice from cm_sku where productID=p.productID order by price asc limit 1)as normalPrice,
                p.step,
                p.shopID          as shopId,
                p.taxPoint        as taxRate,
@@ -53,15 +52,9 @@
             p.actStatus,
             p.name,
             p.aliasName,
-            p.unit,
             p.productCode as code,
             p.priceFlag as priceFlag,
-            p.price as price,
             p.shopID as shopId,
-            p.minBuyNumber as minBuyNumber,
-            p.maxBuyNumber as maxBuyNumber,
-            p.ladderPriceFlag,
-            p.normalPrice,
             p.step,
             p.shopID as shopId,
             p.includedTax,
@@ -98,16 +91,10 @@
         p.aliasName,
         p.visibility,
         p.mainImage as image,
-        p.unit,
         p.productCode as code,
         p.priceFlag,
-        p.price,
         p.shopID as shopId,
         p.searchKey as keyword,
-        p.minBuyNumber as minBuyNumber,
-        p.maxBuyNumber as maxBuyNumber,
-        p.ladderPriceFlag,
-        p.normalPrice,
         p.step,
         p.shopID as shopId,
         p.taxPoint as taxRate,

+ 69 - 62
src/main/resources/mapper/ShopMapper.xml

@@ -5,7 +5,7 @@
             parameterType="com.caimei365.commodity.model.po.ProductPo" useGeneratedKeys="true">
         insert into product (
         shopID, name, aliasName, commodityType, bigTypeID, smallTypeID, tinyTypeID, mainImage,
-        brandID, productType, tags, unit, normalPrice, price, includedTax, minBuyNumber, stock,
+        brandID, productType, tags, includedTax,
         <if test="productCategory != null and  productCategory != '' ">
             productCategory,
         </if>
@@ -30,9 +30,6 @@
         <if test="featuredFlag != null and  featuredFlag != ''">
             featuredFlag,
         </if>
-        <if test="costCheckFlag != null and  costCheckFlag != ''">
-            costCheckFlag,
-        </if>
         <if test="recommendType != null and  recommendType != ''">
             recommendType,
         </if>
@@ -42,9 +39,6 @@
         <if test="actFlag != null and  actFlag != ''">
             actFlag,
         </if>
-        <if test="ladderPriceFlag != null and  ladderPriceFlag != ''">
-            ladderPriceFlag,
-        </if>
         <if test="visibility != null and  visibility != ''">
             visibility,
         </if>
@@ -63,9 +57,6 @@
         <if test="step != null and  step != ''">
             step,
         </if>
-        <if test="costPrice != null and  costPrice != ''">
-            costPrice,
-        </if>
         <if test="provinceIds != null and  provinceIds != ''">
             provinceIds,
         </if>
@@ -87,12 +78,10 @@
         <if test="qualificationTime != null and  qualificationTime != ''">
             qualificationTime,
         </if>
-
         updateTime,validFlag,newProductType,showFlag,newvalidFlag
         ) values (
         #{shopId}, #{name}, #{aliasName}, #{commodityType}, #{bigTypeId}, #{smallTypeId}, #{tinyTypeId}, #{mainImage},
-        #{brandId}, #{productType}, #{tags}, #{unit}, #{normalPrice}, #{price}, #{includedTax}, #{minBuyNumber},
-        #{stock},
+        #{brandId}, #{productType}, #{tags}, #{includedTax},
         <if test="productCategory != null and  productCategory != '' ">
             #{productCategory},
         </if>
@@ -117,9 +106,6 @@
         <if test="featuredFlag != null and  featuredFlag != ''">
             #{featuredFlag},
         </if>
-        <if test="costCheckFlag != null and  costCheckFlag != ''">
-            #{costCheckFlag},
-        </if>
         <if test="recommendType != null and  recommendType != ''">
             #{recommendType},
         </if>
@@ -129,9 +115,6 @@
         <if test="actFlag != null and  actFlag != ''">
             #{actFlag},
         </if>
-        <if test="ladderPriceFlag != null and  ladderPriceFlag != ''">
-            #{ladderPriceFlag},
-        </if>
         <if test="visibility != null and  visibility != ''">
             #{visibility},
         </if>
@@ -150,9 +133,6 @@
         <if test="step != null and  step != ''">
             #{step},
         </if>
-        <if test="costPrice != null and  costPrice != ''">
-            #{costPrice},
-        </if>
         <if test="provinceIds != null and  provinceIds != ''">
             #{provinceIds},
         </if>
@@ -181,11 +161,7 @@
         update product set
         shopID = #{shopId}, name = #{name}, aliasName = #{aliasName}, commodityType = #{commodityType},
         bigTypeId = #{bigTypeId}, smallTypeId = #{smallTypeId}, tinyTypeId = #{tinyTypeId}, mainImage = #{mainImage},
-        brandId = #{brandId}, productType = #{productType}, tags = #{tags}, unit = #{unit}, normalPrice =
-        #{normalPrice},
-        price = #{price}, price = #{price}, includedTax = #{includedTax}, minBuyNumber = #{minBuyNumber}, stock
-        =#{stock},
-        newProductType=#{newProductType},
+        brandId = #{brandId}, productType = #{productType}, tags = #{tags}, includedTax = #{includedTax},newProductType=#{newProductType},
         <if test="qualificationNo !=null and qualificationNo != ''">
             qualificationNo=#{qualificationNo},
         </if>
@@ -198,7 +174,6 @@
         <if test="qualificationLink !=null and qualificationLink != ''">
             qualificationLink=#{qualificationLink},
         </if>
-
         <if test="productCategory != null and  productCategory != ''">
             productCategory = #{productCategory},
         </if>
@@ -226,9 +201,6 @@
         <if test="featuredFlag != null and  featuredFlag != ''">
             featuredFlag = #{featuredFlag},
         </if>
-        <if test="costCheckFlag != null and  costCheckFlag != ''">
-            costCheckFlag = #{costCheckFlag},
-        </if>
         <if test="recommendType != null and  recommendType != ''">
             recommendType = #{recommendType},
         </if>
@@ -238,9 +210,6 @@
         <if test="actFlag != null and  actFlag != ''">
             actFlag = #{actFlag},
         </if>
-        <if test="ladderPriceFlag != null and  ladderPriceFlag != ''">
-            ladderPriceFlag = #{ladderPriceFlag},
-        </if>
         <if test="visibility != null and  visibility != ''">
             visibility = #{visibility},
         </if>
@@ -259,9 +228,6 @@
         <if test="step != null and  step != ''">
             step = #{step},
         </if>
-        <if test="costPrice != null and  costPrice != ''">
-            costPrice = #{costPrice},
-        </if>
         <if test="provinceIds != null and  provinceIds != ''">
             provinceIds = #{provinceIds},
         </if>
@@ -301,6 +267,27 @@
         values (#{name}, #{source}, #{userId}, #{status}, #{delFlag}, #{createDate}, #{updateDate}, #{logo},
                 #{description})
     </insert>
+    <insert id="insertSku">
+        insert into cm_sku
+        (productId,
+         normalPrice,
+         price,
+         costCheckFlag,
+         costprice,
+         stock,
+         minBuyNumber,
+         unit,
+         ladderPriceFlag)
+        values (#{productId},
+                #{normalPrice},
+                #{price},
+                ifnull(#{costCheckFlag}, 1),
+                #{costPrice},
+                #{stock},
+                #{minBuyNumber},
+                #{unit},
+                ifnull(#{ladderPriceFlag}, 0))
+    </insert>
     <update id="updateBrand">
         update cm_brand
         <set>
@@ -370,6 +357,16 @@
         set productCode = #{productCode}
         where productID = #{productId}
     </update>
+    <update id="updateSku">
+        update cm_sku
+        set minBuyNumber=#{minBuyNumber},
+            costPrice=#{costPrice},
+            stock=#{stock},
+            price=#{price},
+            normalPrice=#{normalPrice},
+            unit=#{unit}
+        where skuId = #{skuId}
+    </update>
     <delete id="deleteProductImage">
         delete
         from productimage
@@ -387,8 +384,8 @@
         p.shopID as shopId,
         p.`name` as `name`,
         p.mainImage as image,
-        p.price as price,
-        p.unit as unit,
+        (select price from cm_sku where productId=p.productID order by price asc limit 1) as price,
+        (select unit from cm_sku where productId=p.productID order by price asc limit 1) as unit,
         p.priceFlag as priceFlag,
         IFNULL(p.visibility,3) as visibility,
         p.productType
@@ -402,21 +399,20 @@
         order by p.productID desc limit 4
     </select>
     <select id="getShopProductsSelect" resultType="com.caimei365.commodity.model.vo.ProductItemVo">
-        select
+        select DISTINCT
         p.productID as productId,
         p.actStatus,
         p.name,
         p.aliasName,
         p.mainImage as image,
-        p.unit,
+        (select unit from cm_sku where productId=p.productId order by price asc LIMIT 1) as unit,
         p.productCode as code,
         p.priceFlag,
-        p.price,
+        (select price from cm_sku where productId=p.productId order by price asc LIMIT 1) as price,
+        (select normalPrice from cm_sku where productId=p.productId order by price asc LIMIT 1) as normalPrice,
         p.searchKey as keyword,
-        p.minBuyNumber as minBuyNumber,
-        p.maxBuyNumber as maxBuyNumber,
-        p.ladderPriceFlag,
-        p.normalPrice,
+        (select minBuyNumber from cm_sku where productId=p.productId order by price asc LIMIT 1) as minBuyNumber,
+        (select ladderPriceFlag from cm_sku where productId=p.productId order by price asc LIMIT 1) as ladderPriceFlag,
         p.step,
         p.shopID as shopId,
         p.taxPoint as taxRate,
@@ -518,7 +514,7 @@
                aliasName,
                commodityType,
                mainImage,
-               stock,
+               (select stock from cm_sku where productId=p.productId order by price asc LIMIT 1) as stock,
                invoiceType,
                bigTypeID                 as bigTypeId,
                smallTypeID               as smallTypeId,
@@ -528,23 +524,23 @@
                brandID                   as brandId,
                productType,
                tags,
-               unit,
-               normalPrice,
-               price,
+               (select unit from cm_sku where productId=p.productId order by price asc LIMIT 1)as unit,
+               (select normalPrice from cm_sku where productId=p.productId order by price asc LIMIT 1)as normalPrice,
+               (select price from cm_sku where productId=p.productId order by price asc LIMIT 1)as price,
                includedTax,
-               minBuyNumber,
+               (select minBuyNumber from cm_sku where productId=p.productId order by price asc LIMIT 1)as minBuyNumber,
                productCategory,
                serviceNumber,
                supplierTaxPoint,
                priceFlag,
                actFlag,
-               ladderPriceFlag,
+               (select ladderPriceFlag from cm_sku where productId=p.productId order by price asc LIMIT 1) as ladderPriceFlag,
                addTime,
                hasSkuFlag,
                sellNumber,
                sortIndex,
                featuredFlag,
-               costCheckFlag,
+               (select costCheckFlag from cm_sku where productId=p.productId order by price asc LIMIT 1)as costCheckFlag,
                recommendType,
                machineType,
                productCode,
@@ -553,18 +549,18 @@
                searchKey,
                allAreaFlag,
                step,
-               costPrice,
+               (select costPrice from cm_sku where productId=p.productId order by price asc LIMIT 1)as costPrice,
                provinceIds,
                qualificationImg,
                trainingMethod,
                trainingType,
                trainingFee,
                ifnull(newProductType, 2) as newProductType,
-                qualificationNo as qualificationNo,
-                productName as productName,
-               qualificationTime as qualificationTime,
-               qualificationLink as qualificationLink
-        from product
+               qualificationNo           as qualificationNo,
+               productName               as productName,
+               qualificationTime         as qualificationTime,
+               qualificationLink         as qualificationLink
+        from product p
         where productID = #{productId}
     </select>
     <select id="getBrandNameById" resultType="java.lang.String">
@@ -715,15 +711,26 @@
     </select>
 
     <select id="listingFee" resultType="java.lang.Integer">
-        SELECT COUNT(*) FROM `cm_discern_receipt` WHERE newReceiptType=1 AND shopID=#{shopID}
+        SELECT COUNT(*)
+        FROM `cm_discern_receipt`
+        WHERE newReceiptType = 1
+          AND shopID = #{shopID}
     </select>
 
     <select id="listingfeeExpire" resultType="java.lang.Integer">
-        SELECT COUNT(*) FROM `cm_discern_receipt` WHERE newReceiptType=1 AND shopID=#{shopID} AND NOW()> DATE_ADD(receiptDate, INTERVAL 1 YEAR)
+        SELECT COUNT(*)
+        FROM `cm_discern_receipt`
+        WHERE newReceiptType = 1
+          AND shopID = #{shopID}
+          AND NOW() > DATE_ADD(receiptDate, INTERVAL 1 YEAR)
     </select>
 
     <select id="receStatct" resultType="java.lang.Integer">
-        SELECT COUNT(*) FROM `cm_discern_receipt` WHERE newReceiptType=1 AND shopID=#{shopID} AND receStatct=2
+        SELECT COUNT(*)
+        FROM `cm_discern_receipt`
+        WHERE newReceiptType = 1
+          AND shopID = #{shopID}
+          AND receStatct = 2
     </select>
 
 </mapper>

+ 1 - 7
src/main/resources/mapper/UserLikeMapper.xml

@@ -38,15 +38,9 @@
                p.name,
                p.aliasName,
                p.mainImage       AS image,
-               p.unit,
                p.productCode     AS CODE,
                p.priceFlag,
-               p.price,
                p.searchKey       AS keyword,
-               p.minBuyNumber    AS minBuyNumber,
-               p.maxBuyNumber    AS maxBuyNumber,
-               p.ladderPriceFlag,
-               p.normalPrice,
                p.step,
                p.shopID          AS shopId,
                p.taxPoint        AS taxRate,
@@ -62,7 +56,7 @@
                p.visibility      AS visibility,
                p.productType
         FROM product p
-                 LEFT JOIN cm_product_userlike cpu ON p.productID = cpu.productID
+        LEFT JOIN cm_product_userlike cpu ON p.productID = cpu.productID
         WHERE p.validFlag = '2'
           AND cpu.userLike = '1'
           AND cpu.userID = #{userId}