<?php
class gsnavigationactive extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function gsnavigationactive($pConnection){
		$this->netsDb($pConnection);
	}
	public function Check(&$pTableDescriptAR,$pExceptionAR1,$pExceptionAR2){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		
		if(count($pExceptionAR1)==0){
			$pExceptionAR1=array();
		}
		parent::Check($pTableDescriptAR,$pExceptionAR1,$pExceptionAR2);
		//
		$tmpSTR='gsnatName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		return 0;
	}
	
	public function initialObject($pID){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Check cookie exist ------ --
		//Get cookie
		$tmpCookieName=$this->sysCookieHead.'Cookie_Gsnavigationactive_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		$tmpCookieValue=$tmpAR0[0];
		//-- ------ #Update data ------ --
		//-- #Update Discuss --
		$tmpCountConfigs=array();
		//#Info
		$tmpAR1=$this->sCountUpdateConfig_Template;
		$tmpAR1['Parent_TableName']=$this->sysTableHead.'gsnavigationactivecont';
		$tmpAR1['Parent_CountColumnName']='gsnactCount_Discuss';
		$tmpAR1['Parent_Condition']=' AND gsnactID='.$pID;
		$tmpAR1['Child_A_TableName']=$this->sysTableHead.'gsnavigationactivediscuss';
		$tmpAR1['Child_A_CountColumnName']='gsnadtID';
		$tmpAR1['Child_A_Condition']=' AND gsnadtRecycle=0 AND gsnadtChecked>1 AND gsnadtParid='.$pID;
		$tmpCountConfigs[]=$tmpAR1;
		//#Group
		$tmpSQL=' SELECT A.gsnatID,A.gsnatParid
			FROM {Nets.TableHead}gsnavigationactive AS A 
			WHERE 1=1 AND A.gsnatRecycle=0 AND A.gsnatChecked>1 AND A.gsnatID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		$tmpParid=0;
		if (count($tmpData0)>0) {
			$tmpParid=$tmpData0[0]['gsnatParid'];
		}
		
		$tmpAR1=$this->sCountUpdateConfig_Template;
		$tmpAR1['Parent_TableName']=$this->sysTableHead.'gsnavigationactivegroupcont';
		$tmpAR1['Parent_CountColumnName']='gsnagctCount_Info';
		$tmpAR1['Parent_Condition']=' AND gsnagctID='.$tmpParid;
		$tmpAR1['Child_A_TableName']=$this->sysTableHead.'gsnavigationactive';
		$tmpAR1['Child_A_CountColumnName']='gsnatID';
		$tmpAR1['Child_A_Condition']=' AND gsnatRecycle=0 AND gsnatChecked>1 AND gsnatParid='.$tmpParid;
		$tmpCountConfigs[]=$tmpAR1;
		
		$tmpINT=$this->updateCount($tmpCountConfigs);
		//-- #Update Hit --
		if($tmpCookieValue==''){
			$tmpSQL=' UPDATE {Nets.TableHead}gsnavigationactivecont SET gsnactCount_Views=gsnactCount_Views+1 WHERE 1=1 AND gsnactIndexID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->sysLastError='更新团购数据时出错，请稍后再试。';
				$this->TransRollback();
				return $tmpINT;
			}
			$this->writeCookie($this->sysNormalCookiePath,$tmpCookieName,1);
		}
		
		$this->TransCommit();
		return 0;
	}
	public function OnPositive($pID,&$pData){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Update ------ --
		//Get cookie
		$tmpCookieName=$this->sysCookieHead.'Cookie_Gsnavigationactive_Vote_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		$tmpCookieValue=$tmpAR0[0];
		if ($tmpCookieValue!='') {
			$this->sysLastError='谢谢，您已经投过票了。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//SQL
		$tmpSQL=' UPDATE {Nets.TableHead}gsnavigationactivecont AS A 
			SET A.gsnactCode_Positive=A.gsnactCode_Positive+1
			WHERE 1=1 AND A.gsnactIndexID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if ($tmpINT!=0) {
			$this->sysLastError='对不起，投票失败，请与客服人员联系。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//Get count
		$tmpSQL=' SELECT A.gsnactID,gsnactCode_Positive
			FROM {Nets.TableHead}gsnavigationactivecont AS A
			WHERE 1=1 AND A.gsnactIndexID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if (count($tmpData0)<=0) {
			$this->sysLastError='对不起，获取投票数失败，请与客服人员联系。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//Set cookie
		$this->writeCookie($this->sysNormalCookiePath,$tmpCookieName,1);
		
		$pData=$tmpData0;
		$this->TransCommit();
		return 0;
	}
	public function OnNegative($pID,&$pData){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Update ------ --
		//Get cookie
		$tmpCookieName=$this->sysCookieHead.'Cookie_Gsnavigationactive_Vote_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		$tmpCookieValue=$tmpAR0[0];
		if ($tmpCookieValue!='') {
			$this->sysLastError='谢谢，您已经投过票了。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//SQL
		$tmpSQL=' UPDATE {Nets.TableHead}gsnavigationactivecont AS A 
			SET A.gsnactCode_Negative=A.gsnactCode_Negative+1
			WHERE 1=1 AND A.gsnactIndexID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if ($tmpINT!=0) {
			$this->sysLastError='对不起，投票失败，请与客服人员联系。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//Get count
		$tmpSQL=' SELECT A.gsnactID,gsnactCode_Negative
			FROM {Nets.TableHead}gsnavigationactivecont AS A
			WHERE 1=1 AND A.gsnactIndexID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if (count($tmpData0)<=0) {
			$this->sysLastError='对不起，获取投票数失败，请与客服人员联系。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//Set cookie
		$this->writeCookie($this->sysNormalCookiePath,$tmpCookieName,1);
		
		$pData=$tmpData0;
		$this->TransCommit();
		return 0;
	}
	public function setAllState(){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$this->TransStart();
		
		//-- ------ ### ------ --
		//-- #SEARCH --
		$tmpSQL=' SELECT A.gsnatID
			FROM {Nets.TableHead}gsnavigationactive AS A
			INNER JOIN {Nets.TableHead}gsnavigationactivecont AS B ON B.gsnactIndexID=A.gsnatID
			WHERE 1=1 AND A.gsnatState=2 AND B.gsnactPrice_EndTime<=\'{Nets.Datetime}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Datetime}',date($this->sysTimeFormat),$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		$tmpSTR_0='';
		foreach ($tmpData0 as $Row0){
			$tmpSTR_0.=' OR A.gsnatID='.$Row0['gsnatID'].' ';
		}
		//-- #EXECUTE --
		$tmpSQL=' UPDATE {Nets.TableHead}gsnavigationactive AS A 
			SET A.gsnatState=3 
			WHERE 1=1 AND (1=2 {Nets.IDS}) ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.IDS}',$tmpSTR_0,$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->sysLastError='更新团购数据时出错，请稍后再试。';
			$this->TransRollback();
			return $tmpINT;
		}
		//-- ------ ### ------ --
		//-- #SEARCH --
		$tmpSQL=' SELECT A.gsnatID
			FROM {Nets.TableHead}gsnavigationactive AS A
			INNER JOIN {Nets.TableHead}gsnavigationactivecont AS B ON B.gsnactIndexID=A.gsnatID
			WHERE 1=1 AND (A.gsnatState=0 OR A.gsnatState=1) AND B.gsnactPrice_EndTime<=\'{Nets.Datetime}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Datetime}',date($this->sysTimeFormat),$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		$tmpSTR_0='';
		foreach ($tmpData0 as $Row0){
			$tmpSTR_0.=' OR A.gsnatID='.$Row0['gsnatID'].' ';
		}
		//-- #EXECUTE --
		$tmpSQL=' UPDATE {Nets.TableHead}gsnavigationactive AS A 
			SET A.gsnatState=4
			WHERE 1=1 AND (1=2 {Nets.IDS}) ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSTR);
		$tmpSTR=str_replace('{Nets.IDS}',$tmpSTR_0,$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->sysLastError='更新团购数据时出错，请稍后再试。';
			$this->TransRollback();
			return $tmpINT;
		}
		
		
		$this->TransCommit();
		return 0;
	}
	
	
}
?>