From 77dfe226a67d10dc95c65a67c743c44247c31ad3 Mon Sep 17 00:00:00 2001
From: Targaryen <chengyao.guo@yoho.cn>
Date: Wed, 13 Jul 2016 11:40:35 +0800
Subject: [PATCH] '店铺添加基础模板'

---
 template/www.yohobuy.com/partials/product/list.phtml                      |  74 +++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
 web-static/js/product/brand.js                                            |  30 ++++++++++++++++++++++++++++--
 web-static/sass/product/_list.css                                         |  13 +++++++++++++
 yohobuy/www.yohobuy.com/application/modules/Product/controllers/Index.php | 172 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
 4 files changed, 232 insertions(+), 57 deletions(-)

diff --git a/template/www.yohobuy.com/partials/product/list.phtml b/template/www.yohobuy.com/partials/product/list.phtml
index 2805e41..36c3436 100644
--- a/template/www.yohobuy.com/partials/product/list.phtml
+++ b/template/www.yohobuy.com/partials/product/list.phtml
@@ -21,36 +21,64 @@
                 </div>
             </div>
         {{/ brandBanner}}
+
+        {{# shopBanner}}
+        <div class="brand-banner base-shop-banner">
+            <div class="banner-img" style="height: {{bannerHeight}}px;background: url({{banner}})"></div>
+            <div class="opt-wrap">
+                <p class="opt center-content">
+                    <a href="{{shopHome}}">
+                        <i class="iconfont">&#xe617;</i>
+                        店铺首页
+                    </a>
+                    <a href="{{shopIntro}}">
+                        <i class="iconfont">&#xe631;</i>
+                        店铺介绍
+                    </a>
+                            <span id="shop-favor" class="brand-favor" data-id="{{shopId}}">
+                                <i class="iconfont{{#if coled}} coled{{/if}}">&#xe616;</i>
+                            </span>
+                </p>
+            </div>
+        </div>
+        {{/ shopBanner}}
+
         <div class="center-content clearfix">
             {{> layout/path-nav}}
-            {{#if brandAbout}}
+            {{#if shopAbout}}
                 <div class="brand-about">
-                    {{{brandAbout}}}
+                    {{{shopAbout}}}
                 </div>
             {{^}}
-                <div class="list-left pull-left">
-                    {{> product/left-content}}
-                </div>
-                <div class="list-right pull-right">
-                    {{# sortIntro}}
-                        <div class="sort-intro clearfix">
-                            <div class="texts pull-left">
-                                <p class="name">{{name}}</p>
-                                <p class="en-name">{{enName}}</p>
-                                <p class="desc">{{{description}}}</p>
-                                <div class="key-entry">
-                                    {{#each keyEntry}}
-                                        <a href="{{url}}">{{name}}</a>
-                                    {{/each}}
+                {{#if brandAbout}}
+                    <div class="brand-about">
+                        {{{brandAbout}}}
+                    </div>
+                {{^}}
+                    <div class="list-left pull-left">
+                        {{> product/left-content}}
+                    </div>
+                    <div class="list-right pull-right">
+                        {{# sortIntro}}
+                            <div class="sort-intro clearfix">
+                                <div class="texts pull-left">
+                                    <p class="name">{{name}}</p>
+                                    <p class="en-name">{{enName}}</p>
+                                    <p class="desc">{{{description}}}</p>
+                                    <div class="key-entry">
+                                        {{#each keyEntry}}
+                                            <a href="{{url}}">{{name}}</a>
+                                        {{/each}}
+                                    </div>
                                 </div>
+                                <img class="pull-right img" src="{{img}}">
                             </div>
-                            <img class="pull-right img" src="{{img}}">
-                        </div>
-                    {{/ sortIntro}}
-                    {{> product/shop-entry}}
-                    {{> product/standard-content}}
-                    {{> product/latest-walk}}
-                </div>
+                        {{/ sortIntro}}
+                        {{> product/shop-entry}}
+                        {{> product/standard-content}}
+                        {{> product/latest-walk}}
+                    </div>
+                {{/if}}
             {{/if}}
         </div>
     {{/ list}}
diff --git a/web-static/js/product/brand.js b/web-static/js/product/brand.js
index 386e8c5..4e51e20 100644
--- a/web-static/js/product/brand.js
+++ b/web-static/js/product/brand.js
@@ -7,8 +7,14 @@
 var $ = require('yoho.jquery');
 
 var $brandFavor = $('#brand-favor'),
-    id = $brandFavor.data('id');
+    $shopFavor = $('#shop-favor'),
+    shopId = $shopFavor.data('id'),
+    id = $brandFavor.data('id'),
+    isFavorite = $shopFavor.find('i').hasClass('coled');
 
+/**
+ * 品牌收藏
+ */
 $brandFavor.on('click', function() {
     $.ajax({
         type: 'post',
@@ -20,7 +26,27 @@ $brandFavor.on('click', function() {
         if (res.code === 200) {
             $brandFavor.find('i').toggleClass('coled');
         } else if (res.code === 403) {
-            location.href = 'http://www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
+            location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
+        }
+    });
+});
+
+/**
+ * 店铺收藏
+ */
+$shopFavor.on('click', function() {
+    $.ajax({
+        type: 'post',
+        url: '/product/index/favoriteShop',
+        data: {
+            isFavorite: isFavorite ? 0 : 1,
+            shopId: shopId
+        }
+    }).then(function(res) {
+        if (res.code === 200) {
+            $shopFavor.find('i').toggleClass('coled');
+        } else if (res.code === 403) {
+            location.href = '//www.yohobuy.com/signin.html?refer=' + encodeURIComponent(location.href);
         }
     });
 });
diff --git a/web-static/sass/product/_list.css b/web-static/sass/product/_list.css
index 910d306..8ab7c0a 100644
--- a/web-static/sass/product/_list.css
+++ b/web-static/sass/product/_list.css
@@ -54,6 +54,19 @@
         }
     }
 
+    .base-shop-banner{
+        margin-left: auto;
+        margin-right: auto;
+        width: 1150px;
+        height: 200px;
+
+        .opt {
+            span {
+                margin-right: 60px;
+            }
+        }
+    }
+
     .brand-about {
         font-size: 12px;
         line-height: 150%;
diff --git a/yohobuy/www.yohobuy.com/application/modules/Product/controllers/Index.php b/yohobuy/www.yohobuy.com/application/modules/Product/controllers/Index.php
index 9b715ac..947e9ab 100644
--- a/yohobuy/www.yohobuy.com/application/modules/Product/controllers/Index.php
+++ b/yohobuy/www.yohobuy.com/application/modules/Product/controllers/Index.php
@@ -19,6 +19,7 @@ class IndexController extends WebAction
     {
         //品牌域名,没有获取到品牌域名的跳转首页
         $domain = $this->param('named');
+        $domain = 's';
         if (empty($domain)) {
             $this->go(SITE_MAIN);
         }
@@ -27,20 +28,22 @@ class IndexController extends WebAction
         if (!$result) {
             $this->go(SITE_MAIN);
         }
-        
+
         //获取uid
         $uid = $this->getUid();
-        
-        
+
+        // 1 该品牌在多个店铺存在,2 该品牌只有一个店铺
         $type = intval(isset($result['type']) ? $result['type'] : '');
         switch ($type) {
             case 1:
                 $shopId = intval($this->get('shopId', 0));
                 if (empty($shopId)) {
                     //无单品店有多品店:1--->搜索页
-                    $this->go('http://search.yohobuy.com/?query=' . $domain);
+                    $this->go('//search.yohobuy.com/?query=' . $domain);
                 } else {
                     $shopIntro = ShopModel::getIntro($shopId, $uid);
+
+                    //$shopTemplateType 1基础模板,2经典模板,
                     if (!empty($shopIntro['shopTemplateType']) && $shopIntro['shopTemplateType'] === 1) {
                         //基础模板多个品牌
                         $result['shopTemplateType'] = $shopIntro['shopTemplateType'];
@@ -62,12 +65,16 @@ class IndexController extends WebAction
                     exit(0);
                 }
                 break;
+            default:
+                break;
         }
 
+        // 判断是否是基础模板
+        $isBasicTpl = !empty($result['shopTemplateType']) && $result['shopTemplateType'] === 1 && !empty($result['shopId']);
         //基础模板
-        if (!empty($result['shopTemplateType']) && $result['shopTemplateType'] === 1 && !empty($result['shopId'])) {
+        if ($isBasicTpl) {
             $basisData = ShopModel::basisTemplate($result['shopId']);
-            $result['brandBanner'] = empty($basisData['shopTopBanner_base']['banner']) ?
+            $result['shopBanner'] = empty($basisData['shopTopBanner_base']['banner']) ?
                 $result['brandBanner'] : $basisData['shopTopBanner_base']['banner'] . '?';
             $result['signboard'] = $basisData['signboard'];
             if (isset($result['node'])) {
@@ -109,25 +116,44 @@ class IndexController extends WebAction
 
         //调用模型获得品牌页数据
         $data = BrandsModel::getBrandSearchData($condition, $options);
+
+        /* 为使用基础模板的店铺添加 banner */
+        if ($isBasicTpl) {
+            if (isset($result['shopBanner']) && !empty($result['shopBanner'])) {
+                $shopIntro = ShopModel::getIntro($result['shopId'], $uid);
+
+                $data['shopBanner'] = array(
+                    'banner' => $result['shopBanner'],
+                    'shopHome' => Helpers::url('', array('shopId' => $result['shopId']), $domain),
+                    'shopIntro' => Helpers::url('/aboutShop', array('shopId' => $result['shopId'])),
+                    'coled' => $shopIntro['isFavorite'],
+                    'shopId' => $result['shopId']
+                );
+
+                $data['brandBanner'] = array(); // 刪除品牌banner
+            }
+
+        }
+
         $data['signboard'] = isset($result['signboard']) ? $result['signboard'] : '';//水牌
         //统计前三个商品
-        $skn=array();
-        $arr=array();
+        $skn = array();
+        $arr = array();
         if (isset($data['goods']) && !empty($data['goods'])) {
-            $arr = array_slice($data['goods'],0,3);
-            foreach ($arr as $key=>$value) {
+            $arr = array_slice($data['goods'], 0, 3);
+            foreach ($arr as $key => $value) {
                 $skn[] = $value['skn'];
             }
-            $arr = array('skn'=>$skn);
-        }else{
-            $arr = array('skn'=>array());
-        }
-        
-        if (!empty($result['multBrandShopType']) && !empty($result['shopId']) && $result['multBrandShopType'] === 2) {
-            //多品牌无banner
-            $data['brandBanner'] = array();
+            $arr = array('skn' => $skn);
+        } else {
+            $arr = array('skn' => array());
         }
 
+        /* if (!empty($result['multBrandShopType']) && !empty($result['shopId']) && $result['multBrandShopType'] === 2) {
+             //多品牌无banner
+             $data['brandBanner'] = array();
+         }*/
+
         $seo = $data['seo'];
         $data = array(
             //初始化js
@@ -151,14 +177,13 @@ class IndexController extends WebAction
             return '';
         }
         $node = $this->post('node');
-        //$mode = $this->post('mode');
         if (!isset($node)) {
             return '';
         }
         $nodeContent = BrandData::getByNodeContent($node);
 
         if (isset($nodeContent['code']) && $nodeContent['code'] == 200) {
-            echo '<br>', $nodeContent['data'];
+            echo '<br>', Helpers::getUrlSafe($nodeContent['data']);
         }
     }
 
@@ -173,7 +198,7 @@ class IndexController extends WebAction
         $brandId = $this->post('brandId');
         //$status = $this->post('status');
         if (!isset($brandId)) {
-            return array('code'=>201,'brandId is null');
+            return array('code' => 201, 'brandId is null');
         }
         $result = BrandsModel::getAdNav($brandId);
 
@@ -188,6 +213,7 @@ class IndexController extends WebAction
     {
         //品牌域名
         $domain = $this->param('named');
+
         if (empty($domain)) {
             $this->go(SITE_MAIN);
         }
@@ -225,6 +251,50 @@ class IndexController extends WebAction
     }
 
     /**
+     * 店铺介绍
+     */
+    public function aboutShopAction()
+    {
+        $shopId = $this->get('shopId');
+        $domain = $this->param('named');
+
+        $uid = $this->getUid();
+
+        $shopIntro = ShopModel::getIntro($shopId, $uid);
+
+        $data = array(
+            //初始化js
+            'searchListPage' => true,
+        );
+
+        if (!empty($shopId)) {
+            $basisData = ShopModel::basisTemplate($shopId);
+
+            if (!empty($basisData)) {
+                $data['list'] = array(
+                    'shopBanner' => array(
+                        'banner' => $basisData['shopTopBanner_base']['banner'], // 2600x150
+                        'shopHome' => Helpers::url('/', array('shopId' => $shopId), $domain),
+                        'shopIntro' => Helpers::url('/aboutShop', array('shopId' => $shopId)),
+                        'coled' => $shopIntro['isFavorite'],
+                        'shopId' => $shopId
+                    ),
+                    'shopAbout' => empty($shopIntro['brandCont']) ? $shopIntro['brandName']: $shopIntro['brandCont']
+                );
+            } else {
+                return array('code' => 201, 'no data get from api or data error');
+            }
+        } else {
+            return array('code' => 201, 'no shop id');
+        }
+
+        $this->setWebNavHeader();
+        $this->setTitle($shopIntro['brandName'] . $shopIntro['domain'], true, '|');
+
+        $this->_view->display('list', $data);
+    }
+
+    /**
      * 收藏品牌ajax请求
      */
     public function favoriteBrandAction()
@@ -252,13 +322,51 @@ class IndexController extends WebAction
                 $result = FavoriteData::changeFavoriteBrand($uid, $brandId);
                 break;
             }
-        }
-        while (false);
+        } while (false);
         //返回json格式
         $this->echoJson($result);
 
     }
-    
+
+
+    /**
+     * 收藏店鋪,基礎模板
+     */
+    public function favoriteShopAction()
+    {
+        if (!$this->isAjax()) {
+            return;
+        }
+        $result = array(
+            'code' => 400,
+            'message' => '操作失败'
+        );
+        $uid = $this->getUid();
+        
+        $shopId = $this->post('shopId');
+        $isFavorite = $this->post('isFavorite');
+        $needColloect = $this->post('needColloect', 0);
+
+        do {
+            if (!$uid) {
+                $result = array(
+                    'code' => 403,
+                    'message' => '用户ID不存在',
+                    'data' => array('url' => Helpers::url('/signin.html', array())),
+                );
+                break;
+            }
+            if ($uid && $shopId) {
+
+                //调用接口收藏或取消收藏
+                $result = ShopModel::setFavorite($shopId, $isFavorite, $uid);
+                break;
+            }
+        } while (false);
+        //返回json格式
+        $this->echoJson($result);
+    }
+
     /**
      * 判断品牌是否收藏
      */
@@ -272,7 +380,7 @@ class IndexController extends WebAction
         if ($uid && $brandId) {
             //调用接口收藏或取消收藏
             $result = FavoriteData::isFavoriteBrand($uid, $brandId);
-            $this ->echoJson($result);
+            $this->echoJson($result);
         }
     }
 
@@ -345,9 +453,9 @@ class IndexController extends WebAction
                     'shop' => $shopId
                 ),
                 array(
-                'controller' => 'Index',
-                'action' => 'index',
-                'misort' => $misort
+                    'controller' => 'Index',
+                    'action' => 'index',
+                    'misort' => $misort
                 )
             );
             $data['shopIndexPage'] = true;
@@ -386,7 +494,7 @@ class IndexController extends WebAction
 
         $this->_view->display('shop-index', $data);
     }
-    
+
     //店铺列表页
     public function shopListAction()
     {
@@ -429,7 +537,7 @@ class IndexController extends WebAction
     }
 
     /**
-     * 店铺收藏与取消
+     * 店铺收藏与取消,經典模板
      * @return type json
      */
     public function setFavoriteAction()
@@ -442,7 +550,7 @@ class IndexController extends WebAction
         //获取uid
         $uid = $this->getUid();
 
-        do{
+        do {
             if (empty($uid)) {
                 $result = array(
                     'code' => 401,
@@ -459,7 +567,7 @@ class IndexController extends WebAction
                 break;
             }
 
-            //$needColloect 说明刚登录状态 是cookie 传的值
+            //$needColloect 说明刚登录状态 是cookie传的值
             $isFavorite = $needColloect * 1 === 1 ? true : $isFavorite;
             $result = ShopModel::setFavorite($shopId, $isFavorite, $uid);
 
--
libgit2 0.24.0