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

$uid=(int)onez()->gp('uid');

$format=(int)onez('chat.group.plugin.credit')->option('format');

$u=$G['this']->data()->open('member')->one("id='$uid'");
!$u && onez()->error('目标用户不存在');

$action=onez()->gp('action');
$G['title']='充值';

#初始化表单
$form=onez('admin')->widget('form')
  ->set('title',$G['title'])
  ->set('values',$item)
;
#创建表单项
$form->add(array('type'=>'hidden','key'=>'action','value'=>'save'));
$form->add(array('label'=>'目标用户','type'=>'html','html'=>'<pre><img src="'.onez('chat.group.common')->avatar($u['id']).'" width="16" height="16" /> '.$u['nickname'].'</pre>'));
$form->add(array('label'=>'用户'.onez('chat.group.plugin.credit')->name(),'type'=>'html','html'=>'<pre id="fee_label">'.onez('chat.group.plugin.credit')->value($u['id']).'</pre>'));
$form->add(array('label'=>'充值金额','type'=>'text','key'=>'key1','hint'=>'','notempty'=>'转账金额不能为空','group'=>''));
$form->add(array('label'=>'备注信息','type'=>'textarea','key'=>'summary','hint'=>'','notempty'=>'','default'=>'系统充值'));

#处理提交
if($onez=$form->submit()){
  ob_clean();
  
  $money=onez('chat.group.plugin.credit')->format($onez['key1']);
  $money==0 && onez()->error('转账金额有误');
  
  $total=$money;
  
  
  $total=onez('chat.group.plugin.credit')->format($total);
  $total==0 && onez()->error('转账金额有误');
  

  onez('chat.group.plugin.credit')->add($u['id'],'money',$money,'turn',$onez['summary']);
  
  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">
          立即转账
        </button>
      </div>
    </div>
    <input type="hidden" name="action" value="save" />
  </form>
</section>
<?php

echo $form->js();
onez('admin')->footer();
?>