<?php
namespace app\index\model;

use think\Model;


class Accounts extends Model
{

    //用户
    function getOneAccount($userName)
    {
        $res=db('accounts')->where('user_name',$userName)->find();
        if(!$res){
            return $res;
        }
        return $res;
    }

    //检测token
    function checktoken($token){
        $user = db('accounts')->where('token', $token)->find();
        if(!empty($user)){
            $time = time()-$user['expire_time'];
            if($time<3600){
                db('accounts')->where('id', $user['id'])->update(['expire_time' => time()]);
                return 1;
            }else{
                return -1;
            }
        }
        return -1;
    }

}
