<?php
/**
 * [UQcms System] Copyright uqcms.com
 * QQ: 2200631718
 * Author: gj.name
 * This is NOT a freeware
*/
defined('IN_UQ') or exit('Access Denied'); class category_attr_mod extends module { function __construct(){ parent::__construct(); } public function get_list($cid, $gcid = ''){ $query = $this->db->query("select * from ".table('category')); while($row = $this->db->fetch_array($query)){ $gcats[$row['id']] = $row['name']; } if(!empty($gcid)){ $gcid = 'and cid = '.$gcid; }else{ $gcid_where = ''; } $cquery = $this->db->query("select * from ".table('category_attr')." where pid = ".$id." ".$cid); while($crow = $this->db->fetch_array($cquery)){ $crow['gcname'] = $gcats[$crow['cid']]; $data[] = $crow; } return @$data; } function get_attr($cid){ if($cid){ $tQuery = $this->db->get_all("select * from ".table('category_attr')." where cid in(".$cid.") "); if($tQuery){ foreach($tQuery as $k=>$v){ $allCid[] = $v['id']; } if(isset($allCid)){ $allCid = implode(',', $allCid); $detailQuery = $this->db->get_all("select * from ".table('category_attr')." where pid in (".$allCid.") "); if($detailQuery){ foreach($detailQuery as $tk=>$tv){ $ddata[$tv['pid']][] = $tv; } foreach($tQuery as $k=>$v){ $v['p_attr'] = $ddata[$v['id']]; $data[] = $v; } return $data; } } } }else{ return false; } } public function get_one($id){ return $this->db->get_one("select * from ".table("category_attr")." where id = ".$id); } public function attr_list($arr){ $cid = isset($arr['cid'])?$arr['cid']:''; if($cid){ if(cfg('attr_last_show')){ $cid_arr = $this->module('category')->get_child_cid($cid); if($cid_arr){ $cid_in = implode(',', $cid_arr); }else{ $cid_in = $cid; } $wsql = 'cid in ('.$cid_in.')'; }else{ $wsql = 'cid = '.$cid; } $tAll = $this->db->get_all("select id,pid,cid,name,px,status from ".table('category_attr')." where ".$wsql." and status = 1 order by px desc"); if($tAll){ foreach($tAll as $k=>$v){ $attr_arr[] = $v; $attr_top[] = $v['id']; } if($attr_top){ $attr_top_in = implode(',', $attr_top); $pQuery = $this->db->query("select id,pid,cid,name,px,status from ".table('category_attr')." where pid in (".$attr_top_in.") and status = 1"); while($pRow = $this->db->fetch_array($pQuery)){ $pRowData[$pRow['pid']][] = $pRow; $pRowDataDiff[$pRow['pid']][] = $pRow['id']; $tRowData[$pRow['id']][] = $pRow; } $attr = !empty($arr['attr'])?$arr['attr']:false; $ccc = explode(',',$attr); $attrCount = count($attr_arr); for($i=0; $i<$attrCount; $i++){ if(isset($pRowDataDiff[$attr_arr[$i]['id']])){ $attr_arr[$i]['pattr'] = $pRowData[$attr_arr[$i]['id']]; $attrDiffId = array_diff($ccc, $pRowDataDiff[$attr_arr[$i]['id']]); $last_attr_id = implode(',', $attrDiffId); $attr_arr[$i]['uri_attr'] = $last_attr_id; $last_attr_id = $last_attr_id.','; $last_attr_id = ltrim($last_attr_id, ','); $attr_arr[$i]['uri_public'] = $last_attr_id; $pRowDataDiffArr = $pRowDataDiff[$attr_arr[$i]['id']]; $diffArr = array_intersect($ccc, $pRowDataDiffArr); if(count($diffArr) == '0'){ $data['list'][] = $attr_arr[$i]; } unset($pRowData[$attr_arr[$i]['id']]); unset($pRowDataDiff[$attr_arr[$i]['id']]); } } if($ccc){ foreach($ccc as $v){ if($v){ $mkAttrUrl = ''; foreach($ccc as $vs){ if($vs != $v){ $mkAttrUrl .= $vs.','; } } $mkAttrUrl = trim($mkAttrUrl,','); $bqattr[] = array( 'name'=>$tRowData[$v][0]['name'], 'id'=>$v, 'url_id'=>$mkAttrUrl ); } } $data['ch'] = $bqattr; } return $data; } } } } }