<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>账户充值 - 用户中心 - {$kx.config.sitename}</title>
    <link rel="stylesheet" href="{$kx.config.resurl}/template/kxwebno1/css/global.css"/>
    <link rel="stylesheet" href="{$kx.config.resurl}/template/kxwebno1/css/style.css"/>
</head>
<body>
<!-- 头部 -->
{include file="/system/header"}

<!-- 内容 -->
<div class="pt-content">
    <!-- 一楼 -->
    <div class="pt-floor1 bg-white text-center mt10" style="padding: 50px;">
        {if $payinfo.platform == \App\Model\Order\Order::PLATFORM_ALIPAY}
        <img style="height: 50px;width: 50px" src="{$kx.config.resurl}/template/kxwebno1/images/alipay.png" alt="支付宝">
        {else if $payinfo.platform == \App\Model\Order\Order::PLATFORM_WECHAT}
        <img style="height: 50px;width: 50px" src="{$kx.config.resurl}/template/kxwebno1/images/wx.png" alt="微信">
        {/if}
        <div class="size16 color32 mt10">{$payinfo.platform|default='','支付宝','微信'}支付</div>
        <div class="pt-pay-qrcode mt40 pt10"
             style="background-color:#f5f5f5;height: 175px;width: 175px;margin: auto"></div>
        <div class="size16 color92 mt10">请打开[{$payinfo.platform|default='','支付宝','微信'}扫一扫]扫描上方二维码完成支付</div>
        <div class="size16 mt40 bold" style="color: #000">河南酷信网络科技有限公司</div>
        <div class="size16 mt15 bold">本次消费 <span class="color2 ml10">&yen;{$payinfo.amount}</span></div>
    </div>
</div>

<!-- 底部版权-->
{include file="/system/footer"}
<script src="{$kx.config.resurl}/template/kxwebno1/js/jquery.qrcode.min.js"></script>
<!-- js-->
<script>
    var querying = false;
    $('.pt-pay-qrcode').qrcode({width: 153, height: 153, text: '{$payinfo.code_url}'});
    var interval = setInterval(function () {
        if (querying === false) {
            querying = true;
            $.ajax('{link=user.pay.status}', {
                type: 'post',
                dataType: 'json',
                data: {orderid: '{$payinfo.order_id}',},
                complete: function () {
                    querying = false;
                },
                success: function (res) {
                    if (res.code) {
                        layer.alert(res.msg, {icon: 2,}, function (index) {
                            if (res.data.redirect) {
                                window.location.href = res.data.redirect;
                            } else {
                                layer.close(index);
                            }
                        });
                    } else {
                        switch (res.data.status) {
                            case parseInt('{=\App\Model\Order\Order::STATUS_PAY}'):
                                break;
                            case parseInt('{=\App\Model\Order\Order::STATUS_PAYING}'):
                                break;
                            case parseInt('{=\App\Model\Order\Order::STATUS_CLOSED}'):
                                clearInterval(interval);
                                layer.msg('支付失败,订单已关闭');
                                setTimeout(function () {
                                    window.location.href = '{link=user.index.index}';
                                }, 2000);
                                break;
                            case parseInt('{=\App\Model\Order\Order::STATUS_SUCCESS}'):
                                clearInterval(interval);
                                layer.msg('支付成功');
                                setTimeout(function () {
                                    window.location.href = '{link=user.index.index}';
                                }, 2000);
                                break;
                        }
                    }
                },
                error: function () {
                    clearInterval(interval);
                    layer.alert('支付失败，请稍后重试！', {icon: 2,}, function () {
                        window.history.back();
                    });
                }
            });
        }
    }, 100);
    setTimeout(function () {
        clearInterval(interval);
        layer.alert('支付超时，请重试！', {icon: 2,}, function () {
            window.history.back();
        });
    }, 3000000);
</script>
</body>
</html>