<?php

$arr =array(
	'xiantao'=>array('市辖区')
	//'xiantao'=>array('孝南城区','开发东区','开发西区','孝南乡镇')
	,'xiaogan'=>array('孝南城区','开发东区','开发西区','孝南乡镇')
	,'xianning'=>array('市城区','乡镇')
	,'tianmen'=>array('竟陵','侨乡开发区','仙北工业园')
	,'suizhou'=>array('市城区')
);

$quyu ='';
if($cfg_ml->get_site_setting('pinyin')=='xiaogan' or $cfg_ml->get_site_setting('pinyin')=='xianning'){
	$quyu = "  and locality ='".iconv('UTF-8','gbk','全市')."' ";
}
switch ($cfg_ml->get_site_setting('pinyin')){
	case 'xiantao'  :  $limitSql = "  limit 0,32   ";break;
	case 'xiaogan'  :  $limitSql = "  limit 0,32  ";break;
	case 'xianning' :  $limitSql = "  limit 0,32   ";break;
	case 'tianmen'  :  $limitSql = "  limit 0,96  ";break;

}

function XmlQuYuFun($str,$upMonArr,$area){
	//使用dom生成xml,注意生成的xml中会没有空格。	
		$dom=new DOMDocument('1.0','utf-8');
		//$path="../fw_nav/".$cfg_ml->get_site_setting('pinyin')."/".$str.".xml";     //  $path 为xml文件的存储路径。
		$path="gonggong/".$area."/".$str.".xml";     //  $path 为xml文件的存储路径。
		$chart = $dom->createElement("chart");
		$dom->appendChild($chart);
		
		//生成区域
		$series = $dom->createElement("series");
		$chart->appendChild($series);
		$i=1;
		foreach(array_reverse($upMonArr) as $k=>$v){
			$value = $dom->createElement("value");
			$series->appendChild($value);
			$text = $dom->createTextNode(iconv('gbk','UTF-8',$k));
			$value->appendChild($text);
			$xid = $dom->createAttribute('xid');
			$value->appendChild($xid);
			$priceValue = $dom->createTextNode("$i");
			$xid->appendChild($priceValue);
			$i++;
		}
		$graphs = $dom->createElement("graphs");
		$chart->appendChild($graphs);
	
		//生成上个月区域住宅
		$graph1 = $dom->createElement("graph");
		$graphs->appendChild($graph1);
		$gid = $dom->createAttribute("gid");
		$graph1->appendChild($gid);
		$gidValue = $dom->createTextNode("0");
		$gid->appendChild($gidValue);
		$i=1;
		foreach(array_reverse($upMonArr)  as $k=>$v){
			$value = $dom->createElement("value");
			$graph1->appendChild($value);
			$text = $dom->createTextNode(intval($v[2]['agePrice']));
			$value->appendChild($text);
			$xid = $dom->createAttribute('xid');
			$value->appendChild($xid);
			$xidValue = $dom->createTextNode("$i");
			$xid->appendChild($xidValue);
			$i++;
		}
		//生成商品的套数
		$graph2 = $dom->createElement("graph");
		$graphs->appendChild($graph2);
		$gid = $dom->createAttribute("gid");
		$graph2->appendChild($gid);
		$gidValue = $dom->createTextNode("1");
		$gid->appendChild($gidValue);
		$i=1;
		foreach(array_reverse($upMonArr) as $k=>$v){
			$value = $dom->createElement("value");
			$graph2->appendChild($value);
			$text = $dom->createTextNode(intval($v[1]['agePrice']));
			$value->appendChild($text);
			$xid = $dom->createAttribute('xid');
			$value->appendChild($xid);
			$xidValue = $dom->createTextNode("$i");
			$xid->appendChild($xidValue);
			$i++; 
		}
	$dom->formatOutput = true;
	$dom->save($path);
}
function XmlFun($lx,$arrXML,$area){
	//使用dom生成xml,注意生成的xml中会没有空格。	
		$dom=new DOMDocument('1.0','utf-8');
		if($lx=='ts'){
			$str = 'taoshu';
		}elseif($lx=="jj"){
			$str = 'jiage';
		}
		$path="gonggong/".$area."/".$str.".xml";     //  $path 为xml文件的存储路径。
//		$path="../fw_nav/".$cfg_ml->get_site_setting('pinyin')."/".$str.".xml";     //  $path 为xml文件的存储路径。
		$chart = $dom->createElement("chart");
		$dom->appendChild($chart);
		
		
		//生成日期
		$series = $dom->createElement("series");
		$chart->appendChild($series);
		$i=1;
		foreach($arrXML  as $k=>$v){
			$value = $dom->createElement("value");
			$series->appendChild($value);
			$text = $dom->createTextNode("$v[3]"."."."$k");
			$value->appendChild($text);
			$xid = $dom->createAttribute('xid');
			$value->appendChild($xid);
			$priceValue = $dom->createTextNode("$i");
			$xid->appendChild($priceValue);
			$i++;
		}
		
		$graphs = $dom->createElement("graphs");
		$chart->appendChild($graphs);
	
		//生成住宅的套数
	
		$graph1 = $dom->createElement("graph");
		$graphs->appendChild($graph1);
		$gid = $dom->createAttribute("gid");
		$graph1->appendChild($gid);
		$gidValue = $dom->createTextNode("0");
		$gid->appendChild($gidValue);
		$i=1;
		foreach($arrXML  as $k=>$v){
			$value = $dom->createElement("value");
			$graph1->appendChild($value);
			if($lx=='ts'){
				$text = $dom->createTextNode($v[2]['num']);
			}else{
				$text = $dom->createTextNode(intval($v[2]['age']/$v[2]['num']));
			}
			$value->appendChild($text);
			$xid = $dom->createAttribute('xid');
			$value->appendChild($xid);
			$xidValue = $dom->createTextNode("$i");
			$xid->appendChild($xidValue);
			$i++;
		}
		//生成商品的套数
		$graph2 = $dom->createElement("graph");
		$graphs->appendChild($graph2);
		$gid = $dom->createAttribute("gid");
		$graph2->appendChild($gid);
		$gidValue = $dom->createTextNode("1");
		$gid->appendChild($gidValue);
		$i=1;
		foreach($arrXML  as $k=>$v){
			$value = $dom->createElement("value");
			$graph2->appendChild($value);
			if($lx=='ts'){
				$text = $dom->createTextNode($v[1]['num']);
			}else{
				$text = $dom->createTextNode(intval($v[1]['age']/$v[1]['num']));
			}
			$value->appendChild($text);
			$xid = $dom->createAttribute('xid');
			$value->appendChild($xid);
			$xidValue = $dom->createTextNode("$i");
			$xid->appendChild($xidValue);
			$i++;
		}
	$dom->formatOutput = true;
	$dom->save($path);
}

//生成XML文件
	
	$query = "SELECT * FROM #@__fw_build_regional_sales WHERE AREA='".$cfg_ml->getUserArea()."'  $quyu ORDER BY id desc ,type ASC $limitSql ";
	$dsql->setquery($query);
	$dsql->execute();
	$i=1;
	while($ImgClass = $dsql->getarray()){
		$honors[$i++] = $ImgClass;
	}
	$m=0;
	$i=1;
	foreach(array_reverse($honors) as $k=>$v){
		if($m!=$v['month']){
			$m=$v['month'];
		}
		$arrXML[$m][3]=$v['year'];
		if($v['type'] == '1'){
//			if($lx=='ts'){
				$arrXML[$m][1]['num'] +=$v['num'];
//			}elseif($lx=="jj"){
				$arrXML[$m][1]['age'] +=intval($v['agePrice']*$v['num']);
//			}
		}
		if($v['type'] == '2'){
//			if($lx=='ts'){
				$arrXML[$m][2]['num'] +=$v['num'];
//			}elseif($lx=="jj"){
				$arrXML[$m][2]['age'] +=intval($v['agePrice']*$v['num']);
//			}
		}
	}

	
	$upDate=date('m',strtotime('-1 month'));
	$upquery = "SELECT * FROM #@__fw_build_regional_sales WHERE AREA='".$cfg_ml->getUserArea()."'  $quyu and month =$upDate   ORDER BY id desc ,type ASC $limitSql ";
	$dsql->setquery($upquery);
	$dsql->execute();
	$tmp1='';
	$tmp2='';
	while($ImgClass = $dsql->getarray()){
		if($ImgClass['type'] ==1){
			if($tmp1!=$ImgClass['locality']){
				$tmp1 = $ImgClass['locality'];
				$upMonArr[$tmp1][$ImgClass['type']] = $ImgClass;
			}
		}
		if($ImgClass['type'] ==2){
			if($tmp2!=$ImgClass['locality']){
				$tmp2 = $ImgClass['locality'];
				$upMonArr[$tmp2][$ImgClass['type']] = $ImgClass;
			}
		}
	}
	
XmlFun("ts",$arrXML,$cfg_ml->get_site_setting('pinyin'));
XmlFun("jj",$arrXML,$cfg_ml->get_site_setting('pinyin'));
if($cfg_ml->get_site_setting('pinyin') == 'xiaogan' || $cfg_ml->get_site_setting('pinyin') == 'xianning'){
	if($cfg_ml->get_site_setting('pinyin') == 'xiaogan'){
		$limitSql = "  limit 0,128  ";
	}
$upDate=date('m',strtotime('-1 month'));
	$upquery = "SELECT * FROM #@__fw_build_regional_sales WHERE AREA='".$cfg_ml->getUserArea()."'   and month =$upDate   ORDER BY id desc ,type ASC $limitSql ";
	$dsql->setquery($upquery);
	$dsql->execute();
	$tmp1='';
	$tmp2='';
	while($ImgClass = $dsql->getarray()){
		if($ImgClass['type'] ==1){
			if($tmp1!=$ImgClass['locality']){
				$tmp1 = $ImgClass['locality'];
				$upMonArr[$tmp1][$ImgClass['type']] = $ImgClass;
			}
		}
		if($ImgClass['type'] ==2){
			if($tmp2!=$ImgClass['locality']){
				$tmp2 = $ImgClass['locality'];
				$upMonArr[$tmp2][$ImgClass['type']] = $ImgClass;
			}
		}
	}
	XmlQuYuFun("quyu",$upMonArr,$cfg_ml->get_site_setting('pinyin'));
}
ShowMsg("ok","regional_sales.php?t=$t");
die;
?>


声明:此文系舞林cuznwww.wulinlw.org)原创稿件,转载请保留版权

et_highlighter