Browse Source

多店铺下单

ct 1 month ago
parent
commit
efe252c810

+ 46 - 1
fs-service/src/main/java/com/fs/hisStore/mapper/FsStoreCartScrmMapper.java

@@ -2,6 +2,7 @@ package com.fs.hisStore.mapper;
 
 import java.util.List;
 import com.fs.hisStore.domain.FsStoreCartScrm;
+import com.fs.hisStore.domain.FsStoreScrm;
 import com.fs.hisStore.param.FsStoreCartCountParam;
 import com.fs.hisStore.vo.FsStoreCartQueryVO;
 import com.fs.hisStore.vo.FsStoreCartVO;
@@ -66,7 +67,29 @@ public interface FsStoreCartScrmMapper
      */
     public int deleteFsStoreCartByIds(Long[] ids);
 
-    @Select("select c.*,p.product_type,p.product_name,p.image as product_image,v.price,v.sku as product_attr_name,v.image as product_attr_image,v.stock from fs_store_cart_scrm c inner join fs_store_product_scrm p on p.product_id=c.product_id inner join fs_store_product_attr_value_scrm v on v.id=c.product_attr_value_id where c.is_pay=0 and c.is_del=0 and c.is_buy=0 and p.is_show=1 and p.is_del=0 and c.user_id= #{uid}")
+//    @Select("select c.*,p.product_type,p.product_name,p.image as product_image,v.price,v.sku as product_attr_name,v.image as product_attr_image,v.stock from fs_store_cart_scrm c inner join fs_store_product_scrm p on p.product_id=c.product_id inner join fs_store_product_attr_value_scrm v on v.id=c.product_attr_value_id where c.is_pay=0 and c.is_del=0 and c.is_buy=0 and p.is_show=1 and p.is_del=0 and c.user_id= #{uid}")
+@Select({"<script> " +
+        "select q.* FROM (" +
+        "select c.*,p.product_type,p.product_name,p.image as product_image,v.price,v.sku as product_attr_name," +
+        "v.image as product_attr_image,v.stock,s.store_id,s.store_name " +
+        "from fs_store_cart_scrm c " +
+        "inner join fs_store_product_scrm p on p.product_id=c.product_id " +
+        "inner join fs_store_product_attr_value_scrm v on v.id=c.product_attr_value_id " +
+        "left join fs_store_scrm s on v.store_id = s.store_id " +
+        "where c.is_pay=0 and c.is_del=0 and c.is_buy=0 and p.is_show=1 and p.is_del=0 and c.user_id= #{uid}" +
+        ") q where 1= 1" +
+        "<if test = 'storeId != null    '> " +
+        "<choose>" +
+        "<when test='storeId == -1'>" +
+        "and q.store_id IS NULL" +
+        "</when>" +
+        "<otherwise>" +
+        "and q.store_id =#{storeId} " +
+        "</otherwise>" +
+        "</choose>" +
+        "</if>" +
+        "</script>"})
+List<FsStoreCartVO> selectFsStoreCartListByUid(@Param("uid") long uid,@Param("storeId") Long storeId);
     List<FsStoreCartVO> selectFsStoreCartListByUid(long uid);
     @Delete({"<script>"+
             "delete from fs_store_cart_scrm where id in"+
@@ -120,4 +143,26 @@ public interface FsStoreCartScrmMapper
             "</if>" +
             "</script>"})
     Integer selectFsStoreCartCount(@Param("maps") FsStoreCartCountParam param);
+
+    @Select(
+//            "select s.*" +
+//                    "from fs_store_cart c " +
+//                    "inner join fs_store_product p on p.product_id=c.product_id " +
+//                    "inner join fs_store_product_attr_value v on v.id=c.product_attr_value_id " +
+//                    "left join fs_store s on v.store_id = s.store_id " +
+//                    "where c.is_pay=0 and c.is_del=0 and c.is_buy=0 and p.is_show=1 and p.is_del=0 and c.user_id= #{uid} GROUP BY s.store_id"
+            "SELECT sorted.store_id, sorted.store_name" +
+                    " FROM (" +
+                    "SELECT c.id, c.product_id, c.product_attr_value_id, c.user_id, c.create_time AS cart_create_time," +
+                    "s.store_id, s.store_name " +
+                    "FROM fs_store_cart_scrm c " +
+                    "INNER JOIN fs_store_product_scrm p ON p.product_id = c.product_id " +
+                    "INNER JOIN fs_store_product_attr_value_scrm v ON v.id = c.product_attr_value_id " +
+                    "LEFT JOIN fs_store_scrm s ON v.store_id = s.store_id " +
+                    "WHERE c.is_pay = 0 AND c.is_del = 0 AND c.is_buy = 0 AND p.is_show = 1 AND p.is_del = 0 AND c.user_id= #{uid} " +
+                    "ORDER BY c.create_time DESC " +
+                    ") sorted " +
+                    "GROUP BY sorted.store_id;"
+    )
+    List<FsStoreScrm> selectFsStoreByUid(long uid);
 }

+ 4 - 1
fs-service/src/main/java/com/fs/hisStore/service/IFsStoreCartScrmService.java

@@ -8,6 +8,7 @@ import com.fs.hisStore.param.FsStoreCartCountParam;
 import com.fs.hisStore.param.FsStoreCartDelParam;
 import com.fs.hisStore.param.FsStoreCartNumParam;
 import com.fs.hisStore.param.FsStoreCartParam;
+import com.fs.hisStore.vo.FsStoreCartGroupStoreVO;
 import com.fs.hisStore.vo.FsStoreCartVO;
 
 /**
@@ -69,7 +70,9 @@ public interface IFsStoreCartScrmService
     R addCart(long userId, FsStoreCartParam cartParam);
 
 
-    List<FsStoreCartVO> selectFsStoreCartListByUid(long parseLong);
+    List<FsStoreCartGroupStoreVO> selectFsStoreCartListByUid(long parseLong);
+
+//    List<FsStoreCartVO> selectFsStoreCartListByUid(long parseLong);
 
     R delCart(long userId, FsStoreCartDelParam cartParam);
 

+ 28 - 2
fs-service/src/main/java/com/fs/hisStore/service/impl/FsStoreCartScrmServiceImpl.java

@@ -14,6 +14,7 @@ import com.fs.hisStore.config.FsErpConfig;
 import com.fs.hisStore.domain.FsStoreCartScrm;
 import com.fs.hisStore.domain.FsStoreProductAttrValueScrm;
 import com.fs.hisStore.domain.FsStoreProductGroupScrm;
+import com.fs.hisStore.domain.FsStoreScrm;
 import com.fs.hisStore.dto.StoreProductGroupDTO;
 import com.fs.hisStore.mapper.FsStoreCartScrmMapper;
 import com.fs.hisStore.mapper.FsStoreProductAttrValueScrmMapper;
@@ -24,12 +25,15 @@ import com.fs.hisStore.param.FsStoreCartDelParam;
 import com.fs.hisStore.param.FsStoreCartNumParam;
 import com.fs.hisStore.param.FsStoreCartParam;
 import com.fs.hisStore.service.IFsStoreCartScrmService;
+import com.fs.hisStore.vo.FsStoreCartGroupStoreVO;
 import com.fs.hisStore.vo.FsStoreCartVO;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 
+import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Date;
 import java.util.List;
 
@@ -198,9 +202,31 @@ public class FsStoreCartScrmServiceImpl implements IFsStoreCartScrmService
         }
     }
 
+//    @Override
+//    public List<FsStoreCartVO> selectFsStoreCartListByUid(long uid) {
+//        return fsStoreCartMapper.selectFsStoreCartListByUid(uid);
+//    }
+
     @Override
-    public List<FsStoreCartVO> selectFsStoreCartListByUid(long uid) {
-        return fsStoreCartMapper.selectFsStoreCartListByUid(uid);
+    public List<FsStoreCartGroupStoreVO> selectFsStoreCartListByUid(long uid) {
+        //分组展示购物车信息
+        List<FsStoreCartGroupStoreVO> carts = new ArrayList<>();
+        //查询店铺id
+        List<FsStoreScrm> store = fsStoreCartMapper.selectFsStoreByUid(uid);
+        for (FsStoreScrm fsStore : store) {
+            FsStoreCartGroupStoreVO vo = new FsStoreCartGroupStoreVO();
+            ////todo 目前存在商品属性没有storeid的脏数据 暂且会查询为null的
+            if (fsStore == null) {
+                vo.setStoreName("null");
+                vo.setList(fsStoreCartMapper.selectFsStoreCartListByUid(uid, -1L));
+            } else {
+                vo.setStoreId(fsStore.getStoreId());
+                vo.setStoreName(fsStore.getStoreName());
+                vo.setList(fsStoreCartMapper.selectFsStoreCartListByUid(uid, fsStore.getStoreId()));
+            }
+            carts.add(vo);
+        }
+        return carts;
     }
 
     @Override

+ 12 - 0
fs-service/src/main/java/com/fs/hisStore/vo/FsStoreCartGroupStoreVO.java

@@ -0,0 +1,12 @@
+package com.fs.hisStore.vo;
+
+import lombok.Data;
+
+import java.util.List;
+
+@Data
+public class FsStoreCartGroupStoreVO {
+    private String storeName;
+    private Long storeId;
+    private List<FsStoreCartVO> list;
+}

+ 2 - 1
fs-user-app/src/main/java/com/fs/app/controller/store/ProductScrmController.java

@@ -241,7 +241,8 @@ public class ProductScrmController extends AppBaseController {
     public R getCarts(HttpServletRequest request){
         log.info("获取购物车列表 参数: {}",ServletUtil.getHeaderMap(request));
 
-        List<FsStoreCartVO> carts= cartService.selectFsStoreCartListByUid(Long.parseLong(getUserId()));
+//        List<FsStoreCartVO> carts= cartService.selectFsStoreCartListByUid(Long.parseLong(getUserId()));
+        List<FsStoreCartGroupStoreVO> carts= cartService.selectFsStoreCartListByUid(Long.parseLong(getUserId()));
         return R.ok().put("carts",carts);
     }
     @Login