Browse Source

添加购物车bugfix

chao 3 years ago
parent
commit
de0161467b

+ 5 - 0
src/main/java/com/caimei365/order/mapper/BaseMapper.java

@@ -21,6 +21,11 @@ public interface BaseMapper {
      * @param shopId 供应商Id
      * @param shopId 供应商Id
      */
      */
     String getShopNameById(Integer shopId);
     String getShopNameById(Integer shopId);
+    /**
+     * 获取商品供应商Id
+     * @param productId 商品Id
+     */
+    Integer getShopIdByproductId(Integer productId);
     /**
     /**
      * 获取机构用户Id
      * 获取机构用户Id
      * @param clubId 机构Id
      * @param clubId 机构Id

+ 4 - 0
src/main/java/com/caimei365/order/model/po/CartPo.java

@@ -23,6 +23,10 @@ public class CartPo implements Serializable {
      * 用户id
      * 用户id
      */
      */
     private Integer userId;
     private Integer userId;
+    /**
+     * 用户id
+     */
+    private Integer shopId;
     /**
     /**
      * 商品id
      * 商品id
      */
      */

+ 3 - 1
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -108,7 +108,7 @@ public class CartClubServiceImpl implements CartClubService {
                         // 设置商品有效
                         // 设置商品有效
                         cartItemVo.setStatus(0);
                         cartItemVo.setStatus(0);
                         // 默认所有商品选中状态
                         // 默认所有商品选中状态
-                        cartItemVo.setIsChecked(true);
+                        cartItemVo.setIsChecked(false);
                         // 价格是否可见
                         // 价格是否可见
                         boolean priceVisible = (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2));
                         boolean priceVisible = (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2));
                         // 是否库存充足
                         // 是否库存充足
@@ -510,6 +510,8 @@ public class CartClubServiceImpl implements CartClubService {
             cart.setUserId(cartDto.getUserId());
             cart.setUserId(cartDto.getUserId());
             cart.setProductId(cartDto.getProductId());
             cart.setProductId(cartDto.getProductId());
             cart.setProductCount(cartDto.getProductCount());
             cart.setProductCount(cartDto.getProductCount());
+            Integer shopId = baseMapper.getShopIdByproductId(cartDto.getProductId());
+            cart.setShopId(shopId);
             //判断是否是再次购买
             //判断是否是再次购买
             Double repurchase = baseMapper.getRepurchasePrice(cartDto.getProductId(), cartDto.getUserId());
             Double repurchase = baseMapper.getRepurchasePrice(cartDto.getProductId(), cartDto.getUserId());
             if (null != repurchase && repurchase > 0) {
             if (null != repurchase && repurchase > 0) {

+ 2 - 2
src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java

@@ -156,9 +156,9 @@ public class CartSellerServiceImpl implements CartSellerService {
                                 }
                                 }
                             }
                             }
                         }
                         }
-                        // 再来一单的商品默认选中
+                        // 再来一单的商品
                         if (againBuyIdList.contains(cartItemVo.getProductId())) {
                         if (againBuyIdList.contains(cartItemVo.getProductId())) {
-                            cartItemVo.setIsChecked(true);
+                            cartItemVo.setIsChecked(false);
                         }
                         }
                         // 该供应商下价格累加
                         // 该供应商下价格累加
                         shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
                         shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());

+ 3 - 0
src/main/resources/mapper/BaseMapper.xml

@@ -190,6 +190,9 @@
     <select id="getBindMobileByUserId" resultType="java.lang.String">
     <select id="getBindMobileByUserId" resultType="java.lang.String">
         SELECT bindMobile FROM user WHERE userID = #{userId}
         SELECT bindMobile FROM user WHERE userID = #{userId}
     </select>
     </select>
+    <select id="getShopIdByproductId" resultType="java.lang.Integer">
+        SELECT shopID FROM product WHERE productID = #{productId}
+    </select>
     <insert id="insertDiscernReceipt" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.DiscernReceiptPo" useGeneratedKeys="true">
     <insert id="insertDiscernReceipt" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.po.DiscernReceiptPo" useGeneratedKeys="true">
         INSERT INTO cm_discern_receipt (payWay, payType, receiptType, receiptStatus, receiptAmount, confirmType,
         INSERT INTO cm_discern_receipt (payWay, payType, receiptType, receiptStatus, receiptAmount, confirmType,
         receiptDate, confirmDate, reviewDate, updateDate, delFlag, rePayFlag, formData)
         receiptDate, confirmDate, reviewDate, updateDate, delFlag, rePayFlag, formData)

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

@@ -10,14 +10,14 @@
         FROM cm_cart c
         FROM cm_cart c
         LEFT JOIN shop s ON c.shopID = s.shopID
         LEFT JOIN shop s ON c.shopID = s.shopID
         WHERE c.userID = #{userId}
         WHERE c.userID = #{userId}
-        GROUP BY c.shopID
+        GROUP BY c.shopID, c.cm_cartID
         ORDER BY c.cm_cartID DESC
         ORDER BY c.cm_cartID DESC
     </select>
     </select>
     <select id="getCartShopsByProductIds" resultType="com.caimei365.order.model.vo.CartShopVo">
     <select id="getCartShopsByProductIds" resultType="com.caimei365.order.model.vo.CartShopVo">
         SELECT
         SELECT
-        c.shopID AS shopId,
-        s.name AS shopName,
-        s.logo AS shopLogo
+            c.shopID AS shopId,
+            s.name AS shopName,
+            s.logo AS shopLogo
         FROM cm_cart c
         FROM cm_cart c
         LEFT JOIN shop s ON c.shopID = s.shopID
         LEFT JOIN shop s ON c.shopID = s.shopID
         WHERE c.userID = #{userId}
         WHERE c.userID = #{userId}
@@ -25,7 +25,7 @@
         <foreach collection="productIds" open="(" separator="," close=")" item="productId">
         <foreach collection="productIds" open="(" separator="," close=")" item="productId">
             #{productId}
             #{productId}
         </foreach>
         </foreach>
-        GROUP BY c.shopID
+        GROUP BY c.shopID, c.cm_cartID
         ORDER BY c.cm_cartID DESC
         ORDER BY c.cm_cartID DESC
     </select>
     </select>
     <select id="getCartProductsByShopId" resultType="com.caimei365.order.model.vo.CartItemVo">
     <select id="getCartProductsByShopId" resultType="com.caimei365.order.model.vo.CartItemVo">
@@ -114,6 +114,7 @@
             c.cm_cartID AS id,
             c.cm_cartID AS id,
             c.productCount,
             c.productCount,
             c.productID AS productId,
             c.productID AS productId,
+            c.shopID AS shopId,
             c.userID AS userId
             c.userID AS userId
         FROM cm_cart c
         FROM cm_cart c
         WHERE c.productID = #{productId} and c.userID = #{userId}
         WHERE c.productID = #{productId} and c.userID = #{userId}
@@ -127,8 +128,8 @@
         WHERE userID = #{userId} AND productID = #{productId}
         WHERE userID = #{userId} AND productID = #{productId}
     </update>
     </update>
     <insert id="insertCart" keyColumn="cm_cartID" keyProperty="id"  parameterType="com.caimei365.order.model.po.CartPo" useGeneratedKeys="true">
     <insert id="insertCart" keyColumn="cm_cartID" keyProperty="id"  parameterType="com.caimei365.order.model.po.CartPo" useGeneratedKeys="true">
-        INSERT INTO cm_cart (productID, userID, productCount, addTime, reBuyFlag)
-        VALUES (#{productId}, #{userId}, #{productCount}, #{addTime}, #{reBuyFlag})
+        INSERT INTO cm_cart (shopID, productID, userID, productCount, addTime, reBuyFlag)
+        VALUES (#{shopId}, #{productId}, #{userId}, #{productCount}, #{addTime}, #{reBuyFlag})
     </insert>
     </insert>
     <delete id="deleteCartByProductIds">
     <delete id="deleteCartByProductIds">
         DELETE FROM cm_cart
         DELETE FROM cm_cart