Authored by Rock Zhang

新品到着,折扣专区修改

... ... @@ -18,7 +18,7 @@ class NewsaleData
const URI_NEWSALE_TOPPOS = 'operations/api/v5/resource/get';
/**
* 封装新品到着、折扣专区页面的顶部焦点图和下部商品的数据
* 封装新品到着页面的顶部焦点图和下部商品的数据
*
* @param string $contentCode 获取广告资源需要的位置码
* @param string $gender 1,3表示男, 2,3表示女,1,2,3表示全部
... ... @@ -31,7 +31,7 @@ class NewsaleData
* )
* @author gtskk <rocky.zhang@yoho.cn>
*/
public static function package($contentCode, $gender, $channel, $limit = 50, $page = 1)
public static function newPackage($contentCode, $gender, $channel, $limit = 50, $page = 1)
{
$urlList = array();
... ... @@ -65,6 +65,59 @@ class NewsaleData
return Yohobuy::getMulti($urlList);
}
/**
* 封装折扣专区页面的顶部焦点图和下部商品的数据
*
* @param string $contentCode 获取广告资源需要的位置码
* @param string $gender 1,3表示男, 2,3表示女,1,2,3表示全部
* @param integer $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array(
* "newsaleTop": "顶部的轮翻广告数据",
* "newsaleList": "产品列表数据"
* )
* @author gtskk <rocky.zhang@yoho.cn>
*/
public static function salePackage($contentCode, $gender, $channel, $limit = 50, $page = 1)
{
$urlList = array();
/* 顶部的轮翻广告数据 */
$param = Yohobuy::param();
$param['content_code'] = $contentCode;
$param['client_secret'] = Sign::getSign($param);
$urlList['newsaleTop'] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_NEWSALE_TOPPOS, $param);
/* 产品列表数据 */
$param = Yohobuy::param();
$param['method'] = 'app.search.sales';
$param['gender'] = $gender;
$param['page'] = $page;
$param['limit'] = $limit;
$param['yh_channel'] = $channel;
// 构建url地址列表
$param['p_d'] = '0.1,0.3';
$param['client_secret'] = Sign::getSign($param);
$urlList['1-3折'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['p_d'] = '0.4,0.6';
unset($param['client_secret']);
$param['client_secret'] = Sign::getSign($param);
$urlList['4-6折'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['p_d'] = '0.7,0.9';
unset($param['client_secret']);
$param['client_secret'] = Sign::getSign($param);
$urlList['7-9折'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
$param['p_d'] = '0.1,0.9';
unset($param['client_secret']);
$param['client_secret'] = Sign::getSign($param);
$urlList['ALL'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
return Yohobuy::getMulti($urlList);
}
/**
* 筛选新品到着、折扣专区商品
*
... ... @@ -159,11 +212,12 @@ class NewsaleData
* @param string price 价格
* @param string $channel 1表示男, 2表示女
* @param integer $p_d 折扣
* @param integer $dayLimit查询天数的限制区间,默认为1
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 筛选出来的折扣专区商品
*/
public static function selectSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $limit = 50, $page = 1)
public static function selectSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = 1, $limit = 50, $page = 1)
{
$selectItems = array(
'gender' => $gender,
... ... @@ -181,6 +235,7 @@ class NewsaleData
$param['yh_channel'] = $channel;
$param['p_d'] = $p_d;
$param['page'] = $page;
$param['dayLimit'] = $dayLimit;
$param['limit'] = $limit;
$param = array_merge($param, $queriedParams);
... ...
<?php
namespace Plugin\DataProcess;
use Plugin\Helpers;
/**
* 新品到着、折扣专区数据处理类
*/
class NewSaleProcess
{
/**
* 处理新品到着、折扣专区数据
*
* @param array $data 接口传回的数据
* @return array 处理之后的数据
*/
public static function newSaleData($focus, $products)
{
$result = array(
'headerBanner' => self::bannerData($focus),
'goodsContainer' => array()
);
foreach($products as $single)
{
// 处理Tabs
$noTab = true;
if(isset($single['tabs']) && $noTab)
{
$result['tabs'] = array();
foreach ($single['tabs'] as $key => $one)
{
$tabItem = array();
$tabItem['title'] = $one;
if($key === 1)
{
$tabItem['focus'] = true;
}
$result['tabs'][] = $tabItem;
}
$noTab = false;
}
// 处理商品
$productsLi = array('goods'=>array());
if(isset($single['product_list']))
{
foreach ($single['product_list'] as $value)
{
$productsLi['goods'][] = Helpers::formatProduct($value);
}
}
// 对于第一个productsLi添加show字段
if(count($result['goodsContainer']) === 0)
{
$productsLi['show'] = true;
}
$result['goodsContainer'][] = $productsLi;
}
return $result;
}
/**
* 处理页面顶部焦点图数据
*
* @param array $data 接口传回的焦点图数据
* @return array 处理之后的数据
*/
private static function bannerData($data)
{
$result = array('list'=>array());
foreach ($data as $single)
{
foreach ($single['data'] as $one)
{
$banner = array();
$banner['img'] = Helpers::getImageUrl($one['src'], 750, 364, 1);
$banner['url'] = $one['url'];
$result['list'][] = $banner;
}
}
return $result;
}
}
... ...
... ... @@ -36,33 +36,108 @@ class NewsaleModel
* @param int $channel boys表示男生频道, girls表示女生频道, kids表示潮童频道, lifestyle表示创意生活频道
* @return array
*/
public static function getNewsaleByChannel($channel)
public static function getNewByChannel($channel)
{
$result = array();
$newsale = array();
$new = array();
/* 根据频道调用接口 */
switch (intval($channel)) {
switch ($channel) {
case 'boys': // 男生
$newsale = NewsaleData::package(self::CODE_TOP_NEW_BOYS, '1,3', 1);
$new = NewsaleData::newPackage(self::CODE_TOP_NEW_BOYS, '1,3', 1);
break;
case 'girls': // 女生
$newsale = NewsaleData::package(self::CODE_TOP_NEW_GIRLS, '2,3', 2);
$new = NewsaleData::newPackage(self::CODE_TOP_NEW_GIRLS, '2,3', 2);
break;
case 'kids': // 潮童
$newsale = NewsaleData::package(self::CODE_TOP_NEW_KIDS, '1,2,3', 3);
$new = NewsaleData::newPackage(self::CODE_TOP_NEW_KIDS, '1,2,3', 3);
break;
case 'lifestyle': // 创意生活
$newsale = NewsaleData::package(self::CODE_TOP_NEW_LIFESTYLE, '1,2,3', 4);
$new = NewsaleData::newPackage(self::CODE_TOP_NEW_LIFESTYLE, '1,2,3', 4);
break;
}
/* 顶部的轮翻广告列表 */
$result['headerBanner'] = self::bannerData($newsale['newsaleTop']);
$result['headerBanner'] = self::bannerData($new['newsaleTop']);
/* 下部商品列表 */
unset($newsale['newsaleTop']);
foreach($newsale as $single)
unset($new['newsaleTop']);
foreach($new as $single)
{
// 处理Tabs
$noTab = true;
if(isset($single['tabs']) && $noTab)
{
$result['tabs'] = array();
foreach ($single['tabs'] as $key => $one)
{
$tabItem = array();
$tabItem['title'] = $one;
if($key === 1)
{
$tabItem['focus'] = true;
}
$result['tabs'][] = $tabItem;
}
$noTab = false;
}
// 处理商品
$productsLi = array('goods'=>array());
if(isset($single['product_list']))
{
foreach ($single['product_list'] as $value)
{
$productsLi['goods'][] = Helpers::formatProduct($value);
}
}
// 对于第一个productsLi添加show字段
if(!isset($result['goodsContainer']))
{
$productsLi['show'] = true;
}
$result['goodsContainer'][] = $productsLi;
}
return $result;
}
/**
* 根据频道获取折扣专区数据
*
* @param int $channel boys表示男生频道, girls表示女生频道, kids表示潮童频道, lifestyle表示创意生活频道
* @return array
*/
public static function getSaleByChannel($channel)
{
$result = array();
$sale = array();
/* 根据频道调用接口 */
switch ($channel) {
case 'boys': // 男生
$sale = NewsaleData::salePackage(self::CODE_TOP_SALE_BOYS, '1,3', 1);
break;
case 'girls': // 女生
$sale = NewsaleData::salePackage(self::CODE_TOP_SALE_GIRLS, '2,3', 2);
break;
case 'kids': // 潮童
$sale = NewsaleData::salePackage(self::CODE_TOP_SALE_KIDS, '1,2,3', 3);
break;
case 'lifestyle': // 创意生活
$sale = NewsaleData::salePackage(self::CODE_TOP_SALE_LIFESTYLE, '1,2,3', 4);
break;
}
/* 顶部的轮翻广告列表 */
$result['headerBanner'] = self::bannerData($sale['newsaleTop']);
/* 下部商品列表 */
unset($sale['newsaleTop']);
foreach($sale as $single)
{
// 处理Tabs
$noTab = true;
... ... @@ -137,4 +212,37 @@ class NewsaleModel
return $result;
}
/**
* 筛选出来的商品数据处理
*
* @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 $dayLimit查询天数的限制区间,默认为1
* @param integer $limit 查询返回的最大限制数, 默认为50
* @param integer $page 分页第几页, 默认第1页
* @return array 处理之后的筛选数据
*/
public static function selectData($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = 1, $limit = 50, $page = 1)
{
$data = NewsaleData::selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page);
$result = array();
if($data['code'] === 200)
{
foreach ($data['data']['product_list'] as $val) {
$result['goods'][] = Helpers::formatProduct($val);
}
}
return $result;
}
}
... ...
... ... @@ -25,7 +25,7 @@ class NewsaleController extends AbstractAction
$channel = $this->getCookie('_Channel', 'boys');
// 添加商品数据
$data += NewsaleModel::getNewsaleByChannel($channel);
$data += NewsaleModel::getNewByChannel($channel);
$this->_view->display('new', $data);
}
... ... @@ -50,9 +50,7 @@ class NewsaleController extends AbstractAction
$limit = $this->get('limit', 50);
$page = $this->get('page', 1);
$data = NewsaleData::selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page);
$result = NewSaleProcess::selectData($data);
$result = NewsaleModel::selectData($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit, $limit, $page);
$this->_view->display('product', $result);
}
... ... @@ -74,16 +72,10 @@ class NewsaleController extends AbstractAction
)
);
// 折扣专区顶部焦点图
$focusData = NewsaleData::getNewsaleFocus('e9c9be32d72e2906d404a72ee24cb523');
// 处理返回的数据
$focus = array();
if (isset($focusData['code']) && $focusData['code'] == 200) {
$focus = $focusData['data'];
}
$channel = $this->getCookie('_Channel', 'boys');
// 添加商品数据
$data += NewsaleModel::getSaleByChannel($channel);
// 折扣专区商品数据
$products = NewsaleData::getSaleProducts('1,3', 1);
// 更新tabs
$tabs = array();
foreach (array_keys($products) as $key => $value) {
... ... @@ -95,8 +87,6 @@ class NewsaleController extends AbstractAction
$tabs[] = $tabItem;
}
$data['tabs'] = $tabs;
// 添加商品数据
$data += NewSaleProcess::newSaleData($focus, $products);
/* echo '<pre>';
print_r($data);exit; */
... ...