Переглянути джерело

商品详情无userid接口静态化

zhijiezhao 2 роки тому
батько
коміт
e3a873a270

+ 3 - 0
src/main/java/com/caimei/www/controller/unlimited/ProductController.java

@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
 import com.caimei.www.controller.BaseController;
 import com.caimei.www.pojo.page.Parameter;
 import com.caimei.www.pojo.page.ProductDetail;
+import com.caimei.www.pojo.page.ProductList;
 import com.caimei.www.service.page.ProductService;
 import com.caimei.www.service.page.SinglePageService;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -108,6 +109,8 @@ public class ProductController extends BaseController {
         }
         List<String> images=productService.getImages(productId);
         List<Parameter> params=productService.getParams(productId);
+        List<ProductList> productLists=productService.getProductLists(productId);
+        model.addAttribute("lists",productLists);
         model.addAttribute("params",params);
         model.addAttribute("images",images);
         model.addAttribute("productId", productId);

+ 2 - 0
src/main/java/com/caimei/www/mapper/ProductDao.java

@@ -72,4 +72,6 @@ public interface ProductDao {
      * 修复商品图片(临时)
      */
     List<String> getProductInfo();
+
+    Integer getRecommendType(Integer productId);
 }

+ 3 - 0
src/main/java/com/caimei/www/service/page/ProductService.java

@@ -7,6 +7,7 @@ import com.caimei.www.pojo.baike.BaikeProduct;
 import com.caimei.www.pojo.baike.BaikeType;
 import com.caimei.www.pojo.page.Parameter;
 import com.caimei.www.pojo.page.ProductDetail;
+import com.caimei.www.pojo.page.ProductList;
 
 import java.util.List;
 import java.util.Map;
@@ -99,4 +100,6 @@ public interface ProductService {
     List<String> getImages(Integer productId);
 
     List<Parameter> getParams(Integer productId);
+
+    List<ProductList> getProductLists(Integer productId);
 }

+ 38 - 18
src/main/java/com/caimei/www/service/page/impl/ProductServiceImpl.java

@@ -9,6 +9,7 @@ import com.caimei.www.pojo.JsonModel;
 import com.caimei.www.pojo.baike.*;
 import com.caimei.www.pojo.page.Parameter;
 import com.caimei.www.pojo.page.ProductDetail;
+import com.caimei.www.pojo.page.ProductList;
 import com.caimei.www.service.page.ProductService;
 import com.caimei.www.utils.ImageUtil;
 import com.caimei.www.utils.PriceUtil;
@@ -70,14 +71,14 @@ public class ProductServiceImpl implements ProductService {
      */
     @Override
     public JSONArray getTypeClassifyJson(Integer typeSort) {
-        String dataUrl = coreServer+"/commodity/classify?typeSort="+typeSort+"&source=www";
+        String dataUrl = coreServer + "/commodity/classify?typeSort=" + typeSort + "&source=www";
         try {
             String classifyResult = RequestUtil.sendGet(dataUrl);
             log.debug(classifyResult);
             Map<String, Object> classifyMap = JSONObject.parseObject(classifyResult, Map.class);
             return (JSONArray) classifyMap.get("data");
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -89,14 +90,14 @@ public class ProductServiceImpl implements ProductService {
      */
     @Override
     public Map<String, Object> getTypeFloorJson(Integer pageId) {
-        String dataUrl = coreServer+"/commodity/classify/product?pageId="+ pageId +"&source=1";
+        String dataUrl = coreServer + "/commodity/classify/product?pageId=" + pageId + "&source=1";
         try {
             String floorResult = RequestUtil.sendGet(dataUrl);
             log.debug(floorResult);
             Map<String, Object> floorMap = JSONObject.parseObject(floorResult, Map.class);
             return JSONObject.parseObject(String.valueOf(floorMap.get("data")), Map.class);
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -108,14 +109,14 @@ public class ProductServiceImpl implements ProductService {
      */
     @Override
     public JSONArray getBigTypeJson(Integer typeSort) {
-        String dataUrl = coreServer+"/commodity/type/first?typeSort="+typeSort;
+        String dataUrl = coreServer + "/commodity/type/first?typeSort=" + typeSort;
         try {
             String classifyResult = RequestUtil.sendGet(dataUrl);
             log.debug(classifyResult);
             Map<String, Object> classifyMap = JSONObject.parseObject(classifyResult, Map.class);
             return (JSONArray) classifyMap.get("data");
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -127,14 +128,14 @@ public class ProductServiceImpl implements ProductService {
      */
     @Override
     public JSONArray getSmallTypeJson(Integer bigTypeId) {
-        String dataUrl = coreServer+"/commodity/type/second?bigTypeId="+bigTypeId;
+        String dataUrl = coreServer + "/commodity/type/second?bigTypeId=" + bigTypeId;
         try {
             String classifyResult = RequestUtil.sendGet(dataUrl);
             log.debug(classifyResult);
             Map<String, Object> classifyMap = JSONObject.parseObject(classifyResult, Map.class);
             return (JSONArray) classifyMap.get("data");
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -147,14 +148,14 @@ public class ProductServiceImpl implements ProductService {
      */
     @Override
     public JSONArray getTinyTypeJson(Integer smallTypeId) {
-        String dataUrl = coreServer+"/commodity/type/third?smallTypeId="+smallTypeId;
+        String dataUrl = coreServer + "/commodity/type/third?smallTypeId=" + smallTypeId;
         try {
             String classifyResult = RequestUtil.sendGet(dataUrl);
             log.debug(classifyResult);
             Map<String, Object> classifyMap = JSONObject.parseObject(classifyResult, Map.class);
             return (JSONArray) classifyMap.get("data");
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -166,7 +167,7 @@ public class ProductServiceImpl implements ProductService {
      */
     @Override
     public JSONObject getProductListJson(String params) {
-        String dataUrl = coreServer+"/commodity/search/query/product/type"+params;
+        String dataUrl = coreServer + "/commodity/search/query/product/type" + params;
         try {
             String productResult = RequestUtil.sendGet(dataUrl);
             log.debug(productResult);
@@ -174,7 +175,7 @@ public class ProductServiceImpl implements ProductService {
             String data = (String) productMap.get("data");
             return JSONObject.parseObject(data);
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -188,7 +189,7 @@ public class ProductServiceImpl implements ProductService {
             Map<String, Object> classifyMap = JSONObject.parseObject(classifyResult, Map.class);
             return (JSONArray) classifyMap.get("data");
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -202,7 +203,7 @@ public class ProductServiceImpl implements ProductService {
             Map<String, Object> moreMap = JSONObject.parseObject(moreResult, Map.class);
             return JSONObject.parseObject(String.valueOf(moreMap.get("data")), Map.class);
         } catch (Exception e) {
-            log.error("try-catch:",e);
+            log.error("try-catch:", e);
             return null;
         }
     }
@@ -216,9 +217,9 @@ public class ProductServiceImpl implements ProductService {
     public List<String> getImages(Integer productId) {
         List<String> productDetailImages = productDao.getProductDetailImages(productId);
         List<String> strings = new ArrayList<>();
-        if(null!=productDetailImages&&productDetailImages.size()>0){
-            productDetailImages.forEach(p->{
-                strings.add(ImageUtil.getImageURL("product",p,0,domain));
+        if (null != productDetailImages && productDetailImages.size() > 0) {
+            productDetailImages.forEach(p -> {
+                strings.add(ImageUtil.getImageURL("product", p, 0, domain));
             });
         }
         return strings;
@@ -226,7 +227,26 @@ public class ProductServiceImpl implements ProductService {
 
     @Override
     public List<Parameter> getParams(Integer productId) {
-        return  productDao.getProductParameters(productId);
+        return productDao.getProductParameters(productId);
+    }
+
+    @Override
+    public List<ProductList> getProductLists(Integer productId) {
+        //取不到userId,默认游客 商品可见度默认所有人
+        Integer recommendType = productDao.getRecommendType(productId);
+        List<ProductList> list = null;
+        if (null != recommendType && 1 == recommendType) {
+            list = productDao.getProductRecommendsById(productId);
+        } else {
+            list = productDao.getAutoProductRecommends(productId);
+        }
+        if (null != list && list.size() > 0) {
+            list.forEach(product -> {
+                // 设置 图片路径
+                product.setImage(ImageUtil.getImageURL("product", product.getImage(), 0, domain));
+            });
+        }
+        return list;
     }
 
     @Override

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

@@ -54,8 +54,8 @@ logging:
 caimei:
   siteEnv: 0 #网站环境,(2:正式环境,1:测试环境,0:开发环境)
   #spiServer: http://192.168.2.68:8008
-#  coreServer: https://core-b.caimei365.com
-  coreServer: http://192.168.2.67:18002
+  coreServer: https://core-b.caimei365.com
+#  coreServer: http://192.168.2.67:18002
 #  coreServer: http://192.168.2.75:18002
   imageDomain: https://img-b.caimei365.com
   wwwDomain: http://localhost:8009

+ 16 - 9
src/main/resources/mapper/ProductMapper.xml

@@ -72,20 +72,24 @@
         from product as p
         left join cm_product_recommend as pr on pr.recommendProductID = p.productID
         where
-            pr.productID = #{productId} and p.validFlag  = 2
+            pr.productID = #{productId}
+          and p.validFlag  = 2
+          and p.visibility = 3
         order by pr.sort desc
 	</select>
 	<select id="getAutoProductRecommends" resultType="com.caimei.www.pojo.page.ProductList">
-        select
+		select
 			p.productID as id,
 			p.`name` as `name`,
-			p.productType,
-			p.mainImage as image
-        from product as p
-        where
-			p.validFlag  = 2 and
-			p.tinyTypeID = (select tinyTypeID from product as p1 where p1.productID = #{productId})
-        order by p.sellNumber desc limit 0,7
+			p.mainImage as image,
+			IFNULL(p.visibility,3) as visibility,
+			p.productType
+		from product as p
+		where p.validFlag  = 2
+		  and p.commodityType = (select commodityType from product as p1 where p1.productID = #{productId})
+		  and p.smallTypeID = (select smallTypeID from product as p2 where p2.productID = #{productId})
+		  and p.visibility = 3
+		order by p.sellNumber desc limit 0,7
 	</select>
 	<select id="getProductParameters" resultType="com.caimei.www.pojo.page.Parameter">
 		select id as id,
@@ -129,5 +133,8 @@
     <select id="getProductInfo" resultType="java.lang.String">
         select detailinfo from productdetailinfo where detailinfo like '%img-b.caimei365.com%'
 	</select>
+	<select id="getRecommendType" resultType="java.lang.Integer">
+		select recommendType from product where productId=#{productId}
+	</select>
 
 </mapper>

+ 12 - 12
src/main/resources/static/js/common/serviceapi/product.service.js

@@ -76,18 +76,18 @@ var ProductApi = {
         //         callback(res);
         //     });
         // },
-        GetProductDdtailsRecommend: function (params, callback) {//获取商品推荐
-            Http.AjaxService({
-                url:'/commodity/detail/recommend',
-                type:'get',
-                data:params,
-                json:true,
-                isHost:true
-            })
-            .then(function(res){
-                callback(res);
-            });
-        },
+        // GetProductDdtailsRecommend: function (params, callback) {//获取商品推荐
+        //     Http.AjaxService({
+        //         url:'/commodity/detail/recommend',
+        //         type:'get',
+        //         data:params,
+        //         json:true,
+        //         isHost:true
+        //     })
+        //     .then(function(res){
+        //         callback(res);
+        //     });
+        // },
         GetEquipmentDdtailsRecommend: function (params, callback) {//获取项目详情
             Http.AjaxService({
                 url:'/commodity/equipment/details',

+ 97 - 47
src/main/resources/static/js/product/detail.js

@@ -224,7 +224,7 @@ var productDetail = new Vue({
                         _self.isHideButton = true
                         _self.handleShowProductType()
                     }
-                    _self.getRecommends();
+                    // _self.getRecommends();
                     _self.getProdcutArchiveDetails();  //获取资料列表
                     // 获取路由hash标识,设置默认展开tab
                     var str = CAIMEI.getUrlParam('open');
@@ -461,52 +461,52 @@ var productDetail = new Vue({
                 window.location.href = '/shopping/confirm.html?type=2&productId='+_self.productId+'&count='+_self.number;
             }
         },
-        getRecommends: function () {
-            var _self = this;
-            if (!this.productId) {
-                return;
-            }
-            ProductApi.GetProductDdtailsRecommend(
-                {
-                    productId: _self.productId,
-                    recommendType: _self.recommendType,
-                    userId: _self.userId
-                },
-                function (response) {
-                    if (response.code === 0 && response.data) {
-                        if (response.data.length > 0) {
-                            _self.recommends = response.data;
-                            _self.recommendPage = isPC ? Math.ceil(response.data.length / 7) : Math.ceil(response.data.length / 3);
-                            setTimeout(function () {
-                                if (isPC) {
-                                    $('#productRecommend').slide({
-                                        mainCell: ".swiper-wrapper",
-                                        titCell: ".swiper-pagination span",
-                                        effect: "leftLoop",
-                                        interTime: 3000,
-                                        autoPlay: true,
-                                        scroll: 7,
-                                        vis: 7,
-                                        trigger: "mouseover"
-                                    });
-                                } else {
-                                    var swiper = new Swiper('#productRecommend', {
-                                        slidesPerView: 3,
-                                        spaceBetween: 0,
-                                        autoplay: {
-                                            delay: 3000,
-                                            disableOnInteraction: false
-                                        },
-                                        pagination: {
-                                            el: '.swiper-pagination'
-                                        }
-                                    });
-                                }
-                            }, 500);
-                        }
-                    }
-                });
-        },
+        // getRecommends: function () {
+        //     var _self = this;
+        //     if (!this.productId) {
+        //         return;
+        //     }
+        //     ProductApi.GetProductDdtailsRecommend(
+        //         {
+        //             productId: _self.productId,
+        //             recommendType: _self.recommendType,
+        //             userId: _self.userId
+        //         },
+        //         function (response) {
+        //             if (response.code === 0 && response.data) {
+        //                 if (response.data.length > 0) {
+        //                     _self.recommends = response.data;
+        //                     _self.recommendPage = isPC ? Math.ceil(response.data.length / 7) : Math.ceil(response.data.length / 3);
+        //                     setTimeout(function () {
+        //                         if (isPC) {
+        //                             $('#productRecommend').slide({
+        //                                 mainCell: ".swiper-wrapper",
+        //                                 titCell: ".swiper-pagination span",
+        //                                 effect: "leftLoop",
+        //                                 interTime: 3000,
+        //                                 autoPlay: true,
+        //                                 scroll: 7,
+        //                                 vis: 7,
+        //                                 trigger: "mouseover"
+        //                             });
+        //                         } else {
+        //                             var swiper = new Swiper('#productRecommend', {
+        //                                 slidesPerView: 3,
+        //                                 spaceBetween: 0,
+        //                                 autoplay: {
+        //                                     delay: 3000,
+        //                                     disableOnInteraction: false
+        //                                 },
+        //                                 pagination: {
+        //                                     el: '.swiper-pagination'
+        //                                 }
+        //                             });
+        //                         }
+        //                     }, 500);
+        //                 }
+        //             }
+        //         });
+        // },
         queryProductDetilsCoupons: function() {// 初始化商品详情优惠券信息
             var _self = this;
             ProductApi.QueryProductDetilsCoupons(_self.couponParam, function (response) {
@@ -830,5 +830,55 @@ var productDetail = new Vue({
         //     ,titCell:".tabTit span"
         //     ,trigger: "click"
         // });
+        setTimeout(function () {
+            if (isPC) {
+                var magnifier = new ImageMagnifier(
+                    '#imgShown .smallImage li',
+                    '#imgShown .bigImage',
+                    '#imgShown .zoomImage',
+                    '#imgShown .mask',
+                    '#imgShown .zoom',
+                    "on"
+                ).init();
+            } else {
+                var swiper = new Swiper('#swiperImage', {
+                    loop: true,
+                    autoplay: {
+                        delay: 2000,
+                        disableOnInteraction: false
+                    },
+                    pagination: {
+                        el: '.swiper-pagination',
+                        type: 'fraction'
+                    }
+                });
+            }
+        }, 500);
+        setTimeout(function () {
+            if (isPC) {
+                $('#productRecommend').slide({
+                    mainCell: ".swiper-wrapper",
+                    titCell: ".swiper-pagination span",
+                    effect: "leftLoop",
+                    interTime: 3000,
+                    autoPlay: true,
+                    scroll: 7,
+                    vis: 7,
+                    trigger: "mouseover"
+                });
+            } else {
+                var swiper = new Swiper('#productRecommend', {
+                    slidesPerView: 3,
+                    spaceBetween: 0,
+                    autoplay: {
+                        delay: 3000,
+                        disableOnInteraction: false
+                    },
+                    pagination: {
+                        el: '.swiper-pagination'
+                    }
+                });
+            }
+        }, 500);
     }
 });

+ 5 - 5
src/main/resources/templates/product/detail.html

@@ -417,16 +417,16 @@
             </div>
         </div>
         <!--相关推荐区域-->
-        <div class="recommendBox" v-if="recommends.length>0">
+        <div class="recommendBox" th:if="${lists.size()>0}">
             <div class="hd">相关推荐</div>
             <div id="productRecommend" class="swiper-container">
                 <ul class="swiper-wrapper" v-cloak>
-                    <li class="swiper-slide mfc" v-for="p in recommends">
+                    <li class="swiper-slide mfc" th:each="p : ${lists}">
                         <div class="item">
-                            <a class="image" :href="'/product-'+p.productId+'.html'" target="_blank">
-                                <img :src="p.image" :alt="p.name"
+                            <a class="image" th:href="'/product-'+${p.id}+'.html'" target="_blank">
+                                <img th:src="${p.image}" th:alt="${p.name}"
                                      onerror="javascript:this.src='/img/base/placeholder.png';">
-                                <span v-html="p.name"></span>
+                                <span th:html="${p.name}"></span>
                             </a>
                         </div>
                     </li>