<?php



/**
 *
 * Class dshopAction
 */
class dshopAction
{
	//商城代理商铺的车型品牌
	public function getSuperBrand()
	{
		$B2cBase = new B2cBase();
		$ComModel = new ComModel();
		$table = 'bc_product join bc_product_brand_link on pbl_pro_id=pro_id and pro_status = 1';
		$res = $B2cBase->get($table, ['distinct pbl_brand_id'], sprintf(" and pro_shop_id in (%s)", implode(',', mvc::$cfg['shopInfo']['dshop_ids'])));
		if(!empty($res['data']))
		{
			$where = sprintf(" and brand_id in (%s) order by brand_seq,brand_initial", implode(',', array_column($res['data'], 'pbl_brand_id')));
			$res = $ComModel->get('bc_brand', ['brand_id', 'brand_name', 'brand_initial', 'brand_keyword', 'brand_code'], $where);
            LibFc::ajaxJsonEncode($res);
		}
		LibFc::ajaxJsonEncode(['status' => true,'data' => []]);
	}

	//todo 已经改过了
	public function getSuperModelsParams()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = [];
		//获取目录的车型配置
		if(empty(mvc::$cfg['shopInfo']['dshop_model'][$Params['level']])) LibFc::ReturnJson(true, $arr);
		$ComModel = new ComModel();
		$level = (int) substr($Params['level'], 1);
		$comWhere = '';
		if(!empty($Params['brand_id'])) $comWhere .= sprintf(" and brand_id=%d", (int) $Params['brand_id']);
		$uriP = [];
		for($l = 0; $l <= $level; $l++)
		{
			$dtype = mvc::$cfg['shopInfo']['dshop_model']['L'.($l-1)];

			if(!empty($dtype))
			{
				switch($dtype)
				{
					case 'mod1':
						$comWhere .= sprintf(" and mod1_id=%d", (int) $Params['mod1_id']);
						$res = $ComModel->getModel(1, ['make_id','make_name', 'mod1_id', 'mod1_name'], $comWhere, true);
						if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
						$uriP['level'] = 'L'.$l;
						$uriP['mod1_id'] = $res['data']['mod1_id'];
						$arr[$uriP['level']] = ['param'=>$uriP, 'name'=>$res['data']['mod1_name']];
					break;
					case 'mod2':
						$comWhere .= sprintf(" and mod2_id=%d", (int) $Params['mod2_id']);
						$res = $ComModel->getModel(2, ['mod2_id', 'mod2_name', 'mod2_start_year', 'mod2_end_year'], $comWhere, true);
						if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
						$uriP['level'] = 'L'.$l;
						$uriP['mod2_id'] = $res['data']['mod2_id'];
						$arr[$uriP['level']] = ['param'=>$uriP, 'name'=>$res['data']['mod2_name'].' '.LibFc::formatViewYear($res['data']['mod2_start_year'], $res['data']['mod2_end_year'])];
					break;
					case 'cc':
						$comWhere .= sprintf(" and mod3_cc_name='%s'",  LibFc::Escape($Params['mod3_cc_name']));
						$res = $ComModel->getModel(3, ['mod3_cc_name, mod3_cc_name'], $comWhere, true);
						if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
						$res['data']['mod3_cc_showname'] =  empty($res['data']['mod3_cc_name']) || $res['data']['mod3_cc_name'] == 0.0? '纯电动': $res['data']['mod3_cc_name'];
						$uriP['level'] = 'L'.$l;
						$uriP['mod3_cc_name'] = $res['data']['mod3_cc_name'];
						$arr[$uriP['level']] = ['param'=>$uriP, 'name'=>$res['data']['mod3_cc_showname']];
						
					break;
					case 'engine':
						$comWhere .= sprintf(" and mod3_cc='%s'",  LibFc::Escape($Params['mod3_cc']));
						$comWhere .= sprintf(" and mod3_kw='%s'",  LibFc::Escape($Params['mod3_kw']));
						$comWhere .= sprintf(" and mod3_engine='%s'",  LibFc::Escape($Params['mod3_engine']));
						$res = $ComModel->getModel(3, ['mod3_engine', 'mod3_kw', 'mod3_cc'], $comWhere, true);
						if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
						$uriP['level'] = 'L'.$l;
						$uriP['mod3_kw'] = $res['data']['mod3_kw'];
						$uriP['mod3_cc'] = $res['data']['mod3_cc'];
						$uriP['mod3_engine'] = $res['data']['mod3_engine'];
						$arr[$uriP['level']] = ['param'=>$uriP, 'name'=>$res['data']['mod3_engine'].' '.$res['data']['mod3_kw'].'kw '.$res['data']['mod3_cc'].'cc'];
					break;
					case 'cctrandrive':
						$comWhere .= sprintf(" and mod3_drive_short='%s'",  LibFc::Escape($Params['mod3_drive_short']));
						$Params['cctran'] = base64_decode($Params['cctran']);
						$cc = explode('@', $Params['cctran']);
						$comWhere .= sprintf(" and mod3_cc_name = '%s' and (mod3_transmission ='%s' or mod3_transmission REGEXP '^[0-9]+%s$' or mod3_transmission like '电动车%s%%')", LibFc::Escape($cc[0]), LibFc::Escape($cc[1]), LibFc::Escape($cc[1]), LibFc::Escape($cc[1]));
						$replaceArr = [
							'tran'=>[
								'A/MT'=>'手自一体',
								'AMT'=>'AMT',
								'DCT'=>'双离合',
								'单速'=>'单速',
								'ASG'=>'序列',
								'E-CVT'=>'无级',
								'CVT'=>'无级',
								'AT'=>'自动',
								'MT'=>'手动',
								'自动（模拟10挡）'=>'自动'
							]
						];
						$res = $ComModel->getModel(3, ['mod3_cc_name, mod3_transmission, mod3_drive_short'], $comWhere, true);
						if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
						$dv = $res['data'];
						$kt = '';
						foreach($replaceArr['tran'] as $kt=>$vt)
						{
							if(stripos($v['mod3_transmission'], $kt) !== false)
							{
								$dv['trankey'] = $kt;
								$dv['mod3_transmission'] = $vt;
								break;
							}
						}
						$dv['mod3_cc_name_key'] = $v['mod3_cc_name'];
						$dv['mod3_cc_name'] =  empty($dv['mod3_cc_name']) || $dv['mod3_cc_name'] == 0.0? '纯电动': $dv['mod3_cc_name'];
						$uriP['level'] = 'L'.$l;
						$uriP['cctran'] = base64_encode($dv['mod3_cc_name_key'].'@'.$kt);
						$uriP['mod3_drive_short'] = $dv['mod3_drive_short'];
						$arr[$uriP['level']] = ['param'=>$uriP, 'name'=>$dv['mod3_cc_name'].' '.$dv['mod3_drive_short'].' '.$dv['mod3_transmission']];
					break;
					case 'mod3':
						$comWhere .= sprintf(" and mod3_id=%d", (int) $Params['mod3_id']);
						$res = $ComModel->getModel(3, ['brand_etk_id', 'mod3_id', 'make_show_brand', 'brand_name', 'make_name', 'mod2_name', 'mod3_name', 'mod3_start_year', 'mod3_end_year', 'mod3_engine', 'mod3_kw', 'mod3_cc', 'mod3_transmission', 'mod3_fuel', 'mod3_drive'], $comWhere, true);
						if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
						$dv = $res['data'];
						$uriP['level'] = 'L'.$l;
						$uriP['mod3_id'] = $dv['mod3_id'];
						$arr[$uriP['level']] = ['param'=>$uriP, 'val'=>$dv];
					break;
				}
			}
			else if($l === 0)
			{
				$res = $ComModel->get('bc_brand', ['brand_id', 'brand_name'], $comWhere, true);
				if(empty($res['data'])) LibFc::ReturnJson(true, $arr);
				$uriP['level'] = 'L'.$l;
				$uriP['brand_id'] = $res['data']['brand_id'];
				$arr[$uriP['level']] = ['param'=>$uriP, 'name'=>$res['data']['brand_name']];
			}
		}
		LibFc::ReturnJson(true,$arr);
	}


	/**
     * todo 已经改过了
	  * @method 商城代理商铺的车型品牌的车型级
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @param  level               string [必填] 级别L0 L1 L2...
	  * @param  brand_id            int [必填] 车型品牌ID
	  * @param  mod1_id             int [必填] 一级车型ID
	  * @param  mod2_id             int [选填] 二级车型ID
	  * @param  mod3_drive          string [选填] 驱动方式
	  * @param  mod3_cc_name         string  [选填] 排量
	  * @param  mod3_cc              int [选填] 排量cc
	  * @param  mod3_kw              int [选填] 功率kw
	  * @param  mod3_engine          string [选填] 发动机
	  * @param  cctran              string [选填] 排量+驱动方式
	  * @author soul
	  * @copyright 2019/5/27
	  * @return 
	  	{"status":true,"data":{"next":"item","data":[{"mod3_drive":"\u524d\u7f6e\u524d\u9a71"}],"dtype":"drive"},"code":0}
		next(L0 L1 L2...item )  item 表示车型选择终止，下一步将跳转到配件列表页
		dtype(mod1,mod2,cctran,drive,mod3,engine,cc) 返回的数据类型 
		mod1:{"status":true,"data":{"next":"L1","data":[{"make_id":"114","make_name":"\u522b\u514b(\u8fdb\u53e3)","mods":[{"mod1_id":"842","mod1_name":"\u6602\u79d1\u96f7"}]},...],"dtype":"mod1"},"code":0}
		mod2:{"status":true,"data":{"next":"L2","data":[{"mod2_id":"2375","mod2_name":"GL6 (SK4)","mod2_start_year":"2018","mod2_end_year":"0"}],"dtype":"mod2"},"code":0}
		cctran:{"status":true,"data":{"next":"L3","data":[{"val":"MS4zVEBBL01U","cc":"1.3T","tran":"\u624b\u81ea\u4e00\u4f53"}],"dtype":"cctran"},"code":0}
		cctrandrive:{"status":true,"data":{"next":"L3","data":[{"val":"MS4zVEBBL01U","cc":"1.3T","tran":"\u624b\u81ea\u4e00\u4f53", "mod3_drive_short":"\u524d\u7f6e\u524d\u9a71"}],"dtype":"cctrandrive"},"code":0}
		drive:{"status":true,"data":{"next":"item","data":[{"mod3_drive_short":"\u524d\u7f6e\u524d\u9a71"}],"dtype":"drive"},"code":0}
		mod3:{"status":true,"data":{"next":"item","data":[{"brand_etk_id":"10","mod3_id":"1821","make_show_brand":0,"brand_name":"\u5965\u8fea","make_name":"\u4e00\u6c7d\u5965\u8fea","mod2_name":"A6L(4Z8,C6)","mod3_name":"3.2 FSI","mod3_start_year":2006,"mod3_end_year":2007,"mod3_engine":"AUK","mod3_kw":"188","mod3_cc":"3123","mod3_transmission":"7CVT","mod3_fuel":"\u6c7d\u6cb9","mod3_drive":"\u524d\u7f6e\u524d\u9a71"}],"dtype":"mod3"},"code":0}
		engine:{"status":true,"data":{"next":"item","data":[{"mod3_engine":"AUK","mod3_kw":"188","mod3_cc":"3123"}],"dtype":"engine"},"code":0}
		cc:{"status":true,"data":{"next":"L3","data":[{"mod3_cc_name":"3.2L","mod3_cc_showname":"3.2L"}...],"dtype":"cc"},"code":0}
	  */
	public function getSuperModels()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = implode(',', mvc::$cfg['shopInfo']['dshop_ids']);
		 $arr = [
			 'next'=>'',
			 'data'=>[],
			 'dtype'=>''
		 ];

		//获取目录的车型配置
		$B2cBase = new B2cBase();
		$res = $B2cBase->get('sh_dshop', ['dshop_model'], sprintf(" and dshop_id in(%s)", $shopid),true);
		if(empty($res['data'])) LibFc::ajaxJsonEncode($arr);
		$shopInfo = $res['data'];
		$shopInfo['ssu_model'] = json_decode($shopInfo['dshop_model'], true);
		if(empty($shopInfo['ssu_model'][$Params['level']])) LibFc::ReturnJson(false, '不支持此方式查询！');

		$ComModel = new ComModel();
		$level = (int) substr($Params['level'], 1);
		$comWhere = '';
		if(!empty($Params['brand_id'])) $comWhere .= sprintf(" and brand_id=%d", (int) $Params['brand_id']);
		if(!empty($Params['mod1_id'])) $comWhere .= sprintf(" and mod1_id=%d", (int) $Params['mod1_id']);
		if(!empty($Params['mod2_id'])) $comWhere .= sprintf(" and mod2_id=%d", (int) $Params['mod2_id']);
		if(!empty($Params['mod3_drive'])) $comWhere .= sprintf(" and mod3_drive='%s'",  LibFc::Escape($Params['mod3_drive']));
		if(!empty($Params['mod3_drive_short'])) $comWhere .= sprintf(" and mod3_drive_short='%s'",  LibFc::Escape($Params['mod3_drive_short']));
		if(!empty($Params['mod3_cc_name'])) $comWhere .= sprintf(" and mod3_cc_name='%s'",  LibFc::Escape($Params['mod3_cc_name']));
		if(!empty($Params['mod3_cc'])) $comWhere .= sprintf(" and mod3_cc='%s'",  LibFc::Escape($Params['mod3_cc']));
		if(!empty($Params['mod3_kw'])) $comWhere .= sprintf(" and mod3_kw='%s'",  LibFc::Escape($Params['mod3_kw']));
		if(!empty($Params['mod3_engine'])) $comWhere .= sprintf(" and mod3_engine='%s'",  LibFc::Escape($Params['mod3_engine']));

		if(!empty($Params['cctran']))
		{
			$Params['cctran'] = base64_decode($Params['cctran']);
			$cc = explode('@', $Params['cctran']);
			$comWhere .= sprintf(" and mod3_cc_name = '%s' and (mod3_transmission ='%s' or mod3_transmission REGEXP '^[0-9]+%s$' or mod3_transmission like '电动车%s%%')", LibFc::Escape($cc[0]), LibFc::Escape($cc[1]), LibFc::Escape($cc[1]), LibFc::Escape($cc[1]));
		}
		if(!empty($Params['year'])) $comWhere .= sprintf(" and %d >= mod3_start_year  and (%d <= mod3_end_year or mod3_end_year=0) ", $Params['year'], $Params['year']);
		
		$arr['dtype'] = $shopInfo['ssu_model'][$Params['level']];


		switch($arr['dtype'])
		{
			case 'mod1':
				if($comWhere != '')
				{
					$res = $ComModel->getModel(1, ['distinct mod1_id'], $comWhere);
					if(!empty($res['data']))
					{
					    //产品表关联店铺表
						$table = sprintf("bc_product inner join bc_product_model1_link on pml1_pro_id=pro_id");
						$where = sprintf(" and pml1_mod1_id in(%s) and pro_shop_id in(%s) and pro_status = 1", implode(',', array_column($res['data'], 'mod1_id')),$shopid);
						$res = $B2cBase->get($table, ['distinct pml1_mod1_id'], $where);
						if(!empty($res['data']))
						{
							$where = sprintf(" and mod1_id in(%s) order by make_seq, make_initial, make_name, mod1_name", implode(',', array_column($res['data'], 'pml1_mod1_id')));
							$res = $ComModel->getModel(1, ['make_id','make_name', 'mod1_id', 'mod1_name'], $where);
							foreach($res['data'] as $v)
							{
								$arr['data'][$v['make_id']]['make_id'] = $v['make_id'];
								$arr['data'][$v['make_id']]['make_name'] = $v['make_name'];
								$arr['data'][$v['make_id']]['mods'][] = ['mod1_id'=>$v['mod1_id'], 'mod1_name'=>$v['mod1_name']];
							}
						}
						$arr['data'] = array_values($arr['data']);
					}
				}
			break;
			case 'mod2':
				if($comWhere != '')
				{
					$res = $ComModel->getModel(2, ['distinct mod2_id'], $comWhere);
					if(!empty($res['data']))
					{
						$table = sprintf("bc_product inner join bc_product_model2_link on pml2_pro_id=pro_id");
						$where = sprintf(" and pml2_mod2_id in(%s) and pro_shop_id in(%s) and pro_status = 1", implode(',', array_column($res['data'], 'mod2_id')),$shopid);
						$res = $B2cBase->get($table, ['distinct pml2_mod2_id'], $where);
						if(!empty($res['data']))
						{
							$where = sprintf(" and mod2_id in(%s)  order by mod2_name, mod2_start_year desc", implode(',', array_column($res['data'], 'pml2_mod2_id')));
							$res = $ComModel->getModel(2, ['mod2_id', 'mod2_name', 'mod2_start_year', 'mod2_end_year'], $where);
							$arr['data'] = $res['data'];
						}
					}
				}
			break;
			case 'cc':
				$res = $ComModel->getModel(3, ['distinct mod3_id'], $comWhere);
				if(!empty($res['data']))
				{
					$B2cBase = new B2cBase();
					$table = sprintf("bc_product join bc_product_model3_link on pml3_pro_id=pro_id");
					$where = sprintf(" and pml3_mod3_id in(%s) and pro_shop_id in(%s) and pro_status = 1", implode(',', array_column($res['data'], 'mod3_id')),$shopid);
					$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
					if(!empty($res['data']))
					{
						$where = sprintf(" and mod3_id in(%s) GROUP BY mod3_cc_name order by mod3_cc_name desc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
						$res = $ComModel->getModel(3, ['mod3_cc_name'], $where);
						foreach($res['data'] as $v)
						{
							$v['mod3_cc_showname'] =  empty($v['mod3_cc_name']) || $v['mod3_cc_name'] == 0.0? '纯电动': $v['mod3_cc_name'];
							$arr['data'][] = $v;
						}
					}
				}
			break;
			case 'engine':
				$res = $ComModel->getModel(3, ['distinct mod3_id'], $comWhere);
				if(!empty($res['data']))
				{
					$B2cBase = new B2cBase();
					$table = sprintf("bc_product join bc_product_model3_link on pml3_pro_id=pro_id");
					$where = sprintf(" and pml3_mod3_id in(%s) and pro_status=1  and pro_shop_id in (%s)", implode(',', array_column($res['data'], 'mod3_id')),$shopid);
					$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
					if(!empty($res['data']))
					{
						$where = sprintf(" and mod3_id in(%s) GROUP BY mod3_engine, mod3_kw, mod3_cc order by mod3_engine, mod3_kw, mod3_cc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
						$res = $ComModel->getModel(3, ['mod3_engine', 'mod3_kw', 'mod3_cc'], $where);
						$arr['data'] = $res['data'];
					}
				}
			break;
			case 'cctran':
				$res = $ComModel->getModel(3, ['distinct mod3_id'], $comWhere);
				if(!empty($res['data']))
				{
					$B2cBase = new B2cBase();
					$table = sprintf("bc_product join bc_product_model3_link on pml3_pro_id=pro_id");
					$where = sprintf(" and pml3_mod3_id in(%s) and pro_status = 1 and pro_shop_id in (%s)", implode(',', array_column($res['data'], 'mod3_id')),$shopid);
					$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
					if(!empty($res['data']))
					{
						$where = sprintf(" and mod3_id in(%s) GROUP BY mod3_cc_name, mod3_transmission order by mod3_cc_name desc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
						$replaceArr = [
							'tran'=>[
								'A/MT'=>'手自一体',
								'AMT'=>'AMT',
								'DCT'=>'双离合',
								'单速'=>'单速',
								'ASG'=>'序列',
								'E-CVT'=>'无级',
								'CVT'=>'无级',
								'AT'=>'自动',
								'MT'=>'手动'
							]
						];
						$res = $ComModel->getModel(3, ['mod3_cc_name, mod3_transmission'], $where);
						foreach($res['data'] as $v)
						{
							$kt = '';
							foreach($replaceArr['tran'] as $kt=>$vt)
							{
								if(stripos($v['mod3_transmission'], $kt) !== false)
								{
									$v['trankey'] = $kt;
									$v['mod3_transmission'] = $vt;
									break;
								}
							}
							$v['mod3_cc_name_key'] = $v['mod3_cc_name'];
							$v['mod3_cc_name'] =  empty($v['mod3_cc_name']) || $v['mod3_cc_name'] == 0.0? '纯电动': $v['mod3_cc_name'];
							$arr['data'][$v['mod3_cc_name_key'].'@'.$kt] =['val'=>base64_encode($v['mod3_cc_name_key'].'@'.$kt), 'cc'=>$v['mod3_cc_name'], 'tran'=>$v['mod3_transmission']];
						}
						$arr['data'] = array_values($arr['data']);
					}
				}
			break;
			case 'cctrandrive':
				$res = $ComModel->getModel(3, ['distinct mod3_id'], $comWhere);
				if(!empty($res['data']))
				{
					$B2cBase = new B2cBase();
					$table = sprintf("bc_product join bc_product_model3_link on pml3_pro_id=pro_id");
					$where = sprintf(" and pml3_mod3_id in(%s) and pro_shop_id in(%s) and pro_status = 1", implode(',', array_column($res['data'], 'mod3_id')),$shopid);
					$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
					if(!empty($res['data']))
					{
						$where = sprintf(" and mod3_id in(%s) GROUP BY mod3_cc_name, mod3_transmission, mod3_drive_short order by mod3_cc_name desc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
						$replaceArr = [
							'tran'=>[
								'A/MT'=>'手自一体',
								'AMT'=>'AMT',
								'DCT'=>'双离合',
								'单速'=>'单速',
								'ASG'=>'序列',
								'E-CVT'=>'无级',
								'CVT'=>'无级',
								'AT'=>'自动',
								'MT'=>'手动'
							]
						];
						$res = $ComModel->getModel(3, ['mod3_cc_name, mod3_transmission, mod3_drive_short'], $where);
						foreach($res['data'] as $v)
						{
							$kt = '';
							foreach($replaceArr['tran'] as $kt=>$vt)
							{
								if(stripos($v['mod3_transmission'], $kt) !== false)
								{
									$v['trankey'] = $kt;
									$v['mod3_transmission'] = $vt;
									break;
								}
							}
							$v['mod3_cc_name_key'] = $v['mod3_cc_name'];
							$v['mod3_cc_name'] =  empty($v['mod3_cc_name']) || $v['mod3_cc_name'] == 0.0? '纯电动': $v['mod3_cc_name'];
							$arr['data'][$v['mod3_cc_name_key'].'@'.$kt.$v['mod3_drive_short']] =[
								'val'=>base64_encode($v['mod3_cc_name_key'].'@'.$kt),
								'cc'=>$v['mod3_cc_name'],
								'tran'=>$v['mod3_transmission'],
								'mod3_drive_short'=>$v['mod3_drive_short']
							];
						}
						$arr['data'] = array_values($arr['data']);
					}
				}
			break;
			case 'drive':
				$res = $ComModel->getModel(3, ['distinct mod3_id'], $comWhere);
				if(!empty($res['data']))
				{
					$B2cBase = new B2cBase();
					$table = sprintf("bc_product join bc_product_model3_link on pml3_pro_id=pro_id");
					$where = sprintf(" and pml3_mod3_id in(%s) and pro_status = 1 and pro_shop_id in(%s)", implode(',', array_column($res['data'], 'mod3_id')),$shopid);
					$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
					if(!empty($res['data']))
					{
						$where = sprintf(" and mod3_id in(%s) GROUP BY mod3_drive_short order by mod3_drive_short desc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
						$res = $ComModel->getModel(3, ['mod3_drive_short'], $where);
						$arr['data'] = $res['data'];
					}
				}
			break;
			case 'mod3':
				if(!empty($comWhere))
				{
					$res = $ComModel->getModel(3, ['distinct mod3_id'], $comWhere);
					if(!empty($res['data']))
					{
						$B2cBase = new B2cBase();
						$table = sprintf("bc_product join bc_product_model3_link on pml3_pro_id=pro_id ");
						$where = sprintf(" and pml3_mod3_id in(%s) and pro_shop_id in(%s) and pro_status = 1", implode(',', array_column($res['data'], 'mod3_id')),$shopid);
						$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
						if(!empty($res['data']))
						{
							$where = sprintf(" and mod3_id in(%s)  order by mod3_name, mod3_start_year desc", implode(',', array_column($res['data'], 'pml3_mod3_id')));
							$res = $ComModel->getModel(3, ['brand_etk_id', 'mod3_id', 'make_show_brand', 'brand_name', 'make_name', 'mod2_name', 'mod3_name', 'mod3_start_year', 'mod3_end_year', 'mod3_engine', 'mod3_kw', 'mod3_cc', 'mod3_transmission', 'mod3_fuel', 'mod3_drive'], $where);
							$arr['data'] = $res['data'];
						}
					}
				}
			break;
		}
		$arr['next'] = !empty($shopInfo['ssu_model']['L'.($level+1)]) ? 'L'.($level+1): 'item';
		LibFc::ajaxJsonEncode(['status' => true,'data' => $arr]);
	}

	/**
	  * @method 商城代理商铺的发动机查询
	  * @http	get
	  * @param  shopid             string [必填] 店铺ID
	  * @param  word                string [必填] 关键字 至少2个字符  CAL
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"brand_name":"奔驰","mod3_engine":"M 272.945","mod3_fuel":"汽油","mod3_kw":"170","mod3_cc":"2999"},...],"code":0}
	  */
	public function searchSuperEngine()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = implode(',', mvc::$cfg['shopInfo']['dshop_ids']);

		$word = LibFc::Escape($Params['word']);
		$arr = [];
		if(strlen($word) < 2) LibFc::ReturnJson(true, $arr);
		
		$B2cBase = new B2cBase();
		$ComModel = new ComModel();
		$where = sprintf(" and mod3_engine_format like '%%%s%%'", LibFc::FormatNum($word));
		$res = $ComModel->get('bc_model3', ['distinct mod3_id'], $where);
		if(!empty($res['data']))
		{
			$where = sprintf(" and pml3_mod3_id in(%s)", implode(',', array_column($res['data'], 'mod3_id')));
			$table = sprintf("bc_product join bc_product_model3_link on pml3_pro_id=pro_id");
			$where .= sprintf(" and pro_status = 1 and pro_shop_id in (%s)",$shopid);
			$res = $B2cBase->get($table, ['distinct pml3_mod3_id'], $where);
			if(!empty($res['data']))
			{
				$where = sprintf(" and mod3_id in(%s) group by mod3_engine order by max(brand_initial), mod3_engine", implode(',', array_column($res['data'], 'pml3_mod3_id')));
				$res = $ComModel->getModel(3, ['max(brand_name) brand_name', 'mod3_engine', 'max(mod3_fuel) mod3_fuel', 'max(mod3_kw) mod3_kw','max(mod3_cc) mod3_cc'], $where);
				$arr = $res['data'];
			}
		}
		LibFc::ReturnJson(true, $arr);
	}

	/**
     * todo 已经改过了
	  * @method 商城代理商铺的发动机查询
	  * @http	get
	  * @param  shopid             string [必填] 店铺ID
	  * @param  word                string [必填] 关键字 至少2个字符  CAL
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"brand_name":"奔驰","mod3_engine":"M 272.945","mod3_fuel":"汽油","mod3_kw":"170","mod3_cc":"2999"},...],"code":0}
	  */
	public function searchSuperModel()
	{
		$Params = mvc::$URL_PARAMS;
		$shopid = implode(',', mvc::$cfg['shopInfo']['dshop_ids']);
		$word = LibFc::Escape(strtoupper($Params['word']));
		$arr = [];
		if(strlen($word) < 2) LibFc::ReturnJson(true, $arr);
		$arr = [
			 'next'=>'L1',
			 'data'=>[],
			 'dtype'=>'mod1'
		 ];
		
		$B2cBase = new B2cBase();
		$ComModel = new ComModel();
		$where = sprintf(" and (brand_keyword like '%%%s%%' or make_keyword like '%%%s%%' or mod1_name like '%%%s%%' or mod1_keyword like '%%%s%%')", $word, $word, $word, $word);
		$res = $ComModel->getModel(1, ['distinct mod1_id'], $where);
		if(!empty($res['data']))
		{
			$table = sprintf("bc_product join bc_product_model1_link on pml1_pro_id=pro_id");
			$where = sprintf(" and pml1_mod1_id in(%s) and pro_status = 1 and pro_shop_id in (%s)", implode(',', array_column($res['data'], 'mod1_id')),$shopid);
			$res = $B2cBase->get($table, ['distinct pml1_mod1_id'], $where);
			if(!empty($res['data']))
			{
				$where = sprintf(" and mod1_id in(%s) order by make_seq, make_initial, make_name, mod1_name", implode(',', array_column($res['data'], 'pml1_mod1_id')));
				$res = $ComModel->getModel(1, ['brand_id', 'make_id','make_name', 'mod1_id', 'mod1_name'], $where);
				foreach($res['data'] as $v)
				{
					$arr['data'][$v['make_id']]['make_id'] = $v['make_id'];
					$arr['data'][$v['make_id']]['make_name'] = $v['make_name'];
					$arr['data'][$v['make_id']]['mods'][] = ['brand_id'=>$v['brand_id'], 'mod1_id'=>$v['mod1_id'], 'mod1_name'=>$v['mod1_name']];
				}
			}
			$arr['data'] = array_values($arr['data']);
		}
		LibFc::ReturnJson(true, $arr);
	}

	/**
     * todo 已经改过了
	  * @method 商城代理商铺的配件
	  * @http	get
	  * @param  type               string [选填] 默认：all  号码：number  
	  * @param  shopid              string [必填] 店铺ID
	  * @param  brand_id            int [必填] 车型品牌ID
	  * @param  mod1_id             int [必填] 一级车型ID
	  * @param  mod2_id             int [选填] 二级车型ID
	  * @param  mod3_drive          string [选填] 驱动方式
	  * @param  mod3_cc_name         string  [选填] 排量
	  * @param  mod3_cc              int [选填] 排量cc
	  * @param  mod3_kw              int [选填] 功率kw
	  * @param  mod3_engine          string [选填] 发动机
	  * @param  cctran              string [选填] 排量+驱动方式
	  * @param  keyword               string [选填] 关键字
	  * @param  uid                int [选填] 用户ID
	  * @author soul
	  * @copyright 2019/5/27
	  * @return {"status":true,"data":[{"pro_id":"177598","prb_name":"ABC","pro_status":"1","pro_name":"\u524d\u5239\u8f66\u76d8","pro_shop_id":"149894","pro_sale_price":"0.00","pro_count":"1","pro_user_discount":"N","pro_sold_count":"0","pri_code":"123456","pri_weight":null,"pri_frt_id":null,"pro_sel_des":null,"pri_invoice":"0","pri_warranty":"0","pri_return_promise":"1","pro_spart_id":"2996_4962","price":"0.00","price_type":1,"pro_price":{"title":"\u9500\u552e\u4ef7","price":"0.00"},"pic":[],"num":[{"factory":"ABC","display":"123456"},{"factory":"OE","display":"A0004212512"}],"mod3_para":"\u8f66\u67b6\u53f7\u5c3e\u53f7\u81f3:L365777"}],"code":0}
	  */
	public function getSuperItem()
	{
		$Params = mvc::$URL_PARAMS;

		$arr = [];
		$shopid = implode(',', mvc::$cfg['shopInfo']['dshop_ids']);

        $Params['shopid'] = $shopid;
        $Params['type'] = !empty($Params['type']) && $Params['type'] == 'number'? 'number': 'all';
		if($shopid > 0)
		{
			$B2cSearch = new B2cSearch();
			$res = $B2cSearch->searchSuperItem($shopid, $Params);
			if(!empty($res['data']['proIds']))
			{
			    $LibApi = new LibYpApi();
			    $res = $LibApi->Get('b2c/getAnyProductInfo',[],[
			        'proIds' => $res['data']['proIds'],
                    'uid' => $Params['uid'],
                    'types' => [],
                    'mod3Id' => $Params['mod3_id']
                ]);
				$arr = $res['data'];
			}
		}
		LibFc::ReturnJson(true, array_values($arr));
	}
}

