<?php

namespace App\Http\Controllers\Admin;

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

/**
 *
 */
class UserWaterController extends Controller {
	/**
	 *
	 * [Colse description]
	 */
	function index(Req $req) {
		$id = $req->id;
		if (empty($id)) {
			abort(404);
		}
		return $this->show($id);
	}
	//流水
	function water(Req $req) {
		$id = $req->identity;
		if (empty($id)) {
			abort(404);
		}
		$user_db = new \App\Models\Account; //用户
		$account = $user_db->getinfo($id, 2);
		return $this->show($account['id']);
	}
	function show($id) {
		$dt = \App\Lib\DataTable\DataTable::init();
		$dt->setDataSource('/admin/userWater/getWater?id=' . $id);
		$dt->setLang('user');
		$dt->addColsFields('money_time', array('width' => 105)); //日期
		$dt->addColsFields('trade_id', array('width' => 205)); //定单号
		$dt->addColsFields('trade_type', array('width' => 100)); //交易类型
		$dt->addColsFields('old_money', array('width' => 100)); //交易前
		$dt->addColsFields('money', array('width' => 100)); //交易金额
		$dt->addColsFields('money_cash', array('width' => 100)); //交易后金额
		$dt->addColsFields('trade_desc'); //交易描述
		$dt->addColsFields('details', array('templet' => '#detailsTool', 'width' => 90));
		$dt->setPriKey('order_id');
//        $dt->setToolBar(array('view'));//详情
		return view('admin.user/userwater', $dt->render());
	}

	/**
	 * 会员列表
	 * 'user description'
	 * @return 'type' 'description'
	 */
	function View(Req $req) {
		return $this->Edit($req);
	}

	function getWater() {
		$id = Request::has('id') ? Request::get('id') : '';
		$page = Request::has('page') ? Request::get('page') : 1;
		$list = Request::has('limit') ? Request::get('limit') : 10;
		$startime = Request::get('startime') ? Request::get('startime').' 00:00:00' : '';
		$endtime = Request::get('endtime') ? Request::get('endtime').' 23:59:59' : '';
		$trade_type = Request::has('trade_type') ? Request::get('trade_type') : '';

		$where = array();
		if (!empty($startime)) {
			$startime = date('Y-m-d H:i:s', strtotime($startime));
			$where[] = array('money_time', '>=', $startime);
		}
		if (!empty($endtime)) {
			$endtime = date('Y-m-d H:i:s', strtotime($endtime));
			$where[] = array('money_time', '<=', $endtime);
		}

		if (!empty($trade_type)) {
			$where[] = array('trade_type', '=', $trade_type);
		}
		$user_db = new \App\Models\Account; //用户
		$account = $user_db->getinfo($id, 1);
		$money_db = new \App\Models\Money_details; //资金
		$data = $money_db->getUserWater($account['identity'], $list,$where);

		if (is_array($data['data']) && count($data['data']) > 0) {
			$money_type = trans('status.money_details.trade_type');
			foreach ($data['data'] as $k => $v) {
				$data['data'][$k]['trade_type'] = $money_type[$v['trade_type']];
			}
		}
		return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);

	}
	/**
	 * 用户添加
	 * [add description]
	 */
	function userAdd() {
		return view('admin.menu/userAdd');
	}

	/**
	 * 会员列表
	 * [getCloseTable description]
	 * @return [type] [description]
	 */
	function getUserTable() {
		$table = new \App\Lib\Biz\Game\Table\UserTable();
		$data = $table->getUserTh();
		return \App\Lib\DataTable\DataTable::init()->toJson($data['data'], $data['total']);
	}

	/**
	 * 资金流水
	 * 'money description'
	 * @return 'type' 'description'
	 */
	function money() {
		$db = new \App\Models\Money_details;
		$page = Request::has('statpageus') ? Request::get('page') : '20';
		$identity = Request::has('account_identity') ? Request::get('account_identity') : '45b7d4e9-2bb9-16b3-9a50-6fd6f62235f8';
		if (empty($identity)) {
			return -2020162003; //用户不存在
		}
		$status = Request::has('status') ? Request::get('status') : '1';
		if ($status == 1) {
			$data = $db->money($page, $identity, $status);
			return responseToJson($data);
		} else {
			return -2020162103; //账户异常
		}
	}

	/**
	 * 会员详情
	 */
	function Memdetails() {
//        DB::connection()->enableQueryLog();
		$id = Request::has('account.identity') ? Request::get('account.identity') : '19a67df4-b40e-3e40-ca25-deffbf0c846d';
		if (empty($id)) {
			return Rens(-2020023003); //此用户不存在
		}
//		$data = DB::table('account_detailed')
		//			->join('account', 'account_detailed.account_identity', '=', 'account.identity')
		//			->join('account_bank', 'account_detailed.account_identity', '=', 'account_bank.account_identity')
		//			->select('account', 'cash', 'phone', 'email', 'name', 'email', 'email', 'email', 'bank_name', 'bank_address', 'bank_number', 'register_time', 'register_ip', 'last_time', 'last_ip')
		//			->where('account.status', 1)
		//			->where('account.identity', $id)
		//			->first();
		////        $log= DB::getQueryLog();
		//		//        dd($log);die;
		//		echo "<pre>";
		//		print_r($data);

		$data = array(
			'account' => '13434926679',
			'cash' => '0.00',
			'phone' => '13434926679',
			'email' => '',
			'name' => '方玉佳',
			'bank_name' => '中国工商银行',
			'bank_address' => '洪阳工商银行',
			'bank_number' => '6222082019001327324',
			'register_time' => '2016-10-03 11:10:00',
			'register_ip' => '121.11.142.210',
			'last_time' => '2016-10-07 10:11:45',
			'last_ip' => '121.11.142.210',
		);
		return Rens($data);

	}

	/**
	 * 查看财务
	 * 'finance description'
	 * @return 'type' 'description'
	 */
	function finance() {
		// $id = Request::has('account_identity') ? Request::get('account_identity') : '45b7d4e9-2bb9-16b3-9a50-6fd6f62235f8';
		// $data = DB::table('money_details')->select('account_name', 'id', 'trade_type', 'trade_id', 'money_time', 'money', 'sysetem_user')->where('account_identity', $id)->limit(2)->get();
		// echo "<pre>";
		// print_r($data);

		$data = array(
			'0' => array
			(
				'account_name' => '123qqq',
				'id' => '1094327',
				'trade_type' => 1,
				'trade_id' => '20170913162223362227472',
				'money_time' => '2017-09-13 16:22:23',
				'money' => 20,
				'sysetem_user' => '系统',
			),

			'1' => array
			(
				'account_name' => '123qqq',
				'id' => '1094352',
				'trade_type' => 1,
				'trade_id' => '20170913162250796540257',
				'money_time' => '2017-09-13 16:22:50',
				'money' => 180,
				'sysetem_user' => '系统',
			),
		);

		if (!$data) {
			return Rens(-2020026003);
		}
		return Rens($data);
	}

}

?>