<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'member_check.php';

$action=$_GET["action"];
$money=round($_GET["money"],2);

if($action=="money"){
  $money=round($_POST["money"],2);
  $name=t($_POST["name"]);
  $alipay=t($_POST["alipay"]);
  if($money>=0){
    if($money<$C_limit_money){
      die("{\"msg\":\"最低提现金额为".$C_limit_money."元！\"}");
    }else{
      if($M_money-$money>=0){
        if($name=="" || $alipay==""){
          die("{\"msg\":\"请填全信息！\"}");
        }else{
          sql("update sl_member set M_money=M_money-$money where M_id=$M_id");
          sql("insert into sl_list(L_time,L_title,L_money,L_mid,L_no) values('".date('Y-m-d H:i:s')."','商户提现【姓名：".$name." 支付宝：".$alipay."】',-".$money.",".$M_id.",'".gen_key(20)."')");
          die("{\"msg\":\"success\"}");
        }
      }else{
        die("{\"msg\":\"账户余额不足".$money."元，请重新输入！\"}");
      }
    }
  }else{
    die("{\"msg\":\"提现金额需大于0元，请重新输入！\"}");
  }
}
?>
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>资金提现 - 会员中心</title>
<link rel="shortcut icon" href="../media/<?php echo $C_ico?>" />
<link href="../css/bootstrap.min.css" rel="stylesheet">
<link href="../css/materialdesignicons.min.css" rel="stylesheet">
<link href="../css/style.min.css" rel="stylesheet">
<script type="text/javascript" src="../upload/upload.js"></script>
<style type="text/css">
.qrcode{width:200px;height:200px}
.buy label {
  padding: 5px 10px;
  cursor: pointer;
  border: #CCCCCC solid 1px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
}

.buy .checked {
  border: #33cabb solid 1px;
  -moz-border-radius: 3px;
  -webkit-border-radius: 3px;
  border-radius: 3px;
  color: #33cabb;
  background: #F1FCFA;
}

.buy input[type="radio"] {
  display: none;
}
</style>
</head>
  
<body>
<div class="lyear-layout-web">
  <div class="lyear-layout-container">
  <?php require 'nav.php';?>
    <main class="lyear-layout-content">
      
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-6">
            <div class="card">
              <div class="card-header"><h4>账户充值</h4></div>
              <div class="card-body">
                <div class="row">
                    
                    <?php if($C_pay==0){
                        echo "由商家自行提供收款接口，无需提现。";
                    }else{?>
                    <form id="form">
                    <p>账户余额：<?php echo $M_money?>元</p>
                    
                    <p><div class="input-group">
                        <span class="input-group-addon">提现金额</span>
                        <input type="text" class="form-control" name="money" value="">
                        <span class="input-group-addon">元</span>
                    </div></p>
                    
                    <p><div class="input-group">
                        <span class="input-group-addon">支付宝帐号</span>
                        <input type="text" class="form-control" name="alipay" value="">
                        
                    </div></p>
                    
                    <p><div class="input-group">
                        <span class="input-group-addon">真实姓名</span>
                        <input type="text" class="form-control" name="name" value="">
                        
                    </div></p>
                    
                    
                    <p><button class="btn btn-primary" type="button" onclick="txmoney()">提现</button>  <span style="font-size:12px">说明：一个工作日到账，最低提现金额：<?php echo $C_limit_money?>元</span></p>
                    </form>
                    <?php }?>
                    
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </main>
  </div>
</div>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="../js/main.min.js"></script>
<script src="../js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="../js/lightyear.js"></script>
<script src="../js/jqPaginator.min.js" type="text/javascript"></script>
<script src="../js/help.js" type="text/javascript"></script>
<script src="../js/jconfirm/jquery-confirm.min.js"></script>
<script type="text/javascript">
  $(function() { $('.buy label').click(function(){var aa = $(this).attr('aa');$('[aa="'+aa+'"]').removeAttr('class') ;$(this).attr('class','checked');});});
  $(".buy").find("input:first").attr("checked","checked");
  $(".buy").find("label:first").addClass("checked");
  function txmoney(){
    $.ajax({
        url:'?action=money',
        type:'post',
        data:$("#form").serialize(),
        success:function (data) {
        data=JSON.parse(data);
        if(data.msg=="success"){
          lightyear.notify("提交成功，请等待审核", 'success', 100);
          setTimeout("location.reload()", 2000 );
        }else{
          lightyear.notify(data.msg, 'danger', 100);
        }
        }
    });
  }
</script>
</body>
</html>