Browse Source

呵呵sku版本

zhijiezhao 2 years ago
parent
commit
62f497fe7a
26 changed files with 386 additions and 325 deletions
  1. 5 4
      src/main/java/com/caimei/controller/OrderSubmitApi.java
  2. 20 1
      src/main/java/com/caimei/controller/ShoppingCartApi.java
  3. 2 2
      src/main/java/com/caimei/mapper/CollageMapper.java
  4. 4 4
      src/main/java/com/caimei/mapper/OrderSubmitMapper.java
  5. 10 8
      src/main/java/com/caimei/mapper/ProductMapper.java
  6. 5 3
      src/main/java/com/caimei/mapper/ShoppingCartMapper.java
  7. 3 0
      src/main/java/com/caimei/model/dto/CartDto.java
  8. 2 0
      src/main/java/com/caimei/model/po/CmCartPo.java
  9. 1 0
      src/main/java/com/caimei/model/po/CmHeHeProductPo.java
  10. 2 0
      src/main/java/com/caimei/model/po/CmHeheCollageProductPo.java
  11. 1 0
      src/main/java/com/caimei/model/po/CmOrderProductPo.java
  12. 4 0
      src/main/java/com/caimei/model/vo/CartProductVo.java
  13. 4 0
      src/main/java/com/caimei/model/vo/CollageDetailsVo.java
  14. 1 0
      src/main/java/com/caimei/model/vo/OrderProductVo.java
  15. 3 1
      src/main/java/com/caimei/service/OrderSubmitService.java
  16. 2 0
      src/main/java/com/caimei/service/ShoppingCartService.java
  17. 1 1
      src/main/java/com/caimei/service/impl/OrderServiceImpl.java
  18. 22 21
      src/main/java/com/caimei/service/impl/OrderSubmitServiceImpl.java
  19. 11 4
      src/main/java/com/caimei/service/impl/ShoppingCartServiceImpl.java
  20. 1 1
      src/main/resources/config/dev/application-dev.yml
  21. 10 9
      src/main/resources/mapper/CollageMapper.xml
  22. 0 2
      src/main/resources/mapper/CouponMapper.xml
  23. 2 0
      src/main/resources/mapper/OrderMapper.xml
  24. 138 130
      src/main/resources/mapper/OrderSubmitMapper.xml
  25. 51 45
      src/main/resources/mapper/ProductMapper.xml
  26. 81 89
      src/main/resources/mapper/ShoppingCartMapper.xml

+ 5 - 4
src/main/java/com/caimei/controller/OrderSubmitApi.java

@@ -38,14 +38,15 @@ public class OrderSubmitApi {
             @ApiImplicitParam(name = "userId", value = "机构用户id", required = true),
             @ApiImplicitParam(name = "cartIds", value = "购物车ID串用逗号隔开", required = false),
             @ApiImplicitParam(name = "productId", value = "立即购买商品ID", required = false),
+            @ApiImplicitParam(name = "skuId", value = "立即购买商品skuId", required = false),
             @ApiImplicitParam(name = "productCount", value = "立即购买商品数量", required = false),
             @ApiImplicitParam(name = "heUserId", value = "分销者用户id", required = false),
             @ApiImplicitParam(name = "couponId", value = "领券购买的优惠券id", required = false),
             @ApiImplicitParam(name = "collageFlag", value = "是否拼团购买:0不拼团,1拼团", required = false)
     })
     @GetMapping("/confirm")
-    public ResponseJson<Map<String, Object>> orderConfirm(Integer userId, String cartIds, Integer productId, Integer productCount, Integer heUserId, Integer couponId, Integer collageFlag) {
-        return orderSubmitService.orderConfirm(userId, cartIds, productId, productCount, heUserId, couponId, collageFlag);
+    public ResponseJson<Map<String, Object>> orderConfirm(Integer userId, String cartIds, Integer skuId, Integer productId, Integer productCount, Integer heUserId, Integer couponId, Integer collageFlag) {
+        return orderSubmitService.orderConfirm(userId, cartIds, skuId, productId, productCount, heUserId, couponId, collageFlag);
     }
 
     /**
@@ -69,8 +70,8 @@ public class OrderSubmitApi {
      *               *                     "note":备注,
      *               *                     "splitCode":分账号,
      *               *                     "productInfo":[   // 商品id,数量,分销者userId
-     *               *                         {"productId": 2789, "productNum": 1,"heUserId":1010},
-     *               *                         {"productId": 2789, "productNum": 1,"heUserId":0}
+     *               *                         {"skuId": 2789, "productNum": 1,"heUserId":1010},
+     *               *                         {"skuId": 2789, "productNum": 1,"heUserId":0}
      *               *                      ]
      *               *                   },
      *               *                   {多个供应商商品数据结构同上}

+ 20 - 1
src/main/java/com/caimei/controller/ShoppingCartApi.java

@@ -1,14 +1,17 @@
 package com.caimei.controller;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.CartDto;
 import com.caimei.model.vo.OrderProductVo;
 import com.caimei.service.ShoppingCartService;
+import com.caimei.util.HttpRequest;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
 import io.swagger.annotations.ApiOperation;
 import lombok.RequiredArgsConstructor;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
@@ -27,13 +30,29 @@ import java.util.Map;
 public class ShoppingCartApi {
     private final ShoppingCartService shoppingCartService;
 
+    @Value("${caimei.cloudApi}")
+    private String cloudApi;
+
+    @ApiOperation("购物车重选")
+    @PostMapping("/check/sku")
+    public ResponseJson checkOldCart(@RequestBody String param) {
+        JSONObject paramsMap = JSON.parseObject(param);
+        Integer cartId = (Integer) paramsMap.get("cartId");
+        Integer newSkuId = (Integer) paramsMap.get("newSkuId");
+        Integer count = (Integer) paramsMap.get("count");
+        if (null == cartId || null == newSkuId || null == count) {
+            return ResponseJson.error("参数异常", null);
+        }
+        return shoppingCartService.checkOldCart(cartId, newSkuId, count);
+    }
+
     /**
      * 加入购物车
      */
     @ApiOperation("加入购物车")
     @PostMapping("/add/cart")
     public synchronized ResponseJson<Integer> addShoppingCart(@RequestBody CartDto cart) {
-        if (cart.getUserId() == null || cart.getProductId() == null || cart.getProductCount() == null) {
+        if (null == cart.getSkuId() || null == cart.getUserId() || null == cart.getProductCount()) {
             return ResponseJson.error("参数异常", null);
         }
         return shoppingCartService.addShoppingCart(cart);

+ 2 - 2
src/main/java/com/caimei/mapper/CollageMapper.java

@@ -21,10 +21,10 @@ public interface CollageMapper {
 
     /**
      * 查找拼团商品
-     * @param productID
+     * @param skuId
      * @return
      */
-    CmHeheCollageProductPo findCollageProduct(Integer productID);
+    CmHeheCollageProductPo findCollageProduct(Integer skuId);
 
     /**
      * 新增拼团记录

+ 4 - 4
src/main/java/com/caimei/mapper/OrderSubmitMapper.java

@@ -46,19 +46,19 @@ public interface OrderSubmitMapper {
     /**
      * 查询商品信息
      *
-     * @param productId
+     * @param skuId
      * @return
      */
-    CmHeHeProductPo getProduct(Integer productId);
+    CmHeHeProductPo getProduct(Integer skuId);
 
     /**
      * 删除购物车
      *
      * @param userId    用户id
-     * @param productId 商品id
+     * @param skuId     skuId
      * @param heUserId  分销者id
      */
-    void deleteCartByProductId(@Param("userId") Integer userId, @Param("productId") Integer productId, @Param("heUserId") Integer heUserId);
+    void deleteCartByProductId(@Param("userId") Integer userId, @Param("skuId") Integer skuId, @Param("heUserId") Integer heUserId);
 
     /**
      * 保存订单信息

+ 10 - 8
src/main/java/com/caimei/mapper/ProductMapper.java

@@ -35,18 +35,18 @@ public interface ProductMapper {
      * 活动阶梯价格
      *
      * @param activityId 活动id
-     * @param productId  商品id
+     * @param skuId      skuId
      * @return
      */
-    List<ActivityLadderVo> getActivityLadderList(@Param("activityId") Integer activityId, @Param("productId") Integer productId);
+    List<ActivityLadderVo> getActivityLadderList(@Param("activityId") Integer activityId, @Param("skuId") Integer skuId);
 
     /**
      * 查询商品详情
      *
-     * @param productId
+     * @param skuId
      * @return
      */
-    ProductDetailsVo findProductByProductId(Integer productId);
+    ProductDetailsVo findProductByProductId(Integer skuId);
 
 
     /**
@@ -59,15 +59,17 @@ public interface ProductMapper {
 
     /**
      * 查找拼团商品
-     * @param productId
+     * @param skuId
      * @return
      */
-    CmHeheCollageProductPo findCollageProduct(Integer productId);
+    CmHeheCollageProductPo findCollageProduct(Integer skuId);
 
     /**
      * 查找商品限时特价
-     * @param productId
+     * @param skuId
      * @return
      */
-    BigDecimal getDiscountPrice(Integer productId);
+    BigDecimal getDiscountPrice(Integer skuId);
+
+    Integer getActivityIdBySkuId(Integer skuId);
 }

+ 5 - 3
src/main/java/com/caimei/mapper/ShoppingCartMapper.java

@@ -20,12 +20,12 @@ public interface ShoppingCartMapper {
     /**
      * 查询购物车
      *
-     * @param userId    机构id
-     * @param productId 商品id
+     * @param userId   机构id
+     * @param skuId    skuId
      * @param heUserId 呵呵分销者id
      * @return
      */
-    CmCartPo findCartProduct(@Param("userId") Integer userId, @Param("productId") Integer productId, @Param("heUserId") Integer heUserId);
+    CmCartPo findCartProduct(@Param("userId") Integer userId, @Param("skuId") Integer skuId, @Param("heUserId") Integer heUserId);
 
     /**
      * 保存购物车
@@ -81,4 +81,6 @@ public interface ShoppingCartMapper {
      * @param cartId
      */
     void deleteCart(String cartId);
+
+    void updateCart(@Param("cartId") Integer cartId, @Param("newSkuId") Integer newSkuId, @Param("count") Integer count);
 }

+ 3 - 0
src/main/java/com/caimei/model/dto/CartDto.java

@@ -20,6 +20,9 @@ public class CartDto implements Serializable {
     @ApiModelProperty("商品id")
     private Integer productId;
 
+    @ApiModelProperty("skuId")
+    private Integer skuId;
+
     /**
      * 用户ID
      */

+ 2 - 0
src/main/java/com/caimei/model/po/CmCartPo.java

@@ -12,6 +12,8 @@ import java.util.Date;
  */
 @Data
 public class CmCartPo implements Serializable {
+    private Integer skuId;
+
     private Integer cartId;
 
     private Integer productID;

+ 1 - 0
src/main/java/com/caimei/model/po/CmHeHeProductPo.java

@@ -15,6 +15,7 @@ import java.util.Date;
 public class CmHeHeProductPo implements Serializable {
     private Integer id;
 
+    private Integer skuId;
     /**
      * 商品Id
      */

+ 2 - 0
src/main/java/com/caimei/model/po/CmHeheCollageProductPo.java

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

+ 1 - 0
src/main/java/com/caimei/model/po/CmOrderProductPo.java

@@ -14,6 +14,7 @@ import java.math.BigDecimal;
 public class CmOrderProductPo implements Serializable {
     private Integer orderProductID;
 
+    private Integer skuId;
     /**
      * 主订单编号
      */

+ 4 - 0
src/main/java/com/caimei/model/vo/CartProductVo.java

@@ -15,6 +15,10 @@ import java.util.List;
  */
 @Data
 public class CartProductVo implements Serializable {
+
+    private Integer stock;
+
+    private Integer skuId;
     /**
      * 购物车id
      */

+ 4 - 0
src/main/java/com/caimei/model/vo/CollageDetailsVo.java

@@ -14,6 +14,10 @@ import java.util.Date;
  */
 @Data
 public class CollageDetailsVo implements Serializable {
+    /**
+     * 拼团商品的skuId
+     */
+    private Integer skuId;
     /**
      * 拼团id
      */

+ 1 - 0
src/main/java/com/caimei/model/vo/OrderProductVo.java

@@ -15,6 +15,7 @@ import java.math.BigDecimal;
 public class OrderProductVo implements Serializable {
     private Integer orderProductId;
 
+    private Integer skuId;
     /**
      * 主订单ID
      */

+ 3 - 1
src/main/java/com/caimei/service/OrderSubmitService.java

@@ -18,12 +18,13 @@ public interface OrderSubmitService {
      * @param userId
      * @param cartIds      购物车ID串用逗号隔开。
      * @param productId    立即购买商品ID
+     * @param skuId        立即购买商品skuId
      * @param productCount 立即购买商品数量
      * @param heUserId     用户id。
      * @param collageFlag
      * @return
      */
-    ResponseJson<Map<String, Object>> orderConfirm(Integer userId, String cartIds, Integer productId, Integer productCount, Integer heUserId, Integer couponId, Integer collageFlag);
+    ResponseJson<Map<String, Object>> orderConfirm(Integer userId, String cartIds, Integer skuId, Integer productId, Integer productCount, Integer heUserId, Integer couponId, Integer collageFlag);
 
     /**
      * 提交订单
@@ -39,6 +40,7 @@ public interface OrderSubmitService {
 
     /**
      * 分享减免
+     *
      * @param userId
      * @param reductionId
      * @param shareType

+ 2 - 0
src/main/java/com/caimei/service/ShoppingCartService.java

@@ -65,4 +65,6 @@ public interface ShoppingCartService {
      * @return
      */
     ResponseJson<String> buyAgainAddCart(Integer orderId);
+
+    ResponseJson checkOldCart( Integer cartId, Integer newSkuId, Integer count);
 }

+ 1 - 1
src/main/java/com/caimei/service/impl/OrderServiceImpl.java

@@ -422,7 +422,7 @@ public class OrderServiceImpl implements OrderService {
         if (2 == collageDetails.getStatus()) {
             collageDetails.setExistNum(collageDetails.getMemberNum());
         }
-        ProductDetailsVo product = productMapper.findProductByProductId(collageDetails.getProductId());
+        ProductDetailsVo product = productMapper.findProductByProductId(collageDetails.getSkuId());
         // 拼团价
         product.setPrice(collageDetails.getPrice());
         collageDetails.setUnit(product.getUnit());

+ 22 - 21
src/main/java/com/caimei/service/impl/OrderSubmitServiceImpl.java

@@ -51,7 +51,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
     private String domain;
 
     @Override
-    public ResponseJson<Map<String, Object>> orderConfirm(Integer userId, String cartIds, Integer productId, Integer productCount, Integer heUserId, Integer couponId, Integer collageFlag) {
+    public ResponseJson<Map<String, Object>> orderConfirm(Integer userId, String cartIds, Integer skuId, Integer productId, Integer productCount, Integer heUserId, Integer couponId, Integer collageFlag) {
         Map<String, Object> confirmData = new HashMap<>(5);
         log.info("<<<<< 结算订单 >>>>>");
         //商品总金额
@@ -81,8 +81,8 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         shopList.forEach(shop -> {
             shop.setLogo(ProductUtils.getImageURL("shopLogo", shop.getLogo(), 0, domain));
             List<CartProductVo> shopProducts = new ArrayList<>();
-            if (productId != null && productId > 0) {
-                CartProductVo cartProduct = orderSubmitMapper.findProductById(productId);
+            if (skuId != null && skuId > 0) {
+                CartProductVo cartProduct = orderSubmitMapper.findProductById(skuId);
                 cartProduct.setNum(productCount);
                 cartProduct.setHeUserId(heUserId);
                 shopProducts.add(cartProduct);
@@ -107,7 +107,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         if (null != couponId) {
             // 领券购买对应优惠券领取标识
             AtomicBoolean couponReceiveFlag = new AtomicBoolean(false);
-            receiveCouponList.forEach(coupon->{
+            receiveCouponList.forEach(coupon -> {
                 if (couponId.equals(coupon.getCouponId())) {
                     couponReceiveFlag.set(true);
                 }
@@ -282,7 +282,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
             if (!CollectionUtils.isEmpty(productInfoList)) {
                 // 遍历所有商品
                 for (Map<String, Integer> productTemp : productInfoList) {
-                    Integer productId = productTemp.get("productId");
+                    Integer skuId = productTemp.get("skuId");
                     Integer productNum = productTemp.get("productNum");
                     Integer heUserId = productTemp.get("heUserId");
                     heUserId = heUserId == null ? 0 : heUserId;
@@ -290,7 +290,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                     productCount += productNum;
 
                     // 获取商品信息
-                    CmHeHeProductPo product = orderSubmitMapper.getProduct(productId);
+                    CmHeHeProductPo product = orderSubmitMapper.getProduct(skuId);
                     if (null == product) {
                         return ResponseJson.error("订单商品数据异常", null);
                     }
@@ -305,14 +305,14 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                     BigDecimal addedValueTax = new BigDecimal(0);
                     int priceType = 0;
                     // 商品参与的活动id
-                    Integer activityId = productMapper.getActivityIdByProductId(productId);
+                    Integer activityId = productMapper.getActivityIdBySkuId(skuId);
                     // 商品参与的限时特价活动
-                    BigDecimal discountPrice = productMapper.getDiscountPrice(productId);
+                    BigDecimal discountPrice = productMapper.getDiscountPrice(skuId);
                     // 内部优惠折扣
                     HeHeDiscountVo discount = productMapper.findProductDiscount(product.getProductId(), userId);
                     if (activityId != null && activityId > 0) {
                         //活动阶梯
-                        List<ActivityLadderVo> ladderList = productMapper.getActivityLadderList(activityId, productId);
+                        List<ActivityLadderVo> ladderList = productMapper.getActivityLadderList(activityId, skuId);
                         if (ladderList != null && ladderList.size() > 0) {
                             priceType = 1;
                             for (ActivityLadderVo ladder : ladderList) {
@@ -323,7 +323,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                         }
                     } else if (collageFlag != null && 1 == collageFlag) {
                         // 拼团价
-                        CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(productId);
+                        CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(skuId);
                         if (collageProduct != null) {
                             priceType = 2;
                             productPrice = collageProduct.getPrice();
@@ -332,14 +332,14 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                         // 限时特价
                         priceType = 3;
                         productPrice = discountPrice;
-                    }  else if (discount != null) {
+                    } else if (discount != null) {
                         // 内部优惠价
                         priceType = 4;
                         // 折扣价
                         BigDecimal disPrice = discount.getDiscountPrice();
                         // 折扣率
                         Integer dis = discount.getDiscount();
-                        if (null != disPrice && disPrice.compareTo(BigDecimal.ZERO)>0) {
+                        if (null != disPrice && disPrice.compareTo(BigDecimal.ZERO) > 0) {
                             productPrice = disPrice;
                         } else if (null != dis && dis > 0) {
                             productPrice = MathUtil.div(MathUtil.mul(product.getPrice(), dis), 100);
@@ -353,7 +353,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                         BigDecimal normalPrice = product.getNormalPrice();
                         if (null != normalPrice) {
                             BigDecimal normalPriceTax = MathUtil.div(MathUtil.mul(normalPrice, product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
-                            product.setNormalPrice(MathUtil.add(normalPrice,normalPriceTax));
+                            product.setNormalPrice(MathUtil.add(normalPrice, normalPriceTax));
                         }
                         product.setPrice(productPrice);
                     }
@@ -372,7 +372,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                     // 判断是否选中比例成本价
                     if (MathUtil.compare(product.getCostProportional(), 0) > 0 && 2 == product.getCostType()) {
                         // 通过售价*比例得到成本价
-                        costPrice = BigDecimal.valueOf(MathUtil.div(MathUtil.mul(productPrice, product.getCostProportional()), 100).floatValue());
+                        costPrice = BigDecimal.valueOf(MathUtil.div(MathUtil.mul(productPrice, product.getCostProportional()), 100, 2).floatValue());
                     }
                     product.setCostPrice(costPrice);
 
@@ -385,8 +385,8 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                     orderProductList.add(orderProduct);
 
                     if (cartType == 1) {
-                        orderSubmitMapper.deleteCartByProductId(user.getUserID(), productId, heUserId);
-                        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>删除用户购物车数据productId:" + productId);
+                        orderSubmitMapper.deleteCartByProductId(user.getUserID(), skuId, heUserId);
+                        log.info(">>>>>>>>>>>>>>>>>>>>>>>>>>删除用户购物车数据productId:" + skuId);
                     }
                 }
             }
@@ -529,7 +529,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         //分摊优惠
         BigDecimal allDiscount = MathUtil.add(couponAmount, reductionAmount);
         AtomicReference<BigDecimal> totalBrokerage = new AtomicReference<>(BigDecimal.ZERO);
-        shopOrderList.forEach(shopOrder-> totalBrokerage.set(MathUtil.add(totalBrokerage, shopOrder.getBrokerage())));
+        shopOrderList.forEach(shopOrder -> totalBrokerage.set(MathUtil.add(totalBrokerage, shopOrder.getBrokerage())));
         shopOrderList.sort((o1, o2) -> o2.getBrokerage().compareTo(o1.getBrokerage()));
         log.info(">>>>>>>>>>>>>>>分摊前总佣金:" + totalBrokerage);
         // 前面子订单的分摊优惠总和
@@ -570,7 +570,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                 BigDecimal bro = so.getBrokerage();
                 so.setRealPay(realPay.doubleValue());
                 so.setEachDiscount(0d);
-                if (MathUtil.compare(bro,charge) < 0) {
+                if (MathUtil.compare(bro, charge) < 0) {
                     onlinePay.set(false);
                 }
             });
@@ -585,7 +585,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
             } else {
                 msg = "抱歉,该商品支付正在调整,暂不支持下单";
             }
-            return ResponseJson.error(-1,msg, null);
+            return ResponseJson.error(-1, msg, null);
         }
 
         for (int i = 0; i < shopOrderList.size(); i++) {
@@ -618,7 +618,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                 //使用阶梯价格的订单商品保存下单时的阶梯价格列表
                 Integer activityId = productMapper.getActivityIdByProductId(orderProduct.getProductID());
                 if (activityId != null && activityId > 0) {
-                    List<ActivityLadderVo> ladderPriceList = productMapper.getActivityLadderList(activityId, orderProduct.getProductID());
+                    List<ActivityLadderVo> ladderPriceList = productMapper.getActivityLadderList(activityId, orderProduct.getSkuId());
                     int ladderNum = 0;
                     for (ActivityLadderVo ladder : ladderPriceList) {
                         ladderNum++;
@@ -706,7 +706,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                 // 拼团发起者,构建拼团记录
                 CmHeheCollagePo collage = new CmHeheCollagePo();
                 CmOrderProductPo orderProductPo = orderProductList.get(0);
-                CmHeheCollageProductPo collageProduct = collageMapper.findCollageProduct(orderProductPo.getProductID());
+                CmHeheCollageProductPo collageProduct = collageMapper.findCollageProduct(orderProductPo.getSkuId());
                 if (null == collageProduct) {
                     //设置手动回滚事务
                     TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
@@ -802,6 +802,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
      */
     private CmOrderProductPo setOrderProduct(Integer productNum, CmHeHeProductPo product, int priceType, BigDecimal productPrice, BigDecimal addedValueTax) {
         CmOrderProductPo orderProduct = new CmOrderProductPo();
+        orderProduct.setSkuId(product.getSkuId());
         orderProduct.setShopID(product.getShopId().longValue());
         orderProduct.setProductID(product.getProductId());
         orderProduct.setOrganizeProductID(product.getId());

+ 11 - 4
src/main/java/com/caimei/service/impl/ShoppingCartServiceImpl.java

@@ -43,7 +43,7 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
     public ResponseJson<Integer> addShoppingCart(CartDto cart) {
         Integer heUserId = cart.getHeUserId();
         heUserId = heUserId == null ? 0 : heUserId;
-        CmCartPo cartPo = shoppingCartMapper.findCartProduct(cart.getUserId(), cart.getProductId(), heUserId);
+        CmCartPo cartPo = shoppingCartMapper.findCartProduct(cart.getUserId(), cart.getSkuId(), heUserId);
         if (cartPo == null) {
             shoppingCartMapper.insertCart(cart);
         } else {
@@ -93,15 +93,15 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
         // 活动id
         Integer activityId = productMapper.getActivityIdByProductId(product.getProductId());
         // 拼团商品
-        CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(product.getProductId());
+        CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(product.getSkuId());
         // 限时特价
-        BigDecimal discountPrice = productMapper.getDiscountPrice(product.getProductId());
+        BigDecimal discountPrice = productMapper.getDiscountPrice(product.getSkuId());
         // 内部优惠折扣
         HeHeDiscountVo discount = productMapper.findProductDiscount(product.getProductId(), userId);
         if (activityId != null && activityId > 0) {
             product.setActiveStatus(1);
             //活动阶梯
-            List<ActivityLadderVo> ladderList = productMapper.getActivityLadderList(activityId, product.getProductId());
+            List<ActivityLadderVo> ladderList = productMapper.getActivityLadderList(activityId, product.getSkuId());
             if (ladderList != null && ladderList.size() > 0) {
                 for (ActivityLadderVo ladder : ladderList) {
                     if (product.getNum() >= ladder.getBuyNum()) {
@@ -220,6 +220,7 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
             if (validFlag == 1) {
                 cart.setProductId(orderProduct.getProductId());
                 cart.setProductCount(orderProduct.getNum());
+                cart.setSkuId(orderProduct.getSkuId());
                 Integer heUserId = orderProduct.getHeUserId();
                 if (heUserId != null && heUserId > 0) {
                     Integer activityId = productMapper.getActivityIdByProductId(orderProduct.getProductId());
@@ -237,6 +238,12 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
         return ResponseJson.success(null);
     }
 
+    @Override
+    public ResponseJson checkOldCart(Integer cartId, Integer newSkuId, Integer count) {
+        shoppingCartMapper.updateCart(cartId,newSkuId,count);
+        return ResponseJson.success();
+    }
+
     @Override
     public void updateNumber(Integer cartId, Integer productCount) {
         shoppingCartMapper.updateByProductCount(cartId, productCount);

+ 1 - 1
src/main/resources/config/dev/application-dev.yml

@@ -73,7 +73,7 @@ caimei:
   #支付链接重定向地址
   redirectLink: https://mall2c-b.caimei365.com/PayOrder/jumpPage
   #微服务网关地址
-  cloudApi: http://192.168.2.100:18002
+  cloudApi: http://localhost:18002
   #延时分账异步回调地址
   delayedSplittingUrl: https://mall2c-b.caimei365.com/PayOrder/delayedSplittingCallback
   #图片服务器

+ 10 - 9
src/main/resources/mapper/CollageMapper.xml

@@ -26,9 +26,10 @@
     </insert>
 
     <select id="findCollageProduct" resultType="com.caimei.model.po.CmHeheCollageProductPo">
-        select chcp.productid, chcp.price, chcp.limitednum, chcp.unlimitedflag, chcp.membernum, chcp.status
+        select chcp.productid, chcs.collagePrice as price, chcp.limitednum, chcp.unlimitedflag, chcp.membernum, chcp.status
         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
     </select>
     <select id="findCollage" resultType="com.caimei.model.po.CmHeheCollagePo">
         select id, productId, price, memberNum, status, startTime, completeTime, endTime
@@ -43,12 +44,13 @@
         where chcm.orderId = #{orderId}
     </select>
     <select id="getCollageDetails" resultType="com.caimei.model.vo.CollageDetailsVo">
-        select chc.id                           as collageId,
+        select chc.skuId,
+               chc.id                           as collageId,
                chc.productId,
                p.mainImage                      as productImage,
                p.name                           as productName,
                chc.price,
-               chp.price                        as normalPrice,
+               (select price from cm_hehe_sku where productId=chc.productId order by price asc limit 1) as normalPrice,
                chc.memberNum,
                count(chcm.id)                   as existNum,
                (chc.memberNum - count(chcm.id)) as needNum,
@@ -57,11 +59,10 @@
                limitedNum,
                unlimitedFlag
         from cm_hehe_collage chc
-                 left join cm_hehe_collage_member chcm on chc.id = chcm.collageId
-                 left join cm_order co on chcm.orderId = co.orderID
-                 left join cm_hehe_collage_product chcp on chc.productId = chcp.productId
-                 left join product p on chcp.productId = p.productID
-                 left join cm_hehe_product chp on p.productID = chp.productId
+        left join cm_hehe_collage_member chcm on chc.id = chcm.collageId
+        left join cm_order co on chcm.orderId = co.orderID
+        left join cm_hehe_collage_product chcp on chc.productId = chcp.productId
+        left join product p on chcp.productId = p.productID
         where chc.id = #{collageId}
           and co.receiptStatus = 3
     </select>

+ 0 - 2
src/main/resources/mapper/CouponMapper.xml

@@ -179,12 +179,10 @@
     <select id="getCouponProduct" resultType="com.caimei.model.vo.ProductVo">
         SELECT
         chp.productId,
-        chp.price,
         chp.includedTax,
         chp.invoiceType,
         chp.clubTaxPoint,
         p.name,
-        P.unit,
         p.mainImage
         FROM
             cm_hehe_coupon_product chcp

+ 2 - 0
src/main/resources/mapper/OrderMapper.xml

@@ -119,6 +119,7 @@
 
     <select id="findOrderProduct" resultType="com.caimei.model.vo.OrderProductVo">
         SELECT
+          cop.skuID as skuId,
           cop.orderProductID AS orderProductId,
           cop.orderID AS orderId,
           cop.shopOrderID AS shopOrderId,
@@ -551,6 +552,7 @@
 
     <select id="findOrderProductAll" resultType="com.caimei.model.vo.OrderProductVo">
         SELECT
+          skuID as skuId,
           productID AS productId,
           heUserId,
           name,

+ 138 - 130
src/main/resources/mapper/OrderSubmitMapper.xml

@@ -5,97 +5,101 @@
 <mapper namespace="com.caimei.mapper.OrderSubmitMapper">
     <select id="findShopByCartIds" resultType="com.caimei.model.vo.ShopVo">
         SELECT DISTINCT
-          s.shopID AS shopId,
-          s.name,
-          s.logo,
-          p.splitCode
+        s.shopID AS shopId,
+        s.name,
+        s.logo,
+        p.splitCode
         FROM
-          cm_cart cc
-          LEFT JOIN product p ON cc.productID = p.productID
-          LEFT JOIN shop s ON p.shopID = s.shopID
+        cm_cart cc
+        LEFT JOIN product p ON cc.productID = p.productID
+        LEFT JOIN shop s ON p.shopID = s.shopID
         WHERE
-          cc.cm_cartID IN
+        cc.cm_cartID IN
         <foreach item="cartId" index="index" collection="cartIds" open="(" separator="," close=")">
             #{cartId}
         </foreach>
         ORDER BY
-          cc.addTime DESC
+        cc.addTime DESC
     </select>
 
     <select id="findByShopCartProduct" resultType="com.caimei.model.vo.CartProductVo">
         SELECT
-          cc.cm_cartID AS cartId,
-          cc.productID AS productId,
-          cc.productCount as num,
-          cc.heUserId,
-          chp.price,
-          chp.price as normalPrice,
-          chp.includedTax,
-          chp.invoiceType,
-          chp.clubTaxPoint,
-          p.name,
-          p.shopID AS shopId,
-          p.mainImage as productImage,
-          p.unit as productUnit
-        FROM
-          cm_cart cc
-          LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
-          LEFT JOIN product p ON cc.productID = p.productID
+        cc.skuId,
+        cc.cm_cartID AS cartId,
+        cc.productID AS productId,
+        cc.productCount as num,
+        cc.heUserId,
+        chs.price,
+        chs.price as normalPrice,
+        chp.includedTax,
+        chp.invoiceType,
+        chp.clubTaxPoint,
+        p.name,
+        p.shopID AS shopId,
+        p.mainImage as productImage,
+        cs.unit as productUnit
+        FROM cm_cart cc
+        LEFT JOIN cm_sku cs on cc.skuId=cs.skuId
+        LEFT JOIN cm_hehe_sku chs on cc.skuId=chs.skuId
+        LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
+        LEFT JOIN product p ON cc.productID = p.productID
         WHERE
-          chp.validFlag = 1
-          AND p.shopID = #{shopId}
-          and p.splitCode = #{splitCode}
-          AND cc.cm_cartID IN
+        chp.validFlag = 1
+        AND p.shopID = #{shopId}
+        and p.splitCode = #{splitCode}
+        AND cc.cm_cartID IN
         <foreach item="cartId" index="index" collection="cartIds" open="(" separator="," close=")">
             #{cartId}
         </foreach>
     </select>
 
     <select id="findUser" resultType="com.caimei.model.po.UserPo">
-        SELECT
-          userID,
-          mobile,
-          bindMobile,
-          userName,
-          name
-        FROM
-          user
-        WHERE
-          userID = #{userId}
+        SELECT userID,
+               mobile,
+               bindMobile,
+               userName,
+               name
+        FROM user
+        WHERE userID = #{userId}
     </select>
 
     <select id="getProduct" resultType="com.caimei.model.po.CmHeHeProductPo">
-        SELECT
-          chp.id,
-          chp.productId,
-          chp.price,
-          chp.price as normalPrice,
-          chp.includedTax,
-          chp.invoiceType,
-          p.costCheckFlag AS costType,
-          chp.clubTaxPoint,
-          chp.shopTaxPoint,
-          p.costPrice,
-          p.costProportional,
-          p.shopID AS shopId,
-          p.unit,
-          p.name,
-          p.mainImage,
-          p.splitCode,
-          s.name AS shopName
-        FROM
-          cm_hehe_product chp
-          LEFT JOIN product p ON chp.productId = p.productID
-          LEFT JOIN shop s ON p.shopID = s.shopID
-        WHERE
-          chp.productId = #{productId}
+        SELECT cs.skuId,
+               chp.id,
+               chp.productId,
+               chs.price,
+               chs.price       as normalPrice,
+               chp.includedTax,
+               chp.invoiceType,
+               cs.costCheckFlag AS costType,
+               chp.clubTaxPoint,
+               chp.shopTaxPoint,
+               cs.costPrice,
+               cs.costProportional,
+               p.shopID        AS shopId,
+               cs.unit,
+               p.name,
+               p.mainImage,
+               p.splitCode,
+               s.name          AS shopName
+        FROM cm_hehe_product chp
+        LEFT JOIN cm_sku cs on cs.productId = chp.productId
+        LEFT JOIN cm_hehe_sku chs on cs.skuId=chs.skuId
+        LEFT JOIN product p ON chp.productId = p.productID
+        LEFT JOIN shop s ON p.shopID = s.shopID
+        WHERE cs.skuId = #{skuId}
     </select>
 
     <delete id="deleteCartByProductId">
-        DELETE FROM cm_cart WHERE userID = #{userId} AND productID = #{productId} AND heUserId = #{heUserId}
+        DELETE
+        FROM cm_cart
+        WHERE userID = #{userId}
+          AND skuId = #{skuId}
+          AND heUserId = #{heUserId}
     </delete>
 
-    <insert id="insertOrder" keyColumn="orderID" keyProperty="orderID" parameterType="com.caimei.model.po.CmOrderPo" useGeneratedKeys="true">
+    <insert id="insertOrder" keyColumn="orderID" keyProperty="orderID" parameterType="com.caimei.model.po.CmOrderPo"
+            useGeneratedKeys="true">
         insert into cm_order
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="orderNo != null">
@@ -440,19 +444,15 @@
     </insert>
 
     <select id="findMaxShopOrderNo" resultType="java.lang.String">
-        SELECT
-          shopOrderNo
-        FROM
-          cm_shop_order
-        WHERE
-          orderID = #{orderId}
-        ORDER BY
-          shopOrderNo DESC
-        LIMIT
-          1
+        SELECT shopOrderNo
+        FROM cm_shop_order
+        WHERE orderID = #{orderId}
+        ORDER BY shopOrderNo DESC
+        LIMIT 1
     </select>
 
-    <insert id="insertShopOrder" keyColumn="shopOrderID" keyProperty="shopOrderID" parameterType="com.caimei.model.po.CmShopOrderPo" useGeneratedKeys="true">
+    <insert id="insertShopOrder" keyColumn="shopOrderID" keyProperty="shopOrderID"
+            parameterType="com.caimei.model.po.CmShopOrderPo" useGeneratedKeys="true">
         insert into cm_shop_order
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="shopOrderNo != null">
@@ -910,9 +910,13 @@
         </trim>
     </insert>
 
-    <insert id="insertOrderProduct" keyColumn="orderProductID" keyProperty="orderProductID" parameterType="com.caimei.model.po.CmOrderProductPo" useGeneratedKeys="true">
+    <insert id="insertOrderProduct" keyColumn="orderProductID" keyProperty="orderProductID"
+            parameterType="com.caimei.model.po.CmOrderProductPo" useGeneratedKeys="true">
         insert into cm_order_product
         <trim prefix="(" suffix=")" suffixOverrides=",">
+            <if test="skuId != null">
+                skuId,
+            </if>
             <if test="orderNo != null">
                 orderNo,
             </if>
@@ -1095,6 +1099,9 @@
             </if>
         </trim>
         <trim prefix="values (" suffix=")" suffixOverrides=",">
+            <if test="skuId != null">
+                #{skuId},
+            </if>
             <if test="orderNo != null">
                 #{orderNo,jdbcType=VARCHAR},
             </if>
@@ -1278,13 +1285,10 @@
         </trim>
     </insert>
 
-    <insert id="insertOrderProductLadderPrice"  keyColumn="id" keyProperty="id" useGeneratedKeys="true" parameterType="com.caimei.model.po.OrderProductLadderPricePo">
-        insert into order_product_ladder_price (
-            orderProductId, ladderNum, buyNum, buyPrice, createDate
-        )
-        values (
-            #{orderProductId},#{ladderNum},#{buyNum},#{buyPrice},#{createDate}
-        )
+    <insert id="insertOrderProductLadderPrice" keyColumn="id" keyProperty="id" useGeneratedKeys="true"
+            parameterType="com.caimei.model.po.OrderProductLadderPricePo">
+        insert into order_product_ladder_price (orderProductId, ladderNum, buyNum, buyPrice, createDate)
+        values (#{orderProductId}, #{ladderNum}, #{buyNum}, #{buyPrice}, #{createDate})
     </insert>
 
     <update id="updateOrder" parameterType="com.caimei.model.po.CmOrderPo">
@@ -1448,24 +1452,26 @@
         where id = #{receiveCouponId}
     </update>
     <update id="updateReductionUserId">
-        update cm_hehe_reduction_user set orderId = #{orderId} where id = #{reductionUserId}
+        update cm_hehe_reduction_user
+        set orderId = #{orderId}
+        where id = #{reductionUserId}
     </update>
 
     <select id="findByAddressId" resultType="com.caimei.model.vo.AddressVo">
-        SELECT a.addressID AS addressId,
-               a.userID AS userId,
+        SELECT a.addressID  AS addressId,
+               a.userID     AS userId,
                a.shouHuoRen,
-               a.townID AS townId,
+               a.townID     AS townId,
                a.address,
                a.postalCode,
                a.phone,
                a.mobile,
                a.defaultFlag,
-               c.cityID AS cityId,
+               c.cityID     AS cityId,
                p.provinceID AS provinceId,
-               t.name AS townName,
-               c.name AS cityName,
-               p.name AS provinceName
+               t.name       AS townName,
+               c.name       AS cityName,
+               p.name       AS provinceName
         FROM address a
                  LEFT JOIN town t ON t.townID = a.townID
                  LEFT JOIN city c ON c.cityID = t.cityID
@@ -1473,7 +1479,8 @@
         WHERE a.addressID = #{addressId}
     </select>
 
-    <insert id="insertUserInfo" keyColumn="id" keyProperty="id" parameterType="com.caimei.model.po.BpOrderUserInfoPo" useGeneratedKeys="true">
+    <insert id="insertUserInfo" keyColumn="id" keyProperty="id" parameterType="com.caimei.model.po.BpOrderUserInfoPo"
+            useGeneratedKeys="true">
         insert into bp_order_userinfo
         <trim prefix="(" suffix=")" suffixOverrides=",">
             <if test="orderId != null">
@@ -1559,47 +1566,46 @@
         </trim>
     </insert>
     <insert id="insertCouponOrderRecord">
-        INSERT INTO cm_hehe_coupon_order_record (orderId, receiveCouponId, couponType, couponAmount, touchPrice, createDate)
+        INSERT INTO cm_hehe_coupon_order_record (orderId, receiveCouponId, couponType, couponAmount, touchPrice,
+                                                 createDate)
         VALUES (#{orderId}, #{receiveCouponId}, #{couponType}, #{couponAmount}, #{touchPrice}, #{createDate})
     </insert>
-    <insert id="insertReductionUser" keyColumn="id" keyProperty="reductionUserId" parameterType="com.caimei.model.po.ReductionUserPo" useGeneratedKeys="true">
+    <insert id="insertReductionUser" keyColumn="id" keyProperty="reductionUserId"
+            parameterType="com.caimei.model.po.ReductionUserPo" useGeneratedKeys="true">
         insert into cm_hehe_reduction_user (userId, reductionId, shareType, touchPrice, reductionAmount, shareTime)
         values (#{userId}, #{reductionId}, #{shareType}, #{touchPrice}, #{reducedAmount}, NOW())
     </insert>
 
     <select id="findShopByProductId" resultType="com.caimei.model.vo.ShopVo">
-        SELECT
-          s.shopID AS shopId,
-          s.name,
-          s.logo,
-          p.splitCode
-        FROM
-          cm_hehe_product chp
-          LEFT JOIN product p ON chp.productId = p.productID
-          LEFT JOIN shop s ON p.shopID = s.shopID
-        WHERE
-          chp.productId = #{productId}
+        SELECT s.shopID AS shopId,
+               s.name,
+               s.logo,
+               p.splitCode
+        FROM cm_hehe_product chp
+                 LEFT JOIN product p ON chp.productId = p.productID
+                 LEFT JOIN shop s ON p.shopID = s.shopID
+        WHERE chp.productId = #{productId}
           AND chp.validFlag = 1
     </select>
 
     <select id="findProductById" resultType="com.caimei.model.vo.CartProductVo">
-        SELECT
-          chp.productId,
-          chp.price,
-          chp.price as normalPrice,
-          chp.includedTax,
-          chp.invoiceType,
-          chp.clubTaxPoint,
-          p.name,
-          p.shopID AS shopId,
-          p.mainImage as productImage,
-          p.unit as productUnit
-        FROM
-          cm_hehe_product chp
-          LEFT JOIN product p ON chp.productId = p.productID
-        WHERE
-          chp.validFlag = 1
-          AND chp.productId = #{productId}
+        SELECT cs.skuId,
+               chp.productId,
+               chs.price,
+               chs.price   as normalPrice,
+               chp.includedTax,
+               chp.invoiceType,
+               chp.clubTaxPoint,
+               p.name,
+               p.shopID    AS shopId,
+               p.mainImage as productImage,
+               cs.unit      as productUnit
+        FROM cm_hehe_product chp
+        LEFT JOIN product p ON chp.productId = p.productID
+        LEFT JOIN cm_sku cs on p.productID=cs.productId
+        LEFT JOIN cm_hehe_sku chs on chs.skuId=cs.skuId
+        WHERE chp.validFlag = 1
+          AND cs.skuId = #{skuId}
     </select>
     <select id="findCartProducts" resultType="com.caimei.model.vo.CartProductVo">
         SELECT
@@ -1607,14 +1613,12 @@
         cc.productID AS productId,
         cc.productCount as num,
         cc.heUserId,
-        chp.price,
         chp.includedTax,
         chp.invoiceType,
         chp.clubTaxPoint,
         p.name,
         p.shopID AS shopId,
         p.mainImage as productImage,
-        p.unit as productUnit
         FROM
         cm_cart cc
         LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
@@ -1628,7 +1632,9 @@
     </select>
     <select id="findCurrentReduction" resultType="com.caimei.model.vo.ReductionVo">
         select id as reductionId, reducedAmount, touchPrice, shareNum
-        from cm_hehe_reduction where NOW() <![CDATA[  >=  ]]> startTime and NOW() <![CDATA[  <=  ]]> endTime
+        from cm_hehe_reduction
+        where NOW() <![CDATA[  >=  ]]> startTime
+          and NOW() <![CDATA[  <=  ]]> endTime
     </select>
     <select id="findShareNum" resultType="java.lang.Integer">
         select count(*)
@@ -1637,8 +1643,10 @@
           and reductionId = #{reductionId}
     </select>
     <select id="findReduction" resultType="com.caimei.model.vo.ReductionVo">
-        select chr.id as reductionId, reducedAmount, chr.touchPrice from cm_hehe_reduction chr
-            left join cm_hehe_reduction_user chru on chr.id = chru.reductionId
-        where chru.id = #{reductionUserId} and chru.orderId is null
+        select chr.id as reductionId, reducedAmount, chr.touchPrice
+        from cm_hehe_reduction chr
+                 left join cm_hehe_reduction_user chru on chr.id = chru.reductionId
+        where chru.id = #{reductionUserId}
+          and chru.orderId is null
     </select>
 </mapper>

+ 51 - 45
src/main/resources/mapper/ProductMapper.xml

@@ -17,13 +17,10 @@
 
 
     <select id="getActivityIdByProductId" resultType="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
@@ -32,45 +29,40 @@
     </select>
 
     <select id="getActivityLadderList" resultType="com.caimei.model.vo.ActivityLadderVo">
-        SELECT
-            buyNum,
-            buyPrice
-        FROM
-            cm_hehe_activity_ladder
-        WHERE
-            activityId = #{activityId}
-          AND productId = #{productId}
-        ORDER BY
-            ladderNum
+        SELECT buyNum,
+               buyPrice
+        FROM cm_hehe_activity_ladder
+        WHERE activityId = #{activityId}
+          AND skuId = #{skuId}
+        ORDER BY buyPrice desc
     </select>
 
     <select id="findProductByProductId" resultType="com.caimei.model.vo.ProductDetailsVo">
-        SELECT
-            a.productId,
-            a.price,
-            a.price as normalPrice,
-            a.includedTax,
-            a.invoiceType,
-            a.clubTaxPoint,
-            a.validFlag,
-            p.name,
-            p.mainImage,
-            p.brandID AS "brandId",
-            p.bigTypeID AS "bigTypeId",
-            p.smallTypeID AS "smallTypeId",
-            p.tinyTypeID AS "tinyTypeId",
-            P.unit,
-            P.stock,
-            p.tags
-        FROM
-            cm_hehe_product a
-                LEFT JOIN product p ON a.productId = p.productID
-        WHERE
-            a.productId = #{productId}
+        SELECT a.productId,
+               chs.price,
+               chs.price     as normalPrice,
+               a.includedTax,
+               a.invoiceType,
+               a.clubTaxPoint,
+               a.validFlag,
+               p.name,
+               p.mainImage,
+               p.brandID     AS "brandId",
+               p.bigTypeID   AS "bigTypeId",
+               p.smallTypeID AS "smallTypeId",
+               p.tinyTypeID  AS "tinyTypeId",
+               cs.unit,
+               cs.stock,
+               p.tags
+        FROM cm_hehe_product a
+                 LEFT JOIN product p ON a.productId = p.productID
+                 LEFT JOIN cm_sku cs ON a.productId = cs.productId
+                 LEFT JOIN cm_hehe_sku chs ON cs.skuId = chs.skuId
+        WHERE chs.skuId = #{skuId}
     </select>
 
     <select id="findProductDiscount" resultType="com.caimei.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
@@ -80,17 +72,31 @@
         limit 1
     </select>
     <select id="findCollageProduct" resultType="com.caimei.model.po.CmHeheCollageProductPo">
-        select chcp.productId, chcp.price, chcp.limitedNum, chcp.unlimitedFlag, chcp.memberNum
+        select chcs.skuId, chcp.productId, chcs.collagePrice, 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
     </select>
     <select id="getDiscountPrice" resultType="java.math.BigDecimal">
-        select a.discountPrice
+        select chds.discountPrice
         from hehe_discount_activity_product a
-                 left join cm_hehe_discount_activity chda on a.activityId = chda.id
-        where a.productId = #{productId}
+        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 chds.skuId = #{skuId}
           and a.status = 1
           and NOW() between chda.onlineTime and chda.offlineTime
     </select>
+    <select id="getActivityIdBySkuId" 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
+          AND a.delFlag = 0
+          AND NOW() BETWEEN cha.beginTime
+            AND cha.endTime
+          AND a.productId = (select cm_sku.productId from cm_sku where skuId = #{productId})
+        limit 1
+    </select>
 
 </mapper>

+ 81 - 89
src/main/resources/mapper/ShoppingCartMapper.xml

@@ -4,122 +4,114 @@
         "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei.mapper.ShoppingCartMapper">
     <select id="findCartProduct" resultType="com.caimei.model.po.CmCartPo">
-        SELECT
-          cm_cartID AS cartId,
-          productID,
-          userID,
-          productCount,
-          addTime,
-          reBuyFlag,
-          heUserId
-        FROM
-          cm_cart
-        WHERE
-          userID = #{userId}
-          AND productID = #{productId}
+        SELECT cm_cartID AS cartId,
+               productID,
+               skuId,
+               userID,
+               productCount,
+               addTime,
+               reBuyFlag,
+               heUserId
+        FROM cm_cart
+        WHERE userID = #{userId}
+          AND skuId = #{skuId}
           AND heUserId = #{heUserId}
     </select>
 
     <insert id="insertCart">
-        INSERT INTO cm_cart (
-          productID, userID, productCount, ADDTIME,
-          reBuyFlag, heUserId
-        )
-        VALUES
-          (
-            #{productId}, #{userId}, #{productCount}, NOW(),
-            0, #{heUserId}
-          )
+        INSERT INTO cm_cart (productID, userID, skuId, productCount, ADDTIME,
+                             reBuyFlag, heUserId)
+        VALUES ((select productId from cm_hehe_sku where skuId = #{skuId}), #{userId}, #{skuId}, #{productCount}, NOW(),
+                0, #{heUserId})
     </insert>
 
     <update id="updateByProductCount">
         UPDATE
-          cm_cart
-        SET
-          productCount = #{productCount}
-        WHERE
-          cm_cartID = #{cartId}
+            cm_cart
+        SET productCount = #{productCount}
+        WHERE cm_cartID = #{cartId}
+    </update>
+
+    <update id="updateCart">
+        update cm_cart
+        set skuId=#{newSkuId},
+            productCount=#{count}
+        where cm_cartID = #{cartId}
     </update>
 
     <select id="getCartQuantity" resultType="integer">
-        SELECT
-          COUNT(cc.productID)
-        FROM
-          cm_cart cc
-          LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
-        WHERE
-          cc.userID = #{userId}
+        SELECT COUNT(cc.skuId)
+        FROM cm_cart cc
+                 LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
+        WHERE cc.userID = #{userId}
           AND chp.validFlag = 1
     </select>
 
     <select id="findCartShop" resultType="com.caimei.model.vo.ShopVo">
-        SELECT
-          s.shopID AS shopId,
-          s.name,
-          s.logo
-        FROM
-          cm_cart cc
-          LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
-          LEFT JOIN product p ON cc.productID = p.productID
-          LEFT JOIN shop s ON p.shopID = s.shopID
-        WHERE
-          cc.userID = #{userId}
+        SELECT s.shopID AS shopId,
+               s.name,
+               s.logo
+        FROM cm_cart cc
+                 LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
+                 LEFT JOIN product p ON cc.productID = p.productID
+                 LEFT JOIN shop s ON p.shopID = s.shopID
+        WHERE cc.userID = #{userId}
           AND chp.validFlag = 1
-        GROUP BY
-          s.shopID
-        ORDER BY
-          MAX(cc.addTime) DESC
-
+        GROUP BY s.shopID
+        ORDER BY MAX(cc.addTime) DESC
     </select>
 
     <select id="getCartProductsByShopId" resultType="com.caimei.model.vo.CartProductVo">
-        SELECT
-          cc.cm_cartID AS cartId,
-          cc.productID AS productId,
-          cc.productCount as num,
-          cc.heUserId,
-          chp.price,
-          chp.price as normalPrice,
-          chp.includedTax,
-          chp.invoiceType,
-          chp.clubTaxPoint,
-          p.name,
-          p.shopID AS shopId,
-          p.mainImage as productImage,
-          p.unit as productUnit
-        FROM
-          cm_cart cc
-          LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
-          LEFT JOIN product p ON cc.productID = p.productID
-        WHERE
-          cc.userID = #{userId}
+        SELECT cc.skuId,
+               cc.cm_cartID    AS cartId,
+               cc.productID    AS productId,
+               cc.productCount as num,
+               cc.heUserId,
+               chs.price,
+               chs.price       as normalPrice,
+               chp.includedTax,
+               chp.invoiceType,
+               chp.clubTaxPoint,
+               p.name,
+               p.shopID        AS shopId,
+               p.mainImage     as productImage,
+               cs.unit         as productUnit,
+               cs.stock        as stock
+        FROM cm_cart cc
+                 LEFT JOIN cm_sku cs on cc.skuId = cs.skuId
+                 LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
+                 LEFT JOIN cm_hehe_sku chs on cc.skuId = chs.skuId
+                 LEFT JOIN product p ON cc.productID = p.productID
+        WHERE cc.userID = #{userId}
           AND chp.validFlag = 1
           AND p.shopID = #{shopId}
     </select>
 
     <select id="getInvalidProducts" resultType="com.caimei.model.vo.CartProductVo">
-        SELECT
-          cc.cm_cartID AS cartId,
-          cc.productID AS productId,
-          cc.productCount as num,
-          chp.price,
-          chp.includedTax,
-          chp.invoiceType,
-          chp.clubTaxPoint,
-          p.name,
-          p.shopID AS shopId,
-          p.mainImage as productImage,
-          p.unit as productUnit
-        FROM
-          cm_cart cc
-          LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
-          LEFT JOIN product p ON cc.productID = p.productID
-        WHERE
-          cc.userID = #{userId}
+        SELECT cc.skuId,
+               cc.cm_cartID    AS cartId,
+               cc.productID    AS productId,
+               cc.productCount as num,
+               chs.price,
+               chp.includedTax,
+               chp.invoiceType,
+               chp.clubTaxPoint,
+               p.name,
+               p.shopID        AS shopId,
+               p.mainImage     as productImage,
+               cs.unit         as productUnit
+        FROM cm_cart cc
+                 LEFT JOIN cm_sku cs on cc.skuId = cs.skuId
+                 LEFT JOIN cm_hehe_sku chs on cc.skuId = chs.skuId
+                 LEFT JOIN cm_hehe_product chp ON cc.productID = chp.productId
+                 LEFT JOIN product p ON cc.productID = p.productID
+        WHERE cc.userID = #{userId}
           AND chp.validFlag = 2
     </select>
 
     <delete id="deleteCart">
-        DELETE FROM cm_cart WHERE cm_cartID = #{cartId}
+        DELETE
+        FROM cm_cart
+        WHERE cm_cartID = #{cartId}
     </delete>
 </mapper>