<?php
class shopsalediscuss extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function shopsalediscuss($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='shsdtName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	public function AddAuction($pDbDescriptions){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Check data ------ --
		//Price
		$tmpSQL=' SELECT A.shstID,A.shstName,A.shstPrice,A.shstCode,
			B.shsctAuction,B.shsctTopPrice,B.shsctTopPriceRange,B.shsctTopCodeRange
			FROM '.$this->sysTableHead.'shopsale AS A INNER JOIN shopsalecont AS B ON B.shsctIndexID=A.shstID
			WHERE 1=1 AND A.shstRecycle=0 AND A.shstChecked>1 AND A.shstID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.ID}',$pDbDescriptions[0]['Columns']['shsdtParid']['Value'],$tmpSQL);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)!=1){
			$this->sysLastError='提交出价时出错，请与管理员联系。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		if($tmpData0[0]['shsctAuction']!=2){
			$this->sysLastError='本商品不是拍卖商品，不能参与商品报价。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		if($pDbDescriptions[1]['Columns']['shsdctSendPrice']['Value']>$tmpData0[0]['shsctTopPrice']){
			$this->sysLastError='对不起，本商品已设置了最高价，您的出价已高于本拍卖商品的最高价了，您可以与本商品的供货商联系。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		$tmpINT=$tmpData0[0]['shstPrice']+$tmpData0[0]['shsctTopPriceRange'];
		if($pDbDescriptions[1]['Columns']['shsdctSendPrice']['Value']<$tmpINT){
			$this->sysLastError='您的出价必须大于或等于<span class="FRed1">￥'.$tmpINT.'</span>。';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//Calculation code
		$tmpSaleCode=$tmpData0[0]['shstCode']+$tmpData0[0]['shsctTopCodeRange'];
		//-- ------ #Add ------ --
		//NumCode
		$tmpSTR='shsdtNumCode';
		$pDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$pDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N'.$this->sysSPLIT11.date('YmdHis');
		$tmpINT=$this->numCode($pDbDescriptions[0]);
		//Set value
		$pDbDescriptions[0]['Columns']['shsdtName']['Value']=$pDbDescriptions[0]['Columns']['shsdtNumCode']['Value'];
		$pDbDescriptions[0]['Columns']['shsdtChecked']['Value']=2;
		$pDbDescriptions[0]['Columns']['shsdtType']['Value']=1;
		$pDbDescriptions[0]['Columns']['shsdtCreateTime']['Value']=date($this->sysTimeFormat);
		//Add
		$pDbDescriptions[0]['TableDescription']['SearchColumn']='shsdtNumCode,shsdtID';
		$pDbDescriptions[1]['TableDescription']['SearchColumn']='shsdctIndexID';
		$tmpINT=$this->add($pDbDescriptions);
		if($tmpINT!=0){
			$this->sysLastError='提交出价时出错，请稍后再试';
			$this->TransRollback();
			return $tmpINT;
		}
		//-- ------ #Modify sale data ------ --
		$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsalecont SET shsctTopLastPrice={Nets.Price},shsctTopLastCode={Nets.Code},shsctTopLastTime=\'{Nets.Datetime}\' WHERE 1=1 AND shsctIndexID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.Price}',$pDbDescriptions[1]['Columns']['shsdctSendPrice']['Value'],$tmpSQL);
		$tmpSTR=str_replace('{Nets.Code}',$tmpSaleCode,$tmpSTR);
		$tmpSTR=str_replace('{Nets.Datetime}',$pDbDescriptions[0]['Columns']['shsdtCreateTime']['Value'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.ID}',$pDbDescriptions[0]['Columns']['shsdtParid']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->sysLastError='更新商品价格时时出错，请稍后再试';
			$this->TransRollback();
			return $tmpINT;
		}
		$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsale SET shstPrice={Nets.Price},shstCode={Nets.Code} WHERE 1=1 AND shstID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.Price}',$pDbDescriptions[1]['Columns']['shsdctSendPrice']['Value'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.Code}',$tmpSaleCode,$tmpSTR);
		$tmpSTR=str_replace('{Nets.ID}',$pDbDescriptions[0]['Columns']['shsdtParid']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->sysLastError='更新商品价格时时出错，请稍后再试';
			$this->TransRollback();
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function AddDiscuss($pDbDescriptions){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Check data ------ --
		//Content
		if(strlen($pDbDescriptions[1]['Columns']['shsdctContent']['Value'])<3){
			$this->sysLastError='请填写留言内容';
			$this->TransRollback();
			return $this->sysErrorFuncID.'001';
		}
		//-- ------ #Add ------ --
		//NumCode
		$tmpSTR='shsdtNumCode';
		$pDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$pDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N'.$this->sysSPLIT11.date('YmdHis');
		$tmpINT=$this->numCode($pDbDescriptions[0]);
		//Set value
		$pDbDescriptions[0]['Columns']['shsdtName']['Value']=$pDbDescriptions[0]['Columns']['shsdtNumCode']['Value'];
		$pDbDescriptions[0]['Columns']['shsdtChecked']['Value']=2;
		$pDbDescriptions[0]['Columns']['shsdtType']['Value']=0;
		$pDbDescriptions[0]['Columns']['shsdtCreateTime']['Value']=date($this->sysTimeFormat);
		//Add
		$pDbDescriptions[0]['TableDescription']['SearchColumn']='shsdtNumCode,shsdtID';
		$pDbDescriptions[1]['TableDescription']['SearchColumn']='shsdctIndexID';
		$tmpINT=$this->add($pDbDescriptions);
		if($tmpINT!=0){
			$this->sysLastError='提交留言时出错，请稍后再试';
			$this->TransRollback();
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function OnEvaluation($pID,$pType,&$pEvaluation){
		$this->sysErrorFuncID=$this->sysErrorClassID.'02';
		$tmpCode=new netsCode();
		$tmpHtml=new netsHtml();
		$this->TransStart();
		//-- ------ #Check cookie exist ------ --
		//Get cookie
		$tmpCookieName=$this->sysCookieHead.'Cookie_Shopsalediscuss_'.$pID;
		$tmpAR0=$tmpHtml->AnalyerRequest($tmpCookieName,'',2);
		if ($tmpAR0[0]!=''){
			$this->sysLastError='您已为本评价打过分。';
			$this->TransRollback();
			return 1;
		}
		$tmpColumn='shsdctCode_BePositive';
		if ($pType==1) {
			$tmpColumn='shsdctCode_BePositive';
		}
		//-- #Update Hit --
		if($tmpAR0[0]==''){
			$tmpSQL=' UPDATE {Nets.TableHead}shopsalediscusscont AS A 
				SET {Nets.Column}={Nets.Column}+1 
				WHERE 1=1 AND shsdctID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
			$tmpSTR=str_replace('{Nets.Column}',$tmpColumn,$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->sysLastError='更新商品评价数据时出错，请稍后再试。';
				$this->TransRollback();
				return $tmpINT;
			}
			$this->writeCookie($this->sysNormalCookiePath,$tmpCookieName,1);
		}
		//-- #Search --
		$tmpSQL=' SELECT A.{Nets.Column}
			FROM {Nets.TableHead}shopsalediscusscont AS A 
			WHERE 1=1 AND shsdctID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pID,$tmpSTR);
		$tmpSTR=str_replace('{Nets.Column}',$tmpColumn,$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		$pEvaluation=0;
		if (count($tmpData0)>0) {
			$pEvaluation=$tmpData0[0][$tmpColumn];
		}
		
		$this->TransCommit();
		return 0;
	}
	
	
}
?>