<?php

namespace App\Http\Controllers\Admin;

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

/**
 *
 */
class AdminlogController extends Controller {
	/**
	 * @return 管理员日志管理
	 */
	function index(Req $req) {
		$request=array();
		$request['loginname'] = isset($req->loginname) ? trim($req->loginname) : null;
		$request['ip'] = isset($req->ip) ? trim($req->ip) : null;
		$request['operation'] = isset($req->operation) ? trim($req->operation) : null;
        $request['star_time'] = isset($req->star_time) ? trim($req->star_time) :trans('status.default_time.seven_day') ;
        $request['end_time'] = isset($req->end_time) ? trim($req->end_time) : trans('status.default_time.etime');
		$dt = \App\Lib\DataTable\DataTable::init();
		$dt->setDataSource('/admin/manager/systemLog');
		$dt->setLang('system_user');
		$dt->addColsFields('loginname', array('width' => 160));
		$dt->addColsFields('ip', array('templet' => '#selectip', 'width' => 220));
		$dt->addColsFields('operation_time', array('width' => 260));
		$dt->addColsFields('operation', array('templet' => '#desc','width' => 710));
		$dt->setToolBar();

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

	/**
	 * 登录ip列表
	 * [detail description]
	 * @return [type] [description]
	 */
	function logipDetail() {
		$ip = Request::has('ip') ? Request::get('ip') : '';
		$dt = \App\Lib\DataTable\DataTable::init();
		$dt->setDataSource('/admin/manager/systemLog?ip=' . $ip);
		$dt->setLang('system_user');
		$dt->addColsFields('loginname', array('sort' => false, 'width' => 130));
		$dt->addColsFields('ip', array('width' => 160));
		$dt->addColsFields('operation_time', array('width' => 170));
		$dt->addColsFields('operation', array('width' => 637));
		return view('admin.SystemManage/Viewip', $dt->render());
	}
	//修改管理员密码
	function ChangePwd(Req $req) {
		$admin_id = session('adminInfo.admin_id');
		if (!$req->isMethod('post')) {
			return view('admin.login.edit', ['name' => session('adminInfo.admin_name')]);
		} else {
			$db = new \App\Models\System_user;
			$pwd = $req->password;
			$repwd = $req->repassword;
			$data = array();
			if (!empty($pwd)) {
				if ($pwd != $repwd) {
					return responseToJson(-7051010522); //两次密码不一致
				}
				$pwddata = GenPassword($pwd);
				$data['password'] = $pwddata['password'];
				$data['encryption'] = $pwddata['encryption'];
			}
			$twopwd = $req->password_2;
			$retwopwd = $req->repassword_2;
			if (!empty($twopwd)) {
				if ($twopwd != $retwopwd) {
					return responseToJson(-7051010622); //两次密码不一致
				}
				$twopwddata = GenPassword($twopwd);
				$data['password_2'] = $twopwddata['password'];
				$data['encryption_2'] = $twopwddata['encryption'];
			}
			$res = $db->updateInfo($data, $admin_id);
			return responseToJson($res);
		}
	}

}

?>