2019-02-09 09:15:23 +08:00
|
|
|
<?php
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | ShopXO 国内领先企业级B2C免费开源电商系统
|
|
|
|
// +----------------------------------------------------------------------
|
2021-03-16 10:34:52 +08:00
|
|
|
// | Copyright (c) 2011~2099 http://shopxo.net All rights reserved.
|
2019-02-09 09:15:23 +08:00
|
|
|
// +----------------------------------------------------------------------
|
2021-03-16 10:34:52 +08:00
|
|
|
// | Licensed ( https://opensource.org/licenses/mit-license.php )
|
2019-02-09 09:15:23 +08:00
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
// | Author: Devil
|
|
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service;
|
|
|
|
|
2021-07-18 23:42:10 +08:00
|
|
|
use think\facade\Db;
|
2019-02-09 09:15:23 +08:00
|
|
|
use app\service\ResourcesService;
|
2021-01-06 19:50:37 +08:00
|
|
|
use app\service\PluginsAdminService;
|
2021-04-20 18:38:23 +08:00
|
|
|
use app\service\StoreService;
|
2019-02-09 09:15:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用服务层
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 0.0.1
|
|
|
|
* @datetime 2016-12-01T21:51:08+0800
|
|
|
|
*/
|
|
|
|
class PluginsService
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 根据应用标记获取数据
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-09-29
|
|
|
|
* @desc description
|
2019-02-28 17:27:24 +08:00
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
* @param [array] $attachment_field [附件字段]
|
2019-04-18 16:12:43 +08:00
|
|
|
* @param [boolean] $is_cache [是否缓存读取, 默认true]
|
2019-02-09 09:15:23 +08:00
|
|
|
*/
|
2019-04-18 16:12:43 +08:00
|
|
|
public static function PluginsData($plugins, $attachment_field = [], $is_cache = true)
|
2019-02-09 09:15:23 +08:00
|
|
|
{
|
2019-03-30 01:40:34 +08:00
|
|
|
// 从缓存获取数据
|
2020-12-23 20:15:48 +08:00
|
|
|
$data = ($is_cache === true) ? self::PluginsCacheData($plugins) : [];
|
2019-10-16 20:45:41 +08:00
|
|
|
|
|
|
|
// 数据不存在则从数据库读取
|
2021-07-23 15:58:46 +08:00
|
|
|
if($data === null)
|
2019-02-09 09:15:23 +08:00
|
|
|
{
|
2019-03-30 01:40:34 +08:00
|
|
|
// 获取数据
|
2019-10-17 14:06:52 +08:00
|
|
|
$ret = self::PluginsField($plugins, 'data');
|
|
|
|
if(!empty($ret['data']))
|
2019-02-12 17:36:47 +08:00
|
|
|
{
|
2021-01-06 19:50:37 +08:00
|
|
|
// 数据处理
|
|
|
|
$data = self::PluginsDataHandle($ret['data'], $attachment_field);
|
2021-07-23 15:58:46 +08:00
|
|
|
} else {
|
|
|
|
$data = [];
|
2021-01-06 19:50:37 +08:00
|
|
|
}
|
2021-07-23 15:58:46 +08:00
|
|
|
|
|
|
|
// 存储缓存
|
|
|
|
self::PluginsCacheStorage($plugins, $data);
|
2021-01-06 19:50:37 +08:00
|
|
|
}
|
2021-07-23 15:58:46 +08:00
|
|
|
return DataReturn('处理成功', 0, $data);
|
2021-01-06 19:50:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-07-23 15:58:46 +08:00
|
|
|
* 插件配置数据处理
|
2021-01-06 19:50:37 +08:00
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-01-06
|
|
|
|
* @desc description
|
|
|
|
* @param [array|json] $data [应用配置数据]
|
|
|
|
* @param [array] $attachment_field [附件字段]
|
|
|
|
*/
|
|
|
|
public static function PluginsDataHandle($data, $attachment_field = [])
|
|
|
|
{
|
|
|
|
// 有数据并且非数组则解析json
|
|
|
|
if(!empty($data) && !is_array($data))
|
|
|
|
{
|
|
|
|
$data = json_decode($data, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 处理配置数据
|
|
|
|
if(!empty($data) && is_array($data))
|
|
|
|
{
|
|
|
|
// 是否有自定义附件需要处理
|
|
|
|
if(!empty($attachment_field) && is_array($attachment_field))
|
|
|
|
{
|
|
|
|
foreach($attachment_field as $field)
|
2019-02-12 17:36:47 +08:00
|
|
|
{
|
2021-01-06 19:50:37 +08:00
|
|
|
if(isset($data[$field]))
|
2019-02-12 17:36:47 +08:00
|
|
|
{
|
2021-01-06 19:50:37 +08:00
|
|
|
$data[$field.'_old'] = $data[$field];
|
|
|
|
$data[$field] = ResourcesService::AttachmentPathViewHandle($data[$field]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 所有附件后缀名称
|
2021-07-18 23:42:10 +08:00
|
|
|
$attachment_ext = MyConfig('ueditor.fileManagerAllowFiles');
|
2019-10-16 20:45:41 +08:00
|
|
|
|
2021-01-06 19:50:37 +08:00
|
|
|
// 未自定义附件则自动根据内容判断处理附件,建议自定义附件字段名称处理更高效
|
|
|
|
if(!empty($attachment_ext) && is_array($attachment_ext))
|
|
|
|
{
|
|
|
|
foreach($data as $k=>$v)
|
|
|
|
{
|
|
|
|
if(!empty($v) && !is_array($v) && !is_object($v))
|
2019-10-16 20:45:41 +08:00
|
|
|
{
|
2021-01-06 19:50:37 +08:00
|
|
|
$ext = strrchr(substr($v, -6), '.');
|
|
|
|
if($ext !== false)
|
2019-10-16 20:45:41 +08:00
|
|
|
{
|
2021-01-06 19:50:37 +08:00
|
|
|
if(in_array($ext, $attachment_ext))
|
2019-10-16 20:45:41 +08:00
|
|
|
{
|
2021-01-06 19:50:37 +08:00
|
|
|
$data[$k.'_old'] = $v;
|
|
|
|
$data[$k] = ResourcesService::AttachmentPathViewHandle($v);
|
2019-10-16 20:45:41 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 17:36:47 +08:00
|
|
|
}
|
|
|
|
}
|
2019-02-09 09:15:23 +08:00
|
|
|
}
|
2021-07-23 15:58:46 +08:00
|
|
|
return empty($data) ? [] : $data;
|
2019-02-09 09:15:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用数据保存
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-09-29
|
|
|
|
* @desc description
|
2019-02-28 17:27:24 +08:00
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
* @param [array] $attachment_field [附件字段]
|
2019-02-09 09:15:23 +08:00
|
|
|
*/
|
2019-02-28 17:27:24 +08:00
|
|
|
public static function PluginsDataSave($params = [], $attachment_field = [])
|
2019-02-09 09:15:23 +08:00
|
|
|
{
|
|
|
|
// 请求参数
|
|
|
|
$p = [
|
|
|
|
[
|
|
|
|
'checked_type' => 'empty',
|
|
|
|
'key_name' => 'plugins',
|
|
|
|
'error_msg' => '应用标记不能为空',
|
|
|
|
],
|
|
|
|
[
|
|
|
|
'checked_type' => 'isset',
|
|
|
|
'key_name' => 'data',
|
|
|
|
'error_msg' => '数据参数不能为空',
|
|
|
|
],
|
|
|
|
];
|
|
|
|
$ret = ParamsChecked($params, $p);
|
|
|
|
if($ret !== true)
|
|
|
|
{
|
|
|
|
return DataReturn($ret, -1);
|
|
|
|
}
|
|
|
|
|
2019-02-28 17:27:24 +08:00
|
|
|
// 附件处理
|
|
|
|
$attachment = ResourcesService::AttachmentParams($params['data'], $attachment_field);
|
|
|
|
if($attachment['code'] != 0)
|
|
|
|
{
|
|
|
|
return $attachment;
|
|
|
|
}
|
|
|
|
if(!empty($attachment['data']))
|
|
|
|
{
|
|
|
|
foreach($attachment['data'] as $field=>$value)
|
|
|
|
{
|
|
|
|
$params['data'][$field] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-10-16 20:45:41 +08:00
|
|
|
// 移除多余的字段
|
|
|
|
unset($params['data']['pluginsname'], $params['data']['pluginscontrol'], $params['data']['pluginsaction']);
|
|
|
|
|
2019-02-09 09:15:23 +08:00
|
|
|
// 数据更新
|
|
|
|
if(Db::name('Plugins')->where(['plugins'=>$params['plugins']])->update(['data'=>json_encode($params['data']), 'upd_time'=>time()]))
|
|
|
|
{
|
2019-03-30 01:40:34 +08:00
|
|
|
// 删除缓存
|
2020-12-23 20:15:48 +08:00
|
|
|
self::PluginsCacheDelete($params['plugins']);
|
2019-03-30 01:40:34 +08:00
|
|
|
|
2019-02-09 09:15:23 +08:00
|
|
|
return DataReturn('操作成功');
|
|
|
|
}
|
|
|
|
return DataReturn('操作失败', -100);
|
|
|
|
}
|
2019-05-27 00:58:59 +08:00
|
|
|
|
2020-12-23 20:15:48 +08:00
|
|
|
/**
|
|
|
|
* 应用缓存c存储
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-12-23
|
|
|
|
* @desc description
|
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
* @param [mixed] $data [应用数据]
|
|
|
|
*/
|
|
|
|
public static function PluginsCacheStorage($plugins, $data)
|
|
|
|
{
|
2021-07-18 23:42:10 +08:00
|
|
|
return MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins, $data);
|
2020-12-23 20:15:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用缓存获取
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-12-23
|
|
|
|
* @desc description
|
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
*/
|
|
|
|
public static function PluginsCacheData($plugins)
|
|
|
|
{
|
2021-07-18 23:42:10 +08:00
|
|
|
$data = MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins);
|
2020-12-23 20:15:48 +08:00
|
|
|
return empty($data) ? '' : $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用缓存删除
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-12-23
|
|
|
|
* @desc description
|
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
*/
|
|
|
|
public static function PluginsCacheDelete($plugins)
|
|
|
|
{
|
2021-07-18 23:42:10 +08:00
|
|
|
MyCache(MyConfig('shopxo.cache_plugins_data_key').$plugins, null);
|
2020-12-23 20:15:48 +08:00
|
|
|
}
|
|
|
|
|
2019-05-27 00:58:59 +08:00
|
|
|
/**
|
|
|
|
* 根据应用标记获取指定字段数据
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2018-09-29
|
|
|
|
* @desc description
|
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
* @param [string] $field [字段名称]
|
2019-08-18 00:01:57 +08:00
|
|
|
* @return [mixed] [不存在返回null, 则原始数据]
|
2019-05-27 00:58:59 +08:00
|
|
|
*/
|
|
|
|
public static function PluginsField($plugins, $field)
|
|
|
|
{
|
|
|
|
$data = Db::name('Plugins')->where(['plugins'=>$plugins])->value($field);
|
|
|
|
return DataReturn('操作成功', 0, $data);
|
|
|
|
}
|
2019-10-17 14:06:52 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用状态
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2019-10-17
|
|
|
|
* @desc description
|
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
*/
|
|
|
|
public static function PluginsStatus($plugins)
|
|
|
|
{
|
|
|
|
$ret = self::PluginsField($plugins, 'is_enable');
|
|
|
|
return $ret['data'];
|
|
|
|
}
|
2020-01-02 21:21:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用校验
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-01-02
|
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
*/
|
|
|
|
public static function PluginsCheck($plugins)
|
|
|
|
{
|
|
|
|
$ret = self::PluginsStatus($plugins);
|
|
|
|
if($ret === null)
|
|
|
|
{
|
2021-07-21 15:15:46 +08:00
|
|
|
// 不存在的插件则进入首页
|
|
|
|
$config = PluginsAdminService::GetPluginsConfig($plugins);
|
|
|
|
if(empty($config))
|
|
|
|
{
|
|
|
|
if(IS_AJAX)
|
|
|
|
{
|
|
|
|
return DataReturn('地址有误['.$plugins.']', -10);
|
|
|
|
}
|
|
|
|
MyRedirect(__MY_URL__, true);
|
|
|
|
}
|
2020-01-02 21:21:40 +08:00
|
|
|
return DataReturn('应用未安装['.$plugins.']', -10);
|
|
|
|
}
|
|
|
|
if($ret != 1)
|
|
|
|
{
|
2021-07-21 15:15:46 +08:00
|
|
|
return DataReturn('应用未启用['.$plugins.']', -11);
|
2020-01-02 21:21:40 +08:00
|
|
|
}
|
|
|
|
return DataReturn('验证成功', 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 应用控制器调用
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-01-02
|
2021-01-05 21:38:10 +08:00
|
|
|
* @param [string] $plugins [应用标记]
|
|
|
|
* @param [string] $control [应用控制器]
|
|
|
|
* @param [string] $action [应用方法]
|
|
|
|
* @param [string] $group [应用组(admin, index, api)]
|
|
|
|
* @param [array] $params [输入参数]
|
2020-01-02 21:21:40 +08:00
|
|
|
*/
|
2021-01-06 19:50:37 +08:00
|
|
|
public static function PluginsControlCall($plugins, $control, $action, $group = 'index', $params = [])
|
2020-01-02 21:21:40 +08:00
|
|
|
{
|
|
|
|
// 应用校验
|
|
|
|
$ret = self::PluginsCheck($plugins);
|
|
|
|
if($ret['code'] != 0)
|
|
|
|
{
|
|
|
|
return $ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// 应用控制器
|
|
|
|
$control = ucfirst($control);
|
2021-04-20 18:38:23 +08:00
|
|
|
$plugins_class = '\app\plugins\\'.$plugins.'\\'.$group.'\\'.$control;
|
|
|
|
if(!class_exists($plugins_class))
|
2020-01-02 21:21:40 +08:00
|
|
|
{
|
|
|
|
return DataReturn('应用控制器未定义['.$control.']', -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 调用方法
|
|
|
|
$action = ucfirst($action);
|
2021-04-20 18:38:23 +08:00
|
|
|
$obj = new $plugins_class($params);
|
2020-01-02 21:21:40 +08:00
|
|
|
if(!method_exists($obj, $action))
|
|
|
|
{
|
|
|
|
return DataReturn('应用方法未定义['.$action.']', -1);
|
|
|
|
}
|
2020-06-11 18:48:31 +08:00
|
|
|
|
|
|
|
// 调用方法仅传递请求参数
|
2021-02-18 21:59:49 +08:00
|
|
|
if(!empty($params) && isset($params['data_request']))
|
|
|
|
{
|
|
|
|
$params = $params['data_request'];
|
|
|
|
}
|
2021-04-20 18:38:23 +08:00
|
|
|
|
|
|
|
// 安全判断
|
2021-07-18 23:42:10 +08:00
|
|
|
if(MyConfig('shopxo.is_develop') === false && RequestModule() == 'admin')
|
2021-04-20 18:38:23 +08:00
|
|
|
{
|
|
|
|
$key = 'plugins_legal_check_'.$plugins;
|
2021-07-18 23:42:10 +08:00
|
|
|
$ret = MyCache($key);
|
2021-04-24 13:02:01 +08:00
|
|
|
if(empty($ret))
|
2021-04-20 18:38:23 +08:00
|
|
|
{
|
|
|
|
$config = PluginsAdminService::GetPluginsConfig($plugins);
|
2021-04-23 16:43:23 +08:00
|
|
|
if(empty($config) || empty($config['base']))
|
2021-04-20 18:38:23 +08:00
|
|
|
{
|
2021-04-23 16:43:23 +08:00
|
|
|
return DataReturn('应用插件配置信息有误', -1);
|
2021-04-20 18:38:23 +08:00
|
|
|
}
|
2021-04-23 16:43:23 +08:00
|
|
|
|
2021-04-20 18:38:23 +08:00
|
|
|
$check_params = [
|
2021-04-23 16:43:23 +08:00
|
|
|
'type' => 'plugins',
|
2021-04-20 18:38:23 +08:00
|
|
|
'config' => $config,
|
|
|
|
'plugins' => $plugins,
|
2021-04-23 16:43:23 +08:00
|
|
|
'author' => $config['base']['author'],
|
|
|
|
'ver' => $config['base']['version'],
|
2021-04-20 18:38:23 +08:00
|
|
|
];
|
|
|
|
$ret = StoreService::PluginsLegalCheck($check_params);
|
2021-07-18 23:42:10 +08:00
|
|
|
MyCache($key, $ret, 3600);
|
2021-04-24 13:02:01 +08:00
|
|
|
}
|
|
|
|
if($ret['code'] != 0)
|
|
|
|
{
|
|
|
|
return $ret;
|
2021-04-20 18:38:23 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 调用对应插件
|
2021-02-18 21:59:49 +08:00
|
|
|
return DataReturn('调用成功', 0, $obj->$action($params));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-02-18 22:30:01 +08:00
|
|
|
* 应用回调事件调用
|
2021-02-18 21:59:49 +08:00
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2020-01-02
|
|
|
|
* @param [string] $plugins [应用标记]
|
2021-04-23 16:43:23 +08:00
|
|
|
* @param [string] $action [事件方法(Upload 上传, Install 安装, Uninstall 卸载, Download 下载, Upgrade 更新, Delete 删除)]
|
2021-02-18 21:59:49 +08:00
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
public static function PluginsEventCall($plugins, $action, $params = [])
|
|
|
|
{
|
|
|
|
// 应用事件
|
|
|
|
$plugins = '\app\plugins\\'.$plugins.'\\Event';
|
|
|
|
if(!class_exists($plugins))
|
|
|
|
{
|
|
|
|
return DataReturn('应用事件未定义['.$plugins.']', -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 调用方法
|
|
|
|
$action = ucfirst($action);
|
|
|
|
$obj = new $plugins($params);
|
|
|
|
if(!method_exists($obj, $action))
|
|
|
|
{
|
|
|
|
return DataReturn('应用事件方法未定义['.$action.']', -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 调用方法仅传递请求参数
|
|
|
|
if(!empty($params) && isset($params['data_request']))
|
2020-06-11 18:48:31 +08:00
|
|
|
{
|
|
|
|
$params = $params['data_request'];
|
|
|
|
}
|
2021-01-05 21:38:10 +08:00
|
|
|
return DataReturn('调用成功', 0, $obj->$action($params));
|
2020-01-02 21:21:40 +08:00
|
|
|
}
|
2021-01-06 19:50:37 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 所有有效插件配置列表
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-01-06
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数]
|
|
|
|
*/
|
|
|
|
public static function PluginsBaseList($params = [])
|
|
|
|
{
|
2021-07-18 23:42:10 +08:00
|
|
|
$data = Db::name('Plugins')->where(['is_enable'=>1])->order(PluginsAdminService::$plugins_order_by)->field('id,plugins,data')->select()->toArray();
|
2021-01-06 19:50:37 +08:00
|
|
|
if(!empty($data))
|
|
|
|
{
|
|
|
|
foreach($data as &$v)
|
|
|
|
{
|
|
|
|
$v['data'] = self::PluginsDataHandle($v['data']);
|
|
|
|
}
|
|
|
|
} else {
|
2021-07-23 15:58:46 +08:00
|
|
|
$data = [];
|
2021-01-06 19:50:37 +08:00
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
2021-04-23 16:43:23 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 插件更新信息
|
|
|
|
* @author Devil
|
|
|
|
* @blog http://gong.gg/
|
|
|
|
* @version 1.0.0
|
|
|
|
* @date 2021-04-21
|
|
|
|
* @desc description
|
|
|
|
* @param [array] $params [输入参数、插件信息]
|
|
|
|
*/
|
|
|
|
public static function PluginsUpgradeInfo($params = [])
|
|
|
|
{
|
2021-06-06 23:59:30 +08:00
|
|
|
// 默认返回数据
|
|
|
|
$result = DataReturn('无插件数据', 0);
|
|
|
|
|
|
|
|
// 缓存记录
|
|
|
|
$time = 3600;
|
|
|
|
$key = 'plugins_upgrade_check_info';
|
2021-07-18 23:42:10 +08:00
|
|
|
$res = MyCache($key);
|
2021-06-06 23:59:30 +08:00
|
|
|
if(empty($res))
|
2021-04-23 16:43:23 +08:00
|
|
|
{
|
2021-06-06 23:59:30 +08:00
|
|
|
if(!empty($params) && !empty($params['db_data']) && is_array($params['db_data']))
|
2021-04-23 16:43:23 +08:00
|
|
|
{
|
2021-06-06 23:59:30 +08:00
|
|
|
// 数据组装
|
|
|
|
$data = [];
|
|
|
|
foreach($params['db_data'] as $v)
|
2021-04-23 16:43:23 +08:00
|
|
|
{
|
2021-06-06 23:59:30 +08:00
|
|
|
if(!empty($v['name']) && !empty($v['version']) && !empty($v['plugins']) && !empty($v['author']))
|
|
|
|
{
|
|
|
|
$data[] = [
|
|
|
|
'plugins' => $v['plugins'],
|
|
|
|
'name' => $v['name'],
|
|
|
|
'ver' => $v['version'],
|
|
|
|
'author' => $v['author'],
|
|
|
|
];
|
|
|
|
}
|
2021-04-23 16:43:23 +08:00
|
|
|
}
|
2021-06-06 23:59:30 +08:00
|
|
|
|
2021-04-23 16:43:23 +08:00
|
|
|
// 获取更新信息
|
2021-06-06 23:59:30 +08:00
|
|
|
if(!empty($data))
|
2021-04-23 16:43:23 +08:00
|
|
|
{
|
2021-06-06 23:59:30 +08:00
|
|
|
// 获取更新信息
|
|
|
|
$request_params = [
|
|
|
|
'plugins_type' => 'plugins',
|
|
|
|
'plugins_data' => $data,
|
|
|
|
];
|
|
|
|
$result = StoreService::PluginsUpgradeInfo($request_params);
|
|
|
|
if(!empty($result) && isset($result['code']) && $result['code'] == 0)
|
|
|
|
{
|
|
|
|
// 处理存在更新的插件数据
|
|
|
|
if(!empty($result['data']))
|
|
|
|
{
|
|
|
|
$result['data'] = array_column($result['data'], null, 'plugins');
|
|
|
|
}
|
|
|
|
|
|
|
|
// 存储缓存
|
2021-07-18 23:42:10 +08:00
|
|
|
MyCache($key, $result, $time);
|
2021-06-06 23:59:30 +08:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 存储缓存
|
2021-07-18 23:42:10 +08:00
|
|
|
MyCache($key, $result, $time);
|
2021-04-23 16:43:23 +08:00
|
|
|
}
|
|
|
|
}
|
2021-06-06 23:59:30 +08:00
|
|
|
} else {
|
|
|
|
$result = $res;
|
2021-04-23 16:43:23 +08:00
|
|
|
}
|
|
|
|
|
2021-06-06 23:59:30 +08:00
|
|
|
return $result;
|
2021-04-23 16:43:23 +08:00
|
|
|
}
|
2019-02-09 09:15:23 +08:00
|
|
|
}
|
|
|
|
?>
|