固定数据增加缓存

This commit is contained in:
gongfuxiang 2023-01-14 20:29:37 +08:00
parent e54eec18e4
commit 1ca8f46467
6 changed files with 404 additions and 341 deletions

View File

@ -366,7 +366,7 @@ class Common extends BaseController
$assign['user'] = $this->user;
// 用户中心菜单
$assign['user_left_menu'] = NavigationService::UsersCenterLeftList();
$assign['user_left_menu'] = NavigationService::UserCenterLeftList();
// 商品大分类
$assign['goods_category_list'] = GoodsService::GoodsCategoryAll();

View File

@ -35,7 +35,7 @@ class ArticleService
public static function HomeArticleList($params = [])
{
// 从缓存获取
$key = SystemService::CacheKey('shopxo.cache_home_article_list_key');
$key = SystemService::CacheKey('shopxo.cache_home_article_list_key').APPLICATION_CLIENT_TYPE;
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
@ -51,9 +51,6 @@ class ArticleService
// 存储缓存
MyCache($key, $data, 180);
} else {
// 处理数据、由于平台不一样url地址或者其他数据也会不一样
$data = self::ArticleListHandle($data);
}
return $data;
}

View File

@ -615,6 +615,11 @@ class GoodsCommentsService
* @param [int] $goods_id [商品id]
*/
public static function GoodsCommentsScore($goods_id)
{
// 从缓存获取
$key = SystemService::CacheKey('shopxo.cache_goods_comments_score_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
// 默认
$rating_list = [
@ -644,11 +649,16 @@ class GoodsCommentsService
sort($rating_list);
$avg = PriceNumberFormat(Db::name('GoodsComments')->where($where)->avg('rating'), 1);
$rate = ($avg <= 0) ? 100 : intval(($avg/5)*100);
return [
$data = [
'avg' => $avg,
'rate' => $rate,
'rating' => $rating_list,
];
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
/**

View File

@ -3010,6 +3010,11 @@ class GoodsService
* @param [array] $goods [商品信息]
*/
public static function GoodsDetailMiddleTabsNavList($goods)
{
// 从缓存获取
$key = SystemService::CacheKey('shopxo.cache_goods_detail_middle_tabs_key').APPLICATION;
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
// 是否展示商品评价
$is_comments = MyC('common_is_show_goods_comments', 1);
@ -3072,16 +3077,19 @@ class GoodsService
'data' => &$data,
]);
// 返回数据
if(APPLICATION == 'app')
// web端处理格式
if(APPLICATION == 'web')
{
return $data;
} else {
return [
$data = [
'nav' => $data,
'type' => array_column($data, 'type'),
];
}
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
/**
@ -3212,9 +3220,14 @@ class GoodsService
* @param [array] $goods [商品信息]
*/
public static function GoodsBreadcrumbData($goods)
{
// 从缓存获取
$key = SystemService::CacheKey('shopxo.cache_goods_detail_breadcrumb_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
// 默认首页
$result = [
$data = [
[
'type' => 0,
'name' => '首页',
@ -3240,13 +3253,13 @@ class GoodsService
}, $category);
if(count($category) == 1)
{
$result[] = [
$data[] = [
'type' => 0,
'name' => $category[0]['name'],
'url' => $category[0]['url'],
];
} else {
$result[] = [
$data[] = [
'type' => 1,
'name' => '商品分类',
'data' => $category,
@ -3256,11 +3269,15 @@ class GoodsService
}
// 当前商品名称
$result[] = [
$data[] = [
'type' => 0,
'name' => $goods['title'],
];
return $result;
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
/**

View File

@ -643,20 +643,11 @@ class NavigationService
*/
public static function HomeHavTopRight($params = [])
{
$cart_total = 0;
$message_total = -1;
if(!empty($params['user']))
// 从缓存获取
$key = SystemService::CacheKey('shopxo.cache_header_navigation_top_right_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
// 购物车商品汇总
$cart_res = GoodsCartService::UserGoodsCartTotal(['user'=>$params['user']]);
$cart_total = $cart_res['buy_number'];
// 未读消息总数
$message_params = ['user'=>$params['user'], 'is_more'=>1, 'is_read'=>0, 'user_type'=>'user'];
$message_total = MessageService::UserMessageTotal($message_params);
$message_total = ($message_total <= 0) ? -1 : $message_total;
}
// 列表
$data = [
[
@ -700,7 +691,7 @@ class NavigationService
'name' => '购物车',
'type' => 'cart',
'is_login' => 1,
'badge' => $cart_total,
'badge' => -1,
'icon' => 'am-icon-shopping-cart',
'url' => MyUrl('index/cart/index'),
'items' => [],
@ -709,7 +700,7 @@ class NavigationService
'name' => '消息',
'type' => 'message',
'is_login' => 1,
'badge' => $message_total,
'badge' => 0,
'icon' => 'am-icon-bell',
'url' => MyUrl('index/message/index'),
'items' => [],
@ -725,6 +716,34 @@ class NavigationService
'data' => &$data,
]);
// 存储缓存
MyCache($key, $data, 180);
}
// 实时数据处理
if(!empty($data) && !empty($params['user']))
{
// 所有类型
$type = array_column($data, 'type');
// 消息总数
$index = array_search('message', $type);
if($index !== false)
{
// 未读消息总数
$message_params = ['user'=>$params['user'], 'is_more'=>1, 'is_read'=>0, 'user_type'=>'user'];
$message_total = MessageService::UserMessageTotal($message_params);
$data[$index]['badge'] = ($message_total <= 0) ? -1 : $message_total;
}
// 购物车商品汇总
$index = array_search('cart', $type);
if($index !== false)
{
$cart_res = GoodsCartService::UserGoodsCartTotal(['user'=>$params['user']]);
$data[$index]['badge'] = $cart_res['buy_number'];
}
}
return $data;
}
@ -852,7 +871,7 @@ class NavigationService
* @desc description
* @param [array] $params [输入信息]
*/
public static function UsersCenterLeftList($params = [])
public static function UserCenterLeftList($params = [])
{
// name 名称
// url 页面地址
@ -862,6 +881,11 @@ class NavigationService
// item 二级数据
// is_system 是否系统内置菜单0否, 1是扩展数据可空或0
// 从缓存获取
$key = SystemService::CacheKey('shopxo.cache_user_center_left_nav_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
// 菜单列表
$data = [
'center' => [
@ -995,6 +1019,9 @@ class NavigationService
'data' => &$data,
]);
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}

View File

@ -64,6 +64,15 @@ return [
// 商品大分类缓存
'cache_goods_category_key' => 'cache_goods_category_key_data',
// 商品详情面包屑导航
'cache_goods_detail_breadcrumb_key' => 'cache_goods_detail_breadcrumb_key_data',
// 商品详情中间导航
'cache_goods_detail_middle_tabs_key' => 'cache_goods_detail_middle_tabs_key_data',
// 商品评论评分
'cache_goods_comments_score_key' => 'cache_goods_comments_score_key_data',
// 应用数据缓存
'cache_plugins_data_key' => 'cache_plugins_data_key_data_',
@ -103,6 +112,9 @@ return [
// 首页展示的友情链接列表数据
'cache_home_link_list_key' => 'cache_home_link_list_data',
// 用户中心左侧菜单
'cache_user_center_left_nav_key' => 'cache_user_center_left_nav_key_data',
// 站点域名地址
'domain_url' => $domain_url,