<?php
!defined('IN_ONEZ') && exit('Access Denied');
$action=onez()->gp('action');
if($action=='delete'){
  $id=(int)onez()->gp('id');
  $T=$G['this']->data()->open('package')->one("id='$id'");
  $userid=(int)$T['userid'];
  $G['this']->data()->open('package')->delete("id='$id'");
  
  $totalnum=$hasnum=0;
  $nolimit=0;
  $T=$G['this']->data()->open('package')->record("userid='$userid' and index4>=".time()."");
  foreach($T as $rs){
    $hasnum+=$rs['index1'];
    $totalnum+=$rs['index2'];
    if($rs['index2']==-1){
      $nolimit=1;
    }
  }
  $G['this']->data()->open('userinfo')->update(array(
    'index1'=>$hasnum,
    'index2'=>$totalnum,
    'index5'=>time(),
    'nolimit'=>$nolimit,
  ),"userid='$userid'");

  onez()->ok('删除成功','reload');
}

?>
<style>
span.high{
  color:#f00;
  font-size:16px;
  font-weight: bold;
}
</style>

<?$record=$G['this']->data()->open('package')->page("1 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>
  		<th>支付方式</th>
  		<th></th>
  	</tr>
<?foreach($record[0] as $rs){
        $u=$G['this']->data()->open('member')->one("id='$rs[userid]'");
  ?>
  	<tr>
      <td><img src="<?=$G['this']->avatar($rs['userid'])?>" style="width:16px;height:16px;position: relative;top: -2px;" />  <?=$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;"><?=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>
  		<td style="vertical-align: middle;">
          <a href="javascript:void(0)" onclick="onez.del(<?=$rs['id']?>)" class="btn btn-xs btn-danger">
            删除
          </a></td>
  	</tr>
<?}?>
  </table>
</div>
<?=$record[1]?>
