
@{
    ViewData["Title"] = "平台利润统计";
    Layout = "~/Pages/Shared/_MainLayout.cshtml";
    ViewBag.Nav = new string[] { "统计", "平台利润统计" };
}

<div class="row">
    <div class="col-sm-12">
        <div id="leftcontain" style="position:relative;float:left;width:215px;margin-right:-220px;background-color:#fff;height:780px;border-top:solid 1px #E7EAEC;display:none;">
            <div id="ztree" class="ztree" style="margin:5px 10px;max-height: 800px;overflow: auto;">

            </div>
        </div>
        <div style="float:right;width:100%;">
            <div id="rightcontain">
                <div class="ibox-content m-b-sm border-bottom">
                    <form id="toolbar">
                        <div class="form-inline" style="line-height:40px;">
                            <div class="form-group">
                                <label>&nbsp;</label>
                                <button type="button" class="btn btn-success" onclick="showleft();">分类筛选</button>
                            </div>
                            <div class="form-group">
                                <label>币种</label>
                                <select id="currency" name="currency" class="form-control">
                                    <option value="CNY">人民币</option>
                                    <option value="USD">美元</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>平台类型：</label>
                                <select id="platform" name="platform" class="form-control">
                                    <option value="">选择平台</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>站点：</label>
                                <select id="website" name="website" class="form-control">
                                    <option value="">选择站点</option>
                                </select>
                            </div>
                            <div class="form-group">
                                <label>付款时间</label>
                                <input id="start" name="start" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" placeholder="付款开始时间" />
                                <span>至</span>
                                <input id="end" name="end" type="text" class="form-control" style="width:130px;" value="@(DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd"))" placeholder="付款结束时间" />
                            </div>
                            <div class="form-group">
                                <label>发货时间</label>
                                <input id="shipstart" name="shipstart" type="text" class="form-control" style="width:130px;" placeholder="发货开始时间" />
                                <span>至</span>
                                <input id="shipend" name="shipend" type="text" class="form-control" style="width:130px;" placeholder="发货结束时间" />
                            </div>
                            <div class="form-group">
                                <label>&nbsp;</label>
                                <button type="button" class="btn btn-primary" onclick="list();"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                        </div>
                    </form>
                </div>
                <div class="ibox-content m-b-sm border-bottom">
                    <table id="roletable" class="table table-hover table-bordered table-condensed table-striped" style="table-layout:fixed;">
                        <thead>
                            <tr>
                                <th>平台</th>
                                <th style="width:70px;">订单数</th>
                                <th style="width:40px"></th>
                                <th>销售额</th>
                                <th style="width:40px"></th>
                                <th>产品成本</th>
                                <th style="width:70px;">客单价</th>
                                <th>平台费</th>
                                <th>头程费</th>
                                <th>尾程费</th>
                                <th>处理费(百伦)</th>
                                <th>平台操作费</th>
                                <th>预收金额</th>
                                <th>预收订单数</th>
                                <th>利润</th>
                                <th style="width:40px"></th>
                                <th>利润率%</th>
                                <th>退款</th>
                                <th>退款率%</th>
                            </tr>
                        </thead>
                        <tbody id="tb"></tbody>
                        <tfoot id="footer">

                        </tfoot>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
@section css{
    <link href="~/css/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
    <style>
        .mules {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
        }

        .alink {
            color: cornflowerblue;
            cursor: pointer;
        }

        .tablesorter-headerDesc {
            background-position: right;
            background-repeat: no-repeat;
            padding-right: 30px;
            background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZUlEQVQ4y2NgGAWjYBSggaqGu5FA/BOIv2PBIPFEUgxjB+IdQPwfC94HxLykus4GiD+hGfQOiB3J8SojEE9EM2wuSJzcsFMG4ttQgx4DsRalkZENxL+AuJQaMcsGxBOAmGvopk8AVz1sLZgg0bsAAAAASUVORK5CYII=' );
        }

        .tablesorter-headerAsc {
            background-position: right;
            background-repeat: no-repeat;
            padding-right: 30px;
            background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABMAAAATCAYAAAByUDbMAAAAZ0lEQVQ4y2NgGLKgquEuFxBPAGI2ahhWCsS/gDibUoO0gPgxEP8H4ttArEyuQYxAPBdqEAxPBImTY5gjEL9DM+wTENuQahAvEO9DMwiGdwAxOymGJQLxTyD+jgWDxCMZRsEoGAVoAADeemwtPcZI2wAAAABJRU5ErkJggg==');
        }

       
    </style>
}
@section scripts{
    <script src="~/js/jquery.ztree.core.min.js"></script>
    <script src="~/js/jquery.ztree.excheck.min.js"></script>
    <script src="~/js/jquery.tablesorter.min.js" type="text/javascript"></script>
    <script type="text/javascript">
        var tb;
        $(document).ready(function () {
            laydate.render({ elem: '#start' });
            laydate.render({ elem: '#end' });

            laydate.render({ elem: '#shipstart' });
            laydate.render({ elem: '#shipend' });
            
            list();

            listPlatform();

            listcategory12();

            $('#platform').change(function () {
                listwebsite();
            })
        })

        function list() {
            var shipstart = $('#shipstart').val();
            var shipend = $('#shipend').val();
            var start = $('#start').val();
            var end = $('#end').val();
            if ((shipstart != '' || shipend != '') && (start != '' || end != '')) {
                layer.alert('搜索条件不能同时选择付款时间和发货时间，只能选其一。');
                return false;
            }

            if (start == '' && end == '' && shipstart == '' && shipend == '') {
                layer.alert('请选择时间进行搜索。');
                return false;
            }

            var s = '';

            try {
                s = getChkNode();
            } catch (e) {
                s = '';
            }

            var lindex = layer.load(1, { shade: false }); //0代表加载的风格，支持0-2
            $.submit({
                type:'POST',
                url: '@Url.Content("~/Reports/Orders/PlatformProfitCountJson")',
                paramData: $("#toolbar").serialize() + '&skucategoryids=' + s,
                func: function (result) {
                    layer.close(lindex);
                    if (result && result.length > 0) {
                        $('#tb').html('');
                        $('#footer').html('');
                        for (var i = 0; i < result.length-1; i++) {
                            var s = '<tr><td class="platform"><a href="javascript:;" onclick="ShowWebsite(\'' + result[i].platform_type + '\');">' + result[i].platform_type + '</a></td>';
                            s += '<td class="alink"><a href="javascript:;"  onclick="ShowDetail(\'' + result[i].platform_type + '\',\'订单数\',\'\',0)" >' + result[i].order_count + '</a></td>';
                            s += '<td><img style="width:16px;margin-left:3px" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'' + result[i].platform_type + '\',\'订单数\',\'order_count\');" title="点击查看订单数曲线图"></td>';
                            s += '<td class="alink"><a href="javascript:;"  onclick="ShowDetail(\'' + result[i].platform_type + '\',\'销售额\',\'amount_sales\',0)"> ' + result[i].amount_sales + '</a></td>';
                            s += '<td><img style="width:16px;margin-left:3px" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'' + result[i].platform_type + '\',\'销售额\',\'amount_sales\');" title="点击查看销售额曲线图"></td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'产品成本\',\'cost_product\',1)">' + result[i].cost_product + '</td>';
                            s += '<td>' + result[i].customerprice + '</td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'平台费用\',\'cost_platform_fee\',1)">' + result[i].cost_platform_fee + '</td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'头程费\',\'cost_first\',1)">' + result[i].cost_first + '</td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'尾程费\',\'cost_tail\',1)">' + result[i].cost_tail + '</td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'处理费(百伦)\',\'cost_handle_bailun\',1)">' + result[i].cost_handle_bailun + '</td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'第三方仓处理费\',\'cost_handle_platform\',1)">' + result[i].cost_handle_platform + '</td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'预收款\',\'amount_prepaid\',1)">' + result[i].amount_prepaid + '</td>';
                            s += '<td class="alink">' + result[i].noshippingcount + '</td>';
                            s += '<td class="alink"><a href="javascript:;" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'利润\',\'profit_total\',1)">' + result[i].profit_total + '</a></td>';
                            s += '<td><img style="width:16px;margin-left:3px" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'' + result[i].platform_type + '\',\'利润\',\'profit_total\');" title="点击查看利润曲线图"></td>';
                            s += '<td>' + result[i].profit_rate + '</td>';
                            s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'退款金额\',\'amount_refund\',1)">' + result[i].amount_refund + '</td>';
                            s += '<td>' + result[i].amount_refund_rate + '</td>';
                            $('#tb').append(s);
                        }

                        $("#roletable").trigger("destroy");
                        $("#roletable").tablesorter();

                        var i = result.length - 1;
                        var foot_s = '<tr><td class="platform"><a href="javascript:;" onclick="ShowWebsite(\'' + result[i].platform_type + '\');">' + result[i].platform_type + '</a></td>';
                        foot_s += '<td class="alink"><a href="javascript:;"  onclick="ShowDetail(\'' + result[i].platform_type + '\',\'订单数\',\'\',0)" >' + result[i].order_count + '</a></td>';
                        foot_s += '<td><img style="width:16px;margin-left:3px" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'\',\'订单数\',\'order_count\');" title="点击查看曲线图"></td>';
                        foot_s += '<td class="alink"><a href="javascript:;"  onclick="ShowDetail(\'' + result[i].platform_type + '\',\'销售额\',\'amount_sales\',0)"> ' + result[i].amount_sales + '</a></td>';
                        foot_s += '<td><img style="width:16px;margin-left:3px" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'\',\'销售额\',\'amount_sales\');" title="点击查看曲线图"></td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'产品成本\',\'cost_product\',1)">' + result[i].cost_product + '</td>';
                        foot_s += '<td>' + result[i].customerprice + '</td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'平台费用\',\'cost_platform_fee\',1)">' + result[i].cost_platform_fee + '</td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'头程费\',\'cost_first\',1)">' + result[i].cost_first + '</td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'尾程费\',\'cost_tail\',1)">' + result[i].cost_tail + '</td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'处理费(百伦)\',\'cost_handle_bailun\',1)">' + result[i].cost_handle_bailun + '</td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'第三方仓处理费\',\'cost_handle_platform\',1)">' + result[i].cost_handle_platform + '</td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'预收款\',\'amount_prepaid\',1)">' + result[i].amount_prepaid + '</td>';
                        foot_s += '<td class="alink">' + result[i].noshippingcount + '</td>';
                        foot_s += '<td class="alink"><a href="javascript:;" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'利润\',\'profit_total\',1)">' + result[i].profit_total + '</a></td>';
                        foot_s += '<td><img style="width:16px;margin-left:3px" src="@Url.Content("~/img/chart-icon.png")" onclick="ShowChart(\'\',\'利润\',\'profit_total\');" title="点击查看曲线图"></td>';
                        foot_s += '<td>' + result[i].profit_rate + '</td>';
                        foot_s += '<td class="alink" onclick="ShowDetail(\'' + result[i].platform_type + '\',\'退款金额\',\'amount_refund\',1)">' + result[i].amount_refund + '</td>';
                        foot_s += '<td>' + result[i].amount_refund_rate + '</td>';
                        $('#footer').append(foot_s);
                    }
                    else {
                        $('#tb').html('');
                        $('#footer').html('');
                        layer.alert('没有找到相应数据！');
                    }
                }
            })

        }

        function listPlatform() {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListPlatform")',
                type:'POST',
                paramData: '',
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#platform').html('<option value="">选择平台</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#platform').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

        function listwebsite()
        {
            var p = $('#platform').val();
            if (p == '') {
                $('#website').html('<option value="">选择站点</option>');
                return false;
            }

            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListWebSite")',
                type:'POST',
                paramData: 'platform=' + p,
                func: function (result) {
                    if (result != null && result != undefined) {
                        $('#website').html('<option value="">选择站点</option>');
                        for (var i = 0; i < result.length; i++) {
                            $('#website').append('<option value="' + result[i] + '">' + result[i]+'</option>');
                        }
                    }
                }
            })
        }

        function ShowWebsite(platform) {
            if (platform == '总计') {
                return false;
            }

            var start = $('#start').val();
            var end = $('#end').val();

            layer_show(platform + ' 按站点统计', '@Url.Content("~/Reports/Orders/PlatformProfitCountByWebSite?platform=")' + platform + '&start=' + start + '&end=' + end, '90%', '90%');

        }

        function ShowDetail(platform, coltitle, colval, single) {
            layer_show(platform + " " + $('#start').val() + "至" + $('#end').val() + ' 订单明细', '@Url.Content("~/Reports/Orders/ListOrderDetail?platform=")' + platform + '&start=' + $('#start').val() + '&end=' + $('#end').val() + '&col=' + colval + '&coltitle=' + coltitle + '&showsingle=' + single + '&shipstart=' + $('#shipstart').val() + '&shipend=' + $('#shipend').val(), '90%', '90%');
        }


        function showleft() {
            var c = $('#leftcontain').css('display');
            if (c == 'none') {
                $('#leftcontain').css('display', 'inline');
                $("#rightcontain").animate({ marginLeft: "220px" });
            }
            else {
                $('#leftcontain').css('display', 'none');
                $("#rightcontain").animate({ marginLeft: "0px" });
            }
        }

        function listcategory12()
        {
            $.submit({
                url: '@Url.Content("~/Reports/Orders/ListSkuCategoryOneAndSecondLevel")',
                paramData: '',
                type: 'POST',
                func: function (result) {
                    var setting = {
                        check: {
                            chkStyle:'checkbox',
                            enable: true
                        }
                    };
                    zTreeObj = $.fn.zTree.init($("#ztree"), setting, eval('('+result+')'));
                }
            })
        }

        function getChkNode() {
            var s = '';
            var o = $.fn.zTree.getZTreeObj("ztree");
            var nodes = o.getCheckedNodes();
            for (var i in nodes) {
                if (nodes[i].children == null || nodes[i].children.length <= 0) {
                    s += (nodes[i].id) + '|';
                }
            }

            return s;
        }

        function ShowChart(platform, title, colval) {

            var s = '';

            try {
                s = getChkNode();
            } catch (e) {
                s = '';
            }

            var shipstart = $('#shipstart').val();
            var shipend = $('#shipend').val();
            var start = $('#start').val();
            var end = $('#end').val();

            if (start == '' && end == '') {
                layer.alert('请选择付款时间。');
                return false;
            }

            
            layer_show(platform + " " + title+"曲线图", '@Url.Content("~/Reports/Orders/OrderProfitGraph?platform=")' + platform + '&start=' + $('#start').val() + '&end=' + $('#end').val() + '&col=' + colval + '&shipstart=' + $('#shipstart').val() + '&shipend=' + $('#shipend').val() + '&currency=' + $('#currency').val() + '&skucategoryids=' + s + '&titlename=' + title, '90%', '90%');
        }

    </script>

}


