<?php
require '../conn/conn.php';
require '../conn/function.php';
require 'member_check.php';
$_SESSION["ym"]=time();

$action=$_GET["action"];
if($action=="pay"){
  $paytype=$_POST["paytype"];
  $money=round($_POST["money"],2);
  $arr=array();

  if($money>0){
    $arr["code"]="success";

    $time=date('Y-m-d H:i:s');
    mysqli_query($conn,"insert into sl_orders(O_title,O_attach,O_money,O_time,O_mid) values('账户充值".$money."元','$M_id',".$money.",'$time',$M_id)");
    $notify_url=gethttp().$_SERVER["HTTP_HOST"]."/pay/notify_url.php";
    $return_url=gethttp().$_SERVER["HTTP_HOST"]."/member/pay.php";
    $no=getrs("select O_id from sl_orders where O_title='账户充值".$money."元' and O_time='$time' order by O_id desc","O_id");

    $sign=strtolower(md5("money=".$money."&name=账户充值".$money."元&notify_url=".$notify_url."&out_trade_no=".$no."&pid=".$C_pid."&return_url=".$return_url."&type=".$paytype."".$C_pkey));

    $arr["post"]="<form id=\"post\" method=\"post\" action=\"".$C_payurl."submit.php\">
    <input type=\"hidden\" name=\"name\" value=\"账户充值".$money."元\">
    <input type=\"hidden\" name=\"money\" value=\"".$money."\">
    <input type=\"hidden\" name=\"out_trade_no\" value=\"".$no."\">
    <input type=\"hidden\" name=\"notify_url\" value=\"".$notify_url."\">
    <input type=\"hidden\" name=\"type\" value=\"".$paytype."\">
    <input type=\"hidden\" name=\"pid\" value=\"".$C_pid."\">
    <input type=\"hidden\" name=\"return_url\" value=\"".$return_url."\">
    <input type=\"hidden\" name=\"sign_type\" value=\"MD5\">
    <input type=\"hidden\" name=\"sign\" value=\"".$sign."\">
    </form><script>\$(\"#post\").submit()</script>";

  }else{
    $arr["code"]="error";
    $arr["msg"]="订单金额需大于0元！";
  }
  die(json_encode($arr));

}
?>
<!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="icon" href="../media/<?php echo $C_ico?>" type="image/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">
.showpic{height: 60px;border: solid 1px #DDDDDD;padding: 5px;}
#msg,#msg2{color: #f00;margin-top: 10px;}
</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">
          <form class="form-horizontal" id="form">
          <div class="col-lg-6">

            <div class="card">
              <div class="card-header"><h4>帐号充值</h4></div>
              <div class="card-body">

                <div class="form-group">
                  <label for="firstname" class="col-sm-2 control-label">账户余额</label>
                  <div class="col-sm-10">
                    <p class="form-control-static"><?php echo $M_money?>元</p>
                  </div>
                </div>

                  
                <div class="form-group">
                  <label for="firstname" class="col-sm-2 control-label">充值金额</label>
                  <div class="col-sm-10">
                    <div class="input-group">
                          <input type="text" class="form-control" name="money" value="<?php echo $money?>">
                          <span class="input-group-addon">元</span>
                      </div>
                  </div>
                </div>

                <div class="form-group">
                  <label for="firstname" class="col-sm-2 control-label">支付方式</label>
                  <div class="col-sm-10">
                    <?php if($C_alipayon=="1"){?>
                    <label aa="pay" class="checked"><input type="radio" value="alipay" checked="checked" name="paytype"> <img src="../images/alipay.png"></label> 
                    <?php }?>
                    <?php if($C_wxpayon=="1"){?>
                    <label aa="pay" class="checked"><input type="radio" value="wxpay" name="paytype"> <img src="../images/weixin.png"></label>
                    <?php }?>
                  </div>
                </div>
              <div class="form-group">
                  <div class="col-sm-offset-2 col-sm-10">
                    <button type="button" onclick="pay()" class="btn btn-primary">充值</button>
                  </div>
                </div>
                  
              </div>
            </div>

          </div>
        </form>
        </div>
      </div>
      
    </main>
    <!--End 页面主要内容-->
  </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/qrcode.min.js"></script>
<script type="text/javascript">

      function pay(){
        lightyear.loading('show');
        $.ajax({
            url:'?action=pay',
            type:'post',
            data:$("#form").serialize(),
            success:function (data) {
              data=JSON.parse(data);
              lightyear.loading('hide');
              if(data.code=="success"){
                //window.location.href=data.msg;
                $("body").append(data.post);
              }else{
                  lightyear.notify(data.msg, 'danger', 100);
              }
            }
          });
      }

  var path=window.location.pathname;
  $("a").each(function(){
    if(path.indexOf($(this).attr("href"))!=-1){
      console.log($(this).attr("href"));
      $(this).parent("li").addClass("active");
      $(this).parent("li").parent("ul").parent("li").addClass("open active");
    }
  });
</script>
</body>
</html>