<?php
include "../core.php";
saxue_checklogin();
include SAXUE_ROOT_PATH . "/model/member_account.php";
$account_handler = &saxuememberaccounthandler :: getinstance( "saxuememberaccounthandler" );
$account = $account_handler -> get( $_SESSION['saxueUserId'] );
include SAXUE_ROOT_PATH . "/model/member_bill.php";
$bill_handler = &saxuememberbillhandler :: getinstance( "saxuememberbillhandler" );
if ( isset( $_POST['dosubmit'] ) ) {
		$amount = saxue_dround( $_POST['amount'] );
		if ( $amount <= 0 ) {
				exit( json_encode( array( 'flag' => 0, 'msg' => '提现金额错误' ) ) );
		}
		if ( $amount > $_SESSION['saxueUserMoney'] ) {
				exit( json_encode( array( 'flag' => 0, 'msg' => '您的可用余额不足' ) ) );
		}
		$_POST['uid'] = $_SESSION['saxueUserId'];
		$_POST['applytime'] = SAXUE_NOW_TIME;
		$_POST['account'] = $account -> getvar( 'account' );
		$_POST['status'] = 0;
		$bill = $bill_handler -> create();
		if ( !$bill_handler -> insert( $bill ) ) {
				exit( json_encode( array( 'flag' => 0, 'msg' => LANG_ERROR_DATABASE ) ) );
		} 
		exit( json_encode( array( 'flag' => 1 ) ) );
}
$err = 0;
$_account = array();
if ( !$account ) {
		$err = 1;
} else {
		$_account = $account -> getvars( 'n' );
		$criteria = new criteriacompo( new criteria( "uid", $_SESSION['saxueUserId'] ) );
		$criteria -> add( new criteria( 'status', 0 ) );
		if ( 0 < $bill_handler -> getcount( $criteria ) ) {
				$err = 2;
		}
}
include SAXUE_ROOT_PATH . "/model/member_userdata.php";
$userdata_handler = &saxuememberuserdatahandler :: getinstance( "saxuememberuserdatahandler" );
$saxueUserdata = $userdata_handler -> get( $_SESSION['saxueUserId'] );
include SAXUE_WEB_PATH . "/member/header.php";
$saxueTpl -> assign( "err", $err );
$saxueTpl -> assign_by_ref( "account", $_account );
$saxueTpl -> assign_by_ref( "user", $saxueUserdata -> getvars( 'n' ) );
$saxueTpl -> setcaching( 0 );
$saxueTset['saxue_contents_template'] = SAXUE_THEME_PATH . "/member/cash.html";
include SAXUE_WEB_PATH . "/member/footer.php";
