Authored by Rock Zhang

添加热卖排行榜后台逻辑

@@ -45,9 +45,6 @@ class NewsaleData @@ -45,9 +45,6 @@ class NewsaleData
45 */ 45 */
46 public static function getNewProducts($gender, $channel, $order = 's_t_desc', $limit = 60, $page = 1) 46 public static function getNewProducts($gender, $channel, $order = 's_t_desc', $limit = 60, $page = 1)
47 { 47 {
48 - // 构建url地址列表  
49 - $urlList = array();  
50 -  
51 $param = Yohobuy::param(); 48 $param = Yohobuy::param();
52 $param['method'] = 'app.search.newProduct'; 49 $param['method'] = 'app.search.newProduct';
53 $param['gender'] = $gender; 50 $param['gender'] = $gender;
@@ -82,7 +79,6 @@ class NewsaleData @@ -82,7 +79,6 @@ class NewsaleData
82 */ 79 */
83 public static function selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = null, $limit = 60, $page = 1, $order = 's_t_desc') 80 public static function selectNewSaleProducts($gender, $brand, $sort, $color, $size, $price, $p_d, $channel, $dayLimit = null, $limit = 60, $page = 1, $order = 's_t_desc')
84 { 81 {
85 -  
86 $selectItems = array( 82 $selectItems = array(
87 'gender' => $gender, 83 'gender' => $gender,
88 'brand' => $brand, 84 'brand' => $brand,
@@ -182,4 +178,30 @@ class NewsaleData @@ -182,4 +178,30 @@ class NewsaleData
182 return Yohobuy::get(Yohobuy::API_URL, $param); 178 return Yohobuy::get(Yohobuy::API_URL, $param);
183 } 179 }
184 180
  181 +
  182 + /**
  183 + * 获取热销排行榜商品数据
  184 + *
  185 + * @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示全部
  186 + * @param string|null $sort 品类ID查询参数
  187 + * @param integer|null $tab_id Tab的ID
  188 + * @param integer $limit 查询返回的最大限制数, 默认为50
  189 + * @param integer $page 分页第几页, 默认第1页
  190 + * @return array 新品到着商品数据
  191 + */
  192 + public static function getTopProducts($gender, $sort = null, $tab_id = null, $limit = 50, $page = 1)
  193 + {
  194 + $param = Yohobuy::param();
  195 + $param['method'] = 'app.search.top';
  196 + $param['gender'] = $gender;
  197 + !empty($sort) && $param['sort'] = $sort;
  198 + !empty($tab_id) && $param['tab_id'] = $tab_id;
  199 + $param['page'] = $page;
  200 + $param['limit'] = $limit;
  201 +
  202 + $param['client_secret'] = Sign::getSign($param);
  203 +
  204 + return Yohobuy::get(Yohobuy::API_URL, $param);
  205 + }
  206 +
185 } 207 }
@@ -226,6 +226,24 @@ class NewsaleModel @@ -226,6 +226,24 @@ class NewsaleModel
226 return $result; 226 return $result;
227 } 227 }
228 228
  229 + /**
  230 + * 筛选出来的热销排行榜商品数据处理
  231 + *
  232 + * @param array $data 筛选出来的原数据
  233 + * @return array 处理之后的数据
  234 + */
  235 + public static function selectTopData($data)
  236 + {
  237 + $result = array();
  238 +
  239 + if (isset($data['code']) && $data['code'] === 200 && isset($data['data']['product_list'])) {
  240 + $result = NewSaleProcess::newSaleData($data['data']);
  241 + unset($result['filter']);
  242 + }
  243 +
  244 + return $result;
  245 + }
  246 +
229 247
230 /** 248 /**
231 * 获取筛选数据 249 * 获取筛选数据
@@ -79,23 +79,48 @@ class NewsaleController extends AbstractAction @@ -79,23 +79,48 @@ class NewsaleController extends AbstractAction
79 $this->setTitle('热销排行榜'); 79 $this->setTitle('热销排行榜');
80 $this->setNavHeader('热销排行榜'); 80 $this->setNavHeader('热销排行榜');
81 81
  82 + $channel = Helpers::getChannelByCookie();
82 // 设置一些默认参数 83 // 设置一些默认参数
83 $data = array( 84 $data = array(
84 'discountPage' => true, 85 'discountPage' => true,
  86 + 'headerBanner' => \Product\NewsaleModel::getNewFocus($channel),
85 'showDownloadApp' => true, 87 'showDownloadApp' => true,
86 'pageFooter' => true, 88 'pageFooter' => true,
87 - 'brand' => '0',  
88 - 'sort' => '0',  
89 - 'gender' => Helpers::getGenderByCookie(),  
90 - 'price' => '0',  
91 - 'size' => '0',  
92 - 'discount' => '0.1,0.9',  
93 'cartUrl' => Helpers::url('/cart/index/index', null), 89 'cartUrl' => Helpers::url('/cart/index/index', null),
94 ); 90 );
95 91
96 $this->_view->display('hotrank', $data); 92 $this->_view->display('hotrank', $data);
97 } 93 }
98 94
  95 + /**
  96 + * Ajax方式获取热销排行榜商品
  97 + *
  98 + * @return array 根据指定条件筛选之后的商品
  99 + */
  100 + public function selectHotrankAction()
  101 + {
  102 + $result = array();
  103 +
  104 + if ($this->isAjax()) {
  105 + $sort = $this->get('sort', null);
  106 + $tab_id = $this->get('tab_id', null);
  107 + $limit = $this->get('limit', 50);
  108 + $page = $this->get('page', 1);
  109 +
  110 + // 获取性别
  111 + $gender = Helpers::getGenderByCookie();
  112 +
  113 + $data = NewsaleData::getTopProducts($gender, $sort, $tab_id, $limit, $page);
  114 + $result = \Product\NewsaleModel::selectTopData($data);
  115 + }
  116 +
  117 + if (empty($result)) {
  118 + echo ' ';
  119 + } else {
  120 + $this->_view->display('product', $result);
  121 + }
  122 + }
  123 +
99 /** 124 /**
100 * Ajax方式筛选新品到着、折扣专区商品 125 * Ajax方式筛选新品到着、折扣专区商品
101 * 126 *