Authored by 梁志锋

Merge branch 'develop' of git.dev.yoho.cn:web/yohobuy into develop

... ... @@ -351,7 +351,7 @@
{
//onlyOne
relatedReco: {
onlyOne: true, //若只有一个商品,传此字段为true
id: 1, //必须字段
thumb: '',
name: '',
salePrice: 123,
... ...
framework @ 75bbc3b0
Subproject commit 119c247f5cf929aa1e059e40609bb16dd6b58f05
Subproject commit 75bbc3b075de19f239532f60c5995d06c5f814e2
... ...
... ... @@ -189,6 +189,32 @@ class AbstractAction extends Controller_Abstract
return Cache::get($key, 'slave');
}
}
/**
* 获取当前登录的用户ID
*
* @return int
* @todo
*/
protected function getUid()
{
return 0;
}
/**
* 获取客户端唯一标识
*
* @return string
*/
protected function getUdid()
{
$udid = '';
$ip = $this->_request->getServer('REMOTE_ADDR');
if ($ip) {
$udid = ip2long($ip);
}
return $udid;
}
/*
* 设置网站SEO的标题
... ...
... ... @@ -11,6 +11,8 @@
*/
namespace Api;
use Plugin\Cache;
class Yohobuy
{
... ... @@ -93,12 +95,25 @@ class Yohobuy
*
* @param string $url 接口URL
* @param array $data 参数列表
* @param mixed $cache 控制是否启用接口数据的缓存 如3600表示缓存1小时, false表示不缓存
* @param bool $returnJson 控制是否返回json格式数据
* @param int $timeout 超时时间
* @return mixed
*/
public static function get($url, $data = array(), $returnJson = false, $timeout = 5)
public static function get($url, $data = array(), $cache = false, $returnJson = false, $timeout = 5)
{
// 代表是否开启缓存
$useCache = $cache && isset($data['client_secret']);
/* 先尝试获取一级缓存(master), 有数据则直接返回 */
if ($useCache) {
$key = md5($url . $data['client_secret']);
$result = Cache::get($key, 'master');
if (!empty($result)) {
return $result;
}
}
// 销毁私钥参数
if (isset($data['private_key'])) {
unset($data['private_key']);
... ... @@ -117,6 +132,18 @@ class Yohobuy
}
curl_close($ch);
$data = array();
/* 设置一级二级缓存 或 获取二级缓存(slave) */
if ($useCache) {
// 如果接口异常没数据返回,则获取二级缓存
if (empty($result)) {
$result = Cache::get($key, 'slave');
}
// 如果接口正常有数据返回,则设置数据缓存
else {
Cache::set($key, $result);
}
}
return $result;
}
... ... @@ -176,9 +203,11 @@ class Yohobuy
*
* @param array $urlList 接口列表
* @param array $options CURL设置项
* @parma mixed $cache 控制是否启用接口数据的缓存 如3600表示缓存1小时, false表示不缓存
* @param int $timeout 超时时间,单位是秒
* @return array
*/
public static function getMulti($urlList = array(), $options = array())
public static function getMulti($urlList = array(), $options = array(), $cache = false, $timeout = 3)
{
$result = array();
$response = array();
... ... @@ -188,8 +217,8 @@ class Yohobuy
$defaultOptions = array(
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CONNECTTIMEOUT => 3,
CURLOPT_TIMEOUT => 3,
CURLOPT_CONNECTTIMEOUT => $timeout,
CURLOPT_TIMEOUT => $timeout,
CURLOPT_NOSIGNAL => 1, //忽略所有的curl传递给php的信号,减少并发crash
);
$mh = curl_multi_init();
... ... @@ -269,14 +298,11 @@ class Yohobuy
try {
$result = call_user_func_array(array($client, $method), $parameters);
} catch (\Exception $e) {
var_dump($e);
$result = array();
}
if (!empty($result['data'])) {
return $result['data'];
} else {
return array();
}
return $result;
}
/**
... ...
... ... @@ -34,27 +34,28 @@ class DetailData
$article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticle', array($id));
if (!isset($article['tag'])) {
return $result;
} else {
}
else {
$result['getArticle'] = $article;
}
// 获取作者信息
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_AUTHOR, 'getAuthor', array($id), function ($retval) use (&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_AUTHOR, 'getAuthor', array($article['author_id']), function ($retval) use (&$result) {
$result['getAuthor'] = empty($retval) ? array() : $retval;
});
// 获取资讯内容
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getArticleContent', array($id), function ($retval) use (&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getArticleContent', array($id), function ($retval) use (&$result) {
$result['getArticleContent'] = empty($retval) ? array() : $retval;
});
// 获取资讯相关的品牌
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getBrand', array($id), function ($retval) use (&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getBrand', array($id), function ($retval) use (&$result) {
$result['getBrand'] = empty($retval) ? array() : $retval;
});
// 获取资讯相关的其它资讯
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getOtherArticle', array($article['tag'], $id, 0, 3), function ($retval) use (&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_PACKAGE_ARTICLE, 'getOtherArticle', array($article['tag'], $id, 0, 3), function ($retval) use (&$result) {
$result['getOtherArticle'] = empty($retval) ? array() : $retval;
});
... ...
... ... @@ -4,6 +4,7 @@ namespace LibModels\Wap\Guang;
use Api\Sign;
use Api\Yohobuy;
use Plugin\Cache;
/**
* 逛首页列表相关的数据模型
... ... @@ -16,6 +17,10 @@ use Api\Yohobuy;
*/
class ListData
{
const URI_CATEGORY = 'guang/api/v1/category/get';
const URI_ARTICLELIST = 'guang/api/v2/article/getList';
const URI_AUTHOR = 'guang/service/v1/author/';
/**
* 逛分类
*
... ... @@ -25,39 +30,90 @@ class ListData
*/
public static function category()
{
return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v1/category/get');
$param = Yohobuy::param();
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_CATEGORY, $param);
}
/**
* 逛内容列表
*
* @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示所有
* @param int $sortId 分类ID
* @param int $uid 用户ID
* @param string $udid 客户端唯一标识
* @param int $page 分页第几页, 默认第1页
* @param string $tag 标签
* @param int $authorId 作者ID
* @return array
*/
public static function article($gender, $sortId, $uid = 0, $udid = '', $page = 1, $tag = null, $authorId = null)
{
$param = Yohobuy::param();
$param['gender'] = $gender;
$param['page'] = $page;
$param['uid'] = $uid;
$param['udid'] = $udid;
if (isset($sortId)) {
$param['sort_id'] = $sortId;
}
if (isset($tag)) {
$param['tag'] = $tag;
}
if (isset($authorId) && is_numeric($authorId)) {
$param['author_id'] = $authorId;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
}
/**
* 根据分类进行分组的逛内容列表
*
* @param array $category 分类
* @param string $gender "1,3"表示男, "2,3"表示女
* @param int $page 分页第几页, 默认第1页
* @param int $channel 1表示男, 2表示女
* @param int $uid 用户ID
* @param string $udid 客户端cookie唯一标识
* @param string $udid 客户端唯一标识
* @param int $page 分页第几页, 默认第1页
* @return array
*/
public static function articleGroup($category, $gender, $channel, $uid = 0, $udid, $page = 1)
public static function articleGroup($category, $gender, $uid = 0, $udid, $page = 1)
{
$urlList = array();
$param = array();
foreach ($category as $value) {
$param = Yohobuy::param();
$param['gender'] = $gender;
$param['page'] = $page;
$param['yh_channel'] = $channel;
$param['sort_id'] = $value['id'];
$param['uid'] = $uid;
$param['udid'] = $udid;
$param['client_secret'] = Sign::getSign($param);
$urlList[ $value['id'] ] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . 'guang/api/v2/article/getList', $param);
}
$urlList[$value['id']] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
}
return Yohobuy::getMulti($urlList);
}
/**
* 获取作者信息
*
* @param int $id 作者ID
* @return array
*/
public static function author($id)
{
$result = array();
if (is_numeric($id)) {
$result = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_AUTHOR, 'getAuthor', array($id));
}
return $result;
}
}
... ...
... ... @@ -87,7 +87,7 @@ class PlusstarData
// 品牌详情信息
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_PLUSSTAR, 'getBrandInfo', array(array('id' => $id)) );
if (!isset($brandInfo['brand_id'])) {
if (!isset($brandInfo['data']['brand_id'])) {
return $result;
} else {
$result['getBrandInfo'] = $brandInfo;
... ... @@ -103,7 +103,7 @@ class PlusstarData
// 相关资讯列表 (3篇)
$result['getArticleByBrand'] = array();
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_ARTICLE, 'getArticleByBrand', array($brandInfo['brand_id'], 3, $udid), function($retval) use(&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::URI_BRANDINFO_ARTICLE, 'getArticleByBrand', array($brandInfo['data']['brand_id'], 3, $udid), function($retval) use(&$result) {
$result['getArticleByBrand'] = empty($retval) ? array() : $retval;
});
... ... @@ -115,7 +115,7 @@ class PlusstarData
// 调用搜索接口
$param = Yohobuy::param();
$param['method'] = 'app.search.li';
$param['brand'] = $brandInfo['brand_id'];
$param['brand'] = $brandInfo['data']['brand_id'];
$param['page'] = '0';
$param['limit'] = '6';
$param['gender'] = $gender;
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
namespace LibModels\Wap\Product;
use Api\Yohobuy;
use Api\Sign;
/**
* 商品列表相关的数据模型
*
* @name ListData
* @package LibModels/Wap/Product
* @copyright yoho.inc
* @version 1.0 (2015-10-15 20:15:02)
* @author fei.hong <fei.hong@yoho.cn>
*/
class ListData
{
const URI_PRODUCT = 'shops/service/v1/product';
/**
* 根据商品SKN获取商品的简要信息
*
* @param array $skns
* @return array
*/
public static function productInfoBySkns($skns)
{
//return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PRODUCT, 'getLessInfoByProductSkns', array());
// 调用搜索接口
$param = Yohobuy::param();
$param['method'] = 'app.search.li';
$param['query'] = implode(' ', $skns);
$param['limit'] = count($skns);
$param['order'] = 's_t_desc';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 根据商品SKC获取商品的简要信息
*
* @param array $skcs
* @return array
*/
public static function productInfoBySkcs($skcs)
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_PRODUCT, 'getLessInfoByProductSkcs', array(array('productSkcs' => $skcs)));
}
}
... ...
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
... ...
... ... @@ -16,7 +16,7 @@ class Helpers
* @param integer $mode 模式
* @return string 图片地址
*/
public static function getImageUrl($fileName, $width, $height, $mode = 1)
public static function getImageUrl($fileName, $width, $height, $mode = 2)
{
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
}
... ... @@ -27,7 +27,7 @@ class Helpers
* @param array $productData 需要格式化的商品数据
* @return array | false
*/
public static function formatProduct($productData)
public static function formatProduct($productData, $showTags = true)
{
// 商品信息有问题,则不显示
if (!isset($productData['product_skn'])) {
... ... @@ -42,21 +42,85 @@ class Helpers
$result = array();
$result['id'] = $productData['product_skn'];
$result['product_id'] = $productData['product_id'];
$result['thumb'] = Helpers::getImageUrl($productData['default_images'], 235, 314);
$result['thumb'] = self::getImageUrl($productData['default_images'], 235, 314);
$result['name'] = $productData['product_name'];
$result['price'] = $productData['market_price'];
$result['salePrice'] = $productData['sales_price'];
$result['isFew'] = ($productData['is_soon_sold_out'] === 'Y');
$result['url'] = ''; // @todo
$result['tags'] = array();
$result['tags']['isNew'] = isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品
$result['tags']['isSale'] = isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售
$result['tags']['isLimit'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量
$result['tags']['isYohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD
$result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中
$result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末
$result['tags']['isReNew'] = false; // 再到着
$result['tags']['isNewFestival'] = false; // 新品节
if ($showTags) {
$result['tags'] = array();
$result['tags']['isNew'] = isset($productData['is_new']) && $productData['is_new'] === 'Y'; // 新品
$result['tags']['isSale'] = isset($productData['is_discount']) && $productData['is_discount'] === 'Y'; // 在售
$result['tags']['isLimit'] = isset($productData['is_limited']) && $productData['is_limited'] === 'Y'; // 限量
$result['tags']['isYohood'] = isset($productData['is_yohood']) && $productData['is_yohood'] === 'Y'; // YOHOOD
$result['tags']['midYear'] = isset($productData['mid-year']) && $productData['mid-year'] === 'Y'; // 年中
$result['tags']['yearEnd'] = isset($productData['year-end']) && $productData['year-end'] === 'Y'; // 年末
$result['tags']['isReNew'] = false; // 再到着
$result['tags']['isNewFestival'] = false; // 新品节
}
return $result;
}
/**
* 格式化资讯文章
*
* @param array $articleData 需要格式化的资讯数据
* @param bool $showTag 是否显示左上角标签
* @param mixed $share 是否显示分享,在APP客户端里嵌入需要传url链接
* @param bool $showAuthor 控制是否显示作者信息
* @return array | false
*/
public static function formatArticle($articleData, $showTag = true, $share = false, $showAuthor = true)
{
// 资讯ID不存在,则不显示
if (!isset($articleData['id'])) {
return false;
}
$result = array();
$result['id'] = $articleData['id'];
$result['showTag'] = $showTag;
$result['img'] = self::getImageUrl($articleData['src'], 640, 640);
$result['url'] = $articleData['url']; // @todo
$result['title'] = $articleData['title'];
$result['text'] = $articleData['intro'];
$result['publishTime'] = $articleData['publish_time'];
$result['pageView'] = $articleData['views_num'];
$result['like'] = array();
$result['like']['count'] = $articleData['praise_num'];
$result['like']['isLiked'] = isset($articleData['isPraise']) && $articleData['isPraise'] === 'Y';
$result['collect'] = array();
$result['collect']['isCollected'] = isset($articleData['isFavor']) && $articleData['isFavor'] === 'Y';
$result['share'] = $share;
// 判断是否显示作者信息
if ($showAuthor) {
$result['author'] = $articleData['author'];
}
// 模板中需要的标签标识
if ($showTag) {
switch (strval($articleData['category_id'])) {
case '1': // 话题
$result['isTopic'] = true;
break;
case '2': // 搭配
$result['isCollocation'] = true;
break;
case '3': // 潮人
$result['isFashionMan'] = true;
break;
case '4': // 潮品
$result['isFashionGood'] = true;
break;
case '5': // 小贴士
$result['isTip'] = true;
break;
}
}
return $result;
}
... ... @@ -210,4 +274,29 @@ class Helpers
return false;
}
/**
* 获取商品的ICON
*
* @param int $type
* @return array
*/
public static function getProductIcon($type)
{
static $icons = array(
1 => 'cloth',
3 => 'pants',
4 => 'dress',
6 => 'shoe',
7 => 'bag',
10 => 'lamp',
241 => 'headset',
8 => 'watch',
360 => 'swim-suit',
308 => 'under'
);
$type = intval($type);
return isset($icons[$type]) ? $icons[$type] : '';
}
}
... ...
... ... @@ -66,7 +66,7 @@
{{#if relatedReco}}
<div class="post-block related-reco-block clearfix">
<h2>相关推荐</h2>
{{#if relatedReco.onlyOne}}
{{#if relatedReco.id}}
{{#with relatedReco}}
<div class="one-good">
<img class="thumb lazy" data-original={{thumb}}>
... ...
{{# infos}}
{{> guang/info}}
{{/ infos}}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\DetailData;
use LibModels\Wap\Product\ListData;
use Plugin\Helpers;
/**
* 逛详情页
*/
class DetailController extends AbstractAction
{
/**
* 详情页
*
* @param int id 内容ID
*/
public function indexAction()
{
$data = array(
'id' => 1,
'author' => array(
'avatar' => 'http://7xidk0.com1.z0.glb.clouddn.com/avater.png',
'name' => '山本耀司',
'intro' => '日本设计界一代宗师,分享一些个人区委分享内容不求有用但求有趣区委分享内容不求有用但求有趣区委分享内容不求有用但求有趣区委分享内容不求有用但求有趣',
'url' => ''
),
'detail' => array(
'title' => 'Skin Art Series INN 2015新品',
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'content' => array(
array(
'text' => '复古风劲吹,在各路复古跑鞋嚣张跋扈的当下,历史悠久的Onitsuka也动作频频'
),
array(
'bigImage' => 'http://img10.static.yhbimg.com/yhb-img01/2015/06/11/15/017b3fa0478e26a3ded2ac75d341fe3ab6.jpg?imageView/2/w/640/h/640'
),
array(
'relatedReco' => array(
'onlyOne' => true,
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'GAWS DIGI 丛林数码印花拼接卫衣看看两行文字以上能不能切字啦,样式应该不会乱的吧',
'isLike' => false,
'price' => 1268,
'salePrice' => 589,
'url' => ''
)
),
array(
'collocation' => array(
array(
'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/clothe.png',
'type' => 'pants',
'goods' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'GAWS DIGI 丛林数码印花拼接卫衣',
'price' => 1268,
'salePrice' => 589,
'tags' => array(
array(
'isNew' => true
)
),
'isFew' => true,
'url' => ''
)
),
array(
'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/clothe.png',
'type' => 'cloth',
'goods' => array(
'id' => 1,
'thumb' => 'http://img11.static.yhbimg.com/goodsimg/2015/03/02/07/01ebfb219e22770ffb0c2c3a2cbb2b4bef.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90',
'name' => 'GAWS DIGI 丛林数码印花拼接卫衣',
'price' => 1268,
'salePrice' => 589,
'tags' => array(
array(
'isNew' => true
)
),
'isFew' => true,
'url' => ''
)
)
)
)
)
),
'relatedBrand' => array(
array(
'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/logo.png',
'name' => 'HALFGIRL测试名字长的情况',
'url' => ''
),
array(
'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/logo.png',
'name' => '黄伟文Wyman',
'url' => ''
),
array(
'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/logo.png',
'name' => 'HIPANDA',
'url' => ''
)
),
'relatedTag' => array(
array(
'name' => '棒球服',
'url' => ''
)
),
'relatedInfo' => array(
array(
'thumb' => 'http://7xidk0.com1.z0.glb.clouddn.com/pant.png',
'title' => '复古风劲吹,在各路复古跑鞋嚣张跋扈的当下,历史悠久的Onitsuka',
'url' => '',
'publishTime' => '2月13日 12:34'
)
)
);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('index', array('modulePath' => 'guang/detail', 'guang' => $data));
$id = $this->get('id');
// 判断参数是否有效, 无效会跳转到错误页面
if (!is_numeric($id)) {
$this->error();
}
// 获取详情内容信息, 异常则跳到错误页面
$detail = DetailData::package($id);
if (empty($detail['getArticle'])) {
$this->error();
}
$data = array();
$data['guangDetail'] = true; // 模板中使用JS的标识
$data['guang']['id'] = $id;
// 作者信息数据
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'];
$data['guang']['author']['url'] = '/guang/list/editor?id=' . $detail['getArticle']['author_id'];
}
$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'];
$data['detail']['content'][] = $build;
}
// 单张图
elseif (isset($value['singleImage'])) {
$build['bigImage'] = Helpers::getImageUrl($value['singleImage']['data'][0]['src'], 640, 640);
$data['detail']['content'][] = $build;
}
// 相关推荐
elseif (isset($value['goods']['data'])) {
$good = array();
// 遍历取得SKN
$skns = array();
foreach ($value['goods']['data'] as $goods) {
$skns[] = $goods['id'];
}
// 通过SKN获取商品信息
$product = ListData::productInfoBySkns($skns);
foreach ($product['data']['product_list'] as $i => $goods) {
// 最多显示4个
if ($i > 3) {
break;
}
$good[] = Helpers::formatProduct($goods, false);
}
// 单个商品
if ($i === 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);
foreach ($product['data']['product_list'] as $i => $goods) {
$good['goods'][] = Helpers::formatProduct($goods, false);
}
$build['collocation'][] = $good;
}
}
$data['detail']['content'][] = $build;
}
}
// 相关品牌
if (!empty($detail['getBrand'])) {
$data['relatedBrand'] = $detail['getBrand'];
}
// 相关标签
if (!empty($detail['getArticle']['tags'])) {
foreach ($detail['getArticle']['tags'] as $value) {
$value['url'] = '/guang/list/tag?query=' . $value['name'];
$data['relatedTag'][] = $value;
}
}
// 相关文章
if (!empty($detail['getOtherArticle'])) {
foreach ($detail['getOtherArticle'] as $value) {
$value['url'] = '/guang/detail/index?id=' . $value['id'];
$data['relatedInfo'][] = $value;
}
}
$this->_view->display('index', $data);
$detail = array();
$data = array();
}
}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\ListData;
use Plugin\Helpers;
/**
* 逛首页、列表页、编辑页
... ... @@ -8,351 +11,113 @@ class ListController extends AbstractAction
{
/**
* 首页
*
* @param int type 分类ID 0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士
* @param string gender '1,3'表示男,'2,3'表示女
*/
public function indexAction()
{
$data = array(
'swiper' => array(
array(
'url' => '',
'img' => 'http://img11.static.yhbimg.com/yhb-img01/2015/07/06/10/014fd517e2fe3f3e0dc3cbc3007d8093af.jpg?imageView/2/w/640/h/640'
),
array(
'url' => '',
'img' => 'http://img10.static.yhbimg.com/yhb-img01/2015/07/03/13/01a165dd33db8488edc741241950a596a8.jpg?imageView/2/w/640/h/640'
)
),
'navs' => array(
array(
'typeId' => 1,
'type' => '最新'
),
array(
'typeId' => 2,
'type' => '话题',
'focus' => true
),
array(
'typeId' => 3,
'type' => '搭配'
),
array(
'typeId' => 4,
'type' => '潮人'
),
array(
'typeId' => 5,
'type' => '潮物'
),
array(
'typeId' => 6,
'type' => '小贴士'
)
),
'infos' => array(
array(
'info' => array(
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionMan' => true,
'author' => array(
'url' => '',
'name' => 'LEO_LU',
'avatar' => 'http://img11.static.yhbimg.com/yhb-img02/2015/09/07/02/01a050445c64825eed381c4e049030c692.jpg?imageView/0/w/100/h/100'
)
),
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'collect' => array(
'isCollected' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isTip' => true,
'author' => array(
'url' => '',
'name' => 'Kishi',
'avatar' => 'http://img13.static.yhbimg.com/yhb-img02/2015/06/12/10/0256020c504fb08a176c5457599bdf5b49.jpg?imageView/0/w/100/h/100'
)
)
)
),
array(
'show' => true,
'info' => array(
array(
'id' => 2,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => false,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 100,
'isLiked' => false
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionGood' => true
)
)
),
array(
'info' => array(
array(
'id' => 2,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => false,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 100,
'isLiked' => false
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionGood' => true
),
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isTip' => true
)
)
),
array(
'info' => array(
array(
'id' => 2,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => false,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 100,
'isLiked' => false
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionGood' => true
),
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isTip' => true
)
)
),
array(
'info' => array(
array(
'id' => 2,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => false,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 100,
'isLiked' => false
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionGood' => true
),
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isTip' => true
)
)
),
array(
'info' => array(
array(
'id' => 2,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => false,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 100,
'isLiked' => false
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionGood' => true
),
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isTip' => true
)
)
)
)
);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('index', array('guangHome' => true, 'guang' => $data));
$this->setTitle('逛');
$category = ListData::category();
$articleGroup = array();
$uid = $this->getUid();
$udid = $this->getUdid();
$type = $this->get('type', 0);
$gender = $this->get('gender');
// 男
if ($gender === '1,3') {
$articleGroup = ListData::articleGroup($category['data'], '1,3', $uid, $udid);
}
// 女
elseif ($gender === '2,3') {
$articleGroup = ListData::articleGroup($category['data'], '2,3', $uid, $udid);
}
// 所有
else {
$articleGroup = ListData::articleGroup($category['data'], '1,2,3', $uid, $udid);
}
$data = array();
$build = array();
// 模板中使用JS的标识
$data['guangHome'] = true;
// 顶部的分类列表
foreach ($category['data'] as $value) {
$build = array();
$build['typeId'] = $value['id'];
$build['type'] = $value['name'];
$build['focus'] = ($value['id'] == $type);
$data['navs'][] = $build;
}
$data['guang']['swiper'] = array();
$data['guang']['infos'] = array();
foreach ($articleGroup as $id => $value) {
// 轮番广告
if ($id == 0) {
$build = array();
foreach ($value['list']['adlist'] as $banner) {
$build['url'] = $banner['url'];
$build['img'] = Helpers::getImageUrl($banner['src'], 830, 327);
$data['guang']['swiper'][] = $build;
}
}
// 内容列表
$build = array();
$build['show'] = ($id == $type);
foreach ($value['list']['artList'] as $article) {
$build['info'][] = Helpers::formatArticle($article, true, false);
}
$data['guang']['infos'][] = $build;
}
// 分页需要参数
$data['guang']['gender'] = $gender;
$this->_view->display('index', $data);
}
/**
* 列表页
*
* @param string tag 标签名称
*/
public function listAction()
public function tagAction()
{
$data = array(
'infos' => array(
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionMan' => true
),
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isTip' => true
),
array(
'id' => 2,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => false,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 100,
'isLiked' => false
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionGood' => true
)
)
);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('list', array('modulePath' => 'guang/list', 'guang' => $data));
$tag = $this->get('query');
$uid = $this->getUid();
$udid = $this->getUdid();
// 标签聚合内容列表
$article = ListData::article('', 0, $uid, $udid, 1, $tag);
// 标签聚合内容不存在, 跳到错误页面
if (empty($article['data']['list']['artList'])) {
$this->error();
}
$data = array();
// 模板中使用JS的标识
$data['guangList'] = true;
// 构建资讯文章内容
$build = array();
foreach ($article['data']['list']['artList'] as $article) {
$build[] = Helpers::formatArticle($article, true, false);
}
$data['guang']['infos'] = $build;
// 分页需要的参数
$data['guang']['tag'] = $tag;
$this->setTitle($tag);
$this->_view->display('list', $data);
}
/**
... ... @@ -360,70 +125,104 @@ class ListController extends AbstractAction
*/
public function editorAction()
{
$data = array(
'author' => array(
'avatar' => 'http://7xidk0.com1.z0.glb.clouddn.com/avater.png',
'name' => '山本耀司',
'info' => '设计理念:他以简洁而富有韵味,线条流畅,反时尚的设计风格而著称。'
),
'infos' => array(
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionMan' => true
),
array(
'id' => 1,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '1.副线不知为何总是好看点',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => true,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 459,
'isLiked' => true
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isTip' => true
),
array(
'id' => 2,
'img' => 'http://7xidk0.com1.z0.glb.clouddn.com/bg.png',
'title' => '2.副线不知为何总是好看点测试长度是否会被截取塞真的很恶心啊',
'text' => '具有绅士气质的英伦风格是永走前沿的经典,在众多的Made ' .
'In England中Panul Smith缔造了一个传奇',
'showTags' => false,
'publishTime' => '2月13日 12:34',
'pageView' => 3445,
'like' => array(
'count' => 100,
'isLiked' => false
),
'share' => true,
'url' => '',
'likeUrl' => '',
'isFashionGood' => true
)
)
);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('list', array('modulePath' => 'guang/list', 'guang' => $data));
$id = $this->get('id');
$uid = $this->getUid();
$udid = $this->getUdid();
// 获取作者信息
$author = ListData::author($id);
// 作者信息不存在,则跳到错误页面
if (!isset($author['name'])) {
$this->error();
}
$this->setTitle('编辑简介');
$data = array();
// 模板中使用JS的标识
$data['guangList'] = true;
// 作者信息
$data['author'] = array();
$data['author']['avatar'] = Helpers::getImageUrl($author['avatar'], 100, 100);
$data['author']['name'] = $author['name'];
$data['author']['info'] = $author['author_desc'];
$data['author']['id'] = $id;
// 标签聚合内容列表
$article = ListData::article('', 0, $uid, $udid, 1, null, $id);
// 构建资讯文章内容
if (!empty($article['data']['list']['artList'])) {
$build = array();
foreach ($article['data']['list']['artList'] as $article) {
$build[] = Helpers::formatArticle($article, true, false, false);
}
$data['guang']['infos'] = $build;
}
$this->_view->display('list', $data);
}
/**
* 逛列表页面的资讯分页
*
* 逛首页、标签页、编辑页资讯列表
*
* @param string tag 标签名称, 没有传空或不传
* @param int type 逛首页的分类ID
* @param int page 分页的页码
* @param string gender "1,2,3"表示所有, "1,3"表示男, "2,3"表示女
* @param int authorId 作者ID
* @return html
*/
public function pageAction()
{
do {
/* 判断是不是AJAX请求 */
if (!$this->isAjax()) {
break;
}
/* 判断参数是否有效 */
$tag = $this->get('tag');
$sortId = $this->get('type');
$page = $this->get('page');
$gender = $this->get('gender');
$authorId = $this->get('authorId');
$showAuthor = true;
if (!empty($sortId) && !is_numeric($sortId)) {
break;
}
if (!empty($page) && !is_numeric($page)) {
break;
}
if (!empty($authorId) && is_numeric($authorId)) {
$showAuthor = false;
}
/* 获取资讯文章列表 */
$uid = $this->getUid();
$udid = $this->getUdid();
$article = ListData::article($gender, 0, $uid, $udid, $page, $tag, $authorId);
if (empty($article['data']['list']['artList'])) {
break;
}
/* 构建资讯文章内容 */
$data = array();
$build = array();
foreach ($article['data']['list']['artList'] as $article) {
$build[] = Helpers::formatArticle($article, true, false, $showAuthor);
}
$data['infos'] = $build;
$this->_view->display('page', $data);
exit();
}
while (false);
echo ' ';
}
}
\ No newline at end of file
... ...