<?php
/**
  * @method 
  * @author soul
  * @copyright 2016/3/31
  */
class TcdmItem extends TcdmBase
{
	/**
	  * @method 号码检测
	  * @param  $number array [{"factory":"OE","number":"008 420 06 20"},{"factory":"FMSI","number":"8920-D1694"}]
	  * @param  $Params = ['facseq'=>'TRW,FERODO,ATE,ICER','type'=>'tcd,etk'] 
	  * @author soul
	  * @copyright 
	  */
	public function checkNumberData($numArr, $Params = [])
	{
		ini_set('memory_limit', '1024M');
		$typeArr = empty($Params['type'])? ['tcd','etk'] : explode(',', $Params['type']);
		$arr = [];
		foreach($numArr as $k=>$v){
			if(empty($v['factory'])) $v['factory'] = '';
			$v['format'] = LibFc::FormatNum($v['number']);
			if(empty($v['format'])){
				unset($numArr[$k]);
				continue;
			}
			$numArr[$k] = $v;
		}
		if(empty($numArr)) return LibFc::ReturnData(true, $arr);
		$numstr = implode("','", array_column($numArr, 'format'));
		if(in_array('tcd', $typeArr)){
			//是否有明显错误的号码
			$res = $this->get('tof_article_number', ['arl_format, GROUP_CONCAT(distinct arl_art_id) art_ids'], sprintf(" and arl_format in ('%s') group by arl_format", $numstr));
			$trows = $res['data'];
			$errNum = [];
			foreach($trows as $k=>$v){
				$isok = true;
				foreach($trows as $kk=>$vv){
					if($k != $kk){
						$same = array_intersect(explode(",", $v['art_ids']), explode(",", $vv['art_ids']));
						if(empty($same)){
							$isok = false;
						}else{
							$isok = true;
						}
					}
				}
				if(!$isok) $errNum[] = $v['arl_format'];
			}
			
			if($errNum){
				$arr['errnum'] = [];
				foreach($numArr as $k=>$v){
					if(in_array($v['format'], $errNum)){
						$arr['errnum'][] = $v;
					}
				}
			}
			
			if($Params['facseq']){
				$facs = [];
				foreach(array_unique(explode(',', $Params['facseq'])) as $v){
					if(!empty($v)) $facs[] = LibFc::Escape($v);
				}
				$facstr = implode("','", $facs);
				$res = $this->get('tof_suppliers', ['sup_id'], sprintf(" and sup_brand in ('%s') ORDER BY FIELD(sup_brand, '%s')", $facstr, $facstr));
				$userSeqSupids = implode(',', array_column($res['data'], 'sup_id'));
			}

			$table = 'tof_article_number
			join tof_articles on art_id = arl_art_id
			join tof_generic_articles on ga_id = art_ga_id';
			$where = sprintf(" and arl_format in ('%s') and art_sup_id > 0 and ga_id > 0", $numstr);
			
			if($Params['ganame']){
				$names = [];
				$ganame = strtr($Params['ganame'],['；'=>';']);
				foreach(explode(';', $ganame) as $v){
					if(!empty($v)) $names[] = LibFc::Escape($v);
				}
				if(!empty($names)) $where .= sprintf(" and (ga_name in ('%s') or ga_name_cn in ('%s'))", implode("','", $names), implode("','", $names));
			}
			if($userSeqSupids) $where .= sprintf(" and art_sup_id in (%s)", $userSeqSupids);

			$res = $this->get($table, ['ga_name', 'ga_name_cn', 'group_concat(distinct art_sup_id) sup_ids', 'group_concat(distinct ga_id) ga_ids', 'group_concat(distinct arl_format) hasnum', 'count(distinct art_id) pro_count'], $where." group by ga_name order by count(*) desc");
			if(!empty($res['data'])){
				$tdata = [
					'from'=>'tcd',
					'ga_chk'=>$res['data']
				];
			
				//此品类下的配件
				foreach($tdata['ga_chk'] as &$ctv){
					if($userSeqSupids){
						$seqSupids = $userSeqSupids;
					}else{
						//确认厂商顺序
						$res = $this->get('tj_ga_sup join tof_suppliers on sup_id=gs_sup_id join ms_ga_sup_seq on gss_ga_id = gs_ga_id and gss_sup_id= sup_id', ['sup_id'], sprintf(" and gs_ga_id in (%s) and sup_id in (%s) group by sup_id order by gss_seq,sum(gs_count) desc limit 100", $ctv['ga_ids'], trim($ctv['sup_ids'], ',')));
						$seqSupids = implode(',', array_column($res['data'], 'sup_id'));
					}
					
					//按顺序找10个产品
					$table = 'tof_article_number
					join tof_articles on art_id = arl_art_id
					join tof_suppliers on sup_id = art_sup_id';
					$where = sprintf(" and arl_format in ('%s') and art_ga_id in (%s) and sup_id in (%s) group by art_id ORDER BY FIELD(sup_id, %s),  length(art_format) limit 10", 
						implode("','", explode(',', $ctv['hasnum'])), $ctv['ga_ids'], $seqSupids, $seqSupids);
					$res = $this->get($table, ['art_id pro_id', 'sup_brand pro_factory', 'art_number pro_number', 'art_url2', 'art_pic'], $where);
					$ctv['pros'] = [];
					foreach($res['data'] as $pv){
						$pv['pro_url'] = 'https://webcache.yiparts.com/item?c=cn_'.$pv['art_url2'];
						$pv['pro_img'] = $pv['art_pic']? $pv['art_pic'][0]['small']: '';
						$pv['pro_name'] = $ctv['ga_name'];
						unset($pv['art_url2']);unset($pv['art_pic']);
						$ctv['pros'][] = $pv;
					}
					unset($ctv['sup_ids']);
				}
				$arr['data']['tcd'] = $tdata;
			}
		}

		if(in_array('etk', $typeArr)){
			$res = $this->checkEpcData($numArr);
			if(!empty($res['data'])) $arr['data']['etk'] = $res['data'];
		}
		return LibFc::ReturnData(true, $arr);
	}


	private function checkEpcData($numArr){
		$pros = [];
		$OthNumber = new OthNumber();
		$LibEncry = new LibEncry();
		$type = 'etk';
		foreach($numArr as $v){
			if($v['factory'] != 'OE') continue;
			$pres = $OthNumber->search(['type'=>$type, 'word'=>$v['number'], 'islike'=>false]);
			if(empty($pres['data'][$type])) continue;
			foreach($pres['data'][$type] as $pv){
				$EpcItem = new EpcItem($pv['etk_id']);
				$res = $EpcItem->getItem($pv['pro_id'], $pv['grp2_id'], $pv['lnkId']);
				$data = $res['data'];
				$pro_uri =  sprintf("type=etk&proId=%d&etkId=%d&grp2Id=%d&lnkId=%s", $data['pro_id'], $data['etk_id'], $data['grp2_id'], (int) $data['lnk_id']);
				$pro_uri = base64_encode($LibEncry->encode($pro_uri));
				$realUrl = mvc::$cfg['HOST']['pjlpc'].'?goto='.urlencode(mvc::$cfg['HOST']['pjlpc'].'item/des?uri='.$pro_uri);
				
				//替换号
				$EtkNum = new EtkNum();
				$res = $EtkNum->getReplaceNumber($v['number']);
				$renums = $res['data'];
				$isnew = 0;
				if($renums) $isnew = $renums[0]['format'] == LibFc::FormatNum($data['display'])? 1: -1;
				$pros[$data['pro_id']] = [
					'pro_id'=>$data['pro_id'],
					'pro_url'=>$realUrl,
					'etk_id'=>$data['etk_id'],
					'grp2_id'=>$data['grp2_id'],
					'grp1_name'=>$data['grp1_name'],
					'grp2_name'=>$data['grp2_name'],
					'pro_name'=>$data['pro_name'],
					'pro_img'=>$data['pic']? $data['pic']: '',
					'num'=>[['factory'=>'OE', 'display'=>$data['display']]],
					'isnew'=>$isnew,
					'renum'=>array_column($renums, 'display')
				];
			}
		}
		$arr = [];
		if($pros){
			//替换号一样的多个产品只出其中一个
			if(count($pros) > 1){
				$uniArr = [];
				foreach($pros as $k=>$v){
					if($v['renum']){
						$unikey = implode(',', $v['renum']);
						$uniArr[$unikey][] = $k;
					}
				}

				foreach($uniArr as $unikey=>$ids){
					$ok = 0;
					foreach(explode(',', $unikey) as $num){
						$num = LibFc::FormatNum($num);
						foreach($ids as $id){
							if(LibFc::FormatNum($pros[$id]['num'][0]['display']) == $num){
								$ok = $id;
								break;
							}
						}
						if($ok) break;
					}
					if(!$ok) $ok = $ids[0];
					
					foreach($ids as $id){
						if($ok != $id) unset($pros[$id]);
					}
				}
			}
			$arr = [
				'from'=>'etk',
				'pros'=>array_values($pros)
			];
		}
		return LibFc::ReturnData(true, $arr);
	}



	/**
	  * @method 清洗具体产品数据
	  * @param  $number [号码、产品ID二选一] 号码
	  * @param  $facseq 竞品品牌优先级 TRW,BREMBO,REMSA
	  * @param  $art_id [号码、产品ID二选一] 指定产品ID
	  * @param  $rate_number 号码确认相同率 默认70
	  * @param  $rate_model  车型确认相同率 默认50
	  * @author soul
	  * @copyright 
	  */
	public function cleanData($Params)
	{
		ini_set('memory_limit', '1024M');
		define('TIMEDEBUG', false);
		$arr = [];
		$rateNum = !empty($Params['rate_number']) && $Params['rate_number'] <= 100 && $Params['rate_number'] > 0? (float) $Params['rate_number']: 70;
		$rateModel  = !empty($Params['rate_model']) && $Params['rate_model'] <= 100 && $Params['rate_model'] > 0? (float) $Params['rate_model']: 50;
		
		LibFc::runBegin('P100');
		$table = 'tof_article_number
		join tof_articles on art_id = arl_art_id
		join tof_suppliers on sup_id = art_sup_id
		join tof_generic_articles on ga_id = art_ga_id';
		if(!empty($Params['art_id'])){
			$where = sprintf(" and art_id=%d", $Params['art_id']);
			$artres = $this->get($table, ['art_id,art_cn_artid,sup_id,sup_brand,art_format,art_number,art_pic,ga_id,ga_name,ga_name_cn,sup_format,art_url2'], $where, true);
		}else{
			$number = $Params['number'];
			$formatNum = LibFc::FormatNum($number);
			if(strlen($formatNum) < 3) return LibFc::ReturnData(true, $arr);
			$facs = [];
			foreach(explode(',', $Params['facseq']) as $v){
				if(!empty($v)) $facs[] = $v;
			}
			if(empty($facs)){
				$res = $this->get('tof_article_number join tof_articles on art_id = arl_art_id', ['art_ga_id'], sprintf(" and arl_format = '%s' group by art_ga_id order by count(distinct art_id) desc limit 1", $formatNum));
				if(empty($res['data'])) return LibFc::ReturnData(true, $arr);
				$gaids = array_column($res['data'], 'art_ga_id');
				$res = $this->get('tj_ga_sup join tof_suppliers on sup_id=gs_sup_id join ms_ga_sup_seq on gss_ga_id = gs_ga_id and gss_sup_id= sup_id', ['sup_brand'], sprintf(" and gs_ga_id in (%s) group by sup_brand order by gss_seq,sum(gs_count) desc limit 100", implode(',', $gaids)));
				$facs = array_column($res['data'], 'sup_brand');
			}
			LibFc::runPoint('P100', '获取产品01');
			foreach($facs as $fac){
				$where = sprintf(" and arl_format = '%s' and sup_brand = '%s' GROUP BY art_id ORDER BY length(art_format) LIMIT 1", $formatNum, LibFc::Escape($fac));
				$artres = $this->get($table, ['art_id,art_cn_artid,sup_id,sup_brand,art_format,art_number,art_pic,ga_id,ga_name,ga_name_cn,sup_format,art_url2'], $where, true);
				LibFc::runPoint('P100', '产品'.$fac);
				if(!empty($artres['data'])) break;
			}
		}
		LibFc::runPoint('P100', '获取产品');
		if(empty($artres['data'])) return LibFc::ReturnData(true, $arr);
		$artArr = $artres['data'];
		$artArr['pro_url'] = 'https://webcache.yiparts.com/item?c=cn_'.$artArr['art_url2'];
		unset($artArr['art_url2']);

		//产品自编号外搜产品数，低于3个时不进行清洗判断，呈现原始数据即可  bra_format
		$res = $this->get('tof_brands', ['distinct bra_id'], sprintf(" and bra_format='%s'", $artArr['sup_format']));
		$artArr['brandids'] = array_column($res['data'], 'bra_id');
		$res = $this->get('tof_article_number', ['count(distinct arl_art_id) count'], sprintf(" and (arl_bra_id in (%s) or arl_sup_id in (%s)) and arl_format='%s'", implode(',', $artArr['brandids']), implode(',', $artArr['brandids']), $artArr['art_format']), true);
		$artArr['art_outcount'] = $res['data']['count'];
		$artArr['art_show'] = $artArr['art_outcount'] < 3? 'org': 'clean';
		$arr['pro'] = $artArr;
		$artId = $artArr['art_id'];

		//号码比较
		$res = $this->comOnlyNumByArt($artArr, $rateNum);
		$arr = array_merge($arr, $res['data']);
		
		//确定号码的ArtId数组
		$arr['oknum_artids'] = [];
		$typeArr = ['num', 'othnum'];
		foreach($typeArr as $type){
			foreach($arr[$type] as $key=>$row){
				if($row['ok']){
					$arr[$type.'_count_ok'] = $arr[$type.'_count_ok']? $arr[$type.'_count_ok']+1 : 1;
				}else{
					$arr[$type.'_count_no'] = $arr[$type.'_count_no']? $arr[$type.'_count_no']+1 : 1;
				}
				if($row['ok'] == 1 && $row['art_id'] > 0){
					$arr['oknum_artids'][]= $row['art_id'];
				}
			}
		}
		$arr['oknum_artids'] = array_unique($arr['oknum_artids']);
		sort($arr['oknum_artids']);
		$arr['oknum_artids_count'] = count($arr['oknum_artids']);
		LibFc::runPoint('P100', '号码比较');
		
		
		//产品车型
		$arr['model'] = [];
		$arr['model_oknum'] = [];
		$arr['model_oknum_count'] = 0;
		$arr['model_oknum_count_ok'] = 0;
		$arr['model_oknum_count_no'] = 0;
		$arr['ok_typids'] = [];
		$allArtids = array_merge([$artId], $arr['oknum_artids']);
		$res = $this->get('tof_article_types', ['lat_typ_id,lat_art_id'], sprintf(" and lat_art_id in (%s)", implode(',', $allArtids)));
		foreach($res['data'] as $v){
			if($v['lat_art_id'] == $artId){
				$arr['model'][$v['lat_typ_id']] = ['typ_id'=>$v['lat_typ_id'], 'ok'=>1];
				$arr['ok_typids'][] = $v['lat_typ_id']; 
			}
			//有可能来自主产品
			if(in_array($v['lat_art_id'], $arr['oknum_artids'])){
				if(!isset($arr['model_oknum'][$v['lat_typ_id']])){
					$arr['model_oknum'][$v['lat_typ_id']] = ['typ_id'=>$v['lat_typ_id'], 'artids'=>[$v['lat_art_id']]];
				}else if(!in_array($v['lat_art_id'], $arr['model_oknum'][$v['lat_typ_id']]['artids'])){
					$arr['model_oknum'][$v['lat_typ_id']]['artids'][] = $v['lat_art_id'];
				}
			}
		}
		//车型的安装位置
		$typPosArr = [];
		$posNames = ['Fitting Position'];

		//车型参数
		if($arr['model'] || $arr['model_oknum']){
			$where = sprintf(" and lac_art_id in (%s) order by cri_full_name", implode(',', $allArtids));
			$res = $this->get('tof_article_types_criteria join tof_criteria on lac_cri_id = cri_id', ["lac_art_id, lac_typ_id, cri_id, case when cri_name != '' then cri_name else cri_full_name end cri_name, cri_unit, lac_value, lac_kv"], $where);
			$allTypPara = [];
			foreach($res['data'] as $row){
				$value = !empty($row['lac_value'])? str_replace( ',', '.', $row['lac_value']):  trim($row['lac_kv']);
				$unit = !empty($row['cri_unit'])? $row['cri_unit']: '';
				$allTypPara[$row['lac_art_id']][$row['lac_typ_id']][] = ['name'=>trim($row['cri_name']), 'val'=>trim($value), 'unit'=>trim($unit)];
			}

			foreach($arr['model'] as $typId=>$typInfo){
				$typInfo['para'] = [];
				if(!empty($allTypPara[$artId][$typId])){
					$typInfo['para'] = $allTypPara[$artId][$typId];
					foreach($typInfo['para'] as $pav){
						if(in_array($pav['name'], $posNames)){
							$typPosArr[] = $pav['val'];
						}
					}
				}
				$arr['model'][$typId] = $typInfo;
			}
			
			foreach($arr['model_oknum'] as $typId=>$typInfo){
				$typInfo['rate'] = sprintf("%.2f", count($typInfo['artids'])/$arr['oknum_artids_count']*100);
				$typInfo['ok'] = $typInfo['rate'] >= $rateModel ? 1: 0;
				$typInfo['para'] = [];
				foreach($typInfo['artids'] as $tartid){
					if(!empty($allTypPara[$tartid][$typId])){
						$typInfo['para'] = $allTypPara[$tartid][$typId];
						if($typInfo['ok']){
							foreach($typInfo['para'] as $pav){
								if(in_array($pav['name'], $posNames)){
									$typPosArr[] = $pav['val'];
								}
							}
						}
						$typInfo['para_artid'] = $tartid;
						break;
					}
				}
				$typInfo['artidstr'] = implode(',', $typInfo['artids']);
				unset($typInfo['artids']);
				if($typInfo['ok']){
					$arr['ok_typids'][] = $typId;
					$arr['model_oknum_count_ok'] = $arr['model_oknum_count_ok']? $arr['model_oknum_count_ok']+1 : 1;
				}else{
					$arr['model_oknum_count_no'] = $arr['model_oknum_count_no']? $arr['model_oknum_count_no']+1 : 1;
				}
				$arr['model_oknum'][$typId] = $typInfo;
			}
		}
		$arr['ok_typids'] = array_unique($arr['ok_typids']);
		$arr['model'] = array_values($arr['model']);
		$arr['model_count'] = count($arr['model']);
		$arr['model_oknum'] = array_values($arr['model_oknum']);
		$arr['model_oknum_count'] = count($arr['model_oknum']);
		LibFc::runPoint('P100', '车型比较');
		
		//是否有位置参数
		$haspos = false;
		//参数
		if($artArr['art_cn_artid'] > 0){
			//尝试翻译
			$table = 'tof_article_criteria
			join tof_criteria on acr_cri_id = cri_id
			left join ms_replace_criteria on rc_cri_id = cri_id and acr_ga_id = rc_ga_id';
			$res = $this->get($table, ["case when cri_name != '' then cri_name else cri_full_name end cri_name, cri_name_cn, cri_unit"], sprintf(" and acr_art_id =%d group by cri_name_cn", $artId));
			$nameLink = array_column($res['data'], null, 'cri_name_cn');
			
			$TcdCnProduct = new TcdCnProduct();
			$res = $TcdCnProduct->getProductPara($artArr['art_cn_artid']);
			foreach($res['data'] as $row){
				$row['cn_name'] = $row['name'];
				if($nameLink[$row['cn_name']]){
					$row['name'] = $nameLink[$row['cn_name']]['cri_name'];
					$row['unit'] = $nameLink[$row['cn_name']]['cri_unit'];
				}
				if(in_array($row['name'], $posNames) || in_array($row['cn_name'], $posNames)){
					$haspos = true;
				}
				$arr['para'][] = $row;
			}
		}
		if(empty($arr['para'])){
			$table = 'tof_article_criteria
			join tof_criteria on acr_cri_id = cri_id
			left join ms_replace_criteria on rc_cri_id = cri_id and acr_ga_id = rc_ga_id';
			$res = $this->get($table, ["cri_id, case when cri_name != '' then cri_name else cri_full_name end cri_name, cri_name_cn, acr_value, cri_unit, acr_kv"], sprintf(" and acr_art_id =%d group by cri_id order by min(rc_seq)", $artId));
			foreach($res['data'] as $row){
				$value = !empty($row['acr_value'])? str_replace( ',', '.', $row['acr_value']):  trim($row['acr_kv']);
				$unit = !empty($row['cri_unit'])? $row['cri_unit']: '';
				$trow = ['name'=>trim($row['cri_name']),'cn_name'=>trim($row['cri_name_cn']), 'val'=>trim($value), 'unit'=>trim($unit)];
				if(in_array($trow['name'], $posNames) || in_array($trow['cn_name'], $posNames)){
					$haspos = true;
				}
				$arr['para'][] = $trow;
			}
		}
		
		$typPosArr = array_unique($typPosArr);
		if(!$haspos && count($typPosArr) == 1){
			$paras = [
				['name'=>'Fitting Position','cn_name'=>'安装位置', 'val'=>implode(',', $typPosArr), 'unit'=>'']
			];
			if(!$arr['para']){
				$arr['para'] = $paras;
			}else{
				$arr['para'] = array_merge($paras, $arr['para']);
			}
		}
		return LibFc::ReturnData(true, $arr);
	}


	/*
	<method>
		<name>ComOnlyNumByArt(比较号码)</name>
		<remark></remark>
		<exp.></exp.>
		<Parameter>
			<para name="ArtId" type="int">TCD产品ID</para>
			<para name="sameRate" type="float">相同率</para>
			<para name="sameFac" type="int">至少厂商数</para>
		</Parameter>
		type:0:promainnum  1:samerefnum 2:refnumrate  3:outcom  4:outcomref  chkpart  chkbrand  chkbrandlist
	</method>
	*/
	public function comOnlyNumByArt($artArr, $sameRate = 70, $sameFac = 3)
	{
		LibFc::runBegin('P10');
		$sameRate  = !empty($sameRate) && $sameRate <= 100 && $sameRate > 0? (float)$sameRate: 70;
		$sameFac  = !empty($sameFac) && $sameFac > 2 ? (int)$sameFac: 3;
	
		$allNumArr = ['num'=>[], 'othnum'=>[]];
		$artId = $artArr['art_id'];
		//厂商有重复
		$res = $this->get('tof_brands', ['GROUP_CONCAT(bra_id) bra_ids', 'bra_format'], ' GROUP BY bra_format');
		$brandToIds = [];
		foreach($res['data'] as $v){
			$brandToIds[$v['bra_format']] = explode(',', $v['bra_ids']);
		}

		//主号码
		$artArr['brandids'] = $brandToIds[$artArr['sup_format']];
		$artArr['unikey'] = $artArr['sup_format'].':'.$artArr['art_format'];
		$allNumArr['num'][] = [
			'brandids'=>$artArr['brandids'],
			'brand'=>$artArr['sup_brand'],
			'brandf'=>$artArr['sup_format'],
			'display'=>$artArr['art_number'],
			'format'=>$artArr['art_format'],
			'oe'=>'',
			'pic'=>$artArr['art_pic'],
			'ismain'=>1,
			'check'=>[['type'=>'promainnum', 'msg'=>'[0]产品主号码']],
			'ok'=>1,
			'art_id'=>$artId,
			'unikey'=>$artArr['unikey']
		];
		$allNumKeyArr[$artArr['unikey']] = 1;
		
		$formatArr = [$artArr['art_format']];
		
		//产品对照号
		$table = 'tof_article_number join tof_brands on arl_bra_id=bra_id';
		$where = sprintf(" and arl_art_id=%d and arl_kind in (2,3,4) order by bra_format, arl_format limit 100", $artId);
		$res = $this->get($table, ['bra_brand', 'bra_format', 'arl_number', 'arl_format', 'arl_kind'], $where);
		foreach($res['data'] as $v)
		{
			$unikey = $v['bra_format'].':'.$v['arl_format'];
			if(empty($v['arl_format']) || empty($brandToIds[$v['bra_format']]) || $allNumKeyArr[$unikey]) continue;
			$formatArr[] = $v['arl_format'];
			$allNumArr['num'][] = array(
				'brandids'=>$brandToIds[$v['bra_format']],
				'brand'=>$v['bra_brand'],
				'brandf'=>$v['bra_format'],	
				'display'=>$v['arl_number'],
				'format'=>$v['arl_format'],
				'oe'=>$v['arl_kind'] == 3 ? 'OE': '',
				'pic'=>'',
				'ismain'=>0,
				'check'=>[],
				'ok'=>0,
				'art_id'=>'',
				'unikey'=>$unikey
			);
			$allNumKeyArr[$unikey] = 1;
		}

		if($artArr['art_show'] == 'org') return LibFc::ReturnData(true, $allNumArr);

		//其他号码对应的产品ID
		$tempArtIdArr = [];
		$table = 'tof_articles JOIN tof_suppliers ON sup_id = art_sup_id';
		$where = sprintf(" and art_ga_id=%d  and art_format in ('%s') order by art_id", $artArr['ga_id'], implode("','", $formatArr));
		$res = $this->get($table, ['art_id,sup_brand,sup_format,art_number,art_format,art_pic'], $where);
		$unikeyToArt = [];
		foreach($res['data'] as $v){
			$unikeyToArt[$v['sup_format'].':'.$v['art_format']] = $v;
		}
		foreach($allNumArr['num'] as $k=>$v){
			if(empty($v['art_id']) && !empty($unikeyToArt[$v['unikey']])){
				$tart = $unikeyToArt[$v['unikey']];
				$tempArtIdArr[] = $tart['art_id'];
				$allNumArr['num'][$k]['art_id'] = $tart['art_id'];
				$allNumArr['num'][$k]['display'] = $tart['art_number'];
				$allNumArr['num'][$k]['pic'] = $tart['art_pic'];
			}
		}
		unset($unikeyToArt);

		//本产品主号码搜索出来的结果不存在于对照号的号码（其它号码）  1501223371
		$table = 'tof_article_number 
		join tof_articles ON arl_art_id = art_id
		left join tof_suppliers on sup_id = art_sup_id
		left join tof_brands on bra_id = arl_bra_id';
		$searchNumArr = [];
		$where = sprintf(" and arl_kind != 2 and ( bra_id in (%s) or arl_kind = 1) and arl_format = '%s' and art_ga_id = %d order by sup_format, art_format, art_id", implode(',', $artArr['brandids']), $artArr['art_format'], $artArr['ga_id']);
		$res = $this->get($table, ['art_id,sup_brand,sup_format,art_number,art_format,art_pic'], $where);
		foreach($res['data'] as $v)
		{
			$searchNumArr[] = ['brandf'=>$v['sup_format'], 'art_id'=>$v['art_id']];
			$unikey = $v['sup_format'].':'.$v['art_format'];
			if(empty($v['art_format']) || empty($brandToIds[$v['sup_format']]) || $allNumKeyArr[$unikey]) continue;
			$allNumArr['othnum'][] = array(
				'brandids'=>$brandToIds[$v['sup_format']],
				'brand'=>$v['sup_brand'],
				'brandf'=>$v['sup_format'],
				'display'=>$v['art_number'],
				'format'=>$v['art_format'],
				'oe'=>'',
				'pic'=>$v['art_pic'],
				'ismain'=>0,
				'check'=>[],
				'ok'=>0,
				'art_id'=>$v['art_id'],
				'unikey'=>$unikey
			);
			$tempArtIdArr[] = $v['art_id'];
			$allNumKeyArr[$unikey] = 1;
		}

		//所有ARTID的对照号
		$tempAllArtNumArr = [];
		if(!empty($tempArtIdArr)){
			$tempArtIdArr = array_unique($tempArtIdArr);
			$table = 'tof_article_number join tof_brands on arl_bra_id=bra_id';
			$where = sprintf(" and arl_art_id in (%s) and arl_kind in (2,3,4) order by arl_art_id, bra_format, arl_format", implode(',', $tempArtIdArr));
			$res = $this->get($table, ['arl_art_id art_id, bra_brand', 'bra_format', 'arl_number', 'arl_format', 'arl_kind'], $where);
			foreach($res['data'] as $v){
				$tempAllArtNumArr[$v['art_id']][] = $v;
			}
		}

		LibFc::runPoint('P10', '对照号');
		
		$noPartArtWhere = [];
		$numTempArr0 = [];
		foreach($allNumArr['num'] as $row){
			$numTempArr0[] = ['brandf'=>$row['oe'] == 'OE'?'OE':$row['brandf'], 'format'=>$row['format']];
		}
		
		foreach($allNumArr as $type=>$typeNumArr)
		{
			foreach($typeNumArr as $key=>$row)
			{
				$format = $row['format'];
				//ArtId=1955983 ["display"]=> string(2) "--"
				if(empty($format)) continue;

				$noPartArtWhere[] = sprintf("(art_format='%s' AND sup_format='%s')", $format, $row['brandf']);
				
				//产品主号码无须比较
				if($row['ok'] == 1) continue;

				$artIdTemp = $row['art_id'];
				if(!empty($row['oe']) || empty($row['art_id']) || empty($tempAllArtNumArr[$artIdTemp])) continue;
				$numTempArr = [['brandf'=>$row['oe'] == 'OE'?'OE':$row['brandf'], 'format'=>$row['format']]];
				$flag = true;
				foreach($tempAllArtNumArr[$artIdTemp] as $tv){
					$numTempArr[] = ['brandf'=>$tv['arl_kind'] == 3 ? 'OE': $tv['bra_format'], 'format'=>$tv['arl_format']];
					if($flag && $type == 'num' && $tv['bra_format'].':'.$tv['arl_format'] == $artArr['unikey']){
						$allNumArr[$type][$key]['check'][] = ['type'=>'samerefnum', 'msg'=>'[1]相互对应'];
						$flag = false;
					}
				}
				
				$TcdResTemp = $this->brandNumSameRate($numTempArr0, $numTempArr);
				$TcdResTemp = $TcdResTemp['data'];
				if($TcdResTemp['Rate'] >= $sameRate && $TcdResTemp['SameRate'] >= $sameRate && $TcdResTemp['SameBrand'] >= $sameFac){
					$allNumArr[$type][$key]['check'][] = ['type'=>'refnumrate', 'msg'=>'[2]各自的对照号对比', 'rate'=>$TcdResTemp['SameRate']];
					$allNumArr[$type][$key]['ok'] = 1;
					continue;
				}
			}
		}
		LibFc::runPoint('P10', '对照号比较');

		//外搜比较
		if(!empty($allNumArr['num'])){
			$type = 'num';
			foreach($allNumArr[$type] as $key=>$row){
				if(empty($row['format']) || $row['ok'] == 1 || empty($row['brandids'])) continue;
				if($row['oe'] == 'OE'){
					$where = sprintf(" and arl_kind = 3 and arl_format = '%s' and art_ga_id = %d ", $row['format'], $artArr['ga_id']);
				}else{
					$where = sprintf(" and arl_kind != 2 and (arl_bra_id in (%s) or arl_kind = 1) and arl_format = '%s' and art_ga_id = %d ", implode(',', $row['brandids']), $row['format'], $artArr['ga_id']);
				}
				$brand = $row['oe'] == 'OE'? 'OE': $row['brandf'];
				$searchNumTempArr = [];
				$table = 'tof_article_number
				join tof_articles on arl_art_id = art_id
				left join tof_suppliers on sup_id = art_sup_id';
				$res = $this->get($table, ['art_id', 'sup_format', 'art_format'], $where);
				foreach($res['data'] as $vv){
					$searchNumTempArr[$vv['art_id']] = ['brandf'=>$vv['sup_format'], 'format'=>$vv['art_format'], 'art_id'=>$vv['art_id']];
				}

				$TcdResTemp = $this->brandArtSameRate($searchNumArr, $searchNumTempArr);
				$TcdResTemp = $TcdResTemp['data'];
				if($TcdResTemp['Rate'] >= $sameRate && $TcdResTemp['SameRate'] >= $sameRate && $TcdResTemp['SameBrand'] >= $sameFac){
					$allNumArr[$type][$key]['check'][] = ['type'=>'outcom', 'msg'=>'[3]各自搜索出来的号码', 'rate'=>$TcdResTemp['SameRate']];
					$allNumArr[$type][$key]['ok'] = 1;
					continue;
				}
				
				//$searchNumTempArr与导入产品的对照号XX%以上对应,对应数在3以上;
				$TcdResTemp = $this->brandNumSameRate($allNumArr[$type], $searchNumTempArr);
				$TcdResTemp = $TcdResTemp['data'];
				if($TcdResTemp['Rate'] >= $sameRate && $TcdResTemp['SameRate'] >= $sameRate && $TcdResTemp['SameBrand'] >= $sameFac){
					$allNumArr[$type][$key]['check'][] = ['type'=>'outcomref', 'msg'=>'[4]此号搜索出来的号码与产品的对照号', 'rate'=>$TcdResTemp['SameRate']];
					$allNumArr[$type][$key]['ok'] = 1;
					continue;
				}
			}
		}
		LibFc::runPoint('P10', '搜索号结束');

		$noPartArtArr = array();
		if(!empty($noPartArtWhere)){
			$table = 'tof_articles 
			join tof_suppliers on sup_id = art_sup_id 
			join tof_generic_articles on ga_id = art_ga_id';
			$res = $this->get($table, ['art_id,sup_brand,art_format,art_number,ga_id,ga_name,ga_name_cn,sup_format'], sprintf(" and (%s)", implode(' or ', $noPartArtWhere)));
			foreach($res['data'] as $v){
				$noPartArtArr[$v['art_format'].'@'.$v['sup_format']][$v['art_id']] = $v;
			}
		}
		//补充产品ID
		$noArtIdNum = [];
		foreach($allNumArr as $type=>$typeNumArr){
			foreach($typeNumArr as $key=>$row){
				if(empty($row['art_id']) && empty($row['oe'])){
					$noArtIdNum[] = $row['format'];
				}
			}
		}
		if(!empty($noArtIdNum)){
			$noArtIdNum = array_unique($noArtIdNum);
			$table = 'tof_articles join tof_suppliers on sup_id = art_sup_id';
			$where = sprintf(" and art_format in ('%s') order by art_format, art_id", implode("','", $noArtIdNum));
			$res = $this->get($table, ['art_id,sup_format, art_format'], $where);
			$temp = [];
			foreach($res['data'] as $v){
				$temp[$v['sup_format'].':'.$v['art_format']] = $v['art_id'];
			}
			foreach($allNumArr as $type=>$typeNumArr){
				foreach($typeNumArr as $key=>$row){
					$unikey = $row['brandf'].':'.$row['format'];
					if(empty($row['art_id']) && empty($row['oe']) && $temp[$unikey]){
						$allNumArr[$type][$key]['art_id'] = $temp[$unikey];
					}
				}
			}
		}

		foreach($allNumArr as $type=>$typeNumArr)
		{
			foreach($typeNumArr as $key=>$row)
			{
				$unikey = $row['format'].'@'.$row['brandf'];
				if(!empty($noPartArtArr[$unikey])){
					$TempGa = array();
					foreach($noPartArtArr[$unikey] as $V){
						if($V['ga_id'] != $artArr['ga_id']){
							$TempGa[] = $V['ga_name_cn'];
						}
					}
					$TempGa = array_unique($TempGa);
					if(count($TempGa) > 0){
						$allNumArr[$type][$key]['check'][] = ['type'=>'chkpart', 'msg'=>'此号码零件存在歧义，可能为:'.implode('<br> 或者', $TempGa)];
						$allNumArr[$type][$key]['ok'] = 0;
					}
				}
				
				if(empty($row['art_id']) && empty($row['oe'])){
					$table = 'tof_article_number 
					join tof_articles on art_id=arl_art_id
					join tof_brands on arl_bra_id=bra_id';
					$res = $this->get($table, ['bra_brand, count(*) count'], sprintf(" and arl_format='%s' and art_ga_id=%d group by bra_brand order by count(*) desc", $row['format'], $artArr['ga_id']));
					$TempBrandCountArr = array_column($res['data'], 'count', 'bra_brand');
					$Flag = true;
					foreach($TempBrandCountArr as $KK=>$VV){
						if($Flag && $KK != $row['brand'] && $VV > $TempBrandCountArr[$row['brand']]){
							$allNumArr[$type][$key]['check'][] = ['type'=>'chkbrand', 'msg'=>'此号码品牌存在歧义，可能为:'.$KK];
							$allNumArr[$type][$key]['ok'] = 0;
							$Flag = false;
							break;
						}
					}
					
					if(!$Flag){
						foreach($TempBrandCountArr as $KK=>$VV){
							$brandArtId = 0;
							$Txt = '<div>'.$KK.'：'.$VV.'个。';
							if($KK != $row['brand']){//判断是否为产品
								$table = 'tof_articles 
								join tof_suppliers on sup_id = art_sup_id';
								$where = sprintf(" and sup_format='%s' and art_format='%s' and art_ga_id=%d", LibFc::FormatNum($KK), $row['format'], $artArr['ga_id']);
								$res = $this->get($table, ['art_id,art_format,art_number'], $where, true);
								if(!empty($res['data'])){
									$brandArtId = $res['data']['art_id'];
									$Txt .= $KK.':'.$res['data']['art_number'].'是一个产品。'; 
								}
							}
							$allNumArr[$type][$key]['check'][] = ['type'=>'chkbrandlist', 'msg'=>$Txt, 'brand'=>$KK, 'brandArtId'=>$brandArtId];
						}
					}
				}
			}
		}
		LibFc::runPoint('P10', '歧义检测结束');
		LibFc::runPoint('P10', '号码检测完成');
		return LibFc::ReturnData(true, $allNumArr);
	}

	
	private function __UniqueNumArr($NumArr)
	{
		$Temp = array();
		foreach($NumArr as $K=>$V)
		{
			$Key = $V['brandf'].'@'.$V['format'];
			if(in_array($Key, $Temp)){
				unset($NumArr[$K]);
			}else{
				$Temp[] = $Key;
				$NumArr[$K]['key'] = $Key;
			}
		}
		return $NumArr;
	}

	public function brandNumSameRate($NumArr,$NumArrTmp)
	{
		$NumArr = self::__UniqueNumArr($NumArr);
		$NumArrTmp = self::__UniqueNumArr($NumArrTmp);
		$SameBrandArr = []; $BrandTempArr = [];
		foreach($NumArr as $V){
			$Brand = $V['brandf'];
			$NumKeyArr[] = $Brand.'@'.$V['format'];
			if(empty($BrandArr[$Brand])){
				$BrandArr[$Brand] = 1;
			}else{
				$BrandArr[$Brand]++;
			}
		}
		
		$SameCount = 0;
		foreach($NumArrTmp as $VV){
			$Brand = $VV['brandf'];
			if(array_key_exists($Brand, $BrandArr)){
				if(empty($BrandTempArr[$Brand])){
					$BrandTempArr[$Brand] = 1;
				}else{
					$BrandTempArr[$Brand]++;
				}
			}
			if(in_array($Brand.'@'.$VV['format'], $NumKeyArr)){
				$SameCount++;
				if(empty($SameBrandArr[$Brand])){
					$SameBrandArr[$Brand] = 1;
				}else{
					$SameBrandArr[$Brand]++;
				}
			}
		}
		$AllNumCount = 0;
		foreach($BrandTempArr as $K=>$V){
			$AllNumCount += $V+$BrandArr[$K];
		}

		//号码相同的零件商/相同的零件商
		$Arr['Rate']= sprintf("%.2f", count($SameBrandArr)/count($BrandTempArr)*100);
		//相同率
		$Arr['SameRate']= sprintf("%.2f", $SameCount*2/$AllNumCount*100);
		//号码相同的零件商
		$Arr['SameBrand']=count($SameBrandArr);
		return LibFc::ReturnData(true, $Arr);
	}


	public function brandArtSameRate($SearchNumArr, $SearchNumTempArr)
	{
		foreach($SearchNumArr as $V){
			$Brand = trim($V['brandf']);
			$SearchArtIdArr[] = $V['art_id'];
			if(empty($BrandArr[$Brand])){
				$BrandArr[$Brand] = 1;
			}else{
				$BrandArr[$Brand]++;
			}
		}
		$SameCount = 0;
		foreach($SearchNumTempArr as $VV){
			$Brand = trim($VV['brandf']);
			if(array_key_exists($Brand, $BrandArr)){
				if(empty($BrandTempArr[$Brand])){
					$BrandTempArr[$Brand] = 1;
				}else{
					$BrandTempArr[$Brand]++;
				}
			}
			if(in_array($VV['art_id'], $SearchArtIdArr)){
				$SameCount++;
				if(empty($SameBrandArr[$Brand])){
					$SameBrandArr[$Brand] = 1;
				}else{
					$SameBrandArr[$Brand]++;
				}
			}
		}
		
		$AllNumCount = 0;
		foreach($BrandTempArr as $K=>$V){
			$AllNumCount += $V+$BrandArr[$K];
		}
		
		//号码相同的零件商/相同的零件商
		$Arr['Rate']= sprintf("%.2f", count($SameBrandArr)/count($BrandTempArr)*100);
		//相同率
		$Arr['SameRate']= sprintf("%.2f", $SameCount*2/$AllNumCount*100);
		//号码相同的零件商
		$Arr['SameBrand']=count($SameBrandArr);
		return LibFc::ReturnData(true, $Arr);
	}

	//号码比较
	public function compareNum($numArr = [], $artids = '', $type = '', $ga_id = 0)
	{
		foreach($numArr as $k=>$v){
			if(empty($v['factory'])) $v['factory'] = '';
			$v['format'] = LibFc::FormatNum($v['number']);
			if(empty($v['format'])){
				unset($numArr[$k]);
				continue;
			}
			$numArr[$k] = $v;
		}
	
		if(!empty($numArr)){
			foreach($numArr as $k=>$v){
				//是否为产品
				if($type !== 'out' && !empty($v['factory']) && strtoupper($v['factory']) != 'OE'){
					$where = sprintf(" and art_format = '%s'", $v['format']);
					if(!empty($v['factory'])) $where .= sprintf(" and sup_brand = '%s'", LibFc::Escape($v['factory']));
					if($ga_id) $where .= sprintf(" and art_ga_id = %d", $ga_id);
					$res = $this->get('tof_articles join tof_suppliers on sup_id = art_sup_id', ['art_id'], $where.' group by art_id limit 1', true);
					if(!empty($res['data'])){
						$res = $this->getComArtInfo($res['data']['art_id'], ['nums', 'para', 'model']);
						$numArr[$k] = $res['data'];
						continue;
					}
				}
				
				$where = '';
				if($ga_id) $where .= sprintf(" and art_ga_id = %d", $ga_id);
				if($type !== 'out' && !empty($v['factory'])) $where .= strtoupper($v['factory']) == 'OE'? ' and arl_kind=3': sprintf(" and sup_brand = '%s'", LibFc::Escape($v['factory']));
				$where .= sprintf(" and arl_format = '%s' GROUP BY sup_format, art_format order by sup_format, art_format", $v['format'], LibFc::Escape($fac));
				$table = 'tof_article_number 
				join tof_articles ON arl_art_id = art_id
				left join tof_suppliers on sup_id = art_sup_id
				left join tof_brands on bra_id = arl_bra_id';
				$tres = $this->get($table, ['sup_brand,art_format,art_number,sup_format'], $where);
				$v['nums'] = [];
				foreach($tres['data'] as $tv){
					$unikey = $tv['sup_format'].':'.$tv['art_format'];
					$v['nums'][] = ['factory'=>$tv['sup_brand'],'number'=>$tv['art_number'], 'unikey'=>$unikey];
				}
				$numArr[$k] = $v;
			}
		}
	
		foreach(explode(',', $artids) as $artid){
			$res = $this->getComArtInfo($artid, ['nums', 'para', 'model']);
			if(!empty($res['data'])){
				$numArr[] = $res['data'];
			}
		}
		return LibFc::ReturnData(true, $numArr);
	}


	//号码检测
	public function chkNumBase($numArr, $mainfac)
	{
		foreach($numArr as $k=>$v){
			if(empty($v['factory'])) $v['factory'] = '';
			$v['format'] = LibFc::FormatNum($v['number']);
			if(empty($v['format']) || empty($v['factory'])){
				unset($numArr[$k]);
				continue;
			}
			$numArr[$k] = $v;
		}
	
		if(!empty($numArr)){
			$cache = [];

			$mainfacSql = [];
			foreach(explode(',', $mainfac) as $v){
				if($v) $mainfacSql[] = sprintf("'%s'", LibFc::Escape($v));
			}

			foreach($numArr as $k=>$v){
				$artids = [];
				$v['pros'] = [];
				if(strtoupper($v['factory']) == 'OE'){
					//通过重点竞品品牌找
					if($mainfacSql){
						$where = sprintf(" and sup_brand in (%s) and art_id in (
						select distinct arl_art_id from tof_article_number where arl_kind = 3 and arl_format='%s') group by sup_brand, art_format", implode(',', $mainfacSql), $v['format']);
						$res = $this->get('tof_articles join tof_suppliers on sup_id = art_sup_id', ['art_id'], $where);
						$artids = array_column($res['data'], 'art_id');
					}
				}else{
					//是否为产品
					$where = sprintf(" and sup_brand='%s' and art_format='%s'", LibFc::Escape($v['factory']), $v['format']);
					$res = $this->get('tof_articles join tof_suppliers on sup_id = art_sup_id', ['art_id'], $where.' group by art_id limit 1');
					if(!empty($res['data'])){
						$artids = array_column($res['data'], 'art_id');
					}else if($mainfacSql){
						$where = sprintf(" and sup_brand in (%s) and art_id in (
						select distinct arl_art_id from tof_article_number
						join tof_brands on bra_id = arl_bra_id where bra_brand='%s' and arl_format='%s'
						) group by sup_brand, art_format", implode(',', $mainfacSql), LibFc::Escape($v['factory']), $v['format']);
						$res = $this->get('tof_articles join tof_suppliers on sup_id = art_sup_id', ['art_id'], $where);
						$artids = array_column($res['data'], 'art_id');
					}
				}
				foreach($artids as $art_id){
					if(empty($cache[$art_id])){
						$res = $this->getComArtInfo($art_id, ['para']);
						$cache[$art_id] = $res['data'];
					}
					$v['pros'][] = $cache[$art_id];
				}
				$numArr[$k] = $v;
			}
		}
		return LibFc::ReturnData(true, $numArr);
	}


	//号码检测
	public function chkOneNumBase($number, $factory = '', $ganame = '')
	{
		$arr = [];
		$where = sprintf(" and art_format = '%s'", LibFc::FormatNum($number));
		if(!empty($factory)) $where .= sprintf(" and sup_brand = '%s'", LibFc::Escape($factory));
		
		$names = [];
		$ganame = strtr($ganame,['；'=>';']);
		foreach(explode(';', $ganame) as $v){
			if(!empty($v)) $names[] = LibFc::Escape($v);
		}
		if(!empty($names)) $where .= sprintf(" and (ga_name in ('%s') or ga_name_cn in ('%s'))", implode("','", $names), implode("','", $names));

		$res = $this->get('tof_articles join tof_suppliers on sup_id = art_sup_id JOIN tof_generic_articles ON ga_id=art_ga_id', ['art_id'], $where.' group by art_id limit 1', true);
		if(!empty($res['data'])){
			$res = $this->getComArtInfo($res['data']['art_id'], ['para']);
			$arr = $res['data'];
		}
		return LibFc::ReturnData(true, $arr);
	}

	private function getComArtInfo($artid, $type = ['nums', 'para']){
		$arr = [];
		$res = $this->get('tof_articles JOIN tof_suppliers ON sup_id = art_sup_id join tof_generic_articles on ga_id = art_ga_id', ['art_id', 'ga_name name', 'art_url2 url', 'sup_brand factory', 'art_number number', 'art_format format', 'art_pic', 'art_cn_artid'], sprintf(" and art_id=%d", $artid), true);
		if(!empty($res['data'])){
			$arr = $res['data'];
			$arr['pic'] = [$arr['art_pic'][0]];
			$arr['url'] = 'https://webcache.yiparts.com/item?c=cn_'.$arr['url'];
			unset($arr['art_pic']);
			$table = 'tof_article_number left join tof_brands on arl_bra_id=bra_id';
			$where = sprintf(" and arl_art_id=%d and arl_kind in (3,4) group by factory, arl_format", $artid);
			$tres = $this->get($table, ["case when arl_kind = 3 then 'OE' else bra_brand end factory", 'arl_number', 'arl_format'], $where);
			if(in_array('nums', $type)){
				$arr['nums'] = [];
				foreach($tres['data'] as $tv){
					$unikey = $tv['factory'].':'.$tv['arl_format'];
					$arr['nums'][] = ['factory'=>$tv['factory'],'number'=>$tv['arl_number'], 'unikey'=>$unikey];
				}
			}
			//参数
			if(in_array('para', $type)){
				$arr['para'] = [];
				if($arr['art_cn_artid'] > 0){
					$TcdCnProduct = new TcdCnProduct();
					$res = $TcdCnProduct->getProductPara($arr['art_cn_artid']);
					foreach($res['data'] as $row){
						$row['cn_name'] = $row['name'];
						$arr['para'][] = $row;
					}
				}
				unset($arr['art_cn_artid']);
				if(empty($arr['para'])){
					$table = 'tof_article_criteria
					join tof_criteria on acr_cri_id = cri_id
					left join ms_replace_criteria on rc_cri_id = cri_id and acr_ga_id = rc_ga_id';
					$res = $this->get($table, ["cri_id, case when cri_name != '' then cri_name else cri_full_name end cri_name, cri_name_cn, acr_value, cri_unit, acr_kv"], sprintf(" and acr_art_id =%d group by cri_id order by min(rc_seq)", $artid));
					foreach($res['data'] as $row){
						$value = !empty($row['acr_value'])? str_replace( ',', '.', $row['acr_value']):  trim($row['acr_kv']);
						$unit = !empty($row['cri_unit'])? $row['cri_unit']: '';
						$arr['para'][] = ['name'=>trim($row['cri_name']),'cn_name'=>trim($row['cri_name_cn']), 'val'=>trim($value), 'unit'=>trim($unit)];
					}
				}
			}

			if(in_array('model', $type)){
				$res = $this->get('tof_article_types', ['lat_typ_id'], sprintf(" and lat_art_id =%d", $artid));
				$arr['model'] = array_column($res['data'], 'lat_typ_id');
			}
		}
		return LibFc::ReturnData(true, $arr);
	}


	function artNumber($artIdArr)
	{
		$arr = [];
		$artIdArr = array_unique(array_map('intval', $artIdArr));
		if(!empty($artIdArr)){
			$res = $this->get('tof_articles JOIN tof_suppliers ON sup_id = art_sup_id', ['art_id', 'sup_brand factory', 'art_number number'], sprintf(" and art_id in (%s) order by sup_brand, art_format limit 200", implode(',', $artIdArr)));
			$arr = $res['data'];
		}
		return LibFc::ReturnData(true, $arr);
	}
}