<?php
namespace app\common\model;
use think\facade\Session;
use think\Model;
use think\model\concern\SoftDelete;
class Admin extends Model
{
//软删除
use SoftDelete;
protected $deleteTime = 'delete_time';
protected $defaultSoftDelete = 0;
// 表名
protected $name = 'sys_admin';
//主键
protected $pk = 'id';
// 开启自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'ctime';
protected $updateTime = 'utime';
// 追加属性
protected $append = [
];
/**
* 登录
* @param $data 登录信息
*/
public function login($data)
{
//验证数据
$validate= new \app\common\validate\Admin();
if(!$validate->scene('Login')->check($data)){
return $validate->getError();
}
// 查询账户是否存在
$userinfo=$this->where('username='.$data['username'])->find();
if(!$userinfo){
return '账户不存在';
}
if(!lay_compare_password($data['password'],$userinfo['password'])){
return '密码输入错误';
}
Session::set('admininfo',$userinfo);
Session::set('admin_id',$userinfo['id']);
return 1;
}
}
微信截图_20190220135150.png
( 35.44 KB 下载:4 次 )
最佳答案