mirror of
https://gitee.com/technical-laohu/mpay.git
synced 2025-10-21 01:43:43 +08:00
支持微信支付宝收款功能
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use think\facade\Log;
|
||||
use think\facade\View;
|
||||
|
||||
class IndexController
|
||||
@@ -21,7 +22,17 @@ class IndexController
|
||||
}
|
||||
public function test()
|
||||
{
|
||||
$web = \request()->domain();
|
||||
return $web;
|
||||
$info = request()->post();
|
||||
$action = isset($info['action']) ? $info['action'] : '';
|
||||
if ($action === 'mpay') {
|
||||
$data = json_decode($info['data'], true);
|
||||
$config = \think\facade\Config::load("payconfig/{$data['pid']}_{$data['aid']}", 'payconfig');
|
||||
$payclient_path = "\\payclient\\Mpay";
|
||||
$Payclient = new $payclient_path($info, $config);
|
||||
$res = $Payclient->notify($info);
|
||||
return $res;
|
||||
} else {
|
||||
return 202;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -42,7 +42,12 @@ class PayManageController extends BaseController
|
||||
public function addChannel()
|
||||
{
|
||||
$aid = $this->request->get('aid');
|
||||
View::assign(['aid' => $aid]);
|
||||
$account = PayAccount::find($aid);
|
||||
$platform = $account->getData('platform');
|
||||
View::assign(['aid' => $aid, 'platform' => $platform, 'account' => $account->account]);
|
||||
if ($platform == 'wxpay' || $platform == 'alipay') {
|
||||
return View::fetch('add_channel_code');
|
||||
}
|
||||
return View::fetch();
|
||||
}
|
||||
// 编辑收款终端
|
||||
|
@@ -22,6 +22,50 @@ class PayManageController extends BaseController
|
||||
return json(['code' => 1, 'msg' => '无数据记录', 'count' => 0, 'data' => []]);
|
||||
}
|
||||
}
|
||||
// 收款终端列表
|
||||
public function getChannelList()
|
||||
{
|
||||
$aid = $this->request->post('aid');
|
||||
$res = PayChannel::where(['account_id' => $aid])->order('last_time', 'desc')->select();
|
||||
if ($res) {
|
||||
return \json(\backMsg(0, '获取成功', $res));
|
||||
} else {
|
||||
return \json(\backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 账号状态
|
||||
public function accountEnable()
|
||||
{
|
||||
$info = $this->request->post();
|
||||
$up_res = PayAccount::update($info);
|
||||
if ($up_res) {
|
||||
return json(\backMsg(0, '成功'));
|
||||
} else {
|
||||
return json(\backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 添加账号
|
||||
public function addAccount()
|
||||
{
|
||||
$info = $this->request->post();
|
||||
$pid = $this->request->session('pid');
|
||||
$info['pid'] = $pid;
|
||||
$info['params'] = '{}';
|
||||
$check_acc = PayAccount::where(['account' => $info['account'], 'platform' => $info['platform'], 'pid' => $pid])->find();
|
||||
if ($check_acc) {
|
||||
return \json(\backMsg(1, '账号已存在'));
|
||||
}
|
||||
$acc = PayAccount::create($info);
|
||||
if ($acc) {
|
||||
$state = $this->createAccountConfig($acc);
|
||||
if (!$state) {
|
||||
return json(\backMsg(1, '自字义参数错误'));
|
||||
}
|
||||
return \json(\backMsg(0, '添加成功'));
|
||||
} else {
|
||||
return \json(\backMsg(1, '添加失败'));
|
||||
}
|
||||
}
|
||||
// 编辑账号
|
||||
public function editAccount()
|
||||
{
|
||||
@@ -38,17 +82,6 @@ class PayManageController extends BaseController
|
||||
return json(\backMsg(1, '修改失败'));
|
||||
}
|
||||
}
|
||||
// 账号状态
|
||||
public function accountEnable()
|
||||
{
|
||||
$info = $this->request->post();
|
||||
$up_res = PayAccount::update($info);
|
||||
if ($up_res) {
|
||||
return json(\backMsg(0, '成功'));
|
||||
} else {
|
||||
return json(\backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 删除账号
|
||||
public function delAccount()
|
||||
{
|
||||
@@ -65,32 +98,14 @@ class PayManageController extends BaseController
|
||||
return \json(\backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 添加账号
|
||||
public function addAccount()
|
||||
{
|
||||
$info = $this->request->post();
|
||||
$pid = $this->request->session('pid');
|
||||
$info['pid'] = $pid;
|
||||
$info['params'] = '{}';
|
||||
$check_acc = PayAccount::where(['account' => $info['account'], 'pid' => $pid])->find();
|
||||
if ($check_acc) {
|
||||
return \json(\backMsg(1, '账号已存在'));
|
||||
}
|
||||
$acc = PayAccount::create($info);
|
||||
if ($acc) {
|
||||
$state = $this->createAccountConfig($acc);
|
||||
if (!$state) {
|
||||
return json(\backMsg(1, '自字义参数错误'));
|
||||
}
|
||||
return \json(\backMsg(0, '添加成功'));
|
||||
} else {
|
||||
return \json(\backMsg(1, '添加失败'));
|
||||
}
|
||||
}
|
||||
// 添加收款终端
|
||||
public function addChannel()
|
||||
{
|
||||
$info = $this->request->post();
|
||||
$check = PayChannel::where(['account_id' => $info['account_id'], 'channel' => $info['channel']])->count();
|
||||
if ($check) {
|
||||
return \json(\backMsg(1, '编号已存在'));
|
||||
}
|
||||
$res = PayChannel::create($info);
|
||||
if ($res) {
|
||||
return \json(\backMsg(0, '添加成功'));
|
||||
@@ -120,17 +135,6 @@ class PayManageController extends BaseController
|
||||
return \json(\backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 收款终端列表
|
||||
public function getChannelList()
|
||||
{
|
||||
$aid = $this->request->post('aid');
|
||||
$res = PayChannel::where(['account_id' => $aid])->order('last_time', 'desc')->select();
|
||||
if ($res) {
|
||||
return \json(\backMsg(0, '获取成功', $res));
|
||||
} else {
|
||||
return \json(\backMsg(1, '失败'));
|
||||
}
|
||||
}
|
||||
// 删除账号配置
|
||||
public function delAccountConfig($acc)
|
||||
{
|
||||
|
@@ -18,14 +18,6 @@ class PluginController extends BaseController
|
||||
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 = [])
|
||||
{
|
||||
|
@@ -16,7 +16,7 @@ class Order extends BaseModel
|
||||
public static function createOrder($data)
|
||||
{
|
||||
$my_time = time();
|
||||
$channel = self::setChannel($data['pid']);
|
||||
$channel = self::setChannel($data['pid'], $data['type']);
|
||||
$new_order = [
|
||||
// 订单号
|
||||
'order_id' => self::createOrderID('H'),
|
||||
@@ -112,13 +112,20 @@ class Order extends BaseModel
|
||||
return $order->toArray();
|
||||
}
|
||||
// 选择收款通道
|
||||
private static function setChannel($pid): array
|
||||
private static function setChannel($pid, $type): array
|
||||
{
|
||||
// 查询有效收款账户及通道
|
||||
$aids = PayAccount::where('pid', $pid)->where('state', 1)->column('id');
|
||||
$channel_info = PayChannel::whereIn('account_id', $aids)->where('state', 1)->order('last_time', 'asc')->find();
|
||||
if (!$channel_info || !$aids) {
|
||||
return [];
|
||||
$channel_infos = PayChannel::whereIn('account_id', $aids)->where('state', 1)->order('last_time', 'asc')->select();
|
||||
if (!$channel_infos || !$aids) return [];
|
||||
// 微信/支付宝收款处理
|
||||
$patt_wx = '/^wxpay/i';
|
||||
$patt_ali = '/^alipay/i';
|
||||
foreach ($channel_infos as $key => $value) {
|
||||
|
||||
}
|
||||
$channel_info = $channel_infos[0];
|
||||
// 选取收款通道
|
||||
$patt = PayAccount::find($channel_info->account_id);
|
||||
$channel = ['aid' => $channel_info->account_id, 'cid' => $channel_info->id, 'patt' => $patt->getData('pattern')];
|
||||
PayChannel::update(['last_time' => self::getFormatTime(), 'id' => $channel['cid']]);
|
||||
|
Reference in New Issue
Block a user