NewSaleProcess.php 2.67 KB
<?php

namespace Plugin\DataProcess;

use Plugin\DataProcess\ListProcess;
use Plugin\Helpers;

/**
 * 新品到着、折扣专区数据处理类
 */
class NewSaleProcess
{

    /**
     * 处理新品到着、折扣专区数据
     * 
     * @param  array $products  接口传回的数据
     * @return array       处理之后的数据
     */
    public static function newSaleData($products)
    {
        $result = array();

        // 处理Tabs
        if (isset($products['tabs'])) {
            $result['tabs'] = array();
            foreach ($products['tabs'] as $key => $one) {
                $tabItem = array();
                $tabItem['title'] = $one;
                $tabItem['dataId'] = $key;
                if ($key === 1) {
                    $tabItem['focus'] = true;
                }
                $result['tabs'][] = $tabItem;
            }
        }

        // 处理Filter
        if(isset($products['filter'])) {
            $result['filter'] = ListProcess::getFilterData($products['filter']);
        }

        // 处理商品
        if (isset($products['product_list'])) {
            foreach ($products['product_list'] as $single) {
                $result['goods'][] = Helpers::formatProduct($single, true, false, false, 290, 388);
            }
        }

        return $result;
    }

	/**
	 * 处理热销排行榜数据
	 *
	 * @param  array $products 接口传回的数据
	 * @param  boolean $notab 是否传回tab数据
	 * @param  int $limit 查询返回的最大限制数
	 * @param  int $page 分页第几页
	 * @return array       处理之后的数据
	 */
    public static function topData($products, $notab, $limit, $page)
    {
        $result = array();

        // 处理Tabs
        if (!$notab && isset($products['tabs'])) {
            $result['tabs'] = array();
            foreach ($products['tabs'] as $key => $one) {
                $tabItem = array();
                $tabItem['title'] = $one;
                $tabItem['dataId'] = $key;
                if ($key === 0) {
                    $tabItem['focus'] = true;
                }
                $result['tabs'][] = $tabItem;
            }
        }

        // 处理商品
        if (isset($products['product_list'])) {

	        $count = count($products['product_list']);
	        $one = array();
            foreach ($products['product_list'] as $key => $single) {
                $one = Helpers::formatProduct($single, true, false, false, 75, 114);
	            $one['rank'] = $limit * ($page -1) + $key + 1;
	            !empty($single['sales_phrase']) && $one['sales_phrase'] = $single['sales_phrase'];

	            $result['goods'][] = $one;
            }
        }

        return $result;
    }

}