<?php
class statControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	public function onDefault(){
		
	}
	
	public function onStatWeekAll(){
		//PV
		$time=strtotime(date("Y-m-d 00:00:00"));
		for($i=7;$i>=0;$i--){
			$labels[]=date("m月d",$time-$i*3600*24);
		}
		$total=0;
		for($i=7;$i>=0;$i--){
			$h=date("Y-m-d",$time-$i*3600*24);
			$w="";
			if($url){
				$w=" url like '".$url."%' AND ";
			}
			$sql="select count(*) from ".table('pv')." where ".$w." createtime like '".$h."%'";
			 
			$pvMoneys[]=$count=M("pv")->getOne($sql);
			 
		}
		//uv
		$total=0;
		for($i=7;$i>=0;$i--){
			$h=date("Y-m-d",$time-$i*3600*24);
			$w="";
			if($url){
				$w=" url like '".$url."%' AND ";
			}
			$sql="select COUNT(distinct(ssid)) from ".table('pv')." where ".$w." createtime like '".$h."%'";
			 
			$uvMoneys[]=$count=M("pv")->getOne($sql);
			 
		}
		//ip
		$total=0;
		for($i=7;$i>=0;$i--){
			$h=date("Y-m-d",$time-$i*3600*24);
			$w="";
			if($url){
				$w=" url like '".$url."%' AND ";
			}
			$sql="select COUNT(distinct(ip)) from ".table('pv')." where ".$w." createtime like '".$h."%'";
			 
			$ipMoneys[]=$count=M("pv")->getOne($sql);
			 
		}
		for($i=7;$i>=0;$i--){
			$h=date("Y-m-d",$time-$i*3600*24);
		 
			$sql="select COUNT(*) from ".table('user')." where   createtime like '".$h."%'";
			 
			$count=M("user")->getOne($sql);
			$userMoneys[]=$count==0?0:$count; 
		}
		$this->smarty->goAssign(array(
			"labels"=>$labels,
			"pvMoneys"=>$pvMoneys,
			"ipMoneys"=>$ipMoneys,
			"uvMoneys"=>$uvMoneys,
			"userMoneys"=>$userMoneys,
			"total"=>$total
		));
		
	}
	
	public function onWeekUser(){
		$time=strtotime(date("Y-m-d 00:00:00"));
		for($i=7;$i>=0;$i--){
			$labels[]=date("m月d",$time-$i*3600*24);
		}
		$list=array();
		for($i=7;$i>=0;$i--){
			$h=date("Y-m-d",$time-$i*3600*24);
		 
			$sql="select COUNT(*) from ".table('user')." where   createtime like '".$h."%'";
			 
			$num=M("user")->getOne($sql);
			$list[]=$num==null?0:$num;
			 
		}
		$this->goAll("success",0,array(
			"labels"=>$labels,
			"list"=>$list
		));
	}
	
	public function onWeekRecharge(){
		$time=strtotime(date("Y-m-d 00:00:00"));
		for($i=7;$i>=0;$i--){
			$labels[]=date("m月d",$time-$i*3600*24);
		}
		$list=array();
		for($i=7;$i>=0;$i--){
			 
			$stime=$time-$i*3600*24;
			$etime=$stime+3600*24;
			$sql="select sum(money) from ".table('recharge')." where status=1 AND dateline>=".$stime." AND dateline<".$etime."   ";
			$num=M("recharge")->getOne($sql); 
			 
			$list[]=$num==null?0:$num;
			 
		}
		$this->goAll("success",0,array(
			"labels"=>$labels,
			"list"=>$list
		));
	}
	
}
?>