You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.1 KiB
84 lines
2.1 KiB
<?php
|
|
|
|
namespace app\admin\model\admin;
|
|
|
|
use app\common\dm\Dm;
|
|
use think\Session;
|
|
use app\common\model\admin\User as UserModel;
|
|
|
|
/**
|
|
* 超管后台用户模型
|
|
* Class User
|
|
* @package app\admin\model\admin
|
|
*/
|
|
class User extends UserModel
|
|
{
|
|
/**
|
|
* 超管后台用户登录
|
|
* @param $data
|
|
* @return bool
|
|
* @throws \think\db\exception\DataNotFoundException
|
|
* @throws \think\db\exception\ModelNotFoundException
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public function login($data)
|
|
{
|
|
// 验证用户名密码是否正确
|
|
$dm = new Dm();
|
|
$user = $dm->dmPDOFind('bt_admin_user',[
|
|
'user_name' => $data['user_name'],
|
|
'password' => yoshop_hash($data['password'])
|
|
]);
|
|
if (!$user['status']) {
|
|
$this->error = '登录失败, 用户名或密码错误';
|
|
return false;
|
|
}
|
|
// 保存登录状态
|
|
Session::set('yoshop_admin', [
|
|
'user' => [
|
|
'admin_user_id' => $user['data']['admin_user_id'],
|
|
'user_name' => $user['data']['user_name'],
|
|
],
|
|
'is_login' => true,
|
|
]);
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* 超管用户信息
|
|
* @param $admin_user_id
|
|
* @return null|static
|
|
* @throws \think\exception\DbException
|
|
*/
|
|
public static function detail($admin_user_id)
|
|
{
|
|
return self::get($admin_user_id);
|
|
}
|
|
|
|
/**
|
|
* 更新当前管理员信息
|
|
* @param $data
|
|
* @return bool
|
|
*/
|
|
public function renew($data)
|
|
{
|
|
if ($data['password'] !== $data['password_confirm']) {
|
|
$this->error = '确认密码不正确';
|
|
return false;
|
|
}
|
|
// 更新管理员信息
|
|
if ($this->save([
|
|
'user_name' => $data['user_name'],
|
|
'password' => yoshop_hash($data['password']),
|
|
]) === false) {
|
|
return false;
|
|
}
|
|
// 更新session
|
|
Session::set('yoshop_admin.user', [
|
|
'admin_user_id' => $this['admin_user_id'],
|
|
'user_name' => $data['user_name'],
|
|
]);
|
|
return true;
|
|
}
|
|
|
|
}
|