<?php
namespace homeh5\action;
use \model\carmodelcn;

class carmodelcnAction extends baseAction
{

    public function brand()
    {
        $req = \mvc::$req;

        \view::set('req',$req);
        \view::set('title','中国车型-'.\mvc::$cfg['siteTitle']);
        \view::put();
    }

    public function getModelBrand()
    {
        $req = \mvc::$req;
        if($req['m_type']=='#') $req['m_type']='hot';
        $carmodelcn = new carmodelcn();
        $brandList = $carmodelcn->getBrandListByFilter($req);
        $this->successJson($brandList);
    }

    public function getMod1List()
    {
        $req = \mvc::$req;
        $carmodelcn = new carmodelcn();
        $mod1List = $carmodelcn->getMod1ListByFilter($req);
        $group = [];
        foreach ($mod1List as $key => $val) {
            if(isset($group[$val['make_id']])) {
                $group[$val['make_id']]['mods'][] = $val;
                unset($mod1List[$key]);
                continue;
            }else{
                $group[$val['make_id']] = [
                    'make_id' => $val['make_id'],
                    'make_name' => $val['make_name'],
                    'mods' => [$val]
                ];
            }
        }
        $this->successJson(array_values($group));
    }

    public function getMod2List()
    {
        $req = \mvc::$req;
        $carmodelcn = new carmodelcn();
        $mod2List = $carmodelcn->getMod2ListByFilter($req); 
        $this->successJson(array_values($mod2List));
    }

    public function getModelCar()
    {
        $req = \mvc::$req;
        $carmodelcn = new carmodelcn();
        $modelList = $carmodelcn->getModelCarListByFilter($req);

        $this->successJson($modelList['list']);
    }

}
