Mobileapi.class.php
12.9 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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
<?php
/**
* 手机客户端API接口
*/
class Controller_MobileApi extends Controller_Abstract
{
/**
* 获取客户端模块
*
* @return json
*/
public function getMobileModuleListAction()
{
$modules = Facade_Mobile::getModule();
$data = array();
foreach($modules as $module)
{
$headCover = '';
if($module['id'] == 1)
{
$headCover = SITE_IMG.'/yohood/yohood-logo-mobile_v2.png';
}
$data [] = array('id'=> $module['id'],
'status'=> $module['status'],
'moduleName' => $module['module_name'],
'headCover' => $headCover
);
}
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取资讯
*
* @return json
*/
public function getNewsListAction()
{
list($offset, $limit) = $this->getMobileLimit();
$tag = trim($this->_request->query('tag',''));
if($tag == '全部资讯')
{
$tag = '';
}
if($tag == '视频') //手机端视频要小
{
$tag = '手机视频';
}
$data = array('total' => '0', 'list'=> array());
$newses = Facade_News::getList($tag, $offset, $limit, array('视频'));
$data['total'] = Facade_News::getTotal($tag, array('视频'));
foreach($newses as $news)
{
if($news['tag'] == '视频')
{
continue;
}
if($news['tag'] == '手机视频')
{
$news['tag'] = '视频';
}
if(!empty($news['client_thumb']))
{
$image = $news['client_thumb'];
}
else
{
$image = $news['thumb'];
}
$data['list'][] = array(
'id' => $news['id'],
'tag' => $news['tag'], 'title' => sprintf("[%s] %s", $news['tag'], strip_tags($news['title'])),
'image' => Lib_Images::getImageUrl($image, 'source','fragmentimg'),
'isVideo'=> strval($news['tag'] == '视频'?1:0),
'createTime' => $news['create_time']
);
}
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取资讯标签
*
* @return json
*/
public function getTagsAction()
{
$data = array();
$types = Facade_News::$types;
$newTags = Facade_News::getTags();
foreach($types as $type)
{
foreach($newTags as $tag)
{
if($type == $tag['tag'])
{
$data[] = $type;
break;
}
}
}
$data = array_merge(array('全部资讯'), $data);
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取资讯详情
*
* @return json
*/
public function getNewsDetailAction()
{
$id = $this->_request->query('id');
$news = Facade_News::getOneById($id);
Facade_News::updateHits($id);
$data = array();
$data = array('content'=> '', 'images' => array(), 'video'=> '', 'content' => '','video_image'=>'','url'=>'','title' => '') ;
preg_match_all("@<img([^>]*)\s*src=('|\")([^'\"]+)('|\")@", $news['content'], $imageMatches);
preg_match_all("@<embed([^>]*)\s*src=\"http:\/\/res\.yoho\.cn\/res\/yohood\/swf\/YohoodPlayer\.swf\?url=(.+)\" width=@", $news['content'], $videoMatches);
if(!empty($news['client_thumb']))
{
$image = $news['client_thumb'];
}
else
{
$image = $news['thumb'];
}
if(!empty($imageMatches[3]))
{
$data['images'] = array_unique($imageMatches[3]);//去除数组中重复值
}
$data['thumb'] = Lib_Images::getImageUrl($image, 'source','fragmentimg');
$data['title'] = strip_tags($news['title']);
$data['video_image'] = Lib_Images::getImageUrl($image, 'source','fragmentimg');
$patterns = array("/\s+/", "/<p[^>]*?>(.*?)<\/p>/is","/<(\/?br.*?)>/si");
$replaces = array(" ", "$1\n", "");
$news['content'] = preg_replace($patterns, $replaces, $news['content']);
$news['content'] = Lib_Utils_StringHelper::stripTags($news['content']);
$data['content'] = preg_replace("/([\n]{2,})/","\n", $news['content']);
$data['content'] = htmlspecialchars_decode($data['content']);
$data['brief'] = Lib_Utils_StringHelper::substr_cn(Lib_Utils_StringHelper::stripTags($news['content']), 95);
$data['url'] = SITE_MAIN.'/news/detail/id/'.$id;
if(!empty($videoMatches[2]))
{
$data['video'] = current($videoMatches[2]);
}
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取品牌列表页
*
* @return json
*/
public function getBrandListAction()
{
list($offset, $limit) = $this->getMobileLimit();
$isLike = $this->_request->query('isLike', 0);
$state = 1;
$limit = 500;
$brands = Facade_Brand::getBrandByState($offset, $limit, $state);
$data = array('total'=> '0', 'list'=> array(),
'boothMapImage3F' => SITE_RES.'/images/yohood/yohood3F-app.jpg',
'boothMapImage4F' => SITE_RES.'/images/yohood/yohood4F-3.jpg',
'boothMapImage' => SITE_RES.'/images/yohood/yohood4F-3.jpg',
);
$data['total'] = Facade_Brand::getBrandTotal($state);
$boothList = Facade_Brand::getBoothList();
$yohobuyBrands = Facade_Brand::getYohobuyBrand();
$signBrands = Facade_Brand::getSignBrand();
$boothListPositions = array();
foreach($boothList as $booth)
{
$boothListPositions[$booth['booth_id']] = $booth['position'];
}
foreach($brands as $brand)
{
$boothPositions = array();
$styles = json_decode($brand['pics'], true);
$image = '';
$video = '';
foreach($styles as $style)
{
if($style['type'] == 'pic')
{
$image = Lib_Images::getImageUrl($style['url'], 'source','fragmentimg');
}
else
{
$video = Lib_Video::getVideoUrl($style['url']);
}
}
$brand['name'] = trim($brand['name']);
$yohobuyBrandId = "0";
//店铺没有数据的品牌ID
$shopNoBrandIIds = array(18,55,56,77,111,112,134,147,160,188,240,243,245,253,264,270,
290,294,299,309,333,403,404,405,427,485,497,508,514,515,546,582,595,602,603,605,608,609,610,612,613,614,615,616,617,618,
619,620,621,622,623);
//切换为有货品牌ID
foreach($signBrands as $signBrand)
{
$signBrand['brand_name'] = trim(strtolower($signBrand['brand_name']));
if(strtolower($brand['name']) == $signBrand['brand_name'])
{
$yohobuyBrandId = $signBrand['brand_id'];
break;
}
}
if(empty($yohobuyBrandId))
{
foreach($yohobuyBrands as $yohobuyBrand)
{
$yohobuyBrand['brand_name'] = trim(strtolower($yohobuyBrand['brand_name']));
if(strtolower($brand['name']) == $yohobuyBrand['brand_name'])
{
$yohobuyBrandId = $yohobuyBrand['brand_id'];
break;
}
}
}
$url = SITE_MAIN.'/brand/detail/id/'.$brand['id'];
if($isLike && empty($yohobuyBrandId)) //最喜欢的品牌
{
$yohobuyBrandId = $brand['id'];
}
if(empty($isLike))
{
if(array_search($yohobuyBrandId, $shopNoBrandIIds) !== false)
{
$yohobuyBrandId = '0';
}
}
$brand['id'] = $yohobuyBrandId;
$index = Lib_Utils_StringHelper::getFirstLetter($brand['name']);
if(empty($index))
{
$index = substr($brand['name'], 0, 1);
}
$index = strtoupper($index);
if(is_numeric($index))
{
$index = '0-9';
}
$boothIds = explode(',', $brand['booth_id']);
$booths = array();
foreach($boothIds as $boothId)
{
if(empty($boothId))
{
continue;
}
$x = 0;
$y = 0;
if(isset( $boothListPositions[$boothId]))
{
$position = explode('|', $boothListPositions[$boothId]);
$x = $position[0];
$y = $position[1];
}
$booths[] = array('id' => $boothId, 'x'=> strval($x / 4000.0), 'y' => strval($y / 1567.0) );
}
$data['list'][$index][] = array(
'id' => $brand['id'], 'name' => $brand['name'],
'booths' => $booths,
'boothId'=> $brand['booth_id'],
'logo' => Lib_Images::getImageUrl($brand['logo'], 'source','fragmentimg'),
'image' => $image,
'video'=> $video,
'description'=> $brand['description'],
'brief' => Lib_Utils_StringHelper::substr_cn($brand['description'], 95),
'url' => $url,
);
}
ksort($data['list']);
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取限量推荐商品
*
* @return json
*/
public function recomProductListAction()
{
list($offset, $limit) = $this->getMobileLimit();
$data = array('total'=>'0', 'list'=> array());
$state = 1;
$data['total'] = Facade_Prod::getProdTotal($state);
$products = Facade_Prod::getProd($state, $offset, $limit);
foreach($products as $product)
{
$images = explode('|', $product['pic']);
$data['list'][] = array(
'id' => $product['product_id'],
'brandId' => $product['brand_id'],
'price' => $product['price'], 'url'=> $product['url'],
'name'=> $product['name'], 'image'=> $images[0],
'skn' =>$product['product_skn'],
);
}
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取活动计划
*
* @return json
*/
public function getActivityPlanListAction()
{
$planList = Facade_Activity::getActivityPlan();
$data = array();
$serverTime = time();
foreach($planList as $plan)
{
$data[] = array('id' => $plan['id'], 'title' => $plan['title'],
'content'=> $plan['content'],'place'=> $plan['place'],
'startTime' => $plan['start_time'], 'endTime' => $plan['end_time'],
'image' => Lib_Images::getImageUrl($plan['pic'],'source','fragmentimg'),
'serverTime' => $serverTime,
'url' => SITE_MAIN.'/activity/plan',
);
}
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取活动介绍
*
* @return json
*/
public function getActivityIntroduceAction()
{
$data = array(
'image'=> SITE_RES.'/images/yohood/activity_banner.jpg',
'address'=>'上海世贸商城',
'anavLatitude'=>'31.201374',//高德维度
'anavLongitude'=>'121.401041', //高德经度
'list' => array(
array('id'=> '1', 'title'=>'活动介绍','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('活动介绍客户端')),
array('id'=> '2', 'title'=>'购物流程','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('购物流程客户端')),
// array('id'=> '3', 'title'=>'现场购票流程','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('现场购票流程客户端')),
// array('id'=> '4', 'title'=>'线上购票流程','url'=> SITE_MAIN.'/activity/introduce/title/'.rawurlencode('线上购票流程客户端')),
array('id'=> '5', 'title'=>'Q&A','url'=> SITE_MAIN.'/activity/qa'),
)
);
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 合作伙伴
*
* @return json
*/
public function getPartnerListAction()
{
$partnerList = Facade_Partner::getPartner();
$data = array();
foreach($partnerList as $partner)
{
$data[] = array(
'id'=> $partner['id'],
'title' =>$partner['name'],
'logo'=> Lib_Images::getImageUrl($partner['pic'], 'source','fragmentimg'),
'image' => Lib_Images::getImageUrl($partner['pic'], 'source','fragmentimg'),
'description' => $partner['description'],
'createTime' => $partner['create_time']
);
}
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取booth签到列表
*
* @return json
*/
public function getBoothSignListAction()
{
$data = array_values(Facade_Brand::getSignLayout());
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
/**
* 获取壁纸
*
* @return json
*/
public function getWallpaperListAction()
{
$screenWidth = intval($this->_request->query('screenWidth', '640'));
$screenHeight = intval($this->_request->query('screenHeight', '960'));
$data = array('cover'=> SITE_IMG.'/yohood/wallpaper/cover.jpg', 'list'=> array(), 'url' => SITE_MAIN.'/default/wallpaper');
$dir = SITE_IMG.'/yohood/wallpaper';
if($screenWidth >=1440 && $screenHeight>=1200)
{
$dir.='/1440x1200/';
}
else if($screenWidth >=640 && $screenHeight>=1136)
{
$dir.='/640x1136/';
}
else
{
$dir.='/640x960/';
}
for($i = 1; $i<=11; $i++)
{
$data['list'][] = $dir.$i.'.jpg';
}
return $this->returnJson(self::SUCCESS_STATUS_CODE, Config_Code_Mobile::$success_opt['code'], $data, Config_Code_Mobile::$success_opt['message']);
}
}