<?php include Doo::conf()->SITE_PATH .  Doo::conf()->PROTECTED_FOLDER . "viewc/admin/headAndLeftWrapper.php"; ?>
<div class="mainWrapper container-fluid">
    <div class="page-header pageTop">
        <h3>订单管理</h3>
    </div>
    <div class="shopContent clearfix">
        <!-- <div class="btnGroup">
          <a type="button" class="btn btn-primary" data-toggle="modal" data-target="#myModalAdd">添加管理员</a>
        </div> -->
        <!--<div class="sort" style="margin-right:20px;">-->
            <!--<select class="form-control" id="selectpay">-->
                <!--<option value="0">支付方式</option>-->
                <!--<option value="alipay">支付宝</option>-->
                <!--<option value="offline">银行转账</option>-->
                <!--<option value="recharge">网银在线</option>-->
                <!--<option value="voucher">代金券</option>-->
            <!--</select>-->
        <!--</div>-->
        <div class="sort" style="margin-right:20px;">
            <select class="form-control" id="selectstatus">
                <option value="all" <?php if( $data['status']=='all' ): ?>  selected <?php endif; ?>>全部订单</option>
                <option value="succ" <?php if( $data['status']=='succ' ): ?>  selected <?php endif; ?>>交易成功</option>
                <option value="waitting:unpay" <?php if( $data['status']=='waitting:unpay' ): ?> selected <?php endif; ?>>交易未成功</option>
            </select>
        </div>
        <div class="search">
            <div class="input-group">
                <input type="text" value="<?php echo $data['search']; ?>" id="search" class="form-control" placeholder="注册手机/注册邮箱/称呼">
          <span class="input-group-btn">
            <button class="btn btn-default" id="searchbtn">点击搜索</button>
          </span>
            </div>
        </div>
    </div>
    <div class="tableContent">
        <table class="table table-hover">
            <thead>
            <tr>
                <th width="200">支付单号</th>
                <th width="200">时间</th>
                <th width="100">支付方式</th>
                <th width="80">存入金额</th>
                <th colspan="3" class="text-center bg-success">充值账号(手机/邮箱/称呼)</th>
                <th width="90">支付状态</th>
                <th width="200">操作</th>
            </tr>
            </thead>
            <?php if( isset($data['userArray']) && !empty($data['userArray']) ): ?>
            <?php foreach($data['userArray'] as $k1=>$v1): ?>
            <tr>
                <td><?php echo $v1['trade_sn']; ?></td>
                <td><?php echo formatDate($v1['addtime']); ?></td>
                <td><?php if( $v1['pay_type'] == 'voucher' ): ?><span title="<?php echo $v1['payment']; ?>">代金券</span><?php else: ?><?php echo $v1['payment']; ?><?php endif; ?></td>
                <td><?php echo $v1['money']; ?></td>
                <td><?php if( !empty($v1['mobile']) ): ?><?php echo $v1['mobile']; ?> <i class="text-success glyphicon glyphicon-ok-circle"></i><?php endif; ?></td>
                <td><?php if( !empty($v1['email']) ): ?><?php echo $v1['email']; ?> <?php if( empty($v1['status2']) ): ?><i class="text-danger glyphicon glyphicon-ban-circle"></i><?php else: ?><i class="text-success glyphicon glyphicon-ok-circle"></i><?php endif; ?><?php endif; ?></td>
                <td><?php echo $v1['username']; ?></td>
                <td><?php if( $v1['status']=='unpay' ): ?>交易未支付<?php endif; ?>
                    <?php if( $v1['status']=='succ' ): ?> 交易成功<?php endif; ?>
                    <?php if( $v1['status']=='failed' ): ?> 交易失败<?php endif; ?>
                    <?php if( $v1['status']=='error' ): ?> 交易错误<?php endif; ?>
                    <?php if( $v1['status']=='progress' ): ?> 交易处理中<?php endif; ?>
                    <?php if( $v1['status']=='timeout' ): ?> 交易超时<?php endif; ?>
                    <?php if( $v1['status']=='cancel' ): ?> 交易取消<?php endif; ?>
                    <?php if( $v1['status']=='waitting' ): ?>等待付款<?php endif; ?></td>
                <td>
                    <?php if( !empty($v1['checker']) ): ?> <?php echo $v1['checker']; ?> <?php endif; ?>
                    <?php if( $v1['payment']=="银行转账"&&$v1['status']!='succ' ): ?><a class="btn btn-info btn-xs" data-toggle="modal" data-target="#myModalGj" onclick="sumbitorder('<?php echo $v1['id']; ?>','<?php echo $v1['trade_sn']; ?>','<?php echo $v1['money']; ?>')">改价</a><?php endif; ?>
                    <?php if( $v1['status']!='succ' ): ?><a class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal" onclick="closeorder('<?php echo $v1['id']; ?>')">关闭</a><?php endif; ?>
                    <?php if( $v1['status']=='unpay'or$v1['status']=='waitting' ): ?>
                    <a class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModalEdit" onclick="checkorder('<?php echo $v1['id']; ?>','<?php echo $v1['money']; ?>')">手动确认</a>
                    <?php endif; ?>
                    <!--<a href="#" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#myModal">关闭</a>-->
                    <!--<a href="#" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#myModalEdit">手动确认</a>-->
                </td>
            </tr>
            <?php endforeach; ?>
            <?php endif; ?>
        </table>
    </div>
    <nav style="margin: 20px 0">
        <?php echo $data['pager']; ?>
    </nav>
</div>
<!-- mainWrapper end -->
</div>

<!-- 改价 -->
<div class="modal fade" id="myModalGj" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel">订单改价</h4>
            </div>
            <form class="form-horizontal" action="/m/pay/modify" id="orderchange" method="post">
            <div class="modal-body">
                <div class="form-group">
                    <label for="order_sn" class="col-sm-3 control-label">订单号</label>
                    <div class="col-sm-7">
                        <input type="text" class="form-control" id="order_sn" value="" readonly>
                    </div>
                </div>
                <div class="form-group">
                    <label for="money" class="col-sm-3 control-label">金额数</label>
                    <div class="col-sm-7">
                        <input type="number" class="form-control" name="money" id="money" value="">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="submit" name="citysubmit" class="btn btn-primary">确认</button>
            </div>
            </form>
        </div>
    </div>
</div>

<!--编辑 -->
<div class="modal fade" id="myModalEdit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel2">确认订单</h4>
            </div>
            <form class="form-horizontal" action="/m/c/status" method="post">
            <div class="modal-body">
                <div class="form-group">
                    <label class="col-sm-6 control-label"> 确认后,为该用户加入金额：<b id="checkmoney"></b> &nbsp;元</label>
                </div>
                <div class="form-group">
                    <input type="hidden" name="id" id="orderid" value="">
                    <label class="col-sm-3 control-label">操作人</label>
                    <div class="col-sm-7">
                        <input type="text" name="username" id="username" class="form-control" value="">
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="submit" class="btn btn-primary">确认</button>
            </div>
            </form>
        </div>
    </div>
</div>

<!-- 删除 -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="myModalLabel3">确认关闭</h4>
            </div>
            <div class="modal-body">
                <p>确定要关闭该订单吗？</p>
            </div>
            <div class="modal-footer">
                <a class="btn btn-default" id="closeorder" href="#">确认</a>
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>


<script>
    $(function(){
        $('#selectstatus').change(function(){
            var html = '';
            if($('#search').val() != ''){
                var regExp = new RegExp("[^a-zA-Z0-9\@\.\u4e00-\u9fa5]","i");
                if(regExp.test($('#search').val())){
                    alert('搜索框不能含有特殊字符');
                    return;
                }
                html += 'search='+$('#search').val()+'&';
            }
            window.location.href = '/m/pay/add?'+html+'status='+$(this).val();
        })

        $('#searchbtn').click(function(){

            var html = '';
            if($('#search').val() != ''){
                var regExp = new RegExp("[^a-zA-Z0-9\@\.\u4e00-\u9fa5]","i");
                if(regExp.test($('#search').val())){
                    alert('搜索框不能含有特殊字符');
                    return;
                }
                html += '?search='+$('#search').val();
            }
            if(html != '' && $('#selectstatus').val() != ''){
                html += '&status='+$('#selectstatus').val();
            }else if(html == '' && $('#selectstatus').val() != ''){
                html += '?status='+$('#selectstatus').val();
            }

            window.location.href = '/m/pay/add'+html;
        })
    });

    function sumbitorder(id,order,money){
        $('#orderchange').attr('action','/m/pay/modify/'+id);
        $('#order_sn').val(order);
        $('#money').val(money);
    }

    function closeorder(id){
        $('#closeorder').attr('href','/m/pay/close/'+id);
    }

    function checkorder(id,money){
        $('#checkmoney').text(money);
        $('#orderid').val(id);
    }
</script>
</body>
</html>

