初始化项目
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\service;
|
||||
|
||||
use app\common\service\BaseService;
|
||||
use think\facade\Cache as CacheDriver;
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
* Class Cache
|
||||
*/
|
||||
class Cache extends BaseService
|
||||
{
|
||||
// 缓存驱动句柄
|
||||
/** @var $CacheDriver \think\Cache */
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* 构造方法
|
||||
* Cache constructor.
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
// 实例化缓存驱动
|
||||
$this->cache = CacheDriver::instance();
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除缓存
|
||||
* @param $data
|
||||
* @return bool
|
||||
*/
|
||||
public function rmCache($data)
|
||||
{
|
||||
// 数据缓存
|
||||
if (in_array('data', $data['item'])) {
|
||||
// 强制模式
|
||||
$isForce = isset($data['isForce']) && $data['isForce'];
|
||||
// 清除缓存
|
||||
$isForce ? $this->cache->clear() : $this->cache->tag('cache')->clear();
|
||||
}
|
||||
// 临时文件
|
||||
if (in_array('temp', $data['item'])) {
|
||||
$paths = [
|
||||
'temp' => web_path() . 'temp/',
|
||||
'runtime-image' => runtime_root_path() . 'image/',
|
||||
'runtime-local' => runtime_root_path() . 'local/',
|
||||
];
|
||||
foreach ($paths as $path) {
|
||||
$this->deleteFolder($path);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 递归删除指定目录下所有文件
|
||||
* @param $path
|
||||
* @return bool
|
||||
*/
|
||||
private function deleteFolder($path)
|
||||
{
|
||||
if (!is_dir($path))
|
||||
return false;
|
||||
// 扫描一个文件夹内的所有文件夹和文件
|
||||
foreach (scandir($path) as $val) {
|
||||
// 排除目录中的.和..
|
||||
if (!in_array($val, ['.', '..', '.gitignore'])) {
|
||||
// 如果是目录则递归子目录,继续操作
|
||||
if (is_dir($path . $val)) {
|
||||
// 子目录中操作删除文件夹和文件
|
||||
$this->deleteFolder($path . $val . '/');
|
||||
// 目录清空后删除空文件夹
|
||||
rmdir($path . $val . '/');
|
||||
} else {
|
||||
// 如果是文件直接删除
|
||||
unlink($path . $val);
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\service\admin;
|
||||
|
||||
use think\facade\Cache;
|
||||
use app\common\service\BaseService;
|
||||
|
||||
/**
|
||||
* 超管用户服务类
|
||||
* Class User
|
||||
*/
|
||||
class User extends BaseService
|
||||
{
|
||||
// 用于生成token的自定义盐
|
||||
const TOKEN_SALT = '_admin_user_salt_';
|
||||
|
||||
/**
|
||||
* 获取登录的信息
|
||||
* @return mixed
|
||||
*/
|
||||
public static function getLoginInfo()
|
||||
{
|
||||
if (($token = self::getToken()) !== false) {
|
||||
return Cache::get($token);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 记录登录信息
|
||||
* @param array $userInfo
|
||||
* @return string
|
||||
*/
|
||||
public static function login(array $userInfo)
|
||||
{
|
||||
// 生成token
|
||||
$token = self::makeToken((int)$userInfo['admin_user_id']);
|
||||
// 记录缓存, 7天
|
||||
Cache::set($token, [
|
||||
'user' => [
|
||||
'admin_user_id' => (int)$userInfo['admin_user_id'],
|
||||
'user_name' => $userInfo['user_name'],
|
||||
],
|
||||
'is_login' => true,
|
||||
], 86400 * 7);
|
||||
return $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清空登录状态
|
||||
* @return bool
|
||||
*/
|
||||
public static function logout()
|
||||
{
|
||||
Cache::delete(self::getToken());
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新登录信息
|
||||
* @param array $userInfo
|
||||
* @return mixed
|
||||
*/
|
||||
public static function update(array $userInfo)
|
||||
{
|
||||
return Cache::set(self::getToken(), [
|
||||
'user' => [
|
||||
'admin_user_id' => $userInfo['admin_user_id'],
|
||||
'user_name' => $userInfo['user_name'],
|
||||
],
|
||||
'is_login' => true,
|
||||
], 86400 * 7);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成用户认证的token
|
||||
* @param int $userId
|
||||
* @return string
|
||||
*/
|
||||
private static function makeToken(int $userId)
|
||||
{
|
||||
// 生成一个不会重复的随机字符串
|
||||
$guid = get_guid_v4();
|
||||
// 当前时间戳 (精确到毫秒)
|
||||
$timeStamp = microtime(true);
|
||||
// 自定义一个盐
|
||||
$salt = self::TOKEN_SALT;
|
||||
return md5("{$timeStamp}_{$userId}_{$guid}_{$salt}");
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户认证Token
|
||||
* @return bool|string
|
||||
*/
|
||||
private static function getToken()
|
||||
{
|
||||
// 获取请求中的token
|
||||
$token = request()->header('Access-Token');
|
||||
// 调试模式下可通过param
|
||||
if (empty($token) && is_debug()) {
|
||||
$token = request()->param('Access-Token');
|
||||
}
|
||||
// 不存在token报错
|
||||
if (empty($token)) {
|
||||
return false;
|
||||
}
|
||||
return $token;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 萤火商城系统 [ 致力于通过产品和服务,帮助商家高效化开拓市场 ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Licensed 这不是一个自由软件,不允许对程序代码以任何形式任何目的的再发行
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 萤火科技 <admin@yiovo.com>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types=1);
|
||||
|
||||
namespace app\admin\service\store;
|
||||
|
||||
use app\common\service\store\User as Basics;
|
||||
use app\admin\model\store\User as StoreUserModel;
|
||||
|
||||
/**
|
||||
* 超管用户服务类
|
||||
* Class User
|
||||
*/
|
||||
class User extends Basics
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user