NewSaleProcess.php 1.3 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;
    }

}