multi-store/app/store/logic/LoginLogic.php

86 lines
2.8 KiB
PHP
Raw Normal View History

2024-06-01 16:07:53 +08:00
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\store\logic;
use app\common\logic\BaseLogic;
use app\common\model\auth\Admin;
2024-06-03 15:48:47 +08:00
use app\common\model\system_store\SystemStoreStaff;
2024-06-01 16:07:53 +08:00
use app\store\service\AdminTokenService;
use app\common\model\auth\AdminRole;
use app\common\service\FileService;
use Webman\Config;
/**
* 登录逻辑
* Class LoginLogic
* @package app\store\logic
*/
class LoginLogic extends BaseLogic
{
/**
* @notes 管理员账号登录
* @param $params
* @return false|mixed
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 乔峰
* @date 2021/6/30 17:00
*/
public function login($params)
{
$time = time();
2024-06-03 15:48:47 +08:00
$admin = SystemStoreStaff::where('account', '=', $params['account'])->find();
2024-06-01 16:07:53 +08:00
//用户表登录信息更新
2024-06-03 15:48:47 +08:00
$admin->last_time = $time;
$admin->last_ip = request()->getLocalIp();
2024-06-01 16:07:53 +08:00
$admin->save();
//设置token
2024-06-03 15:48:47 +08:00
$adminInfo = AdminTokenService::setToken($admin->id, $params['terminal']);
2024-06-01 16:07:53 +08:00
//返回登录信息
$avatar = $admin->avatar ? $admin->avatar : Config::get('project.default_image.admin_avatar');
$avatar = FileService::getFileUrl($avatar);
return [
'name' => $adminInfo['name'],
'avatar' => $avatar,
'role_name' => $adminInfo['role_name'],
'token' => $adminInfo['token'],
'store_id' => $admin['store_id'],
2024-06-01 16:07:53 +08:00
];
}
/**
* @notes 退出登录
* @param $adminInfo
* @return bool
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author 乔峰
* @date 2021/7/5 14:34
*/
public function logout($adminInfo)
{
//token不存在不注销
if (!isset($adminInfo['token'])) {
return false;
}
//设置token过期
return AdminTokenService::expireToken($adminInfo['token']);
}
}