mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-09-17 17:26:40 +08:00
插件管理优化
This commit is contained in:
parent
0473a992a8
commit
5728976e9f
12
!.env
Normal file
12
!.env
Normal file
@ -0,0 +1,12 @@
|
||||
APP_DEBUG = true
|
||||
|
||||
DB_TYPE = mysql
|
||||
DB_HOST = 127.0.0.1
|
||||
DB_NAME = mpay
|
||||
DB_USER = admin
|
||||
DB_PASS = Aa123456
|
||||
DB_PORT = 3306
|
||||
DB_CHARSET = utf8
|
||||
DB_PREFIX = mpay_
|
||||
|
||||
DEFAULT_LANG = zh-cn
|
@ -116,20 +116,39 @@ class PayManageController extends BaseController
|
||||
{
|
||||
$platform = Platform::where('platform', $acc->getData('platform'))->find();
|
||||
$user = User::where('pid', $acc->pid)->find();
|
||||
$query = \unserialize($platform->query);
|
||||
$data = [
|
||||
'pid' => $user->pid,
|
||||
'key' => $user->secret_key,
|
||||
'aid' => $acc->id,
|
||||
'platform' => $acc->getData('platform'),
|
||||
'account' => $acc->account,
|
||||
'password' => $acc->password,
|
||||
'payclass' => $platform->class_name,
|
||||
'query' => \var_export($query, \true)
|
||||
];
|
||||
$config = View::fetch('tpl/account_config', $data);
|
||||
$name = "{$data['pid']}_{$data['aid']}";
|
||||
$path = "../config/payconfig/{$name}.php";
|
||||
$query = var_export(\unserialize($platform->query), \true);
|
||||
$config = <<<EOF
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 支付监听配置,一个文件,一个账号
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [
|
||||
// 用户账号配置
|
||||
'user' => [
|
||||
'pid' => {$user->pid},
|
||||
'key' => '$user->secret_key'
|
||||
],
|
||||
// 收款平台账号配置
|
||||
'pay' => [
|
||||
// 账号id
|
||||
'aid' => $acc->id,
|
||||
// 收款平台
|
||||
'platform' => '{$acc->getData('platform')}',
|
||||
// 插件类名
|
||||
'payclass' => '{$platform->class_name}',
|
||||
// 账号
|
||||
'account' => '{$acc->account}',
|
||||
// 密码
|
||||
'password' => '{$acc->password}',
|
||||
// 订单查询参数配置
|
||||
'query' => {$query},
|
||||
]
|
||||
];
|
||||
|
||||
EOF;
|
||||
$name = "{$user->pid}_{$acc->id}";
|
||||
$path = config_path() . "/payconfig/{$name}.php";
|
||||
\file_put_contents($path, $config);
|
||||
}
|
||||
}
|
||||
|
@ -10,36 +10,103 @@ use think\facade\View;
|
||||
|
||||
class PluginController extends BaseController
|
||||
{
|
||||
// 插件列表
|
||||
// 获取插件列表
|
||||
public function getPluginList()
|
||||
{
|
||||
$query = $this->request->get();
|
||||
$data = Platform::order('id', 'desc')->paginate(['list_rows' => $query['limit'], 'page' => $query['page']]);
|
||||
if ($data) {
|
||||
return json(['code' => 0, 'msg' => 'OK', 'count' => $data->total(), 'data' => $data->items()]);
|
||||
$plugin_config = $this->getPluginConfig();
|
||||
if ($plugin_config) {
|
||||
return json(['code' => 0, 'msg' => 'OK', 'count' => \count($plugin_config), 'data' => $plugin_config]);
|
||||
} else {
|
||||
return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]);
|
||||
}
|
||||
}
|
||||
// 测试
|
||||
public function test()
|
||||
{
|
||||
// $res = $this->addPlugin(['platform' => 'haopay', 'name' => '好支付', 'class_name' => 'Haopay', 'price' => 99, 'describe' => '好支付', 'website' => 'https://store.zhihuijingyingba.com/', 'state' => 1, 'query' => []]);
|
||||
// $res = $this->delPlugin('haopay');
|
||||
$res = $this->setPlugin('haopay', ['state' => 0]);
|
||||
return $res;
|
||||
}
|
||||
// 添加插件
|
||||
public function addPlugin(array $option = [])
|
||||
{
|
||||
$keys = ['platform', 'name', 'class_name', 'price', 'describe', 'website', 'state', 'query'];
|
||||
$config = [];
|
||||
foreach ($option as $key => $value) {
|
||||
if (in_array($key, $keys)) {
|
||||
$config[$key] = $value;
|
||||
}
|
||||
}
|
||||
$plugin_config = $this->getPluginConfig();
|
||||
$plugin_platform = $config['platform'] ?: '';
|
||||
foreach ($plugin_config as $value) {
|
||||
if ($plugin_platform == $value['platform']) {
|
||||
return 1; //'插件已存在'
|
||||
}
|
||||
}
|
||||
$plugin_config[] = $config;
|
||||
$this->savePluginConfig($plugin_config, '支付插件列表');
|
||||
return 0;
|
||||
}
|
||||
// 删除插件
|
||||
public function delPlugin($plugin_name = '')
|
||||
{
|
||||
$plugin_config = $this->getPluginConfig();
|
||||
$keys = [];
|
||||
foreach ($plugin_config as $index => $value) {
|
||||
if ($value['platform'] == $plugin_name) {
|
||||
$keys[] = $index;
|
||||
}
|
||||
}
|
||||
foreach ($keys as $index) {
|
||||
unset($plugin_config[$index]);
|
||||
}
|
||||
$config = \array_values($plugin_config);
|
||||
$this->savePluginConfig($config, '支付插件列表');
|
||||
return 0;
|
||||
}
|
||||
// 修改插件
|
||||
public function setPlugin($platform = '', $option = [])
|
||||
{
|
||||
$config = $this->getPluginConfig();
|
||||
if (!$platform) {
|
||||
return 1; //'请选择插件'
|
||||
}
|
||||
if (!$option) {
|
||||
return 2; //请添加插件配置
|
||||
}
|
||||
foreach ($config as $index => $options) {
|
||||
if ($options['platform'] == $platform) {
|
||||
foreach ($options as $key => $value) {
|
||||
if (\array_key_exists($key, $option)) {
|
||||
$config[$index][$key] = $option[$key];
|
||||
}
|
||||
}
|
||||
$this->savePluginConfig($config, '支付插件列表');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 插件启用
|
||||
public function pluginEnable()
|
||||
{
|
||||
$info = $this->request->post();
|
||||
$up_res = Platform::update($info);
|
||||
$up_res = $this->setPlugin($info['platform'], ['state' => $info['state']]);
|
||||
if ($up_res) {
|
||||
return json(\backMsg(0, '成功'));
|
||||
} else {
|
||||
return json(\backMsg(1, '失败'));
|
||||
} else {
|
||||
return json(\backMsg(0, '成功'));
|
||||
}
|
||||
}
|
||||
// 插件选项
|
||||
public function pluginOption()
|
||||
{
|
||||
// 加载平台配置
|
||||
$platform = \think\facade\Config::load("extendconfig/platform", 'extendconfig');
|
||||
$config = $this->getPluginConfig();
|
||||
$option = [];
|
||||
foreach ($platform as $key => $value) {
|
||||
$option[] = ['platform' => $key, 'name' => $value];
|
||||
foreach ($config as $value) {
|
||||
$option[] = ['platform' => $value['platform'], 'name' => $value['name']];
|
||||
}
|
||||
return json($option);
|
||||
}
|
||||
@ -60,4 +127,27 @@ class PluginController extends BaseController
|
||||
return \json(\backMsg(1, '创建成功'));
|
||||
}
|
||||
}
|
||||
// 获取插件配置
|
||||
private function getPluginConfig(): array
|
||||
{
|
||||
$payplugin_path = config_path() . '/extendconfig/payplugin.php';
|
||||
if (!file_exists($payplugin_path)) {
|
||||
return [];
|
||||
}
|
||||
// 加载插件配置
|
||||
$payplugin_config = require_once $payplugin_path;
|
||||
return $payplugin_config;
|
||||
}
|
||||
// 保存插件配置
|
||||
private function savePluginConfig(array $config, string $note = '说明')
|
||||
{
|
||||
$payplugin_path = config_path() . '/extendconfig/payplugin.php';
|
||||
$note_tpl = <<<EOF
|
||||
// +----------------------------------------------------------------------
|
||||
// | $note
|
||||
// +----------------------------------------------------------------------
|
||||
EOF;
|
||||
$config_str = "<?php\n" . $note_tpl . "\n\nreturn " . var_export($config, true) . ";\n";
|
||||
\file_put_contents($payplugin_path, $config_str);
|
||||
}
|
||||
}
|
||||
|
@ -27,9 +27,17 @@ class PayAccount extends BaseModel
|
||||
// 获取器
|
||||
public function getPlatformAttr($value)
|
||||
{
|
||||
// 加载平台配置
|
||||
$platform = \think\facade\Config::load("extendconfig/platform", 'extendconfig');
|
||||
return $platform[$value];
|
||||
$payplugin_path = config_path() . '/extendconfig/payplugin.php';
|
||||
if (!file_exists($payplugin_path)) {
|
||||
return [];
|
||||
}
|
||||
// 加载插件配置
|
||||
$payplugin_config = require_once $payplugin_path;
|
||||
$option = [];
|
||||
foreach ($payplugin_config as $config) {
|
||||
$option[$config['platform']] = $config['name'];
|
||||
}
|
||||
return $option[$value];
|
||||
}
|
||||
public function getPatternAttr($value)
|
||||
{
|
||||
|
86
config/extendconfig/payplugin.php
Normal file
86
config/extendconfig/payplugin.php
Normal file
@ -0,0 +1,86 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 支付插件列表
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return array (
|
||||
0 =>
|
||||
array (
|
||||
'platform' => 'sqbpay',
|
||||
'name' => '收钱吧',
|
||||
'class_name' => 'ShouQianBa',
|
||||
'price' => '99.00',
|
||||
'describe' => '主流移动支付全能收 信用卡,花呗都能用,生意帮手收钱吧,移动收款就用它!',
|
||||
'website' => 'https://www.shouqianba.com/',
|
||||
'state' => 1,
|
||||
'query' => 'a:8:{s:8:"date_end";N;s:10:"date_start";N;s:4:"page";i:1;s:9:"page_size";i:10;s:13:"upayQueryType";i:0;s:6:"status";s:4:"2000";s:8:"store_sn";s:0:"";s:4:"type";s:2:"30";}',
|
||||
),
|
||||
1 =>
|
||||
array (
|
||||
'platform' => 'storepay',
|
||||
'name' => '数字门店',
|
||||
'class_name' => 'ZhiHuiJingYing',
|
||||
'price' => '99.00',
|
||||
'describe' => '数字门店',
|
||||
'website' => 'https://store.zhihuijingyingba.com/',
|
||||
'state' => 1,
|
||||
'query' => 'a:7:{s:6:"pageNo";i:1;s:8:"pageSize";i:10;s:9:"payClient";i:4;s:6:"status";i:2;s:2:"_t";N;s:16:"createTime_begin";N;s:14:"createTime_end";N;}',
|
||||
),
|
||||
2 =>
|
||||
array (
|
||||
'platform' => 'ysepay',
|
||||
'name' => '小Y经营',
|
||||
'class_name' => 'Ysepay',
|
||||
'price' => '99.00',
|
||||
'describe' => '为商户和消费者提供安全、便捷、高效的支付产品与服务助力商户提升运营效率,实现数字化运营',
|
||||
'website' => 'https://xym.ysepay.com/',
|
||||
'state' => 1,
|
||||
'query' => 'a:10:{s:7:"storeNo";s:0:"";s:7:"bizType";i:3;s:7:"payType";s:0:"";s:11:"orderStatus";i:3;s:5:"trmNo";s:0:"";s:12:"operatorUser";s:0:"";s:13:"codeBoardCode";s:0:"";s:8:"pageSize";i:10;s:6:"pageNo";i:1;s:7:"orderNo";s:0:"";}',
|
||||
),
|
||||
3 =>
|
||||
array (
|
||||
'platform' => 'mqpay',
|
||||
'name' => '码钱',
|
||||
'class_name' => 'MaQian',
|
||||
'price' => '99.00',
|
||||
'describe' => '码钱商管平台',
|
||||
'website' => 'https://m.hkrt.cn/',
|
||||
'state' => 0,
|
||||
'query' => 'a:12:{s:12:"terminalType";s:0:"";s:7:"payType";s:0:"";s:7:"payMode";s:0:"";s:11:"tradeStatus";s:1:"1";s:7:"tradeNo";s:0:"";s:7:"storeId";s:0:"";s:4:"page";i:1;s:4:"rows";i:10;s:7:"endDate";N;s:7:"endTime";N;s:9:"startDate";N;s:9:"startTime";N;}',
|
||||
),
|
||||
4 =>
|
||||
array (
|
||||
'platform' => 'lklpay',
|
||||
'name' => '拉卡拉',
|
||||
'class_name' => 'LaKaLa',
|
||||
'price' => '99.00',
|
||||
'describe' => '数字支付,更安全,更高效',
|
||||
'website' => 'https://customer.lakala.com/',
|
||||
'state' => 0,
|
||||
'query' => '',
|
||||
),
|
||||
5 =>
|
||||
array (
|
||||
'platform' => 'sftpay',
|
||||
'name' => '盛付通',
|
||||
'class_name' => 'ShengPay',
|
||||
'price' => '99.00',
|
||||
'describe' => '轻松生活 放心支付',
|
||||
'website' => 'https://b.shengpay.com/',
|
||||
'state' => 0,
|
||||
'query' => '',
|
||||
),
|
||||
6 =>
|
||||
array (
|
||||
'platform' => 'haopay',
|
||||
'name' => '好支付',
|
||||
'class_name' => 'Haopay',
|
||||
'price' => 99,
|
||||
'describe' => '好支付',
|
||||
'website' => 'https://store.zhihuijingyingba.com/',
|
||||
'state' => 0,
|
||||
'query' =>
|
||||
array (
|
||||
),
|
||||
),
|
||||
);
|
@ -1,13 +0,0 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 支持平台
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return array(
|
||||
'sqbpay' => '收钱吧',
|
||||
'storepay' => '数字门店',
|
||||
'ysepay' => '小Y经营',
|
||||
'mqpay' => '码钱',
|
||||
'lklpay' => '拉卡拉',
|
||||
'sftpay' => '盛付通',
|
||||
);
|
@ -2,6 +2,7 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | 支付监听配置,一个文件,一个账号
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return [
|
||||
// 用户账号配置
|
||||
'user' => [
|
||||
@ -14,7 +15,7 @@ return [
|
||||
'aid' => 1,
|
||||
// 收款平台
|
||||
'platform' => 'sqbpay',
|
||||
// 收款平台
|
||||
// 插件类名
|
||||
'payclass' => 'ShouQianBa',
|
||||
// 账号
|
||||
'account' => '14725836911',
|
||||
|
@ -43,7 +43,7 @@
|
||||
<button class="layui-btn layui-btn-primary layui-bg-gray layui-btn-sm" grp-btn lay-event="showWaitInstall">待安装</button>
|
||||
</script>
|
||||
<script type="text/html" id="plugin-state">
|
||||
<input type="checkbox" name="state" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="pluginEnable" {{ d.state == 1 ? 'checked' : '' }} />
|
||||
<input type="checkbox" name="state" value="{{d.platform}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="pluginEnable" {{ d.state == 1 ? 'checked' : '' }} />
|
||||
</script>
|
||||
<script type="text/html" id="plugin-action">
|
||||
<a href="javascript:;" class="layui-font-green" lay-event="createConfig">配置</a><div class="divider-vl"></div>
|
||||
@ -105,8 +105,8 @@
|
||||
// 启用状态
|
||||
form.on('switch(pluginEnable)', function (obj) {
|
||||
const state = obj.elem.checked == true ? 1 : 0;
|
||||
const id = obj.value;
|
||||
const field = { state: state, id: id };
|
||||
const platform = obj.value;
|
||||
const field = { state: state, platform: platform };
|
||||
plugin.enable(obj, field);
|
||||
return false;
|
||||
});
|
||||
|
@ -1,26 +0,0 @@
|
||||
<?php echo "<?php\n"; ?>
|
||||
// +----------------------------------------------------------------------
|
||||
// | 支付监听配置,一个文件,一个账号
|
||||
// +----------------------------------------------------------------------
|
||||
return [
|
||||
// 用户账号配置
|
||||
'user' => [
|
||||
'pid' => <?php echo $pid; ?>,
|
||||
'key' => '<?php echo $key; ?>'
|
||||
],
|
||||
// 收款平台账号配置
|
||||
'pay' => [
|
||||
// 账号id
|
||||
'aid' => <?php echo $aid; ?>,
|
||||
// 收款平台
|
||||
'platform' => '<?php echo $platform; ?>',
|
||||
// 收款平台
|
||||
'payclass' => '<?php echo $payclass; ?>',
|
||||
// 账号
|
||||
'account' => '<?php echo $account; ?>',
|
||||
// 密码
|
||||
'password' => '<?php echo $password; ?>',
|
||||
// 订单查询参数配置
|
||||
'query' => <?php echo $query; ?>,
|
||||
]
|
||||
];
|
@ -1,6 +0,0 @@
|
||||
<?php echo "<?php\n"; ?>
|
||||
// +----------------------------------------------------------------------
|
||||
// | 支持平台
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
return <?php echo var_export($data, true); ?>;
|
Loading…
Reference in New Issue
Block a user