Mobileapi.class.php
11.6 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
<?php
/**
* 手机客户端API接口
*/
class Controller_MobileApi extends Controller_Abstract
{
/**
* 获取客户端模块
*
* @return json
*/
public function getMobileModuleListAction()
{
$modules = Facade_Mobile::getModule();
$data = array();
foreach($modules as $module)
{
$headCover = '';
$url = '';
if($module['id'] == 1)
{
$headCover = SITE_IMG.'/yohood/yohood-logo-mobile_v3.png';
}
if(!empty($module['url']))
{
if(preg_match('@^http://@', $module['url']))
{
$url = $module['url'];
}
else
{
$url = SITE_MAIN.$module['url'];
}
}
$data [] = array('id'=> $module['id'],
'status'=> $module['status'],
'moduleName' => $module['module_name'],
'headCover' => $headCover,
'url' => $url,
);
}
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(),
'boothMapImage1F' => SITE_RES.'/images/yohood/yohood1F.jpg',
'boothMapImage4F' => SITE_RES.'/images/yohood/yohood4F.jpg',
);
$boothList = Facade_Brand::getBoothList();
$data['total'] = count($boothList);
$yohobuyBrands = Facade_Brand::getYohobuyBrand();
$signBrands = Facade_Brand::getSignBrand();
foreach($boothList as $booth)
{
$index = Lib_Utils_StringHelper::getFirstLetter($booth['brand_name']);
if(empty($index))
{
$index = substr($booth['brand_name'], 0, 1);
}
$index = strtoupper($index);
if(is_numeric($index))
{
$index = '0-9';
}
$x = $y = 0;
if($booth['floor'] == 1)
{
$x = strval(intval($booth['x']) / 3802.0);
$y = strval(intval($booth['y']) / 2019.0);
}
else if($booth['floor'] == 4)
{
$x = strval(intval($booth['x']) / 3775.0);
$y = strval(intval($booth['y']) / 2104.0);
}
$yohobuyBrandId = '0';
foreach($yohobuyBrands as $yohobuyBrand)
{
if(strtolower($yohobuyBrand['brand_name']) == strtolower($booth['brand_name']))
{
$yohobuyBrandId = $yohobuyBrand['brand_id'];
break;
}
}
$url = '';
foreach($brands as $brand)
{
if(strtolower($brand['name']) == strtolower($booth['brand_name']))
{
$url = SITE_MAIN.'/brand/detail/id/'.$brand['id'];
break;
}
}
$data['list'][$index][] = array(
'id' => $yohobuyBrandId,
'name' => $booth['brand_name'],
'booths' => array('id' => $booth['booth_id'], 'x'=> $x, 'y' => $y ),
'boothId'=> $booth['booth_id'],
'url' => $url,
'floor'=> $booth['floor']
);
}
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']);
}
}