提交 cb0d297b 编写于 作者: D Devil

细节优化

上级 22e4ab16
......@@ -21,7 +21,6 @@ use app\service\BuyService;
use app\service\MessageService;
use app\service\SearchService;
use app\service\ConfigService;
use app\service\LinkService;
use app\service\UserService;
use app\service\AdminService;
use app\service\QuickNavService;
......@@ -287,10 +286,6 @@ class Common extends BaseController
// 搜索框下热门关键字
MyViewAssign('home_search_keywords', SearchService::SearchKeywordsList());
// 友情链接
$link = LinkService::LinkList(['where'=>['is_enable'=>1]]);
MyViewAssign('link_list', $link['data']);
// 开发模式
MyViewAssign('shopxo_is_develop', MyConfig('shopxo.is_develop'));
......
......@@ -19,6 +19,7 @@ use app\service\ArticleService;
use app\service\OrderService;
use app\service\AppHomeNavService;
use app\service\BrandService;
use app\service\LinkService;
use app\service\LayoutService;
/**
......@@ -123,14 +124,8 @@ class Index extends Common
MyViewAssign('goods_floor_list', GoodsService::HomeFloorList());
// 文章
$params = [
'where' => ['is_enable'=>1, 'is_home_recommended'=>1],
'field' => 'id,title,title_color,article_category_id',
'm' => 0,
'n' => 9,
];
$article_list = ArticleService::ArticleList($params);
MyViewAssign('article_list', $article_list['data']);
$article_list = ArticleService::HomeArticleList();
MyViewAssign('article_list', $article_list);
// 用户订单状态
$user_order_status = OrderService::OrderStatusStepTotal(['user_type'=>'user', 'user'=>$this->user, 'is_comments'=>1]);
......@@ -138,6 +133,10 @@ class Index extends Common
}
}
// 友情链接
$link_list = LinkService::HomeLinkList();
MyViewAssign('link_list', $link_list);
// 加载百度地图api
// 存在地图事件则载入
if(in_array(3, array_column($banner, 'event_type')))
......
......@@ -70,7 +70,7 @@
<div class="am-footer-miscs">
<div class="am-container">
<!-- 友情链接 -->
{{if !empty($link_list) and $module_name.$controller_name.$action_name eq 'indexindexindex' and (!IsMobile() or (IsMobile() and MyC('home_index_friendship_link_status') eq 1))}}
{{if !empty($link_list)}}
<div class="friendship-list">
<ul class="am-cf am-margin-bottom-sm">
<li class="am-fl am-text-center title">友情链接</li>
......
......@@ -275,8 +275,7 @@ class AppHomeNavService
// 缓存
$key = MyConfig('shopxo.cache_app_home_navigation_key').$platform;
$data = MyCache($key);
if(empty($data))
if($data === null || MyEnv('app_debug'))
{
// 获取导航数据
$field = 'id,name,images_url,event_value,event_type,bg_color,is_need_login';
......@@ -306,18 +305,23 @@ class AppHomeNavService
}
}
// 存储缓存
MyCache($key, $data, 60);
}
// 手机首页导航钩子
$hook_name = 'plugins_service_app_home_navigation_'.$platform;
MyEventTrigger($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'data' => &$data,
]);
// 手机首页导航钩子
$hook_name = 'plugins_service_app_home_navigation_'.$platform;
MyEventTrigger($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'data' => &$data,
]);
// 没数据则赋空数组值
if(empty($data))
{
$data = [];
}
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
}
......
......@@ -22,6 +22,38 @@ use app\service\ResourcesService;
*/
class ArticleService
{
/**
* 首页展示列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-07-23
* @desc description
* @param [array] $params [输入参数]
*/
public static function HomeArticleList($params = [])
{
// 从缓存获取
$key = MyConfig('shopxo.cache_home_article_list_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
// 文章
$params = [
'where' => ['is_enable'=>1, 'is_home_recommended'=>1],
'field' => 'id,title,title_color,article_category_id',
'm' => 0,
'n' => 9,
];
$ret = self::ArticleList($params);
$data = empty($ret['data']) ? [] : $ret['data'];
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
/**
* 获取文章列表
* @author Devil
......
......@@ -39,7 +39,7 @@ class BannerService
// 缓存
$key = MyConfig('shopxo.cache_banner_list_key').$platform;
$data = MyCache($key);
if(empty($data))
if($data === null || MyEnv('app_debug'))
{
// 获取banner数据
$field = 'name,images_url,event_value,event_type,bg_color';
......@@ -66,10 +66,12 @@ class BannerService
$v['event_value'] = null;
}
}
} else {
$data = [];
}
// 存储缓存
MyCache($key, $data, 60);
MyCache($key, $data, 180);
}
return $data;
}
......
......@@ -246,38 +246,42 @@ class ConfigService
{
$key = MyConfig('shopxo.cache_common_my_config_key');
$data = MyCache($key);
if(empty($data) || $status == 1)
if($data === null || $status == 1)
{
// 所有配置
$data = Db::name('Config')->column('value', 'only_tag');
// 数据处理
// 字符串转数组
foreach(self::$string_to_array_field_list as $fv)
if(!empty($data))
{
if(isset($data[$fv]))
// 数据处理
// 字符串转数组
foreach(self::$string_to_array_field_list as $fv)
{
$data[$fv] = ($data[$fv] == '') ? [] : explode(',', $data[$fv]);
if(isset($data[$fv]))
{
$data[$fv] = ($data[$fv] == '') ? [] : explode(',', $data[$fv]);
}
}
}
// 数据处理
foreach($data as $k=>&$v)
{
// 富文本字段处理
if(in_array($k, self::$rich_text_list))
// 数据处理
foreach($data as $k=>&$v)
{
$v = ResourcesService::ContentStaticReplace($v, 'get');
}
// 富文本字段处理
if(in_array($k, self::$rich_text_list))
{
$v = ResourcesService::ContentStaticReplace($v, 'get');
}
// 公共内置数据缓存
MyCache($k, $v);
// 公共内置数据缓存
MyCache($k, $v);
// 数据文件缓存
if(in_array($k, self::$file_cache_keys))
{
MyFileConfig($k, $v);
// 数据文件缓存
if(in_array($k, self::$file_cache_keys))
{
MyFileConfig($k, $v);
}
}
} else {
$data = [];
}
// 所有配置缓存集合
......@@ -357,11 +361,8 @@ class ConfigService
*/
public static function ConfigContentRow($key)
{
// 缓存key,单条新增前缀,与公共配置区分开
$data = MyCache('config_content_row_'.$key);
// 获取内容
if(empty($data))
$data = MyCache($key);
if($data === null)
{
$data = Db::name('Config')->where(['only_tag'=>$key])->field('name,value,type,upd_time')->find();
if(!empty($data))
......@@ -372,6 +373,8 @@ class ConfigService
$data['value'] = ResourcesService::ContentStaticReplace($data['value'], 'get');
}
$data['upd_time_time'] = empty($data['upd_time']) ? null : date('Y-m-d H:i:s', $data['upd_time']);
} else {
$data = [];
}
MyCache($key, $data);
}
......
......@@ -65,7 +65,7 @@ class GoodsService
// 从缓存获取
$key = MyConfig('shopxo.cache_goods_category_key');
$data = MyCache($key);
if(empty($data) || MyEnv('app_debug'))
if($data === null || MyEnv('app_debug'))
{
// 获取分类
$params['where'] = [
......@@ -75,7 +75,7 @@ class GoodsService
$data = self::GoodsCategory($params);
// 存储缓存
MyCache($key, $data, 60);
MyCache($key, $data, 180);
}
return $data;
}
......@@ -134,6 +134,8 @@ class GoodsService
}
}
}
} else {
$data = [];
}
return $data;
}
......@@ -212,7 +214,7 @@ class GoodsService
// 缓存
$key = MyConfig('shopxo.cache_goods_floor_list_key');
$data = MyCache($key);
if(empty($data) || MyEnv('app_debug'))
if($data === null || MyEnv('app_debug'))
{
// 商品大分类
$where = [
......@@ -318,10 +320,12 @@ class GoodsService
// 楼层关键字
$v['config_keywords'] = (empty($floor_keywords) || empty($floor_keywords[$v['id']])) ? [] : explode(',', $floor_keywords[$v['id']]);
}
} else {
$data = [];
}
// 存储缓存
MyCache($key, $data, 60);
MyCache($key, $data, 180);
}
// 商品读取、商品信息需要实时读取
......
......@@ -22,6 +22,37 @@ use app\service\GoodsService;
*/
class LinkService
{
/**
* 首页展示列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2021-07-23
* @desc description
* @param [array] $params [输入参数]
*/
public static function HomeLinkList($params = [])
{
// 从缓存获取
$key = MyConfig('shopxo.cache_home_link_list_key');
$data = MyCache($key);
if($data == null || MyEnv('app_debug'))
{
$is_mobile = IsMobile();
if(!$is_mobile || ($is_mobile && MyC('home_index_friendship_link_status') == 1))
{
$ret = self::LinkList(['where'=>['is_enable'=>1]]);
$data = empty($ret['data']) ? [] : $ret['data'];
} else {
$data = [];
}
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
/**
* 列表
* @author Devil
......
......@@ -44,14 +44,14 @@ class NavigationService
$footer = MyCache(MyConfig('shopxo.cache_common_home_nav_footer_key'));
// 缓存没数据则从数据库重新读取,顶部菜单
if(empty($header) || MyEnv('app_debug'))
if($header === null || MyEnv('app_debug'))
{
// 获取导航数据
$header = self::NavDataAll('header');
}
// 底部导航
if(empty($footer) || MyEnv('app_debug'))
if($footer === null || MyEnv('app_debug'))
{
// 获取导航数据
$footer = self::NavDataAll('footer');
......@@ -150,8 +150,14 @@ class NavigationService
$nav_type => &$data,
]);
// 没数据则赋空数组值
if(empty($data))
{
$data = [];
}
// 缓存
MyCache(MyConfig('shopxo.cache_common_home_nav_'.$nav_type.'_key'), $data, 60);
MyCache(MyConfig('shopxo.cache_common_home_nav_'.$nav_type.'_key'), $data, 180);
return $data;
}
......
......@@ -41,7 +41,7 @@ class PluginsService
$data = ($is_cache === true) ? self::PluginsCacheData($plugins) : [];
// 数据不存在则从数据库读取
if(empty($data))
if($data === null)
{
// 获取数据
$ret = self::PluginsField($plugins, 'data');
......@@ -49,15 +49,18 @@ class PluginsService
{
// 数据处理
$data = self::PluginsDataHandle($ret['data'], $attachment_field);
// 存储缓存
self::PluginsCacheStorage($plugins, $data);
} else {
$data = [];
}
// 存储缓存
self::PluginsCacheStorage($plugins, $data);
}
return DataReturn('处理成功', 0, empty($data) ? [] : $data);
return DataReturn('处理成功', 0, $data);
}
/**
* 插件配置数据处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
......@@ -113,7 +116,7 @@ class PluginsService
}
}
}
return empty($data) ? null : $data;
return empty($data) ? [] : $data;
}
/**
......@@ -413,7 +416,7 @@ class PluginsService
$v['data'] = self::PluginsDataHandle($v['data']);
}
} else {
$data = null;
$data = [];
}
return $data;
}
......
......@@ -274,8 +274,7 @@ class QuickNavService
// 缓存
$key = MyConfig('shopxo.cache_quick_navigation_key').$platform;
$data = MyCache($key);
if(empty($data))
if($data === null || MyEnv('app_debug'))
{
// 获取导航数据
$field = 'id,name,images_url,event_value,event_type,bg_color';
......@@ -305,20 +304,25 @@ class QuickNavService
}
}
// 存储缓存
MyCache($key, $data, 60);
}
// 快捷导航钩子
// web端数据参数可以自定义新增 class_name 名称、方便非url事件使用js控制点击事件
// 支持标签自定义数据值 data_value 名称、方便自定义事件响应需要依赖的数据
$hook_name = 'plugins_service_quick_navigation_'.$platform;
MyEventTrigger($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'data' => &$data,
]);
// 快捷导航钩子
// web端数据参数可以自定义新增 class_name 名称、方便非url事件使用js控制点击事件
// 支持标签自定义数据值 data_value 名称、方便自定义事件响应需要依赖的数据
$hook_name = 'plugins_service_quick_navigation_'.$platform;
MyEventTrigger($hook_name, [
'hook_name' => $hook_name,
'is_backend' => true,
'data' => &$data,
]);
// 没数据则赋空数组值
if(empty($data))
{
$data = [];
}
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
}
......
......@@ -380,20 +380,32 @@ class SearchService
*/
public static function SearchKeywordsList($params = [])
{
// 搜索框下热门关键字
$data = [];
switch(intval(MyC('home_search_keywords_type', 0)))
$key = MyConfig('shopxo.cache_search_keywords_key');
$data = MyCache($key);
if($data === null || MyEnv('app_debug'))
{
case 1 :
$data = Db::name('SearchHistory')->where([['keywords', '<>', '']])->group('keywords')->limit(10)->column('keywords');
break;
case 2 :
$keywords = MyC('home_search_keywords', '', true);
if(!empty($keywords))
{
$data = explode(',', $keywords);
}
break;
switch(intval(MyC('home_search_keywords_type', 0)))
{
case 1 :
$data = Db::name('SearchHistory')->where([['keywords', '<>', '']])->group('keywords')->limit(10)->column('keywords');
break;
case 2 :
$keywords = MyC('home_search_keywords', '', true);
if(!empty($keywords))
{
$data = explode(',', $keywords);
}
break;
}
// 没数据则赋空数组值
if(empty($data))
{
$data = [];
}
// 存储缓存
MyCache($key, $data, 180);
}
return $data;
}
......
......@@ -289,7 +289,7 @@ class StoreService
$key = 'cache_store_url_http_code';
$time = 600;
$code = MyCache($key);
if($code == null)
if($code === null)
{
$code = GetHttpCode(self::StoreUrl(), 2);
MyCache($key, $code, $time);
......
......@@ -84,6 +84,15 @@ return [
// 地区所有数据缓存、1~3级
'cache_region_all_key' => 'cache_region_all_data',
// 搜索热门关键字
'cache_search_keywords_key' => 'cache_search_keywords_data',
// 首页展示的文章列表数据
'cache_home_article_list_key' => 'cache_home_article_list_data',
// 首页展示的友情链接列表数据
'cache_home_link_list_key' => 'cache_home_link_list_data',
// 附件host、最后不要带/斜杠结尾, 数据库图片地址以/static/...开头
'attachment_host' => $cdn_attachment_host,
......
{
"name":"默认主题",
"ver":"2.0.2",
"ver":"2.2.0",
"author":"Devil",
"home":"https://shopxo.net/"
}
\ No newline at end of file
{
"name":"默认主题",
"ver":"2.0.2",
"ver":"2.2.0",
"author":"Devil",
"home":"https://shopxo.net/"
}
\ No newline at end of file
{
"name":"默认主题",
"ver":"2.0.2",
"ver":"2.2.0",
"author":"Devil",
"home":"https://shopxo.net/"
}
\ No newline at end of file
{
"name":"默认主题",
"ver":"2.0.2",
"ver":"2.2.0",
"author":"Devil",
"home":"https://shopxo.net/"
}
\ No newline at end of file
{
"name":"默认主题",
"ver":"2.0.2",
"ver":"2.2.0",
"author":"Devil",
"home":"https://shopxo.net/"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册