Authored by Rock Zhang

首页有关内容添添加

<?php
namespace LibModels\wap\Home;
use Api\Yohobuy;
use Api\Sign;
use Plugin\Helpers;
/**
* 首页数据接口操作类
*
* @name IndexData
* @package Library/LibModels/wap/Home
* @copyright yoho.inc
* @version 1.0 (2015-10-9)
* @author gtskk <rocky.zhang@yoho.cn>
*/
class IndexData
{
/**
* 获取启动轮播图
*
* @return array 轮播图有关数据
*/
public static function getBannerStart()
{
// 构建必传参数
$param = Yohobuy::param();
$param['content_code'] = '7ba9118028f9b22090b57341487567eb';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/resource/get', $param);
}
/**
* 获取启动封面图
*
* @return array 封面图有关数据
*/
public static function getCoverStart()
{
// 构建必传参数
$param = Yohobuy::param();
$param['method'] = 'app.cover.getCoverStart';
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 获取启动页频道数据
*
* @return array 启动页频道有关数据
*/
public static function getHomeChannels()
{
// 构建必传参数
$param = Yohobuy::param();
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/category/getCategory', $param);
}
/**
* 获取用户个人信息
*
* @param integer $uid 用户ID
* @return array 用户个人信息数据
*/
public static function getUserProfile($uid)
{
// 构建必传参数
$param = Yohobuy::param();
$param['method'] = 'app.passport.profile';
$param['uid'] = $uid;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
}
/**
* 获取首页频道数据(除了可能喜欢的各楼层有关数据)
* @param integer $uid 用户ID
* @param string $gender 用户性别, "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* @param string $contentCode 内容位置码
* @param integer $limit 查询返回的最大限字数,默认为20
* @param integer $page 分页第几页,默认为第1页
* @return array 首页频道数据
*/
public static function getUserChannelData($uid, $gender, $contentCode, $limit = 20, $page = 1)
{
$param = Yohobuy::param();
$param['uid'] = $uid;
$param['gender'] = $gender;
$param['content_code'] = $contentCode;
$param['page'] = $page;
$param['limit'] = $limit;
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL.'operations/api/v5/resource/home', $param);
}
}
... ...
... ... @@ -9,7 +9,7 @@ use Plugin\Helpers;
* 新品到着,折扣专区接口操作类
*
* @name NewsaleData
* @package Library/LibModels/Channel
* @package Library/LibModels/wap/Product
* @copyright yoho.inc
* @version 1.0 (2015-10-8)
* @author gtskk <rocky.zhang@yoho.cn>
... ... @@ -50,15 +50,17 @@ class NewsaleData
$param['page'] = $page;
$param['limit'] = $limit;
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::getSign($param);
// 构建url地址列表
$urlList = array();
$param['dayLimit'] = 1;
$param['client_secret'] = Sign::getSign($param);
$urlList['new'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['dayLimit'] = 2;
$param['client_secret'] = Sign::getSign($param);
$urlList['week'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['dayLimit'] = 3;
$param['client_secret'] = Sign::getSign($param);
$urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
//var_dump($urlList);exit;
... ... @@ -66,34 +68,34 @@ class NewsaleData
}
/**
* 筛选新品到着商品
* 筛选新品到着、折扣专区商品
*
* @param
* @param array $selectParams 筛选条件参数,可传递的条件参数有:
* string gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* integer brand 品牌Id
* integer sort 品类Id
* integer color 颜色Id
* integer size 尺码Id
* string price 价格
* string p_d 折扣
* @param string $channel 1表示男, 2表示女
* @param integer $dayLimit 限制读取多少天,默认为1天
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 筛选出来的新品到着商品
* @param string gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* @param integer $brand 品牌Id
* @param integer $sort 品类Id
* @param integer $color 颜色Id
* @param integer $size 尺码Id
* @param string $price 价格
* @param string $p_d 折扣
* @param string $channel 1表示男, 2表示女
* @param integer $dayLimit 限制读取多少天,默认为1天
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 根据指定条件筛选出来的商品
*/
public static function selectNewProducts(array $selectParams, $channel, $dayLimit = 1, $limit = 50, $page = 1)
public static function selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = null, $limit = 50, $page = 1)
{
$selectItems = array(
'gender',
'brand',
'sort',
'color',
'size',
'price',
'p_d'
'gender' => $gender,
'brand' => $brand,
'sort' => $sort,
'color' => $color,
'size' => $size,
'price' => $price,
'p_d' => $p_d
);
// 拉取筛选参数
$queriedParams = array_filter($selectItems, function($v) {return $v !== null;});
$param = Yohobuy::param();
$param['method'] = 'app.search.newProduct';
... ... @@ -101,10 +103,8 @@ class NewsaleData
$param['page'] = $page;
$param['limit'] = $limit;
$param['yh_channel'] = $channel;
// 拉取筛选参数
$queriedParams = Helpers::array_get($selectParams, $selectItems);
$param = array_merge($param, $queriedParams);
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
... ... @@ -128,19 +128,21 @@ class NewsaleData
$param['page'] = $page;
$param['limit'] = $limit;
$param['yh_channel'] = $channel;
$param['client_secret'] = Sign::getSign($param);
// 构建url地址列表
$urlList = array();
$param['p_d'] = '0.1,0.3';
$urlList['new'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['client_secret'] = Sign::getSign($param);
$urlList['oneThree'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['p_d'] = '0.4,0.6';
$urlList['week'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['client_secret'] = Sign::getSign($param);
$urlList['fourSix'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['p_d'] = '0.7,0.9';
$urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['client_secret'] = Sign::getSign($param);
$urlList['SevenNine'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['p_d'] = '0.1,0.9';
$urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
// var_dump($urlList);exit;
$param['client_secret'] = Sign::getSign($param);
$urlList['OneNine'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
return Yohobuy::getMulti($urlList);
}
... ... @@ -148,41 +150,39 @@ class NewsaleData
/**
* 筛选折扣专区商品
*
* @param
* @param array $selectParams 筛选条件参数,可传递的条件参数有:
* string gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* integer brand 品牌Id
* integer sort 品类Id
* integer color 颜色Id
* integer size 尺码Id
* string price 价格
* @param string $channel 1表示男, 2表示女
* @param integer $discount 折扣
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 筛选出来的折扣专区商品
* @param string gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
* @param integer brand 品牌Id
* @param integer sort 品类Id
* @param integer color 颜色Id
* @param integer size 尺码Id
* @param string price 价格
* @param string $channel 1表示男, 2表示女
* @param integer $p_d 折扣
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 筛选出来的折扣专区商品
*/
public static function selectSaleProducts(array $selectParams, $channel, $discount, $limit = 50, $page = 1)
public static function selectSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $limit = 50, $page = 1)
{
$selectItems = array(
'gender',
'brand',
'sort',
'color',
'size',
'price'
'gender' => $gender,
'brand' => $brand,
'sort' => $sort,
'color' => $color,
'size' => $size,
'price' => $price
);
// 拉取筛选参数
$queriedParams = array_filter($selectItems, function($v) {return $v !== null;});
$param = Yohobuy::param();
$param['method'] = 'app.search.sales';
$param['yh_channel'] = $channel;
$param['p_d'] = $discount;
$param['p_d'] = $p_d;
$param['page'] = $page;
$param['limit'] = $limit;
// 拉取筛选参数
$queriedParams = Helpers::array_get($selectParams, $selectItems);
$param = array_merge($param, $queriedParams);
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::API_URL, $param);
... ...
... ... @@ -26,8 +26,8 @@ class Helpers
* @param array|string $keys 指定键值,数组或者字符串
* @return array 获取的数据
*/
public static function array_get($array, $keys)
/*public static function array_get($array, $keys)
{
return array_intersect_key($array, array_flip((array) $keys));
}
}*/
}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Home\IndexData as Index;
/**
* 男生首页
*/
class BoysController extends AbstractAction
{
public function indexAction()
{
echo 'boys';
// 频道数据
$channelData = Index::getUserChannelData(0, '1,3', '201504091403001');
echo '<pre>';
print_r($channelData);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('boys', compact('channelData'));
}
}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Home\IndexData as Index;
/**
* 女生首页
*/
class GirlsController extends AbstractAction
{
public function indexAction()
{
echo 'boys';
// 频道数据
$channelData = Index::getUserChannelData(0, '2,3', '201504091403002');
echo '<pre>';
print_r($channelData);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('girls', compact('channelData'));
}
}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Guang\PlusstarData;
use LibModels\Wap\Home\IndexData as Index;
/**
* 频道选择
*/
class IndexController extends AbstractAction
{
/**
* 启动首页
*/
public function indexAction()
{
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('index', array('test' => 'hello world'));
$test = PlusstarData::brandInfo();
var_dump($test);
// 启动滚动图
$startBannerData = Index::getBannerStart();
$startBanner = array();
if($startBannerData['code'] == 200)
{
foreach ($startBannerData['data'] as $single)
{
$startBanner = $single['data'];
}
}
// 启动频道数据
$homeChannels = Index::getHomeChannels();
// 用户个人信息
$userProfile = Index::getUserProfile(0);
/*echo '<pre>';
var_dump($homeChannels);exit;*/
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('index', compact('startBanner', 'homeChannels', 'userProfile'));
}
}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Home\IndexData as Index;
/**
* 潮童首页
*/
class KidsController extends AbstractAction
{
public function indexAction()
{
echo 'kids';
// 频道数据
$channelData = Index::getUserChannelData(0, '', 'e9875682c1599a886bfbdb965b740022');
echo '<pre>';
print_r($channelData);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('kids', compact('channelData'));
}
}
\ No newline at end of file
... ...
<?php
use Action\AbstractAction;
use LibModels\Wap\Home\IndexData as Index;
/**
* 创意生活首页
*/
class LifestyleController extends AbstractAction
{
public function indexAction()
{
echo 'life style';
// 频道数据
$channelData = Index::getUserChannelData(0, '1,3', '9aa25f5133f011ec96c2045eb15ae425');
echo '<pre>';
print_r($channelData);
$this->_view->assign('title', 'YOHO!有货');
$this->_view->display('lifestyle', compact('channelData'));
}
}
\ No newline at end of file
... ...
... ... @@ -14,12 +14,8 @@ class NewsaleController extends AbstractAction
// 新品到着顶部焦点图
$focusData = Newsale::getNewsaleFocus('a7989369aa86681c678bc40f171b8f1d');
// 新品到着商品数据
// $productsData = Newsale::getNewProducts('1,3', 1, 60);
// 处理返回的数据
$focus = array();
$products = array();
if($focusData['code'] == 200)
{
foreach ($focusData['data'] as $single)
... ... @@ -30,24 +26,24 @@ class NewsaleController extends AbstractAction
}
}
}
/*if($productsData['code'] == 200)
{
$products = $productsData['data'];
foreach ($products['product_list'] as &$val) {
$val['default_images'] = Helpers::getImageUrl($val['default_images'], 290, 386);
}
}*/
// 批量获取新品到着商品数据
$products = Newsale::getNewProducts('1,3', 1, 60);
var_dump($focus);
$this->_view->display('new', compact('focus', 'products'));
}
/**
* Ajax方式筛选新品到着商品
*
* @return array 根据指定条件筛选之后的商品
*/
public function selectNewAction()
{
if($this->isAjax())
if($this->isAjax())
{
$data = '';
$gender = $this->get('gender', '1,3');
$brand = $this->get('brand', null);
$sort = $this->get('sort', null);
... ... @@ -56,6 +52,11 @@ class NewsaleController extends AbstractAction
$price = $this->get('price', null);
$p_d = $this->get('p_d', null);
$channel = $this->get('channel', '1');
$dayLimit = $this->get('dayLimit', '1');
$limit = $this->get('limit', 50);
$page = $this->get('page', 1);
$data = Newsale::selectNewProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page);
$this->echoJson($data);
}
... ... @@ -68,12 +69,8 @@ class NewsaleController extends AbstractAction
// 折扣专区顶部焦点图
$focusData = Newsale::getNewsaleFocus('e9c9be32d72e2906d404a72ee24cb523');
// 折扣专区商品数据
// $productsData = Newsale::getNewProducts('1,3', 1, 60);
// 处理返回的数据
$focus = array();
$products = array();
if($focusData['code'] == 200)
{
foreach ($focusData['data'] as $single)
... ... @@ -84,16 +81,38 @@ class NewsaleController extends AbstractAction
}
}
}
/*if($productsData['code'] === 200)
{
$products = $productsData['data'];
foreach ($products['product_list'] as &$val) {
$val['default_images'] = Helpers::getImageUrl($val['default_images'], 290, 386);
}
}*/
var_dump($focus);
// 折扣专区商品数据
$products = Newsale::getNewProducts('1,3', 1, 60);
var_dump($products);
$this->_view->display('new', compact('focus', 'products'));
}
/**
* Ajax方式筛选折扣专区商品
*
* @return array 根据指定条件筛选之后的商品
*/
public function selectSaleAction()
{
if($this->isAjax())
{
$gender = $this->get('gender', '1,3');
$brand = $this->get('brand', null);
$sort = $this->get('sort', null);
$color = $this->get('color', null);
$size = $this->get('size', null);
$price = $this->get('price', null);
$p_d = $this->get('p_d', null);
$channel = $this->get('channel', '1');
$dayLimit = $this->get('dayLimit', '1');
$limit = $this->get('limit', 50);
$page = $this->get('page', 1);
$data = Newsale::selectSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page);
$this->echoJson($data);
}
}
}
\ No newline at end of file
... ...