<?php
class shopcodesaleorder extends netsDb {
	private $sysErrorClassID='0000';
	private $sysErrorFuncID=0;
	private $sysErrorID=0;
	
	protected  $sOrderRecordType=3;
	public $sCellCount=9;
	
	
	public function shopcodesaleorder($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='shcsotName';
		if(strlen($pTableDescriptAR[0]['Columns'][$tmpSTR]['Value'])<1 && !in_array($tmpSTR,$pExceptionAR2)){
			$this->sysLastError='提交内容错误:1.名称不能为空';
			return $this->sysErrorFuncID.'001';
		}
		
		return 0;
	}
	
	public function order_Generate(&$pDescriptions,$pUserinfo){
		/*
		Generate orders
		
		#.Record user HABITS
		#.ORDER
		#.Calculation of MONEY and CODE
		#.Update sales count
		#.Generate orders
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Record user HABITS ------ --
		$tmpAR0=array('Order_Userreceiveaddress_Codesale',
			'Order_Sendmodel_Codesale',);
		foreach ($tmpAR0 as $Row0){
			//-- #VALUE --
			$tmpValue='';
			if ($Row0=='Order_Userreceiveaddress_Codesale') {
				$tmpValue=$pDescriptions[1]['Columns']['shcsoctReceiveaddressid']['Value'];
			}else if ($Row0=='Order_Userpaytype') {
				$tmpValue=$pDescriptions[1]['Columns']['shcsoctPayTypeid']['Value'];
			}else if ($Row0=='Order_PayBeforehand') {
				$tmpValue=$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value'];
			}else if ($Row0=='Order_Sendmodel_Codesale') {
				$tmpValue=$pDescriptions[1]['Columns']['shcsoctSendmodelid']['Value'];
			}else if ($Row0=='Order_Invoice') {
				$tmpValue=$pDescriptions[1]['Columns']['shcsoctInvoice']['Value'].$this->sysSPLIT5.
					$pDescriptions[1]['Columns']['shcsoctInvoiceContent']['Value'].$this->sysSPLIT5.
					str_replace($this->sysSPLIT1,$this->sysSPLIT2,$pDescriptions[1]['Columns']['shcsoctFavourableids']['Value']).$this->sysSPLIT5;
				
			}
			//-- #SEARCH --
			$tmpSQL=' SELECT A.uihtID,A.uihtFlag,A.uihtValue
				FROM {Nets.TableHead}netsuserinfohabits AS A
				WHERE 1=1 AND A.uihtRecycle=0 AND A.uihtChecked>1 AND 
				A.uihtCreateBy={Nets.CreateBy} AND A.uihtFlag LIKE \'{Nets.Flag}\' ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.CreateBy}',$pUserinfo[0]['Columns']['uitID']['Value'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.Flag}',$Row0,$tmpSTR);
			$tmpData0=$this->Search($tmpSTR);
			if (count($tmpData0)==0) {
				//-- #ADD --
				$tmpDbDescriptions=array(
					$this->sDbDescriptions_Other[2],
					$this->sDbDescriptions_Other[3],);
				//#Get numCode
				$tmpSTR='uihtNumCode';
				$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
				$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N'.$this->sysSPLIT11.date('YmdHis');
				$this->numCode($tmpDbDescriptions[0]);
				
				//-- #Setting --
				$tmpDbDescriptions[0]['Columns']['uihtName']['Value']=$Row0;
				$tmpDbDescriptions[0]['Columns']['uihtChecked']['Value']=2;
				$tmpDbDescriptions[0]['Columns']['uihtFlag']['Value']=$Row0;
				$tmpDbDescriptions[0]['Columns']['uihtValue']['Value']=$tmpValue;
				
				$tmpDbDescriptions[0]['Columns']['uihtCreateBy']['Value']=$pUserinfo[0]['Columns']['uitID']['Value'];
				$tmpDbDescriptions[0]['Columns']['uihtCreateTime']['Value']=date($this->sysTimeFormat);
				//-- #Add --
				$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='uihtNumCode,uihtID';
				$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='uihctIndexID';
				$tmpINT=$this->add($tmpDbDescriptions);
				if($tmpINT!=0){
					$this->TransRollback();
					$this->sysLastError='保存用户习惯信息出错，请客服人员联系。';
					return $tmpINT;
				}
				
			}else if ($tmpData0[0]['uihtValue']!=$tmpValue) {
				//-- #MODIFY --
				$tmpDbDescriptions=array(
					$this->sDbDescriptions_Other[2],
					$this->sDbDescriptions_Other[3],);
				//#Get one
				$tmpDbDescriptions[0]['Columns']['uihtID']['Value']=$tmpData0[0]['uihtID'];
				$tmpDbDescriptions[1]['Columns']['uihctIndexID']['Value']=$tmpData0[0]['uihtID'];
				$this->getOne($tmpDbDescriptions);
				//-- #Setting --
				$tmpDbDescriptions[0]['Columns']['uihtName']['Value']=$Row0;
				$tmpDbDescriptions[0]['Columns']['uihtChecked']['Value']=2;
				$tmpDbDescriptions[0]['Columns']['uihtFlag']['Value']=$Row0;
				$tmpDbDescriptions[0]['Columns']['uihtValue']['Value']=$tmpValue;
				
				$tmpDbDescriptions[0]['Columns']['uihtCreateBy']['Value']=$pUserinfo[0]['Columns']['uitID']['Value'];
				$tmpDbDescriptions[0]['Columns']['uihtCreateTime']['Value']=date($this->sysTimeFormat);
				
				//#Modify
				$tmpINT=$this->modify($tmpDbDescriptions);
				if($tmpINT!=0){
					$this->TransRollback();
					$this->sysLastError='保存用户习惯信息出错，请客服人员联系。';
					return $tmpINT;
				}
				
				
			}
		}
		//-- ------ #ORDER ------ --
		//-- ------ #Calculation of MONEY and CODE ------ --
		$tmpAR0=explode($this->sysSPLIT5,$pDescriptions[1]['Columns']['shcsoctSales']['Value']);
		$tmpCar_List=array();//ID,Count,Price,Code,Activeid,Parentid,Type,Parameters(8)
		$tmpSTR_0='';
		foreach ($tmpAR0 as $Row0) {
			$tmpAR1=explode($this->sysSPLIT2,$Row0);
			if (count($tmpAR1)==$this->sCellCount) {
				$tmpCar_List[]=array(
					'ID'=>$tmpAR1[0],
					'Count'=>$tmpAR1[1],
					'Price'=>$tmpAR1[2],
					'Code'=>$tmpAR1[3],
					'Activeid'=>$tmpAR1[4],
					'Parentid'=>$tmpAR1[5],
					'Type'=>$tmpAR1[6],
					'Parameters'=>$tmpAR1[7],
					);
			}
			
		}
		$tmpINT=$this->order_CheckContent($tmpCar_List);
		$tmpPay_Price=0.00;
		$tmpPay_Code=0.00;
		foreach ($tmpCar_List as $Row0){
			$tmpPay_Price+=$Row0['Price']*$Row0['Count'];
			$tmpPay_Code+=$Row0['Code']*$Row0['Count'];
		}
		
		//-- ------ #Update sales count ------ --
		//-- #Check count --
		$tmpSQL=' SELECT A.shcsctIndexID
				FROM {Nets.TableHead}shopcodesalecont AS A
				WHERE 1=1 AND (1=2 {Nets.Condition}) ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR_0='';
		foreach ($tmpCar_List as $Row0){
			$tmpSTR_0.=' OR (A.shcsctIndexID='.$Row0['ID'].' AND A.shcsctCount_Total<'.$Row0['Count'].') ';
		}
		$tmpSTR=str_replace('{Nets.Condition}',$tmpSTR_0,$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if (count($tmpData0)>0) {
			$this->TransRollback();
			$this->sysLastError='您所订购的商品数量不足。';
			return $this->sysErrorFuncID.'001';
		}
		
		//-- #Update count --
		foreach ($tmpCar_List as $Row0){
			$tmpSQL=' UPDATE {Nets.TableHead}shopcodesalecont AS A SET
				A.shcsctCount_Total=A.shcsctCount_Total-{Nets.Count},
				A.shcsctCount_Order=A.shcsctCount_Order+{Nets.Count}
				WHERE 1=1 AND A.shcsctIndexID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Count}',$Row0['Count'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.ID}',$Row0['ID'],$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='更新商品数量时出错，请与客服人员联系。';
				return $tmpINT;
			}
			
		}
		
		//-- ------ #Generate orders ------ --
		//-- ------ #Add ------ --
		//#Get numCode
		$tmpSTR='shcsotNumCode';
		$pDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$pDescriptions[0]['Columns'][$tmpSTR]['Value']=$this->sysFileConfig['NumCodeHead_Order'].$this->sysSPLIT11.date('YmdHis');
		$this->numCode($pDescriptions[0]);
		
		//-- #Setting --
		//#shcsotPayyet,shcsotTotalPrice,shcsotTotalCode
		$pDescriptions[0]['Columns']['shcsotPayyet']['Value']=0.00;
		$pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']=$tmpPay_Price;
		//#shcsoctSales
		$tmpContent='';
		foreach ($tmpCar_List as $Row0){
			$tmpContent.=$Row0['ID'].$this->sysSPLIT2.
				$Row0['Count'].$this->sysSPLIT2.
				$Row0['Price'].$this->sysSPLIT2.
				$Row0['Code'].$this->sysSPLIT2.
				$Row0['Activeid'].$this->sysSPLIT2.
				$Row0['Parentid'].$this->sysSPLIT2.
				$Row0['Type'].$this->sysSPLIT2.
				$Row0['Parameters'].$this->sysSPLIT2.
				$this->sysSPLIT5;
		}
		$pDescriptions[1]['Columns']['shcsoctSales']['Value']=$tmpContent;
		//#Other
		$pDescriptions[0]['Columns']['shcsotState']['Value']=0;
		$pDescriptions[0]['Columns']['shcsotName']['Value']=$pDescriptions[0]['Columns']['shcsotNumCode']['Value'];
		$pDescriptions[0]['Columns']['shcsotCreateBy']['Value']=$pUserinfo[0]['Columns']['uitID']['Value'];
		$pDescriptions[0]['Columns']['shcsotCreateTime']['Value']=date($this->sysTimeFormat);
		
		//-- #Add --
		$tmpINT=$this->Check($pDescriptions,array(),array());
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请客服人员联系。';
			return $tmpINT;
		}
		$pDescriptions[0]['TableDescription']['SearchColumn']='shcsotNumCode,shcsotID';
		$pDescriptions[1]['TableDescription']['SearchColumn']='shcsoctIndexID';
		$tmpINT=$this->add($pDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请客服人员联系。';
			return $tmpINT;
		}
		
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：生成订单；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		
		$this->TransCommit();
		return 0;
	}
	public function order_Pay(&$pDescriptions,$pUserinfo,&$pURL){
		/*
		Pay order
		
		#.Get order
		#.根据不同支付方式支付
		#.如果资金不足则用已选支付方式支付
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Get order ------ --
		$tmpSQL=' SELECT * 
			FROM {Nets.TableHead}shopcodesaleorder AS A
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1 AND A.shcsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shcsotNumCode']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		
		//-- ------ #Pay ------ --
		//1.先从帐号的资金里扣除，再使用以下方式支付 
		//2.直接从帐号的资金里扣除，不足的提示我充值 
		//3.先从帐号的资金里扣除，不足部分使用货到付款 
		//4.直接使用已选择的方式支付 
		//5.货到付款 
		
		//Check pay type
		$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']=2;
		if($pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']!=1 &&
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']!=2 &&
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']!=3 &&
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']!=4 &&
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']!=5){
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']=1;
		}
		//Beforehand pay
		//1.先从帐号的资金里扣除，再使用以下方式支付
		//2.直接从帐号的资金里扣除，不足的提示我充值
		//3.先从帐号的资金里扣除，不足部分使用货到付款
		if($pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==1 ||
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==2 ||
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==3){
			$tmpPayyet=0.00;
			$tmpPaymust=$pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
			if($pUserinfo[0]['Columns']['uitCode']['Value']<$tmpPaymust){
				//-- ### --
				$this->TransRollback();
				$this->sysLastError='您的积分不足，请客服人员联系。';
				return $this->sysErrorFuncID.'002';
			}else {
				$tmpPayyet=$tmpPaymust;
			}
			$tmpSQL=' UPDATE {Nets.TableHead}netsuserinfo AS A 
				SET A.uitCode=A.uitCode-{Nets.Money} 
				WHERE 1=1 AND A.uitID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Money}',$tmpPayyet,$tmpSTR);
			$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 {Nets.TableHead}shopcodesaleorder AS A
				SET A.shcsotPayyet=A.shcsotPayyet+{Nets.Money} 
				WHERE 1=1 AND shcsotID={Nets.ID}; ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Money}',$tmpPayyet,$tmpSTR);
			$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
			$tmpINT=$this->Execute($tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='用户帐户支付错误，请客服人员联系。';
				return $this->sysErrorFuncID.'002';
			}
			$pDescriptions[0]['Columns']['shcsotPayyet']['Value']=$pDescriptions[0]['Columns']['shcsotPayyet']['Value']+$tmpPayyet;
		}
		//Set pay set
		$tmpState=0;
		if($pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shcsotPayyet']['Value']){
			//用户帐户里资金不足，或不用用户帐户扣除
			if($pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==3 ||
				$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==5){
				$tmpState=3;
			}else {
				$tmpState=1;
			}
		}else {
			//用户帐户里资金足以支付本订单
			$tmpState=2;
		}
		$tmpSQL=' UPDATE {Nets.TableHead}shopcodesaleorder AS A 
			SET A.shcsotState={Nets.State} 
			WHERE 1=1 AND A.shcsotID={Nets.ID}; ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.State}',$tmpState,$tmpSTR);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='用户帐户支付错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$pDescriptions[0]['Columns']['shcsotState']['Value']=$tmpState;
		//Clear my sale car
		/*
		$tmpSQL=' SELECT A.shcsctID
			FROM {Nets.TableHead}groupsalecar AS A
			WHERE 1=1 AND A.shcsctCreateBy={Nets.CreateBy} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.CreateBy}',$pUserinfo[0]['Columns']['uitID']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		$tmpSQL=' DELETE FROM {Nets.TableHead}groupsalecar AS A
			WHERE 1=1 AND (1=2 {Nets.IDS}) ';
		$tmpSTR_0='';
		foreach ($tmpData0 as $Row0) {
			$tmpSTR_0.=' AND A.shcsctID='.$Row0['shcsctID'];
		}
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.IDS}',$tmpSTR_0,$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='清理用户购物车错误，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpSQL=' DELETE FROM {Nets.TableHead}groupsalecarcont 
			WHERE 1=1 AND (1=2 {Nets.IDS}) ';
		$tmpSTR_0='';
		foreach ($tmpData0 as $Row0) {
			$tmpSTR_0.=' AND gscctIndexID='.$Row0['shcsctID'];
		}
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.IDS}',$tmpSTR_0,$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='清理用户购物车错误，请联系管理员。';
			return $this->sysErrorFuncID.'002';
		}
		*/
		//Redirect
		if($pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==1 ||
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==4){
			//1.先从帐号的资金里扣除，再使用以下方式支付
			//4.直接使用以下方式支付
			if($pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shcsotPayyet']['Value']){
				$tmpSQL=' SELECT B.shuptctWebpaySiteURL
					FROM {Nets.TableHead}shopuserpaytype AS A
					INNER JOIN {Nets.TableHead}shopuserpaytypecont AS B ON B.shuptctIndexID=A.shupttID
					WHERE 1=1 AND A.shupttID={Nets.ID} ';
				$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
				$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[1]['Columns']['shcsoctPayTypeid']['Value'],$tmpSTR);
				$tmpData0=$this->Search($tmpSTR);
				if (count($tmpData0)==0) {
					$pURL=$this->sysFileConfig['PaySubmit_Default'];
				}else {
					$pURL=$tmpData0[0]['shuptctWebpaySiteURL'];
				}
				$pURL.='?NumCode='.$pDescriptions[0]['Columns']['shcsotNumCode']['Value'];
				$tmpPayyet=$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，您还必须为本订单支付￥'.$tmpPaywill.'(人民币)。';
			}else {
				$pURL='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)。';
			}
		}else if($pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==2){
			//2.直接从帐号的资金里扣除，不足的提示我充值
			if($pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shcsotPayyet']['Value']){
				$pURL='Plus/Common/Shop/userpay0.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，您还必须为您的帐户充值￥'.$tmpPaywill.'(人民币)才足已支付本订单。';
			}else {
				$pURL='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)。';
			}
		}else if($pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==3 ||
			$pDescriptions[1]['Columns']['shcsoctPayBeforehand']['Value']==5){
			//3.先从帐号的资金里扣除，不足部分使用货到付款
			//5.货到付款
			if($pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']>$pDescriptions[0]['Columns']['shcsotPayyet']['Value']){
				$pURL='Plus/Common/Shop/saleorder.php';
				$tmpPayyet=$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$tmpPaywill=$pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']-$pDescriptions[0]['Columns']['shcsotPayyet']['Value'];
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！为支付本订单，系统已从您平台帐户里扣除了￥'.$tmpPayyet.'(人民币)，由于您的帐户里的资金不足已支付本订单，当收款时，您还必须为本订单支付￥'.$tmpPaywill.'(人民币)。';
			}else {
				$pURL='Plus/Common/Shop/saleorder.php';
				$this->sysLastMessage='订单已提交成功，平台已通知商家发货！(货到付款方式)';
			}
		}
		$pURL='';
		$this->sysLastMessage='您的积分订单已成功提交，请等待送货';
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：正在支付本订单；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function order_PaySuccess(&$pDescriptions){
		/*
		支付返回，确认订单支付完成
		
		#.Get order
		#.Make up the user order the amount paid
		#.Modify Order Status
		#.Add user CODE
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Get order ------ --
		$tmpSQL=' SELECT * 
			FROM {Nets.TableHead}shopcodesaleorder AS A
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1 AND A.shcsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shcsotNumCode']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='更新订单时错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		
		//-- ------ #Make up the user order the amount paid ------ --
		//-- ------ #Modify Order Status ------ --
		//-- #Check --
		if ($pDescriptions[0]['Columns']['shcsotState']['Value']!=0 &&
			$pDescriptions[0]['Columns']['shcsotState']['Value']!=1) {
			$this->TransRollback();
			$this->sysLastError='您的订单已完成支付，不能再次支付。';
			return $this->sysErrorFuncID.'002';
		}
		//-- #Update --
		$tmpSQL=' UPDATE {Nets.TableHead}shopcodesaleorder AS A
			SET A.shcsotState=2,A.shcsotPayyet=A.shcsotTotalPrice
			WHERE 1=1 AND A.shcsotID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		
		//-- ------ #Add user CODE ------ --
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：支付成功；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function order_RecieveConfirm(&$pDescriptions){
		/*
		申请退货
		
		#.Get order
		#.Update order status
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Get order ------ --
		$tmpSQL=' SELECT * 
			FROM {Nets.TableHead}shopcodesaleorder AS A
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1 AND A.shcsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shcsotNumCode']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		
		//-- ------ #Update order status ------ --
		//-- #Check --
		if ($pDescriptions[0]['Columns']['shcsotState']['Value']!=2 &&
			$pDescriptions[0]['Columns']['shcsotState']['Value']!=3) {
			$this->TransRollback();
			$this->sysLastError='未发起送货的商品不能确认收货。';
			return $this->sysErrorFuncID.'002';
		}
		//-- #Update --
		$tmpSQL=' UPDATE {Nets.TableHead}shopcodesaleorder AS A
			SET A.shcsotState=4,A.shcsotPayyet=A.shcsotTotalPrice
			WHERE 1=1 AND A.shcsotID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：成功收货；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function order_Complete(&$pDescriptions){
		/*
		订单完成
		
		#.Get order
		#.Update order status
		#.Add CODE to user
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Get order ------ --
		$tmpSQL=' SELECT * 
			FROM {Nets.TableHead}shopcodesaleorder AS A
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1 AND A.shcsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shcsotNumCode']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		
		//-- ------ #Update order status ------ --
		//-- #Check --
		if ($pDescriptions[0]['Columns']['shcsotState']['Value']!=3 &&
			$pDescriptions[0]['Columns']['shcsotState']['Value']!=4 &&
			$pDescriptions[0]['Columns']['shcsotState']['Value']!=5) {
			$this->TransRollback();
			$this->sysLastError='商品未发货或未确认收货，不能结单。';
			return $this->sysErrorFuncID.'002';
		}
		if ($pDescriptions[0]['Columns']['shcsotPayyet']['Value']!=$pDescriptions[0]['Columns']['shcsotTotalPrice']['Value']) {
			$this->TransRollback();
			$this->sysLastError='订单未完成支付，不能结单。';
			return $this->sysErrorFuncID.'002';
		}
		//-- #Update --
		$tmpSQL=' UPDATE {Nets.TableHead}shopcodesaleorder AS A
			SET A.shcsotState=5
			WHERE 1=1 AND A.shcsotID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		//-- ------ #Add CODE to user ------ --
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：成功完成订单；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function order_Cancel(&$pDescriptions){
		/*
		取消订单
		
		#.Get order
		#.Modify Order Status
		#.Return of money paid to the user
		#.Return sales
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Get order ------ --
		$tmpSQL=' SELECT * 
			FROM {Nets.TableHead}shopcodesaleorder AS A
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1 AND A.shcsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shcsotNumCode']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='更新订单时错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		
		//-- ------ #Modify Order Status ------ --
		//-- #Check --
		if ($pDescriptions[0]['Columns']['shcsotState']['Value']!=0 &&
			$pDescriptions[0]['Columns']['shcsotState']['Value']!=1) {
			$this->TransRollback();
			$this->sysLastError='您的订单已支付成功，不能取消。';
			return $this->sysErrorFuncID.'002';
		}
		//-- #Update --
		$tmpSQL=' UPDATE {Nets.TableHead}shopcodesaleorder AS A
			SET A.shcsotState=7,A.shcsotPayyet=0
			WHERE 1=1 AND A.shcsotID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		//-- ------ #Return of money paid to the user ------ --
		$tmpSQL=' UPDATE {Nets.TableHead}netsuserinfo AS A
			SET A.uitCode=A.uitCode+{Nets.Money}
			WHERE 1=1 AND A.uitID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Money}',$pDescriptions[0]['Columns']['shcsotPayyet']['Value'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotCreateBy']['Value'],$tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新用户资金时错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		
		//-- ------ #Return sales ------ --
		$tmpCar_List=array();
		$tmpAR0=explode($this->sysSPLIT3,$pDescriptions[1]['Columns']['shcsoctSales']['Value']);
		$Coun0=0;
		foreach ($tmpAR0 as $Row0){
			$tmpAR1=explode($this->sysSPLIT2,$Row0);
			if (count($tmpAR1)==$this->sCellCount) {
				$tmpCar_List[$Coun0]['ID']=$tmpAR1[0];
				$tmpCar_List[$Coun0]['Count']=$tmpAR1[1];
				$tmpCar_List[$Coun0]['Price']=$tmpAR1[2];
				$tmpCar_List[$Coun0]['Code']=$tmpAR1[3];
				$tmpCar_List[$Coun0]['Activeid']=$tmpAR1[4];
				$tmpCar_List[$Coun0]['Parentid']=$tmpAR1[5];
				$tmpCar_List[$Coun0]['Type']=$tmpAR1[6];
				$tmpCar_List[$Coun0]['Parameters']=$tmpAR1[7];
				$Coun0++;
			}
		}
		$Coun0=0;
		foreach ($tmpCar_List as $Row0){		
			$tmpSQL=' UPDATE {Nets.TableHead}shopcodesalecont AS A
				SET A.shcsctCount_Total=A.shcsctCount_Total-{Nets.Count_Order},
				A.shcsctCount_Order=A.shcsctCount_Order-{Nets.Count_Order}
				WHERE 1=1 AND A.shcsctIndexID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Count_Order}',$Row0['Count'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.ID}',$Row0['ID'],$tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='返回商品数量时错误，请客服人员联系。';
				return $this->sysErrorFuncID.'002';
			}
			
			$Coun0++;
		}
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：确定取消订单；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function order_Returns(&$pDescriptions){
		/*
		申请退货
		
		#.Get order
		#.Update order status
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Get order ------ --
		$tmpSQL=' SELECT * 
			FROM {Nets.TableHead}shopcodesaleorder AS A
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1 AND A.shcsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shcsotNumCode']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		
		//-- ------ #Update order status ------ --
		//-- #Check --
		if ($pDescriptions[0]['Columns']['shcsotState']['Value']!=3 &&
			$pDescriptions[0]['Columns']['shcsotState']['Value']!=4 &&
			$pDescriptions[0]['Columns']['shcsotState']['Value']!=5) {
			$this->TransRollback();
			$this->sysLastError='您的订单已支付成功，不能取消。';
			return $this->sysErrorFuncID.'002';
		}
		//-- #Update --
		$tmpSQL=' UPDATE {Nets.TableHead}shopcodesaleorder AS A
			SET A.shcsotState=6
			WHERE 1=1 AND A.shcsotID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：申请返还货物；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}
	public function order_ReturnsSuccess(&$pDescriptions){
		/*
		退货成功确认
		
		#.Get order
		#.Update order status
		#.返还资金给用户
		#.返还订单积分
		#.返还商品数量
		*/
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		$this->TransStart();
		$tmpApp_Code=new netsCode();
		//-- ------ #Get order ------ --
		$tmpSQL=' SELECT * 
			FROM {Nets.TableHead}shopcodesaleorder AS A
			INNER JOIN {Nets.TableHead}shopcodesaleordercont AS B ON B.shcsoctIndexID=A.shcsotID
			WHERE 1=1 AND A.shcsotNumCode LIKE \'{Nets.NumCode}\' ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.NumCode}',$pDescriptions[0]['Columns']['shcsotNumCode']['Value'],$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		if(count($tmpData0)==0){
			$this->TransRollback();
			$this->sysLastError='订单生成错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		$tmpINT=$this->getDescriptionFromData($pDescriptions,$tmpData0);
		
		//-- ------ #Update order status ------ --
		//-- #Check --
		if ($pDescriptions[0]['Columns']['shcsotState']['Value']!=6) {
			$this->TransRollback();
			$this->sysLastError='未申请退货，不能确认退货。';
			return $this->sysErrorFuncID.'002';
		}
		//-- #Update --
		$tmpSQL=' UPDATE {Nets.TableHead}shopcodesaleorder AS A
			SET A.shcsotState=7
			WHERE 1=1 AND A.shcsotID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotID']['Value'],$tmpSTR);
		$tmpINT=$this->Execute($tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新订单状态错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		
		//-- ------ #Return of money paid to the user ------ --
		$tmpSQL=' UPDATE {Nets.TableHead}netsuserinfo AS A
			SET A.uitCode=A.uitCode+{Nets.Money}
			WHERE 1=1 AND A.uitID={Nets.ID} ';
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.Money}',$pDescriptions[0]['Columns']['shcsotPayyet']['Value'],$tmpSTR);
		$tmpSTR=str_replace('{Nets.ID}',$pDescriptions[0]['Columns']['shcsotCreateBy']['Value'],$tmpSTR);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='更新用户资金时错误，请客服人员联系。';
			return $this->sysErrorFuncID.'002';
		}
		//-- ------ #Return of money paid to the user ------ --
		
		//-- ------ #Return sales ------ --
		$tmpCar_List=array();
		$tmpAR0=explode($this->sysSPLIT3,$pDescriptions[1]['Columns']['shcsoctSales']['Value']);
		$Coun0=0;
		foreach ($tmpAR0 as $Row0){
			$tmpAR1=explode($this->sysSPLIT2,$Row0);
			if (count($tmpAR1)==4) {
				$tmpCar_List[$Coun0]['ID']=$tmpAR1[0];
				$tmpCar_List[$Coun0]['Count']=$tmpAR1[1];
				$tmpCar_List[$Coun0]['Price']=$tmpAR1[2];
				$tmpCar_List[$Coun0]['Code']=$tmpAR1[3];
				$tmpCar_List[$Coun0]['Activeid']=$tmpAR1[4];
				$tmpCar_List[$Coun0]['Parentid']=$tmpAR1[5];
				$tmpCar_List[$Coun0]['Type']=$tmpAR1[6];
				$tmpCar_List[$Coun0]['Parameters']=$tmpAR1[7];
				$Coun0++;
			}
		}
		$Coun0=0;
		foreach ($tmpCar_List as $Row0){		
			$tmpSQL=' UPDATE {Nets.TableHead}shopcodesalecont AS A
				SET A.shcsctCount_Order=A.shcsctCount_Order-{Nets.Count_Order}
				WHERE 1=1 AND A.shcsctIndexID={Nets.ID} ';
			$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
			$tmpSTR=str_replace('{Nets.Count_Order}',$Row0['Count'],$tmpSTR);
			$tmpSTR=str_replace('{Nets.ID}',$Row0['ID'],$tmpSTR);
			if($tmpINT!=0){
				$this->TransRollback();
				$this->sysLastError='返回商品数量时错误，请客服人员联系。';
				return $this->sysErrorFuncID.'002';
			}
			
			$Coun0++;
		}
		//-- ------ #Record ------ --
		$tmpDbDescriptions=array(
			$this->sDbDescriptions_Other[0],
			$this->sDbDescriptions_Other[1],
			);
		//#Get numCode
		$tmpSTR='shsortNumCode';
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']=$tmpSTR;
		$tmpDbDescriptions[0]['Columns'][$tmpSTR]['Value']='N_'.date('YmdHis');
		$this->numCode($tmpDbDescriptions[0]);
		//-- #Set --
		$tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'].='：成功收货；';
		
		$tmpDbDescriptions[0]['Columns']['shsortName']['Value']=$tmpApp_Code->SubString($tmpDbDescriptions[1]['Columns']['shsorctContent']['Value'],0,60);
		$tmpDbDescriptions[0]['Columns']['shsortParid']['Value']=$pDescriptions[0]['Columns']['shcsotID']['Value'];
		$tmpDbDescriptions[0]['Columns']['shsortChecked']['Value']=2;
		$tmpDbDescriptions[0]['Columns']['shsortSaleType']['Value']=$this->sOrderRecordType;
		$tmpDbDescriptions[0]['Columns']['shsortCreateTime']['Value']=date($this->sysTimeFormat);
		
		//#Add
		$tmpDbDescriptions[0]['TableDescription']['SearchColumn']='shsortNumCode,shsortID';
		$tmpDbDescriptions[1]['TableDescription']['SearchColumn']='shsorctIndexID';
		$tmpINT=$this->add($tmpDbDescriptions);
		if($tmpINT!=0){
			$this->TransRollback();
			$this->sysLastError='生成操作记录错误，请客服人员联系。';
			return $tmpINT;
		}
		
		$this->TransCommit();
		return 0;
	}

	public function order_MakeContent($pOperation,$pContent,&$pContent_Cookie,&$pAR_Content){
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		//-- ------ ### ------ --
		$tmpAR_Content=array();
		$tmpAR_Operation=array();
		//-- ------ #$pContent_Cookie ------ --
		$tmpAR0=explode($this->sysSPLIT5,$pContent_Cookie);
		$Coun0=0;
		foreach ($tmpAR0 as $Row0){
			$tmpAR1=explode($this->sysSPLIT2,$Row0);
			if (count($tmpAR1)==$this->sCellCount) {
				$tmpAR_Content[]=$tmpAR1;
			}
			$Coun0++;
		}
		//-- ------ #$pContent ------ --
		if ($pContent!='') {
			$tmpAR_Content=array();
			$tmpAR0=explode($this->sysSPLIT5,$pContent);
			$Coun0=0;
			foreach ($tmpAR0 as $Row0){
				$tmpAR1=explode($this->sysSPLIT2,$Row0);
				if (count($tmpAR1)==$this->sCellCount) {
					$tmpAR_Content[]=$tmpAR1;
				}
				$Coun0++;
			}
		}
		//-- ------ #$pOperation ------ --
		$tmpAR0=explode($this->sysSPLIT5,$pOperation);
		$Coun0=0;
		foreach ($tmpAR0 as $Row0){
			$tmpAR1=explode($this->sysSPLIT2,$Row0);
			if (count($tmpAR1)==$this->sCellCount) {
				$tmpAR_Operation[]=$tmpAR1;
			}
			$Coun0++;
		}
		//-- ------ ### ------ --
		//-- #Replace --
		$Coun0=0;
		while (count($tmpAR_Operation)>$Coun0) {
			$Coun1=0;
			while (count($tmpAR_Content)>$Coun1){
				if ($tmpAR_Operation[$Coun0][0]==$tmpAR_Content[$Coun1][0] &&
					$tmpAR_Operation[$Coun0][4]==$tmpAR_Content[$Coun1][4] &&
					$tmpAR_Operation[$Coun0][5]==$tmpAR_Content[$Coun1][5] &&
					$tmpAR_Operation[$Coun0][6]==$tmpAR_Content[$Coun1][6] &&
					$tmpAR_Operation[$Coun0][7]==$tmpAR_Content[$Coun1][7]) {
					$tmpAR_Content[$Coun1]=$tmpAR_Operation[$Coun0];
					$tmpAR_Operation[$Coun0]=array();
					$Coun1=count($tmpAR_Content)+1;
				}
				
				$Coun1++;
			}
			$Coun0++;
		}
		//-- #Add --
		$Coun0=0;
		while (count($tmpAR_Operation)>$Coun0) {
			if (count($tmpAR_Operation[$Coun0])==$this->sCellCount) {
				$tmpAR_Content[]=$tmpAR_Operation[$Coun0];
			}
			$Coun0++;
		}
		//-- #Sub zore --
		$tmpAR0=$tmpAR_Content;
		$tmpAR_Content=array();
		$Coun0=0;
		while (count($tmpAR0)>$Coun0) {
			if (count($tmpAR0[$Coun0])==$this->sCellCount && $tmpAR0[$Coun0][1]>0) {
				$tmpAR_Content[]=$tmpAR0[$Coun0];
			}
			$Coun0++;
		}
		//-- #STR --
		$tmpSTR='';
		$Coun0=0;
		foreach ($tmpAR_Content as $Row0){
			$tmpSTR.=$Row0[0].$this->sysSPLIT2.
				$Row0[1].$this->sysSPLIT2.
				$Row0[2].$this->sysSPLIT2.
				$Row0[3].$this->sysSPLIT2.
				$Row0[4].$this->sysSPLIT2.
				$Row0[5].$this->sysSPLIT2.
				$Row0[6].$this->sysSPLIT2.
				$Row0[7].$this->sysSPLIT2.$this->sysSPLIT5;
			$Coun0++;
		}
		//-- ------ ### ------ --
		$pContent_Cookie=$tmpSTR;
		$pAR_Content=$tmpAR_Content;
		
		return 0;
	}
	public function order_CheckContent(&$pAR){
		$this->sysErrorFuncID=$this->sysErrorClassID.'01';
		//-- ------ ### ------ --
		$tmpCar_List=$pAR;
		//-- ------ ### ------ --
		//-- #Normal --
		$tmpSQL=' SELECT A.shcstID,A.shcstName,A.shcstPrice
		
			FROM {Nets.TableHead}shopcodesale AS A
			INNER JOIN {Nets.TableHead}shopcodesalecont AS B ON B.shcsctIndexID=A.shcstID
			WHERE 1=1 AND A.shcstRecycle=0 AND A.shcstChecked>1 AND (1=2 {Nets.IDS}) ';
		
		$Coun0=0;
		$tmpSTR_0='';
		foreach ($tmpCar_List as $Row0){
			if ($Row0['Type']==0) {
				$tmpSTR_0.=' OR A.shcstID='.$Row0['ID'];
			}
		}
		
		$tmpSTR=str_replace('{Nets.TableHead}',$this->sysTableHead,$tmpSQL);
		$tmpSTR=str_replace('{Nets.IDS}',$tmpSTR_0,$tmpSTR);
		$tmpData0=$this->Search($tmpSTR);
		$Coun0=0;
		foreach ($tmpData0 as $Row0){
			$Coun1=0;
			while (count($tmpCar_List)>$Coun1) {
				if ($tmpCar_List[$Coun1]['ID']==$Row0['shcstID']) {
					$tmpCar_List[$Coun1]['Price']=$Row0['shcstPrice'];
					$tmpCar_List[$Coun1]['Code']='0.00';
				}
				$Coun1++;
			}
			$Coun0++;
		}
		
		//-- ------ ### ------ --
		$pAR=$tmpCar_List;
		return 0;
	}

	
	
	
	
	
	
	
	
	
	
}
?>