Authored by hf

do guang list and detail data model

... ... @@ -264,7 +264,12 @@ class Yohobuy
$client->SetOpt(YAR_OPT_PACKAGER, 'php');
$client->SetOpt(YAR_OPT_TIMEOUT, $timeout);
$client->SetOpt(YAR_OPT_CONNECT_TIMEOUT, $timeout);
$result = call_user_func_array(array($client, $method), $parameters);
try {
$result = call_user_func_array(array($client, $method), $parameters);
} catch (\Exception $e) {
$result = array();
}
if (!empty($result['data'])) {
return $result['data'];
... ...
<?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\Guang;
use Api\Yohobuy;
/**
* 逛资讯详情相关的数据模型
*
* @name DetailData
* @package LibModels/Wap/Guang
* @copyright yoho.inc
* @version 1.0 (2015-10-10 14:49:15)
* @author fei.hong <fei.hong@yoho.cn>
*/
class DetailData
{
const API_URI_ARTICLE = 'guang/service/v2/article/';
const API_URI_AUTHOR = 'guang/service/v1/author/';
/**
* 逛资讯详情页数据封装
*/
public static function package($id)
{
$result = array();
$result['getAuthor'] = array();
$result['getArticle'] = array();
$result['getArticleContent'] = array();
$result['getBrand'] = array();
$result['getOtherArticle'] = array();
// 获取资讯
$article = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::API_URI_ARTICLE, 'getArticle', array($id));
if (!isset($article['tag'])) {
return $result;
} else {
$result['getArticle'] = $article;
}
// 获取作者信息
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_AUTHOR, 'getAuthor', array($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) {
$result['getArticleContent'] = empty($retval) ? array() : $retval;
});
// 获取资讯相关的品牌
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . self::API_URI_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) {
$result['getOtherArticle'] = empty($retval) ? array() : $retval;
});
// 调用发起请求
Yohobuy::yarConcurrentLoop();
return $result;
}
}
... ...
<?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\Guang;
use Api\Sign;
use Api\Yohobuy;
use Hood\Cache;
/**
* 逛首页列表相关的数据模型
*
* @name ListData
* @package LibModels/Wap/Guang
* @copyright yoho.inc
* @version 1.0 (2015-10-10 9:54:07)
* @author fei.hong <fei.hong@yoho.cn>
*/
class ListData
{
/**
* 逛分类
*
* 备注: id (0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士)
*
* @return array
*/
public static function category()
{
return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v1/category/get');
}
/**
* 根据分类进行分组的逛内容列表
*
* @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唯一标识
* @return array
*/
public static function articleGroup($category, $gender, $channel, $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);
}
return Yohobuy::getMulti($urlList);
}
}
... ...
<?php
namespace LibModels\Wap\Guang;
use Api\Sign;
use Api\Yohobuy;
/**
* 逛操作相关的数据模型
*
* @name OptData
* @package LibModels/Wap/Guang
* @copyright yoho.inc
* @version 1.0 (2015-10-10 11:51:16)
* @author fei.hong <fei.hong@yoho.cn>
*/
class OptData
{
/**
* 品牌收藏/取消收藏
*
* @param int $uid 用户ID
* @param int $id 唯一的ID
* @param string $opt 操作(ok:表示确定,cancel:表示取消)
* @return array
*/
public static function favoriteBrand($uid, $id, $opt = 'ok')
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'toggleBrandFav', array($uid, $id));
}
/**
* 商品收藏/取消收藏
*
* @param int $uid 用户ID
* @param int $skn 商品标识
* @param string $opt 操作(ok:表示确定,cancel:表示取消)
* @return array
*/
public static function favoriteProduct($uid, $skn, $opt = 'ok')
{
if ($opt === 'cancel') {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'addUidProductFav', array($uid, $skn));
} else {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'delUidProductFav', array($uid, $skn));
}
}
/**
* 品牌相关资讯点赞/取消赞
*
* @param int $uid 用户ID
* @param int $id 唯一的ID
* @param string $opt 操作(ok:表示确定,cancel:表示取消)
* @return array
*/
public static function praiseBrandArticle($uid, $id, $opt = 'ok')
{
if ($opt === 'cancel') {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'cancelPraise', array($id, $uid));
} else {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'setPraise', array($id, $uid));
}
}
/**
* 逛资讯点赞/取消赞
*
* @param int $udid 唯一客户端cookie标识
* @param int $id 唯一资讯的ID
* @param string $opt 操作(ok:表示确定,cancel:表示取消)
* @return array
*/
public static function praiseArticle($udid, $id, $opt = 'ok')
{
$param = Yohobuy::param();
$param['udid'] = $udid;
$param['article_id'] = $id;
$param['client_secret'] = Sign::getSign($param);
if ($opt === 'cancel') {
return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v2/praise/setPraise', $param);
} else {
return Yohobuy::get(Yohobuy::SERVICE_URL . 'guang/api/v2/praise/cancel', $param);
}
}
}
... ...
... ... @@ -72,22 +72,23 @@ class PlusstarData
*/
public static function brandInfo($id, $gender, $uid, $udid = null)
{
$isUidOk = $uid && is_numeric($uid);
// 品牌详情信息
$result = array();
$result['getBrandInfo'] = Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/plustar/', 'getBrandInfo', array(array('id' => $id)) );
$result['getBrandInfo'] = array();
$result['getUidBrandFav'] = false;
$result['getNewProduct'] = array();
$result['getUidProductFav'] = array();
$result['getArticleByBrand'] = array();
// 判断
if (!isset($result['getBrandInfo']['brand_id'])) {
// 品牌详情信息
$brandInfo = Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/plustar/', 'getBrandInfo', array(array('id' => $id)) );
if (!isset($brandInfo['brand_id'])) {
return $result;
} else {
$result['getBrandInfo'] = $brandInfo;
}
// 是否收藏店铺
$isUidOk = $uid && is_numeric($uid);
if ($isUidOk) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'getUidBrandFav', array($uid, $id), function($retval) use(&$result) {
$result['getUidBrandFav'] = empty($retval['data']) ? false : $retval['data'];
... ... @@ -96,7 +97,7 @@ class PlusstarData
// 相关资讯列表 (3篇)
$result['getArticleByBrand'] = array();
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'guang/service/v1/article/', 'getArticleByBrand', array($result['getBrandInfo']['brand_id'], 3, $udid), function($retval) use(&$result) {
Yohobuy::yarConcurrentCall(Yohobuy::SERVICE_URL . 'guang/service/v1/article/', 'getArticleByBrand', array($brandInfo['brand_id'], 3, $udid), function($retval) use(&$result) {
$result['getArticleByBrand'] = empty($retval) ? array() : $retval;
});
... ... @@ -108,7 +109,7 @@ class PlusstarData
// 调用搜索接口
$param = Yohobuy::param();
$param['method'] = 'app.search.li';
$param['brand'] = $result['getBrandInfo']['brand_id'];
$param['brand'] = $brandInfo['brand_id'];
$param['page'] = '0';
$param['limit'] = '6';
$param['gender'] = $gender;
... ... @@ -142,7 +143,7 @@ class PlusstarData
// 调用发起请求
Yohobuy::yarConcurrentLoop();
return $result;
... ... @@ -203,52 +204,5 @@ class PlusstarData
}
/**
* 品牌收藏/取消收藏
*
* @param int $uid 用户ID
* @param int $id 唯一的ID
* @param string $opt 操作(ok:表示确定,cancel:表示取消)
* @return array
*/
public static function favoriteBrand($uid, $id, $opt = 'ok')
{
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'toggleBrandFav', array($uid, $id));
}
/**
* 商品收藏/取消收藏
*
* @param int $uid 用户ID
* @param int $skn 商品标识
* @param string $opt 操作(ok:表示确定,cancel:表示取消)
* @return array
*/
public static function favoriteProduct($uid, $skn, $opt = 'ok')
{
if ($opt === 'cancel') {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'addUidProductFav', array($uid, $skn));
} else {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'shops/service/v1/favorite/', 'delUidProductFav', array($uid, $skn));
}
}
/**
* 资讯点赞/取消赞
*
* @param int $uid 用户ID
* @param int $id 唯一的ID
* @param string $opt 操作(ok:表示确定,cancel:表示取消)
* @return array
*/
public static function praiseArticle($uid, $id, $opt = 'ok')
{
if ($opt === 'cancel') {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'cancelPraise', array($id, $uid));
} else {
return Yohobuy::yarClient(Yohobuy::SERVICE_URL . 'guang/service/v1/favorite/', 'setPraise', array($id, $uid));
}
}
}
... ...
<?php
/**
*
* @name Cache
* @package
* @copyright yoho.inc
* @version 1.0 (2015-10-10 11:23:47)
* @author fei.hong <fei.hong@yoho.cn>
*/
class Cache
{
}
... ...
... ... @@ -7,17 +7,18 @@ namespace Plugin;
*/
class Helpers
{
/**
* 根据尺寸获得图片url
* @param string $fileName 文件名
* @param integer $width 图片宽度
* @param integer $height 图片高度
* @param integer $mode 模式
* @return string 图片地址
*/
public static function getImageUrl($fileName, $width, $height, $mode = 1){
return str_replace('{width}', $width, str_replace('{height}', $height, str_replace('{mode}', $mode, $fileName)));
/**
* 根据尺寸获得图片url
* @param string $fileName 文件名
* @param integer $width 图片宽度
* @param integer $height 图片高度
* @param integer $mode 模式
* @return string 图片地址
*/
public static function getImageUrl($fileName, $width, $height, $mode = 1)
{
return strtr($fileName, array('{width}' => $width, '{height}' => $height, '{mode}' => $mode));
}
/**
... ... @@ -28,6 +29,9 @@ class Helpers
*/
public static function array_get($array, $keys)
{
return array_intersect_key($array, array_flip((array) $keys));
return array_intersect_key($array, array_flip((array) $keys));
}
}
\ No newline at end of file
}
... ...
... ... @@ -45,4 +45,9 @@ server
expires 1h;
}
location ~* \.(svg|eot|ttf|woff|otf)$ {
add_header Access-Control-Allow-Origin *;
expires 30d;
}
}
\ No newline at end of file
... ...