<?php
/**
 * Author：晴天 QQ：1186258278
 * Creation：2020/3/21 13:08
 * Filename：checkstandM.php
 * 订单确认？
 */
if (!defined('IN_CRONLITE')) die();
if (empty((int)$_QET['order'])) show_msg('警告', '参数异常,请重新提交！', 2, '/');
$DataOrder = $DB->get_row("SELECT * FROM `sky_journal` WHERE `count` = '{$_QET['order']}' AND `name` = '订单缓存' AND `uid` = -1024 LIMIT 1");
if (!$DataOrder) show_msg('警告', '订单异常,获取订单失败！', 2, '/');
$data = config::common_unserialize($DataOrder['content'])['data'][0];
$DataGoods = $DB->get_row("SELECT * FROM `sky_goods` WHERE `gid` = '{$data['gid']}' AND `state` = 1 LIMIT 1");
if (!$DataGoods) show_msg('警告', '商品不存在或已下架,请返回主页重新选择商品！', 2, '/');
if (empty($data['gid']) || empty($data['input']) || empty($data['num']) || empty($data['conts'])) show_msg('警告', '订单创建失败，订单参数异常！，请返回重新创建订单！', 4, '/?gid=' . $DataGoods['gid'] . '&cid=' . $DataGoods['cid']);
$DataUser = login_data::user_data();
if (!in_array(7, json_decode($DataGoods['method'], TRUE))) {
    $data['num'] = 1;
}

$pricer = price::price_uid(login_data::user_grade(($DataUser == false ? -1 : $DataUser['id'])), $DataGoods['profits'], $DataGoods['money']);
if ($DataGoods['freight'] <> -1) {
    $freight = $DB->get_row("SELECT * FROM `sky_freight` WHERE `id` = '{$DataGoods['freight']}' LIMIT 1");
    if ($freight) {
        $price = price::freight($freight, $data['input'], $pricer['price'], $data['num']);
    }
}

if (isset($_QET['set'])) $data['conts'] = '<font size="3" color="#f4a460">考虑到用户隐私问题，平台已经隐藏该用户下单信息</font>';

$url_doem = is_https(false) . href() . $_SERVER['PHP_SELF'] . '?' . $_SERVER['QUERY_STRING'] . '&set';
$_SESSION['url_pr'] = $url_doem;
$url_doem = str_replace("[url]", $url_doem, $conf['share_url']);
$pay = 0;
?>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title><?= '购买 [' . $DataGoods['name'] . ' ] 确认订单 - ' . $conf['sitename'] ?></title>
    <meta name="keywords" content="<?= $conf['keywords'] ?>">
    <meta name="description" content="<?= $conf['description'] ?>">
    <link rel="stylesheet" type="text/css" href="<?php echo $cdnserver; ?>assets/layui/css/layui.css"/>
    <link href="<?php echo $cdnpublic ?>limonte-sweetalert2/7.33.1/sweetalert2.min.css" rel="stylesheet">
    <link href="<?php echo $cdnpublic ?>animate.css/3.7.2/animate.min.css" rel="stylesheet">
</head>
<style>
    .information {
        font-size: 0.9em;
        color: black
    }
</style>
<body style="<?= background::image() == false ? 'background:#f5f5f5;' : background::image() ?>;overflow-x: hidden;font-family: '微软雅黑 Light'"
      order="<?= $_QET['order'] ?>" data-level_arr='<?= json_encode($pricer) ?>'>
<div class="layui-container" style="padding: 0">
    <div class="layui-row layui-col-space8">
        <div class="layui-col-xs12"
             style="z-index: 3;;background-color: white;position: fixed;top: 0;left: 0;height: 3em;line-height: 1.5em;box-shadow: 3px 3px 16px #ccc">
            <a href="<?= '/?gid=' . $DataGoods['gid'] . '&cid=' . $DataGoods['cid'] ?>">
                <p style="margin-top: 0.5em;font-size: 1.2em"><span class="layui-icon layui-icon-left"></span> 确认订单</p>
            </a>
        </div>
        <div class="layui-col-xs12" style="margin-top: 3.5em;padding: 1em;">
            <div class="layui-card" style="border-radius: 0.5em">
                <div class="layui-row layui-col-space8">
                    <div class="layui-col-xs2">
                        <div style="border-radius: 0.5em;width: 3em;text-align: center;height: 3em;line-height: 3em;color:white;margin: 0.8em;box-shadow: 3px 3px 16px #eee">
                            <img src="<?= ($DataUser == false ? '/assets/img/pays.png' : $DataUser['image']) ?>"
                                 width="35"/>
                        </div>
                    </div>
                    <div class="layui-col-xs10">
                        <div class="layui-card-header" style="font-size: 1.1em;font-family: '微软雅黑 Light'">
                            下单信息
                        </div>
                        <div class="layui-card-body information">
                            <?= htmlspecialchars_decode($data['conts']) ?>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-col-xs12" style="padding: 0.1em 1em 0 1em;">
            <div class="layui-card" style="border-radius: 0.5em">
                <div class="layui-card-header">
                    <img src="<?= $conf['logo'] ?>" style="height:18px; "/> <?= $conf['sitename'] ?>
                    <span style="float: right;"><?= $DataGoods['sqid'] == -3 ? '<span class="layui-badge layui-bg-orange">自动发卡' : '<span class="layui-badge" style="background-color: lightsalmon">自动发货' ?></span></span>
                </div>
                <div class="layui-row layui-col-space8">
                    <div class="layui-col-xs2">
                        <div style="border-radius: 0.5em;width: 3em;text-align: center;height: 3em;line-height: 3em;background-color: #ff6f58;color:white;margin: 0.8em;box-shadow: 3px 3px 16px #eee">
                            <img src="<?= $DataGoods['image'] ?>" style="width: 100%;border-radius: 0.5em"/>
                        </div>
                    </div>
                    <div class="layui-col-xs10">
                        <div class="layui-card-header"
                             style="font-size: 1.1em;line-height: 2em;height:auto;">
                            <?= $DataGoods['name'] ?>
                        </div>
                        <div class="layui-card-body information layui-text" style="line-height: 2em">
                            <p><span onclick="layer.msg('份数×数量=购买数量')">购买数量</span><span
                                        style="float: right;"><?= $DataGoods['quantity'] * $data['num'] ?>个</span></p>
                            <p>售价等级<span style="float: right;"><a id="level"><?= $pricer['level'] ?></a></span></p>
                            <p>商品售价<span
                                        style="float: right;"><?= round($pricer['price'] * $data['num'],2) ?> 元</span>
                            </p>
                            <p><?= $conf['currency'] ?>兑换<span
                                        style="float: right;"><?= $pricer['points'] * $data['num'] ?> <?= $conf['currency'] ?></span>
                            </p>
                            <p style="<?= $DataGoods['freight'] == -1 ? 'display: none' : '' ?>">运费金额：<span
                                        style="float: right;"><?= (($price - ($pricer['price'] * $data['num'])) <= 0 ? '免运费' : '<font color="#228b22">' . $_SESSION['retos'] . '</font><font color="#ff4500">' . round(($price - ($pricer['price'] * $data['num'])),2) . '元') . '</font>' ?></span>
                            </p>
                            <p style="float: right;margin-top: 0.8em;font-size: 1.05em">共<?= $data['num'] ?>份 小计：<font
                                        color="#ff4500"
                                        style="font-size: 1.1em">￥<?= $DataGoods['freight'] == -1 ? round($pricer['price'] * $data['num'], 2) : $price ?></font>
                            </p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12" style="padding: 0.1em 1em 0 1em;margin-top: 0.9em;margin-bottom: 5em;">
            <div class="layui-card" style="border-radius: 0.5em">

                <div class="layui-card-body layui-form layui-form-pane" style="padding: 0.5em">
                    <?php if (!in_array(1, json_decode($DataGoods['method'], TRUE))) {
                        $conf['pay_alipay'] = $conf['pay_wxpay'] = $conf['pay_qqapy'] = -1;
                    } ?>
                    <div style="padding: 0.3em;border-radius: 0.3em;line-height: 2em;height: 2.5em;">
                        <input type="radio" name="pay" <?= ($conf['pay_alipay'] <> -1 ? '' : 'disabled') ?>
                               value="1"
                               title="<p style='width:100%'><img src='/assets/img/alipay.png' width='13px' /> 支付宝</p>">
                    </div>
                    <div style="padding: 0.3em;border-radius: 0.3em;line-height: 2em;height: 2.5em;">
                        <input type="radio" name="pay" <?= ($conf['pay_wxpay'] <> -1 ? '' : 'disabled') ?> value="2"
                               title="<p style='width:100%'><img src='/assets/img/wxpay.png' width='13px' /> 微信</p>">
                    </div>
                    <div style="padding: 0.3em;border-radius: 0.3em;line-height: 2em;height: 2.5em;">
                        <input type="radio" name="pay" <?= ($conf['pay_qqapy'] <> -1 ? '' : 'disabled') ?> value="3"
                               title="<p style='width:100%'><img src='/assets/img/qqpay.png' width='13px' /> QQ钱包</p>">
                    </div>
                    <div style="padding: 0.3em;border-radius: 0.3em;line-height: 2em;height: 2.5em;">
                        <input type="radio" name="pay"
                               <?= (in_array(2, json_decode($DataGoods['method'], TRUE)) ? '' : 'disabled') ?> value="4"
                               title="<p style='width:100%'><img src='/assets/img/moneypay.png' width='13px' /> 余额 <span style='color:#999;font-size:0.8em;margin-left:1em'><?= ($DataUser == false ? '未登陆无法使用' : '剩' . round($DataUser['money'], 2) . '元') ?></span></p>">
                    </div>
                    <div style="padding: 0.3em;border-radius: 0.3em;line-height: 2em;height: 2.5em">
                        <input type="radio" name="pay"
                               <?= (in_array(3, json_decode($DataGoods['method'], TRUE)) ? '' : 'disabled') ?> value="5"
                               title="<p style='width:100%'><img src='/assets/img/total.png' width='13px' /> <?= $conf['currency'] ?> <span style='color:#999;font-size:0.8em;margin-left:1em'><?= ($DataUser == false ? '未登陆无法使用' : '剩' . round($DataUser['currency'], 0) . $conf['currency']) ?></span></p>">
                    </div>
                    <div id="demo_url" data-url="<?= $url_doem ?>"
                         style="padding: 0.3em;border-radius: 0.3em;line-height: 2em;height: 2.5em">
                        <input type="radio" name="pay" value="6"
                               title="<p style='width:100%'><img src='/assets/img/payd.png' width='13px' /> 帮我付 (朋友代付)</p>">
                    </div>
                </div>
            </div>
        </div>
        <div class="layui-col-xs12"
             style="z-index: 3;;background-color: white;position: fixed;bottom: 0;left: 0;height: 4em;line-height: 3.5em;box-shadow: 0px 0px 8px #ccc;text-align: right;">
            <span style="font-size: 1.2em;float: left;text-indent: 0.5em"><span
                        style="color: #A6A6A6;font-size: 0.9em">共<?= $data['num'] ?>份，</span><span>合计：</span><font
                        color="#ff4500">￥<?= $DataGoods['freight'] == -1 ? round($pricer['price'] * $data['num'], 2) : $price ?>元</font></span>
            <button class="layui-btn layui-btn-danger layui-btn-radius" onclick="merchandise.get_data()"
                    style="background: linear-gradient(to right, #f85032, #e73827);margin-right: 0.5em;">提交订单
            </button>
        </div>
    </div>
</div>

<script src="<?= $cdnpublic ?>jquery/3.4.1/jquery.min.js"></script>
<script src="<?php echo $cdnserver; ?>assets/layui/layui.all.js"></script>
<script src="<?php echo $cdnpublic ?>limonte-sweetalert2/7.33.1/sweetalert2.min.js"></script>
<script type="text/javascript" src="http://www.jq22.com/demo/copy20161120/dist/clipboard.min.js"></script>
<script src="<?php echo $cdnserver; ?>assets/js/main.js?var=<?= $accredit['versions'] ?>"></script>
<script>var checkstandM = <?=$DataGoods['gid']?>;</script>
<script src="/template/public/template.js?var=<?= $accredit['versions'] ?>"></script>
<script>
    var level_arr = JSON.parse($("body").attr('data-level_arr')).level_arr;
    var contents = '';
    count = 1;
    count_arr = 0;
    $.each(level_arr, function (key, val) {
        if (count == 1) {
            tips = '<span style="float:right;margin-right: 1em;" >当前 <font color=red>' + val.price.toFixed(2) + '元</font></span>';
        } else {
            tips = '<span style="float:right;margin-right: 1em;color:seagreen;" >' + val.price.toFixed(2) + '元</span>';
        }
        contents += '<p>等级：' + val.name + tips + '</p>';
        ++count;
        ++count_arr;
    });
    if (count_arr <= 1) {
        $("#level").attr('onclick', 'layer.msg(\'恭喜！您当前为最高等级密价！\')');
    } else {
        layer.tips('<font color="white">此商品有更多优惠哦！</font>', '#level', {tips: [3, 'red']});
        $("#level").attr('onclick', 'layer.alert(\'' + contents + '\',{title:\'密价等级表\',btn:[\'朕已阅\',\'升级密价\'],shade: [0.8, \'#000\'],shadeClose:true,btn2:function(layero,index){window.open(\'/user/grade.php\')}})');
    }
    $.ajax({
        type: "POST",
        url: "/ajax.php?act=prevent",
        dataType: "json",
        success: function (data) {
            $("#demo_url").attr('data-url', data.msg);
        },
        error: function () {
            layer.alert('加载失败！');
        }
    });
</script>
</body>
</html>
