<?php
error_reporting(0); 
include("../../config/qiantai.php");
session_start();
if(!isset($_SESSION['username'])){echo "<script>alert('请重新登录!')</script><script>top.location.href='/index$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='/index$dshz'</script>";exit;}
$cz=ubo($_GET[cz]);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="gb2312">
<title>邀请码</title>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<link rel="stylesheet" href="/2019newui/qiantai/css/x-admin.css" media="all">
<script src="/2019newui/js/jquery1.9.min.js"></script>
<script src="/2019newui/js/bootstrap.min.js"></script>
</head>
<body>
<div class="x-body">
<?php
$sql = mysql_query("SELECT * FROM yqm where userid='$userid'");
$bs= mysql_num_rows($sql);
?>
<blockquote class="layui-elem-quote">
<dl class="apps-filter-tr">
<dt><span  class="xb">我的邀请码</span> <span style="font-size:14px;color:#ff0000">(友情提示：您所购买的邀请码均会在此显示并查看使用状态！)</dt>
</dl>
<span class="x-right" style="margin-top:-24px;line-height:10px">共有邀请码：<?php echo $bs?> 个 
<a class="layui-btn-small" style="line-height:10px;margin-top:-2px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="fa fa-refresh"></i></a></span>
</blockquote>
<fieldset class="layui-elem-field"><legend>邀请码说明</legend>
<div class="layui-field-box">
<p>1、推广邀请码只是为了方便代理用户推广下线用户！</p>
<p>2、邀请码可以有效避免无效用户进入平台！</p>
<p>3、当您的下线进行提现时，下级用户提现金额乘以 <span style="font-size:24px;color:#ff0000"><?php echo $user[fy]?>%</span> 将作为提成返佣直接进入你的账户余额中，望用户周知！</p>
<p>4、邀请码收费为 <span style="font-size:24px;color:#ff0000"><?php echo $yqm?></span> 元/个，总营业额达 <span style="font-size:24px;color:#ff0000"><?php echo $yqm?></span> 元的代理可以购买！</p>
</div>
</fieldset>
<div class="layui-form-item">
<a href="/yqmpageso/1/sy/"   class="layui-btn layui-btn-small layui-btn-normal"><span >全部邀请码</span></a>
<a href="/yqmpageso/1/wjh/"   class="layui-btn layui-btn-small layui-btn-normal"><span >所有未激活</span></a>
<a href="/yqmpageso/1/yjh/"   class="layui-btn layui-btn-small layui-btn-normal"><span >所有已激活</span></a>
<?php if($user['money']=='0'){?>
<span  class="layui-btn layui-btn-small layui-btn-normal layui-btn-danger">您账户余额不足以购买邀请码，请推广营业后方可购买，当前邀请码售价为：<?php  echo $yqm?> 元/个</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 }?>
</div>
<table class="layui-table">
<thead>
<tr>
<th  style="text-align:center;" >邀请码</th>
<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";
if($cz==null){
$sql .=" and userid='$userid' ";
}elseif($cz=='sy'){
$sql .=" and userid='$userid' ";
}elseif($cz=='wjh'){
$sql .=" and userid='$userid' ";
$sql .=" and zt='未使用' ";
}elseif($cz=='yjh'){
$sql .=" and userid='$userid' ";
$sql .=" and zt='已使用' ";
}
$resw = mysql_query("select id from  yqm     ".$sql."");
$count = mysql_num_rows($resw);
if($count == 0){echo '<tr><td colspan="4" style="text-align:center;">没有记录</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); 
$zgg = mysql_query("select * from  yqm   ".$sql."  order by id desc     limit $offset, $page_size");
while ($mgg=mysql_fetch_array($zgg)) { 
?> 	
<tr>
<td   style="text-align:center;" ><?php echo $mgg['yqm']?> </td>
<td  style="text-align:center;" ><?php echo  $mgg['shijian']?></td>
<td   style="text-align:center;" ><?php if($mgg['zt']=='未使用'){?>未使用<?php }else{?><span style="font-size:15px;color:#ff0000">已使用</span><?php }?></td>
<td   style="text-align:center;" ><?php echo $mgg['name']?></td>
</tr>
<?php 
} 
$page_len = ($page_len%2)?$page_len:$pagelen+1;//页码个数 
$pageoffset = ($page_len-1)/2;//页码个数左右偏移量 
if($page!=1){ 
if($cz){
$keyt.="<a href=\""."/yqmpageso/1/$cz/\">首页</a>"; //首页 
$keyt.="<a href=\""."/yqmpageso/".($page-1)."/$cz/\">上一页 </a>"; //上一页 
}else{
$keyt.="<a href=\""."/yqmpage/1/\">首页</a>"; //首页 
$keyt.="<a href=\""."/yqmpage/".($page-1)."/\">上一页 </a>"; //上一页 
}
}else { 
$keyt.="<p>首页</p>"; //首页 
$keyt.="<p>上一页 </p>"; //上一页  
} 
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.='<a class="cur">'.$i.'</a>'; 
} else { 
if($cz){
$keyt.="<a href=\""."/yqmpageso/".$i."/$cz/\">".$i."</a>"; 
}else{
$keyt.="<a href=\""."/yqmpage/".$i."/\">".$i."</a>"; 
}
} 
} 
if($page!=$pages){ 
if($cz){
$keyt.="<a href=\""."/yqmpageso/".($page+1)."/$cz/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/yqmpageso/{$pages}/$cz/\">尾页</a> "; //最后一页 
}else{
$keyt.="<a href=\""."/yqmpage/".($page+1)."/\">下一页 </a> ";//下一页 
$keyt.="<a href=\""."/yqmpage/{$pages}/\">尾页</a> "; //最后一页 
}
}else { 
$keyt.="<p>下一页 </p>";//下一页 
$keyt.="<p>尾页</p>"; //最后一页 
} 
$keyt.="<p class='pageRemark' >当前第 <b>$page</b> 页/共 <b>$pages</b> 页  共 <b>$count</b> 条数据 </p>"; //第几页,共几页 
?>  	
</tbody>
</table>
<div style="padding:0 20px;">
<div class="pagination">
<?php if($count =="0"){?><?php }else{?><?php echo $keyt?><?php }?>
</div>
</div>
</div>
</div>
<?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">购买邀请码  <span style="font-size:14px;color:#ff0000">(您的账户余额为:<?php echo $user['money']?>元 可购买 <?php echo floor($user['money']/$yqm)?> 个邀请码)</span></h4>
</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 : "/post<?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>
<?php }?>
</body>
</html>