<?php
defined('PP_PATH') or exit;
class pay_control extends admin_control{
	var $paydetail = NULL;
	public function __construct(){
		$this->_cfg = $this->runtime->xget('cfg');
		$this->id 	= (int)R('id', 'G');
	}
	public function lifealipay(){
		$this->getPaydetail($this->id);

		$submitdata['optEmail'] 	= $this->paydetail['alipay'];
		$submitdata['payAmount'] 	= $this->paydetail['money'];
		$submitdata['title'] 		= '提现';
		$submitdata['id'] 			= $this->paydetail['order_id'];
		$submitdata['memo'] 		= $this->paydetail['username'].'，提现'.$this->paydetail['totalmoney'].'，手续费'.$this->paydetail['charge'];
		
		$submitdata['isReceiveNameSend'] 		= 'true';
		$submitdata['inputRealName'] 			=  $this->paydetail['alipay_name'];
		$submitdata['isSend'] 					= 'true';
		$submitdata['smsNo'] 					=  $this->paydetail['mobile'];

		//print_r($submitdata);
		$this->create($submitdata,"https://shenghuo.alipay.com/send/payment/fill.htm");
	}
	private function getPaydetail($id){
		$data = $this->record->get($id);
		$user = $this->user->get($data['uid']);
		$this->paydetail['money'] 		= $data['money'] - $data['charge'];
		$this->paydetail['order_id']	= $data['order_id'];
		$this->paydetail['username']	= $user['username'];
		$this->paydetail['mobile'] 		= $user['mobile'];
		$this->paydetail['alipay_name'] 	= $user['alipay_name'];
		$this->paydetail['alipay'] 		= $user['alipay'];
		$this->paydetail['totalmoney'] 	= $data['money'];
		$this->paydetail['charge'] 		= $data['charge'];
	}
	private function create($data,$submitUrl){
		$inputstr = "";
		foreach($data as $key=>$v){
			$inputstr .= '
			<input type="hidden"  id="'.$key.'" name="'.$key.'" value="'.$v.'"/>
		';
		}
		
		$form = '
			<form action="'.$submitUrl.'" name="pay" id="pay" method="POST" accept-charset="GBK">
		';
		$form.=	$inputstr;
		$form.=	'
			</form>
		';
		
		$html = '
			<!doctype html>
			<html>
			<head>
			<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
			<title>请不要关闭页面,支付跳转中.....</title>
			</head>
			<body>
        ';
        $html.=	$form;
        $html.=	'
			<script type="text/javascript">
				document.getElementById("pay").submit();
			</script>
        ';
        $html.= '
			</body>
			</html>
		';
		echo $html;
		exit;
	}
}
