mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-09-17 17:26:40 +08:00
更新后台管理接口
This commit is contained in:
parent
6a8ec71b8d
commit
e85e71f8d9
@ -7,7 +7,6 @@ namespace app\controller\api;
|
||||
use app\BaseController;
|
||||
use app\model\PayAccount;
|
||||
use app\model\PayChannel;
|
||||
use app\model\User;
|
||||
|
||||
class PayManageController extends BaseController
|
||||
{
|
||||
@ -28,9 +27,9 @@ class PayManageController extends BaseController
|
||||
$aid = $this->request->post('aid');
|
||||
$res = PayChannel::where(['account_id' => $aid])->order('last_time', 'desc')->select();
|
||||
if ($res) {
|
||||
return \json(\backMsg(0, '获取成功', $res));
|
||||
return json(backMsg(0, '获取成功', $res));
|
||||
} else {
|
||||
return \json(\backMsg(1, '失败'));
|
||||
return json(backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 账号状态
|
||||
@ -39,9 +38,9 @@ class PayManageController extends BaseController
|
||||
$info = $this->request->post();
|
||||
$up_res = PayAccount::update($info);
|
||||
if ($up_res) {
|
||||
return json(\backMsg(0, '成功'));
|
||||
return json(backMsg(0, '成功'));
|
||||
} else {
|
||||
return json(\backMsg(1, '失败'));
|
||||
return json(backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 添加账号
|
||||
@ -53,17 +52,13 @@ class PayManageController extends BaseController
|
||||
$info['params'] = '{}';
|
||||
$check_acc = PayAccount::where(['account' => $info['account'], 'platform' => $info['platform'], 'pid' => $pid])->find();
|
||||
if ($check_acc) {
|
||||
return \json(\backMsg(1, '账号已存在'));
|
||||
return json(backMsg(1, '账号已存在'));
|
||||
}
|
||||
$acc = PayAccount::create($info);
|
||||
if ($acc) {
|
||||
$state = $this->createAccountConfig($acc);
|
||||
if (!$state) {
|
||||
return json(\backMsg(1, '自字义参数错误'));
|
||||
}
|
||||
return \json(\backMsg(0, '添加成功'));
|
||||
return json(backMsg(0, '添加成功'));
|
||||
} else {
|
||||
return \json(\backMsg(1, '添加失败'));
|
||||
return json(backMsg(1, '添加失败'));
|
||||
}
|
||||
}
|
||||
// 编辑账号
|
||||
@ -72,14 +67,9 @@ class PayManageController extends BaseController
|
||||
$info = $this->request->post();
|
||||
$up_res = PayAccount::update($info);
|
||||
if ($up_res) {
|
||||
$acc = PayAccount::find($info['id']);
|
||||
$state = $this->createAccountConfig($acc);
|
||||
if (!$state) {
|
||||
return json(\backMsg(1, '自字义参数错误'));
|
||||
}
|
||||
return json(\backMsg(0, '修改成功'));
|
||||
return json(backMsg(0, '修改成功'));
|
||||
} else {
|
||||
return json(\backMsg(1, '修改失败'));
|
||||
return json(backMsg(1, '修改失败'));
|
||||
}
|
||||
}
|
||||
// 删除账号
|
||||
@ -89,13 +79,9 @@ class PayManageController extends BaseController
|
||||
$res = PayAccount::destroy($ids);
|
||||
$res2 = PayChannel::whereIn('account_id', $ids)->select()->delete();
|
||||
if ($res && $res2) {
|
||||
$accs = PayAccount::whereIn('id', $ids)->withTrashed()->select();
|
||||
foreach ($accs as $acc) {
|
||||
$this->delAccountConfig($acc);
|
||||
}
|
||||
return \json(\backMsg(0, '已删除'));
|
||||
return json(backMsg(0, '已删除'));
|
||||
} else {
|
||||
return \json(\backMsg(1, '失败'));
|
||||
return json(backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 添加收款终端
|
||||
@ -104,13 +90,13 @@ class PayManageController extends BaseController
|
||||
$info = $this->request->post();
|
||||
$check = PayChannel::where(['account_id' => $info['account_id'], 'channel' => $info['channel']])->count();
|
||||
if ($check) {
|
||||
return \json(\backMsg(1, '编号已存在'));
|
||||
return json(backMsg(1, '编号已存在'));
|
||||
}
|
||||
$res = PayChannel::create($info);
|
||||
if ($res) {
|
||||
return \json(\backMsg(0, '添加成功'));
|
||||
return json(backMsg(0, '添加成功'));
|
||||
} else {
|
||||
return \json(\backMsg(1, '添加失败'));
|
||||
return json(backMsg(1, '添加失败'));
|
||||
}
|
||||
}
|
||||
// 编辑收款终端
|
||||
@ -119,9 +105,9 @@ class PayManageController extends BaseController
|
||||
$info = $this->request->post();
|
||||
$up_res = PayChannel::update($info);
|
||||
if ($up_res) {
|
||||
return json(\backMsg(0, '修改成功'));
|
||||
return json(backMsg(0, '修改成功'));
|
||||
} else {
|
||||
return json(\backMsg(1, '修改失败'));
|
||||
return json(backMsg(1, '修改失败'));
|
||||
}
|
||||
}
|
||||
// 删除收款终端
|
||||
@ -130,17 +116,9 @@ class PayManageController extends BaseController
|
||||
$cid = $this->request->post('id');
|
||||
$res = PayChannel::destroy($cid);
|
||||
if ($res) {
|
||||
return \json(\backMsg(0, '已删除'));
|
||||
return json(backMsg(0, '已删除'));
|
||||
} else {
|
||||
return \json(\backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 删除账号配置
|
||||
public function delAccountConfig($acc)
|
||||
{
|
||||
$path = config_path() . "/payconfig/{$acc->pid}_{$acc->id}.php";
|
||||
if (file_exists($path)) {
|
||||
unlink($path);
|
||||
return json(backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 上传二维码图片
|
||||
@ -186,51 +164,4 @@ class PayManageController extends BaseController
|
||||
return json(backMsg(1, '查询空订单'));
|
||||
}
|
||||
}
|
||||
|
||||
// 生成账号配置
|
||||
private function createAccountConfig($acc)
|
||||
{
|
||||
$params = \json_decode($acc->params, \true);
|
||||
if ($params === null) {
|
||||
return false; // 自定义参数错误
|
||||
}
|
||||
$platform = \app\controller\api\PluginController::getPluginInfo($acc->getData('platform'));
|
||||
$user = User::where('pid', $acc->pid)->find();
|
||||
$query_tpl = $platform['query'];
|
||||
$query = var_export(\array_merge($query_tpl, $params), \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);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
2
config/payconfig/.gitignore
vendored
2
config/payconfig/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
Loading…
Reference in New Issue
Block a user