mirror of
				https://gitee.com/technical-laohu/mpay.git
				synced 2025-11-04 08:43:42 +08:00 
			
		
		
		
	优化收款监听模式前端逻辑
This commit is contained in:
		@@ -90,10 +90,12 @@ class PayController
 | 
			
		||||
    public function console($order_id = '')
 | 
			
		||||
    {
 | 
			
		||||
        if ($order_id) {
 | 
			
		||||
            $act_order = Order::where('order_id', $order_id)->field(['out_trade_no', 'name', 'really_price', 'close_time', 'type', 'order_id', 'cid'])->find();
 | 
			
		||||
            $act_order = Order::where('order_id', $order_id)->find();
 | 
			
		||||
            if ($act_order) {
 | 
			
		||||
                $qrcode = PayChannel::where('id', $act_order->cid)->value('qrcode');
 | 
			
		||||
                View::assign($act_order->toArray());
 | 
			
		||||
                $passtime = strtotime($act_order->close_time) - time();
 | 
			
		||||
                View::assign('passtime', $passtime > 0 ? $passtime : 0);
 | 
			
		||||
                View::assign('payUrl', $qrcode);
 | 
			
		||||
                return View::fetch();
 | 
			
		||||
            } else {
 | 
			
		||||
@@ -139,6 +141,22 @@ class PayController
 | 
			
		||||
            return '订单号参数错误';
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // 验证支付结果
 | 
			
		||||
    public function validatePayResult(Request $request)
 | 
			
		||||
    {
 | 
			
		||||
        $data = $request->post();
 | 
			
		||||
        $order = Order::find($data['id']);
 | 
			
		||||
        if (\strtotime($order->close_time) < \time()) {
 | 
			
		||||
            return \json(\backMsg(1, '订单已关闭'));
 | 
			
		||||
        }
 | 
			
		||||
        $up_data = ['id' => $data['id'], 'patt' => $data['patt']];
 | 
			
		||||
        $up_res = Order::update($up_data);
 | 
			
		||||
        if ($up_res) {
 | 
			
		||||
            return \json(\backMsg(0, '更新成功'));
 | 
			
		||||
        } else {
 | 
			
		||||
            return \json(\backMsg(1, '更新失败'));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
    // 处理收款通知
 | 
			
		||||
    public function payHeart($pid = '', $aid = '', $sign = '')
 | 
			
		||||
    {
 | 
			
		||||
 
 | 
			
		||||
@@ -131,21 +131,4 @@ class PayManageController extends BaseController
 | 
			
		||||
        $path = "../config/payconfig/{$name}.php";
 | 
			
		||||
        \file_put_contents($path, $config);
 | 
			
		||||
    }
 | 
			
		||||
    // 生成平台列表配置
 | 
			
		||||
    public function crtPlfConfig()
 | 
			
		||||
    {
 | 
			
		||||
        $info = Platform::where('state', 1)->field('platform, name')->select()->toArray();
 | 
			
		||||
        $data = [];
 | 
			
		||||
        foreach ($info as $value) {
 | 
			
		||||
            $data[$value['platform']] = $value['name'];
 | 
			
		||||
        }
 | 
			
		||||
        $config = View::fetch('tpl/platform_config', $data);
 | 
			
		||||
        $path = "../config/extendconfig/platform.php";
 | 
			
		||||
        $res = \file_put_contents($path, $config);
 | 
			
		||||
        if ($res) {
 | 
			
		||||
            return \json(\backMsg(msg: '创建成功'));
 | 
			
		||||
        } else {
 | 
			
		||||
            return \json(\backMsg(1, '创建成功'));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ namespace app\controller\api;
 | 
			
		||||
 | 
			
		||||
use app\BaseController;
 | 
			
		||||
use app\model\Platform;
 | 
			
		||||
use think\facade\View;
 | 
			
		||||
 | 
			
		||||
class PluginController extends BaseController
 | 
			
		||||
{
 | 
			
		||||
@@ -34,7 +35,29 @@ class PluginController extends BaseController
 | 
			
		||||
    // 插件选项
 | 
			
		||||
    public function pluginOption()
 | 
			
		||||
    {
 | 
			
		||||
        $option = Platform::field('platform,name')->where('state', 1)->select();
 | 
			
		||||
        // 加载平台配置
 | 
			
		||||
        $platform = \think\facade\Config::load("extendconfig/platform", 'extendconfig');
 | 
			
		||||
        $option = [];
 | 
			
		||||
        foreach ($platform as $key => $value) {
 | 
			
		||||
            $option[] = ['platform' => $key, 'name' => $value];
 | 
			
		||||
        }
 | 
			
		||||
        return json($option);
 | 
			
		||||
    }
 | 
			
		||||
    // 生成插件配置
 | 
			
		||||
    public function crtPlfConfig()
 | 
			
		||||
    {
 | 
			
		||||
        $info = Platform::where('state', 1)->field('platform, name')->select()->toArray();
 | 
			
		||||
        $data = [];
 | 
			
		||||
        foreach ($info as $value) {
 | 
			
		||||
            $data[$value['platform']] = $value['name'];
 | 
			
		||||
        }
 | 
			
		||||
        $config = View::fetch('tpl/platform_config', $data);
 | 
			
		||||
        $path = "../config/extendconfig/platform.php";
 | 
			
		||||
        $res = \file_put_contents($path, $config);
 | 
			
		||||
        if ($res) {
 | 
			
		||||
            return \json(\backMsg(msg: '创建成功'));
 | 
			
		||||
        } else {
 | 
			
		||||
            return \json(\backMsg(1, '创建成功'));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										11
									
								
								config/extendconfig/platform.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								config/extendconfig/platform.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
<?php
 | 
			
		||||
// +----------------------------------------------------------------------
 | 
			
		||||
// | 支持平台
 | 
			
		||||
// +----------------------------------------------------------------------
 | 
			
		||||
 | 
			
		||||
return array (
 | 
			
		||||
  'sqbpay' => '收钱吧',
 | 
			
		||||
  'storepay' => '数字门店',
 | 
			
		||||
  'ysepay' => '小Y经营',
 | 
			
		||||
  'mqpay' => '码钱',
 | 
			
		||||
);
 | 
			
		||||
@@ -16,6 +16,8 @@ Route::rule('checkOrder/[:pid]/[:sign]', 'Pay/checkOrder');
 | 
			
		||||
Route::rule('payHeart/[:pid]/[:aid]/[:sign]', 'Pay/payHeart');
 | 
			
		||||
// 监听收款通知
 | 
			
		||||
Route::rule('checkPayResult', 'Pay/checkPayResult');
 | 
			
		||||
// 验证支付结果
 | 
			
		||||
Route::rule('validatePayResult', 'Pay/validatePayResult');
 | 
			
		||||
 | 
			
		||||
// API多级控制器
 | 
			
		||||
Route::rule('api/:controller/:methon', 'api.:controller/:methon');
 | 
			
		||||
 
 | 
			
		||||
@@ -1 +1 @@
 | 
			
		||||
{"code":1,"msg":"\u67091\u4e2a\u65b0\u8ba2\u5355","orders":[{"id":27428,"pid":1001,"aid":1,"cid":1,"patt":1}]}
 | 
			
		||||
{"code":0,"msg":"没有新订单"}
 | 
			
		||||
@@ -5,7 +5,7 @@
 | 
			
		||||
    <meta charset="utf-8">
 | 
			
		||||
    <meta name="viewport" content="width=device-width, initial-scale=1">
 | 
			
		||||
    <title>收银台</title>
 | 
			
		||||
    <link rel="stylesheet" href="/static/css/layui.min.css">
 | 
			
		||||
    <link rel="stylesheet" href="/component/pear/css/pear.css" />
 | 
			
		||||
    <style>
 | 
			
		||||
        body {
 | 
			
		||||
            background: #f7f7f7;
 | 
			
		||||
@@ -148,7 +148,7 @@
 | 
			
		||||
            </div>
 | 
			
		||||
        </div>
 | 
			
		||||
    </div>
 | 
			
		||||
    <script src="/static/js/layui.min.js"></script>
 | 
			
		||||
    <script src="/component/layui/layui.js"></script>
 | 
			
		||||
    <script src="/static/js/awesome-qr.min.js"></script>
 | 
			
		||||
    <script>
 | 
			
		||||
        const payCode = '<?php echo htmlentities($payUrl); ?>';
 | 
			
		||||
@@ -179,6 +179,7 @@
 | 
			
		||||
                orderTimer = setTimeout(() => { queryOrder(url) }, 1000);
 | 
			
		||||
                if (jsonData.state === 1) {
 | 
			
		||||
                    clearTimeout(orderTimer);
 | 
			
		||||
                    layer.closeAll();
 | 
			
		||||
                    document.getElementById('divTime').innerHTML = '<small class="note">订单支付成功</small>';
 | 
			
		||||
                    document.getElementById('qrcode').src = '/static/img/pay_ok.png';// 输出支付成功提示图片
 | 
			
		||||
                    setTimeout(() => {
 | 
			
		||||
@@ -192,8 +193,65 @@
 | 
			
		||||
                timer(passtime);
 | 
			
		||||
            }
 | 
			
		||||
            queryOrder(`/getOrderState/${order}`);
 | 
			
		||||
 | 
			
		||||
        })();
 | 
			
		||||
        // <?php if ($patt == 0 && $passtime > 0) { ?>
 | 
			
		||||
        // 验证支付结果
 | 
			
		||||
        const id = '<?php echo htmlentities($id);?>';
 | 
			
		||||
        const reVali = () => {
 | 
			
		||||
            setTimeout(() => {
 | 
			
		||||
                layer.confirm('是否已支付?', { icon: 3, title: '提示' },
 | 
			
		||||
                    (index) => {
 | 
			
		||||
                        (async () => {
 | 
			
		||||
                            const res = await validatePayResult(id, 1);
 | 
			
		||||
                            if (res) { reVali() }
 | 
			
		||||
                        })()
 | 
			
		||||
                        layer.close(index);
 | 
			
		||||
                    }, (index) => {
 | 
			
		||||
                        reVali();
 | 
			
		||||
                        layer.close(index);
 | 
			
		||||
                    })
 | 
			
		||||
            }, 5000);
 | 
			
		||||
        }
 | 
			
		||||
        setTimeout(() => {
 | 
			
		||||
            layer.confirm('是否已支付?', { icon: 3, title: '提示' },
 | 
			
		||||
                (index) => {
 | 
			
		||||
                    (async () => {
 | 
			
		||||
                        const res = await validatePayResult(id, 1);
 | 
			
		||||
                        if (res) { reVali() }
 | 
			
		||||
                    })()
 | 
			
		||||
                    layer.close(index);
 | 
			
		||||
                },
 | 
			
		||||
                (index) => {
 | 
			
		||||
                    reVali();
 | 
			
		||||
                    layer.close(index);
 | 
			
		||||
                })
 | 
			
		||||
        }, 10000);
 | 
			
		||||
        // 验证支付结果
 | 
			
		||||
        async function validatePayResult(id, patt) {
 | 
			
		||||
            const lay = layer.load(1, { shade: [0.1, '#393D49'] });
 | 
			
		||||
            let data = { id: id, patt: patt };
 | 
			
		||||
            const res1 = await fetch(`/validatePayResult`, { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) });
 | 
			
		||||
            const rec1_info = await res1.json();
 | 
			
		||||
            const info = await new Promise((resolve, reject) => {
 | 
			
		||||
                setTimeout(() => {
 | 
			
		||||
                    data.patt = 0;
 | 
			
		||||
                    fetch(`/validatePayResult`, { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(data) })
 | 
			
		||||
                        .then((res2) => { return res2.json() }).then((rec2_info) => {
 | 
			
		||||
                            if (rec2_info.code == 0) {
 | 
			
		||||
                                layer.close(lay);
 | 
			
		||||
                                layer.msg('验证失败,稍后重新验证!');
 | 
			
		||||
                                resolve(true);
 | 
			
		||||
                            } else {
 | 
			
		||||
                                layer.close(lay);
 | 
			
		||||
                                layer.msg(rec2_info.msg);
 | 
			
		||||
                                resolve(false);
 | 
			
		||||
                            }
 | 
			
		||||
                        });
 | 
			
		||||
                }, 5000);
 | 
			
		||||
            })
 | 
			
		||||
            return info;
 | 
			
		||||
        }
 | 
			
		||||
        // <?php } ?>
 | 
			
		||||
        // 生成二维码
 | 
			
		||||
        async function getQrcode(text, QR) {
 | 
			
		||||
            const qrcodeUrl = await new Promise((resolve) => {
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user