ShopProcess.php
14.4 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
<?php
namespace Plugin\DataProcess;
use LibModels\Wap\Product\SearchData;
use Plugin\Helpers;
use Plugin\Images;
use LibModels\Wap\Product\DetailData;
/**
* 店铺楼层数据处理类
*/
class ShopProcess
{
private static $shopData = array();
private static $shopId = 0;
private static $appVersion = 0;
//店铺品牌
private static $brandId;
//单品店
private static $single = false;
private static $channel;
/**
* 修改资源位的链接
* @param $val
* @param $shopId
* @return string
*/
private static function modifyWapUrl($val, $shopId)
{
if (isset($val['linkType']) && $val['linkType'] == 1) {
return Helpers::url('', array('filter_poolId' => $val['categoryId'],
'title' => $val['categoryName']), 'search');
} else {
if (isset($val['url'])) {
return $val['url'];
} else {
return '';
}
}
}
/**
* 修改资源位的链接
* @param $val
* @param $shopId
* @return string
*/
private static function modifyAppUrl($val, $shopId)
{
if (isset($val['linkType']) && $val['linkType'] == 1) {
return Helpers::url('/search/list') . sprintf('?openby:yohobuy={"action":"go.poollist","params":{"shop_id":"%s","title":"%s","productPool":"%s"}}',
$shopId . '', $val['categoryName'] . '', $val['categoryId'] . '', '');
} else {
if (isset($val['url'])) {
return $val['url'];
} else {
return '';
}
}
}
/**
* 组织店铺页面数据
* @param array $data 接口返回的店铺页所需数据
* @param int $shopId 店铺id
* @param int $appVersion app版本
* @param $channel //tar add 160820
* @return array
* @author sefon 2016-4-26 21:56:32
*/
public static function formShopData($data, $shopId, $appVersion, $channel)
{
self::$channel = $channel; // tar add 160820
self::$shopData['shopId'] = self::$shopId = $shopId;
self::$shopData['appVersion'] = self::$appVersion = $appVersion;
foreach ($data as $key => $val) {
if (empty($val) || !is_callable("self::$key")) {
continue;
}
self::$key($val, $shopId, $appVersion);
}
if (self::$single) {
self::$shopData['favId'] = self::$shopData['shopId'];
// self::$shopData['shopId'] = ''; // tar modified 160830 从店铺搜索都需要 shopId
}
return self::$shopData;
}
/**
* 店铺基本信息
* @param $data
* @author sefon 2016-4-29 01:48:50
*/
private static function shopInfo($data)
{
self::$shopData['logoImg'] = Images::getImageUrl($data['shop_logo'], 500, 500, 'shopLogo');
self::$shopData['storeName'] = $data['is_show_shop_name'] == 'Y' ? $data['shop_name'] : '';
//用户是否收藏店铺
self::$shopData['collect'] = $data['is_favorite'] == 'Y' ? true : false;
//全部商品链接
$allGoodsParam['title'] = '全部商品';
//单品店
if (self::$single) {
$allGoodsParam['brand'] = self::$brandId;
} else {
//店铺id
self::$shopData['shopId'] = self::$shopId;
$allGoodsParam['shop_id'] = self::$shopId;
}
if (empty(self::$appVersion)) {
self::$shopData['allGoods'] = Helpers::url('', $allGoodsParam, 'search');
//店铺简介页地址
self::$shopData['shopIntroHref'] = Helpers::url('/product/index/intro', array('shop_id' => self::$shopId));
} else {
self::$shopData['allGoods'] = Helpers::url('', $allGoodsParam, 'search') . '&openby:yohobuy={"action":"go.list","params":{"title":"全部商品", "actiontype":"0","shop_id":"' . self::$shopId . '","page":"1"}}';
self::$shopData['shopIntroHref'] = Helpers::url('/product/index/intro', array('shop_id' => self::$shopId, 'app_version' => self::$appVersion));
}
//搜索链接
self::$shopData['url'] = Helpers::url('/index/search/searchShop', array('shop_id' => self::$shopId));
//人气单品的链接
self::$shopData['more_url'] = Helpers::url('', array('shop_id' => self::$shopId, 'order' => 's_n_d', 'title' => '人气单品',), 'search');
if (self::$appVersion) {
self::$shopData['more_url'] = 'openby:yohobuy={"action":"go.list","params":{"shop_id":"' . self::$shopId . '","title":"人气单品"}}';
}
}
/**
* 组织店铺装修
* @param array $data
* @author sefon 2016-4-26 22:04:04
*/
private static function decorator($data, $shopId, $appVersion)
{
if (!isset($data['list']) || empty($data['list'])) {
return;
}
if (empty($appVersion)) {
$modifyUrl = function ($item, $shopid) {
return self::modifyWapUrl($item, $shopid);
};
} else {
$modifyUrl = function ($item, $shopid) {
return self::modifyAppUrl($item, $shopid);
};
}
foreach ($data['list'] as $val) {
if (empty($val['resource_data']) || !is_callable("self::$val[resource_name]")) {
continue;
}
$json = json_decode($val['resource_data'], true);
foreach ($json as &$val2) {
$url = $modifyUrl($val2, $shopId);
if (!empty($url)) {
$val2['url'] = $url;
}
if (isset($val2['data']) && is_array($val2['data'])) {
foreach ($val2['data'] as &$v) {
$url2 = $modifyUrl($v, $shopId);
if (!empty($url2)) {
$v['url'] = $url2;
}
}
}
if (!isset($val2['data']) && is_array($val2)) {
foreach ($val2 as $k1 => &$v1) {
$url3 = $modifyUrl($v1, $shopId);
if (!empty($url3)) {
$v1['url'] = $url3;
}
}
}
}
self::$val['resource_name']($json);
}
}
/**
* 店铺Banner
* @param array $data
* @author sefon 2016-4-27 08:40:05
*/
private static function shopTopBanner_APP($data)
{
self::$shopData['branerImg'] = Images::getResizeImagesUrl($data[0]['shopSrc'], 640, 200, 1);
}
/**
* 资源位小图 接口返回两组,取每组第一张
* @param array $data
* @author sefon 2016-4-27 08:37:30
*/
private static function oneRowTwoColImages_APP($data)
{
foreach ($data as $key => $val) {
if (empty($val['data'])) {
continue;
}
self::$shopData['spring'][$key] = array(
'url' => $val['data'][0]['url'],
'springType' => str_replace('http:', '', $val['data'][0]['src']) . '?imageView/2/format/jpg/w/275/h/160/q/80'
);
}
}
/**
* 店铺品牌一览
* @param array $data
* @author sefon 2016-4-26 22:04:04
* @return array
*/
private static function brandBrowse($data)
{
$brandId = '';
$brandNumber = count($data);
//少于2个不展示 单品店:单品店根据品牌id查询
if ($brandNumber < 2) {
self::$brandId = self::$shopData['brand'] = $data[0]['id'];
self::$single = true;
return;
}
foreach ($data as $val) {
if (empty($val['brandDomain'])) {
continue;
}
$brandId .= $val['id'] . ',';
// tar modified 1606031153 跳转当前店铺下的这个品牌的商品列表
$appSuffix = 'openby:yohobuy={"action":"go.brand","params":{"shop_id":"' . self::$shopId . '","brand_id":"' . $val['id'] . '"}}';
// $appSuffix = 'openby:yohobuy={"action":"go.list","params":{"shop_id":"' . self::$shopId . '","brand":"' . $val['id'] . '","title":"' . $val['brandName'] . '"}}';
$brand['url'] = Helpers::url('', '', $val['brandDomain']);
// $brand['url'] = Helpers::url('', array('shop_id' => self::$shopId, 'brand' => $val['id'], 'title' => $val['brandName']), 'list');
if (!empty(self::$appVersion)) {
$brand['url'] .= '?' . $appSuffix;
}
$brand['img'] = Images::getImageUrl($val['brandIco'], 640, 400);
$brand['brandName'] = $val['brandName'];
self::$shopData['brandList']['list'][] = $brand;
}
//大于5个返回更多品牌链接
if ($brandNumber > 5) {
self::$shopData['brandList']['url'] = Helpers::url('/product/index/allBrand', array('shop_id' => self::$shopId));
}
}
/**
* 资源位大图幻灯
* @param $data
* @author sefon 2016-4-27 16:50:01
*/
private static function largeSlideImg_APP($data)
{
foreach ($data as $slide) {
if (empty($slide['data'][0])) {
continue;
}
self::$shopData['bannerTop']['list'][] = array('url' => $slide['data'][0]['url'], 'img' => str_replace('http:', '', $slide['data'][0]['src']) . '?imageView/2/format/jpg/w/640/h/310/q/80');
}
}
/**
* 热门品类
* @param array $data
* @author sefon 2016-4-27 08:38:36
* @return array
*/
private static function recommend_APP($data)
{
// tar modified 160824 热门分类有数据才显示
if (!empty($data)) {
self::$shopData['hotCategory']['name'] = '热门品类';
foreach ($data as $cate) {
self::$shopData['hotCategory']['list'][] = array(
'url' => $cate['url'],
'img' => str_replace('http:', '', $cate['src']) . '?imageView/2/w/160/h/160/q/80',
'name' => $cate['name'] // tar add 160824 热门分类的名称
);
}
}
}
/**
* 人气单品
* @param array $data
* @author sefon 2016-4-27 08:38:36
*/
private static function hotProducts_APP($data)
{
$condition['query'] = '';
foreach ($data as $val) {
$condition['query'] .= $val['productSkn'] . ',';
}
/* tar modified 160826 根据资源位接口返回的 skn 去查数据,查到后取商品数据,查不到取资源位接口数据 */
$hotProducts = SearchData::searchBySkn($condition);
if (isset($hotProducts['code']) && $hotProducts['code'] === 200 && isset($hotProducts['data']['product_list'])) {
foreach ($hotProducts['data']['product_list'] as $val) {
/* 取第一个设为默认商品 goods */
$defaultGoods = $val['goods_list'][0];
/* 判断是否设置了默认 goods,如果设置了就重新赋值 */
foreach ($val['goods_list'] as $key => $goods) {
if ($goods['is_default'] === 'Y') {
$defaultGoods = $goods;
}
}
$goodsCover = $val['goods_list'][0]['images_url'];
if (self::$channel == 1) {
$goodsCover = empty($defaultGoods['cover_1']) ? $defaultGoods['images_url'] : $defaultGoods['cover_1'];
}
if (self::$channel == 2) {
$goodsCover = empty($defaultGoods['cover_2']) ? $defaultGoods['images_url'] : $defaultGoods['cover_2'];
}
/* 如果还是没取到,取 product 默认图片 */
if (empty($goodsCover)) {
$goodsCover = $val['default_images'];
}
$goods = array(
'url' => Helpers::getUrlBySkc($val['product_id'], $val['goods_list'][0]['goods_id'], $val['cn_alphabet']),
'img' => Helpers::getImageUrl($goodsCover, 235, 314),
'productName' => $val['product_name'],
'salesPrice' => '¥' . $val['sales_price'],
'presentPrice' => '¥' . $val['sales_price']
);
if (!empty(self::$appVersion)) {
$goods['url'] .= '?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' . $val['product_skn'] . '}}';
}
self::$shopData['hotList'][] = $goods;
}
} else {
$productSkn = array();
foreach ($data as $val) {
$productSkn[] = $val['productSkn'];
}
$product = DetailData::productBatch($productSkn);
if ($product['code'] === 200 && isset($product['data']['product_list'])) {
foreach ($product['data']['product_list'] as $key => $value) {
$goods = Helpers::formatProduct($value, false, false, false, 235, 314, self::$appVersion);
//店铺人气商品不须要其它标签、即将售罄
$goods['tags'] = array();
$goods['is_soon_sold_out'] = false;
$goods['tags']['is_hot'] = true;
self::$shopData['hotList'][] = $goods;
}
}
}
}
/**
* 店铺下面的所有分类
* @author sefon 2016-4-27 21:40:28
*/
private static function shopCategory($data)
{
if (isset($data['code']) && $data['code'] == 200 && !empty($data['data'])) {
$total = count($data['data']);
if ($total > 6) {
self::$shopData['shopCategory']['url'] = Helpers::url('/product/index/category', array('shop_id' => self::$shopId));
return;
}
foreach ($data['data'] as $key => $val) {
self::$shopData['shopCategory']['list'][] = array(
// 'url' => Helpers::url('', array('shop_id' => self::$shopId, 'brand' => self::$brandId, 'sort' => $val['relation_parameter']['sort']), 'search'),
'url' => Helpers::url('', array('shop_id' => self::$shopId, 'sort' => $val['relation_parameter']['sort']), 'search'),
'categoryId' => $val['category_id'],
'name' => $val['category_name']
);
}
}
}
}