Blame view

library/Plugin/DataProcess/FloorProcess.php 15 KB
Rock Zhang authored
1 2
<?php
3
namespace Plugin\DataProcess;
4
5
use Plugin\Helpers;
Rock Zhang authored
6 7 8 9 10 11

/**
 * 楼层数据处理类
 */
class FloorProcess
{
12
Rock Zhang authored
13
    /**
14
     * 频道参数
15 16
     *
     * @var array
17 18 19 20 21 22 23
     */
    private static $channel = array(
        '1' => '1,3',
        '2' => '2,3'
    );

    /**
24 25 26 27 28 29
     * 处理首页内容
     * @param $data
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
     */
    public static function getContent($data, $type = 1)
    {
30 31 32 33
        if (empty($data['list'])) {
            return array();
        }
34
        $result = array();
35 36 37

        $build = array();
        foreach ($data['list'] as $v) {
38 39 40
            if (empty($v)) {
                continue;
            }
41
42 43 44 45 46 47 48
            $fun = $v['template_name'];
            if (empty($v['data']) || !is_callable("self::$fun")) {
                continue;
            }
            $build = self::$fun($v['data'], $type);
            if (empty($build)) {
                continue;
49
            }
50
            $result[] = $build;
51
        }
52 53
        $build = array();
54 55 56 57
        return $result;
    }

    /**
Rock Zhang authored
58 59
     * 焦点图数据处理方法
     * @param  array $data 焦点图数据
60
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
61 62
     * @return array       处理之后的焦点图数据
     */
63
    private static function focus($data, $type)
Rock Zhang authored
64 65 66
    {
        $result = array();
67 68
        foreach ($data as $one) {
            $result['bannerTop']['list'][] = Helpers::formatBanner($one, 640, 240);
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
        }

        return $result;
    }

    /**
     * 图标
     */
    private static function floor($data)
    {
        $result = array();

        foreach ($data as &$one) {
            $one['url'] = Helpers::getFilterUrl($one['url']);
            $one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
84
            unset($one['src']);
Rock Zhang authored
85
        }
86
        $result['iconsEnter']['list'] = $data;
Rock Zhang authored
87
88
        return $result;
Rock Zhang authored
89 90 91 92
    }

    /**
     * 图标列表数据处理方法
93
     *
Rock Zhang authored
94
     * @param  array $data 图标列表数据
95
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
96 97
     * @return array       处理之后的图标列表数据
     */
98
    private static function app_icon_list($data, $type)
Rock Zhang authored
99 100 101 102
    {
        $result = array();

        foreach ($data as &$one) {
103 104
            $one['url'] = Helpers::getFilterUrl($one['url']);
            $one['img'] = Helpers::getImageUrl($one['src'], 98, 98);
105
            unset($one['src']);
Rock Zhang authored
106
        }
107
        $result['iconsEnter']['list'] = $data;
Rock Zhang authored
108
109
        return $result;
Rock Zhang authored
110 111 112
    }

    /**
113
     * 单广告图片数据处理方法
114
     *
Rock Zhang authored
115
     * @param  array $data 单图片数据
116
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
117 118
     * @return array       处理之后的单图片数据
     */
119
    private static function single_image($data, $type)
Rock Zhang authored
120
    {
121 122
        $result = array();
Rock Zhang authored
123
        foreach ($data as &$one) {
124 125
            $one['url'] = Helpers::getFilterUrl($one['url']);
            $one['img'] = Helpers::getImageUrl($one['src'], 640, 200);
126
            unset($one['src']);
Rock Zhang authored
127
        }
128 129 130 131 132 133 134
        $result['banner'] = $data;

        return $result;
    }

    /**
     * 女生品类
135
     * 推荐(1T-12F)
136 137 138 139 140 141 142
     */
    private static function recommend_content_three($data, $type)
    {
        $result = array();

        $build = array();
        if (!empty($data['big_image'][0])) {
143
            $build['img'] = Helpers::getImageUrl($data['big_image'][0]['src'], 640, 200);
144 145 146 147 148 149 150
            $build['url'] = Helpers::getFilterUrl($data['big_image'][0]['url']);
            $result['hotCategory']['banner'] = $build;
        }

        $build = array();
        foreach ($data['list'] as $one) {
            $build['url'] = Helpers::getFilterUrl($one['url']);
151
            $build['img'] = Helpers::getImageUrl($one['src'], 128, 140);
152 153 154
            $build['textCn'] = $one['title'];
            $result['hotCategory']['list'][] = $build;
        }
hf authored
155
hf authored
156 157 158
        if (isset($data['title']['more_url'])) {
            $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
        }
Rock Zhang authored
159
160
        return $result;
Rock Zhang authored
161 162 163 164
    }

    /**
     * 带标题的12个小图推荐数据处理方法
165
     *
Rock Zhang authored
166
     * @param  array $data 带标题的12个小图推荐数据
167
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
168 169
     * @return array       处理之后的带标题的12个小图推荐数据
     */
170
    private static function recommend_content_five($data, $type)
Rock Zhang authored
171 172 173 174
    {
        $result = array();

        foreach ($data['list'] as &$one) {
175 176 177 178 179
            if (isset($one['url'])) {
                $one['url'] = Helpers::getFilterUrl($one['url']);
            }
            $one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
            $one['textCn'] = $one['title'];
Rock Zhang authored
180 181
            unset($one['src']);
        }
182 183 184
        $data['is_show_name'] = $data['title']['is_show'];
        $data['name'] = $data['title']['title'];
        unset($data['title']);
hf authored
185 186

        if (isset($data['title']['more_url'])) {
hf authored
187 188
            $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
        }
Rock Zhang authored
189
190 191 192
        $result['hotCategory'] = $data;

        return $result;
Rock Zhang authored
193 194 195 196 197
    }

    /**
     * 推荐品牌数据处理方法
     * @param  array $data 推荐品牌数据
198
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
199 200
     * @return array       处理之后的推荐品牌数据
     */
201
    private static function app_hot_brands($data, $type)
Rock Zhang authored
202 203 204
    {
        $result = array();
205
        $data['is_show_name'] = (isset($data['is_show_name']) && $data['is_show_name'] === 'Y') ? 1 : 0;
Rock Zhang authored
206 207 208
        $data['name'] = $data['title']['title'];
        unset($data['title']);
        foreach ($data['list'] as &$one) {
209
            if (isset($one['url'])) {
210
                $one['url'] = Helpers::getFilterUrl($one['url']);
211
//                isset(self::$channel[$type]) && $one['url'] .= '?gender=' . self::$channel[$type];
212 213
            }
            $one['img'] = Helpers::getImageUrl($one['src'], 158, 174);
Rock Zhang authored
214 215
            unset($one['src']);
        }
hf authored
216
        $data['more'] = '/brands?channel=' . $type;
217
        $result['hotBrands'] = $data;
Rock Zhang authored
218
219
        return $result;
Rock Zhang authored
220 221 222 223 224
    }

    /**
     * 潮人·搭配数据处理方法
     * @param  array $data 潮人·搭配数据
225
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
226 227
     * @return array       处理之后的潮人·搭配数据
     */
228
    private static function trendsetter_collocation($data, $type)
Rock Zhang authored
229 230 231
    {
        $result = array();
hf authored
232 233
        foreach ($data as $key => &$value) {
            if ($key == 'title') {
234
                $value['more_url'] = Helpers::url('', array('id' => 3, 'gender' => self::$channel[$type]), 'guang');
235
            }
hf authored
236 237
            if ($key == 'article') {
                foreach ($value as &$one) {
238 239 240 241 242 243 244
                    if (isset($one['url'])) {
                        $one['url'] = Helpers::getFilterUrl($one['url']);
                    }
                    $one['img'] = Helpers::getImageUrl($one['src'], 400, 400);
                    unset($one['src']);
                }
            }
hf authored
245 246
            if ($key == 'recommend_collocation') {
                foreach ($value as &$one) {
247 248 249 250 251 252
                    if (isset($one['url'])) {
                        $one['url'] = Helpers::getFilterUrl($one['url']);
                    }
                    $one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
                    unset($one['src']);
                }
253
            }
Rock Zhang authored
254
        }
255
        $result['trendColloaction'] = $data;
Rock Zhang authored
256
257
        return $result;
Rock Zhang authored
258 259 260 261 262
    }

    /**
     * 潮品·话题数据处理方法
     * @param  array $data 潮品·话题数据
263
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
264 265
     * @return array       处理之后的潮品·话题数据
     */
266
    private static function trendgoods_topic($data, $type)
Rock Zhang authored
267 268 269
    {
        $result = array();
hf authored
270 271
        foreach ($data as $key => &$value) {
            if ($key == 'title') {
272 273
           $urlParam = array('id' => 4);
           //isset(self::$channel[$type]) && $urlParam['gender'] = self::$channel[$type];
274
                $value['more_url'] = Helpers::url('', $urlParam, 'guang');
275
            }
276
            if ($key == 'list' && is_array($value)) {
277 278 279 280 281 282 283
                foreach ($value as &$one) {
                    if (isset($one['url'])) {
                        $one['url'] = Helpers::getFilterUrl($one['url']);
                    }
                    $one['img'] = Helpers::getImageUrl($one['src'], 580, 360);
                    unset($one['src']);
                }
284
            }
Rock Zhang authored
285
        }
286
        $result['trendTopics'] = $data;
Rock Zhang authored
287
288
        return $result;
Rock Zhang authored
289 290 291 292 293
    }

    /**
     * 一张大图一个大的推荐和4个小图推荐数据处理方法
     * @param  array $data 一张大图一个大的推荐和4个小图推荐数据
294
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
295 296
     * @return array       处理之后的一张大图一个大的推荐和4个小图推荐数据
     */
297
    private static function recommend_content_one($data, $type)
Rock Zhang authored
298 299 300 301
    {
        $result = array();

        foreach ($data['big_image'] as &$one) {
302 303 304 305
            if (isset($one['url'])) {
                $one['url'] = Helpers::getFilterUrl($one['url']);
            }
            $one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
Rock Zhang authored
306 307
            unset($one['src']);
        }
308
309 310 311 312 313
        // 区别多张图与一张图
        if (count($data['big_image']) > 1) {
            $result['big_image']['big_list'] = $data['big_image'];
            unset($data['big_image']);
        }
314
315 316 317 318 319 320 321 322 323 324 325
        foreach ($data['list'] as $kk => &$one) {
            if ($kk == 0) {
                $one['img'] = Helpers::getImageUrl($one['src'], 253, 383);
            } else {
                $one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
            }
            if (isset($one['url'])) {
                $one['url'] = Helpers::getFilterUrl($one['url']);
            }
            $one['textCn'] = $one['title'];
Rock Zhang authored
326 327
            unset($one['src']);
        }
hf authored
328 329

        if (isset($data['title']['more_url'])) {
hf authored
330 331
            $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
        }
Rock Zhang authored
332
333 334 335
        $result['goodsCategory'] = $data;

        return $result;
Rock Zhang authored
336 337 338 339 340
    }

    /**
     * 一张大图和6个小图推荐数据处理方法
     * @param  array $data 一张大图和6个小图推荐数据
341
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
342 343
     * @return array       处理之后的一张大图和6个小图推荐数据
     */
344
    private static function recommend_content_two($data, $type)
Rock Zhang authored
345 346 347 348
    {
        $result = array();

        foreach ($data['big_image'] as &$one) {
349 350 351
            if (isset($one['url'])) {
                $one['url'] = Helpers::getFilterUrl($one['url']);
            }
352
            $one['img'] = Helpers::getImageUrl($one['src'], 640, 403);
Rock Zhang authored
353 354
            unset($one['src']);
        }
355
        $data['banner'] = $data['big_image'];
356 357
        unset($data['big_image']);
Rock Zhang authored
358
        foreach ($data['list'] as &$one) {
359 360 361
            if (isset($one['url'])) {
                $one['url'] = Helpers::getFilterUrl($one['url']);
            }
362
            $one['img'] = Helpers::getImageUrl($one['src'], 191, 191);
Rock Zhang authored
363 364
            unset($one['src']);
        }
hf authored
365 366

        if (isset($data['title']['more_url'])) {
hf authored
367 368
            $data['title']['more_url'] = Helpers::getFilterUrl($data['title']['more_url']);
        }
369
        $result['creativeLife'] = $data;
Rock Zhang authored
370
371
        return $result;
Rock Zhang authored
372 373 374 375 376
    }

    /**
     * 小图片数据处理方法
     * @param  array $data 小图片数据
377
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
Rock Zhang authored
378 379
     * @return array       处理之后的小图片数据
     */
380
    private static function small_pic($data, $type)
Rock Zhang authored
381 382 383 384
    {
        $result = array();

        foreach ($data as &$one) {
385 386 387
            if (isset($one['url'])) {
                $one['url'] = Helpers::getFilterUrl($one['url']);
            }
388
            $one['img'] = Helpers::getImageUrl($one['src'], 275, 160);
Rock Zhang authored
389 390
            unset($one['src']);
        }
391 392 393
        if (!empty($data)) {
            $result['smallPic']['list'] = $data;
        }
Rock Zhang authored
394
395
        return $result;
Rock Zhang authored
396
    }
397 398

    /**
399 400 401 402 403
     * plus,star
     * @param  array $data 单名字图片数据
     * @param $type 类型 默认1:男首页 2:女首页  3:kids 4:lifestyle
     * @return array       处理之后的单名字图片数据
     */
404 405 406
    private static function single_name_image($data, $type)
    {
        if (empty($data)) {
407 408
            return array();
        }
hf authored
409
410
        $data['name'] = $data['title'];
411 412 413 414
        $data['img'] = Helpers::getImageUrl($data['src'], 640, 198);
        if (isset($data['url'])) {
            $data['url'] = Helpers::getFilterUrl($data['url']);
        }
415 416

        return array('plusStar' => $data);
417
    }
418
419 420 421 422 423 424 425 426 427 428 429
    /**
     * 自定义品牌
     *
     * @param unknown $data
     * @param mixed $type
     * @return multitype:
     */
    private static function custom_brands($data, $type)
    {
        // URL附加参数
        $param = '';
430
        /*if (isset(self::$channel[$type])) {
431
            $param = '/?gender=' . self::$channel[$type];
432
        }*/
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453

        $result = array();
        $result['hotBrandsScroll']['name'] = $data['title']['title'];
        foreach ($data['list'] as &$one) {
            if (isset($one['url'])) {
                $one['url'] = Helpers::getFilterUrl($one['url']);
            }
            $one['img'] = Helpers::getImageUrl($one['src'], 140, 140);
            $one['textCn'] = $one['name'];
            if (isset($one['url'])) {
                $one['url'] .= $param;
            }
        }
        if (!empty($data['is_show_name']) && $data['is_show_name'] == 'Y') {
            $result['hotBrandsScroll']['is_show_name'] = true;
        }
        $result['hotBrandsScroll']['list'] = $data['list'];

        return $result;
    }
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482
    /**
     * 新人专享
     * @param $data
     * @param $type
     * @author sefon 2016-4-19 11:43:56
     * @return array
     */
    private static function new_user_floor($data, $type)
    {
        $result = array();
        $result['title']['title'] = $data['title']['title'];
        if ($data['title']['more_url']) {
            $result['title']['more_url'] = $data['title']['more_url'];
        }
        $result['big_image']['url'] = $data['banner_image'][0]['url'];
        $result['big_image']['title'] = $data['banner_image'][0]['title'];
        $result['big_image']['img'] = Helpers::getImageUrl($data['banner_image'][0]['src'], 640, 200);
        if (empty($data['list'])) {
            return $result;
        }
        foreach ($data['list'] as $key => $val) {
            $result['list'][$key]['url'] = Helpers::getUrlBySkc($val['product_id'], $val['goods_list'][0]['goods_id'], $val['cn_alphabet']);
            $result['list'][$key]['img'] = helpers::getImageUrl($val['default_images'], 235, 314);
            $result['list'][$key]['title'] = $val['product_name'];
            $result['list'][$key]['salePrice'] = number_format($val['sales_price'], 2);
            $result['list'][$key]['price'] = number_format($val['market_price'], 2);
        }
        return array('freshOnly'=>$result);
    }
483
}