Hotrank.php
4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<?php
namespace product;
use Plugin\Images;
use Api\Yohobuy;
//use Plugin\Helpers;
//use LibModels\Web\Home\IndexData;
use \LibModels\Web\Product\HotrankData;
use \LibModels\Web\Product\SearchData;
class HotrankModel {
/**
* 人气单品 一周热卖
*/
static public function getSearchData($param,$page,$ajax)
{
// 调用接口查询商品数据
$result = SearchData::searchElasticByCondition($param);
//print_r($result);
if(!empty($result)){
$res = self::getProductList($result,$page,$ajax);
if(!empty($res['popular'])){
$data['popular'] = $res['popular'];
}
if(!empty($res['hotWeek'])){
$data['hotWeek'] = $res['hotWeek'];
}
}
return $data;
}
/**
* 获取分类标签
*/
static public function getHotranktag($client_type,$channel,$is_concurrent)
{
$list = \LibModels\Web\Product\HotrankData::getHotranktag($client_type,$channel,$is_concurrent);
$nav = array();
if(!empty($list['data']['list'])){
foreach($list['data']['list'] as $li=>$lt){
$nav[$li]['sid'] = $lt['id'];
$nav[$li]['textCn'] = $lt['tag_name'];
}
}
return $nav;
}
/**
* 人气单品 一周热卖 数据处理
*/
static public function getProductList($result,$page,$ajax=0)
{
// 调用发起请求
Yohobuy::yarConcurrentLoop();
/*----product start---------*/
if(empty($result) || empty($result['data']) || empty($result['data']['product_list'])){
return;
}
$data = $result['data']['product_list'];
$popular = array();
$hotWeek = array();
foreach($data as $key=>$val){
if(empty($val['goods_list'])){
continue;
}
$defaultGoodsId = 0;
foreach ($val['goods_list'] as $v){
if($v['is_default'] == 'Y'){
$defaultGoodsId = $v['goods_id'];
}
}
if(empty($defaultGoodsId)){
$defaultGoodsId = $val['goods_list'][0]['goods_id'];
}
$product_id = empty($val['product_id']) ? '' : $val['product_id'];
$re['url'] = 'http://item.yohobuy.com/product/pro_'.$product_id.'_'.$defaultGoodsId.'.html';
$re['name'] = $val['product_name'];
if($key <= 9 && $page == 1 && $ajax == 0){
$re['rank'] = $key + 1;
if($key <= 5){
$re['price'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : '¥'.$val['market_price'];
$re['sPrice'] = empty($val['sales_price']) ? '' : '¥'.$val['sales_price'];
$re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 378, 504, 2);
$popular['list'][] = $re;
}else{
$re['price'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : '¥'.$val['market_price'];
$re['sPrice'] = empty($val['sales_price']) ? '' : '¥'.$val['sales_price'];
$re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
$popular['list'][] = $re;
}
}else if ($ajax == 1){
$re['marketPrice'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : '¥'.$val['market_price'];
$re['salePrice'] = empty($val['sales_price']) ? '' : '¥'.$val['sales_price'];
$re['rank'] = '';
$re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
$hot[] = $re;
}else{
$re['marketPrice'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : '¥'.$val['market_price'];
$re['salePrice'] = empty($val['sales_price']) ? '' : '¥'.$val['sales_price'];
$re['rank'] = '';
$re['thumb'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
$hot[] = $re;
}
}
$popular['name'] = '人气单品';
$hotWeek = array(
'name'=>'一周热卖',
'list'=>$hot,
);
return array('popular'=>$popular,'hotWeek'=>$hotWeek);
}
}