<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request as Req;
use Request;

/**
 *
 */
class RechargeController extends Controller {
	/**
	 * @return 充值管理
	 */
	function index() {
        $reqest=array();
        $reqest['account_name'] = Request::has('account_name') ? Request::get('account_name') : '';
        $reqest['order_id'] = Request::has('order_id') ? Request::get('order_id') : '';
        $reqest['recharge_type'] = Request::has('recharge_type') ? Request::get('recharge_type') : '';
        $reqest['status'] = Request::has('status') ? Request::get('status') : '';
        $reqest['apply_startime'] = Request::get('apply_startime') ? Request::get('apply_startime') : '';
        $reqest['apply_endtime'] = Request::get('apply_endtime') ? Request::get('apply_endtime') : '';
        $reqest['haddle_startime'] = Request::get('haddle_startime') ? Request::get('haddle_startime') : '';
        $reqest['haddle_endtime'] = Request::get('haddle_endtime') ? Request::get('haddle_endtime') : '';
        $reqest['money_small'] = Request::has('money_small') ? Request::get('money_small') : '';
        $reqest['money_big'] = Request::has('money_big') ? Request::get('money_big') : '';
        $reqest['sureblur'] = Request::has('sureblur') ? Request::get('sureblur') : '';
        
		$dt = \App\Lib\DataTable\DataTable::init();
		$account = Request::has('account_name') ? Request::get('account_name') : '';
		$isuser = !empty(Request::has('isuser')) ? Request::get('isuser') : 2;
		$dt->setDataSource('/admin/money/recharge?account_name=' . $account . '&isuser=' . $isuser);
		$dt->setLang('money');
		$dt->setPriKey('order_id');
		$dt->addColsFields('id', array('width' => 100));
		$dt->addColsFields('account_name', array('templet' => '#userrecharge', 'width' => 150));
		$dt->addColsFields('apply_time', array('templet' => '#orderid_time', 'width' => 260));
		$dt->addColsFields('complete_time', array('templet' => '#taked', 'width' => 220));
		// $dt->addColsFields('money', array('width' => 140));
		// $dt->addColsFields('status', array('width' => 105));
		$dt->addColsFields('money', array('templet' => '#money_aftercash', 'width' => 300));
		$dt->addColsFields('systemuser_rechargetype', array('templet' => '#act_type', 'sort' => false));
		$dt->setToolBar(array('view'), array('width' => 100,'align' => 'left'));	

		return view('admin.Recharge/index', $dt->render($reqest));
	}

	/**
	 * 单用户充值列表
	 * [detail description]
	 * @return [type] [description]
	 */
	function userrecharge() {
		$account_name = Request::has('account_name') ? Request::get('account_name') : '';
		$dt = \App\Lib\DataTable\DataTable::init();
		$dt->setDataSource('/admin/money/recharge?account_name=' . $account_name . '&sureblur=精确');
		$dt->setLang('money');
		$dt->addColsFields('id', array('width' => 90));
		$dt->setPriKey('order_id');
		$dt->addColsFields('account_name', array('sort' => false, 'width' => 110));
		$dt->addColsFields('apply_time', array('templet' => '#use', 'width' => 240));
		$dt->addColsFields('complete_time', array('width' => 165));
		$dt->addColsFields('money');
		$dt->addColsFields('money_cash');
		$dt->addColsFields('systemuser_rechargetype', array('sort' => false));
		$dt->setToolBar(array('view'), array('width' => 100));
		return view('admin.view', $dt->render());
	}

	//查看充值
	function View(Req $req) {
		$order_id = $req->order_id;
		if (empty($order_id)) {
			abort(404);
		}
		$moneydetails = new \App\Models\Money_recharge();
		$data = $moneydetails->getOrderDetails($order_id, 3);
		$bank = new \App\Models\Account_bank();
		$bank_data = $bank->getInfoByUid($data['account_identity']);
		$data['bank_name'] = isset($bank_data['bank_name']) ? $bank_data['bank_name'] : '';
		$data['bank_address'] = isset($bank_data['bank_address']) ? $bank_data['bank_address'] : '';
		$data['bank_number'] = isset($bank_data['bank_number']) ? $bank_data['bank_number'] : '';
		$data['name'] = isset($bank_data['account_name']) ? $bank_data['account_name'] : '';
		$remark = new \App\Models\Recharge_Remark();
		$remark = $remark->getinfoByoid($order_id);
		$data['remark'] = isset($remark['remark']) ? $remark['remark'] : '';
		return view('admin.Recharge/view', ['data' => $data]);
	}

}

?>