<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
/*
后台登录
*/
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020 http://myucms.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Login extends Controller
{
    public function index()
    {
        if (request()->isPost()) {
            $data = input('post.');
            $open['open'] = 1;
            $open['admin'] = 1;
            $map['phone|username'] = $data['phone'];
            $key = 'www.115cms.com';
            $user = Db::name('member')->where($open)->where($map)->find();
            if ($user) {
                if (jiami($user['password'], 'DECODE', $key, 0) == $data['password']) {
                    session('phone', $user['phone']);
                    session('userid', $user['userid']);
                    session('username', $user['username']);
                    Db::name('member')->where($map)->setField(array('last_login_ip' => $_SERVER['REMOTE_ADDR'], 'last_login_time' => time()));
                    $this->success('登录成功');
                } else {
                    $this->error('密码错误');
                }
            } else {
                $this->error('管理员不存在');
            }
        }
        return $this->fetch();
    }
    public function logout()
    {
        session("phone", NULL);
        session("username", NULL);
        session("userid", NULL);
        return json(array('code' => 1, 'msg' => '退出成功'));
        return NULL;
    }
}