CouponFloorProcess.php 3.34 KB
<?php
/**
 * Created by PhpStorm.
 * User: Targaryen
 * Date: 2016/4/15
 * Time: 13:17
 */

namespace Plugin\DataProcess;


use Plugin\Images;

class CouponFloorProcess
{

    /**
     * 获取楼层数据
     *
     * @param $data
     * @return array
     */
    public static function getContent($data)
    {
        $result = array();

        if (empty($data)) {
            return array();
        }

        $build = array();
        foreach ($data as $k => &$v) {
            if (empty($v) || !is_array($v) || !array_key_exists('template_name', $v)) {
                continue;
            }
            $fun = $v['template_name'];
            if (empty($v['data']) || !is_callable("self::$fun")) {
                continue;
            }
            // tar note 处理楼层标题
            if ($fun === 'getCoupon' && $data[$k - 1]['template_name'] === 'text') {
                $v['data']['floorTitle'] = $data[$k - 1]['data'];
            }
            $build = self::$fun($v['data']);
            if (empty($build)) {
                continue;
            }
            $result[] = $build;
        }
        $build = array();
        return $result;
    }

    /**
     * 焦点图处理
     *
     * @param $data
     * @return mixed
     */
    private static function carousel_banner($data)
    {
        if (empty($data['list'])) {
            return array();
        }
        foreach ($data['list'] as &$item) {
            $imageSrc = Images::getImageUrl($item['src'], 0, 0);
            $item['src'] = $imageSrc;
        }
        $data['isCarouselBanner'] = true;
        return $data;
    }

    /**
     *
     * 领券楼层数据处理
     *
     * @param $data
     * @return array
     * @internal param $type
     */
    private static function getCoupon($data)
    {
        $result = array();
        if (empty($data)) {
            return array();
        }
        $floorTitle = '';
        foreach ($data as $key => &$item) {
            if ($key === 'floorTitle') {
                $floorTitle = (key_exists('text', $item) && ($item['text'] !== '')) ? $item['text'] : '';
                continue;
            }
            $imageSrc = Images::getImageUrl($item['image']['src'], 0, 0);
            $item['image']['src'] = $imageSrc;
            switch ($item['status']) {
                case 1:
                    $item['isGet'] = true;
                    break;
                case 2:
                    $item['isZero'] = true;
                    break;
                case 3:
                    $item['isGeted'] = true;
                    break;
                default:
                    break;
            }
        }
        if ($floorTitle !== '') {
            $data[0]['floorTitle'] = $floorTitle;
            $data[0]['showFloorTitle'] = true;
        }
        $result = $data[0];
        $result['isCoupon'] = true;
        return $result;
    }

    /**
     * 处理标题数据
     *
     * @param $data
     * @return bool
     */
    private static function text($data)
    {
        $data['isTitle'] = true;
        if ($data['text']) {
            $data['isShow'] = true;
        }
        return $data;
    }

    /**
     *
     * 单张图片的处理方法,不用
     *
     * @param $data
     * @return mixed
     */
    private static function single_image($data)
    {
        $data['isSingleImage'] = true;
        return $data;
    }
}