<?php
/**
* @method 贝偲特定制接口 2023/7/12
* @http  get
* @author soul
*/
class comBmtsrAction extends baseAction
{
	public $appkey = 225801;
	public $comCfg = [];
	public function __construct()
	{
		parent::__construct();
		$this->comCfg = mvc::$cfg['COMAPI'][$this->appkey];
	}

	/**
	  * @method 获取全量宜配车型库
	  * @http  get
	  * @author soul
	  * @copyright 2023/7/12
	  * @return {"status":true,"data":[{"mch_code":"2980513c88aceb1facd388659c9fd096","brand_id":"98","brand_name":"MINI","brand_initial":"M","make_id":"141","make_name":"MINI(进口)","mod1_id":"1112","mod1_name":"CLUBMAN","mod2_id":"1696","mod2_name":"CLUBMAN (F54)","mod2_start_year":"2016","mod2_end_year":"2019","mch_engine":"B38A15A","mch_kw":"75","mch_cc":"1499","mch_cc_name":"1.5T","mch_transmission":"6A\/MT","mch_drive":"前置前驱","mch_fuel":"汽油","mod3_mcode":"LU91"},{"mch_code":"4e7c42d6afb48f12301d4236c0fc1625","brand_id":"98","brand_name":"MINI","brand_initial":"M","make_id":"141","make_name":"MINI(进口)","mod1_id":"1112","mod1_name":"CLUBMAN","mod2_id":"1696","mod2_name":"CLUBMAN (F54)","mod2_start_year":"2016","mod2_end_year":"2019","mch_engine":"B38A15A","mch_kw":"100","mch_cc":"1499","mch_cc_name":"1.5T","mch_transmission":"6A\/MT","mch_drive":"前置前驱","mch_fuel":"汽油","mod3_mcode":"LN31"}],"code":0,"runtime":82}
	  */
	public function getChassisModel()
	{
		$Ypc2Base = new Ypc2Base();
		$filed = ['mch_code, brand_id, brand_name, brand_initial, make_id, make_name, mod1_id,mod1_name, mod2_id, mod2_name,mod2_start_year, mod2_end_year, mod2_pc, mod2_cv, mch_engine, mch_kw,mch_cc,mch_cc_name,mch_transmission,mch_drive,mch_fuel,m3_mcode mod3_mcode'];
		$table = sprintf("bc_modchassis
		JOIN bc_model2 ON mod2_id = mch_mod2_id
		JOIN bc_model1 ON mod2_mod1_id = mod1_id
		JOIN bc_make ON mod1_make_id = make_id
		JOIN bc_brand ON mod1_brand_id = brand_id
		JOIN bc_modchassis_mod3 ON mcm_mch_code = mch_code
		JOIN %s.yp_model3 ON m3_id = mcm_mod3_id",mvc::$cfg['DB']['YP_CAR']['db_name']);
		$res = $Ypc2Base->get($table, $filed, sprintf(" and brand_id IN (%s) GROUP BY mch_code order by brand_name, make_name, mod2_name, mod2_start_year", implode(',', $this->comCfg['brandids'])));
		LibFc::EchoJson($res);
	}


	/**
	  * @method get  VIN解码
	  * @http  get
	  * @param  vin                string [必填] 17位车架号 WBAWX3100D0G01954
	  * @author soul
	  * @copyright 2023/7/12
	  * @return {"status":true,"data":{"mch_code":["7ce78e37b943dd4206f6343810f2d935"],"vin_year":"2013-02","vin_year_name":"制造日期"},"code":"","runtime":573}
	  */
	public function decodeVin()
	{
		$Params = mvc::$URL_PARAMS;
		$vin = $Params['vin'];
		$OthCom = new OthCom();
		$res = $OthCom->decodeVinBmtsr($vin);
		if(!empty($res['data']['mch_code']))
		{
			$MainZyb = new MainZyb();
			$MainZyb->addFastComZybHistory('vin', $vin);
		}
		LibFc::EchoJson($res);
	}


	/**
	  * @method get  号码搜索
	  * @http  get
	  * @param  number			   string [必填] 号码 GDB900
	  * @author soul
	  * @copyright 2023/7/12
	  * @return {"status":true,"data":{"yp":[{"pro_id":"29620","pro_url":"http:\/\/www.yiparts.com\/alfa_romeo,brake_pad_set,0060750413,cn.html","pro_name":"刹车片(前轮)","pic":["http:\/\/www.yiparts.com\/Files\/ProFile\/Image\/000455\/58\/\/52fe0bef51551.jpg"],"num":[{"factory":"TRW","display":"GDB900"},{"factory":"OE","display":"0060 750 413"}]}]},"code":0,"runtime":371}
	  */
	public function searchNumber()
	{
		$Params = mvc::$URL_PARAMS;
		$Params = [
			'word'=>$Params['number'],
			'type'=>'yp',
		];
		$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('number', $Params['word']);
		$OthNumber = new OthNumber();
		$res = $OthNumber->search($Params);
		foreach($res['data'] as $type=>$rows)
		{
			foreach($rows as $pk=>$pv)
			{
				unset($res['data'][$type][$pk]['pro_price']);
				unset($res['data'][$type][$pk]['para']);
			}
		}
		LibFc::EchoJson($res);
	}
	
	/**
	  * @method get  号码匹配车型
	  * @http  get
	  * @param  number			   string [必填] 号码 11138616793,11 41 8 612 615 多个号码用英文逗号分隔
	  * @author soul
	  * @copyright 2023/7/12
	  * @return {"status":true,"data":["03f7f994a401d9e400c9a85bbbf22ea9","0d81f78820842364de0992ebb51a2b62","0e2319508534fcfba30263ec12e488e4","283b822d4b2102ccbe08eb400b961375","3c994c8f901c476ad04c4f3c570bd8bb","555ae17fbf12947ec80fe10bda474c51","65cd2e3bfcb2c03bdfdac617a92a651c","6720de725c1b9dd8e79f067f234021a7","683fb9d08d8630a3ce75bad0e4ab3a34","701dd1cb7853089fb571698c0dd7c97d","7eb56b10575d9f1788824d528dba992e","97375ced4f9a36123be358f99f57ef74","9889db65689220a14db5304f47d59b8d","c01f653c700613e4e190ebd721d4f1ac","c8810ee688ff4dc0d55a907a016d02bc","cb107f17d1ab7d068082a8585fad26c9","d20ab39b5ec34a38129f368365e1b7f2","dd337687b850ad2e66760f9a098bd228","eb9ed68b9eed6230c64091d24e34ea2a","f16996d8b76cfcb3f3da033ccd8c2554"],"code":"","runtime":125}
	  */
	public function getModelByNumber()
	{
		$Params = mvc::$URL_PARAMS;
		$EtkNum = new EtkNum();
		$res = $EtkNum->getModelByNumber($Params['number'], 'chassis');
		$arr = $res['data'];
		if(!empty($arr)){
			$MainZyb = new MainZyb();
			$MainZyb->addFastComZybHistory('matchmod', $Params['number']);
        }
		LibFc::ReturnJson(true, $arr);
	}
}