<?php
class shopsale extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function shopsale($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='shstName';
		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_Shopsale_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		//-- ------ #Update data ------ --
		//-- #Update Discuss --
		$tmpCountConfigs=array();
		//#Info
		$tmpAR1=$this->sCountUpdateConfig_Template;
		$tmpAR1['Parent_TableName']=$this->sysTableHead.'shopsalecont';
		$tmpAR1['Parent_CountColumnName']='shsctCount_Discuss';
		$tmpAR1['Parent_Condition']=' AND shsctIndexID='.$pID;
		$tmpAR1['Child_A_TableName']=$this->sysTableHead.'shopsalediscuss';
		$tmpAR1['Child_A_CountColumnName']='shsdtID';
		$tmpAR1['Child_A_Condition']=' AND shsdtRecycle=0 AND shsdtChecked>1 AND shsdtParid='.$pID;
		$tmpCountConfigs[]=$tmpAR1;
		//#Group
		$tmpSQL=' SELECT A.shstID,A.shstParid
			FROM {Nets.TableHead}shopsale AS A 
			WHERE 1=1 AND A.shstRecycle=0 AND A.shstChecked>1 AND A.shstID={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]['shstParid'];
		}
		
		$tmpAR1=$this->sCountUpdateConfig_Template;
		$tmpAR1['Parent_TableName']=$this->sysTableHead.'shopsalegroupcont';
		$tmpAR1['Parent_CountColumnName']='shsgctCount_Info';
		$tmpAR1['Parent_Condition']=' AND shsgctID='.$tmpParid;
		$tmpAR1['Child_A_TableName']=$this->sysTableHead.'shopsalegroup';
		$tmpAR1['Child_A_CountColumnName']='shstID';
		$tmpAR1['Child_A_Condition']=' AND shstRecycle=0 AND shstChecked>1 AND shstParid='.$tmpParid;
		$tmpCountConfigs[]=$tmpAR1;
		
		$tmpINT=$this->updateCount($tmpCountConfigs);
		//-- #Update Hit --
		if($tmpAR0[0]==''){
			$tmpSQL=' UPDATE {Nets.TableHead}shopsalecont SET shsctCount_Views=shsctCount_Views+1 WHERE 1=1 AND shsctIndexID={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;
	}
	
	
}
?>