<?php
class shopsaleorder extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	public function shopsaleorder($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='shsotName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	
	
	
	public function Order(&$pDescriptions,$pCar_list,$pUserinfo,&$pUrl){
		$this->sysErrorFuncID=$this->sysErrorClassID.'04';
		$this->TransStart();
		//-- ------ #Add ------ --
		//#Get numCode
		$tmpSTR='shsotNumCode';
		$pDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$pDescriptions[0]['Columns'][$tmpSTR]['Value']=$this->sysFileConfig['NumCodeHead_Order'].$this->sysSPLIT11.date('YmdHis');
		$this->numCode($pDescriptions[0]);
		//-- #Other --
		$tmpPay_Price=0.00;
		$tmpPay_Code=0.00;
		foreach ($pCar_list as $Row0){
			$tmpPay_Price+=$Row0['shstPrice']*$Row0['shsctCount'];
			$tmpPay_Code+=$Row0['shstCode']*$Row0['shsctCount'];
		}
		//-- #Setting --
		//#shsotPayyet,shsotTotalPrice,shsotTotalCode
		$pDescriptions[0]['Columns']['shsotPayyet']['Value']=0.00;
		$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']=$tmpPay_Price+
			$pDescriptions[1]['Columns']['shsoctInvoicePrice']['Value']+
			$pDescriptions[1]['Columns']['shsoctSendmodelPrice']['Value'];
		$pDescriptions[0]['Columns']['shsotTotalCode']['Value']=$tmpPay_Code;
		//#shsoctSales
		$pDescriptions[1]['Columns']['shsoctSales']['Value']=serialize($pCar_list);
		//#Other
		$pDescriptions[0]['Columns']['shsotState']['Value']=0;
		$pDescriptions[0]['Columns']['shsotName']['Value']=$pDescriptions[0]['Columns']['shsotNumCode']['Value'];
		$pDescriptions[0]['Columns']['shsotCreateBy']['Value']=$pUserinfo[0]['Columns']['uitID']['Value'];
		$pDescriptions[0]['Columns']['shsotCreateTime']['Value']=date($this->sysTimeFormat);
		//-- #Add --
		$tmpINT=$this->Check($pDescriptions,array(),array());
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请联系管理员。';
			return $tmpINT;
		}
		$pDescriptions[0]['TableDescription']['SearchColumn']='shsotNumCode,shsotID';
		$pDescriptions[1]['TableDescription']['SearchColumn']='shsoctIndexID';
		$tmpINT=$this->add($pDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请联系管理员。';
			return $tmpINT;
		}
		//-- #Reseach --
		$tmpSQL=' SELECT * FROM '.$this->sysTableHead.'shopsaleorder AS A
			INNER JOIN '.$this->sysTableHead.'shopsaleordercont AS B ON B.shsoctIndexID=A.shsotID
			WHERE 1=1 AND A.shsotNumCode LIKE \''.$pDescriptions[0]['Columns']['shsotNumCode']['Value'].'\' ';
		$tmpData0=$this->Search($tmpSQL);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		//-- ------ #Pay ------ --
		//0.先从帐号的资金里扣除，再使用以下方式支付
		//1.直接从帐号的资金里扣除，不足的提示我充值
		//2.先从帐号的资金里扣除，不足部分使用货到付款
		//3.直接使用以下方式支付
		//4.货到付款
		
		//Check pay type
		if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=0 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=1 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=2 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=3 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=4){
			$this->TransRollback();
			$this->sysLastError='支付方式错误，请联系管理员。';
			return $this->sysErrorFuncID.'003';
		}
		//Beforehand pay
		//0.先从帐号的资金里扣除，再使用以下方式支付
		//1.直接从帐号的资金里扣除，不足的提示我充值
		//2.先从帐号的资金里扣除，不足部分使用货到付款
		if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==0 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==1 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==2){
			$tmpPayyet=0.00;
			if($pUserinfo[0]['Columns']['uitMoney']['Value']<$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']){
				$tmpPayyet=$pUserinfo[0]['Columns']['uitMoney']['Value'];
			}else {
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
			}
			$tmpSQL=' UPDATE '.$this->sysTableHead.'netsuserinfo SET uitMoney=uitMoney-{Nets.Money} WHERE 1=1 AND uitID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.Money}',$tmpPayyet,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pUserinfo[0]['Columns']['uitID']['Value'],$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='用户帐户支付错误，请联系管理员。';
				return $this->sysErrorFuncID.'002';
			}
			$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsaleorder SET shsotPayyet=shsotPayyet+{Nets.Money} WHERE 1=1 AND shsotID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.Money}',$tmpPayyet,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='用户帐户支付错误，请联系管理员。';
				return $this->sysErrorFuncID.'002';
			}
			$pDescriptions[0]['Columns']['shsotPayyet']['Value']=$tmpPayyet;
		}
		//Set pay set
		$tmpState=0;
		if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
			//用户帐户里资金不足，或不用用户帐户扣除
			if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==2 ||
				$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==4){
				$tmpState=3;
			}else {
				$tmpState=1;
			}
		}else {
			//用户帐户里资金足以支付本订单
			$tmpState=2;
		}
		$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsaleorder SET shsotState={Nets.State} WHERE 1=1 AND shsotID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.State}',$tmpState,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='用户帐户支付错误，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		$pDescriptions[0]['Columns']['shsotState']['Value']=$tmpState;
		//Clear my sale car
		$tmpSQL=' DELETE FROM '.$this->sysTableHead.'shopsalecar WHERE 1=1 AND shsctID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.ID}',$pUserinfo[0]['Columns']['uitID']['Value'],$tmpSQL);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='清理用户购物车错误，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpSQL=' DELETE FROM '.$this->sysTableHead.'shopsalecarcont WHERE 1=1 AND shscctIndexID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.ID}',$pUserinfo[0]['Columns']['uitID']['Value'],$tmpSQL);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='清理用户购物车错误，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		//Redirect
		if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==0 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==3){
			//0.先从帐号的资金里扣除，再使用以下方式支付
			//3.直接使用以下方式支付
			if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
				$tmpSQL=' SELECT 
					B.shuptctWebpayRequestURL
					FROM '.$this->sysTableHead.'shopuserpaytype AS A
					INNER JOIN '.$this->sysTableHead.'shopuserpaytypecont AS B ON B.shuptctIndexID=A.shupttID
					WHERE 1=1 AND A.shupttID={Nets.ID} ';
				$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[1]['Columns']['shsoctPayTypeid']['Value'],$tmpSQL);
				$tmpData0=$this->Search($tmpSTR);
				if (count($tmpData0)==0) {
					$pUrl=$this->sysFileConfig['PaySubmit_Default'];
				}else {
					$pUrl=$tmpData0[0]['shuptctWebpayRequestURL'];
				}
				$pUrl.='?NumCode='.$pDescriptions[0]['Columns']['shsotNumCode']['Value'];
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，您还必须为本订单支付￥'.$tmpPaywill.'(人民币)。';
			}else {
				$pUrl='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)。';
			}
		}else if($this->sLocalDbDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==1){
			//1.直接从帐号的资金里扣除，不足的提示我充值
			if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
				$pUrl='Plus/Common/Shop/userpay0.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，您还必须为您的帐户充值￥'.$tmpPaywill.'(人民币)才足已支付本订单。';
			}else {
				$pUrl='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)。';
			}
		}else if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==2 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==4){
			//2.先从帐号的资金里扣除，不足部分使用货到付款
			//4.货到付款
			if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
				$pUrl='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，当收款时，您还必须为本订单支付￥'.$tmpPaywill.'(人民币)。';
			}else {
				$pUrl='Plus/Common/Shop/saleorder.php';
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！(货到付款方式)';
			}
		}

		$this->TransCommit();
		return 0;
	}
	public function pay(&$pDescriptions,$pUserinfo,&$pUrl){
		$this->sysErrorFuncID=$this->sysErrorClassID.'04';
		$this->TransStart();
		//-- ------ #Pay ------ --
		//0.先从帐号的资金里扣除，再使用以下方式支付
		//1.直接从帐号的资金里扣除，不足的提示我充值
		//2.先从帐号的资金里扣除，不足部分使用货到付款
		//3.直接使用以下方式支付
		//4.货到付款
		
		//Check pay type
		if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=0 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=1 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=2 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=3 &&
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']!=4){
			$this->TransRollback();
			$this->sysLastError='支付方式错误，请联系管理员。';
			return $this->sysErrorFuncID.'003';
		}
		//Beforehand pay
		//0.先从帐号的资金里扣除，再使用以下方式支付
		//1.直接从帐号的资金里扣除，不足的提示我充值
		//2.先从帐号的资金里扣除，不足部分使用货到付款
		if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==0 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==1 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==2){
			$tmpPayyet=0.00;
			if($pUserinfo[0]['Columns']['uitMoney']['Value']<$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']){
				$tmpPayyet=$pUserinfo[0]['Columns']['uitMoney']['Value'];
			}else {
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
			}
			$tmpSQL=' UPDATE '.$this->sysTableHead.'netsuserinfo SET uitMoney=uitMoney-{Nets.Money} WHERE 1=1 AND uitID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.Money}',$tmpPayyet,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pUserinfo[0]['Columns']['uitID']['Value'],$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='用户帐户支付错误，请联系管理员。';
				return $this->sysErrorFuncID.'002';
			}
			$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsaleorder SET shsotPayyet=shsotPayyet+{Nets.Money} WHERE 1=1 AND shsotID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.Money}',$tmpPayyet,$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='用户帐户支付错误，请联系管理员。';
				return $this->sysErrorFuncID.'002';
			}
			$pDescriptions[0]['Columns']['shsotPayyet']['Value']=$tmpPayyet;
		}
		//Set pay set
		$tmpState=0;
		if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
			//用户帐户里资金不足，或不用用户帐户扣除
			if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==2 ||
				$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==4){
				$tmpState=3;
			}else {
				$tmpState=1;
			}
		}else {
			//用户帐户里资金足以支付本订单
			$tmpState=2;
		}
		$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsaleorder SET shsotState={Nets.State} WHERE 1=1 AND shsotID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.State}',$tmpState,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='用户帐户支付错误，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		$pDescriptions[0]['Columns']['shsotState']['Value']=$tmpState;
		//Redirect
		if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==0 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==3){
			//0.先从帐号的资金里扣除，再使用以下方式支付
			//3.直接使用以下方式支付
			if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
				$tmpSQL=' SELECT 
					B.shuptctWebpayRequestURL
					FROM '.$this->sysTableHead.'shopuserpaytype AS A
					INNER JOIN '.$this->sysTableHead.'shopuserpaytypecont AS B ON B.shuptctIndexID=A.shupttID
					WHERE 1=1 AND A.shupttID={Nets.ID} ';
				$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[1]['Columns']['shsoctPayTypeid']['Value'],$tmpSQL);
				$tmpData0=$this->Search($tmpSTR);
				if (count($tmpData0)==0) {
					$pUrl=$this->sysFileConfig['PaySubmit_Default'];
				}else {
					$pUrl=$tmpData0[0]['shuptctWebpayRequestURL'];
				}
				$pUrl.='?NumCode='.$pDescriptions[0]['Columns']['shsotNumCode']['Value'];
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，您还必须为本订单支付￥'.$tmpPaywill.'(人民币)。';
			}else {
				$pUrl='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)。';
			}
		}else if($this->sLocalDbDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==1){
			//1.直接从帐号的资金里扣除，不足的提示我充值
			if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
				$pUrl='Plus/Common/Shop/userpay0.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，您还必须为您的帐户充值￥'.$tmpPaywill.'(人民币)才足已支付本订单。';
			}else {
				$pUrl='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)。';
			}
		}else if($pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==2 ||
			$pDescriptions[1]['Columns']['shsoctPayBeforehand']['Value']==4){
			//2.先从帐号的资金里扣除，不足部分使用货到付款
			//4.货到付款
			if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
				$pUrl='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，当收款时，您还必须为本订单支付￥'.$tmpPaywill.'(人民币)。';
			}else {
				$pUrl='Plus/Common/Shop/saleorder.php';
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！(货到付款方式)';
			}
		}
		
		$this->TransCommit();
		return 0;
	}
	public function repayOrder(&$pDescriptions,$pPay){
		/*
		1.结算金额
		2.更改订单状态
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'04';
		$this->TransStart();
		//-- ------ #Settlement Amount ------ --
		//Get order
		$tmpSQL=' SELECT *
			FROM '.$this->sysTableHead.'shopsaleorder AS A
			INNER JOIN '.$this->sysTableHead.'shopsaleordercont AS B ON B.shsoctIndexID=A.shsotID
			WHERE 1=1 AND A.shsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shsotNumCode']['Value'],$tmpSQL);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='查询的订单号并不存在，请联系管理员。';
			return $this->sysErrorFuncID.'001';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		//Update payyet
		$tmpExtra=0.00;
		$pDescriptions[0]['Columns']['shsotPayyet']['Value']+=$pPay;
		if($pDescriptions[0]['Columns']['shsotPayyet']['Value']>$pDescriptions[0]['Columns']['shsotTotalPrice']['Value']){
			$tmpExtra=$pDescriptions[0]['Columns']['shsotPayyet']['Value']-$pDescriptions[0]['Columns']['shsotTotalPrice']['Value'];
			$pDescriptions[0]['Columns']['shsotPayyet']['Value']=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value'];
		}
		$tmpSQL=' UPDATE shopsaleorder SET shsotPayyet={Nets.Pay} WHERE shsotID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.Pay}',$pDescriptions[0]['Columns']['shsotPayyet']['Value'],$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='结算支付金额时出错，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		//-- ------ #Update order state ------ --
		if($tmpExtra>0.00){
			$this->TransRollback();
			$this->sysLastError='处理用户资金时出错，请联系管理员。';
			return $this->sysErrorFuncID.'004';
		}
		if($pDescriptions[0]['Columns']['shsotState']['Value']>=2){
			$this->TransRollback();
			$this->sysLastError='本订单已在处理中，请等待发货。';
			return $this->sysErrorFuncID.'004';
		}
		//Update order state
		if($pDescriptions[0]['Columns']['shsotPayyet']['Value']>=$pDescriptions[0]['Columns']['shsotTotalPrice']['Value'] &&
			($pDescriptions[0]['Columns']['shsotState']['Value']==0 ||
			$pDescriptions[0]['Columns']['shsotState']['Value']==1)){
			$pDescriptions[0]['Columns']['shsotState']['Value']=2;
			$tmpSQL=' UPDATE shopsaleorder SET shsotState={Nets.State} WHERE shsotID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.State}',$pDescriptions[0]['Columns']['shsotState']['Value'],$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSQL);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='更新订单状态时出错，请联系管理员。';
				return $this->sysErrorFuncID.'003';
			}
		}
		
		$this->TransCommit();
		return 0;
	}
	public function confirmResevice(&$pDescriptions){
		/*
		结算积分给用户
		修改订单状态
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'04';
		$this->TransStart();
		//-- ------ #Settlement Amount ------ --
		//Get order
		$tmpSQL=' SELECT *
			FROM '.$this->sysTableHead.'shopsaleorder AS A
			INNER JOIN '.$this->sysTableHead.'shopsaleordercont AS B ON B.shsoctIndexID=A.shsotID
			WHERE 1=1 AND A.shsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shsotNumCode']['Value'],$tmpSQL);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='查询的订单号并不存在，请联系管理员。';
			return $this->sysErrorFuncID.'001';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		//-- ------ #Update state ------ --
		if($pDescriptions[0]['Columns']['shsotState']['Value']==5){
			$this->TransRollback();
			$this->sysLastError='本订单已处理，积分已支付给用户。';
			return $this->sysErrorFuncID.'004';
		}
		//Check money
		if($pDescriptions[0]['Columns']['shsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shsotPayyet']['Value']){
			$pDescriptions[0]['Columns']['shsotState']['Value']=4;
		}else {
			$pDescriptions[0]['Columns']['shsotState']['Value']=5;
		}
		//Settlement Code
		if($pDescriptions[0]['Columns']['shsotState']['Value']==5){
			$tmpSQL=' UPDATE '.$this->sysTableHead.'netsuserinfo SET uitCode=uitCode+{Nets.Code} WHERE 1=1 AND uitID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.Code}',$pDescriptions[0]['Columns']['shsotTotalCode']['Value'],$tmpSQL);
			$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotCreateBy']['Value'],$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='处理用户积分时出错，请联系管理员。';
				return $this->sysErrorFuncID.'004';
			}
		}
		//Update order state
		$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsaleorder SET shsotState={Nets.State} WHERE shsotID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.State}',$pDescriptions[0]['Columns']['shsotState']['Value'],$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态时出错，请联系管理员。';
			return $this->sysErrorFuncID.'003';
		}
		
		$this->TransCommit();
		return 0;
	}
	public function cancelOrder(&$pDescriptions){
		/*
返回资金给用户
修改订单状态
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'04';
		$this->TransStart();
		//-- ------ #Get order ------ --
		//Get order
		$tmpSQL=' SELECT *
			FROM '.$this->sysTableHead.'shopsaleorder AS A
			INNER JOIN '.$this->sysTableHead.'shopsaleordercont AS B ON B.shsoctIndexID=A.shsotID
			WHERE 1=1 AND A.shsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shsotNumCode']['Value'],$tmpSQL);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='查询的订单号并不存在，请联系管理员。';
			return $this->sysErrorFuncID.'001';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		//-- ------ #Settlement Amount ------ --
		$tmpMoney=$pDescriptions[0]['Columns']['shsotPayyet']['Value'];
		$tmpCode=0.00;
		if($pDescriptions[0]['Columns']['shsotState']['Value']==5){
			$tmpCode=$pDescriptions[0]['Columns']['shsotTotalCode']['Value'];
		}
		$tmpSQL=' UPDATE '.$this->sysTableHead.'netsuserinfo SET uitCode=uitCode+{Nets.Money},uitCode=uitCode-{Nets.Code} WHERE 1=1 AND uitID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.Code}',$tmpMoney,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Code}',$tmpCode,$tmpSTR);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotCreateBy']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='处理用户资金与积分时出错，请联系管理员。';
			return $this->sysErrorFuncID.'004';
		}
		//-- ------ #Update state ------ --
		//Update order state
		$pDescriptions[0]['Columns']['shsotState']['Value']=7;
		$tmpSQL=' UPDATE shopsaleorder SET shsotState={Nets.State} WHERE shsotID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.State}',$pDescriptions[0]['Columns']['shsotState']['Value'],$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态时出错，请联系管理员。';
			return $this->sysErrorFuncID.'003';
		}
		
		$this->TransCommit();
		return 0;
	}
	public function backOrder(&$pDescriptions){
		/*
修改订单状态
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'04';
		$this->TransStart();
		$this->TransStart();
		//-- ------ #Get order ------ --
		//Get order
		$tmpSQL=' SELECT *
			FROM '.$this->sysTableHead.'shopsaleorder AS A
			INNER JOIN '.$this->sysTableHead.'shopsaleordercont AS B ON B.shsoctIndexID=A.shsotID
			WHERE 1=1 AND A.shsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shsotNumCode']['Value'],$tmpSQL);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='查询的订单号并不存在，请联系管理员。';
			return $this->sysErrorFuncID.'001';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		//-- ------ #Update state ------ --
		//Check state
		if($pDescriptions[0]['Columns']['shsotState']['Value']==4 ||
			$pDescriptions[0]['Columns']['shsotState']['Value']==5){
			$pDescriptions[0]['Columns']['shsotState']['Value']=6;
		}else {
			$this->TransRollback();
			$this->sysLastError='对不起，只有在确认收货后，才能退货。';
			return $this->sysErrorFuncID.'001';
		}
		//Update order state
		$tmpSQL=' UPDATE '.$this->sysTableHead.'shopsaleorder SET shsotState={Nets.State} WHERE shsotID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.State}',$pDescriptions[0]['Columns']['shsotState']['Value'],$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态时出错，请联系管理员。';
			return $this->sysErrorFuncID.'003';
		}
		
		$this->TransCommit();
		return 0;
	}
	
	
	
}
?>