<?php
/**
* @method 对外公共接口
* @http  get
* @author soul
*/
class comAction extends baseAction
{
	public $comCfg = [];
	public function __construct()
	{
		parent::__construct();
		mvc::$cfg['LOGUSER']['uid'] = 8;
		mvc::$cfg['LOGUSER']['urname'] = '系统API';
		$this->comCfg = mvc::$cfg['COMAPI'][mvc::$cfg['RQTOKEN']['uid']]? : [];
	}

	/**
	  * @method 获取全量全车件车型库
	  * @http  get
	  * @author soul
	  * @copyright 2022/8/11
	  * @return 压缩包数据流 yiparts_model.zip
	  */
	public function getAllModel()
	{
		ini_set('memory_limit', '512M');
		set_time_limit(1200);
		$name = 'yiparts_model';
		$zipfile = mvc::$cfg['PATH_CACHE'].$name.'.zip';
		if(!file_exists($zipfile) || (filemtime($zipfile) < (time()-3600)))
		{
			@unlink($zipfile);
			$jsonFile = mvc::$cfg['PATH_CACHE'].$name.'.json';
			$Ypc2Model = new Ypc2Model();
			$filed = ['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, mod3_id, mod3_name, mod3_start_year, mod3_end_year, mod3_engine, mod3_kw, mod3_cc, mod3_transmission, mod3_fuel, mod3_body, mod3_front_brake, mod3_rear_brake, mod3_parking_brake, mod3_drive, mod3_atime, mod3_etime'];
			$res = $Ypc2Model->getModel(3, $filed, ' order by brand_name, make_name, mod2_name, mod3_name, mod3_start_year');
			file_put_contents($jsonFile, json_encode($res['data'], JSON_UNESCAPED_UNICODE));

			$zipTmpfile = mvc::$cfg['PATH_CACHE'].$name.'.zip.tmp';
			$zip = new ZipArchive();
			if($zip->open($zipTmpfile, ZipArchive::CREATE))
			{
				$zip->addFile($jsonFile, $name.'.json');
				$zip->close(); 
				rename($zipTmpfile,$zipfile);
			}
			@unlink($jsonFile);
		}
		header('Content-Description: File Transfer');
		header('Content-type: application/zip');
		header('Content-Disposition: attachment; filename='.basename($zipfile));
		header('Content-Transfer-Encoding: binary');
		header('Expires: 0');
		header('Cache-Control: must-revalidate');
		header('Pragma: public');
		header('Content-Length: ' . filesize($zipfile));
		ob_clean();
		flush();
		echo file_get_contents($zipfile);
		fclose($handle);
		ob_flush();
		flush();
	}


	/**
	  * @method get  VIN解码
	  * @http  get
	  * @param  vin                string [必填] 17位车架号
	  * @author soul
	  * @copyright 2022/8/11
	  * @return 
		返回的label均不固定

		ypc:LFV3A28W2K3759614  LL66HAB04HB121003
		{"status":true,"data":{"from":"ypc","ads_make":"奥迪","model":[{"make_show_brand":"0","brand_id":"6","brand_name":"奥迪","make_name":"一汽奥迪","mod1_name":"A4L","mod2_name":"A4L(868,B9)","brand_etk_id":"10","mod3_id":"17026","mod3_name":"40 TFSI 进取型 国VI 19款","mod3_start_year":"2018","mod3_end_year":"2020","mod3_engine":"DKUA","mod3_kw":"140","mod3_cc":"1984","mod3_cc_name":"2.0T","mod3_transmission":"7DCT","mod3_fuel":"汽油","mod3_body":"4门5座三厢车","mod3_front_brake":"通风盘式","mod3_rear_brake":"盘式","mod3_parking_brake":"电子驻车","mod3_drive":"前置前驱","vin_year":"2019-05-09","vin_year_style":"buid","vin_year_name":"制造日期"}]},"code":0,"runtime":89}

		vinbase: LS5A2ABE0CA510728
		{"status":true,"data":{"from":"vinbase","model":[{"品牌":"依维柯","整车型号":"A3010XJJ","尺寸(mm)":"4850*2000*2490"}],"label":["品牌","整车型号","尺寸(mm)"],"ads_make":"依维柯"},"code":0,"runtime":153}

		bigcar:
		LS4A272P3DG001529
		{"status":true,"data":{"from":"bigcar","model":[{"mod_id":"8072@280456","mod_make":"长安牌","mod_name":"长安神童 幼儿专用校车 (SC6515XAG4)","mod_code":"SC6515XAG4","sma_engine":"JM491Q-ME","mod_tran":"MT","size":"5145*1975*2410","mod_drive":"后轮驱动"}],"label":{"mod_make":"品牌","mod_name":"车型","mod_code":"整车型号","sma_engine":"发动机","mod_tran":"变速箱","size":"尺寸(mm)","mod_drive":"驱动方式"},"ads_make":"长安牌"},"code":0,"runtime":164}

		LZZ1CLXB0HA180574
	    {"status":true,"data":{"from":"bigcar","model":[{"mod_id":"9268","mod_make":"中国重汽","mod_name":"中国重汽 HOWO-T7H重卡 440马力 6×4牵引车(ZZ4257V324HD1B)","mod_code":"ZZ4257V324HD1B"},{"mod_id":"9763","mod_make":"中国重汽","mod_name":"中国重汽 HOWO-T7H重卡 540马力6×4 牵引车(ZZ4257V324HD1B)","mod_code":"ZZ4257V324HD1B"},{"mod_id":"11974","mod_make":"中国重汽","mod_name":"中国重汽 HOWO-T7H 重卡440马力 6X4 牵引车 ZZ4257V324HD1B","mod_code":"ZZ4257V324HD1B"},{"mod_id":"13610","mod_make":"中国重汽","mod_name":"中国重汽 HOWO-T7H重卡 540马力 6×4牵引车(ZZ4257W324HE1B)","mod_code":"ZZ4257W324HE1B"}],"label":{"mod_make":"品牌","mod_name":"车型","mod_code":"整车型号"},"ads_make":"中国重汽"},"code":0,"runtime":139}

		oem:WBADT61000CE53527
		{"status":true,"data":{"from":"oem","oem":"bmw","model":[{"品牌":"宝马","车系":" 5' E39","车型":" 530I","年份":"1995-2003","发动机":" M54","功率":" 170kW","驱动":" 后驱","转向":" 左方向盘","车身":" 三厢轿车","区域":" 欧洲"}],"label":["品牌","车系","车型","年份","发动机","功率","驱动","转向","车身","区域"],"ads_make":"BMW","year":0},"code":0,"runtime":142}

		gxb:LM6AFABF0KX602898
		{"status":true,"data":{"from":"gxb","model":[{"品牌":"金杯","车系":"小海狮X30","车型":"2019款 1.5L 厢货标准型国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"小海狮X30","车型":"2019款 1.5L 厢货舒适型国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"小海狮X30","车型":"2019款 1.5L 标准型国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"小海狮X30","车型":"2019款 1.5L 舒适型国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.5L厢货商务版国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.5L厢货财富版国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.6L厢货商务版国VI SWD16M","前制动器":"盘式","发动机":"SWD16M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1599","功率(kW)":"85","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.6L厢货财富版国VI SWD16M","前制动器":"盘式","发动机":"SWD16M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1599","功率(kW)":"85","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.6L商务版六座国VI SWD16M","前制动器":"盘式","发动机":"SWD16M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1599","功率(kW)":"85","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.6L商务版国VI SWD16M","前制动器":"盘式","发动机":"SWD16M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1599","功率(kW)":"85","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.6L财富版六座国VI SWD16M","前制动器":"盘式","发动机":"SWD16M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1599","功率(kW)":"85","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮S","车型":"2019款 1.6L财富版国VI SWD16M","前制动器":"盘式","发动机":"SWD16M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1599","功率(kW)":"85","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮X30L","车型":"2019款 1.5L厢货商务版国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮X30L","车型":"2019款 1.5L厢货财富版国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮X30L","车型":"2019款 1.5L商务版国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"},{"品牌":"金杯","车系":"海狮X30L","车型":"2019款 1.5L财富版国VI SWC15M","前制动器":"盘式","发动机":"SWC15M","变速箱":"5挡手动","后制动器":"鼓式","排量(mL)":"1451","功率(kW)":"75","燃料":"汽油","驱动":"中置后驱"}],"label":["品牌","车系","车型","发动机","排量(mL)","功率(kW)","燃料","变速箱","驱动","前制动器","后制动器","驻车制动"],"ads_make":"金杯","year":2019},"code":0,"runtime":648}

		eur:1FALP53S3VA220419
		{"status":true,"data":{"from":"eur","model":[{"品牌":"Ford","车系":"Taurus","车型":"DP Ghia +LT &amp; CD Sedan 4dr Auto 4sp 3.0i","车型年":"1997","座位":"5\n\t","驱动方式":"Front Wheel Drive\n\t","燃料":"Petrol - Unleaded ULP\n\t","进气方式":"Aspirated\n\t","缸数":"6\n\t","发动机":"2967\n\t"},{"品牌":"Ford","车系":"Taurus","车型":"DP Ghia Sedan 4dr Auto 4sp 3.0i","车型年":"1997","座位":"5\n\t","驱动方式":"Front Wheel Drive\n\t","燃料":"Petrol - Unleaded ULP\n\t","进气方式":"Aspirated\n\t","缸数":"6\n\t","发动机":"2967\n\t"}],"label":["品牌","车系","车型","车型年","发动机","缸数","燃料","驱动方式","进气方式","座位"],"ads_make":"Ford","year":1997},"code":0,"runtime":142}

	    usa:137PH84346E221044
		{"status":true,"data":{"from":"usa","model":[{"品牌":"悍马","车型":"H1 ALPHA HMCS","年份":"2006"}],"label":["品牌","车型","年份"],"ads_make":"悍马","year":2006},"code":0,"runtime":128}
		
		wmi:1AMHATEDEC0009018
		{"status":true,"data":{"from":"wmi","model":[{"品牌":"AMERICAN MOTOR"},{"品牌":"AMC"}],"label":["品牌"],"ads_make":"AMERICAN MOTOR","year":2012},"code":0,"runtime":126}
	  */
	public function decodeVin()
	{
		$Params = mvc::$URL_PARAMS;
		$vin = $Params['vin'];
		$YpcVin = new YpcVin();
		$res = $YpcVin->decodeVin($vin);
		$YpcVin->tongjiVin($vin, $res['data']['from']);
		if(!empty($res['data']['model']))
		{
			$MainZyb = new MainZyb();
			$MainZyb->addFastComZybHistory('vin', $vin);
			$res['data']['vin'] = $vin;
		}
		unset($res['data']['modtype']);
		unset($res['data']['brand_name']);
		unset($res['data']['brand_id']);
		LibFc::EchoJson($res);
	}

	/**
	  * @method get  VIN解码
	  * @http  POST
	  * @param  image            string|file [必填] base64 图片信息 /9j/4AAQSkZJRgABAQAAAQA.....  base64_encode(file_get_contents('D:\www\ocr/ocr.jpg'))   或  multipart/form-data 二进制文件
	  * @demo  方式一：Base64 文本
	  *        imgdata  string  data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9Zf1sAAAAASUVORK5CYII=

	  *        方式二：multipart/form-data 二进制文件
	  *        imgdata  File    文件 
	  * @author soul
	  * @copyright 2022/8/11
	  * @return 
	  */
	public function decodeVinByImg()
	{
		$MainOcr = new MainOcr();
		$imgdata = LibFc::getImageBase64('image');
		$res = $MainOcr->vinCls($imgdata);
		if(!in_array($res['data'], ['mp', 'xsz','hgz', 'djzs'])) LibFc::ReturnJson(false, '非铭牌或者行驶证图', 'imgerr');
		$res = $MainOcr->vin($imgdata, $_POST);
		if(strlen($res['data']) == 17){
			$vin = $res['data'];
			$YpcVin = new YpcVin();
			$res = $YpcVin->decodeVin($vin);
			$YpcVin->tongjiVin($vin, $res['data']['from']);
			if(!empty($res['data']['model'])){
				$MainZyb = new MainZyb();
				$MainZyb->addFastComZybHistory('vin', $vin);
			}
			$res['data']['vin'] = $vin;
			unset($res['data']['modtype']);
			unset($res['data']['brand_name']);
			unset($res['data']['brand_id']);
			LibFc::EchoJson($res);
		}else{
			LibFc::ReturnJson(false, '图片无法识别车架号', 'novin');
		}
	}


	/**
	  * @method 图片识别vin
	  * @http  POST
	  * @param  image              string [必填] 图片内容的base64  /9j/4AAQSkZJRgABAQAAAQA.....  base64_encode(file_get_contents('D:\www\ocr/ocr.jpg')) 
	  * @author soul
	  * @copyright 2022/8/11
	  * @return {"status":true,"data":"LSGPC52H8FF219160","code":0,"runtime":109}
	  */
	public function vinOcr()
	{
		$MainOcr = new MainOcr();
		$res = $MainOcr->vin($_POST['image'], $_POST);
		$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('vinocr');
		LibFc::EchoJson($res);
	}
	
	/**
	  * @method 号码查询目录配件
	  * @http	get
	  * @param  number              string [必填] 自编号 或者 参考号码
	  * @param  page           int [选填] 第几页 默认 1
	  * @param  per            int [选填] 每页数量 默认 20
	  * @param  sort_id              int [选填] 店铺分类ID
	  * @author soul
	  * @copyright 2022/8/11
	  * @return {"status":true,"data":{"items":[{"pro_id":"517079","prb_name":"TKPA","part_name":"刹车片","pas_name":"前刹车片","pro_name":"奥迪Q5
Q5L前刹车片","pro_count":"1","pro_part_id":"4021","pri_code":"A-14454","pri_weight":"0.000","pro_sel_des":"更安全 更安静
更环保","pro_sale_price":"300.00","pro_price_vip1":"270.00","pro_price_vip2":"260.00","pro_price_vip3":"250.00","pro_price_vip4":"230.00","pic":["https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=product&f=shop149894\/product\/400\/19cd056da166f78c.jpg&i=f1"],"num":[{"factory":"TKPA","display":"A-14454","type":"zb"},{"factory":"OE","display":"80A
698 151 C","type":"main"}],"mod3_para":""}]},"code":0,"runtime":100}
	  */
	public function searchItemByNumber()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = ['items'=>[], 'total'=>0];
		$B2cSearch = new B2cSearch();
		$res = $B2cSearch->searchApiItem(mvc::$cfg['RQTOKEN']['uid'], $Params, $Params['per']);
		$arr['total'] = $res['data']['total'];
		if(!empty($res['data']['proIds']))
		{
			$B2cProduct = new B2cProduct();
			$res = $B2cProduct->getApiProductInfo(mvc::$cfg['RQTOKEN']['uid'], $res['data']['proIds'], ['numMain', 'picMain'], $Params['mod3_id']);
			$arr['items'] = array_values($res['data']);
		}
		$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('number', $Params['number']);
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 车型查询目录配件
	  * @http	get
	  * @param  mod3_id              int [必填] 车型ID
	  * @param  page           int [选填] 第几页 默认 1
	  * @param  per            int [选填] 每页数量 默认 20
	  * @param  sort_id              int [选填] 店铺分类ID
	  * @author soul
	  * @copyright 2022/8/11
	  * @return {"status":true,"data":{"items":[{"pro_id":"517079","prb_name":"TKPA","part_name":"刹车片","pas_name":"前刹车片","pro_name":"奥迪Q5
Q5L前刹车片","pro_count":"1","pro_part_id":"4021","pri_code":"A-14454","pri_weight":"0.000","pro_sel_des":"更安全 更安静
更环保","pro_sale_price":"300.00","pro_price_vip1":"270.00","pro_price_vip2":"260.00","pro_price_vip3":"250.00","pro_price_vip4":"230.00","pic":["https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=product&f=shop149894\/product\/400\/19cd056da166f78c.jpg&i=f1"],"num":[{"factory":"TKPA","display":"A-14454","type":"zb"},{"factory":"OE","display":"80A
698 151 C","type":"main"}],"mod3_para":"前轮"}]},"code":0,"runtime":140}
	  */
	public function searchItemByModel()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = ['items'=>[], 'total'=>0];
		$B2cSearch = new B2cSearch();
		$res = $B2cSearch->searchApiItem(mvc::$cfg['RQTOKEN']['uid'], $Params, $Params['per']);
		$arr['total'] = $res['data']['total'];
		if(!empty($res['data']['proIds']))
		{
			$B2cProduct = new B2cProduct();
			$res = $B2cProduct->getApiProductInfo(mvc::$cfg['RQTOKEN']['uid'], $res['data']['proIds'], ['numMain', 'picMain'], $Params['mod3_id']);
			$arr['items'] = array_values($res['data']);
		}
		$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('model', $Params['mod3_id']);
		LibFc::ReturnJson(true, $arr);
	}

	/**
	  * @method 配件详细信息
	  * @http	get
	  * @param  pro_id              int [必填] 配件ID
	  * @param  mod3_id             int [选填] 车型ID
	  * @author soul
	  * @copyright 2022/8/11
	  * @return {"status":true,"data":{"pro_id":"517079","prb_name":"TKPA","part_name":"刹车片","pas_name":"前刹车片","pro_name":"奥迪Q5
Q5L前刹车片","pro_count":"1","pro_part_id":"4021","pri_code":"A-14454","pri_weight":"0.000","pro_sel_des":"更安全 更安静
更环保","pro_sale_price":"300.00","pro_price_vip1":"270.00","pro_price_vip2":"260.00","pro_price_vip3":"250.00","pro_price_vip4":"230.00","pri_des":"
<p><img src=\"https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=adorn&f=shop149894\/adorn\/d081ee4a650495a3.jpg&i=f1\" title=\"d081ee4a650495a3.jpg\" alt=\"d081ee4a650495a3.jpg\"\/>
	<\/p>","para":[{"name":"制动系统","val":"Brembo","unit":""},{"name":"宽度","val":"135.7","unit":"mm"},{"name":"高度","val":"81","unit":"mm"},{"name":"厚度","val":"16.6","unit":"mm"}],"pic":["https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=product&f=shop149894\/product\/400\/19cd056da166f78c.jpg&i=f1"],"num":[{"factory":"TKPA","display":"A-14454","type":"zb"},{"factory":"OE","display":"80A
		698 151
		C","type":"main"}],"mod3_para":"前轮","numall":[{"oe":0,"factory":"A.B.S.","display":"35241"},{"oe":0,"factory":"BREMBO","display":"P
		85
		177"},{"oe":0,"factory":"BREMBO","display":"P85177N"},{"oe":0,"factory":"BREMSI","display":"BP3852"},{"oe":1,"factory":"OE","display":"80A
		698 151
		C"}],"models":["11222","11223","15377","15378","15379","15380","15381","15382","17027","17028","17029","17030","19147","19148","19149","19150","19151","19152"]},"code":0,"runtime":109}
	  */
	public function getItemInfo()
	{
		$Params = mvc::$URL_PARAMS;
		$pro_id = $Params['pro_id'];
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->getApiProductInfo(mvc::$cfg['RQTOKEN']['uid'], [$pro_id], ['numMain', 'picAll', 'desc', 'numAll', 'para', 'modelAll'], $Params['mod3_id']);
		$arr = empty($res['data'][$pro_id])? []: $res['data'][$pro_id];
		$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('item', $pro_id);
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method 获取所有商家编码
	  * @http	get
	  * @param  btime              int [选填] 开始时间（配件最后编辑时间） 2024-10-30 09:41:56
	  * @param  etime              int [选填] 结束时间（配件最后编辑时间） 2025-10-30 09:41:56
	  * @author soul
	  * @copyright 2024/3/28
	  * @return {"status":true,"data":{"pro_id":"517079","prb_name":"TKPA","part_name":"刹车片","pas_name":"前刹车片","pro_name":"奥迪Q5
Q5L前刹车片","pro_count":"1","pro_part_id":"4021","pri_code":"A-14454","pri_weight":"0.000","pro_sel_des":"更安全 更安静
更环保","pro_sale_price":"300.00","pro_price_vip1":"270.00","pro_price_vip2":"260.00","pro_price_vip3":"250.00","pro_price_vip4":"230.00","pri_des":"
<p><img src=\"https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=adorn&f=shop149894\/adorn\/d081ee4a650495a3.jpg&i=f1\" title=\"d081ee4a650495a3.jpg\" alt=\"d081ee4a650495a3.jpg\"\/>
	<\/p>","para":[{"name":"制动系统","val":"Brembo","unit":""},{"name":"宽度","val":"135.7","unit":"mm"},{"name":"高度","val":"81","unit":"mm"},{"name":"厚度","val":"16.6","unit":"mm"}],"pic":["https:\/\/file.paojd.cn\/center\/read.php?site=b2c&c=product&f=shop149894\/product\/400\/19cd056da166f78c.jpg&i=f1"],"num":[{"factory":"TKPA","display":"A-14454","type":"zb"},{"factory":"OE","display":"80A
		698 151
		C","type":"main"}],"mod3_para":"前轮","numall":[{"oe":0,"factory":"A.B.S.","display":"35241"},{"oe":0,"factory":"BREMBO","display":"P
		85
		177"},{"oe":0,"factory":"BREMBO","display":"P85177N"},{"oe":0,"factory":"BREMSI","display":"BP3852"},{"oe":1,"factory":"OE","display":"80A
		698 151
		C"}],"models":["11222","11223","15377","15378","15379","15380","15381","15382","17027","17028","17029","17030","19147","19148","19149","19150","19151","19152"]},"code":0,"runtime":109}
	  */
	public function getItemCodes()
	{
		$Params = mvc::$URL_PARAMS;
		$B2cProduct = new B2cProduct();
		$where = sprintf(" and pro_shop_id=%d", mvc::$cfg['RQTOKEN']['uid']);
		if($Params['btime']) $where .= sprintf(" and pro_set_time>=%d", strtotime($Params['btime']));
		if($Params['etime']) $where .= sprintf(" and pro_set_time<=%d", strtotime($Params['etime']));
		$table = 'bc_product
		JOIN bc_product_info ON pro_id = pri_pro_id
		JOIN bc_probrand ON prb_id = pro_prb_id';
		$res = $B2cProduct->get($table, ['pro_id, prb_name, pri_code'], $where);
		LibFc::EchoJson($res);
	}


	/**
	  * @method 新增或更新配件
	  * @http	post
	  * @param  pro_id              int [必填] 配件ID
	  * @author soul
	  * @copyright 2024/2/20
	  * @return {"status":true,"data":100,"code":0,"runtime":304}
	  */
	public function updateItem()
	{
		$pro_id = $_POST['pro_id'];
		$B2cProduct = new B2cProduct();
		$proArr = [$_POST];
		$res = $B2cProduct->updateItemByApi(mvc::$cfg['RQTOKEN']['uid'], $proArr);
		/*$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('item', $pro_id);*/
		LibFc::EchoJson($res);
	}


	/**
	  * @method 更新配件图片
	  * @http	post
	  * @param  pro_id              int [必填] 配件ID
	  * @param  images              string [必填] 图片内容的base64 json ["图片内容的base64","图片内容的base64"] 为空则清空
	  * @author soul
	  * @copyright 2024/2/20
	  * @return {"status":true,"data":100,"code":0,"runtime":304}
	  */
	public function updateItemImage()
	{
		$pro_id = $_POST['pro_id'];
		$B2cProduct = new B2cProduct();
		$dataArr = isset($_POST['images']) && empty($_POST['images'])? []: json_decode($_POST['images'], true);
		$res = $B2cProduct->updateItemImageByApi(mvc::$cfg['RQTOKEN']['uid'], $pro_id, $dataArr);
		/*$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('item', $pro_id);*/
		LibFc::EchoJson($res);
	}


	/**
	  * @method 更新配件车型
	  * @http	post
	  * @param  pro_id              int [必填] 配件ID
	  * @param  models             string [必填] [{"mod3_id":"10", "remark":"前左"}...]为空则清空
	  * @author soul
	  * @copyright 2024/2/20
	  * @return {"status":true,"data":100,"code":0,"runtime":304}
	  */
	public function updateItemModel()
	{
		$pro_id = $_POST['pro_id'];
		$B2cProduct = new B2cProduct();
		$modArr = [];
		foreach(json_decode($_POST['models'], true) as $v){
			$modArr[] = ['pml3_mod3_id'=>$v['mod3_id'], 'pml3_remark'=>$v['remark']];
		}
		$res = $B2cProduct->updateItemModelByApi(mvc::$cfg['RQTOKEN']['uid'], $pro_id, $modArr);
		/*$MainZyb = new MainZyb();
		$MainZyb->addFastComZybHistory('item', $pro_id);*/
		LibFc::EchoJson($res);
	}


	/**
	  * @method 删除配件
	  * @http	post
	  * @param  pro_ids  string [必填] 配件ID, 多个逗号分隔
	  * @author soul
	  * @copyright 2024/2/20
	  * @return {"status":true,"data":100,"code":0,"runtime":304}
	  */
	public function delteItem()
	{
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->delProduct(mvc::$cfg['RQTOKEN']['uid'], explode(',', $_POST['pro_ids']));
		LibFc::EchoJson($res);
	}


	/**
	  * @method get  获取机器人群列表
	  * @http  post
	  * @param  room_id			   string [选填] 指定群ID，多个英文逗号分隔，不指定则返回所有
	  * @author soul
	  * @copyright 2024/5/16
	  * @return {"status":true,"data":[{"wrr_room_id":"22631433078@chatroom","wrr_room_name":"机器人","wrr_info":{"avatar":"https:\/\/wx.qlogo.cn\/mmcrhead\/ia6Tg5xKL9rkSURz90CuXrDQFYtia4LaIMBDsJvdCyyLotSPP9D8QKvlSMMhMopQ1gJK44Brz6CoVYVo0eSoJRa3PduLGAmmzy\/0","id":"22631433078@chatroom","memberIdList":["wxid_2y89f9twgcpn22","wxid_mrpiqi4t8ems21"],"ownerId":"wxid_2y89f9twgcpn22","topic":"机器人"}}],"code":"","runtime":77}
	  */
	public function getRobotRooms()
	{
		$Params = mvc::$URL_PARAMS;
		$arr = [];
		$B2cBase = new B2cBase();
		$where = sprintf(" and wr_uid=%d", mvc::$cfg['RQTOKEN']['uid']);
		if(!empty($_POST['room_id'])){
			$tarr = [];
			foreach(explode(',', $_POST['room_id']) as $v){
				$tarr[] = LibFc::Escape($v);
			}
			$where .= sprintf(" and wrr_room_id in ('%s')", implode("','", $tarr));
		}
		$res = $B2cBase->get('wx_robot_room JOIN wx_robot ON wr_id = wrr_wr_id', ['wrr_room_id', 'wrr_room_name', 'wrr_info'], $where);
		foreach($res['data'] as $row)
		{
			$row['wrr_info'] = json_decode($row['wrr_info'], true);
			$arr[] = $row;
		}
		
		LibFc::ReturnJson(true, $arr);
	}



	/**
	  * @method get  号码匹配全车件模式车型
	  * @http  get
	  * @param  number			   string [必填] 号码 11138616793,11 41 8 612 615 多个号码用英文逗号分隔
	  * @author soul
	  * @copyright 2023/7/12
	  * @return {"status":true,"data":["4189","21007","6288"],"code":"","runtime":97}
	  */
	public function getModelByNumber()
	{
		$Params = mvc::$URL_PARAMS;
		$EtkNum = new EtkNum();
		$res = $EtkNum->getModelByNumber($Params['number'], 'all');
		$arr = $res['data'];
		if(!empty($arr)){
			$MainZyb = new MainZyb();
			$MainZyb->addFastComZybHistory('matchmod', $Params['number']);
        }
		LibFc::ReturnJson(true, $arr);
	}


	/**
	  * @method get  获取目录配件类别
	  * @http  get
	  * @author soul
	  * @copyright 2023/7/12
	  * @return {"status":true,"data":["4189","21007","6288"],"code":"","runtime":97}
	  */
	public function getPartTree()
	{
		$B2cProduct = new B2cProduct();
		$res = $B2cProduct->get('bc_part_tree JOIN bc_part ON pt_part_id=part_id', ['part_id, part_name, part_is_end, pt_parent_part_id'], " ORDER BY pt_path, pt_seq ASC");
		$arr = ['parts'=>$res['data'], 'parts_small'=>[]];
		$res = $B2cProduct->get('bc_part_small', ['pas_id, pas_part_id part_id, pas_name'], " ORDER BY pas_part_id, pas_seq ASC");
		$arr['parts_small'] = $res['data'];
		LibFc::ReturnJson(true, $arr);
	}

	/**
	  * @method get  获取车型的汽车品牌
	  * @http  get
	  * @author soul
	  * @copyright 2023/7/12
	  * @return {"status":true,"data":[{"brand_id":"210","brand_name":"AITO","brand_initial":"A"},{"brand_id":"135","brand_name":"埃安","brand_initial":"AA"},{"brand_id":"227","brand_name":"爱驰","brand_initial":"AC"},{"brand_id":"6","brand_name":"奥迪","brand_initial":"AD"}],"code":0,"runtime":64}
	  */
	public function getBrand()
	{
		$Ypc2Base = new Ypc2Base();
		$res = $Ypc2Base->get('bc_brand', ['brand_id, brand_name, brand_initial'], " ORDER BY brand_initial ASC");
		LibFc::EchoJson($res);
	}

	/**
	  * @method 获取公众号或者目录的分类
	  * @http	get
	  * @param  shopid              string [必填] 店铺ID
	  * @param  mod3_id             int [选填] 末级车型ID
	  * @param  number              string [选填] 号码
	  * @author soul
	  * @copyright 2019/7/22
	  * @return  
	  {"status":true,"data":{"spart":[{"spart_id":"4012_0","spart_name":"\u63a7\u5236\u81c2"},{"spart_id":"4935_0","spart_name":"\u7403\u5934"}],"sort":[{"sort_id":"7391","sort_name":"\u7403\u5934"},{"sort_id":"7392","sort_name":"\u524d\u5e73\u8861\u6746\u7403\u5934"},{"sort_id":"7393","sort_name":"\u6a2a\u62c9\u6746\u5916\u7403\u5934"},{"sort_id":"7394","sort_name":"\u6a2a\u62c9\u6746\u5185\u7403\u5934"},{"sort_id":"7396","sort_name":"\u540e\u5e73\u8861\u6746\u7403\u5934"},{"sort_id":"7398","sort_name":"\u63a7\u5236\u81c2"},{"sort_id":"7400","sort_name":"\u4e0b\u6446\u81c2"}]},"code":0}
	  */
	public function getSearchSort()
	{	
		$Params = mvc::$URL_PARAMS;
		$B2cSearch = new B2cSearch();
		$res = $B2cSearch->getSearchParts(mvc::$cfg['RQTOKEN']['uid'], $Params);
		$arr = $res['data']['sort'];
		LibFc::ReturnJson(true, $arr);
	}
}