Hotrank.php
7.06 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<?php
namespace product;
use WebPlugin\Images;
use Api\Yohobuy;
use LibModels\Web\Product\HotrankData;
use LibModels\Web\Product\SearchData;
use LibModels\Web\Home\IndexData;
use WebPlugin\DataProcess\WebChannel\Channel as ChannelProcess;
class HotrankModel {
/**
* 获取热销排行频道资源
*
* @return array
*/
static public function getChannelResource()
{
$channel = isset($_COOKIE['_Channel']) ? $_COOKIE['_Channel'] : 'boys';
switch ($channel)
{
case 'boys' :
$resource = array('channel' => 'boys', 'gender' => '1,3','road' => 1,'code' => '80d772d8dff25300a2a2e4c97165330c');
return $resource;
case 'girls' :
$resource = array('channel' => 'girls','gender' => '2,3','road' => 2,'code' => '8df64e505e94edb9881fd1e7efb702e9');
return $resource;
case 'lifestyle' :
$resource = array('channel' => 'lifestyle','gender' => '','road' => 4,'code' => 'd131aba83a84a6977eee3a7403a713de');
return $resource;
case 'kids' :
$resource = array('channel' => 'kids','gender' => '','road' => 3,'code' => 'bd6a06a08f8ca9b0db762f78e0bc5b68');
return $resource;
}
}
/**
* 获取焦点图,热门品牌资源
* @param string $channel
* @param string $content_code
* @return array
*/
static public function getFocusResource($channel, $content_code)
{
$resource = IndexData::getResourceData($content_code);
// 格式化数据
$data = ChannelProcess::getFormat($channel, $resource['data']);
return $data;
}
/**
* 获取人气单品,一周热卖商品资源
* @param $config 过滤参数
* @param $page 当前页数
* @param $ajax 是否是ajax加载 默认0不是
*/
static public function getSearchData($config,$page,$ajax)
{
//配置查询商品参数
$viewNum = 60;
$param = array('order'=>'s_n_desc','viewNum'=>$viewNum,'page'=>$page,'stocknumber'=>1,'status'=>1,
'sort'=>$config['sort'],'gender'=>$config['gender'],'attribute_not'=>2);
if($ajax == 0)
{
if($config['sort'] != 0)
{
$param['sort'] = $sort_id;
}else{
$param['sort'] = '';
}
if($config['road'] == 3)
{
$param['msort'] = 365;
}elseif($config['road'] == 4){
$param['msort'] = 10;
}else{
$param['not_maxSortId'] = '10,365';
}
}else{
if(empty($param['sort']))
{
if($config['road'] == 3)
{
$param['msort'] = 365;
}elseif($config['road'] == 4){
$param['msort'] = 10;
}else{
$param['not_maxSortId'] = '10,365';
}
}
}
//根据给定查询数据搜索数据列表
$result = SearchData::searchElasticByCondition($param);
$data = self::getProductList($result,$page,$ajax);
return $data;
}
/**
* 获取标签资源
* @param $client_type 客户端类型
* @param $channel 频道类型
* @param $is_concurrent 是否异步,true异步,false同步,默认true
*/
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;
}
/**
* 人气单品 一周热卖 数据处理
* @param $result 过滤参数
* @param $page 当前页数
* @param $ajax 是否是ajax加载 默认0不是
*/
static public function getProductList($result,$page,$ajax=0)
{
// 调用发起请求
Yohobuy::yarConcurrentLoop();
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['name'] = $val['product_name'];
if($key <= 9 && $page == 1 && $ajax == 0)
{
//人气单品
$re['rank'] = $key + 1;
$re['href'] = 'http://item.yohobuy.com/product/pro_'.$product_id.'_'.$defaultGoodsId.'.html';
$re['price'] = (int)$val['market_price'] == (int)$val['sales_price'] ? '' : $val['market_price'];
$re['sPrice'] = empty($val['sales_price']) ? '' : $val['sales_price'];
if($key <= 5)
{
$re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 378, 504, 2);
$popular['list'][] = $re;
}else{
$re['img'] = empty($val['default_images']) ? '' : Images::getImageUrl($val['default_images'], 280, 373, 2);
$popular['list'][] = $re;
}
}else{
//一周热卖
$re['url'] = 'http://item.yohobuy.com/product/pro_'.$product_id.'_'.$defaultGoodsId.'.html';
$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,
);
$data['popular'] = $popular;
$data['hotWeek'] = $hotWeek;
return $data;
}
}