<?php
error_reporting(0); 
include("../../config/wap.php");
session_start();
if(!isset($_SESSION['username'])){echo "<script>alert('请重新登录!')</script><script>top.location.href='/m$dshz'</script>";exit;}
$username=$_SESSION['username'];
$type="where name='$username'";
$user=queryall(user,$type);
$userid=$user['userid'];
if(!$user){echo "<script>alert('请重新登录!')</script><script>top.location.href='/m$dshz'</script>";exit;}
$cz=ubo($_GET['cz']);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312">
<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no">
<title>邀请码管理</title>
<link href="/2019newui/m/css/common.css" rel="stylesheet" type="text/css"/>
<link href="/layui/css/m.css" rel="stylesheet"/>
<script src="/2019newui/js/jquery1.9.min.js"></script>
<script src="/2019newui/js/bootstrap.min.js"></script>
<link href="/2019newui/page.css" rel="stylesheet" type="text/css"/>
<style> 
#pic_list{display:block;white-space:nowrap;width:100%;overflow:hidden;}
#pic_list li{margin:13px;display:inline-block;width:20%;height:40px;font-size:16px;text-align:center;line-height:40px;border-radius:6px;background:#29a7e2;color:#fff;}
</style> 
</head>
<body>
<header class="aui-navBar aui-navBar-fixed">
<a href="javascript:;"  onclick="window.history.back(-1);" class="aui-navBar-item"><i class="icon layui-icon" style="font-size: 20px;">&#xF060;</i></a>
<div class="aui-center"><span class="aui-center-title">邀请码管理</span></div>
</header>
<div class="divHeight"></div>
<?php
$sql = mysql_query("SELECT * FROM yqm where userid='$userid'");
$bs = mysql_num_rows($sql);
?>
<p style="height: 2.0rem;margin:10px auto;margin-left:14px;">我的邀请码数量：<?php if($bs==null){?>0<?php }else{?><?php echo $bs?><?php }?> 个 
<?php if($user['money']=='0'){?>
<span  class="layui-btn layui-btn-small layui-btn-normal layui-btn-danger">余额不足</span>
<?php }else{?>
<button   class="layui-btn layui-btn-small layui-btn-normal layui-btn-danger  publish_btn" data-toggle="modal"  data-target="#myPublic">购买邀请码</button >
<?php }?>
</p>
<table class="layui-table" >
<thead>
<tr>
<th  style="text-align:center;" >邀请码</th>
<th  style="text-align:center;" >状态</th>
<th  style="text-align:center;" >使用者</th>
</tr>
</thead>
<tbody>
<?php 
$page_size=10; 
$sql = "WHERE 1=1";
$sql .=" and userid='$userid' ";
$result = mysql_query("select id from  yqm    ".$sql."");
$count = mysql_num_rows($result);
if($count == 0){echo '<tr><td  style="text-align:center;" colspan=4>暂无记录</td></tr>';}
$page_count = ceil($count/$page_size); 
$init=1; 
$page_len=7; 
$max_p=$page_count; 
$pages=$page_count; 
if(empty($_GET['page'])||$_GET['page']<0){ 
$page=1; 
}else { 
$page=$_GET['page']; 
} 
$offset=$page_size*($page-1); 
$query = mysql_query("select * from  yqm  ".$sql."  order by id desc     limit $offset, $page_size");
while ($vgg=mysql_fetch_array($query)) { 
?> 	
<tr>
<td   style="text-align:center;"><?php echo $vgg['yqm']?> </td>
<td   style="text-align:center;"><?php if($vgg['zt']=='未使用'){?>未使用<?php }else{?><span style="font-size:15px;color:#ff0000">已使用</span><?php }?></td>
<td   style="text-align:center;"><?php echo $vgg['name']?></td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
$keyt.="<li><a href=\""."/myqmpage/1/\">首页</a></li>"; //首页 
$keyt.="<li><a href=\""."/myqmpage/".($page-1)."/\">上页 </a></li>"; //上一页 
}else { 
$keyt.="<li>首页</li>"; //首页 
$keyt.="<li>上页</li>"; //上一页  
} 
if($pages>$page_len){ 
//如果当前页小于等于左偏移 
if($page<=$pageoffset){ 
$init=1; 
$max_p = $page_len; 
}else{//如果当前页大于左偏移 
//如果当前页码右偏移超出最大分页数 
if($page+$pageoffset>=$pages+1){ 
$init = $pages-$page_len+1; 
}else{ 
//左右偏移都存在时的计算 
$init = $page-$pageoffset; 
$max_p = $page+$pageoffset; 
} 
} 
} 
for($i=$init;$i<=$max_p;$i++){ 
if($i==$page){ 
$keyt.='<li class="active">'.$i.'</li>'; 
} else { 
$keyt.="<li><a href=\""."/myqmpage/".$i."/\">".$i."</a></li>"; 
} 
} 
if($page!=$pages){ 
$keyt.="<li><a href=\""."/myqmpage/".($page+1)."/\">下页 </a></li>";//下一页 
$keyt.="<li><a href=\""."/myqmpage/{$pages}/\">尾页</a></li>"; //最后一页 
}else { 
$keyt.="<li>下页</li>";//下一页 
$keyt.="<li>尾页</li>"; //最后一页 
} 
$keyt.='<li class="totalPage">跳转<input type="text" onkeyup="cq(this.value)" value="'.$page.'" ><span>页</span></li><br>';
$keyt.="<li class='totalPage'>当前第 <b>$page</b> 页/共 <b>$pages</b> 页</li>"; 
$keyt.="<li class='totalPage'>每页<b>$page_size</b>条数据</li>"; 
$keyt.="<li class='totalPage'>总共<b>$count</b>条数据 "; 
?> 
</tbody>
</table>
<?php if($count=="0"){?>
<?php }else{?>
<div style="height:10px;"></div>
<div id="pagination" class="pagination">
<ul>
<?php if($count =="0"){?><?php }else{?><?php echo $keyt?><?php }?>
</ul>
</div>
<div style="height: 8rem;"></div>
</div>
<?php }?>
<footer class="aui-footer aui-footer-fixed">
<a href="/mmain<?php echo $dshz?>" class="aui-tabBar-item"><i class="icon layui-icon" style="font-size: 30px;">&#xF015;</i><span class="aui-tabBar-item-text">首页</span></a>
<a href="/mdingdan<?php echo $dshz?>" class="aui-tabBar-item"><i class="icon layui-icon" style="font-size: 30px;">&#xF123;</i><span class="aui-tabBar-item-text">订单</span></a>
<a href="/muser<?php echo $dshz?>" class="aui-tabBar-item"><i class="icon layui-icon" style="font-size: 30px;">&#xF007;</i><span class="aui-tabBar-item-text">我的</span></a>
</footer>
<?php if($user['money']=='0'){?>
<?php }else{?>
<div class="modal fade" id="myPublic" tabindex="-1" role="dialog" aria-labelledby="myPublicLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">购买邀请码 </h4>
 <span style="font-size:14px;color:#ff0000">(您的账户余额为:<?php echo $user['money']?>元 可购买 <?php echo floor($user['money']/$yqm)?> 个邀请码)</span>
</div>
<div class="modal-body">
<div class="form-group">
<label  class="control-label">邀请码数量</label>
<input type="text" name="sl" class="layui-input" id="sl" lay-verify="required" placeholder="请输入您要购买的邀请码数量" oninput="pay(event)" onporpertychange="pay(event)" >
</div>
<div class="form-group" id='txt'></div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
<button type="button" id="publish_btn" class="btn btn-primary">确认</button>
</div>
</div>
</div>
</div>
<script src="/layui/layui.js"></script>
<script>
layui.use(['form', 'layedit', 'laydate', 'element', 'jquery', 'layer'], function(){
var form = layui.form
,layer = layui.layer
,layedit = layui.layedit
,element = layui.element
,laydate = layui.laydate
,$ = layui.jquery;
});
$(function () {
$("#publish_btn").click(function () {
var sl = $("#sl").val();
var index = layer.load(3, {
shade: [0.1,'#fff'] 
});
$('#myPublic').css('display',"none");
$.ajax({
type:'POST',
url : "/mpost<?php echo $dshz?>",
data: {lx:'yqmgm',sl:sl},
dataType:'json',
success:function(result){
if(result.status == '1'){
layer.closeAll('loading');
layer.msg('购买成功');
location.reload();
}else{
layer.closeAll('loading');
layer.msg(result.msg);
location.reload();
}
}	
});
});
})
$('.publish_btn').on('click', function () {
})
function pay(e){
var thisTxt=$("#sl").val();
$('#txt').html("当前购买:  "+ thisTxt+" 个邀请码 需付费："  + thisTxt*<?php echo $yqm?>+" 元");
}
</script>
<script type="text/javascript">
function cq(page) {
if(page><?php echo $count?>){
layer.msg('当前共<?php echo $count?>页<br>请正确输入页码');
}else{
window.location.href='/myqmpage/'+page+'/';
} 
}
</script>
<?php }?>
</body>
</html>