vr-shopxo-source/app/service/ConfigService.php

815 lines
28 KiB
PHP
Raw Normal View History

2018-12-28 10:58:37 +00:00
<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
2021-03-16 02:34:52 +00:00
// | Licensed ( https://opensource.org/licenses/mit-license.php )
2018-12-28 10:58:37 +00:00
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
namespace app\service;
2021-07-18 15:42:10 +00:00
use think\facade\Db;
2022-04-21 14:08:53 +00:00
use app\service\SystemService;
use app\service\ResourcesService;
2018-12-28 10:58:37 +00:00
/**
* 配置服务层
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2016-12-01T21:51:08+0800
*/
class ConfigService
{
2021-07-25 02:52:27 +00:00
// 不参与缓存的配置
public static $not_cache_field_list = [
'common_agreement_userregister',
'common_agreement_userprivacy',
2022-11-20 13:29:44 +00:00
'common_agreement_userlogout',
2021-07-25 02:52:27 +00:00
];
2019-05-16 10:42:22 +00:00
// 富文本,不实例化的字段
public static $rich_text_list = [
2021-07-25 02:52:27 +00:00
'common_agreement_userregister',
'common_agreement_userprivacy',
2022-11-20 13:29:44 +00:00
'common_agreement_userlogout',
2021-07-25 02:52:27 +00:00
'common_email_currency_template',
'home_footer_info',
2024-01-19 06:49:32 +00:00
'home_email_user_reg_template',
'home_email_user_forget_pwd_template',
'home_email_user_email_binding_template',
2021-07-25 02:52:27 +00:00
'home_site_close_reason',
2023-11-08 07:43:08 +00:00
'common_site_type',
2021-07-25 02:52:27 +00:00
'common_self_extraction_address',
'home_index_floor_top_right_keywords',
'home_index_floor_manual_mode_goods',
'home_index_floor_left_top_category',
'admin_email_login_template',
'home_email_login_template',
'home_site_security_record_url',
'home_site_company_license',
'common_default_payment',
2023-08-27 08:59:15 +00:00
'common_domain_multilingual_bind_list',
2023-09-17 14:54:33 +00:00
'common_multilingual_choose_list',
2024-01-19 06:49:32 +00:00
'common_regex_mobile',
'common_regex_tel',
'common_regex_id_card',
2024-07-03 14:46:04 +00:00
'common_app_customer_service_custom',
2024-10-22 09:24:02 +00:00
'common_app_home_data_diy_mode',
2021-07-25 02:52:27 +00:00
];
2019-05-16 10:42:22 +00:00
2019-05-16 17:42:37 +00:00
// 附件字段列表
public static $attachment_field_list = [
2024-01-19 06:49:32 +00:00
'admin_logo',
'admin_login_logo',
'admin_login_ad_images',
2019-05-16 17:42:37 +00:00
'home_site_logo',
'home_site_logo_wap',
2023-11-08 07:43:08 +00:00
'home_site_logo_app',
2021-10-23 10:23:43 +00:00
'home_site_logo_square',
2025-04-25 12:21:19 +00:00
'home_site_title_icon',
2019-05-16 17:42:37 +00:00
'common_customer_store_qrcode',
'home_site_user_register_bg_images',
2019-05-17 09:47:47 +00:00
'home_site_user_login_ad1_images',
'home_site_user_login_ad2_images',
'home_site_user_login_ad3_images',
'home_site_user_forgetpwd_ad1_images',
'home_site_user_forgetpwd_ad2_images',
'home_site_user_forgetpwd_ad3_images',
];
// 字符串转数组字段列表, 默认使用英文逗号处理 [ , ]
public static $string_to_array_field_list = [
'common_images_verify_rules',
'home_user_login_type',
'home_user_reg_type',
'admin_login_type',
2024-01-19 06:49:32 +00:00
'home_site_app_state',
2021-04-11 15:37:12 +00:00
'home_search_params_type',
2024-12-25 09:35:54 +00:00
'common_user_verify_bind_mobile_list',
'common_user_onekey_bind_mobile_list',
'common_user_address_platform_import_list',
2023-08-27 08:59:15 +00:00
'common_app_user_base_popup_pages',
'common_app_user_base_popup_client',
2024-10-21 02:51:14 +00:00
'common_token_created_rules',
2025-03-03 09:49:22 +00:00
'common_buy_datetime_info',
'common_buy_extraction_contact_info',
2019-05-16 17:42:37 +00:00
];
// json数组字段
public static $data_json_array_field_list = [
2023-11-08 07:43:08 +00:00
'common_site_type',
'common_default_payment',
2023-08-27 08:59:15 +00:00
'common_domain_multilingual_bind_list',
2023-09-17 14:54:33 +00:00
'common_multilingual_choose_list',
2024-07-03 14:46:04 +00:00
'common_app_customer_service_custom',
2024-10-22 09:24:02 +00:00
'common_app_home_data_diy_mode',
2023-09-17 14:54:33 +00:00
];
// 二维数组附件字段
public static $data_array_attachment_field_list = [
'common_multilingual_choose_list' => 'icon'
];
// 需要文件缓存的key
public static $file_cache_keys = [
// 伪静态后缀
'home_seo_url_html_suffix',
// 前端默认主题
'common_default_theme',
// 时区
'common_timezone',
2023-08-27 08:59:15 +00:00
// 是否开启缓存
'common_data_is_use_cache',
2023-08-27 08:59:15 +00:00
'common_data_is_use_redis_cache',
'common_cache_data_redis_host',
'common_cache_data_redis_port',
'common_cache_data_redis_password',
'common_cache_data_redis_expire',
'common_cache_data_redis_prefix',
// session是否开启redis缓存
'common_session_is_use_cache',
'common_cache_session_redis_prefix',
// 站点域名地址和cdn地址
'common_domain_host',
'common_cdn_attachment_host',
'common_cdn_public_host',
// h5地址
'common_app_h5_url',
// 编辑器配置信息
'home_max_limit_image',
'home_max_limit_video',
'home_max_limit_file',
2021-10-24 03:36:22 +00:00
// 是否采用https连接商店
'common_is_https_connect_store',
// cookie有效域名
'common_cookie_domain',
2023-03-22 10:59:53 +00:00
2023-06-01 07:01:28 +00:00
// 多语言可选列表和默认值
2023-03-22 10:59:53 +00:00
'common_multilingual_choose_list',
2024-12-25 09:35:54 +00:00
'common_multilingual_admin_default_value',
'common_multilingual_user_default_value',
];
2018-12-28 10:58:37 +00:00
/**
* 配置列表唯一标记作为key
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2018-12-07
* @desc description
* @param [array] $params [输入参数]
*/
public static function ConfigList($params = [])
2018-12-28 10:58:37 +00:00
{
$field = isset($params['field']) ? $params['field'] : 'only_tag,name,describe,value,error_tips';
2021-07-18 15:42:10 +00:00
$data = Db::name('Config')->column($field, 'only_tag');
if(!empty($data))
{
2023-01-31 10:44:32 +00:00
$lang = MyLang('common_config');
foreach($data as $k=>&$v)
{
// 字符串转数组
foreach(self::$string_to_array_field_list as $fv)
{
if($k == $fv)
{
2021-07-18 15:42:10 +00:00
$v['value'] = (!isset($v['value']) || $v['value'] == '' || is_array($v['value'])) ? [] : explode(',', $v['value']);
}
}
// json数据数组
foreach(self::$data_json_array_field_list as $fv)
{
if($k == $fv)
{
$v['value'] = empty($v['value']) ? [] : json_decode($v['value'], true);
}
}
2023-01-29 10:11:08 +00:00
2023-09-17 14:54:33 +00:00
// 数组附件字段
foreach(self::$data_array_attachment_field_list as $fk=>$fv)
{
if(!empty($data[$fk]) && is_array($data[$fk]) && !empty($data[$fk]['value']) && is_array($data[$fk]['value']))
{
foreach($data[$fk]['value'] as $fkk=>$fvv)
{
if(!empty($fvv[$fv]))
{
$data[$fk]['value'][$fkk][$fv] = ResourcesService::AttachmentPathViewHandle($fvv[$fv]);
}
}
}
}
2023-01-29 10:11:08 +00:00
// 多语言定义
if(!empty($lang) && is_array($lang) && array_key_exists($k, $lang) && is_array($lang[$k]))
{
$temp = $lang[$k];
if(array_key_exists('name', $temp))
{
$v['name'] = $temp['name'];
}
if(array_key_exists('desc', $temp))
{
$v['describe'] = $temp['desc'];
}
if(array_key_exists('tips', $temp))
{
$v['error_tips'] = $temp['tips'];
}
}
}
}
return $data;
2018-12-28 10:58:37 +00:00
}
/**
* 配置数据保存
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-01-02T23:08:19+0800
* @param [array] $params [输入参数]
*/
public static function ConfigSave($params = [])
2018-12-28 10:58:37 +00:00
{
// 参数校验
if(empty($params))
{
2023-02-08 13:20:04 +00:00
return DataReturn(MyLang('params_empty_tips'), -1);
2018-12-28 10:58:37 +00:00
}
2018-12-28 16:00:14 +00:00
// 当前参数中不存在则移除
2019-05-16 17:42:37 +00:00
$data_fields = self::$attachment_field_list;
2018-12-28 16:00:14 +00:00
foreach($data_fields as $key=>$field)
{
if(!isset($params[$field]))
{
unset($data_fields[$key]);
}
}
// 获取附件
2018-12-28 10:58:37 +00:00
$attachment = ResourcesService::AttachmentParams($params, $data_fields);
foreach($attachment['data'] as $k=>$v)
{
$params[$k] = $v;
}
// 循环保存数据
$success = 0;
// 开始更新数据
foreach($params as $k=>$v)
{
2024-07-03 14:46:04 +00:00
// 数据是数组则转为json字符串
if(is_array($v))
2018-12-28 10:58:37 +00:00
{
2024-07-03 14:46:04 +00:00
$v = empty($v) ? '' : json_encode($v, JSON_UNESCAPED_UNICODE);
2019-05-16 10:42:22 +00:00
} else {
2024-07-03 14:46:04 +00:00
// 富文本处理
if(in_array($k, self::$rich_text_list))
{
$v = ResourcesService::ContentStaticReplace($v, 'add');
} else {
$v = htmlentities($v);
}
2018-12-28 10:58:37 +00:00
}
2024-10-21 02:51:14 +00:00
if(Db::name('Config')->where(['only_tag'=>$k])->update(['value'=>$v, 'upd_time'=>time()]) !== false)
2018-12-28 10:58:37 +00:00
{
$success++;
2019-05-20 10:35:28 +00:00
// 单条配置缓存删除
2021-07-18 15:42:10 +00:00
MyCache($k, null);
2021-07-25 02:52:27 +00:00
MyCache($k.'_row_data', null);
2018-12-28 10:58:37 +00:00
}
}
if($success > 0)
{
2020-09-14 10:53:42 +00:00
// 删除所有配置的缓存数据
2022-04-21 14:08:53 +00:00
MyCache(SystemService::CacheKey('shopxo.cache_common_my_config_key'), null);
2020-09-14 10:53:42 +00:00
// 所有配置信息更新
self::ConfigInit(1);
2018-12-28 10:58:37 +00:00
2018-12-31 11:07:03 +00:00
// 是否需要更新路由规则
$ret = self::RouteSeparatorHandle($params);
2018-12-31 11:07:03 +00:00
if($ret['code'] != 0)
{
return $ret;
}
2025-04-25 12:21:19 +00:00
// 浏览器图标
$ret = self::SiteTitleIconHandle($params);
if($ret['code'] != 0)
{
return $ret;
}
2024-04-15 02:25:01 +00:00
// 站点默认首页配置
$ret = self::SiteDefaultIndexHandle($params);
if($ret['code'] != 0)
{
return $ret;
}
2023-01-19 09:44:03 +00:00
return DataReturn(MyLang('operate_success').'['.$success.']');
2018-12-28 10:58:37 +00:00
}
2023-01-19 09:44:03 +00:00
return DataReturn(MyLang('operate_fail'), -100);
2018-12-28 10:58:37 +00:00
}
/**
* 系统配置信息初始化
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-01-03T21:36:55+0800
* @param [int] $status [是否更新数据,0,1]
*/
public static function ConfigInit($status = 0)
2018-12-28 10:58:37 +00:00
{
2022-04-21 14:08:53 +00:00
$key = SystemService::CacheKey('shopxo.cache_common_my_config_key');
2021-07-18 15:42:10 +00:00
$data = MyCache($key);
2024-10-21 02:51:14 +00:00
if($data === null || $status == 1 || MyEnv('app_debug') || MyInput('lang') || MyFileConfig('common_data_is_use_cache') != 1)
2018-12-28 10:58:37 +00:00
{
2024-12-25 09:35:54 +00:00
static $is_init_config_data = false;
if($status == 1 || $is_init_config_data === false)
2018-12-28 10:58:37 +00:00
{
2024-12-25 09:35:54 +00:00
// 所有配置
$data = Db::name('Config')->column('value', 'only_tag');
if(!empty($data))
2019-05-17 09:47:47 +00:00
{
2024-12-25 09:35:54 +00:00
// 数据处理
// 字符串转数组
foreach(self::$string_to_array_field_list as $fv)
2021-07-23 07:58:46 +00:00
{
2024-12-25 09:35:54 +00:00
if(isset($data[$fv]))
{
$data[$fv] = ($data[$fv] == '') ? [] : explode(',', $data[$fv]);
}
2021-07-23 07:58:46 +00:00
}
2019-05-16 10:42:22 +00:00
2024-12-25 09:35:54 +00:00
// json数据数组
foreach(self::$data_json_array_field_list as $fv)
{
2024-12-25 09:35:54 +00:00
if(isset($data[$fv]))
{
$data[$fv] = empty($data[$fv]) ? [] : json_decode($data[$fv], true);
}
}
2024-12-25 09:35:54 +00:00
// 单附件字段
foreach(self::$attachment_field_list as $fv)
2024-01-19 06:49:32 +00:00
{
2024-12-25 09:35:54 +00:00
if(!empty($data[$fv]))
{
$data[$fv] = ResourcesService::AttachmentPathViewHandle($data[$fv]);
}
2024-01-19 06:49:32 +00:00
}
2024-12-25 09:35:54 +00:00
// 数组附件字段
foreach(self::$data_array_attachment_field_list as $fk=>$fv)
2023-09-17 14:54:33 +00:00
{
2024-12-25 09:35:54 +00:00
if(!empty($data[$fk]) && is_array($data[$fk]))
2023-09-17 14:54:33 +00:00
{
2024-12-25 09:35:54 +00:00
foreach($data[$fk] as $fkk=>$fvv)
2023-09-17 14:54:33 +00:00
{
2024-12-25 09:35:54 +00:00
if(!empty($fvv[$fv]))
{
$data[$fk][$fkk][$fv] = ResourcesService::AttachmentPathViewHandle($fvv[$fv]);
}
2023-09-17 14:54:33 +00:00
}
}
}
2024-12-25 09:35:54 +00:00
// 数据处理
foreach($data as $k=>&$v)
2021-07-25 02:52:27 +00:00
{
2024-12-25 09:35:54 +00:00
// 不参与缓存的配置
if(in_array($k, self::$not_cache_field_list))
{
unset($data[$k]);
continue;
}
2021-07-25 02:52:27 +00:00
2024-12-25 09:35:54 +00:00
// 富文本字段处理
if(in_array($k, self::$rich_text_list))
{
$v = ResourcesService::ContentStaticReplace($v, 'get');
}
2020-09-14 10:53:42 +00:00
2024-12-25 09:35:54 +00:00
// 数据文件缓存
if(in_array($k, self::$file_cache_keys))
{
MyFileConfig($k, $v);
}
2021-07-23 07:58:46 +00:00
}
2024-12-25 09:35:54 +00:00
} else {
$data = [];
}
2019-05-16 10:42:22 +00:00
2024-12-25 09:35:54 +00:00
// 所有配置缓存集合
MyCache($key, $data);
// 已初始化状态
$is_init_config_data = true;
}
2018-12-28 10:58:37 +00:00
}
2024-10-21 02:51:14 +00:00
return $data;
2018-12-28 10:58:37 +00:00
}
2018-12-31 11:07:03 +00:00
2024-04-15 02:25:01 +00:00
/**
* 站点默认首页配置
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2024-02-03
* @desc description
* @param [array] $params [输入参数]
*/
public static function SiteDefaultIndexHandle($params = [])
{
if(array_key_exists('common_site_default_index', $params))
{
// 默认首页配置
$dir = APP_PATH.'index'.DS.'config';
$home_file = $dir.DS.'home.php';
// 是否有权限操作文件
if(file_exists($home_file))
{
if(!is_writable($home_file))
{
return DataReturn(MyLang('common_service.config.default_index_config_file_no_power_tips').'['.$home_file.']', -1);
}
} else {
if(!is_writable($dir))
{
return DataReturn(MyLang('common_service.config.default_index_config_dir_no_power_tips').'['.$dir.']', -1);
}
}
// 是否设置默认首页
if(empty($params['common_site_default_index']))
{
if(file_exists($home_file))
{
if(!\base\FileUtil::UnlinkFile($home_file))
{
return DataReturn(MyLang('common_service.config.default_index_deploy_fail').'['.$home_file.']', -1);
}
}
} else {
$arr = explode('|', $params['common_site_default_index']);
if(count($arr) == 2)
{
// get s参数值
$value = '';
switch($arr[0])
{
// 插件
case 'plugins' :
$value = 'plugins/index/pluginsname/'.$arr[1].'/pluginscontrol/index/pluginsaction/index';
break;
// 页面设计
case 'design' :
$value = 'design/index/id/'.$arr[1];
break;
// 自定义页面
case 'custom_view' :
$value = 'customview/index/id/'.$arr[1];
break;
}
// 站点默认首页处理值钩子
$hook_name = 'plugins_service_config_site_default_index_value';
MyEventTrigger($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => true,
'value' => &$value,
]);
// 空则错误提示
if(empty($value))
{
return DataReturn(MyLang('common_service.config.default_index_type_not_undefined').'['.$arr[0].']', -1);
}
// 生成域名配置文件
$ret = @file_put_contents($home_file, "<?php
// +----------------------------------------------------------------------
// | ShopXO 国内领先企业级B2C免费开源电商系统
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( https://opensource.org/licenses/mit-license.php )
// +----------------------------------------------------------------------
// | Author: Devil
// +----------------------------------------------------------------------
// 默认首页配置文件\nreturn '".$value."';\n?>");
if($ret === false)
{
return DataReturn(MyLang('common_service.config.default_index_deploy_fail').'['.$home_file.']', -1);
}
}
}
}
return DataReturn(MyLang('handle_noneed'), 0);
}
2025-04-25 12:21:19 +00:00
/**
* 浏览器图标处理
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-01-02T23:08:19+0800
* @param [array] $params [输入参数]
*/
public static function SiteTitleIconHandle($params = [])
{
if(!empty($params['home_site_title_icon']))
{
$file = RequestGet($params['home_site_title_icon']);
if(!empty($file))
{
$ico_file = ROOT.'public'.DS.'favicon.ico';
if(!is_writable($ico_file))
{
return DataReturn(MyLang('common_service.config.site_title_icon_power_tips').'['.$ico_file.']', -1);
}
if(file_put_contents($ico_file, $file) === false)
{
return DataReturn(MyLang('common_service.config.site_title_icon_fail_tips').'['.$ico_file.']', -1);
}
return DataReturn(MyLang('handle_success'), 0);
}
}
return DataReturn(MyLang('handle_noneed'), 0);
}
2018-12-31 11:07:03 +00:00
/**
* 路由规则处理
* @author Devil
* @blog http://gong.gg/
* @version 0.0.1
* @datetime 2017-01-02T23:08:19+0800
* @param [array] $params [输入参数]
*/
public static function RouteSeparatorHandle($params = [])
2018-12-31 11:07:03 +00:00
{
2024-04-15 02:25:01 +00:00
if(array_key_exists('home_seo_url_model', $params))
2018-12-31 11:07:03 +00:00
{
2024-12-29 10:30:21 +00:00
// 模块组
$route_arr = ['admin', 'index', 'api'];
2018-12-31 11:07:03 +00:00
2021-07-22 03:41:57 +00:00
// 后端+前端都生成对应的路由定义规则、为了后台进入前端url保持一致
foreach($route_arr as $module)
2018-12-31 11:07:03 +00:00
{
2021-07-22 03:41:57 +00:00
// 文件目录
if(!is_writable(APP_PATH.$module.DS.'route'))
2018-12-31 11:07:03 +00:00
{
2023-02-08 13:20:04 +00:00
return DataReturn(MyLang('common_service.config.route_dir_no_power_tips').'[./app/'.$module.'/route]', -11);
2018-12-31 11:07:03 +00:00
}
2021-07-22 03:41:57 +00:00
// 路配置文件权限
2023-02-08 13:20:04 +00:00
$route_file_php = APP_PATH.$module.DS.'route'.DS.'route.php';
2021-07-22 03:41:57 +00:00
if(file_exists($route_file_php) && !is_writable($route_file_php))
2018-12-31 11:07:03 +00:00
{
2023-02-08 13:20:04 +00:00
return DataReturn(MyLang('common_service.config.route_file_no_power_tips').'[./app/'.$module.'/route/route.php]', -11);
2018-12-31 11:07:03 +00:00
}
2021-07-22 03:41:57 +00:00
// pathinfo+短地址模式
if($params['home_seo_url_model'] == 2)
2018-12-31 11:07:03 +00:00
{
2024-12-29 10:30:21 +00:00
// 伪静态规则配置文件
$route_file = APP_PATH.'route'.DS.'route.config';
$module_route_file = APP_PATH.$module.DS.'route'.DS.'route.config';
if(file_exists($module_route_file))
{
$route_file = $module_route_file;
}
2021-07-22 03:41:57 +00:00
if(!file_exists($route_file))
{
2023-02-08 13:20:04 +00:00
return DataReturn(MyLang('common_service.config.route_file_config_no_exist_tips').'[./app/route/route.config]', -14);
2021-07-22 03:41:57 +00:00
}
// 开始生成规则文件
if(file_put_contents($route_file_php, file_get_contents($route_file)) === false)
{
2023-02-08 13:20:04 +00:00
return DataReturn(MyLang('common_service.config.route_file_create_fail_tips'), -10);
2021-07-22 03:41:57 +00:00
}
// 兼容模式+pathinfo模式
} else {
if(file_exists($route_file_php) && @unlink($route_file_php) === false)
{
2023-02-08 13:20:04 +00:00
return DataReturn(MyLang('common_service.config.route_file_handle_fail_tips'), -10);
2021-07-22 03:41:57 +00:00
}
2018-12-31 11:07:03 +00:00
}
}
2023-01-19 09:44:03 +00:00
return DataReturn(MyLang('handle_success'), 0);
2018-12-31 11:07:03 +00:00
}
2023-01-19 09:44:03 +00:00
return DataReturn(MyLang('handle_noneed'), 0);
2018-12-31 11:07:03 +00:00
}
2019-05-16 10:42:22 +00:00
/**
* 根据唯一标记获取条配置内容
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-05-16
* @desc description
2020-09-14 10:53:42 +00:00
* @param [string] $key [唯一标记]
2019-05-16 10:42:22 +00:00
*/
2020-09-14 10:53:42 +00:00
public static function ConfigContentRow($key)
2019-05-16 10:42:22 +00:00
{
2021-07-25 02:52:27 +00:00
$cache_key = $key.'_row_data';
$data = MyCache($cache_key);
2021-07-23 07:58:46 +00:00
if($data === null)
2019-05-16 10:42:22 +00:00
{
2020-09-14 10:53:42 +00:00
$data = Db::name('Config')->where(['only_tag'=>$key])->field('name,value,type,upd_time')->find();
2019-05-20 10:35:28 +00:00
if(!empty($data))
2019-05-16 10:42:22 +00:00
{
2019-05-20 10:35:28 +00:00
// 富文本处理
2020-09-14 10:53:42 +00:00
if(in_array($key, self::$rich_text_list))
2019-05-20 10:35:28 +00:00
{
$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']);
2021-07-23 07:58:46 +00:00
} else {
$data = [];
2019-05-16 10:42:22 +00:00
}
2021-07-25 02:52:27 +00:00
MyCache($cache_key, $data);
2019-05-16 10:42:22 +00:00
}
2023-01-19 09:44:03 +00:00
return DataReturn(MyLang('operate_success'), 0, $data);
2019-05-16 10:42:22 +00:00
}
2019-11-13 12:51:43 +00:00
/**
* 站点自提模式 - 自提地址列表
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-11-13
* @desc description
2021-03-14 15:03:31 +00:00
* @param [string] $value [自提的配置数据]
* @param [array] $params [输入参数]
2019-11-13 12:51:43 +00:00
*/
2021-03-14 15:03:31 +00:00
public static function SiteTypeExtractionAddressList($value = null, $params = [])
2019-11-13 12:51:43 +00:00
{
// 未指定内容则从缓存读取
if(empty($value))
{
$value = MyC('common_self_extraction_address');
}
// 数据处理
$data = [];
if(!empty($value) && is_string($value))
{
$temp_data = json_decode($value, true);
if(!empty($temp_data) && is_array($temp_data))
{
$data = $temp_data;
}
}
2021-03-06 15:49:19 +00:00
if(!empty($data))
{
foreach($data as &$v)
{
2021-03-14 15:03:31 +00:00
if(array_key_exists('logo', $v))
{
$v['logo'] = ResourcesService::AttachmentPathViewHandle($v['logo']);
}
2021-03-06 15:49:19 +00:00
}
}
2019-11-19 13:46:22 +00:00
2020-01-29 13:12:15 +00:00
// 自提点地址列表数据钩子
$hook_name = 'plugins_service_site_extraction_address_list';
2021-07-18 15:42:10 +00:00
MyEventTrigger($hook_name, [
2020-01-29 13:12:15 +00:00
'hook_name' => $hook_name,
'is_backend' => true,
'data' => &$data,
]);
2021-03-14 15:03:31 +00:00
// 数据距离处理
2024-01-19 06:49:32 +00:00
if(!empty($data) && is_array($data) && !empty($params))
2021-03-14 15:03:31 +00:00
{
2024-01-19 06:49:32 +00:00
$lng = empty($params['lng']) ? (empty($params['user_lng']) ? '' : $params['user_lng']) : $params['lng'];
$lat = empty($params['lat']) ? (empty($params['user_lat']) ? '' : $params['user_lat']) : $params['lat'];
if(!empty($lng) && !empty($lat))
2021-03-14 15:03:31 +00:00
{
2024-01-19 06:49:32 +00:00
$unit = 'km';
foreach($data as &$v)
2021-03-14 15:03:31 +00:00
{
2024-01-19 06:49:32 +00:00
if(!empty($v) && is_array($v))
{
// 计算距离
$v['distance_value'] = \base\GeoTransUtil::GetDistance($v['lng'], $v['lat'], $lng, $lat, 2);
$v['distance_unit'] = $unit;
}
2021-03-14 15:03:31 +00:00
}
2024-01-19 06:49:32 +00:00
// 根据距离排序
if(count($data) > 1 && array_sum(array_column($data, 'distance_value')) > 0)
{
$data = ArrayQuickSort($data, 'distance_value');
}
2021-03-14 15:03:31 +00:00
}
}
2023-01-19 09:44:03 +00:00
return DataReturn(MyLang('operate_success'), 0, $data);
2019-11-13 12:51:43 +00:00
}
2019-11-19 13:46:22 +00:00
/**
2019-11-25 13:08:55 +00:00
* 站点虚拟模式 - 虚拟销售信息
2019-11-19 13:46:22 +00:00
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2019-11-19
* @desc description
* @param [array] $params [输入参数]
*/
public static function SiteFictitiousConfig($params = [])
{
// 标题
$title = MyC('common_site_fictitious_return_title', '密钥信息', true);
// 提示信息
2019-11-20 10:35:38 +00:00
$tips = MyC('common_site_fictitious_return_tips', null, true);
2019-11-19 13:46:22 +00:00
2024-04-25 06:47:59 +00:00
// 返回数据
2019-11-19 13:46:22 +00:00
$result = [
2024-04-25 06:47:59 +00:00
'title' => $title,
'tips' => empty($tips) ? '' : str_replace("\n", '<br />', $tips),
2019-11-19 13:46:22 +00:00
];
2023-01-19 09:44:03 +00:00
return DataReturn(MyLang('operate_success'), 0, $result);
2019-11-19 13:46:22 +00:00
}
/**
* 字段空值数据处理
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2022-04-10
* @desc description
* @param [array] $params [输入参数]
* @param [array] $fields [字段列表]
* @return [array] [处理的数据]
*/
public static function FieldsEmptyDataHandle($params, $fields)
{
if(!empty($fields))
{
foreach($fields as $fv)
{
if(!isset($params[$fv]))
{
$params[$fv] = '';
}
}
}
return $params;
}
2024-01-19 06:49:32 +00:00
/**
* 短信模板配置
* @author Devil
* @blog http://gong.gg/
* @version 1.0.0
* @date 2023-11-18
* @desc description
* @param [string] $key [模板key]
*/
public static function SmsTemplateValue($key)
{
// 读取短信配置信息
$value = MyC($key);
// 短信配置读取钩子
$hook_name = 'plugins_service_config_sms_template_value';
MyEventTrigger($hook_name,
[
'hook_name' => $hook_name,
'is_backend' => true,
'key' => $key,
'value' => &$value,
]);
return $value;
}
2018-12-28 10:58:37 +00:00
}
?>