<?php
!defined('IN_ONEZ') && exit('Access Denied');
include_once(dirname(__FILE__).'/init.php');

$id=(int)onez()->gp('id');
$type=onez()->gp('type');

$item=$G['this']->data()->open('cash')->one("id='$id'");
$G['title']='处理充值结果';
$u=$G['this']->data()->open('member')->one("id='$item[userid]'");
$btnname='确定';

#初始化表单
$form=onez('admin')->widget('form')
  ->set('title',$G['title'])
  ->set('values',$item)
;
#创建表单项
$form->add(array('type'=>'hidden','key'=>'action','value'=>'save'));

$options=array();
if($type=='ok'){
  $options['ok']='成功';
}elseif($type=='fail'){
  $options['fail']='失败';
}
$form->add(array('label'=>'处理结果','type'=>'select','key'=>'token','options'=>$options,'group'=>''));


$form->add(array('label'=>'提现金额','type'=>'html','html'=>'<pre>'.$item['money'].' '.onez('chat.group.plugin.credit')->unit().'</pre>','hint'=>'','notempty'=>'','group'=>''));
$form->add(array('label'=>'手续费','type'=>'html','html'=>'<pre>'.$item['fee'].' '.onez('chat.group.plugin.credit')->unit().'</pre>','hint'=>'','notempty'=>'','group'=>''));
$form->add(array('label'=>'收款账号','type'=>'html','html'=>'<pre>'.$item['key2'].'</pre>','hint'=>'','notempty'=>'','group'=>''));
$form->add(array('label'=>'会员账号','type'=>'html','html'=>'<img src="'.onez('chat.group.common')->avatar($item['userid']).'" width="16" height="16" /> '.$u['nickname']));
if($type=='fail'){
  $form->add(array('label'=>'失败理由','type'=>'textarea','key'=>'because','hint'=>'','notempty'=>'','group'=>''));
}

#处理提交
if($onez=$form->submit()){
  ob_clean();
  $onez['token']=$type;
  $onez['index4']=time();
  $onez['index5']=$G['userid'];
  if($type=='fail'){
    onez('chat.group.plugin.credit')->add($item['userid'],'money',$item['money'],'trun',"退还提现金额");
    if($item['fee']>0){
      onez('chat.group.plugin.credit')->add($item['userid'],'money',$item['fee'],'trun',"退还提现手续费");
    }
  }
  $G['this']->data()->open('cash')->update($onez,"id='$id'");
  onez()->ok('操作成功','reload2');
}
onez('admin')->header();
?>
<section class="content-header">
  <h1>
    <?=$G['title']?>
  </h1>
  <ol class="breadcrumb">
    <li>
      <a href="<?php echo onez()->href('/')?>">
        <i class="fa fa-dashboard">
        </i>
        管理首页
      </a>
    </li>
    <li class="active">
      <?=$G['title']?>
    </li>
  </ol>
</section>
<section class="content">
  <form id="form-common" method="post">
    <div class="box box-info">
      <div class="box-header with-border">
        <h3 class="box-title">
          <?=$G['title']?>
        </h3>
        <div class="box-tools pull-right">
        </div>
      </div>
      <div class="box-body">
        <?=$form->code()?>
      </div>
      <div class="box-footer clearfix">
        <button type="submit" class="btn btn-primary">
          <?=$btnname?>
        </button>
        <!--<a href="<?=onez()->href('/admin/pages/content.php')?>" class="btn btn-default">
          返回
        </a>-->
      </div>
    </div>
    <input type="hidden" name="action" value="save" />
  </form>
</section>
<?php
echo $form->js();
onez('admin')->footer();
?>