<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="lowerlist.aspx.cs" Inherits="AgentManager.admin.lowerlist" %>

<link rel="stylesheet" href="css/bootstrap/css/bootstrap.min.css"/>
<link rel="stylesheet" href="css/AdminLTE.css"/>
<link rel="stylesheet" href="css/plugins/iCheck/flat/blue.css"/>

<script src="js/jquery-1.9.1.min.js"></script>
<script src="css/bootstrap/js/bootstrap.min.js"></script>
<script src="css/My97DatePicker/WdatePicker.js"></script>
<script src="js/mainData.js"></script>
<div class="content-wrapper">

<section class="content-header">
    <h1>
        下级会员列表
        <small></small>
    </h1>

</section>
<form action="lowerlist.aspx" method="post">
    <div class="col-md-3">
        <table class="table">
            <tr>
            <td>
                <label>账号</label>
            </td>
            <td>
                <input name="username" id="username" value="<%= username %>" maxlength="15" autocomplete="off" class="form-control" list="a"/>

                <datalist id="a">


                    <% foreach (var item in li1) {


                    %>

                        <option value="<%= item.Username %>"><%= item.Myname %></option>

                    <%
                       } %>
                </datalist>
            </td>
            <td>
                <input type="submit" name="Submit" value="搜索" class="btn btn-block btn-primary"/>
            </td>
        </table>
    </div>

</form>
<section class="content">

    <div id="mainbox">
        <form id="form1" name="form1" method="post">

            <table class="box">

                <tr>
                    <td>
                        <strong>ID</strong>
                    </td>
                    <td>
                        <strong>账户名</strong>
                    </td>
                    <td>
                        <strong>姓名</strong>
                    </td>
                    <td>
                        <strong>上级</strong>
                    </td>
                    <td>
                        <strong>帐户类型</strong>
                    </td>
                    <td>
                        <strong>代理返点比例</strong>
                    </td>
                    <td>
                        <strong>系统余额</strong>
                    </td>
                    <td>
                        <strong>游戏余额</strong>
                    </td>
                    <td>
                        <strong>手机</strong>
                    </td>
                    <td>
                        <strong>创建时间</strong>
                    </td>
                    <td>
                        <strong>状态</strong>
                    </td>


                </tr>

                <% foreach (var item in li) { %>
                    <tr>
                        <td>
                            <strong><%= item.Id %></strong>
                        </td>
                        <td>
                            <div class="btn-group">
                                <button type="button" class="btn btn-primary btn-xs"><%= item.Username %></button>
                                <button type="button" style="height: 22px" class="btn btn-primary btn-xs dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                    <span class="caret"></span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li>
                                        <a href="lowerbetdata.aspx?username=<%= item.Username %>">会员下注记录</a>
                                    </li>
                                    <li>
                                        <a href="lowercreditdata.aspx?username=<%= item.Username %>">会员充值记录</a>
                                    </li>
                                    <li>
                                        <a href="lowershowdata.aspx?username=<%= item.Username %>">会员提现记录</a>
                                    </li>
                                    <li>
                                        <a href="lowerrecodedata.aspx?username=<%= item.Username %>">会员提现记录</a>
                                    </li>
                                    <li>
                                        <a href="agentincomereport.aspx?username=<%= item.Username %>">会员下注流水报表</a>
                                    </li>
                                    <li>
                                        <a href="lowerfsdata.aspx?username=<%= item.Username %>">会员反水记录</a>
                                    </li>
                                    <li>
                                        <a href="#" onclick="updatemoney(<%= item.Id %>,'<%= item.Username %>',<%= item.Mymoney %>)">加款扣款</a>
                                    </li>
                                </ul>
                            </div>
                        </td>
                        <td>
                            <strong><%= item.Myname %></strong>
                        </td>


                        <% if (item.Agentid != (Session["LoginUser"] as Model.usertableInfo).Id) { %>

                            <td>
                                <strong><%= (li2.FirstOrDefault(u => u.Id == item.Agentid) == null ? "信息错误" : li2.FirstOrDefault(u => u.Id == item.Agentid).Username) + "--" + (li2.FirstOrDefault(u => u.Id == item.Agentid) == null ? "信息错误" : li2.FirstOrDefault(u => u.Id == item.Agentid).Myname) %></strong>
                            </td>


                        <%
                           } else {
                        %>
                            <td>
                                <strong style="color: deepskyblue"><%= item.Is_agent ? "直属代理" : "直属会员" %> </strong>
                            </td>
                        <%
                           } %>
                        <td>
                            <strong><%= item.Is_agent ? "代理" : "会员" %></strong>
                        </td>
                        <td>
                            <strong>
                                <% if (item.Is_agent == true) { %>

                                    <span><%= Getagentfs(item.Username) %></span>
                                <%
                                   } %>
                                &nbsp;&nbsp;&nbsp;&nbsp;
                                <% if (item.Agentid == (Session["LoginUser"] as Model.usertableInfo).Id) {
                                       if (item.Is_agent) { %>
                                        <%--  <input type="button" onclick="deleteagent('<%=item.Username%>','True')" name="" class="btn btn-primary  btn-xs"  value="修改" />--%>
                                    <%
                                       } else if ((Session["LoginUser"] as Model.usertableInfo).addagent) {
                                    %>
                                        <input type="button" name="" class="btn btn-success btn-xs" onclick="addagent('<%= item.Username %>','True')" value="设为代理"/>
                                <%
                                       }
                                   } %>
                            </strong>
                        </td>
                        <td>
                            <strong><%= item.Mymoney %></strong>
                        </td>
                        <td><span>-</span>&nbsp;&nbsp;&nbsp;<input type="button" name="<%= item.Username %>,<%= item.gamepassword %>" onclick="getbimoney(this)" class="btn btn-primary btn-xs" name="name" value="刷新"/></td>
                        <td>
                            <strong><%= item.Myphone %></strong>
                        </td>
                        <td>
                            <strong><%= item.Regdatetime %></strong>
                        </td>
                        <td>
                            <strong>
                                <%= item.is_blacklist == true ? "黑名单 | " : item.Is_stop == true ? "停用 | " : "<span style='color:green'>正常 | </span>" %>
                                <%= item.Online == 1 ? "离线" : "<span style='color:green'>在线</span>" %>
                            </strong>
                        </td>


                    </tr>
                <%
                   } %>
            </table>
        </form>

    </div>

</section>


<div class="page" id="pagebox" runat="server">
    <div>页码<strong><%= pageindex %></strong>/<%= pagecount %>，共<span><%= count %></span>条记录，每页显示<span><%= pagesize %></span>条</div>
    <% if (pagecount > 1) { %>
        <div>
            <a class="btn btn-primary btn-sm" href="lowerlist.aspx?username=<%= username %>&page=<%= 1 %>">首页</a>
            <a class="btn btn-primary btn-sm" href="lowerlist.aspx?username=<%= username %>&page=<%= pageindex - 1 %>">上一页</a>
            <a class="btn btn-primary btn-sm" href="lowerlist.aspx?username=<%= username %>&page=<%= pageindex + 1 %>">下一页</a>
            <a class="btn btn-primary btn-sm" href="lowerlist.aspx?username=<%= username %>&page=<%= pagecount %>">末页</a>
        </div>
    <% } %>
</div>


</div>
<input type="hidden" id="isok" name="name" value="<%= isok %>"/>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" data-backdrop="false" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">新增反水比例</h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="hidid" name="name" value=""/>
                <%--   <label>等级名称</label>
    <input type="text" class="form-control" id="grade1" placeholder="">--%>

                <label>玩家类型</label>
                <input type="text" id="usertype1" disabled style="color: red" class="form-control" name="name" value="代理"/>

                <label>反水类型</label>
                <select disabled style="color: red" class="form-control" id="fstype1">
                    <% if (fstype == 1) { %>
                        <option value="1">流水</option>
                    <% } else { %>
                        <option value="2">盈利</option>
                    <% } %>
                </select>

                <br/>
                <div class="input-group">
                    <span class="input-group-addon" style="font-weight: bold">真人反水比例</span>
                    <input type="text" name="" maxlength="10" value="0" id="fs_live1" onblur="if (!(/^[\d]+\.?\d*$/.test(this.value)&&this.value<=<%= fs_live * 100 %>) ){ this.value='0'}" class="form-control"/>
                    <span class="input-group-addon">%</span>
                    <span style="color: red" class="input-group-addon">不超过<%= (fs_live * 100).ToString("f1") %>%</span>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon" style="font-weight: bold">电子反水比例</span>
                    <input type="text" name="" maxlength="10" value="0" id="fs_game1" onblur="if (!(/^[\d]+\.?\d*$/.test(this.value)&&this.value<=<%= fs_game * 100 %>) ){ this.value='0'}" class="form-control"/>
                    <span class="input-group-addon">%</span>
                    <span style="color: red" class="input-group-addon">不超过<%= (fs_game * 100).ToString("f1") %>%</span>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon" style="font-weight: bold">棋牌反水比例</span>
                    <input type="text" name="" maxlength="10" value="0" id="fs_chess1" onblur="if (!(/^[\d]+\.?\d*$/.test(this.value)&&this.value<=<%= fs_chess * 100 %>) ){ this.value='0'}" class="form-control"/>
                    <span class="input-group-addon">%</span>
                    <span style="color: red" class="input-group-addon">不超过<%= (fs_chess * 100).ToString("f1") %>%</span>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon" style="font-weight: bold">体育反水比例</span>
                    <input type="text" name="" maxlength="10" value="0" id="fs_sport1" onblur="if (!(/^[\d]+\.?\d*$/.test(this.value)&&this.value<=<%= fs_sport * 100 %>) ){ this.value='0'}" class="form-control"/>
                    <span class="input-group-addon">%</span>
                    <span style="color: red" class="input-group-addon">不超过<%= (fs_sport * 100).ToString("f1") %>%</span>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon" style="font-weight: bold">捕鱼反水比例</span>
                    <input type="text" name="" maxlength="10" value="0" id="fs_fish1" onblur="if (!(/^[\d]+\.?\d*$/.test(this.value)&&this.value<=<%= fs_fish * 100 %>) ){ this.value='0'}" class="form-control"/>
                    <span class="input-group-addon">%</span>
                    <span style="color: red" class="input-group-addon">不超过<%= (fs_fish * 100).ToString("f1") %>%</span>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon" style="font-weight: bold">彩票反水比例(只根据流水)</span>
                    <input type="text" name="" maxlength="10" value="0" id="fs_lottery1" onblur="if (!(/^[\d]+\.?\d*$/.test(this.value)&&this.value<=<%= fs_lottery * 100 %>) ){ this.value='0'}" class="form-control"/>
                    <span class="input-group-addon">%</span>
                    <span style="color: red" class="input-group-addon">不超过<%= (fs_lottery * 100).ToString("f1") %>%</span>
                </div>
                <br/>
                <div class="input-group">
                    <span class="input-group-addon" style="font-weight: bold">六合彩反水比例(只根据流水)</span>
                    <input type="text" name="" maxlength="10" value="0" id="fs_sixlottery1" onblur="if (!(/^[\d]+\.?\d*$/.test(this.value)&&this.value<=<%= fs_sixlottery * 100 %>) ){ this.value='0'}" class="form-control"/>
                    <span class="input-group-addon">%</span>
                    <span style="color: red" class="input-group-addon">不超过<%= (fs_sixlottery * 100).ToString("f1") %>%</span>
                </div>
                <br/>
            </div>


            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" onclick="butclick(this)" id="but" name="add" class="btn btn-primary">提交更改</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>

<div class="modal fade" id="addMoneyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" id="myModal1">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    会员加款/扣款
                </h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="userid" name="name" value=""/>
                <b>会员名字：</b><input id="usernamex" type="text" class="form-control" disabled="disabled" name="name" value=""/>
                <b>会员当前余额：</b><input id="usermoney" type="text" disabled="disabled" class="form-control" name="name" value=""/>
                <label>
                    <b>加款：</b><input type="radio" id="jia" checked="checked" name="name" value=""/>
                </label>
                <br/>
                <label>
                    <b>扣款：</b><input type="radio" id="jian" name="name" value=""/>
                </label>
                <br/>
                <b>加款金额：</b><input type="text" id="upmoney" onkeyup="value=value.replace(/[^\d]/g,'')" maxlength="7" class="form-control" name="name" value=""/>
                <b>加/扣类型：</b>
                <select id="jjtype" class="form-control">
                    <option value="5" selected="selected">优惠活动</option>
                    <option value="4">游戏返水</option>
                    <option value="1">扫码/转账支付</option>
                    <option value="5">周返利</option>
                    <option value="5">月返利</option>
                    <option value="6">其它情况</option>
                </select>
                <b>原因：</b><input id="yuany" type="text" class="form-control" name="name" value=""/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">
                    关闭
                </button>
                <button type="button" onclick="startclick()" class="btn btn-primary">
                    提交更改
                </button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->
</div>
<script>
    function addagent(name, bool) {
        if (bool == "True") {
            $('#but').show();
        } else {
            $('#but').hide();
        }

        $('#fs_game1').val(0)
        $('#fs_fish1').val(0)
        $('#fs_sport1').val(0)
        $('#fs_chess1').val(0)
        $('#fs_lottery1').val(0)

        $('#fs_sixlottery1').val(0)
        $('#but').attr('name', 'add,' + name + '')
        $('#myModal').modal('show')


    }
    //function deleteagent(name,bool) {
    //       if (bool == "True") {
    //         $('#but').show();
    //    } else {
    //        $('#but').hide();
    //    }

    //    $.post('ajax/getagentfs.ashx', { username: name }, function (msg) {
    //        if (msg == "0") {
    //            alert("查看失败")
    //        } else if (msg == "-1") {
    //            addagent(name)
    //        } else {
    //            var fss = msg.split(',');
    //            $('#fstype1').empty()
    //            if (fss[0]==1)
    //                $('<option value="1">流水</option>').appendTo($('#fstype1'))
    //            else
    //                $('<option value="2">盈利</option>').appendTo($('#fstype1'))

    //            $('#fs_live1').val((fss[1] * 100).toFixed(2))

    //            $('#fs_game1').val((fss[2] * 100).toFixed(2))

    //            $('#fs_fish1').val((fss[3] * 100).toFixed(2))

    //            $('#fs_sport1').val((fss[4] * 100).toFixed(2))

    //            $('#fs_chess1').val((fss[5] * 100).toFixed(2))

    //            $('#fs_lottery1').val((fss[6] * 100).toFixed(2))

    //            $('#fs_sixlottery1').val((fss[7] * 100).toFixed(2))

    //            $('#myModal').modal('show')
    //            $('#but').attr('name', 'up,' + name + '')
    //        }


    //    })



    //}
    function butclick(thiss) {

        var type = $(thiss).attr('name').split(',');
        var fss = fss = $('#fs_live1').val() + "," + $('#fs_game1').val() + "," + $('#fs_fish1').val() + "," + $('#fs_sport1').val() + "," + $('#fs_chess1').val() + "," + $('#fs_lottery1').val() + "," + $('#fs_sixlottery1').val();;
        if (type[0] == "add") {
            fss = fss + "," + $('#fstype1').val();
            $.post('ajax/addagent.ashx', { name: type[1], fss: fss }, function (msg) {
                alert(msg)
                window.location.reload();

            })
        } else if (type[0] == "up") {

            $.post('ajax/deleteagent.ashx', { name: type[1], fss: fss }, function (msg) {
                alert(msg)
                window.location.reload();
            })
        }

    }

    function getbimoney(thiss) {
        $(thiss).prop("disabled", "disabled").val("查询中");
        var x = $(thiss).attr('name');

        $.post("ajax/getbimoney.ashx", { name: x.split(',')[0], pwd: x.split(',')[1] }, function (msg) {
            var json = msg;
            if (json["statusCode"] != '01') {
                $(thiss).removeAttr("disabled").val("失败");
            } else if (json["statusCode"] == '01') {
                var num = 0;
                if (json["data"] != '') {
                    $.each(JSON.parse(JSON.stringify(json["data"])), function (z, y) {
                        if (y > 0) {
                            num += parseInt(y);
                        }
                    })
                }
                $(thiss).removeAttr("disabled").val("刷新");
                $(thiss).prev().html(num);
            }
        }, 'json')
    }
    
    function updatemoney(id, username,usermoney) {
        // $.post("ajax/getbimoney.ashx", { queryType: 'jkkk', name: username }, function (msg) {
        //     $('#usermoney').val(msg);
        // }, 'json')
        $('#usermoney').val(usermoney);
        $('#upmoney').val("")
        $('#yuany').val("")
        $('#jia').prop("checked", "true")
        $('#usernamex').val(username)
        $('#userid').val(id)
        $('#addMoneyModal').modal('show');
    }
    
    function startclick() {
        var name = $('#usernamex').val()
        var id = $('#userid').val()
        var upmoney = $('#upmoney').val()
        var jjtype = $('#jjtype').val()
        var yuany = $('#yuany').val()
        var type = $('#jia').prop("checked")
        if (id < 1 || id == "" || upmoney < 1 || upmoney.length > 7 || upmoney == "" || jjtype < 1 || name == "") {
            alert("请将条件填写完整！")
            return false;
        } if (yuany == "") {
            alert("必须填写原因！")
            return false;
        }
        $.post("ajax/updatemoney.ashx", { id: id, upmoney: upmoney, jjtype: jjtype, yuany: yuany, type: type, name: name }, function (msg) {
            alert(msg);
            window.location.reload()
        })

        $('#myModal').modal('hide');

        
    }

</script>