ShopProcess.php 6.45 KB
<?php

namespace Plugin\DataProcess;

use Plugin\Helpers;
use Plugin\Images;

/**
 * 店铺楼层数据处理类
 */
class ShopProcess
{
    private static $shopData = array();
    private static $shopId = 0;
    private static $appVersion = 0;

    /**
     * 组织店铺页面数据
     * @param array $data 接口返回的店铺页所需数据
     * @param int $shopId 店铺id
     * @param int $appVersion app版本
     * @author sefon 2016-4-26 21:56:32
     * @return array
     */
    public static function formShopData($data, $shopId, $appVersion)
    {
        self::$shopId = $shopId;
        self::$appVersion = $appVersion;
        foreach ($data as $key => $val) {
            if (empty($val) || !is_callable("self::$key")) {
                continue;
            }
            self::$key($val);
        }
        return self::$shopData;
    }

    /**
     * 店铺基本信息
     * @param $data
     * @author sefon 2016-4-29 01:48:50
     */
    private static function shopInfo($data)
    {
        self::$shopData['logoImg'] = Images::getImageUrl($data['data']['shop_logo'], 500, 500, 'shopLogo');
        self::$shopData['storeName'] = $data['data']['shop_name'];
        //用户是否收藏店铺
        self::$shopData['collect'] = $data['data']['is_favorite'] == 'Y' ? true : false;
        //店铺id
        self::$shopData['shopId'] = self::$shopId;
        //店铺简介页地址
        self::$shopData['shopIntroHref'] = Helpers::url('/product/index/intro', array('shop_id' => self::$shopId));
        //全部商品链接
        $appSuffix = '{"action":"go.list","params":{"title":"全部商品", "shop_id":"'.self::$shopId.'","page":"1"}}';
        self::$shopData['allGoods'] = Helpers::url('', array('shop_id' => self::$shopId, 'title' => '全部商品', 'yohobuy' => $appSuffix), 'search');
        //搜索链接
        self::$shopData['url'] = Helpers::url('', array('shop_id' => self::$shopId), 'search');
        //人气单品的链接
        self::$shopData['more_url'] = Helpers::url('', array('shop_id' => self::$shopId, 'order' => 's_n_d', 'title' => '人气'), 'search');
    }

    /**
     * 组织店铺装修
     * @param array $data
     * @author sefon 2016-4-26 22:04:04
     */
    private static function decorator($data)
    {
        if (!isset($data['code']) || $data['code'] != 200 || !isset($data['data']['list']) || empty($data['data']['list'])) {
            return;
        }
        foreach ($data['data']['list'] as $val) {
            if (empty($val['resource_data']) || !is_callable("self::$val[resource_name]")) {
                continue;
            }
            self::$val['resource_name'](json_decode($val['resource_data'], true));
        }
    }

    /**
     * 店铺Banner
     * @param array $data
     * @author sefon 2016-4-27 08:40:05
     */
    private static function shopTopBanner_APP($data)
    {
        self::$shopData['branerImg'] = $data[0]['shopSrc'];
    }

    /**
     * 资源位小图 接口返回两组,取每组第一张
     * @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' => $val['data'][0]['src']
            );
        }
    }

    /**
     * 店铺品牌一览
     * @param array $data
     * @author sefon 2016-4-26 22:04:04
     * @return array
     */
    private static function brandBrowse($data)
    {
        $brandNumber = count($data);
        //少于2个不展示
        if ($brandNumber < 2) {
            return;
        }
        foreach ($data as $val) {
            self::$shopData['brandList']['list'][] = array(
                'url' => Helpers::url('', '', $val['brandDomain']),
                'img' => Images::getImageUrl($val['brandIco'], 640, 400),
                'brandName' => $val['brandName']
            );
        }
        //大于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($data)
    {
        if (empty($data[0]['data'])) {
            return;
        }
        foreach ($data[0]['data'] as $slide) {
            self::$shopData['bannerTop']['list'][] = array('url' => $slide['url'], 'img' => $slide['src']);
        }
    }
    /**
     * 热门分类
     * @param array $data
     * @author sefon 2016-4-27 08:38:36
     * @return array
     */
    private static function recommend($data)
    {
        self::$shopData['hotCategory']['name'] = '热门品类';
        foreach ($data as $cate) {
            self::$shopData['hotCategory']['list'][] = array('url' => $cate['url'], 'img' => $cate['src']);
        }
        return $data;
    }

    /**
     * 人气单品
     * @param array $data
     * @author sefon 2016-4-27 08:38:36
     */
    private static function hotProducts($data)
    {
        foreach ($data as $val) {
            self::$shopData['hotList'][] = array(
                'url' => Helpers::getUrlBySkc($val['product_id'], $val['goods_id'], $val['cn_alphabet']),
                'img' => Helpers::getImageUrl($val['src'], 235, 314),
                'productName' => $val['productName'],
                'salesPrice' => '¥'.$val['salesPrice'],
                'presentPrice' => '¥'.$val['salesPrice']
            );
        }
    }

    /**
     * 店铺下面的所有分类
     * @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), 'search'),
                    'categoryId' => $val['category_id'],
                    'name' => $val['category_name']
                );
            }
        }
    }

}