<?php
!defined('IN_ONEZ') && exit('Access Denied');

$tabs=array();
$tabs['users']='推广记录';
$tabs['money']='收支明细';
$tab=onez()->gp('tab');
empty($tabs[$tab]) && $tab='users';

$action=onez()->gp('action');
if($action=='alipay'){
  
}
?>
<style>
span.high{
  color:#f00;
  font-size:16px;
  font-weight: bold;
}
.nav{
  display: none;
}
</style>
<?if(!$G['userid']){?>
<div class="panel panel-info">
	<div class="panel-heading">推广平台已正式开放</div>
  <table class="table table-striped">
  	<tr>
  		<td>寻找有需要的人，为每一位作出贡献的用户提供现金回报。自被推荐用户注册之日起三个月内，用户每一次有效付费（包括单次、套餐），您都可以得到支付额的10%作为回报。</td>
  	</tr>
  	<tr>
  		<td>结算周期为次日凌晨6点前，即3日结算2日23:59:59之前的推广佣金，由系统自动结算到绑定的微信账号。每日最低1元起结，最高500元（超出部分次日继续结算）</td>
  	</tr>
  </table>
  
</div>
  <div style="text-align: center">
    <button type="button" onclick="parent._login()" class="btn btn-success">登录</button>
    <button type="button" onclick="parent._register()" class="btn btn-success">注册</button>
    <a href="<?=onez('login.weixin')->link($G['this']->token,'http://www.onez.cn')?>" target="_parent" class="btn btn-info">微信登录</a>
    <a href="<?=onez('login.qq')->link($G['this']->token)?>" class="btn btn-info" target="_parent">QQ登录</a>
  </div>
<?}else{?>
  <div class="panel panel-primary">
  	<div class="panel-heading">推广说明</div>
    <table class="table table-striped">
    	<tr>
    		<td>寻找有需要的人，为每一位作出贡献的用户提供现金回报。自被推荐用户注册之日起三个月内，用户每一次有效付费（包括单次、套餐），您都可以得到支付额的10%作为回报。</td>
  <?if(!$G['userinfo']['openid']){$url=onez()->homepage().'/?_p='.$G['this']->token.'&_m=bindwx&id='.$G['userinfo']['id'];?>
    		<td rowspan="4" width="170" style="border-left: 1px solid #ccc;text-align: center">
          <p>微信扫描绑定收款账号</p>
          <p><img src="http://qrcode.onez.cn/api.php?size=256&text=<?=urlencode($url)?>" style="height:130px" /></p>
        </td>
  <?}?>
    	</tr>
    	<tr>
    		<td>结算周期为次日凌晨6点前，即3日结算2日23:59:59之前的推广佣金，由系统自动结算。每日最低1元起结，最高500元（超出部分次日继续结算）</td>
    	</tr>
  <?

  $url='http://build.onez.cn/?_op='.onez()->strcode("$G[userid]\t{$G[userinfo][id]}",'ENCODE');
  ?>
    	<tr>
    		<td>我的推广网址：<a href="<?=$url?>"><?=$url?></a> <button type="button" class="btn btn-xs btn-success" onclick="<?=onez('event')->load('copy')->click('@this',$url)?>">复制</button></td>
    	</tr>
    	<tr>
    		<td>
          推广总额：¥<code class="totalprice"><?=$G['userinfo']['money1']?></code>元， 
          已结算总额：¥<code class="totalprice"><?=$G['userinfo']['money2']?></code>元， 
          可结算总额：¥<code class="totalprice"><?=$G['userinfo']['money3']?></code>元， 
          总计推广：¥<code class="totalprice"><?=$G['userinfo']['index7']?></code>人 
        </td>
    	</tr>
  <?if($G['userinfo']['openid']){?>
    	<tr>
    		<td style="color:red">
          微信收款账号：<img src="<?=$G['userinfo']['wx_avatar']?>" style="width:16px;height:16px;position: relative;top: -2px;" /> <?=$G['userinfo']['wx_nickname']?>
        </td>
    	</tr>
  <?}?>
    </table>
  </div>

  <div class="" style="padding-bottom: 10px">
    <div class="pull-left">
  <?foreach($tabs as $k=>$v){?>
  <a href="<?=onez()->href('/index.php?menu=recommend&tab='.$k)?>" class="btn btn-<?=$k==$tab?'success':'default'?>"><?=$v?></a>
  <?}?>
    </div>
    <div class="pull-right">
    
     </div>
    <div class="clearfix"></div>
  </div>

  <?if($tab=='money'){
    $record=$G['this']->data()->open('money')->page("userid='$G[userid]' order by id desc",false,10);
    ?>
  <div class="panel panel-primary" style="margin-bottom: 0">
  	<div class="panel-heading">收支明细</div>
    <table class="table table-striped">
    	<tr>
    		<th>发生时间</th>
    		<th>金额</th>
    		<th>备注</th>
    	</tr>
  <?foreach($record[0] as $rs){
    ?>
    	<tr>
    		<td style="vertical-align: middle;"><?=date('Y-m-d H:i:s',$rs['addtime'])?></td>
    		<td style="vertical-align: middle;"><?=number_format((float)$rs['money1'],2,'.','')?></td>
    		<td style="vertical-align: middle;"><?=$rs['subject']?></td>
    	</tr>
  <?}?>
    </table>
  </div>
  <?=$record[1]?>
  <?}elseif($tab=='users'){
    $record=$G['this']->data()->open('userinfo')->page("upid='$G[userid]' order by id desc",false,10);
    ?>
  <div class="panel panel-primary" style="margin-bottom: 0">
  	<div class="panel-heading">我推广的用户</div>
    <table class="table table-striped">
    	<tr>
    		<th>用户名称</th>
    		<th>注册时间</th>
    		<th>消费</th>
    		<th>佣金</th>
    	</tr>
  <?foreach($record[0] as $rs){
        $u=$G['this']->data()->open('member')->one("id='$rs[userid]'");
    ?>
    	<tr>
    		<td style="vertical-align: middle;"><?=$u['nickname']?> (<?=$u['key2']?>)</td>
    		<td style="vertical-align: middle;"><?=date('Y-m-d H:i:s',$rs['addtime'])?></td>
    		<td style="vertical-align: middle;"><?=number_format((float)$rs['totalpay'],2,'.','')?></td>
    		<td style="vertical-align: middle;"><?=number_format((float)$rs['bill'],2,'.','')?></td>
    	</tr>
  <?}?>
    </table>
  </div>
  <?=$record[1]?>
  <?}?>
<?}?>