<?php
/*
可操作内容
$pd = model\pdflib\pdfData

$cateStyle,$cateTitle,$cateRemark,$cateList,$cateArea,$cateVer,
$type,$typeName,$cols,
$id,$code,$key,$name,$title,$remark,$tplCates,$jsonArr,$hasIndex

*/

// 轮毂参数排版-Hub Assemblies
if(empty($tplCates)) msgJson($name.' 未绑定品名');

$sql = <<<EOF
SELECT
p_id,
p_seq seq,
p_cate,
p_outnum outnum,
cate.en_name catename
%s
FROM pro
JOIN pro_cate cate ON p_cate = cate.id
%s
WHERE p_state_main IN ($dataVer) AND p_cate IN ($tplCates) %s
%s
%s
EOF;

/** G 品牌*/
if($gspband=='g'){
$sql = <<<EOF
SELECT
p_id,
p_seq seq,
p_cate,
num.pn_number outnum,
cate.en_name catename
%s
FROM pro
JOIN pro_cate cate ON p_cate = cate.id
JOIN pro_numidx num ON num.pn_p_id = p_id AND num.pn_pf_id = $g_brand_id
%s
WHERE p_state_main IN ($dataVer) AND p_cate IN ($tplCates) %s
%s
%s
EOF;
}//G 品牌


/***********************************************************/
$fileds = '';
$join = '';
$where = '';
$group = '';
$order = 'ORDER BY p_outnum';
if(!empty($cateVer)){
	$join = " JOIN tags_link ON p_id=tl_value_id AND tl_type='pro'";
	if($cateVer=="2") $join .= "JOIN p_code ON pc_p_id = p_id AND (pc_release_vers='' OR CONCAT(',',pc_release_vers,',') like '%,".$newVerName.",%')";
	$where = sprintf("AND tl_t_id > tl_t_id ^ %d",$cateVer);
}
$sql = sprintf($sql,$fileds,$join,$where,$group,$order);
/***********************************************************/

$items = [];
$rows  = $pd->db->query($sql)->fetchAll(PDO::FETCH_ASSOC);
$colRegI = 1;
foreach($rows as &$row){
	$params = $pd->getProParamValue($row['p_cate'],$row['p_id'],$code,[
		'A','B','C','H','L','P',
	]);
	$hasValue = '';
	foreach($params as $v){
	    $v = trim($v);
	    if(!empty($v)) $hasValue .= $v;
	}
	if($hasValue=='') continue;

	array_push($items,[
		'col1'=> sprintf("%s",$row['catename']),
		'col2'=> sprintf("%s",$row['outnum']),

		'col3'=> $this->formartDecimal1($params['A']),
		'col4'=> $this->formartDecimal1($params['B']),
		'col5'=> $this->formartDecimal1($params['C']),
		'col6'=> $this->formartDecimal1($params['H']),
		'col7'=> $this->formartDecimal1($params['L']),
		'col8'=> $this->formartDecimal1($params['P']),
	]);
	$colRegI++;
	if(!in_array($row['outnum'], $numbers)) $numbers[] = $row['outnum'];
}
$items = array_column($items,null);

$data = [
	'style' => 'propellerShaftByDrive',
	'title' => $title,
	'remark' => $remark,
	'compute' => $hasIndex, // 是否需要计算页码
	'value' => $items
];
return !empty($items) ? $data : [];