<?php

class pay_class extends CustomPage {
	public $sPayurl='';
	public $sAccount='vir@unionnets.com';//商户编号
	public $sPxd='123456';//商户编号
	public $sWebpayPartnerid='1000000';//商户编号
	public $sSecurity_code='AAAAAAAAAAAAAAAAAAAAAAAAAAAA';//商户密钥
	public $sTrade_on='';
	public $sTotal_fee=0.00;
	public $sNotify_url='';//交易过程中服务器通知的页面 要用 http://格式的完整路径
	public $sReturn_url='';//付完款后跳转的页面 要用 http://格式的完整路径
	public $sCancel_url='';//取消支付跳转的页面 要用 http://格式的完整路径
	public $sKey='';//生成加密串，注意顺序
	
	public $sSubmitput='';
	
	public $sErrorImg='';
	public $sErrorTxt='';
	
	public function pay_class(){
		$this->CustomPage();
		$this->sErrorImg='../../../Ui/m_unionnets/Img/Home/23.jpg';
		$this->sErrorTxt='欢迎来到网集在线商务办公平台';
	}
	public function OnSubmit(){
		
		return 0;
	}
	public function OnNotify(){
		
		return 0;
	}
	public function OnReturn(){
		
		return 0;
	}
	public function OnCancel(){
		
		return 0;
	}
	public function getPaytype($pConfirmcode,&$pData){
		$tmpSQL=' SELECT A.shupttName,
			B.shuptctWebpayName,B.shuptctWebpayAccount,B.shuptctWebpayPxd,B.shuptctWebpayPartnerid,B.shuptctWebpayKey,
			B.shuptctWebpaySiteURL,B.shuptctWebpayRequestURL,B.shuptctWebpayNotifyURL,B.shuptctWebpayReturnURL,B.shuptctWebpayCancelURL
			FROM '.$this->sysTableHead.'shopuserpaytype AS A
			INNER JOIN '.$this->sysTableHead.'shopuserpaytypecont AS B ON B.shuptctIndexID=A.shupttID
			WHERE 1=1 AND A.shupttConfirmcode=\'{Nets.Confirmcode}\' ';
		$tmpSTR=str_replace('{Nets.Confirmcode}',$pConfirmcode,$tmpSQL);
		$pData=$this->sDb->Search($tmpSTR);
		if(count($pData)==0){
			return 1;
		}
		return 0;
	}
	public function getOrder($pNumCode,&$pData,&$pPay){
		$tmpAR0=explode($this->sysSPLIT11,$pNumCode);
		if(count($tmpAR0)!=2){
			$this->sysLastError='订单号格式不正确，请与管理员联系。';
			return 1;
		}
		//-- ------ # ------ --
		if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_Order']){
			$tmpSQL=' SELECT A.shsotNumCode,A.shsotPayyet,A.shsotTotalPrice
				FROM {Nets.TableHead}shopsaleorder AS A
				WHERE 1=1 AND A.shsotNumCode LIKE \'{Nets.NumCode}\' ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.NumCode}',$this->sTrade_on,$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)==0){
				$this->sysLastError='您所提交的订单并不存在，请确定后再试。';
				return 2;
			}
			if($tmpData0[0]['shsotTotalPrice']<=$tmpData0[0]['shsotPayyet']){
				$this->sysLastError='本订单费用已付清，请等待发货。';
				return 3;
			}
			$pPay=$tmpData0[0]['shsotTotalPrice']-$tmpData0[0]['shsotPayyet'];
		}else if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_GroupsaleOrder']){
			$tmpSQL=' SELECT A.gsotNumCode,A.gsotPayyet,A.gsotTotalPrice
				FROM {Nets.TableHead}groupsaleorder AS A
				WHERE 1=1 AND A.gsotNumCode LIKE \'{Nets.NumCode}\' ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.NumCode}',$this->sTrade_on,$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)==0){
				$this->sysLastError='您所提交的订单并不存在，请确定后再试。';
				return 2;
			}
			if($tmpData0[0]['gsotTotalPrice']<=$tmpData0[0]['gsotPayyet']){
				$this->sysLastError='本订单费用已付清，请等待发货。';
				return 3;
			}
			$pPay=$tmpData0[0]['gsotTotalPrice']-$tmpData0[0]['gsotPayyet'];
		}else if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_Userpay']){
			$tmpSQL=' SELECT A.shuptNumCode,A.shuptTotalPrice
				FROM {Nets.TableHead}shopuserpay AS A
				WHERE 1=1 AND A.shuptNumCode LIKE \'{Nets.NumCode}\' ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.NumCode}',$this->sTrade_on,$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)==0){
				$this->sysLastError='您所提交的订单并不存在，请确定后再试。';
				return 2;
			}
			$pPay=$tmpData0[0]['shuptTotalPrice'];
		}else if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_ServicesaleOrder']){
			$tmpSQL=' SELECT A.sesotNumCode,A.sesotTotalPrice
				FROM {Nets.TableHead}servicesaleorder AS A
				WHERE 1=1 AND A.sesotNumCode LIKE \'{Nets.NumCode}\' ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.NumCode}',$this->sTrade_on,$tmpSTR);
			$tmpData0=$this->sDb->Search($tmpSTR);
			if(count($tmpData0)==0){
				$this->sysLastError='您所提交的订单并不存在，请确定后再试。';
				return 2;
			}
			$pPay=$tmpData0[0]['sesotTotalPrice'];
		}else {
			print_r($tmpAR0);
			exit('DONE');
			
			$this->sysLastError='订单号格式不正确，请与管理员联系。';
			return 4;
		}
		
		$pData=$tmpData0;
		return 0;
	}
	public function orderPay($pNumCode,$pPrice){
		$tmpAR0=explode($this->sysSPLIT11,$pNumCode);
		if(count($tmpAR0)!=2){
			$this->sJscript=$this->Message('SUCCESS','','订单号格式不正确，请与管理员联系。','');
			return 1;
		}
		//-- ------ # ------ --
		if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_Order']){
			$tmpApp=new shopsaleorder($this->sConnString);
			$tmpDescriptions=array(
				$this->sysDbDescriptions[$this->sysTableHead.'shopsaleorder'],
				$this->sysDbDescriptions[$this->sysTableHead.'shopsaleordercont']);
			$tmpDescriptions[0]['Columns']['shsotNumCode']['Value']=$pNumCode;
			$tmpINT=$tmpApp->order_Complete($tmpDescriptions,$pPrice);
			if($tmpINT!=0){
				$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
				return 2;
			}
		}else if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_GroupsaleOrder']){
			$tmpApp=new groupsaleorder($this->sConnString);
			$tmpDescriptions=array(
				$this->sysDbDescriptions[$this->sysTableHead.'groupsaleorder'],
				$this->sysDbDescriptions[$this->sysTableHead.'groupsaleordercont']);
			$tmpDescriptions[0]['Columns']['gsotNumCode']['Value']=$pNumCode;
			$tmpINT=$tmpApp->order_Complete($tmpDescriptions,$pPrice);
			if($tmpINT!=0){
				$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
				return 2;
			}
		}else if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_UserOrder']){
			$tmpApp=new shopuserpay($this->sConnString);
			$tmpDescriptions=array(
				$this->sysDbDescriptions[$this->sysTableHead.'shopuserpay'],
				$this->sysDbDescriptions[$this->sysTableHead.'shopuserpaycont']);
			$tmpDescriptions[0]['Columns']['shuptNumCode']['Value']=$pNumCode;
			$tmpINT=$tmpApp->Pay_Confirm($tmpDescriptions,$pPrice);
			if($tmpINT!=0){
				$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
				return 2;
			}
		}else if($tmpAR0[0]==$this->sysFileConfig['NumCodeHead_ServicesaleOrder']){
			$tmpApp=new servicesaleorder($this->sConnString);
			$tmpDescriptions=array(
				$this->sysDbDescriptions[$this->sysTableHead.'servicesaleorder'],
				$this->sysDbDescriptions[$this->sysTableHead.'servicesaleordercont']);
			$tmpDescriptions[0]['Columns']['sesotNumCode']['Value']=$pNumCode;
			$tmpINT=$tmpApp->Pay_Confirm($tmpDescriptions,$pPrice);
			if($tmpINT!=0){
				$this->sJscript=$this->Message('ERROR','',$tmpApp->sysLastError,'');
				return 2;
			}
		}else {
			$this->sJscript=$this->Message('SUCCESS','','订单号格式不正确，请与管理员联系。','');
			return 4;
		}
		return 0;
	}
}
?>