<?php
/**
 * 后台首页
 */
$title = '管理后台首页';
$tise = 'index';
include "header.php";
$index_data = admin::index_data();
?>
<!-- Start Content-->
<div class="container-fluid">
    <!-- end 分割线 -->
    <div class="row">
        <!--平台数据-->

        <div class="col-xl-4">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%;">
                    <div class="card widget-flat" id="data1">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-cart-simple widget-icon"
                                   style="background-color: #7C4DFF;color: white;"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="累计订单总数为：<?= $index_data['data1'] ?>条<br>可在运维面板里面清除订单!">
                                订单总数</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= $index_data['data1'] ?>条</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data2">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-cart-simple widget-icon"
                                   style="background-color: #43A047;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="今日订单数：<?= round($index_data['data2'], 0) ?>条<br>从<?= $times ?>开始计数">
                                今日订单</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data2'], 2) ?>条</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
            </div>
        </div>
        <div class="col-xl-4">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data3">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-cart-simple widget-icon"
                                   style="background-color: #FF9800;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="累计未完成订单数：<?= round($index_data['data3'], 0) ?>条<br>所有订单状态非已完成的订单将参与计数！">
                                未完成数</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data3'], 2) ?>条</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data4">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-rmb widget-icon"
                                   style="background-color: #FF7043;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="今日订单消耗成本：<?= round($index_data['data4'], 2) ?>元<br>只计入已完成状态订单的成本！">
                                今日成本</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data4'], 2) ?>元</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
            </div>
        </div>
        <div class="col-xl-4">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data5">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-rmb widget-icon"
                                   style="background-color: #1DE9B6;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="今日交易额为：<?= round($index_data['data5'], 2) ?>元<br>QQ:<?= round($index_data['data8'], 2) ?>元 / 微信:<?= round($index_data['data7'], 2) ?>元 / 支付宝:<?= round($index_data['data9'], 2) ?>元<br>只计算QQ/微信/支付宝在线收款金额！">
                                今日流水
                            </h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data5'], 2) ?>元</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->

                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data6">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-rmb widget-icon"
                                   style="background-color: #40C4FF;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="昨日交易额为：<?= round($index_data['data6'], 2) ?>元<br>只计算QQ/微信/支付宝在线收款金额！">
                                昨日流水
                            </h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data6'], 2) ?>元</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
            </div> <!-- end row -->
        </div>
        <!--平台数据end-->

        <!--用户数据-->

        <div class="col-xl-4">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data11">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px" title="用户总数">
                                <i class="layui-icon layui-icon-user widget-icon"
                                   style="background-color: #C6FF00;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0" text="平台用户总数为：<?= $index_data['data11'] ?>人">
                                用户总数</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= $index_data['data11'] ?>人</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data12">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-add-circle-fine widget-icon"
                                   style="background-color: #00C853;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="今日新增用户：<?= round($index_data['data12'], 0) ?>人">
                                今日新增</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data12'], 0) ?>人</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
            </div>
        </div>
        <div class="col-xl-4">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data13">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-add-circle-fine widget-icon"
                                   style="background-color: #69F0AE;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="昨日新增用户：<?= round($index_data['data13'], 0) ?>人">
                                昨日新增</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data13'], 0) ?>人</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data14">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-rmb widget-icon"
                                   style="background-color: #FFC107;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="用户累计消费金额为：<?= round($index_data['data14'], 2) ?>元<br>只计算非游客订单金额总数！<br>包含在线付款/余额付款金额！">
                                累计消费</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data14'], 2) ?>元</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
            </div>
        </div>
        <div class="col-xl-4">
            <div class="row">
                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data15">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-rmb widget-icon"
                                   style="background-color: #9575CD;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="用户今日消费金额为：<?= round($index_data['data15'], 2) ?>元<br>只计算非游客订单金额总数！<br>包含在线付款/余额付款金额！">
                                今日消费</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= round($index_data['data15'], 2) ?>元</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->

                <div class="col-lg-6 col-md-6 col-sm-6 col-xl-6" style="width: 50%">
                    <div class="card widget-flat" id="data16">
                        <div class="card-body">
                            <div class="float-right" style="width: 30px;height: 30px">
                                <i class="layui-icon layui-icon-chart widget-icon"
                                   style="background-color: #304FFE;color: white"></i>
                            </div>
                            <h5 class="text-muted font-weight-normal mt-0"
                                text="用户今日签到人数：<?= $index_data['data16'] ?>人">今日签到</h5>
                            <h5 class="mt-3 mb-0" style="font-weight: 300"><?= $index_data['data16'] ?>人</h5>
                        </div> <!-- end card-body-->
                    </div> <!-- end card-->
                </div> <!-- end col-->
            </div>
        </div>

        <div class="col-xl-6">
            <div class="card">
                <div class="card-body update">
                    <h4 class="header-title mb-2">网站更新日志 <?= $index_data['Versions'] ?> <a
                                href="javascript:index_update(1)">[检测]</a></h4>
                    <a href="?deployment_update=1" style="color: red;font-weight: 300;display: none;font-size: 0.9em;"
                       id="Versions_index"></a>
                    <div class="slimscroll" style="position: relative; overflow: hidden; width: auto; height: 656.8px;">
                        <div class="slimscroll"
                             style="max-height: 680px; overflow: hidden; width: auto; height: 656.8px;">
                            <div class="timeline-alt pb-1" id="vers_data"></div>
                            <!-- end timeline -->
                        </div>
                    </div> <!-- end slimscroll -->
                </div>
                <!-- end card-body -->
            </div>
            <!-- end card-->
        </div>
        <style>
            .message .notify-icon {
                display: none;
            }

            .message .notify-item {
                padding: 0;
                height: 3em;
                line-height: 3em;
                box-shadow: 0px 0px 2px #ccc
            }
        </style>
        <div class="col-lg-6">
            <div class="card">
                <div class="card-body update">
                    <h4 class="header-title" style="margin-bottom: 1.4em;">系统公告</h4>
                    <div class="slimscroll message " style="max-height: 230px;"></div>
                </div>
            </div>
        </div>

    </div>
    <!-- end row -->
</div>
<!-- container -->
</div>
<!-- content -->
</div>
</div>
<!-- END wrapper -->

<?php include "bottom.php"; ?>
<script>
    function index_update(type = 0) {
        var datar = layui.data('index_data');
        if (datar.data != undefined && type == 0) {
            var headertime = layui.data('indextime');
            var mis = headertime.time - 1;
            if (mis > 0) {
                read(JSON.parse(datar.data), type);
                layui.data('indextime', {
                    key: 'time'
                    , value: mis
                });
                return false;
            }
        }
        $.ajax({
            type: "post",
            url: "ajax.php?act=index_update",
            dataType: "json",
            success: function (data) {
                if (data.code == 1) {
                    var datas = JSON.stringify(data);
                    layui.data('index_data', {
                        key: 'data'
                        , value: datas
                    });
                    layui.data('indextime', {
                        key: 'time'
                        , value: 38
                    });
                    read(data, type)
                } else if (data.code == -2) {
                    layer.alert(data.msg, {icon: 2});
                    setTimeout(function () {
                        index_update();
                    }, 1000);
                } else {
                    layui.data('indextime', {
                        key: 'time'
                        , value: 0
                    });
                    layer.msg(data.msg, {icon: 4});
                }
            }
        });
    }

    function read(data = '', type = 0) {
        var content = '';
        for (let a = 0; a < data.data.length; a++) {
            content += '<div class="timeline-item">' +
                '<i class="layui-icon layui-icon-time bg-primary-lighten text-primary timeline-icon"></i>' +
                '<div class="timeline-item-info">' +
                '<a href="#" class="text-primary font-weight-bold mb-1 d-block">' + data.data[a]['versions'] + '</a>' +
                data.data[a]['content'] +
                '<p class="mb-0 pb-2">' +
                '<small class="text-muted">' + data.data[a]['date'] + '</small>' +
                '</p>' +
                '</div>' +
                '</div>';
        }
        $("#vers_data").html(content);
        $("#image_index").attr('src', data.image);
        $("#name_index").text(data.name);
        $(".update .slimScrollDiv,.update .slimscroll,.update .slimScrollDiv,.update .slimscroll").height(238);
        $(".update .slimScrollBar").height(58);
        $(".message").html($("#message").html());
        if ($(".message").html() == '') {
            location.reload()
        }
        if (data.state != 1) {
            layui.data('indextime', {
                key: 'time'
                , value: 0
            });
            $("#Versions_index").text('[ 有新的更新 ' + data.versions + ' ]');
            $("#Versions_index").show();
            layer.alert('有新的版本可供更新！<br><font color=#20b2aa>' + data.versions + ' <font color=red>[新]</font></font>', {
                title: '版本更新提醒', btn: ['更新', '取消'], btn1: function (layero, index) {
                    layui.data('index_data', null);
                    location.href = '?deployment_update=1';
                }
            })
        } else {
            if (type == 1) layer.msg('当前为最新版', {icon: 1})
        }
    }

    index_update()

    $(".widget-flat").click(function () {
        layer.tips($("#" + this.id + ' .font-weight-normal').attr('text'), '#' + this.id, {
            tips: 1
        });
    })

</script>
</body>
</html>