Authored by 周少峰

添加浏览记录,接口地址统一,

@@ -11,31 +11,114 @@ class SearchData extends \LibModels\Wap\Product\SearchData @@ -11,31 +11,114 @@ class SearchData extends \LibModels\Wap\Product\SearchData
11 * 11 *
12 * @return string 12 * @return string
13 */ 13 */
14 - private static function getUrl($type = 'search') 14 + public static function getUrl($type = 'search')
15 { 15 {
16 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer'); 16 defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');
17 switch (APPLICATION_ENV) { 17 switch (APPLICATION_ENV) {
18 case 'release': 18 case 'release':
19 - if($type == 'sort'){ 19 + if ($type == 'sort') {
20 return 'http://100.98.132.63/yohosearch/sortgroup.json'; 20 return 'http://100.98.132.63/yohosearch/sortgroup.json';
21 } 21 }
22 - elseif($type == 'suggest'){  
23 - return 'http://100.98.132.63/yohosearch/suggest.json'; 22 + elseif ($type == 'discount') {
  23 + return 'http://100.98.132.63/yohosearch/discount.json';
  24 + }
  25 + elseif ($type == 'recent') {
  26 + return 'http://100.98.132.63/yohosearch/recent.json';
  27 + }
  28 + elseif ($type == 'shop') {
  29 + return 'http://100.98.132.63/yohosearch/shops.json';
24 } 30 }
25 return 'http://100.98.132.63/yohosearch/search.json'; 31 return 'http://100.98.132.63/yohosearch/search.json';
26 case 'test': 32 case 'test':
27 case 'preview': 33 case 'preview':
28 case 'developer': 34 case 'developer':
29 default: 35 default:
30 - if($type == 'sort'){ 36 + if ($type == 'sort') {
31 return 'http://101.200.31.165/yohosearch/sortgroup.json'; 37 return 'http://101.200.31.165/yohosearch/sortgroup.json';
32 } 38 }
33 - elseif($type == 'suggest'){  
34 - return 'http://101.200.31.165/yohosearch/suggest.json'; 39 + elseif ($type == 'discount') {
  40 + return 'http://101.200.31.165/yohosearch/discount.json';
  41 + }
  42 + elseif ($type == 'recent') {
  43 + return 'http://101.200.31.165/yohosearch/recent.json';
  44 + }
  45 + elseif ($type == 'shop') {
  46 + return 'http://101.200.31.165/yohosearch/shops.json';
35 } 47 }
36 -  
37 return 'http://101.200.31.165/yohosearch/search.json'; 48 return 'http://101.200.31.165/yohosearch/search.json';
  49 + //return 'http://192.168.10.64:8080/yohosearch/search-once.json';
  50 + }
  51 + }
  52 +
  53 + /**
  54 + * 根据给定查询数据搜索数据列表 (新的)
  55 + *
  56 + * @param string $query 查询条件, 默认为null
  57 + * @param string $brand 品牌,默认为null
  58 + * @param string $gender 性别,默认为null,"1,3"表示男, "2,3"表示女, "1,2,3"表示全部
  59 + * @param integer $color 颜色id
  60 + * @param integer $size 尺码id
  61 + * @param integer $price 价格
  62 + * @param string $p_d 折扣,默认为null
  63 + * @param string $sort 商品所属品类,默认为null
  64 + * @param string $order 排序方式,默认为按照时间倒序排列s_t_desc,
  65 + * s_t_asc表示按时间正序排列,
  66 + * s_p_asc表示按价格正序排列,
  67 + * s_p_desc表示按价格倒序排列,
  68 + * p_d_asc表示按折扣正序排列,
  69 + * p_d_desc表示按折扣倒序排列
  70 + * @param integer $page 指定查询是多少页,默认为第一页
  71 + * @param integer $limit 指定查询多少个,默认是60个
  72 + * @param integer $channel表示哪个频道,1表示男生,2表示女生,3表示潮童,4表示创意生活
  73 + * @return array 搜索到的数据
  74 + */
  75 + public static function searchElasticByCondition($condition, $cache = false)
  76 + {
  77 + // 排序数据映射表
  78 + $orderMaps = array(
  79 + 's_t_desc' => 'shelve_time:desc',
  80 + 's_t_asc' => 'shelve_time:asc',
  81 + 's_p_asc' => 'sales_price:asc',
  82 + 's_p_desc' => 'sales_price:desc',
  83 + 'p_d_desc' => 'discount:desc',
  84 + 'p_d_asc' => 'discount:asc',
  85 + 'skn_desc' => 'product_skn:desc',
  86 + 'skn_asc' => 'product_skn:asc',
  87 + 'activities_desc' => 'activities.order_by:desc',
  88 + 'activities_asc' => 'activities.order_by:asc',
  89 + 's_n_asc' => 'sales_num:asc',
  90 + 's_n_desc' => 'sales_num:desc',
  91 + 'activities_id_desc' => 'activities.activity_id:desc',
  92 + 'activities_id_asc' => 'activities.activity_id:asc',
  93 + );
  94 +
  95 + $param = array();
  96 + $param['status'] = 1; // 是否上架,1表示在架,2表示不在
  97 + $param['sales'] = 'Y'; // 只搜索销售的产品
  98 + $param['stocknumber'] = 1; // 过滤掉已售罄的商品
  99 + // $param['needFilter'] = 1; // 是否需要返回筛选条件
  100 + if (!isset($condition['order'])) {
  101 + $param['order'] = $orderMaps['s_t_desc'];
  102 + } else {
  103 + $param['order'] = $orderMaps[$condition['order']];
38 } 104 }
  105 + if (!isset($condition['page'])) {
  106 + $param['page'] = 1;
  107 + }
  108 +
  109 + if(isset($condition['viewNum'])) {
  110 + $param['viewNum'] = $condition['viewNum'];
  111 + } else if (!isset($condition['limit'])) {
  112 + $param['viewNum'] = 60;
  113 + } else {
  114 + $param['viewNum'] = $condition['limit'];
  115 + unset($condition['limit']);
  116 + }
  117 + if (!empty($condition)) {
  118 + $param += $condition;
  119 + }
  120 +
  121 + return Yohobuy::get(self::getUrl('search'), $param, $cache);
39 } 122 }
40 /** 123 /**
41 * 根据分类列表获取商品信息 124 * 根据分类列表获取商品信息
@@ -4,6 +4,7 @@ namespace Plugin; @@ -4,6 +4,7 @@ namespace Plugin;
4 4
5 use Plugin\Paging; 5 use Plugin\Paging;
6 use LibModels\Web\Product\BrandData; 6 use LibModels\Web\Product\BrandData;
  7 +use LibModels\Web\Product\SearchData;
7 use Api\Yohobuy; 8 use Api\Yohobuy;
8 use Api\Sign; 9 use Api\Sign;
9 /** 10 /**
@@ -90,7 +91,9 @@ class HelperSearch @@ -90,7 +91,9 @@ class HelperSearch
90 //分页 91 //分页
91 $result['pager'] = self::pager($result['totalCount'],$options['viewNum']-1); 92 $result['pager'] = self::pager($result['totalCount'],$options['viewNum']-1);
92 //浏览记录 93 //浏览记录
93 - $result['latestWalk'] = array(); 94 + if ($options['reviewNum']) {
  95 + $result['latestWalk'] = $options['reviewNum'];
  96 + }
94 //选中条件 97 //选中条件
95 $result['filters']['checkedConditions'] = self::getSelected(); 98 $result['filters']['checkedConditions'] = self::getSelected();
96 if (isset($options['controller']) && $options['controller'] == 'Search') { 99 if (isset($options['controller']) && $options['controller'] == 'Search') {
@@ -349,10 +352,6 @@ class HelperSearch @@ -349,10 +352,6 @@ class HelperSearch
349 array( 352 array(
350 'index' => 'all', 353 'index' => 'all',
351 'name' => '全部' 354 'name' => '全部'
352 - ),  
353 - array(  
354 - 'index' => '0-9',  
355 - 'name' => '0 ~ 9'  
356 ) 355 )
357 ), 356 ),
358 'brandsShow' => array() 357 'brandsShow' => array()
@@ -362,17 +361,29 @@ class HelperSearch @@ -362,17 +361,29 @@ class HelperSearch
362 $brandIds = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array(); 361 $brandIds = isset($params['brand']) && !empty($params['brand']) ? explode(',', $params['brand']) : array();
363 if (isset($filter['brand']) && !empty($filter['brand'])) { 362 if (isset($filter['brand']) && !empty($filter['brand'])) {
364 $brand = $filter['brand']; 363 $brand = $filter['brand'];
  364 +// print_r($filter); exit;
  365 + //已选中品牌数量
  366 + $existBrandNum = 0;
  367 + //已选中品牌标签名
  368 + $existName = '';
365 foreach ($brand as $key => $v) { 369 foreach ($brand as $key => $v) {
366 $selectBrandIds = $brandIds; 370 $selectBrandIds = $brandIds;
367 - //品牌id在提交的参数中,构造url参数去除该品牌id 371 + //品牌已被选中
368 if (in_array($v['id'], $brandIds)) { 372 if (in_array($v['id'], $brandIds)) {
369 $filterKey = array_search($v['id'], $selectBrandIds); 373 $filterKey = array_search($v['id'], $selectBrandIds);
370 unset($selectBrandIds[$filterKey]); 374 unset($selectBrandIds[$filterKey]);
371 $url = self::buildUrl(array_merge($params, array( 375 $url = self::buildUrl(array_merge($params, array(
372 'brand' => implode(',', $selectBrandIds) 376 'brand' => implode(',', $selectBrandIds)
373 ))); 377 )));
  378 + if ($existBrandNum === 0) {
  379 + $existName .= $v['brand_name'].'、';
  380 + }
  381 + if ($existBrandNum === 1){
  382 + $existName .= substr($v['brand_name'], 0, 3).'...';
  383 + }
  384 + $existBrandNum++;
374 } 385 }
375 - //该品牌url参数中添加该品牌的id 386 + //该品牌未被选中
376 else { 387 else {
377 $selectBrandIds[] = $v['id']; 388 $selectBrandIds[] = $v['id'];
378 $url = self::buildUrl(array_merge($params, array( 389 $url = self::buildUrl(array_merge($params, array(
@@ -402,25 +413,6 @@ class HelperSearch @@ -402,25 +413,6 @@ class HelperSearch
402 } 413 }
403 //清空品牌参数 414 //清空品牌参数
404 unset($params['brand']); 415 unset($params['brand']);
405 - //设置已选中的品牌  
406 - $existBrandNum = 0;  
407 - $existName = '';  
408 - foreach ($brandIds as $key => $val) {  
409 - if (isset($brandAll[$val])) {  
410 - $brandParam = $brandIds;  
411 - unset($brandParam[$key]);  
412 - if ($existBrandNum === 0) {  
413 - $existName .= $brandAll[$val].'、';  
414 - }  
415 - if ($existBrandNum === 1){  
416 - $existName .= substr($brandAll[$val], 0, 3).'...';  
417 - }  
418 - $existBrandNum++;  
419 - }  
420 - if ($existBrandNum > 1) {  
421 - break;  
422 - }  
423 - }  
424 //设置选中 416 //设置选中
425 if (isset(self::$params['brand']) && !empty(self::$params['brand'])) { 417 if (isset(self::$params['brand']) && !empty(self::$params['brand'])) {
426 self::$selected['brand'] = array( 418 self::$selected['brand'] = array(
@@ -454,6 +446,7 @@ class HelperSearch @@ -454,6 +446,7 @@ class HelperSearch
454 if (count($result['brandsShow']) < 11) { 446 if (count($result['brandsShow']) < 11) {
455 $result['hideMore'] = true; 447 $result['hideMore'] = true;
456 } 448 }
  449 +// print_r($result); exit;
457 return $result; 450 return $result;
458 } 451 }
459 /** 452 /**
@@ -1206,7 +1199,7 @@ class HelperSearch @@ -1206,7 +1199,7 @@ class HelperSearch
1206 if (!empty($condition)) { 1199 if (!empty($condition)) {
1207 $param += $condition; 1200 $param += $condition;
1208 } 1201 }
1209 - return Yohobuy::httpBuildQuery(self::getUrl(), $param); 1202 + return Yohobuy::httpBuildQuery(SearchData::getUrl(), $param);
1210 } 1203 }
1211 1204
1212 /** 1205 /**
@@ -1219,7 +1212,7 @@ class HelperSearch @@ -1219,7 +1212,7 @@ class HelperSearch
1219 $condition['sales'] = 'Y'; //在销售商品分类 1212 $condition['sales'] = 'Y'; //在销售商品分类
1220 $condition['status'] = 1; //上架商品分类 1213 $condition['status'] = 1; //上架商品分类
1221 $condition['stocknumber'] = 1; //过滤掉已售罄 1214 $condition['stocknumber'] = 1; //过滤掉已售罄
1222 - return Yohobuy::httpBuildQuery(self::getUrl('sort'), $condition); 1215 + return Yohobuy::httpBuildQuery(SearchData::getUrl('sort'), $condition);
1223 } 1216 }
1224 1217
1225 /** 1218 /**
@@ -1229,7 +1222,7 @@ class HelperSearch @@ -1229,7 +1222,7 @@ class HelperSearch
1229 1222
1230 public static function getDiscountUrl($param = array()) 1223 public static function getDiscountUrl($param = array())
1231 { 1224 {
1232 - return Yohobuy::httpBuildQuery(self::getUrl('discount'), $param); 1225 + return Yohobuy::httpBuildQuery(SearchData::getUrl('discount'), $param);
1233 } 1226 }
1234 1227
1235 /** 1228 /**
@@ -1237,7 +1230,7 @@ class HelperSearch @@ -1237,7 +1230,7 @@ class HelperSearch
1237 */ 1230 */
1238 public static function getRecentShelveUrl($param = array()) 1231 public static function getRecentShelveUrl($param = array())
1239 { 1232 {
1240 - return Yohobuy::httpBuildQuery(self::getUrl('recent'), $param); 1233 + return Yohobuy::httpBuildQuery(SearchData::getUrl('recent'), $param);
1241 } 1234 }
1242 1235
1243 /** 1236 /**
@@ -1268,15 +1261,6 @@ class HelperSearch @@ -1268,15 +1261,6 @@ class HelperSearch
1268 1261
1269 return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param); 1262 return Yohobuy::httpBuildQuery(Yohobuy::API_URL, $param);
1270 } 1263 }
1271 -  
1272 -  
1273 - /**  
1274 - * 并行调接口url获取(获取用户浏览记录)  
1275 - */  
1276 -// public static function getReviewUrl($param = array())  
1277 -// {  
1278 -// return Yohobuy::httpBuildQuery(self::getUrl('review'), $param);  
1279 -// }  
1280 1264
1281 1265
1282 /** 1266 /**
@@ -1286,58 +1270,7 @@ class HelperSearch @@ -1286,58 +1270,7 @@ class HelperSearch
1286 */ 1270 */
1287 public static function getShopUrl($param) 1271 public static function getShopUrl($param)
1288 { 1272 {
1289 - return Yohobuy::httpBuildQuery(self::getUrl('shop'), $param);  
1290 - }  
1291 - /**  
1292 - * 获取搜索的服务地址  
1293 - *  
1294 - * 备注:此处是根据环境来确定使用阿里云内网还是外网的URL  
1295 - *  
1296 - * @return string  
1297 - */  
1298 - private static function getUrl($type = 'search')  
1299 - {  
1300 - defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'developer');  
1301 - switch (APPLICATION_ENV) {  
1302 - case 'release':  
1303 - if ($type == 'sort') {  
1304 - return 'http://100.98.132.63/yohosearch/sortgroup.json';  
1305 - }  
1306 - elseif ($type == 'discount') {  
1307 - return 'http://100.98.132.63/yohosearch/discount.json';  
1308 - }  
1309 - elseif ($type == 'recent') {  
1310 - return 'http://100.98.132.63/yohosearch/recent.json';  
1311 - }  
1312 -// elseif ($type == 'review') {  
1313 -//  
1314 -// }  
1315 - elseif ($type == 'shop') {  
1316 - return 'http://100.98.132.63/yohosearch/shops.json';  
1317 - }  
1318 - return 'http://100.98.132.63/yohosearch/search.json';  
1319 - case 'test':  
1320 - case 'preview':  
1321 - case 'developer':  
1322 - default:  
1323 - if ($type == 'sort') {  
1324 - return 'http://101.200.31.165/yohosearch/sortgroup.json';  
1325 - }  
1326 - elseif ($type == 'discount') {  
1327 - return 'http://101.200.31.165/yohosearch/discount.json';  
1328 - }  
1329 - elseif ($type == 'recent') {  
1330 - return 'http://101.200.31.165/yohosearch/recent.json';  
1331 - }  
1332 -// elseif ($type == 'review') {  
1333 -//  
1334 -// }  
1335 - elseif ($type == 'shop') {  
1336 - return 'http://101.200.31.165/yohosearch/shops.json';  
1337 - }  
1338 -// return 'http://101.200.31.165/yohosearch/search.json';  
1339 - return 'http://192.168.10.64:8080/yohosearch/search-once.json';  
1340 - } 1273 + return Yohobuy::httpBuildQuery(SearchData::getUrl('shop'), $param);
1341 } 1274 }
1342 1275
1343 /** 1276 /**
@@ -50,7 +50,7 @@ class ListController extends WebAction @@ -50,7 +50,7 @@ class ListController extends WebAction
50 public function saleAction() 50 public function saleAction()
51 { 51 {
52 $condition = array(); 52 $condition = array();
53 - $list = SearchModel::getListData($condition); 53 + $list = SearchModel::getListData($condition,array('reviewNum'=>6));
54 $data = array( 54 $data = array(
55 //初始化js 55 //初始化js
56 'productListPage' => true, 56 'productListPage' => true,