Blame view

yohobuy/m.yohobuy.com/application/modules/Guang/controllers/Info.php 13.4 KB
1 2 3 4 5
<?php

use Action\AbstractAction;
use LibModels\Wap\Guang\DetailData;
use LibModels\Wap\Product\ListData;
6
use LibModels\Wap\Guang\OptData;
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
use Plugin\Helpers;

/**
 * 逛详情页
 */
class InfoController extends AbstractAction
{

    /**
     * 详情页
     * 
     * @param int id 内容ID
     */
    public function indexAction()
    {
        $id = $this->get('id');
23
24 25 26 27
        // 判断参数是否有效, 无效会跳转到错误页面
        if (!is_numeric($id)) {
            $this->error();
        }
28
hf authored
29 30 31 32
        $data = array();
        $data['guangDetail'] = true; // 模板中使用JS的标识
        $data['guang']['id'] = $id;
33 34
        // 标识是不是APP访问的
        $isApp = null !== $this->get('app_version', null);
hf authored
35 36
        // 标识是否是微信访问
        $isWeixin = stripos($this->server('HTTP_USER_AGENT', ''), 'MicroMessenger') !== false;
37
38
        // WAP上设置头部导航
hf authored
39
        if (!$isApp && !$isWeixin) {
40
            $this->setNavHeader('逛', true, SITE_MAIN);
hf authored
41 42 43 44 45 46 47 48
        }

        // 获取详情内容信息, 异常则跳到错误页面
        $detail = DetailData::package($id, $isApp);
        if (empty($detail['getArticle'])) {
            $this->_view->display('index', $data);
            return;
        }
49
50 51 52 53 54 55
        // 作者信息数据
        if (isset($detail['getAuthor']['name'])) {
            $data['guang']['author'] = array();
            $data['guang']['author']['avatar'] = $detail['getAuthor']['avatar'];
            $data['guang']['author']['name'] = $detail['getAuthor']['name'];
            $data['guang']['author']['intro'] = $detail['getAuthor']['author_desc'];
56
            $data['guang']['author']['url'] = $isApp ? $detail['getAuthor']['url'] : Helpers::url('/author/index', array('id' => $detail['getArticle']['author_id']), 'guang');
57 58 59 60 61 62 63
        }

        $data['detail'] = array();
        $data['detail']['title'] = $detail['getArticle']['article_title'];
        $data['detail']['publishTime'] = $detail['getArticle']['publishTime'];
        $data['detail']['pageView'] = $detail['getArticle']['pageViews'];
        $data['detail']['content'] = array();
64
65 66 67 68 69
        if (!empty($detail['getArticleContent'])) {
            $build = array();
            $good = array();
            $skns = array();
            $product = array();
xuqi authored
70
71 72 73 74 75
            foreach ($detail['getArticleContent'] as $value) {
                $build = array();
                // 文字
                if (isset($value['text'])) {
                    $build['text'] = $value['text']['data']['text'];
76
                }
77 78 79
                // 单张图
                elseif (isset($value['singleImage'])) {
                    $build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640);
80
                } elseif (isset($value['smallPic']['data'])) {
xuqi authored
81 82 83 84 85 86 87 88 89
                    $imgs = $value['smallPic']['data'];
                    $build['smallImage'] = array(
                        array(
                            'src' => Helpers::getImageUrl($imgs[0]['src'], 315, 420)
                        ),
                        array(
                            'src' => Helpers::getImageUrl($imgs[1]['src'], 315, 420)
                        )
                    );
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
                }
                // 相关推荐
                elseif (isset($value['goods']['data'])) {
                    $good = array();
                    // 遍历取得SKN
                    $skns = array();
                    foreach ($value['goods']['data'] as $goods) {
                        $skns[] = $goods['id'];
                    }
                    // 通过SKN获取商品信息
                    $product = ListData::productInfoBySkns($skns);
                    if (!empty($product['data']['product_list'])) {
                        foreach ($product['data']['product_list'] as $i => $goods) {
                            // 最多显示4个
                            if ($i > 3) {
                                break;
                            }
107
                            $good[] = Helpers::formatProduct($goods, false, true, true, 235, 314, $isApp);
108 109 110 111 112 113 114
                        }
                    }
                    // 没有商品
                    if (!isset($i)) {
                        continue;
                    }
                    // 单个商品
hf authored
115
                    elseif ($i === 0 && isset($good[0])) {
116
                        $build['relatedReco'] = $good[0];
117
                    }
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
                    // 多个商品
                    else {
                        $build['relatedReco'] = $good;
                    }
                }
                // 悬停浮动商品
                elseif (isset($value['goodsGroup']['data'])) {
                    foreach ($value['goodsGroup']['data'] as $goods) {
                        $good = array();
                        $good['thumb'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314);
                        $good['type'] = Helpers::getProductIcon($goods['cover']['maxSortId']);
                        $good['goods'] = array();
                        $skns = array();
                        foreach ($goods['list'] as $mini) {
                            $skns[] = $mini['id'];
                        }
                        // 通过SKN获取商品信息
                        $product = ListData::productInfoBySkns($skns);
                        if (!empty($product['data']['product_list'])) {
                            foreach ($product['data']['product_list'] as $i => $goods) {
138
                                $good['goods'][] = Helpers::formatProduct($goods, false, true, true, 235, 314, $isApp);
139 140 141 142 143
                            }
                            $build['collocation'][] = $good;
                        }
                    }
                }
144
145 146 147
                $data['detail']['content'][] = $build;
            }
        }
148
149 150 151 152
        // 相关品牌
        if (!empty($detail['getBrand'])) {
            $data['relatedBrand'] = $detail['getBrand'];
        }
153
154 155 156
        // 相关标签
        if (!empty($detail['getArticle']['tags'])) {
            foreach ($detail['getArticle']['tags'] as $value) {
157
                if (!$isApp) {
hf authored
158
                    $value['url'] = Helpers::url('/tags/index', array('query' => $value['name']), 'guang');
159
                }
160 161 162
                $data['relatedTag'][] = $value;
            }
        }
163
164 165 166
        // 相关文章
        if (!empty($detail['getOtherArticle'])) {
            foreach ($detail['getOtherArticle'] as $value) {
167 168 169
                if (!$isApp) {
                    $value['url'] = Helpers::url('/info/index', array('id' => $value['id']), 'guang');
                }
170
                $value['thumb'] = Helpers::getImageUrl($value['thumb'], 279, 175);
171 172 173
                $data['relatedInfo'][] = $value;
            }
        }
174 175 176 177 178 179 180 181 182 183 184

        // 分享参数
        if (isset($detail['getArticle']['cover_image'])) {
            $data['shareLink'] = Helpers::url('/info/index', array('id' => $id), 'guang');
            $data['shareTitle'] = $detail['getArticle']['article_title'];
            $data['shareDesc'] = $detail['getArticle']['article_summary'];
            if ($detail['getArticle']['cover_image_type'] == 1) {
                $data['shareImg'] = Helpers::getImageUrl($detail['getArticle']['cover_image'], 640, 640);
            } else {
                $data['shareImg'] = Helpers::getImageUrl($detail['getArticle']['cover_image'], 640, 320);
            }
185 186
            $this->setTitle($detail['getArticle']['article_title']);
            $this->setDescription($detail['getArticle']['article_summary']);
187
        }
hf authored
188
hf authored
189 190
        // 标识有微信分享
        $data['hasWxShare'] = true;
191
        
192
        $this->_view->display('index', $data);
193
194 195 196
        $detail = array();
        $data = array();
    }
hf authored
197
198 199 200 201 202 203 204
    /**
     * APP里使用的收藏内容的接口
     * 
     * @param id 资讯ID
     * @param type "fav"表示收藏 或者 "cancel"表示取消收藏
     * @return json
     */
hf authored
205
    public function miniAction()
206
    {
hf authored
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
        $id = $this->get('id');

        // 判断参数是否有效, 无效会跳转到错误页面
        if (!is_numeric($id)) {
            $this->error();
        }

        $data = array();
        $data['guangEzine'] = true; // 模板中使用JS的标识
        $data['guang']['id'] = $id;

        // 获取详情内容信息, 异常则跳到错误页面
        $detail = DetailData::packageFoEzine($id, true);
        if (empty($detail['getArticle'])) {
            $this->_view->display('index', $data);
            return;
        }

        $data['detail'] = array();
        $data['detail']['title'] = $detail['getArticle']['article_title'];
        $data['detail']['publishTime'] = $detail['getArticle']['publishTime'];
        $data['detail']['pageView'] = $detail['getArticle']['pageViews'];
        $data['detail']['content'] = array();

        if (!empty($detail['getArticleContent'])) {
            $build = array();
            $good = array();
            $skns = array();
            $product = array();

            foreach ($detail['getArticleContent'] as $value) {
                $build = array();
                // 文字
                if (isset($value['text'])) {
                    $build['text'] = $value['text']['data']['text'];
                }
                // 单张图
                elseif (isset($value['singleImage'])) {
                    $build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640);
                } elseif (isset($value['smallPic']['data'])) {
                    $imgs = $value['smallPic']['data'];
                    $build['smallImage'] = array(
                        array(
                            'src' => Helpers::getImageUrl($imgs[0]['src'], 315, 420)
                        ),
                        array(
                            'src' => Helpers::getImageUrl($imgs[1]['src'], 315, 420)
                        )
                    );
                }
                // 相关推荐
                elseif (isset($value['goods']['data'])) {
                    $good = array();
                    // 遍历取得SKN
                    $skns = array();
                    foreach ($value['goods']['data'] as $goods) {
                        $skns[] = $goods['id'];
                    }
                    // 通过SKN获取商品信息
                    $product = ListData::productInfoBySkns($skns);
                    if (!empty($product['data']['product_list'])) {
                        foreach ($product['data']['product_list'] as $i => $goods) {
                            // 最多显示4个
                            if ($i > 3) {
                                break;
                            }
                            $good[] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
                        }
                    }
                    // 没有商品
                    if (!isset($i)) {
                        continue;
                    }
                    // 单个商品
                    elseif ($i === 0 && isset($good[0])) {
                        $build['relatedReco'] = $good[0];
                    }
                    // 多个商品
                    else {
                        $build['relatedReco'] = $good;
                    }
                }
                // 悬停浮动商品
                elseif (isset($value['goodsGroup']['data'])) {
                    foreach ($value['goodsGroup']['data'] as $goods) {
                        $good = array();
                        $good['thumb'] = Helpers::getImageUrl($goods['cover']['cover'], 235, 314);
                        $good['type'] = Helpers::getProductIcon($goods['cover']['maxSortId']);
                        $good['goods'] = array();
                        $skns = array();
                        foreach ($goods['list'] as $mini) {
                            $skns[] = $mini['id'];
                        }
                        // 通过SKN获取商品信息
                        $product = ListData::productInfoBySkns($skns);
                        if (!empty($product['data']['product_list'])) {
                            foreach ($product['data']['product_list'] as $i => $goods) {
                                $good['goods'][] = Helpers::formatProduct($goods, false, true, true, 235, 314, true);
                            }
                            $build['collocation'][] = $good;
                        }
                    }
                }

                $data['detail']['content'][] = $build;
312
            }
hf authored
313 314 315 316 317 318
        }

        // 相关品牌
        if (!empty($detail['getBrand'])) {
            $data['relatedBrand'] = $detail['getBrand'];
        }
hf authored
319
hf authored
320 321 322 323 324 325 326 327 328
        // 分享参数
        if (isset($detail['getArticle']['cover_image'])) {
            $data['shareLink'] = Helpers::url('/info/index', array('id' => $id), 'guang');
            $data['shareTitle'] = $detail['getArticle']['article_title'];
            $data['shareDesc'] = $detail['getArticle']['article_summary'];
            if ($detail['getArticle']['cover_image_type'] == 1) {
                $data['shareImg'] = Helpers::getImageUrl($detail['getArticle']['cover_image'], 640, 640);
            } else {
                $data['shareImg'] = Helpers::getImageUrl($detail['getArticle']['cover_image'], 640, 320);
hf authored
329
            }
hf authored
330 331 332 333 334 335 336 337 338
        }

        // 标识有微信分享
        $data['hasWxShare'] = true;

        $this->_view->display('index', $data);

        $detail = array();
        $data = array();
339
    }
340 341

}