diff --git a/app/admin/controller/Plugins.php b/app/admin/controller/Plugins.php index 82e467813..422061774 100755 --- a/app/admin/controller/Plugins.php +++ b/app/admin/controller/Plugins.php @@ -10,6 +10,7 @@ // +---------------------------------------------------------------------- namespace app\admin\controller; +use app\service\SystemService; use app\service\ApiService; use app\service\PluginsService; use app\service\ResourcesService; @@ -85,7 +86,7 @@ class Plugins extends Common } // 插件权限校验 - $power_plugins = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$this->admin['id']); + $power_plugins = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$this->admin['id']); if(empty($power_plugins) || !array_key_exists($params['data_request']['pluginsname'], $power_plugins)) { $msg = '无权限使用该插件'; diff --git a/app/admin/controller/Site.php b/app/admin/controller/Site.php index ef19011f6..1589cc93e 100755 --- a/app/admin/controller/Site.php +++ b/app/admin/controller/Site.php @@ -10,6 +10,7 @@ // +---------------------------------------------------------------------- namespace app\admin\controller; +use app\service\SystemService; use app\service\ConfigService; use app\service\GoodsService; use app\service\SiteService; @@ -382,11 +383,11 @@ class Site extends Common { // 登录 case 'login' : - MyCache(MyConfig('shopxo.cache_user_login_left_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_user_login_left_key'), null); // 密码找回 case 'forgetpwd' : - MyCache(MyConfig('shopxo.cache_user_forgetpwd_left_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_user_forgetpwd_left_key'), null); break; } } diff --git a/app/index/controller/User.php b/app/index/controller/User.php index 64b97df41..e711e2970 100755 --- a/app/index/controller/User.php +++ b/app/index/controller/User.php @@ -10,6 +10,7 @@ // +---------------------------------------------------------------------- namespace app\index\controller; +use app\service\SystemService; use app\service\OrderService; use app\service\GoodsService; use app\service\UserService; @@ -221,7 +222,7 @@ class User extends Common MyViewAssign('home_seo_site_title', SeoService::BrowserSeoTitle('密码找回', 1)); // 左侧图片,随机其中一个 - $left_data = UserService::UserEntranceLeftData(['left_key'=>'forgetpwd', 'cache_key'=>MyConfig('shopxo.cache_user_forgetpwd_left_key')]); + $left_data = UserService::UserEntranceLeftData(['left_key'=>'forgetpwd', 'cache_key'=>SystemService::CacheKey('shopxo.cache_user_forgetpwd_left_key')]); MyViewAssign('user_forgetpwd_left_data', empty($left_data['data']) ? [] : $left_data['data'][array_rand($left_data['data'], 1)]); return MyView(); @@ -287,7 +288,7 @@ class User extends Common MyViewAssign('referer_url', $this->GetrefererUrl()); // 左侧图片,随机其中一个 - $left_data = UserService::UserEntranceLeftData(['left_key'=>'login', 'cache_key'=>MyConfig('shopxo.cache_user_login_left_key')]); + $left_data = UserService::UserEntranceLeftData(['left_key'=>'login', 'cache_key'=>SystemService::CacheKey('shopxo.cache_user_login_left_key')]); MyViewAssign('user_login_left_data', empty($left_data['data']) ? [] : $left_data['data'][array_rand($left_data['data'], 1)]); return MyView(); diff --git a/app/service/AdminPowerService.php b/app/service/AdminPowerService.php index 9b9dde23c..a9dfa0d15 100755 --- a/app/service/AdminPowerService.php +++ b/app/service/AdminPowerService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\AdminService; use app\service\AdminRoleService; @@ -189,9 +190,9 @@ class AdminPowerService { foreach($admin as $id) { - MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$id, null); - MyCache(MyConfig('shopxo.cache_admin_power_key').$id, null); - MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$id, null); + MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$id, null); + MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$id, null); + MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$id, null); } } } @@ -213,9 +214,9 @@ class AdminPowerService $role_id = isset($admin['role_id']) ? intval($admin['role_id']) : 0; // 读取缓存数据 - $admin_left_menu = MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin_id); - $admin_power = MyCache(MyConfig('shopxo.cache_admin_power_key').$admin_id); - $admin_plugins = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin_id); + $admin_left_menu = MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin_id); + $admin_power = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin_id); + $admin_plugins = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin_id); // 缓存没数据则从数据库重新读取 if((($role_id > 0 || $admin_id == 1) && empty($admin_left_menu)) || $is_refresh || MyEnv('app_debug')) @@ -309,9 +310,9 @@ class AdminPowerService $admin_plugins = Db::name('RolePlugins')->where(['role_id'=>$role_id])->column('name', 'plugins'); } } - MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin_id, $admin_left_menu); - MyCache(MyConfig('shopxo.cache_admin_power_key').$admin_id, $admin_power); - MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin_id, $admin_plugins); + MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin_id, $admin_left_menu); + MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin_id, $admin_power); + MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin_id, $admin_plugins); } return true; } @@ -329,7 +330,7 @@ class AdminPowerService $admin = AdminService::LoginInfo(); if(!empty($admin['id'])) { - $data = MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin['id']); + $data = MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin['id']); } // 后台左侧菜单钩子 @@ -357,7 +358,7 @@ class AdminPowerService $admin = AdminService::LoginInfo(); if(!empty($admin['id'])) { - $data = MyCache(MyConfig('shopxo.cache_admin_power_key').$admin['id']); + $data = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin['id']); } // 后台左侧菜单权限钩子 diff --git a/app/service/AdminService.php b/app/service/AdminService.php index bba445271..ca8c727d3 100755 --- a/app/service/AdminService.php +++ b/app/service/AdminService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\AdminPowerService; /** @@ -506,9 +507,9 @@ class AdminService if(Db::name('Admin')->where(['id'=>$admin['id']])->update($data)) { // 清空权限缓存数据 - MyCache(MyConfig('shopxo.cache_admin_left_menu_key').$admin['id'], null); - MyCache(MyConfig('shopxo.cache_admin_power_key').$admin['id'], null); - MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin['id'], null); + MyCache(SystemService::CacheKey('shopxo.cache_admin_left_menu_key').$admin['id'], null); + MyCache(SystemService::CacheKey('shopxo.cache_admin_power_key').$admin['id'], null); + MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin['id'], null); // 权限菜单初始化 AdminPowerService::PowerMenuInit(); diff --git a/app/service/AppCenterNavService.php b/app/service/AppCenterNavService.php index b2a845d42..bf4814a95 100755 --- a/app/service/AppCenterNavService.php +++ b/app/service/AppCenterNavService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\ResourcesService; /** @@ -274,7 +275,7 @@ class AppCenterNavService public static function AppCenterNav($params = []) { // 缓存 - $key = MyConfig('shopxo.cache_app_user_center_navigation_key').APPLICATION_CLIENT_TYPE; + $key = SystemService::CacheKey('shopxo.cache_app_user_center_navigation_key').APPLICATION_CLIENT_TYPE; $data = MyCache($key); if(empty($data)) diff --git a/app/service/AppHomeNavService.php b/app/service/AppHomeNavService.php index 1944b9d34..bbd8d7f15 100755 --- a/app/service/AppHomeNavService.php +++ b/app/service/AppHomeNavService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\ResourcesService; /** @@ -269,7 +270,7 @@ class AppHomeNavService public static function AppHomeNav($params = []) { // 缓存 - $key = MyConfig('shopxo.cache_app_home_navigation_key').APPLICATION_CLIENT_TYPE; + $key = SystemService::CacheKey('shopxo.cache_app_home_navigation_key').APPLICATION_CLIENT_TYPE; $data = MyCache($key); if($data === null || MyEnv('app_debug')) { diff --git a/app/service/ArticleService.php b/app/service/ArticleService.php index a6f8d7c97..39e30091f 100755 --- a/app/service/ArticleService.php +++ b/app/service/ArticleService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\ResourcesService; /** @@ -34,7 +35,7 @@ class ArticleService public static function HomeArticleList($params = []) { // 从缓存获取 - $key = MyConfig('shopxo.cache_home_article_list_key'); + $key = SystemService::CacheKey('shopxo.cache_home_article_list_key'); $data = MyCache($key); if($data === null || MyEnv('app_debug')) { diff --git a/app/service/BannerService.php b/app/service/BannerService.php index ea1d149ea..09f9bb2d8 100755 --- a/app/service/BannerService.php +++ b/app/service/BannerService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\ResourcesService; /** @@ -34,7 +35,7 @@ class BannerService public static function Banner($params = []) { // 缓存 - $key = MyConfig('shopxo.cache_banner_list_key').APPLICATION_CLIENT_TYPE; + $key = SystemService::CacheKey('shopxo.cache_banner_list_key').APPLICATION_CLIENT_TYPE; $data = MyCache($key); if($data === null || MyEnv('app_debug')) { diff --git a/app/service/ConfigService.php b/app/service/ConfigService.php index 686b719b5..add9c69c4 100755 --- a/app/service/ConfigService.php +++ b/app/service/ConfigService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\ResourcesService; /** @@ -204,7 +205,7 @@ class ConfigService if($success > 0) { // 删除所有配置的缓存数据 - MyCache(MyConfig('shopxo.cache_common_my_config_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_common_my_config_key'), null); // 所有配置信息更新 self::ConfigInit(1); @@ -257,7 +258,7 @@ class ConfigService */ public static function ConfigInit($status = 0) { - $key = MyConfig('shopxo.cache_common_my_config_key'); + $key = SystemService::CacheKey('shopxo.cache_common_my_config_key'); $data = MyCache($key); if($data === null || $status == 1) { diff --git a/app/service/GoodsService.php b/app/service/GoodsService.php index 71a8744e6..25e341b1e 100755 --- a/app/service/GoodsService.php +++ b/app/service/GoodsService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\SystemBaseService; use app\service\ResourcesService; use app\service\BrandService; @@ -63,7 +64,7 @@ class GoodsService public static function GoodsCategoryAll($params = []) { // 从缓存获取 - $key = MyConfig('shopxo.cache_goods_category_key'); + $key = SystemService::CacheKey('shopxo.cache_goods_category_key'); $data = MyCache($key); if($data === null || MyEnv('app_debug')) { @@ -219,7 +220,7 @@ class GoodsService public static function HomeFloorList($params = []) { // 缓存 - $key = MyConfig('shopxo.cache_goods_floor_list_key'); + $key = SystemService::CacheKey('shopxo.cache_goods_floor_list_key'); $data = MyCache($key); if($data === null || MyEnv('app_debug')) { @@ -2639,7 +2640,7 @@ class GoodsService } // 删除大分类缓存 - MyCache(MyConfig('shopxo.cache_goods_category_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_goods_category_key'), null); $res = self::GoodsCategoryDataHandle([$data]); return DataReturn('操作成功', 0, json_encode($res[0])); @@ -2681,7 +2682,7 @@ class GoodsService if(Db::name('GoodsCategory')->where(['id'=>$ids])->delete()) { // 删除大分类缓存 - MyCache(MyConfig('shopxo.cache_goods_category_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_goods_category_key'), null); return DataReturn('删除成功', 0); } diff --git a/app/service/LinkService.php b/app/service/LinkService.php index 037569b06..108edc9ba 100755 --- a/app/service/LinkService.php +++ b/app/service/LinkService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\GoodsService; /** @@ -34,7 +35,7 @@ class LinkService public static function HomeLinkList($params = []) { // 从缓存获取 - $key = MyConfig('shopxo.cache_home_link_list_key'); + $key = SystemService::CacheKey('shopxo.cache_home_link_list_key'); $data = MyCache($key); if($data == null || MyEnv('app_debug')) { diff --git a/app/service/NavigationService.php b/app/service/NavigationService.php index b5d83a07b..3c9507c9c 100755 --- a/app/service/NavigationService.php +++ b/app/service/NavigationService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\BuyService; use app\service\MessageService; use app\service\OrderService; @@ -40,8 +41,8 @@ class NavigationService public static function Nav($params = []) { // 读取缓存数据 - $header = MyCache(MyConfig('shopxo.cache_common_home_nav_header_key')); - $footer = MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key')); + $header = MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_header_key')); + $footer = MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_footer_key')); // 缓存没数据则从数据库重新读取,顶部菜单 if($header === null || MyEnv('app_debug')) @@ -157,7 +158,7 @@ class NavigationService } // 缓存 - MyCache(MyConfig('shopxo.cache_common_home_nav_'.$nav_type.'_key'), $data, 180); + MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_'.$nav_type.'_key'), $data, 180); return $data; } @@ -470,7 +471,7 @@ class NavigationService public static function NacDataSave($params = []) { // 缓存 key - $cache_key = MyConfig('shopxo.cache_common_home_nav_'.$params['nav_type'].'_key'); + $cache_key = SystemService::CacheKey('shopxo.cache_common_home_nav_'.$params['nav_type'].'_key'); // 非自定义导航数据处理 if(empty($params['name'])) @@ -573,8 +574,8 @@ class NavigationService Db::commit(); // 清除缓存 - MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'), null); - MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_header_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_footer_key'), null); return DataReturn('删除成功'); } @@ -623,8 +624,8 @@ class NavigationService if(Db::name('Navigation')->where(['id'=>intval($params['id'])])->update([$params['field']=>intval($params['state']), 'upd_time'=>time()])) { // 清除缓存 - MyCache(MyConfig('shopxo.cache_common_home_nav_header_key'), null); - MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_header_key'), null); + MyCache(SystemService::CacheKey('shopxo.cache_common_home_nav_footer_key'), null); return DataReturn('编辑成功'); } diff --git a/app/service/PluginsAdminService.php b/app/service/PluginsAdminService.php index d4429368c..22800b270 100755 --- a/app/service/PluginsAdminService.php +++ b/app/service/PluginsAdminService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\PluginsService; use app\service\ResourcesService; use app\service\SqlConsoleService; @@ -64,7 +65,7 @@ class PluginsAdminService $admin = AdminService::LoginInfo(); if(!empty($admin)) { - $res = MyCache(MyConfig('shopxo.cache_admin_power_plugins_key').$admin['id']); + $res = MyCache(SystemService::CacheKey('shopxo.cache_admin_power_plugins_key').$admin['id']); if(!empty($res)) { $power_plugins = $res; diff --git a/app/service/PluginsService.php b/app/service/PluginsService.php index 587395f0a..ac2012309 100755 --- a/app/service/PluginsService.php +++ b/app/service/PluginsService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\ResourcesService; use app\service\PluginsAdminService; use app\service\StoreService; @@ -186,7 +187,7 @@ class PluginsService */ public static function PluginsCacheStorage($plugins, $data) { - return MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins, $data); + return MyCache(SystemService::CacheKey('shopxo.cache_plugins_data_key').$plugins, $data); } /** @@ -200,7 +201,7 @@ class PluginsService */ public static function PluginsCacheData($plugins) { - return MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins); + return MyCache(SystemService::CacheKey('shopxo.cache_plugins_data_key').$plugins); } /** @@ -214,7 +215,7 @@ class PluginsService */ public static function PluginsCacheDelete($plugins) { - MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins, null); + MyCache(SystemService::CacheKey('shopxo.cache_plugins_data_key').$plugins, null); } /** diff --git a/app/service/QuickNavService.php b/app/service/QuickNavService.php index 4448a63f0..f40becbcc 100755 --- a/app/service/QuickNavService.php +++ b/app/service/QuickNavService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\ResourcesService; /** @@ -268,7 +269,7 @@ class QuickNavService public static function QuickNav($params = []) { // 缓存 - $key = MyConfig('shopxo.cache_quick_navigation_key').APPLICATION_CLIENT_TYPE; + $key = SystemService::CacheKey('shopxo.cache_quick_navigation_key').APPLICATION_CLIENT_TYPE; $data = MyCache($key); if($data === null || MyEnv('app_debug')) { diff --git a/app/service/RegionService.php b/app/service/RegionService.php index 2e80ad551..630366c5a 100755 --- a/app/service/RegionService.php +++ b/app/service/RegionService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; /** * 地区服务层 @@ -261,7 +262,7 @@ class RegionService public static function RegionAll($params = []) { // 缓存 - $key = MyConfig('shopxo.cache_region_all_key'); + $key = SystemService::CacheKey('shopxo.cache_region_all_key'); $data = MyCache($key); if(empty($data)) { diff --git a/app/service/SearchService.php b/app/service/SearchService.php index 44516ca16..0d42eaa49 100755 --- a/app/service/SearchService.php +++ b/app/service/SearchService.php @@ -11,6 +11,7 @@ namespace app\service; use think\facade\Db; +use app\service\SystemService; use app\service\GoodsService; use app\service\BrandService; use app\service\ResourcesService; @@ -380,7 +381,7 @@ class SearchService */ public static function SearchKeywordsList($params = []) { - $key = MyConfig('shopxo.cache_search_keywords_key'); + $key = SystemService::CacheKey('shopxo.cache_search_keywords_key'); $data = MyCache($key); if($data === null || MyEnv('app_debug')) { diff --git a/app/service/SystemService.php b/app/service/SystemService.php index b3f7ac2a4..068fb6b82 100644 --- a/app/service/SystemService.php +++ b/app/service/SystemService.php @@ -139,5 +139,19 @@ class SystemService return $value; } + + /** + * 缓存key获取 + * @author Devil + * @blog http://gong.gg/ + * @version 1.0.0 + * @date 2022-04-21 + * @desc description + * @param [string] $key [缓存key] + */ + public static function CacheKey($key) + { + return MyConfig($key).'_'.SYSTEM_TYPE; + } } ?> \ No newline at end of file diff --git a/app/service/UserService.php b/app/service/UserService.php index 94181ae56..3e0485e91 100755 --- a/app/service/UserService.php +++ b/app/service/UserService.php @@ -95,7 +95,7 @@ class UserService self::UserLoginRecord($user_login_info['id']); if(!empty($user_login_info['token'])) { - MyCache(MyConfig('shopxo.cache_user_info').$user_login_info['token'], $user_login_info); + MyCache(SystemService::CacheKey('shopxo.cache_user_info').$user_login_info['token'], $user_login_info); } } } @@ -114,7 +114,7 @@ class UserService */ public static function UserTokenData($token) { - $user = MyCache(MyConfig('shopxo.cache_user_info').$token); + $user = MyCache(SystemService::CacheKey('shopxo.cache_user_info').$token); if($user !== null && isset($user['id'])) { return $user; @@ -2107,7 +2107,7 @@ class UserService $user['token'] = self::CreatedUserToken($user_id); if(Db::name('User')->where(['id'=>$user_id])->update(['token'=>$user['token'], 'upd_time'=>time()])) { - MyCache(MyConfig('shopxo.cache_user_info').$user['token'], $user); + MyCache(SystemService::CacheKey('shopxo.cache_user_info').$user['token'], $user); } // web端用户登录纪录处理