<?php
namespace admin\action\pro;
use \model\carmodel;
use \model\pro\promodel;
class modelsAction  extends \action
{
	 /**
	  * @method 车型选择
	  * @param  ma_id  int  [选填] 车型区域ID, 默认所有
	  * @param  style  string  [选填] 选择模式 anychk:多选  空(默认):单选
	  * @author soul
	  */
    function select()
	{
		$req = \mvc::$req;
		$style = !empty($req['style']) && $req['style'] == 'anychk'? 'anychk': '';
        $carmodel = new carmodel();
		
		$data = $carmodel->getAreaShowFiled(0);
		\view::set('filedArr', $data);

		$res = $carmodel->getMakeLetter();
		\view::set('letterArr', $res);
		\view::set('style', $style);
		\view::set('ma_id', $req['ma_id']);
		\view::put();
    }

	 /**
	  * @method 车型选择
	  * @param  ma_id  int  [选填] 车型区域ID, 默认所有
	  * @param  style  string  [选填] 选择模式 anychk:多选  空(默认):单选
	  * @author soul
	  */
    function select2()
	{
		$req = \mvc::$req;
		$style = !empty($req['style']) && $req['style'] == 'anychk'? 'anychk': '';
        $carmodel = new carmodel();
		
		$data = $carmodel->getAreaShowFiled(0);
		\view::set('filedArr', $data);

		$res = $carmodel->getMakeLetter();
		\view::set('letterArr', $res);
		\view::set('style', $style);
		\view::set('ma_id', $req['ma_id']);
		\view::put();
    }
	

	/**
	  * @method 查询小车型
	  * @param  ma_id  int  [选填] 车型区域ID, 默认所有
	  * @param  mk_id  int  [必填] 大车型ID
	  * @author soul
	  */
    function getModelSeries()
	{
		$req = \mvc::$req;
		$carmodel = new carmodel();
		$data = $carmodel->getModelSeries($req['ma_id'], $req['mk_id']);
		$this->successJson($data);
    }


	/**
	  * @method 查询小车型
	  * @param  ma_id  int  [选填] 车型区域ID, 默认所有
	  * @param  mk_id  int  [必填] 大车型ID
	  * @param  ms_id  int  [必填] 小车型ID
	  * @param  mkword  string  [必填] 大车型关键字
	  * @param  msword  string  [必填] 小车型关键字
	  * @param  mmword  string  [必填] 车型关键字
	  * @param  mcode  string  [必填] 车型代码
	  * @author soul
	  */
    function getModel()
	{
		$req = \mvc::$req;
		$carmodel = new carmodel();
		$req["LIMIT"] = 500;
		$data = $carmodel->getModel($req);
		$this->successJson($data);
    }

	/**
	  * @method 添加产品的适用车型
	  * @param  p_id  int  [必填] 产品ID
	  * @param  mm_ids  string  [必填] 车型ID  多个逗号分隔
	  * @author soul
	  */
	public function addProModel()
	{
		$req = \mvc::$req;
		$promodel = new promodel();
		$mmArr = [];
		foreach(explode(',', $req['mm_ids']) as $mmid)
		{
			$mmArr[] = ['pml_mm_id'=>$mmid];
		}
		$data = $promodel->addProModel($req['p_id'], $mmArr);
		$this->successJson($data);
	}
	
	/**
	  * @method 编辑产品的适用车型的基本信息
	  * @param  id  int  [必填] pml_id
	  * @param  field  string  [必填] 字段
	  * @author soul
	  */
	public function setProModelInfo()
	{
		$req = \mvc::$req;
		if(!empty($req['id']) && preg_match('/^\d+$/', $req['id']))
		{
			$setArr = [
				$req['field']=>$req[$req['field']]
			];
			$promodel = new promodel();
			$promodel->setProModelInfo($req['id'], $setArr);
		}
	}


	/**
	  * @method 删除产品的适用车型
	  * @param  ids  string  [必填] pml_id  多个逗号分隔
	  * @author soul
	  */
	public function delProModel()
	{
		$req = \mvc::$req;
		$promodel = new promodel();
		$data = $promodel->delProModel(explode(',', $req['ids']));
		$this->successJson($data);
	}
}