Authored by 周少峰

代码评审后,修改

@@ -218,4 +218,109 @@ class SearchData extends \LibModels\Wap\Product\SearchData @@ -218,4 +218,109 @@ class SearchData extends \LibModels\Wap\Product\SearchData
218 } 218 }
219 return Yohobuy::get(self::getUrl('suggest'),$param, $cache); 219 return Yohobuy::get(self::getUrl('suggest'),$param, $cache);
220 } 220 }
  221 + /**
  222 + * 并行调接口url获取(搜索产品数据)
  223 + * @param
  224 + */
  225 + public static function getProductUrl($condition)
  226 + {
  227 + // 排序数据映射表
  228 + $orderMaps = array(
  229 + 's_t_desc' => 'shelve_time:desc',
  230 + 's_t_asc' => 'shelve_time:asc',
  231 + 's_p_asc' => 'sales_price:asc',
  232 + 's_p_desc' => 'sales_price:desc',
  233 + 'p_d_desc' => 'discount:desc',
  234 + 'p_d_asc' => 'discount:asc',
  235 + 'skn_desc' => 'product_skn:desc',
  236 + 'skn_asc' => 'product_skn:asc',
  237 + 'activities_desc' => 'activities.order_by:desc',
  238 + 'activities_asc' => 'activities.order_by:asc',
  239 + 's_n_asc' => 'sales_num:asc',
  240 + 's_n_desc' => 'sales_num:desc',
  241 + 'activities_id_desc' => 'activities.activity_id:desc',
  242 + 'activities_id_asc' => 'activities.activity_id:asc',
  243 + );
  244 + $param = array();
  245 + $param['status'] = 1; // 是否上架,1表示在架,2表示不在
  246 + $param['sales'] = 'Y'; // 只搜索销售的产品
  247 + $param['stocknumber'] = 1; // 过滤掉已售罄的商品
  248 + if (!isset($condition['order'])) {
  249 + $param['order'] = $orderMaps['s_t_desc'];
  250 + } else {
  251 + $param['order'] = $orderMaps[$condition['order']];
  252 + }
  253 + if (!isset($condition['page'])) {
  254 + $param['page'] = 1;
  255 + }
  256 +
  257 + if(isset($condition['viewNum'])) {
  258 + $param['viewNum'] = $condition['viewNum'];
  259 + } else if (!isset($condition['limit'])) {
  260 + $param['viewNum'] = 60;
  261 + } else {
  262 + $param['viewNum'] = $condition['limit'];
  263 + unset($condition['limit']);
  264 + }
  265 + if (!empty($condition)) {
  266 + $param += $condition;
  267 + }
  268 + return Yohobuy::httpBuildQuery(SearchData::getUrl(), $param);
  269 + }
  270 +
  271 + /**
  272 + * 并行调接口url获取(产品分类)
  273 + * @param
  274 + */
  275 +
  276 + public static function getClassesUrl($condition)
  277 + {
  278 + $condition['sales'] = 'Y'; //在销售商品分类
  279 + $condition['status'] = 1; //上架商品分类
  280 + $condition['stocknumber'] = 1; //过滤掉已售罄
  281 + return Yohobuy::httpBuildQuery(SearchData::getUrl('sort'), $condition);
  282 + }
  283 +
  284 + /**
  285 + * 并行调接口url获取(获取折扣区间)
  286 + * @param
  287 + */
  288 +
  289 + public static function getDiscountUrl($param = array())
  290 + {
  291 + return Yohobuy::httpBuildQuery(SearchData::getUrl('discount'), $param);
  292 + }
  293 +
  294 + /**
  295 + * 并行调接口url获取(获取最新上架)
  296 + */
  297 + public static function getRecentShelveUrl($param = array())
  298 + {
  299 + return Yohobuy::httpBuildQuery(SearchData::getUrl('recent'), $param);
  300 + }
  301 +
  302 + /**
  303 + * 并行调接口url获取(获取品牌数据)
  304 + */
  305 + public static function getBrandUrl($customOptions = array())
  306 + {
  307 + // 构建必传参数
  308 + $param = Yohobuy::param();
  309 + $param['brand_id'] = $customOptions['brandId'];
  310 + $param['uid'] = $customOptions['uid'];
  311 + $param['method'] = 'app.brand.getBrandIntro';
  312 + $param['client_secret'] = Sign::getSign($param);
  313 +
  314 + return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
  315 + }
  316 +
  317 + /**
  318 + * 获取品牌店铺接口地址
  319 + * @param $param
  320 + * @return string
  321 + */
  322 + public static function getShopUrl($param)
  323 + {
  324 + return Yohobuy::httpBuildQuery(SearchData::getUrl('shop'), $param);
  325 + }
221 } 326 }
@@ -390,7 +390,10 @@ class HelperSearch @@ -390,7 +390,10 @@ class HelperSearch
390 $params = self::$params; 390 $params = self::$params;
391 //url中的品牌ids 391 //url中的品牌ids
392 $brandIds = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array(); 392 $brandIds = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
393 - if (isset($filter['brand']) && !empty($filter['brand'])) { 393 + //如果没有品牌返回空
  394 + if (!isset($filter['brand']) || empty($filter['brand'])) {
  395 + return array();
  396 + }
394 $brand = $filter['brand']; 397 $brand = $filter['brand'];
395 //已选中品牌数量 398 //已选中品牌数量
396 $existBrandNum = 0; 399 $existBrandNum = 0;
@@ -427,54 +430,40 @@ class HelperSearch @@ -427,54 +430,40 @@ class HelperSearch
427 'key' => strtolower($v['brand_name']), 430 'key' => strtolower($v['brand_name']),
428 'checked' => in_array($v['id'], $brandIds) ? true : false 431 'checked' => in_array($v['id'], $brandIds) ? true : false
429 ); 432 );
  433 + //默认品牌
  434 + if ($key < 10) {
  435 + //默认品牌
  436 + $result['default'][] = $this_brand;
  437 + }
430 if (is_numeric($v['brand_alif'])) { 438 if (is_numeric($v['brand_alif'])) {
431 $this_brand['index'] = '0-9'; 439 $this_brand['index'] = '0-9';
432 } 440 }
433 else { 441 else {
434 $this_brand['index'] = strtolower($v['brand_alif']); 442 $this_brand['index'] = strtolower($v['brand_alif']);
435 } 443 }
436 - //默认品牌 TODO  
437 - if (count($result['default']) < 10) {  
438 - $result['default'][] = $this_brand;  
439 - }  
440 //品牌列表 444 //品牌列表
441 - $brandList[$v['brand_alif']][] = $this_brand; 445 + $brandList[$this_brand['index']][] = $this_brand;
442 $brandAll[$v['id']] = $v['brand_name']; 446 $brandAll[$v['id']] = $v['brand_name'];
443 } 447 }
444 -// print_r($brandList); exit;  
445 //清空品牌参数 448 //清空品牌参数
446 unset($params['brand']); 449 unset($params['brand']);
447 //设置选中 450 //设置选中
448 if (isset(self::$params['brand']) && !empty(self::$params['brand'])) { 451 if (isset(self::$params['brand']) && !empty(self::$params['brand'])) {
449 self::$selected['brand'] = array( 452 self::$selected['brand'] = array(
450 - 'name' => str_replace('、', '', $existName), 453 + 'name' => rtrim($existName, '、'),
451 'href' => self::buildUrl($params) 454 'href' => self::buildUrl($params)
452 ); 455 );
453 } 456 }
454 ksort($brandList); 457 ksort($brandList);
455 - //品牌列表排序, 添加品牌索引 TODO  
456 - $index_key = array();  
457 -// print_r($brandList); exit; 458 + //品牌列表排序
458 foreach ($brandList as $key => $val) { 459 foreach ($brandList as $key => $val) {
459 - if ($key && !in_array($key, $index_key) && !is_numeric($key)) {  
460 - $index['index'] = strtolower(($key));  
461 - $index['name'] = $key;  
462 - $index_key[] = $index;  
463 - }  
464 - if ($key && !in_array($key, $index_key) && is_numeric($key) && count($result['brandIndex']) === 1) {  
465 - $index['index'] = '0-9';  
466 - $index['name'] = '0~9'; 460 + $index['name'] = $key != '0-9' ? strtoupper($key) : '0~9';
  461 + $index['index'] = $key;
  462 + $result['brandsShow'] = array_merge_recursive($result['brandsShow'], $val);
467 $result['brandIndex'][] = $index; 463 $result['brandIndex'][] = $index;
468 } 464 }
469 - if (is_array($val)) {  
470 - foreach ($val as $v) {  
471 - $result['brandsShow'][] = $v;  
472 - }  
473 - }  
474 - }  
475 - $result['brandIndex'] = array_merge($result['brandIndex'], $index_key);  
476 unset($brandList); 465 unset($brandList);
477 - } 466 +
478 //搜索页已选中,返回空 467 //搜索页已选中,返回空
479 if (self::checkSearch('brand')) { 468 if (self::checkSearch('brand')) {
480 return array(); 469 return array();
@@ -577,24 +566,14 @@ class HelperSearch @@ -577,24 +566,14 @@ class HelperSearch
577 } 566 }
578 $result = array(); 567 $result = array();
579 //设置已选中价格 568 //设置已选中价格
580 - if (!empty($priceId) && isset($filter['price'][$priceId])) { 569 + if (!empty($priceId)) {
  570 + $price = explode(',' ,$priceId);
  571 + $customName = self::$params['price'] == '2000,99999' ? '¥2000以上' : '¥' . (int)$price[0] . '-' . (int)$price[1];
  572 + $name = isset($filter['price'][$priceId]) ? $filter['price'][$priceId] : $customName;
581 self::$selected['price'] = array( 573 self::$selected['price'] = array(
582 - 'name' => $filter['price'][$priceId], 574 + 'name' => $name,
583 'href' => self::buildUrl($params) 575 'href' => self::buildUrl($params)
584 ); 576 );
585 - }else{  
586 - $price = explode(',', $priceId);  
587 - //TODO  
588 - if (!$price[0]) {  
589 - $price[0] = 0;  
590 - }  
591 - if (!$price[1]) {  
592 - $price[1] = 99999;  
593 - }  
594 - self::$selected['price'] = array(  
595 - 'name' => self::$params['price'] == '2000,99999' ? '¥2000以上' : '¥' . (int)$price[0] . '-' . (int)$price[1],  
596 - 'href' => self::buildurl($params)  
597 - );  
598 } 577 }
599 if (self::checkSearch('price')) { 578 if (self::checkSearch('price')) {
600 return array(); 579 return array();
@@ -794,9 +773,9 @@ class HelperSearch @@ -794,9 +773,9 @@ class HelperSearch
794 } 773 }
795 774
796 /** 775 /**
797 - * 是否新品 TODO 776 + * 是否新品
798 */ 777 */
799 - public static function isnew() 778 + public static function isNew()
800 { 779 {
801 $params = self::$params; 780 $params = self::$params;
802 $selected = ''; 781 $selected = '';
@@ -978,7 +957,6 @@ class HelperSearch @@ -978,7 +957,6 @@ class HelperSearch
978 $result['conditions'] = $data; 957 $result['conditions'] = $data;
979 $result['clearUrl'] = self::current(); 958 $result['clearUrl'] = self::current();
980 } 959 }
981 -// print_r($result); exit;  
982 return $result; 960 return $result;
983 } 961 }
984 962
@@ -1192,114 +1170,6 @@ class HelperSearch @@ -1192,114 +1170,6 @@ class HelperSearch
1192 } 1170 }
1193 1171
1194 /** 1172 /**
1195 - * 并行调接口url获取(搜索产品数据)  
1196 - * @param  
1197 - */  
1198 - public static function getProductUrl($condition)  
1199 - {  
1200 - // 排序数据映射表  
1201 - $orderMaps = array(  
1202 - 's_t_desc' => 'shelve_time:desc',  
1203 - 's_t_asc' => 'shelve_time:asc',  
1204 - 's_p_asc' => 'sales_price:asc',  
1205 - 's_p_desc' => 'sales_price:desc',  
1206 - 'p_d_desc' => 'discount:desc',  
1207 - 'p_d_asc' => 'discount:asc',  
1208 - 'skn_desc' => 'product_skn:desc',  
1209 - 'skn_asc' => 'product_skn:asc',  
1210 - 'activities_desc' => 'activities.order_by:desc',  
1211 - 'activities_asc' => 'activities.order_by:asc',  
1212 - 's_n_asc' => 'sales_num:asc',  
1213 - 's_n_desc' => 'sales_num:desc',  
1214 - 'activities_id_desc' => 'activities.activity_id:desc',  
1215 - 'activities_id_asc' => 'activities.activity_id:asc',  
1216 - );  
1217 - $param = array();  
1218 - $param['status'] = 1; // 是否上架,1表示在架,2表示不在  
1219 - $param['sales'] = 'Y'; // 只搜索销售的产品  
1220 - $param['stocknumber'] = 1; // 过滤掉已售罄的商品  
1221 - if (!isset($condition['order'])) {  
1222 - $param['order'] = $orderMaps['s_t_desc'];  
1223 - } else {  
1224 - $param['order'] = $orderMaps[$condition['order']];  
1225 - }  
1226 - if (!isset($condition['page'])) {  
1227 - $param['page'] = 1;  
1228 - }  
1229 -  
1230 - if(isset($condition['viewNum'])) {  
1231 - $param['viewNum'] = $condition['viewNum'];  
1232 - } else if (!isset($condition['limit'])) {  
1233 - $param['viewNum'] = 60;  
1234 - } else {  
1235 - $param['viewNum'] = $condition['limit'];  
1236 - unset($condition['limit']);  
1237 - }  
1238 - if (!empty($condition)) {  
1239 - $param += $condition;  
1240 - }  
1241 - return Yohobuy::httpBuildQuery(SearchData::getUrl(), $param);  
1242 - }  
1243 -  
1244 - /**  
1245 - * 并行调接口url获取(产品分类)  
1246 - * @param  
1247 - */  
1248 -  
1249 - public static function getClassesUrl($condition)  
1250 - {  
1251 - $condition['sales'] = 'Y'; //在销售商品分类  
1252 - $condition['status'] = 1; //上架商品分类  
1253 - $condition['stocknumber'] = 1; //过滤掉已售罄  
1254 - return Yohobuy::httpBuildQuery(SearchData::getUrl('sort'), $condition);  
1255 - }  
1256 -  
1257 - /**  
1258 - * 并行调接口url获取(获取折扣区间)  
1259 - * @param  
1260 - */  
1261 -  
1262 - public static function getDiscountUrl($param = array())  
1263 - {  
1264 - return Yohobuy::httpBuildQuery(SearchData::getUrl('discount'), $param);  
1265 - }  
1266 -  
1267 - /**  
1268 - * 并行调接口url获取(获取最新上架)  
1269 - */  
1270 - public static function getRecentShelveUrl($param = array())  
1271 - {  
1272 - return Yohobuy::httpBuildQuery(SearchData::getUrl('recent'), $param);  
1273 - }  
1274 -  
1275 - /**  
1276 - * 并行调接口url获取(获取品牌数据)  
1277 - */  
1278 - public static function getBrandUrl($customOptions = array())  
1279 - {  
1280 - // 构建必传参数  
1281 - $param = Yohobuy::param();  
1282 - $param['brand_id'] = $customOptions['brandId'];  
1283 - $param['uid'] = $customOptions['uid'];  
1284 - $param['method'] = 'app.brand.getBrandIntro';  
1285 - $param['client_secret'] = Sign::getSign($param);  
1286 -  
1287 - return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);  
1288 - }  
1289 -  
1290 -  
1291 -  
1292 - /**  
1293 - * 获取品牌店铺接口地址 TODO  
1294 - * @param $param  
1295 - * @return string  
1296 - */  
1297 - public static function getShopUrl($param)  
1298 - {  
1299 - return Yohobuy::httpBuildQuery(SearchData::getUrl('shop'), $param);  
1300 - }  
1301 -  
1302 - /**  
1303 * 获取品牌首页banner条 1173 * 获取品牌首页banner条
1304 * 1174 *
1305 * @return array 品牌banner条数据 1175 * @return array 品牌banner条数据
@@ -1362,7 +1232,7 @@ class HelperSearch @@ -1362,7 +1232,7 @@ class HelperSearch
1362 //排序方式 1232 //排序方式
1363 $result['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount()); 1233 $result['sortType'] = array( self::orderDefault(),self::orderTime(),self::orderPrice(),self::orderDiscount());
1364 //特殊:新品、特价、限量 1234 //特殊:新品、特价、限量
1365 - $result['checks'] = array(self::isnew(),self::specialoffer(),self::limited()); 1235 + $result['checks'] = array(self::isNew(),self::specialoffer(),self::limited());
1366 //每行显示5个产品 1236 //每行显示5个产品
1367 $result['fivePerLine'] = true; 1237 $result['fivePerLine'] = true;
1368 //每行显示6个产品 1238 //每行显示6个产品
@@ -145,11 +145,11 @@ class SearchModel @@ -145,11 +145,11 @@ class SearchModel
145 $urlList = array(); 145 $urlList = array();
146 $searchCondition = self::searchCondition($customCondition, $customOptions); 146 $searchCondition = self::searchCondition($customCondition, $customOptions);
147 // 组合搜索商品url 147 // 组合搜索商品url
148 - $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']); 148 + $urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
149 // 组合搜索分类url 149 // 组合搜索分类url
150 - $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['sortCondition']); 150 + $urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']);
151 // 组合搜索折扣区间url 151 // 组合搜索折扣区间url
152 - $urlList['discount'] = HelperSearch::getDiscountUrl($searchCondition['condition']); 152 + $urlList['discount'] = SearchData::getDiscountUrl($searchCondition['condition']);
153 153
154 $result = Yohobuy::getMulti($urlList, array(), true); 154 $result = Yohobuy::getMulti($urlList, array(), true);
155 // 组织模板数据 155 // 组织模板数据
@@ -179,13 +179,13 @@ class SearchModel @@ -179,13 +179,13 @@ class SearchModel
179 } 179 }
180 } 180 }
181 // 组合搜索商品url 181 // 组合搜索商品url
182 - $urlList['product'] = HelperSearch::getProductUrl($searchCondition['condition']); 182 + $urlList['product'] = SearchData::getProductUrl($searchCondition['condition']);
183 // 组合搜索分类url 183 // 组合搜索分类url
184 - $urlList['sort'] = HelperSearch::getClassesUrl($searchCondition['sortCondition']); 184 + $urlList['sort'] = SearchData::getClassesUrl($searchCondition['sortCondition']);
185 // 组合搜索店铺url 185 // 组合搜索店铺url
186 if (isset($searchCondition['condition']['query'])) { 186 if (isset($searchCondition['condition']['query'])) {
187 $param['keyword'] = $searchCondition['condition']['query']; 187 $param['keyword'] = $searchCondition['condition']['query'];
188 - $urlList['shop'] = HelperSearch::getShopUrl($param); 188 + $urlList['shop'] = SearchData::getShopUrl($param);
189 } 189 }
190 $data = Yohobuy::getMulti($urlList, array(), true); 190 $data = Yohobuy::getMulti($urlList, array(), true);
191 //获取品牌商品分类 191 //获取品牌商品分类