Authored by Rock Zhang

新品上架以及折扣专区

1 <?php 1 <?php
2 -namespace LibModels\wap\Channel; 2 +namespace LibModels\wap\Product;
3 3
4 use Api\Yohobuy; 4 use Api\Yohobuy;
5 use Api\Sign; 5 use Api\Sign;
6 use Plugin\Helpers; 6 use Plugin\Helpers;
7 7
8 /** 8 /**
9 - * 新品到着接口操作类 9 + * 新品到着,折扣专区接口操作类
10 * 10 *
11 * @name NewsaleData 11 * @name NewsaleData
12 * @package Library/LibModels/Channel 12 * @package Library/LibModels/Channel
@@ -18,7 +18,7 @@ class NewsaleData @@ -18,7 +18,7 @@ class NewsaleData
18 { 18 {
19 19
20 /** 20 /**
21 - * 获取新品到着焦点图数据 21 + * 获取新品到着,折扣专区焦点图数据
22 * @param string $contentCode 内容位置码 22 * @param string $contentCode 内容位置码
23 * @return array 新品到着焦点图有关数据 23 * @return array 新品到着焦点图有关数据
24 */ 24 */
@@ -42,7 +42,7 @@ class NewsaleData @@ -42,7 +42,7 @@ class NewsaleData
42 * @param integer $page 分页第几页, 默认第1页 42 * @param integer $page 分页第几页, 默认第1页
43 * @return array 新品到着商品数据 43 * @return array 新品到着商品数据
44 */ 44 */
45 - public static function getNewsaleProducts($gender, $channel, $limit = 50, $page = 1) 45 + public static function getNewProducts($gender, $channel, $limit = 50, $page = 1)
46 { 46 {
47 $param = Yohobuy::param(); 47 $param = Yohobuy::param();
48 $param['method'] = 'app.search.newProduct'; 48 $param['method'] = 'app.search.newProduct';
@@ -83,7 +83,7 @@ class NewsaleData @@ -83,7 +83,7 @@ class NewsaleData
83 * @param integer $page 分页第几页, 默认第1页 83 * @param integer $page 分页第几页, 默认第1页
84 * @return array 筛选出来的新品到着商品 84 * @return array 筛选出来的新品到着商品
85 */ 85 */
86 - public static function selectNewsaleProducts(array $selectParams, $channel, $dayLimit = 1, $limit = 50, $page = 1) 86 + public static function selectNewProducts(array $selectParams, $channel, $dayLimit = 1, $limit = 50, $page = 1)
87 { 87 {
88 $selectItems = array( 88 $selectItems = array(
89 'gender', 89 'gender',
@@ -110,4 +110,82 @@ class NewsaleData @@ -110,4 +110,82 @@ class NewsaleData
110 return Yohobuy::get(Yohobuy::API_URL, $param); 110 return Yohobuy::get(Yohobuy::API_URL, $param);
111 } 111 }
112 112
  113 +
  114 + /**
  115 + * 获取折扣专区商品数据
  116 + *
  117 + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
  118 + * @param string $channel 1表示男, 2表示女
  119 + * @param integer $limit 查询返回的最大限制数, 默认为50
  120 + * @param integer $page 分页第几页, 默认第1页
  121 + * @return array 折扣专区商品数据
  122 + */
  123 + public static function getSaleProducts($gender, $channel, $limit = 50, $page = 1)
  124 + {
  125 + $param = Yohobuy::param();
  126 + $param['method'] = 'app.search.sales';
  127 + $param['gender'] = $gender;
  128 + $param['page'] = $page;
  129 + $param['limit'] = $limit;
  130 + $param['yh_channel'] = $channel;
  131 + $param['client_secret'] = Sign::getSign($param);
  132 +
  133 + // 构建url地址列表
  134 + $urlList = array();
  135 + $param['p_d'] = '0.1,0.3';
  136 + $urlList['new'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
  137 + $param['p_d'] = '0.4,0.6';
  138 + $urlList['week'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
  139 + $param['p_d'] = '0.7,0.9';
  140 + $urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
  141 + $param['p_d'] = '0.1,0.9';
  142 + $urlList['sale'] = Yohobuy::httpBuildQuery(Yohobuy::API_URL,$param);
  143 + // var_dump($urlList);exit;
  144 +
  145 + return Yohobuy::getMulti($urlList);
  146 + }
  147 +
  148 + /**
  149 + * 筛选折扣专区商品
  150 + *
  151 + * @param
  152 + * @param array $selectParams 筛选条件参数,可传递的条件参数有:
  153 + * string gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
  154 + * integer brand 品牌Id
  155 + * integer sort 品类Id
  156 + * integer color 颜色Id
  157 + * integer size 尺码Id
  158 + * string price 价格
  159 + * @param string $channel 1表示男, 2表示女
  160 + * @param integer $discount 折扣
  161 + * @param integer $limit 查询返回的最大限制数, 默认为50
  162 + * @param integer $page 分页第几页, 默认第1页
  163 + * @return array 筛选出来的折扣专区商品
  164 + */
  165 + public static function selectSaleProducts(array $selectParams, $channel, $discount, $limit = 50, $page = 1)
  166 + {
  167 + $selectItems = array(
  168 + 'gender',
  169 + 'brand',
  170 + 'sort',
  171 + 'color',
  172 + 'size',
  173 + 'price'
  174 + );
  175 +
  176 + $param = Yohobuy::param();
  177 + $param['method'] = 'app.search.sales';
  178 + $param['yh_channel'] = $channel;
  179 + $param['p_d'] = $discount;
  180 + $param['page'] = $page;
  181 + $param['limit'] = $limit;
  182 +
  183 + // 拉取筛选参数
  184 + $queriedParams = Helpers::array_get($selectParams, $selectItems);
  185 + $param = array_merge($param, $queriedParams);
  186 + $param['client_secret'] = Sign::getSign($param);
  187 +
  188 + return Yohobuy::get(Yohobuy::API_URL, $param);
  189 + }
  190 +
113 } 191 }
1 <?php 1 <?php
2 2
3 use Action\AbstractAction; 3 use Action\AbstractAction;
4 -use LibModels\wap\Channel\NewsaleData as Newsale; 4 +use LibModels\wap\Product\NewsaleData as Newsale;
5 use Plugin\Helpers; 5 use Plugin\Helpers;
6 /** 6 /**
7 * 新品到着 7 * 新品到着
@@ -15,28 +15,84 @@ class NewsaleController extends AbstractAction @@ -15,28 +15,84 @@ class NewsaleController extends AbstractAction
15 // 新品到着顶部焦点图 15 // 新品到着顶部焦点图
16 $focusData = Newsale::getNewsaleFocus('a7989369aa86681c678bc40f171b8f1d'); 16 $focusData = Newsale::getNewsaleFocus('a7989369aa86681c678bc40f171b8f1d');
17 // 新品到着商品数据 17 // 新品到着商品数据
18 - $productsData = Newsale::getNewsaleProducts('1,3', 1, 60);  
19 - var_dump($productsData); 18 + // $productsData = Newsale::getNewProducts('1,3', 1, 60);
20 19
21 // 处理返回的数据 20 // 处理返回的数据
22 $focus = array(); 21 $focus = array();
23 $products = array(); 22 $products = array();
24 - if($focusData['code'] === 200) 23 + if($focusData['code'] == 200)
25 { 24 {
26 - foreach ($focusData['data']['data'] as $single) 25 + foreach ($focusData['data'] as $single)
27 { 26 {
28 - $single['src'] = Helpers::getImageUrl($val['src'], 375, 667, 1);  
29 - $focus[] = $single; 27 + foreach ($single['data'] as $val) {
  28 + $val['src'] = Helpers::getImageUrl($val['src'], 375, 667, 1);
  29 + $focus[] = $val;
30 } 30 }
31 } 31 }
32 - if($productsData['code'] === 200) 32 + }
  33 + /*if($productsData['code'] == 200)
33 { 34 {
34 $products = $productsData['data']; 35 $products = $productsData['data'];
35 foreach ($products['product_list'] as &$val) { 36 foreach ($products['product_list'] as &$val) {
36 $val['default_images'] = Helpers::getImageUrl($val['default_images'], 290, 386); 37 $val['default_images'] = Helpers::getImageUrl($val['default_images'], 290, 386);
37 } 38 }
  39 + }*/
  40 + var_dump($focus);
  41 +
  42 + $this->_view->display('new', compact('focus', 'products'));
38 } 43 }
39 - var_dump($products);exit; 44 +
  45 +
  46 + public function selectNewAction()
  47 + {
  48 + if($this->isAjax())
  49 + {
  50 + $data = '';
  51 + $gender = $this->get('gender', '1,3');
  52 + $brand = $this->get('brand', null);
  53 + $sort = $this->get('sort', null);
  54 + $color = $this->get('color', null);
  55 + $size = $this->get('size', null);
  56 + $price = $this->get('price', null);
  57 + $p_d = $this->get('p_d', null);
  58 + $channel = $this->get('channel', '1');
  59 +
  60 + $this->echoJson($data);
  61 + }
  62 + }
  63 +
  64 +
  65 + public function discountAction()
  66 + {
  67 + $this->_view->assign('title', '折扣专区');
  68 +
  69 + // 折扣专区顶部焦点图
  70 + $focusData = Newsale::getNewsaleFocus('e9c9be32d72e2906d404a72ee24cb523');
  71 + // 折扣专区商品数据
  72 + // $productsData = Newsale::getNewProducts('1,3', 1, 60);
  73 +
  74 + // 处理返回的数据
  75 + $focus = array();
  76 + $products = array();
  77 + if($focusData['code'] == 200)
  78 + {
  79 + foreach ($focusData['data'] as $single)
  80 + {
  81 + foreach ($single['data'] as $val) {
  82 + $val['src'] = Helpers::getImageUrl($val['src'], 375, 667, 1);
  83 + $focus[] = $val;
  84 + }
  85 + }
  86 + }
  87 + /*if($productsData['code'] === 200)
  88 + {
  89 + $products = $productsData['data'];
  90 + foreach ($products['product_list'] as &$val) {
  91 + $val['default_images'] = Helpers::getImageUrl($val['default_images'], 290, 386);
  92 + }
  93 + }*/
  94 +
  95 + var_dump($focus);
40 96
41 $this->_view->display('new', compact('focus', 'products')); 97 $this->_view->display('new', compact('focus', 'products'));
42 } 98 }