<?php

namespace App\Http\Controllers\Admin;

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

/**
 *
 */
class ReturnController extends Controller {
	/**
	 * @return 回水记录
	 */
	function index(Req $req) {
		$request=array();
		$request['account_name']=isset($req->account_name)?trim($req->account_name):null;
		$request['order_id'] = isset($req->order_id) ? trim($req->order_id) : null;
		$request['haddle_startime'] = isset($req->haddle_startime) ? trim($req->haddle_startime) : trans('status.default_time.seven_day');
		$request['haddle_endtime'] = isset($req->haddle_endtime) ? trim($req->haddle_endtime) : trans('status.default_time.etime');
		$request['money_small'] = isset($req->money_small) ? trim($req->money_small) : null;
		$request['money_big'] = isset($req->money_big) ? trim($req->money_big) : null;
		$request['lossmoney_small'] = isset($req->lossmoney_small) ? trim($req->lossmoney_small) : null;
		$request['lossmoney_big'] = isset($req->lossmoney_big) ? trim($req->lossmoney_big) : null;
		
		$dt = \App\Lib\DataTable\DataTable::init();
		$dt->setDataSource('/admin/money/returnList');
		$dt->setLang('money');
		$dt->setPriKey('order_id');
		$dt->addColsFields('id', array('width' => 110));
		$dt->addColsFields('account_name', array('sort' => false, 'templet' => '#userReturn', 'width' => 200));
		$dt->addColsFields('order_id', array('sort' => false, 'width' => 260));
		$dt->addColsFields('return_money', array('width' => 200));
		$dt->addColsFields('total_money', array('templet' => '#moneyReturn', 'width' => 200));
		$dt->addColsFields('processing_time');
		$dt->setToolBar(array('view'), array('width' => 100,'align' => 'left'));
		//$dt->addColsFields('action',array('width'=>250));

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

	/**
	 * 单用户回水列表
	 * [detail description]
	 * @return [type] [description]
	 */
	function userReturn() {
		$account_name = Request::has('account_name') ? Request::get('account_name') : '';
		$dt = \App\Lib\DataTable\DataTable::init();
		$dt->setDataSource('/admin/money/returnList?account_name=' . $account_name . '&sureblur=精确');
		$dt->setLang('money');
		$dt->setPriKey('order_id');
		$dt->addColsFields('id', array('fixed' => 'left'));
		$dt->addColsFields('account_name', array('templet' => '#userReturn'));
		$dt->addColsFields('order_id');
		$dt->addColsFields('money');
		$dt->addColsFields('total_money');
		$dt->addColsFields('processing_time');
		$dt->setToolBar(array('view'), array('width' => '103'));
		return view('admin.view', $dt->render());
	}

	//查看回水
	function View(Req $req) {
		$order_id = $req->order_id;
		if (empty($order_id)) {
			abort(404);
		}
//        $back_db=new \App\Model\Money_return;
		$money_db = new \App\Models\Money_details;
		$account_db = new \App\Models\Account;
		$bank_db = new \App\Models\Account_bank;
//        $data=$back_db->getOrderDetails($order_id,3);
		$data = $money_db->getOrderDetails($order_id, 3);
		$account = $account_db->getinfo($data['account_identity'], 2);
		$data['account_name'] = $account['account'];
		$bank_data = $bank_db->getInfoByUid($data['account_identity']);

		$data['bank_name'] = '';
		$data['bank_address'] = '';
		$data['bank_number'] = '';
		$data['name'] = '';
		if (!empty($bank_data)) {
			$data['bank_name'] = $bank_data['bank_name'];
			$data['bank_address'] = $bank_data['bank_address'];
			$data['bank_number'] = $bank_data['bank_number'];
			$data['name'] = $bank_data['account_name'];
		}
//        $data['trade_type ']='回水';
		//        dd($data);
		return view('admin.Return/view', ['data' => $data]);
	}

}

?>