<?php


namespace app\index\controller;

class Login extends \think\Controller
{
	public function index()
	{
	    if(isset($_GET['account']) && isset($_GET['pwd']) && isset($_GET['serverid']) && isset($_GET['guid'])){
	        $account = $_GET['account'];
	        $pwd = $_GET['pwd'];
	        $serverid = $_GET['serverid'];
	        $guid = $_GET['guid'];
	        $indexdata = \think\Db::name("user")->field(["lock"])->where(["account" => $account, "password" => md5($pwd)])->find();
			if ($indexdata) {
				if ($indexdata["lock"] == 0) {
				    \think\Session::set("account", $account);
				    \think\Session::set("serverid", $serverid);
				    \think\Session::set("guid", $guid);
					$time = date("Y-m-d H:i:s", time());
					$requestD = \think\Request::instance();
					\think\Db::name("user")->where("account", $account)->update(["logintime" => $time, "ipd" => $requestD->ip()]);
					//$this->success("登录成功", url("@index/Home"));
					//跳转到个人中心商城页面
					$this->redirect(url("@index/Home"));exit;
				} else {
					$data = ["code" => 100, "msg" => "账号已被锁定", "data" => ["access_token", ""]];
				}
			} else {
				$data = ["code" => 100, "msg" => "账号密码错误", "data" => ["access_token", ""]];
			}
			$this->error($data["msg"]);
	    }else{
	        return "非法访问！";
	    }
	}
}