<?php
!defined('IN_ONEZ') && exit('Access Denied');
$grade=array();
$grade[]=array('name'=>'网址转客户端(含安装包)/安卓版任选','num'=>10,'price'=>'200');
$grade[]=array('name'=>'网址转客户端(含安装包)/安卓版任选','num'=>60,'price'=>'600');
$grade[]=array('name'=>'网址转客户端(含安装包)/安卓版任选','num'=>500,'price'=>'2000');
$grade[]=array('name'=>'网址转客户端(含安装包)/安卓版任选','num'=>-1,'price'=>'5000');
$action=onez()->gp('action');
if($action=='alipay'){
  ob_clean();
  $subject='';
  $num=0;
  $price=(float)onez()->gp('price');
  foreach($grade as $v){
    if($v['price']==$price){
      $times=($v['num']==-1?'无限次':($v['num'].'次'));
      $subject='购买服务：网址转客户端(含安装包)'.$times.'，有效期一年';
      $num=$v['num'];
      break;
    }
  }
  onez('alipay')->pay($price,$subject,array(
    'plugintoken'=>$G['this']->token,
    'paytype'=>'alipay',
    'payname'=>'支付宝支付',
    'userid'=>$G['userid'],
    'type'=>'package',
    'price'=>$price,
    'num'=>$num,
    'goto'=>'http://build.onez.cn/?mod=%2Findex.php&menu=vip',
  ));
}
?>
<style>
span.high{
  color:#f00;
  font-size:16px;
  font-weight: bold;
}
</style>
<?if($G['userid']){?>
<div class="panel panel-primary">
	<div class="panel-heading">当前计费方式</div>
  <table class="table table-striped">
  	<tr>
  		<td>网址转客户端：¥<code class="totalprice">30</code>元/次</td>
  	</tr>
  	<tr>
  		<td>客户端转安装包：¥<code class="totalprice">20</code>元/次</td>
  	</tr>
  	<tr>
  		<td>剩余次数：<code class="totalprice"><?=$G['userinfo']['nolimit']?'无限':$G['userinfo']['index1']?></code>次</td>
  	</tr>
  </table>
</div>
<?}else{?>
<div class="panel panel-primary">
	<div class="panel-heading">单次封装收费</div>
  <table class="table table-striped">
  	<!--<tr>
  		<td style="color:red">
        系统优惠：新用户开通免费赠送<span style="font-size:20px;font-weight: bold;">1</span>次，每推荐<span style="font-size:20px;font-weight: bold;">1</span>人额外赠送<span style="font-size:20px;font-weight: bold;">1</span>次。<span style="color:gray">(推荐方式参照底部“推广平台”)</span>
      </td>
  	</tr>-->
  	<tr>
  		<td>
        电脑客户端：¥<code class="totalprice">30</code>/次
        (如需生成安装包：每次加<code class="totalprice">20</code>元)
      </td>
  	</tr>
  	<tr>
  		<td>安卓客户端：¥<code class="totalprice">30</code>/次</td>
  	</tr>
  </table>
</div>
<?}?>

<div class="panel panel-primary">
	<div class="panel-heading">购买套餐</div>
  <table class="table table-striped">
  	<tr>
  		<th>范围</th>
  		<th>次数(有效期均为一年)</th>
  		<th>价格</th>
  		<th></th>
  	</tr>
<?foreach($grade as $v){
      $times=($v['num']==-1?'无限次':($v['num'].'次'));?>
  	<tr>
  		<td style="vertical-align: middle;"><?=$v['name']?></td>
  		<td style="vertical-align: middle;"><?=$v['num']==-1?('<span class="high">无限</span>'):('<span class="high">'.$v['num'].'</span>')?>次</td>
  		<td style="vertical-align: middle;">¥<code class="totalprice"><?=$v['price']?></code>元</td>
  		<td>
        <button type="button" onclick="_alipay('<?=$v['price']?>')" class="url-build btn btn-info">支付宝付款</button>
        <button type="button" onclick="<?=onez('wxpay')->set('info',array(
          'plugintoken'=>$G['this']->token,
          'paytype'=>'wxpay',
          'payname'=>'微信支付',
          'userid'=>$G['userid'],
          'type'=>'package',
          'price'=>$v['price'],
          'subject'=>'购买服务：网址转客户端(含安装包)'.$times.'，有效期一年',
          'num'=>$v['num'],
          'goto'=>'http://build.onez.cn/?mod=%2Findex.php&menu=vip',
          'proxy'=>'http://www.onez.cn',
        ))->click()?>" class="url-build btn btn-success">微信支付</button>
      </td>
  	</tr>
<?}?>
  </table>
</div>

<?if($G['userid']){?>
<?$record=$G['this']->data()->open('package')->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>
  		<th>剩余次数</th>
  		<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;"><?=date('Y-m-d H:i:s',$rs['index4'])?></td>
  		<td style="vertical-align: middle;"><?=$rs['index2']==-1?'无限':$rs['index2']?></td>
  		<td style="vertical-align: middle;"><?=$rs['index1']==-1?'---':$rs['index1']?></td>
  		<td style="vertical-align: middle;"><?=$rs['index3']?></td>
  		<td style="vertical-align: middle;"><?=$rs['index5']?date('Y-m-d H:i:s',$rs['index5']):'---'?></td>
  		<td style="vertical-align: middle;"><?=$rs['payname']?></td>
  	</tr>
<?}?>
  </table>
</div>
<?=$record[1]?>
<?}?>

<script type="text/javascript">
function _alipay(price){
  location.href='<?=onez()->href('/index.php?menu=vip&action=alipay')?>&price='+price;
}
</script>