diff --git a/.env b/.env index 47ab4c7..3410a9b 100644 --- a/.env +++ b/.env @@ -2,11 +2,11 @@ APP_DEBUG = true DB_TYPE = mysql DB_HOST = 127.0.0.1 -DB_NAME = test1 -DB_USER = a1 -DB_PASS = 123456 +DB_NAME = mpay +DB_USER = admin +DB_PASS = Aa123456 DB_PORT = 3306 -DB_CHARSET = utf8mb4 +DB_CHARSET = utf8 DB_PREFIX = mpay_ DEFAULT_LANG = zh-cn \ No newline at end of file diff --git a/app/controller/api/PluginController.php b/app/controller/api/PluginController.php index b32674b..9ffd505 100644 --- a/app/controller/api/PluginController.php +++ b/app/controller/api/PluginController.php @@ -12,7 +12,13 @@ class PluginController extends BaseController public function getPluginList() { $local_plugin_config = self::getPluginConfig(); - $plugin_config = \Plugin::getPluginList($local_plugin_config); + $show = $this->request->get('show', 1); + $plugin_config = match ((int)$show) { + 0 => \Plugin::getAllPlugins($local_plugin_config), + 1 => \Plugin::getInstall($local_plugin_config), + 2 => \Plugin::getUninstallPlugins($local_plugin_config), + default => [] + }; if ($plugin_config) { return json(['code' => 0, 'msg' => 'OK', 'count' => count($plugin_config), 'data' => $plugin_config]); } else { @@ -83,11 +89,28 @@ class PluginController extends BaseController public function pluginEnable() { $info = $this->request->post(); + if ($this->isPluginInstall($info['platform']) == false) { + return json(backMsg(1, '插件未安装')); + } $up_res = $this->setPlugin($info['platform'], ['state' => $info['state']]); if ($up_res) { - return json(\backMsg(1, '失败')); + return json(backMsg(1, '失败')); } else { - return json(\backMsg(0, '成功')); + return json(backMsg(0, '成功')); + } + } + // 检测插件是否安装 + public function isPluginInstall(string $platform): bool + { + $config = self::getPluginConfig(); + $platforms = []; + foreach ($config as $key => $value) { + $platforms[] = $value['platform']; + } + if (in_array($platform, $platforms)) { + return true; + } else { + return false; } } // 插件选项 diff --git a/config/extendconfig/payplugin.php b/config/extendconfig/payplugin.php index 8cf9712..1ef4065 100644 --- a/config/extendconfig/payplugin.php +++ b/config/extendconfig/payplugin.php @@ -50,5 +50,5 @@ return array ( 'store_sn' => '', 'type' => '30', ), - ) + ), ); diff --git a/extend/Plugin.php b/extend/Plugin.php index cd35c64..1a8f281 100644 --- a/extend/Plugin.php +++ b/extend/Plugin.php @@ -6,7 +6,8 @@ use think\facade\Log; class Plugin { - public static function getPluginList(array $local_plugin = []): array + // 获取全部插件(含本地) + public static function getAllPlugins(array $local_plugin = []): array { $app_plugin = []; $app_plugin_all = self::getAllPlugin(); @@ -15,6 +16,11 @@ class Plugin $app_plugin = array_merge($local_plugin, $plugin_uninstall); return $app_plugin; } + // 获取未安装插件 + public static function getUninstallPlugins(array $local_plugin = []): array + { + return self::getUninstall(self::getAllPlugin(), $local_plugin); + } // 获取已安装插件 public static function getInstall(array $local_plugin = []): array { @@ -53,7 +59,7 @@ class Plugin 'price' => '0.00', 'describe' => '支持微信个人收款码、赞赏码、经营码、商家码收款,监听回调', 'website' => 'https://weixin.qq.com/', - 'state' => 1, + 'state' => 0, 'query' => array(), ), @@ -65,7 +71,7 @@ class Plugin 'price' => '0.00', 'describe' => '支持支付宝个人收款码、经营码收款,监听回调', 'website' => 'https://www.alipay.com/', - 'state' => 1, + 'state' => 0, 'query' => array(), ), @@ -77,7 +83,7 @@ class Plugin 'price' => '49.00', 'describe' => '主流移动支付全能收 信用卡,花呗都能用,生意帮手收钱吧,移动收款就用它!', 'website' => 'https://www.shouqianba.com/', - 'state' => 1, + 'state' => 0, 'query' => array( 'date_end' => NULL, @@ -98,7 +104,7 @@ class Plugin 'price' => '49.00', 'describe' => '数字门店', 'website' => 'https://store.zhihuijingyingba.com/', - 'state' => 1, + 'state' => 0, 'query' => array( 'pageNo' => 1, diff --git a/view/plugin/index.html b/view/plugin/index.html index f231230..bc71e99 100644 --- a/view/plugin/index.html +++ b/view/plugin/index.html @@ -43,12 +43,19 @@ @@ -66,14 +73,13 @@ { title: '说明', field: 'describe', align: 'left' }, { title: '价格', field: 'price', align: 'center', maxWidth: 180, templet: `
{{= d.price==0 ? '免费' : d.price }}
` }, { title: '状态', field: 'state', align: 'center', maxWidth: 180, templet: `#plugin-state` }, - { title: '操作', align: 'right', maxWidth: 180, fixed: 'right', templet: `#plugin-action` }, + { title: '操作', align: 'center', maxWidth: 180, fixed: 'right', templet: `#plugin-action` }, ]] table.render({ id: 'plugin-table', elem: '#plugin-table', url: '/api/Plugin/getPluginList', - page: true, skin: 'line', cols: cols, where: { show: 1 }, @@ -84,20 +90,17 @@ // 表头工具事件 table.on('toolbar(plugin-table)', function (obj) { if (obj.event === 'showAllPlugin') { - plugin.changClass(this); - table.reload('plugin-table', { where: { show: 0 } }); + table.reload('plugin-table', { where: { show: 0 }, done: () => { plugin.changClass(obj.event) } }); } else if (obj.event === 'showInstalled') { - plugin.changClass(this); - table.reload('plugin-table', { where: { show: 1 } }); + table.reload('plugin-table', { where: { show: 1 }, done: () => { plugin.changClass(obj.event) } }); } else if (obj.event === 'showWaitInstall') { - plugin.changClass(this); - table.reload('plugin-table', { where: { show: 2 } }); + table.reload('plugin-table', { where: { show: 2 }, done: () => { plugin.changClass(obj.event) } }); } }); // 单元格事件 table.on('tool(plugin-table)', function (obj) { const id = obj.data.id; - if (obj.event === 'createConfig') { + if (obj.event === 'pluginInstall') { layer.msg(obj.event); } else if (obj.event === 'pluginUpdate') { layer.msg(obj.event); @@ -117,9 +120,10 @@ let plugin = {}; // 处理点击btn切换class - plugin.changClass = (ele) => { + plugin.changClass = (event) => { const select = 'layui-btn layui-btn-primary layui-bg-green layui-btn-sm'; const unselect = 'layui-btn layui-btn-primary layui-bg-gray layui-btn-sm'; + const ele = document.querySelector(`button[lay-event="${event}"]`); ele.className = select; const btns = document.querySelectorAll(`button[grp-btn]`); btns.forEach(val => {