<?php

namespace Main\Lib;

use Dever;

class Core
{
    protected $uid = -1;
    protected $use = array();
    public $data = array();

    public function __construct()
    {
        $this->uid = Dever::load('passport/user')->check(false);
        if ($this->uid <= 0) {
            $this->uid = 1;
        }
        if ($this->uid) {
            $this->user = Dever::load('passport/api')->info($this->uid);
        } else {
            $this->user = Dever::load('passport/user')->init();
            $this->uid = $this->user['id'];
        }

        if ($this->user) {
            $this->user['uid'] = $this->user['id'];
        }
    }

    public function checkLogin()
    {
        if (!$this->uid || $this->uid <= 0) {
            Dever::alert('请先登录', -2);
        }
    }

    public function alert($state)
    {
        if ($state) {
            return array('msg' => 'ok');
        } else {
            Dever::alert('操作失败');
        }
    }
}