<?php
namespace admin\action;
use \model\carmodelcn;
use \model\collocation;
class carmodelcnAction  extends \action
{
	
	/**
	  * @method 中国车型选择
	  * @param  style  string  [选填] 选择模式 anychk:多选  空(默认):单选
	  * @author soul
	  */
    function select()
	{
		$req = \mvc::$req;
		$style = !empty($req['style']) && $req['style'] == 'anychk'? 'anychk': '';
        $carmodelcn = new carmodelcn();
		$res = $carmodelcn->getBrandLetter();
		$chkids = $carmodelcn->getChkIdsByParams($req);
		
		$chkids =array_merge($chkids,$req['id']?explode(',',$req['id']):[]);

		\view::set('chkids', $chkids);
		\view::set('id',$req['id']);
		\view::set('letterArr', $res);
		\view::set('style', $style);
		\view::set('req',$req);
		\view::put();
    }

	function select2()
	{
		$req = \mvc::$req;
		$style = !empty($req['style']) && $req['style'] == 'anychk'? 'anychk': '';
        $carmodelcn = new carmodelcn();
	
		\view::set('style', $style);
		\view::set('req',$req);
		\view::put();
    }
	
	/**
	  * @method 中国车型列表
	  * @author soul
	  */
	public function getModelList()
	{
		$req = \mvc::$req;
        $carmodelcn = new carmodelcn();
		$data = $carmodelcn->getModelList($req);
        $this->successJson($data);
	}


	/**
	  * @method 同步中国车型
	  * @author soul
	  */
	public function uploadModel()
	{
		set_time_limit(0);
		ignore_user_abort(true);
		set_time_limit(\mvc::$cfg['bigtable_memory_limit']);
		$req = \mvc::$req;
        $carmodelcn = new carmodelcn();
        $data = $carmodelcn->uploadModel();
		$this->successJson($data);
	}

	public function setHotBrand()
	{
		$req = \mvc::$req;
        $ckv = new \model\ckv();
		$hot = explode(',', $req['ids']);
		$data = $ckv->setKV('hot_cnbrands', $hot);
        $this->successJson([]);
	}


	/**
	  * @method 中国车型统计
	  * @author soul
	  */
	public function getModelReport()
	{
		$req = \mvc::$req;
		$rules = $this->urlRulesToWhere($req);
        $carmodelcn = new carmodelcn();
		$data = $carmodelcn->getModelReport($req, $rules);
        $this->successJson($data);
	}
}