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

$action=$_GET["action"];
if($action=="vip"){
  if($C_vipprice>0){
    if($M_money-$C_vipprice>=0){
      if($M_vip==1){
        die("{\"code\":\"error\",\"msg\":\"您已经是VIP，无需重复开通！\"}");
      }else{
        mysqli_query($conn,"update sl_member set M_vip=1,M_money=M_money-".$C_vipprice." where M_id=".$M_id);
        mysqli_query($conn,"insert into sl_orders(O_title,O_attach,O_money,O_time,O_mid,O_state,O_tradeno) values('开通VIP会员','".$M_id."',-".$C_vipprice.",'".date('Y-m-d H:i:s')."',".$M_id.",1,'".date('YmdHis').rand(10000000,99999999)."')");
        die("{\"code\":\"success\",\"msg\":\"开通成功！\"}");
      }
    }else{
        die("{\"code\":\"error\",\"msg\":\"账户余额不足，请先充值！\"}");
    }
  }else{
    die("{\"code\":\"error\",\"msg\":\"VIP功能暂未开放！\"}");
  }
}
?>
<!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>开通VIP - 后台管理</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>开通VIP</h4></div>
              <div class="card-body">
                  <div class="row">
                <div class="col-lg-6">
	              <div class="panel panel-primary">
		              <div class="panel-heading ">
		                普通用户
		              </div>
					<ul class="list-group">
					    <li class="list-group-item"><span style="font-size: 20px;color: #f00;font-weight: bold;">0元</span>/月</li>
					    <li class="list-group-item"><img src="images/tec_<?php if($C_creatprice>0){echo "x";}else{echo "s";}?>.png"> 生成短链接<?php echo $C_creatprice?>元/条</li>
					    <li class="list-group-item"><img src="images/tec_x.png"> 短链接有效期<?php echo $C_day?>天</li>
					    <li class="list-group-item"><img src="images/tec_x.png"> 短链接底部带广告</li>
					    <li class="list-group-item"><img src="images/tec_x.png"> 短链接仅可点击100次</li>
					    <li class="list-group-item"><img src="images/tec_x.png"> 短链接升级<?php echo $C_urlprice?>元/条</li>
					    <li class="list-group-item"><a href="javascript:;" class="btn btn-info">免费使用</a></li>
					</ul>
                  </div>
                </div>
                
                <div class="col-lg-6">
                  <div class="panel panel-info">
                  	<div class="panel-heading ">
		                VIP会员
		              </div>

		              <ul class="list-group">
					    <li class="list-group-item"><span style="font-size: 20px;color: #f00;font-weight: bold;"><?php echo $C_vipprice?>元</span>/永久</li>
					    <li class="list-group-item"><img src="images/tec_s.png"> 生成短链接免费不限条数</li>
					    <li class="list-group-item"><img src="images/tec_s.png"> 短链接永久有效</li>
					    <li class="list-group-item"><img src="images/tec_s.png"> 去除所有广告</li>
					    <li class="list-group-item"><img src="images/tec_s.png"> 无限次数点击</li>
					    <li class="list-group-item"><img src="images/tec_s.png"> 短链接免费升级</li>
					    <?php
              if($C_vipprice==0){
                echo "<li class=\"list-group-item\"><button class=\"btn btn-warning\" type=\"button\">暂未开放</button></li>";
              }else{
                if($M_vip==1){
                    echo "<li class=\"list-group-item\"><button class=\"btn btn-warning\" type=\"button\">已开通</button></li>";
                }else{
                    echo "<li class=\"list-group-item\"><button class=\"btn btn-warning\" type=\"button\" onclick=\"vip()\">立即开通</button></li>";
                }
              }
					    ?>
					</ul>
                  </div>
                </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 vip(){
        lightyear.loading('show');
        $.ajax({
            url:'?action=vip',
            type:'post',
            data:$("#form").serialize(),
            success:function (data) {
              data=JSON.parse(data);
              lightyear.loading('hide');
              if(data.code=="success"){
                  lightyear.notify(data.msg, 'success', 100);
              }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>