@extends('base.base')
@section('base')
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-header">
                    <h3 class="card-title">推广员奖励报表</h3>
                </div>
                <div class="card-body">
                    <form class="form-inline mb-4" method="post" action="{{ route('admin.extension_new.reward') }}">
                        @csrf
                        <div class="form-group mx-sm-3 mb-2">
                            <label for="UserID" class="mr-2">会员ID：</label>
                            <input type="text" class="form-control" name="UserID" id="UserID" value="{{ $UserID }}">
                        </div>
                        <div class="form-group mx-sm-3 mb-2">
                            <label for="SpreaderID" class="mr-2">上级ID：</label>
                            <input type="text" class="form-control" name="SpreaderID" id="SpreaderID" value="{{ $SpreaderID }}">
                        </div>
{{--                        <div class="form-group mx-sm-3 mb-2">--}}
{{--                            <label for="Type" class="mr-2">选择类型：</label>--}}
{{--                            <select class="form-control" name="Type" id="Type">--}}
{{--                                <option value="">全部</option>--}}
{{--                                <option value="1" @if($Type == 1) selected @endif>注册</option>--}}
{{--                                <option value="2" @if($Type == 2) selected @endif>对局</option>--}}
{{--                                <option value="3" @if($Type == 3) selected @endif>充值</option>--}}
{{--                            </select>--}}
{{--                        </div>--}}
                        <div class="form-group mx-sm-3 mb-2">
                            <label for="start_time" class="mr-2">发放时间：</label>
                            <input type="datetime-local" step="01" name="start_time" id="start_time" class="form-control" value="{{ $start_time }}">
                            <input type="datetime-local" step="01" name="end_time" id="end_time" class="form-control ml-2" value="{{ $end_time }}">
                        </div>
                        <a href="{{ route('admin.extension_new.reward') }}" class="btn btn-secondary mb-2 mr-2">重置</a>
                        <button type="submit" class="btn btn-primary mb-2">搜索</button>
                    </form>

                    <div class="mb-3">
                        自动审核：
                        @if($AutoVerify == 1)
                            已开启 <button class="btn btn-sm btn-dark" onclick="autoVerify(0)">关闭</button>
                        @else
                            已关闭 <button class="btn btn-sm btn-dark" onclick="autoVerify(1)">开启</button>
                        @endif
                    </div>

                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                                <tr>
                                    <th>推广员ID</th>
                                    <th>会员ID</th>
                                    <th>发放时间</th>
                                    <th>佣金金额</th>
                                    <th>订单号</th>
{{--                                    <th>类型</th>--}}
                                    <th>佣金比例</th>
                                    <th>充值金额</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach($list as $value)
                                <tr>
                                    <td>
                                        <a href="/admin/global/id_find?UserID={{$value->SpreaderID}}">{{$value->SpreaderGameID}}</a>
                                    </td>
                                    <td>
                                        <a href="/admin/global/id_find?UserID={{$value->UserID}}">{{$value->GameID}}</a>
                                    </td>
                                    <td>{{date("Y-m-d H:i:s", strtotime($value->created_at))}}</td>
                                    <td>{{$value->commission_amount}}</td>
                                    <td>{{$value->order_sn}}</td>
{{--                                    <td>{{$value->TypeDesc}}</td>--}}
                                    <td>{{$value->commission_rate}}%</td>
                                    <td>{{$value->deposit_amount}}</td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                    <div class="card-footer clearfix">
                        总共 <b>{{ $list->appends([
                            'UserID' => $UserID,
                            'SpreaderID' => $SpreaderID,
                            'start_time' => $start_time,
                            'end_time' => $end_time,
                            'Type' => $Type
                        ])->total() }}</b> 条, 分为 <b>{{ $list->lastPage() }}</b> 页
                        {{ $list->links() }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script>
    $(function() {
        $('#start_time, #end_time').datetimepicker({
            format: 'YYYY-MM-DD HH:mm:ss'
        });
    });

    // 自动审核开关
    function autoVerify(StatusValue) {
        $.post("/admin/extension_new/auto_verify", {
            StatusValue: StatusValue,
            _token: '{{ csrf_token() }}'
        }, function(res) {
            if (res.code === 0) {
                alert('设置成功');
                location.reload();
            } else {
                alert(res.msg || '设置失败');
            }
        });
    }
</script>
@endsection
