<?php
class shopunit extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function shopunit($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='shutName';
		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_Shopunit_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		//-- ------ #Update data ------ --
		//-- #Update Discuss --
		$tmpCountConfigs=array();
		//#Info
		$tmpAR1=$this->sCountUpdateConfig_Template;
		$tmpAR1['Parent_TableName']=$this->sysTableHead.'shopunitcont';
		$tmpAR1['Parent_CountColumnName']='shuctCount_Discuss';
		$tmpAR1['Parent_Condition']=' AND shuctIndexID='.$pID;
		$tmpAR1['Child_A_TableName']=$this->sysTableHead.'shopunitdiscuss';
		$tmpAR1['Child_A_CountColumnName']='shudtID';
		$tmpAR1['Child_A_Condition']=' AND shudtRecycle=0 AND shudtChecked>1 AND shudtParid='.$pID;
		$tmpCountConfigs[]=$tmpAR1;
		//#Group
		$tmpSQL=' SELECT A.shutID,A.shutParid
			FROM {Nets.TableHead}shopunit AS A 
			WHERE 1=1 AND A.shutRecycle=0 AND A.shutChecked>1 AND A.shutID={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]['shutParid'];
		}
		
		$tmpAR1=$this->sCountUpdateConfig_Template;
		$tmpAR1['Parent_TableName']=$this->sysTableHead.'shopunitgroupcont';
		$tmpAR1['Parent_CountColumnName']='shugctCount_Info';
		$tmpAR1['Parent_Condition']=' AND shugctID='.$tmpParid;
		$tmpAR1['Child_A_TableName']=$this->sysTableHead.'shopunitgroup';
		$tmpAR1['Child_A_CountColumnName']='shutID';
		$tmpAR1['Child_A_Condition']=' AND shutRecycle=0 AND shutChecked>1 AND shutParid='.$tmpParid;
		$tmpCountConfigs[]=$tmpAR1;
		
		$tmpINT=$this->updateCount($tmpCountConfigs);
		//-- #Update Hit --
		if($tmpAR0[0]==''){
			$tmpSQL=' UPDATE {Nets.TableHead}shopunitcont SET shuctCount_Views=shuctCount_Views+1 WHERE 1=1 AND shuctIndexID={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;
	}
	
	
}
?>