Authored by cailing

hotrank代码整理

@@ -67,9 +67,9 @@ class HotrankModel @@ -67,9 +67,9 @@ class HotrankModel
67 public static function getHotrankResource($data, $sid, $page) 67 public static function getHotrankResource($data, $sid, $page)
68 { 68 {
69 //焦点图 热门品牌 69 //焦点图 热门品牌
70 -// $focus = self::getFocusResource($data['channel'], $data['code']);  
71 -// $data['slide'] = $focus[0]['slide'];  
72 -// $data['hotBrands'] = $focus[1]['hotBrands']; 70 + $focus = self::getFocusResource($data['channel'], $data['code']);
  71 + $data['slide'] = $focus[0]['slide'];
  72 + $data['hotBrands'] = $focus[1]['hotBrands'];
73 //人气单品 一周热卖 73 //人气单品 一周热卖
74 $sort = ($sid == 1) ? '' : $sid; 74 $sort = ($sid == 1) ? '' : $sid;
75 $config = array( 75 $config = array(
@@ -203,6 +203,7 @@ class HotrankModel @@ -203,6 +203,7 @@ class HotrankModel
203 public static function getProductList($result, $page, $ajax = 0) 203 public static function getProductList($result, $page, $ajax = 0)
204 { 204 {
205 $product = array(); 205 $product = array();
  206 + $url = Helpers::url('/product/pro', '', 'item');
206 if (empty($result) || empty($result['data']) || empty($result['data']['product_list'])) { 207 if (empty($result) || empty($result['data']) || empty($result['data']['product_list'])) {
207 return $product; 208 return $product;
208 } 209 }
@@ -213,36 +214,35 @@ class HotrankModel @@ -213,36 +214,35 @@ class HotrankModel
213 if (empty($val['goods_list'])) { 214 if (empty($val['goods_list'])) {
214 continue; 215 continue;
215 } 216 }
216 - $defaultGoodsId = 0; 217 + //$defaultGoodsId = 0;
217 foreach ($val['goods_list'] as $v) { 218 foreach ($val['goods_list'] as $v) {
218 if ($v['is_default'] == 'Y') { 219 if ($v['is_default'] == 'Y') {
219 - $defaultGoodsId = $v['goods_id']; 220 + $defaultGoodsId = empty($v['goods_id']) ? $val['goods_list'][0]['goods_id'] : $v['goods_id'];
220 } 221 }
221 } 222 }
222 - if (empty($defaultGoodsId)) {  
223 - $defaultGoodsId = $val['goods_list'][0]['goods_id'];  
224 - }  
225 $product_id = empty($val['product_id']) ? '' : $val['product_id']; 223 $product_id = empty($val['product_id']) ? '' : $val['product_id'];
226 - $product['name'] = $val['product_name'];  
227 if ($key <= 9 && $page == 1 && $ajax == 0) { 224 if ($key <= 9 && $page == 1 && $ajax == 0) {
228 //人气单品 225 //人气单品
229 $product['rank'] = $key + 1; 226 $product['rank'] = $key + 1;
230 - $product['href'] = 'http://item.yohobuy.com/product/pro_' . $product_id . '_' . $defaultGoodsId . '.html'; 227 + $product['title'] = $val['product_name'];
  228 + $product['href'] = $url . '_' . $product_id . '_' . $defaultGoodsId . '.html';
231 $product['price'] = (int) $val['market_price'] == (int) $val['sales_price'] ? '' : $val['market_price']; 229 $product['price'] = (int) $val['market_price'] == (int) $val['sales_price'] ? '' : $val['market_price'];
232 $product['sPrice'] = empty($val['sales_price']) ? '' : $val['sales_price']; 230 $product['sPrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];
233 if ($key <= 5) { 231 if ($key <= 5) {
  232 + //6张大图
234 $product['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 378, 504, 2); 233 $product['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 378, 504, 2);
235 $popular['list'][] = $product; 234 $popular['list'][] = $product;
236 } 235 }
237 else { 236 else {
  237 + //4张小图
238 $product['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2); 238 $product['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
239 $popular['list'][] = $product; 239 $popular['list'][] = $product;
240 } 240 }
241 } 241 }
242 else { 242 else {
243 //一周热卖 243 //一周热卖
244 -// $product['url'] = 'http://item.yohobuy.com/product/pro_' . $product_id . '_' . $defaultGoodsId . '.html';  
245 - $product['url'] = Helpers::url('/product/pro',array('product_id' => $product_id,'defaultGoodsId'=> $defaultGoodsId),'item'); 244 + $product['name'] = $val['product_name'];
  245 + $product['url'] = $url . '_' . $product_id . '_' . $defaultGoodsId . '.html';
246 $product['marketPrice'] = (int) $val['market_price'] == (int) $val['sales_price'] ? '' : $val['market_price']; 246 $product['marketPrice'] = (int) $val['market_price'] == (int) $val['sales_price'] ? '' : $val['market_price'];
247 $product['salePrice'] = empty($val['sales_price']) ? '' : $val['sales_price']; 247 $product['salePrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];
248 $product['rank'] = ''; 248 $product['rank'] = '';
1 -<?php 1 +<?php
  2 +
2 use Action\WebAction; 3 use Action\WebAction;
3 use LibModels\Web\Product\FavoriteData; 4 use LibModels\Web\Product\FavoriteData;
4 use Product\BrandsModel; 5 use Product\BrandsModel;
5 -  
6 use product\HotrankModel; 6 use product\HotrankModel;
7 7
8 class IndexController extends WebAction 8 class IndexController extends WebAction
9 { 9 {
  10 +
10 /** 11 /**
11 - * 品牌首页  
12 - */ 12 + * 品牌首页
  13 + */
13 public function brandAction() 14 public function brandAction()
14 { 15 {
15 //品牌域名,没有获取到品牌域名的跳转首页 16 //品牌域名,没有获取到品牌域名的跳转首页
16 $domain = $this->param('named'); 17 $domain = $this->param('named');
17 if (empty($domain)) { 18 if (empty($domain)) {
18 $this->go(SITE_MAIN); 19 $this->go(SITE_MAIN);
19 - } 20 + }
20 //根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页 21 //根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页
21 $type = 1; 22 $type = 1;
22 $result = BrandsModel::getBrandByDomain($domain, $type); 23 $result = BrandsModel::getBrandByDomain($domain, $type);
23 if (!$result) { 24 if (!$result) {
24 $this->go(SITE_MAIN); 25 $this->go(SITE_MAIN);
25 } 26 }
26 - 27 +
27 //获取uid 28 //获取uid
28 $uid = $this->getUid(); 29 $uid = $this->getUid();
29 - 30 +
30 //传品牌ID参数 31 //传品牌ID参数
31 $condition = array(); 32 $condition = array();
32 $condition['brand'] = isset($result['brandId']) ? $result['brandId'] : ''; 33 $condition['brand'] = isset($result['brandId']) ? $result['brandId'] : '';
33 - 34 +
34 //品牌系列参数 35 //品牌系列参数
35 $condition['folder_id'] = $this->get('folder_id'); 36 $condition['folder_id'] = $this->get('folder_id');
36 - 37 +
37 //$options参数数组 38 //$options参数数组
38 $options = array(); 39 $options = array();
39 $options['brandName'] = $domain; 40 $options['brandName'] = $domain;
@@ -46,10 +47,10 @@ class IndexController extends WebAction @@ -46,10 +47,10 @@ class IndexController extends WebAction
46 $options['reviewNum'] = 6; 47 $options['reviewNum'] = 6;
47 $options['controller'] = 'Index'; 48 $options['controller'] = 'Index';
48 $options['action'] = 'brand'; 49 $options['action'] = 'brand';
49 - 50 +
50 //调用模型获得数据 51 //调用模型获得数据
51 $data = BrandsModel::getBrandSearchData($condition, $options); 52 $data = BrandsModel::getBrandSearchData($condition, $options);
52 - 53 +
53 $data = array( 54 $data = array(
54 //初始化js 55 //初始化js
55 'searchListPage' => true, 56 'searchListPage' => true,
@@ -60,9 +61,9 @@ class IndexController extends WebAction @@ -60,9 +61,9 @@ class IndexController extends WebAction
60 $this->setDescription('潮流商品搜索,上衣,衬衫,TEE,卫衣,冲锋衣,风衣,羽绒服,裤子,休闲鞋,板鞋,配饰,复古眼镜'); 61 $this->setDescription('潮流商品搜索,上衣,衬衫,TEE,卫衣,冲锋衣,风衣,羽绒服,裤子,休闲鞋,板鞋,配饰,复古眼镜');
61 $this->setWebNavHeader(); 62 $this->setWebNavHeader();
62 //渲染模板 63 //渲染模板
63 - $this->_view->display('list',$data); 64 + $this->_view->display('list', $data);
64 } 65 }
65 - 66 +
66 //品牌介绍页 67 //品牌介绍页
67 public function aboutAction() 68 public function aboutAction()
68 { 69 {
@@ -70,21 +71,21 @@ class IndexController extends WebAction @@ -70,21 +71,21 @@ class IndexController extends WebAction
70 $domain = $this->param('named'); 71 $domain = $this->param('named');
71 if (empty($domain)) { 72 if (empty($domain)) {
72 $this->go(SITE_MAIN); 73 $this->go(SITE_MAIN);
73 - } 74 + }
74 $uid = $this->getUid(); 75 $uid = $this->getUid();
75 -  
76 - 76 +
  77 +
77 //根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页TODO 78 //根据品牌域名获取品牌id(同时判断品牌域名是否有效),无效跳转首页TODO
78 $type = 2; 79 $type = 2;
79 $result = BrandsModel::getBrandByDomain($domain, $type); 80 $result = BrandsModel::getBrandByDomain($domain, $type);
80 if (!$result) { 81 if (!$result) {
81 $this->go(SITE_MAIN); 82 $this->go(SITE_MAIN);
82 } 83 }
83 - 84 +
84 //品牌ID参数 85 //品牌ID参数
85 $condition = array(); 86 $condition = array();
86 $condition['brand'] = isset($result['brandId']) ? $result['brandId'] : ''; 87 $condition['brand'] = isset($result['brandId']) ? $result['brandId'] : '';
87 - 88 +
88 //$options参数数组 89 //$options参数数组
89 $options = array(); 90 $options = array();
90 $options['brandName'] = $domain; 91 $options['brandName'] = $domain;
@@ -96,18 +97,18 @@ class IndexController extends WebAction @@ -96,18 +97,18 @@ class IndexController extends WebAction
96 $options['action'] = 'brand'; 97 $options['action'] = 'brand';
97 //调用模型获得数据 98 //调用模型获得数据
98 $data = BrandsModel::getBrandIntro($condition, $options); 99 $data = BrandsModel::getBrandIntro($condition, $options);
99 - 100 +
100 $data = array( 101 $data = array(
101 //初始化js 102 //初始化js
102 'searchListPage' => true, 103 'searchListPage' => true,
103 'list' => $data 104 'list' => $data
104 ); 105 );
105 - 106 +
106 $this->setWebNavHeader(); 107 $this->setWebNavHeader();
107 //渲染模板 108 //渲染模板
108 - $this->_view->display('list',$data); 109 + $this->_view->display('list', $data);
109 } 110 }
110 - 111 +
111 //收藏品牌 112 //收藏品牌
112 public function favoriteBrandAction() 113 public function favoriteBrandAction()
113 { 114 {
@@ -117,15 +118,15 @@ class IndexController extends WebAction @@ -117,15 +118,15 @@ class IndexController extends WebAction
117 $result = array( 118 $result = array(
118 'code' => 400, 119 'code' => 400,
119 'message' => 'operation failed' 120 'message' => 'operation failed'
120 - ); 121 + );
121 $uid = $this->getUid(); 122 $uid = $this->getUid();
122 $brandId = $this->post('brandId'); 123 $brandId = $this->post('brandId');
123 - do{ 124 + do {
124 if (!$uid) { 125 if (!$uid) {
125 $result = array( 126 $result = array(
126 'code' => 403, 127 'code' => 403,
127 'message' => 'uid is null' 128 'message' => 'uid is null'
128 - ); 129 + );
129 break; 130 break;
130 } 131 }
131 if ($uid && $brandId) { 132 if ($uid && $brandId) {
@@ -133,46 +134,49 @@ class IndexController extends WebAction @@ -133,46 +134,49 @@ class IndexController extends WebAction
133 $result = FavoriteData::changeFavoriteBrand($uid, $brandId); 134 $result = FavoriteData::changeFavoriteBrand($uid, $brandId);
134 break; 135 break;
135 } 136 }
136 - }while(false);  
137 - 137 + }
  138 + while (false);
  139 +
138 $this->echoJson($result); 140 $this->echoJson($result);
139 } 141 }
140 -  
141 - /** 142 +
  143 + /**
142 * 热销排行 144 * 热销排行
143 */ 145 */
144 - public function hotrankAction() 146 + public function hotrankAction()
145 { 147 {
146 //获取频道 148 //获取频道
147 $channel = HotrankModel::getChannelResource(); 149 $channel = HotrankModel::getChannelResource();
148 $this->setWebNavHeader($channel['channel']); 150 $this->setWebNavHeader($channel['channel']);
149 - $page = $this->get('page',1);  
150 - $sort = $this->get('sid',1);  
151 - $data = array( 'hotrankPage' => true,  
152 - 'footerTop'=> true,  
153 - 'hotrank' => HotrankModel::getHotrankResource($channel, $sort, $page)  
154 - );  
155 - $this->_view->display('hotrank', $data); 151 + $page = $this->get('page', 1);
  152 + $sort = $this->get('sid', 1);
  153 + $data = array('hotrankPage' => true,
  154 + 'footerTop' => true,
  155 + 'hotrank' => HotrankModel::getHotrankResource($channel, $sort, $page)
  156 + );
  157 +
  158 + $this->_view->display('hotrank', $data);
156 } 159 }
157 - 160 +
158 /* 161 /*
159 * 一周热卖加载更多 162 * 一周热卖加载更多
160 */ 163 */
  164 +
161 public function getdataAction() 165 public function getdataAction()
162 { 166 {
163 - $page = $this->get('page',1); 167 + $page = $this->get('page', 1);
164 //加载到100个以后停止 168 //加载到100个以后停止
165 - if($page > 2)  
166 - {  
167 - echo json_encode(array('code'=>201,'data'=>'')); 169 + if ($page > 2) {
  170 + echo json_encode(array('code' => 201, 'data' => ''));
168 exit; 171 exit;
169 } 172 }
170 - $sid = $this->get('sid',1); 173 + $sid = $this->get('sid', 1);
171 //获取频道资源 174 //获取频道资源
172 $channel = HotrankModel::getChannelResource(); 175 $channel = HotrankModel::getChannelResource();
173 //获取一周热卖资源 176 //获取一周热卖资源
174 - $data = HotrankModel::getListData($channel, $sid, $page); 177 + $data = HotrankModel::getListData($channel, $sid, $page);
175 echo json_encode($data); 178 echo json_encode($data);
176 - exit; 179 + exit;
177 } 180 }
178 -}  
  181 +
  182 +}