Browse Source

呵呵商城sku

zhijiezhao 2 years ago
parent
commit
9883059d41

+ 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),

+ 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);
 }

+ 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;
+}

+ 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
      */

+ 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
      */

+ 50 - 52
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,45 +181,69 @@ 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())));
@@ -244,11 +251,11 @@ public class HeheServiceImpl implements HeheService {
             // 售价税费
             BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
             BigDecimal price = MathUtil.add(product.getPrice(), addedValueTax);
-            product.setPrice(price);
+            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);
+            sku.setNormalPrice(price);
         }
         // 查询用户的注册时间
         Date registerTime = heheMapper.getUserRegisterTime(userId);
@@ -267,7 +274,7 @@ public class HeheServiceImpl implements HeheService {
         List<HeheCouponVo> unableCouponList = new ArrayList<>();
         if (couponList.size() > 0) {
             // 有可用优惠券
-            couponList.forEach(coupon->{
+            couponList.forEach(coupon -> {
                 if (1 == coupon.getNoThresholdFlag() || MathUtil.compare(product.getPrice(), coupon.getTouchPrice()) >= 0) {
                     ableCouponList.add(coupon);
                 } else {
@@ -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) {

+ 103 - 75
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
@@ -73,60 +73,54 @@
             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 chcp.skuId,chcp.productId, chcp.price, chcp.limitedNum, chcp.unlimitedFlag, chcp.memberNum
         from cm_hehe_collage_product chcp
-        where chcp.productId = #{productID} and chcp.status = 1
+        where chcp.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 +132,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,7 +142,9 @@
         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>
@@ -155,9 +152,11 @@
         select a.discountPrice, a.productId, chda.offlineTime
         from hehe_discount_activity_product a
                  left join cm_hehe_discount_activity chda on a.activityId = chda.id
-        where a.productId = #{productId}
+        where a.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 +176,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 +191,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 +208,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 +227,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 +241,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 +288,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 +320,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_sku cs
+        left join cm_hehe_sku chs on cs.skuId = chs.skuId
+        where cs.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>