Authored by cailing

代码评审修改

1 <?php 1 <?php
  2 +
2 namespace LibModels\Web\Product; 3 namespace LibModels\Web\Product;
3 4
4 use Api\Yohobuy; 5 use Api\Yohobuy;
5 6
6 -  
7 /** 7 /**
8 * 热销排行 8 * 热销排行
9 */ 9 */
10 class HotrankData extends \LibModels\Wap\Product\SearchData 10 class HotrankData extends \LibModels\Wap\Product\SearchData
11 -{ 11 +{
  12 +
12 const URI_HOTRANK_TAG = 'operations/service/v1/hotranktag'; 13 const URI_HOTRANK_TAG = 'operations/service/v1/hotranktag';
13 - 14 +
14 /** 15 /**
15 * 获取标签 16 * 获取标签
16 * $client_type 客户端类型 17 * $client_type 客户端类型
17 * $channel 频道类型 18 * $channel 频道类型
18 */ 19 */
19 - public static function getHotranktag($client_type = 'web',$channel = 0,$is_concurrent = true) 20 + public static function getHotrankTag($client_type = 'web', $channel = 0, $is_concurrent = true)
20 { 21 {
21 - $params = array('client_type'=>$client_type,'channel'=>$channel,'is_concurrent' => $is_concurrent);  
22 - return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_HOTRANK_TAG, 'getTag',$params); 22 + $params = array(
  23 + 'client_type' => $client_type,
  24 + 'channel' => $channel,
  25 + 'is_concurrent' => $is_concurrent);
  26 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_HOTRANK_TAG, 'getTag', $params);
23 } 27 }
24 28
25 /** 29 /**
26 * 通过ID获取标签信息 30 * 通过ID获取标签信息
27 * $id 标签ID 31 * $id 标签ID
28 */ 32 */
29 - public static function getTagById($id,$is_concurrent = true) 33 + public static function getTagById($id, $is_concurrent = true)
30 { 34 {
31 $params['id'] = $id; 35 $params['id'] = $id;
32 - return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_HOTRANK_TAG, 'getOneTag',$params); 36 + return Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_HOTRANK_TAG, 'getOneTag', $params);
33 } 37 }
34 -}  
  38 +
  39 +}
1 <?php 1 <?php
  2 +
2 namespace product; 3 namespace product;
3 4
4 use WebPlugin\Images; 5 use WebPlugin\Images;
5 use Api\Yohobuy; 6 use Api\Yohobuy;
  7 +use Plugin\Helpers;
6 use LibModels\Web\Product\HotrankData; 8 use LibModels\Web\Product\HotrankData;
7 use LibModels\Web\Product\SearchData; 9 use LibModels\Web\Product\SearchData;
8 use LibModels\Web\Home\IndexData; 10 use LibModels\Web\Home\IndexData;
@@ -12,33 +14,49 @@ use WebPlugin\DataProcess\Channel as ChannelProcess; @@ -12,33 +14,49 @@ use WebPlugin\DataProcess\Channel as ChannelProcess;
12 * Hotrank页数据模型 14 * Hotrank页数据模型
13 */ 15 */
14 16
15 -class HotrankModel {  
16 - 17 +class HotrankModel
  18 +{
  19 +
17 /** 20 /**
18 * 获取频道资源 21 * 获取频道资源
19 * 22 *
20 * @return array 23 * @return array
21 */ 24 */
22 - static public function getChannelResource() 25 + public static function getChannelResource()
23 { 26 {
24 $channel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys'; 27 $channel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
25 - switch ($channel)  
26 - { 28 + switch ($channel) {
27 case 'boys' : 29 case 'boys' :
28 - $resource = array('channel' => 'boys', 'gender' => '1,3','road' => 1,'code' => '80d772d8dff25300a2a2e4c97165330c'); 30 + $resource = array(
  31 + 'channel' => 'boys',
  32 + 'gender' => '1,3',
  33 + 'road' => 1,
  34 + 'code' => '80d772d8dff25300a2a2e4c97165330c');
29 return $resource; 35 return $resource;
30 case 'girls' : 36 case 'girls' :
31 - $resource = array('channel' => 'girls','gender' => '2,3','road' => 2,'code' => '8df64e505e94edb9881fd1e7efb702e9'); 37 + $resource = array(
  38 + 'channel' => 'girls',
  39 + 'gender' => '2,3',
  40 + 'road' => 2,
  41 + 'code' => '8df64e505e94edb9881fd1e7efb702e9');
32 return $resource; 42 return $resource;
33 case 'lifestyle' : 43 case 'lifestyle' :
34 - $resource = array('channel' => 'lifestyle','gender' => '','road' => 4,'code' => 'd131aba83a84a6977eee3a7403a713de'); 44 + $resource = array(
  45 + 'channel' => 'lifestyle',
  46 + 'gender' => '',
  47 + 'road' => 4,
  48 + 'code' => 'd131aba83a84a6977eee3a7403a713de');
35 return $resource; 49 return $resource;
36 case 'kids' : 50 case 'kids' :
37 - $resource = array('channel' => 'kids','gender' => '','road' => 3,'code' => 'bd6a06a08f8ca9b0db762f78e0bc5b68'); 51 + $resource = array(
  52 + 'channel' => 'kids',
  53 + 'gender' => '',
  54 + 'road' => 3,
  55 + 'code' => 'bd6a06a08f8ca9b0db762f78e0bc5b68');
38 return $resource; 56 return $resource;
39 } 57 }
40 } 58 }
41 - 59 +
42 /** 60 /**
43 * 获取热销排行所有资源 61 * 获取热销排行所有资源
44 * @param $data 频道信息 62 * @param $data 频道信息
@@ -46,26 +64,27 @@ class HotrankModel { @@ -46,26 +64,27 @@ class HotrankModel {
46 * @param $page 页码 64 * @param $page 页码
47 * @return array 65 * @return array
48 */ 66 */
49 - static public function HotrankResource($data,$sid,$page) 67 + public static function getHotrankResource($data, $sid, $page)
50 { 68 {
51 //焦点图 热门品牌 69 //焦点图 热门品牌
52 - $focus = self::getFocusResource($data['channel'], $data['code']);  
53 - $data['hotrank']['slide'] = $focus[0]['slide'];  
54 - $data['hotrank']['hotBrands'] = $focus[1]['hotBrands'];  
55 - 70 +// $focus = self::getFocusResource($data['channel'], $data['code']);
  71 +// $data['slide'] = $focus[0]['slide'];
  72 +// $data['hotBrands'] = $focus[1]['hotBrands'];
56 //人气单品 一周热卖 73 //人气单品 一周热卖
57 - $config = array('sort' =>$sid,'gender' => $data['gender'],'road' => $data['road']);  
58 - $publiclist = self::getSearchData($config,$page,0);  
59 - $data['hotrank']['popular'] = $publiclist['popular'];  
60 - $data['hotrank']['hotWeek'] = $publiclist['hotWeek'];  
61 - 74 + $sort = ($sid == 1) ? '' : $sid;
  75 + $config = array(
  76 + 'sort' => $sort,
  77 + 'gender' => $data['gender'],
  78 + 'road' => $data['road']);
  79 + $publiclist = self::getSearchData($config, $page, 0);
  80 + $data['popular'] = $publiclist['popular'];
  81 + $data['hotWeek'] = $publiclist['hotWeek'];
62 //分类标签 82 //分类标签
63 - $nav = HotrankModel::getHotranktag('web',$data['road'],true);  
64 - $data['hotrank']['hotWeek']['nav'] = $nav;  
65 -  
66 - return $data['hotrank']; 83 + $nav = self::getHotrankTag('web', $data['road'], true);
  84 + $data['hotWeek']['nav'] = $nav;
  85 +
  86 + return $data;
67 } 87 }
68 -  
69 88
70 /* 89 /*
71 * 一周热卖加载更多 90 * 一周热卖加载更多
@@ -73,194 +92,172 @@ class HotrankModel { @@ -73,194 +92,172 @@ class HotrankModel {
73 * @param $sid 一周热卖分类id 92 * @param $sid 一周热卖分类id
74 * @param $page 页码 93 * @param $page 页码
75 */ 94 */
76 - static public function getListData($data,$sid,$page) 95 +
  96 + public static function getListData($data, $sid, $page)
77 { 97 {
78 - $sort = ''; 98 + $sort = '';
79 //是否是默认标签 99 //是否是默认标签
80 - if($sid > 1)  
81 - { 100 + if ($sid > 1) {
82 //通过ID获取标签信息 101 //通过ID获取标签信息
83 $info = HotrankData::getTagById($sid, false); 102 $info = HotrankData::getTagById($sid, false);
84 - if(!empty($info['data']))  
85 - { 103 + if (!empty($info['data'])) {
86 $sort = $info['data']['category_id']; 104 $sort = $info['data']['category_id'];
87 - } 105 + }
88 } 106 }
89 - //获取频道资源  
90 - $channel = self::getChannelResource();  
91 //一周热卖 107 //一周热卖
92 - $config = array('sort' =>$sort,'gender' => $data['gender'],'road' => $data['road']); 108 + $config = array(
  109 + 'sort' => $sort,
  110 + 'gender' => $data['gender'],
  111 + 'road' => $data['road']);
93 $list = self::getSearchData($config, $page, 1); 112 $list = self::getSearchData($config, $page, 1);
94 $lister = $list['hotWeek']['list']; 113 $lister = $list['hotWeek']['list'];
95 $lister = array_values($lister); 114 $lister = array_values($lister);
96 - if($sid == 1 && $page == 1)  
97 - { 115 + if ($sid == 1 && $page == 1) {
98 $lister = array_slice($lister, 10, 50); 116 $lister = array_slice($lister, 10, 50);
99 - }else{ 117 + }
  118 + else {
100 $lister = array_slice($lister, 0, 50); 119 $lister = array_slice($lister, 0, 50);
101 } 120 }
102 - $data = array( 'code'=>200, 'data'=>$lister,); 121 + $data = array(
  122 + 'code' => 200,
  123 + 'data' => $lister,);
103 return $data; 124 return $data;
104 } 125 }
105 -  
106 - 126 +
107 /** 127 /**
108 * 获取焦点图,热门品牌资源 128 * 获取焦点图,热门品牌资源
109 * @param string $channel 129 * @param string $channel
110 * @param string $content_code 130 * @param string $content_code
111 * @return array 131 * @return array
112 */ 132 */
113 - static public function getFocusResource($channel, $content_code) 133 + public static function getFocusResource($channel, $content_code)
114 { 134 {
115 - $resource = IndexData::getResourceData($content_code);  
116 - // 格式化数据  
117 - $data = ChannelProcess::getFormat($channel, $resource['data']);  
118 - return $data; 135 + $resource = IndexData::getResourceData($content_code);
  136 + // 格式化数据
  137 + $data = ChannelProcess::getFormat($channel, $resource['data']);
  138 + return $data;
119 } 139 }
120 -  
121 - 140 +
122 /** 141 /**
123 * 获取人气单品,一周热卖商品资源 142 * 获取人气单品,一周热卖商品资源
124 * @param $config 过滤参数 143 * @param $config 过滤参数
125 * @param $page 当前页数 144 * @param $page 当前页数
126 * @param $ajax 是否是ajax加载 默认0不是 145 * @param $ajax 是否是ajax加载 默认0不是
127 */ 146 */
128 - static public function getSearchData($config,$page,$ajax) 147 + public static function getSearchData($config, $page, $ajax)
129 { 148 {
130 //配置查询商品参数 149 //配置查询商品参数
131 $viewNum = 60; 150 $viewNum = 60;
132 - $param = array('order'=>'s_n_desc','viewNum'=>$viewNum,'page'=>$page,'stocknumber'=>1,'status'=>1,  
133 - 'sort'=>$config['sort'],'gender'=>$config['gender'],'attribute_not'=>2);  
134 - if($ajax == 0)  
135 - {  
136 - if($config['sort'] != 0)  
137 - {  
138 - $param['sort'] = $sort_id;  
139 - }else{  
140 - $param['sort'] = '';  
141 - }  
142 - if($config['road'] == 3)  
143 - {  
144 - $param['msort'] = 365;  
145 - }elseif($config['road'] == 4){  
146 - $param['msort'] = 10;  
147 - }else{  
148 - $param['not_maxSortId'] = '10,365';  
149 - }  
150 - }else{  
151 - if(empty($param['sort']))  
152 - {  
153 - if($config['road'] == 3)  
154 - { 151 + $param = array(
  152 + 'order' => 's_n_desc',
  153 + 'viewNum' => $viewNum,
  154 + 'page' => $page,
  155 + 'stocknumber' => 1,
  156 + 'status' => 1,
  157 + 'sort' => $config['sort'],
  158 + 'gender' => $config['gender'],
  159 + 'attribute_not' => 2);
  160 + if ($ajax == 0 || ($ajax == 1 && empty($param['sort']))) {
  161 + switch ($config['road']) {
  162 + case 3 :
155 $param['msort'] = 365; 163 $param['msort'] = 365;
156 - }elseif($config['road'] == 4){ 164 + break;
  165 + case 4 :
157 $param['msort'] = 10; 166 $param['msort'] = 10;
158 - }else{ 167 + break;
  168 + default :
159 $param['not_maxSortId'] = '10,365'; 169 $param['not_maxSortId'] = '10,365';
160 - }  
161 } 170 }
162 } 171 }
163 //根据给定查询数据搜索数据列表 172 //根据给定查询数据搜索数据列表
164 $result = SearchData::searchElasticByCondition($param); 173 $result = SearchData::searchElasticByCondition($param);
165 - $data = self::getProductList($result,$page,$ajax); 174 + $data = self::getProductList($result, $page, $ajax);
166 return $data; 175 return $data;
167 } 176 }
168 -  
169 177
170 /** 178 /**
171 - * 获取标签资源  
172 - * @param $client_type 客户端类型  
173 - * @param $channel 频道类型  
174 - * @param $is_concurrent 是否异步,true异步,false同步,默认true 179 + * 获取标签资源
  180 + * @param $client_type 客户端类型
  181 + * @param $channel 频道类型
  182 + * @param $is_concurrent 是否异步,true异步,false同步,默认true
175 */ 183 */
176 - static public function getHotranktag($client_type,$channel,$is_concurrent) 184 + public static function getHotrankTag($client_type, $channel, $is_concurrent)
177 { 185 {
178 - $list = \LibModels\Web\Product\HotrankData::getHotranktag($client_type,$channel,$is_concurrent); 186 + $list = HotrankData::getHotrankTag($client_type, $channel, $is_concurrent);
179 $nav = array(); 187 $nav = array();
180 - if(!empty($list['data']['list']))  
181 - {  
182 - foreach($list['data']['list'] as $li=>$lt)  
183 - {  
184 - $nav[$li]['sid'] = $lt['id'];  
185 - $nav[$li]['textCn'] = $lt['tag_name'];  
186 - } 188 + if (!empty($list['data']['list'])) {
  189 + foreach ($list['data']['list'] as $li => $lt) {
  190 + $nav[$li]['sid'] = $lt['id'];
  191 + $nav[$li]['textCn'] = $lt['tag_name'];
  192 + }
187 } 193 }
188 return $nav; 194 return $nav;
189 } 195 }
190 -  
191 - 196 +
192 /** 197 /**
193 * 人气单品 一周热卖 数据处理 198 * 人气单品 一周热卖 数据处理
194 * @param $result 过滤参数 199 * @param $result 过滤参数
195 * @param $page 当前页数 200 * @param $page 当前页数
196 * @param $ajax 是否是ajax加载 默认0不是 201 * @param $ajax 是否是ajax加载 默认0不是
197 */ 202 */
198 - static public function getProductList($result,$page,$ajax=0) 203 + public static function getProductList($result, $page, $ajax = 0)
199 { 204 {
200 - // 调用发起请求  
201 - Yohobuy::yarConcurrentLoop();  
202 -  
203 - if(empty($result) || empty($result['data']) || empty($result['data']['product_list']))  
204 - {  
205 - return; 205 + $product = array();
  206 + if (empty($result) || empty($result['data']) || empty($result['data']['product_list'])) {
  207 + return $product;
206 } 208 }
207 $data = $result['data']['product_list']; 209 $data = $result['data']['product_list'];
208 $popular = array(); 210 $popular = array();
209 $hotWeek = array(); 211 $hotWeek = array();
210 - foreach($data as $key=>$val)  
211 - {  
212 - if(empty($val['goods_list']))  
213 - { 212 + foreach ($data as $key => $val) {
  213 + if (empty($val['goods_list'])) {
214 continue; 214 continue;
215 } 215 }
216 $defaultGoodsId = 0; 216 $defaultGoodsId = 0;
217 - foreach ($val['goods_list'] as $v)  
218 - {  
219 - if($v['is_default'] == 'Y')  
220 - { 217 + foreach ($val['goods_list'] as $v) {
  218 + if ($v['is_default'] == 'Y') {
221 $defaultGoodsId = $v['goods_id']; 219 $defaultGoodsId = $v['goods_id'];
222 } 220 }
223 } 221 }
224 - if(empty($defaultGoodsId))  
225 - { 222 + if (empty($defaultGoodsId)) {
226 $defaultGoodsId = $val['goods_list'][0]['goods_id']; 223 $defaultGoodsId = $val['goods_list'][0]['goods_id'];
227 } 224 }
228 -  
229 $product_id = empty($val['product_id']) ? '' : $val['product_id']; 225 $product_id = empty($val['product_id']) ? '' : $val['product_id'];
230 - $re['name'] = $val['product_name'];  
231 - if($key <= 9 && $page == 1 && $ajax == 0)  
232 - { 226 + $product['name'] = $val['product_name'];
  227 + if ($key <= 9 && $page == 1 && $ajax == 0) {
233 //人气单品 228 //人气单品
234 - $re['rank'] = $key + 1;  
235 - $re['href'] = 'http://item.yohobuy.com/product/pro_'.$product_id.'_'.$defaultGoodsId.'.html';  
236 - $re['price'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : $val['market_price'];  
237 - $re['sPrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];  
238 - if($key <= 5)  
239 - {  
240 - $re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 378, 504, 2);  
241 - $popular['list'][] = $re;  
242 - }else{  
243 - $re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);  
244 - $popular['list'][] = $re; 229 + $product['rank'] = $key + 1;
  230 + $product['href'] = 'http://item.yohobuy.com/product/pro_' . $product_id . '_' . $defaultGoodsId . '.html';
  231 + $product['price'] = (int) $val['market_price'] == (int) $val['sales_price'] ? '' : $val['market_price'];
  232 + $product['sPrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];
  233 + if ($key <= 5) {
  234 + $product['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 378, 504, 2);
  235 + $popular['list'][] = $product;
  236 + }
  237 + else {
  238 + $product['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
  239 + $popular['list'][] = $product;
245 } 240 }
246 - }else{ 241 + }
  242 + else {
247 //一周热卖 243 //一周热卖
248 - $re['url'] = 'http://item.yohobuy.com/product/pro_'.$product_id.'_'.$defaultGoodsId.'.html';  
249 - $re['marketPrice'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : $val['market_price'];  
250 - $re['salePrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];  
251 - $re['rank'] = '';  
252 - $re['thumb'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);  
253 - $hot[] = $re; 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');
  246 + $product['marketPrice'] = (int) $val['market_price'] == (int) $val['sales_price'] ? '' : $val['market_price'];
  247 + $product['salePrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];
  248 + $product['rank'] = '';
  249 + $product['thumb'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
  250 + $hot[] = $product;
254 } 251 }
255 } 252 }
256 $popular['name'] = '人气单品'; 253 $popular['name'] = '人气单品';
257 $hotWeek = array( 254 $hotWeek = array(
258 - 'name'=>'一周热卖',  
259 - 'list'=>$hot, 255 + 'name' => '一周热卖',
  256 + 'list' => $hot,
260 ); 257 );
261 $data['popular'] = $popular; 258 $data['popular'] = $popular;
262 $data['hotWeek'] = $hotWeek; 259 $data['hotWeek'] = $hotWeek;
263 return $data; 260 return $data;
264 } 261 }
265 -  
266 -}  
  262 +
  263 +}
@@ -133,10 +133,10 @@ class IndexController extends WebAction @@ -133,10 +133,10 @@ class IndexController extends WebAction
133 $channel = HotrankModel::getChannelResource(); 133 $channel = HotrankModel::getChannelResource();
134 $this->setWebNavHeader($channel['channel']); 134 $this->setWebNavHeader($channel['channel']);
135 $page = $this->get('page',1); 135 $page = $this->get('page',1);
136 - $sort_id = $this->get('sid',0); 136 + $sort = $this->get('sid',1);
137 $data = array( 'hotrankPage' => true, 137 $data = array( 'hotrankPage' => true,
138 'footerTop'=> true, 138 'footerTop'=> true,
139 - 'hotrank' => HotrankModel::HotrankResource($channel,$sort_id,$page) 139 + 'hotrank' => HotrankModel::getHotrankResource($channel, $sort, $page)
140 ); 140 );
141 $this->_view->display('hotrank', $data); 141 $this->_view->display('hotrank', $data);
142 } 142 }
@@ -157,7 +157,7 @@ class IndexController extends WebAction @@ -157,7 +157,7 @@ class IndexController extends WebAction
157 //获取频道资源 157 //获取频道资源
158 $channel = HotrankModel::getChannelResource(); 158 $channel = HotrankModel::getChannelResource();
159 //获取一周热卖资源 159 //获取一周热卖资源
160 - $data = HotrankModel::getListData($channel,$sid,$page); 160 + $data = HotrankModel::getListData($channel, $sid, $page);
161 echo json_encode($data); 161 echo json_encode($data);
162 exit; 162 exit;
163 } 163 }