说明:可以使用手机号、用户名、邮箱等多种方式登录
// 定义多种登录方式
private $loginWay = [
// 用户名
'user_name',
// 邮箱
'user_email',
// 电话
'phone'
];
/**
* 登录
* @param $date
* @return bool|int
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function login($date)
{
foreach($this->loginWay as $k=>$v){
$userinfo = $this->where([$v=>$date['user_name']])->find();
if($userinfo){
break;
}
}
if(!$userinfo){
return 21; //用户名不存在
}
if($userinfo['user_password'] !== appkit_hash($date['user_password'])){
return 22; //密码不正确
}
//存session
Session::set('userinfo',$userinfo);
return true;
}