<?php include $this->admin_tpl('meta', 'admin');?>
<title>在线充值 - YzmCMS内容管理系统</title>
</head>
<body>
<nav class="breadcrumb"><i class="yzm-iconfont yzm-iconai-home"></i> 首页 <span class="c-gray en">&gt;</span> 会员管理 <span class="c-gray en">&gt;</span> 账单管理 <span class="c-gray en">&gt;</span> 在线充值 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="yzm-iconfont yzm-iconshuaxin"></i></a></nav>
<div class="page-container">
  <div class="sub_menu"><a href="<?php echo U('pay');?>">入账记录</a> <a href="<?php echo U('pay_spend');?>">消费记录</a> <a href="<?php echo U('recharge');?>"  class="on">在线充值</a></div>
 <div class="formdoby_normal"> 
	<form method="post" action="" onsubmit="return checkall(this)">
		<ul>
			 <li><label><span class="c-red">*</span>充值类型：</label>
			 	<label class="label_radio"><input name="type" type="radio" value="2" checked> 金钱</label>
			 	<label class="label_radio"><input name="type" type="radio" value="1" > 积分</label>
			 </li>
			 <li class="yzm-explain-box">
			 	<label><span class="c-red">*</span>用户名：</label>
			 	<input type="text" class="input" name="username" id="username" value="<?php echo $username;?>">
			 	<span class="yzm-explain">当输入为邮箱时，系统将自动转换成用户名</span>
			 	<span class="userinfo f-12 ml-5"></span>
			 </li> 
			 <li><label><span class="c-red">*</span>充值额度：</label>
				 <label class="label_radio"><input name="unit" type="radio" value="1" checked> 增加</label>
				 <label class="label_radio"><input name="unit" type="radio" value="0" > 减少</label>
				 <input type="text" class="input" name="money" id="money" value="" style="width:70px"> 
				 <span style="color:#888;font-size:12px">输入修改数量（金钱或积分）</span>
			 </li> 
			 <li><label><span class="c-red">*</span>备注说明：</label>
			 	<textarea class="textarea" name="remarks" style="width:600px"></textarea>
			 </li>
			 <li class="yzm-explain-box"><label>提醒操作：</label>
			 	<input name="sendemail" value="1" type="checkbox"> 发送e-mail通知会员 <span class="yzm-explain">需填写邮箱配置</span>
			 </li>					 
			 <li style="margin:20px 0px;" >
			 	<input class="dosubmit w_100 btn-primary radius" name="dosubmit" type="submit" value="提交">
			 	<input class="btn w_100 btn-default radius h35" type="reset" value="重置">
			 </li> 
		</ul>
		
	</form>
  </div>
</div>
<?php include $this->admin_tpl('footer', 'admin');?>
<script type="text/javascript">
<?php if($username) echo 'checkname();'; ?>
$(function(){
   $("#username").blur(function(){
	  checkname();
   });	
   
   $("#money").blur(function(){
	  checkmoney();
   });   
})

function checkname(){
	var res = false;
	if($("#username").val() != ''){
		$.ajax({   
			type: "post",   
			url: "<?php echo U('member/member/public_memberinfo');?>",   
			dataType: "json",
			async: false,	
			data: "username="+$('#username').val(), 			
			success: function(msg){  
				if(msg.status){
					res = true;
					$(".userinfo").html('用户邮箱：'+msg.data.email+'，余额：<em class="c-red">'+msg.data.amount+'</em>，积分：<em class="c-green">'+msg.data.point+'</em>');	
					if(msg.status==2) $("#username").val(msg.data.username);
				}else{
					$(".userinfo").html('<span class="c-red">'+msg.message+'</span>');	
					layer.msg(msg.message, {icon:2});  
				}				 
			} 
		});
		return res;
	}else{
		$(".userinfo").html('<span class="c-red">用户名不能为空！</span>');
		layer.msg('用户名不能为空！', {icon:2});  
		return res;
	}		   
}

function checkmoney(){
	if($("#money").val() != ''){
		if(!isNaN($("#money").val())){
			return true;				  
		}else{
			layer.msg('充值额度只能为数字！', {icon:2});	
			return false;
		}
	}else{
		layer.msg('充值额度不能为空！', {icon:2});
		return false;
	}		   
}

function checkall(obj){
    if(!checkname() || !checkmoney()){
		return false;
	}

	if($("textarea[name='remarks']").val() == ''){
		layer.msg('备注说明不能为空！', {icon:2});
		return false;
	}

	layer.msg('正在充值中……', {icon:16, time:0, shade:0.3});
	$.ajax({
        type: 'POST',
        url: '<?php echo U(ROUTE_A);?>', 
        data: $(obj).serialize(),
	    dataType: "json", 
        success: function (msg) {
			if(msg.status == 1){
				layer.msg(msg.message, {icon:1, time:2000}, function(){
					window.location.href = msg.url;
				});
		    }else{
				layer.msg(msg.message, {icon:2});
			}
        }
    })		 
	return false;
}
</script>

</body>
</html>