@extends('base.base')
@section('base')
    <style>
        .form-inline .form-group {
            margin-bottom: 10px;
        }
    </style>
    <!-- 内容区域 -->
    <div class="main-panel">
        <div class="content-wrapper">
            <div class="page-header">
                <h3 class="page-title">
                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
                        <i class="mdi mdi-settings"></i>
                    </span>
                    {{ __('auto.咖啡查询') }}
                </h3>
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb">
                        <li class="breadcrumb-item"><a href="#">{{ __('auto.咖啡管理') }}</a></li>
                        <li class="breadcrumb-item active" aria-current="page">{{ __('auto.咖啡查询') }}</li>
                    </ol>
                </nav>
            </div>
            <div class="row">
                <div class="col-lg-12 grid-margin stretch-card">
                    <div class="card">
                        <div class="card-body">
                            <h4 class="card-title">{{ __('auto.咖啡查询') }}</h4>
                            {{--                            <form class="well form-group margin-top-20" method="get" action='/admin/recharge/list'>--}}
                            <form class="well form-inline margin-top-20" method="get">
                                <div>
                                    <div class="form-group">
                                        <span style="padding-left: 10px">{{ __('auto.咖啡单号：') }}</span>
                                        <input class="form-control" type="text" name="order_sn" style="width: 10%; "
                                               value="{{$order_sn}}">

                                        <span style="padding-left: 10px">{{ __('auto.玩家ID：') }}</span>
                                        <input class="form-control" type="text" name="UserID" style="width: 10%; "
                                               value="{{$UserID}}">&nbsp;

                                        <span style="padding-left: 10px">{{ __('auto.咖啡状态：') }}</span>
                                        <select class="form-control" name="recharge_type" value="" style="color: black">
                                            <option value="">{{ __('auto.请选择') }}</option>
                                            <option value="1" @if ($recharge_type == 1) selected

                                                @endif >{{ __('auto.已到账') }}
                                            </option>
                                            <option value="2" @if ($recharge_type == 2) selected

                                                @endif>{{ __('auto.咖啡失败') }}
                                            <option value="3" @if ($recharge_type == 3) selected

                                                @endif>{{ __('auto.未支付') }}
                                            <option value="9" @if ($recharge_type == 9) selected

                                                @endif>{{ __('auto.退款') }}
                                            </option>
                                        </select>&nbsp;

                                        <span style="padding-left: 10px">{{ __('auto.渠道搜索：') }}</span>
                                        <select class="form-control" name="Channel" value="" style="color: black">
                                            <option value="">{{ __('auto.请选择') }}</option>
                                            @foreach($allChannel as $key=>$val)
                                                <option value="{{$val}}"
                                                        @if($val == $Channel) selected @endif>{{$val}}</option>
                                            @endforeach

                                        </select>

                                        <span style="padding-left: 10px">{{ __('auto.咖啡渠道：') }}</span>
                                        <select class="form-control" name="type" value="{{$type}}" style="color: black">
                                            <option value="">{{ __('auto.选择类别') }}</option>
                                            @foreach($type_list as $k=>$v)
                                                <option value="{{$v}}" @if($v==$type) selected @endif>{{$v}}</option>
                                            @endforeach
                                        </select>
                                        
                                        <span style="padding-left: 10px">支付渠道：</span>
                                        <select class="form-control" name="payMethod" value="{{$payMethod}}" style="color: black">
                                            <option value="">{{ __('auto.选择类别') }}</option>
                                            @foreach($payMethods as $methodValue => $methodName)
                                                <option value="{{$methodValue}}" @if($methodValue == $payMethod) selected @endif>{{$methodName}}</option>
                                            @endforeach
                                        </select>

                                        <span style="padding-left: 10px">操作人：</span>
                                        <select class="form-control" name="operator_admin_id" style="color: black">
                                            <option value="">{{ __('auto.请选择') }}</option>
                                            <option value="0" @if ((string)($operator_admin_id ?? '') === '0') selected @endif>无操作人</option>
                                            @foreach($operatorOptions ?? [] as $op)
                                                <option value="{{ $op->id }}" @if ((string)($operator_admin_id ?? '') === (string)$op->id) selected @endif>{{ $op->account }}</option>
                                            @endforeach
                                        </select>
                                    </div>
                                    <div class="form-group">
                                        <span style="padding-left: 10px">{{ __('auto.选择支付时间') }}：</span>
                                        <input type="datetime-local" step="01" name="start_time" class="form-control" id="start_time"
                                               value="{{$start_time}}" onclick="start_times('start_time')"/>&nbsp;&nbsp;
                                        <input type="datetime-local" step="01" name="end_time" class="form-control" id="end_time"
                                               value="{{$end_time}}"  onclick="end_times('end_time')"/>&nbsp;&nbsp;

                                        <span style="padding-left: 10px;">{{ __('auto.按单价排序：') }}</span>
                                        <input type="radio" name="order" value="1">&nbsp;

                                    </div>


                                    <div class="form-group">
                                        <span style="padding-left: 10px">{{ __('auto.订单创建时间') }}：</span>
                                        <input type="datetime-local" step="01" name="create_start_time" class="form-control" id="create_start_time"
                                               value="{{$create_start_time}}" onclick="create_start_times()"/>&nbsp;&nbsp;
                                        <input type="datetime-local" step="01" name="create_end_time" class="form-control" id="create_end_time"
                                               value="{{$create_end_time}}" onclick="create_end_times()"/>
                                        <span style="padding-left: 10px">更新时间：</span>
                                        <input type="datetime-local" step="01" name="updated_start_time" class="form-control" id="updated_start_time"
                                               value="{{$updated_start_time}}" onclick="start_times('updated_start_time')"/>&nbsp;&nbsp;
                                        <input type="datetime-local" step="01" name="updated_end_time" class="form-control" id="updated_end_time"
                                               value="{{$updated_end_time}}" onclick="end_times('updated_end_time')"/>

                                        <span style="padding-left: 10px">{{ __('auto.用户注册日期：') }}</span>
                                        <input type="datetime-local" step="01" name="register_start_time" class="form-control" id="register_start_time"
                                               value="{{$register_start_time}}" onclick="register_start_timeFunc()"/>&nbsp;&nbsp;
                                        <input type="datetime-local" step="01" name="register_end_time" class="form-control" id="register_end_time"
                                               value="{{$register_end_time}}" onclick="register_end_timeFunc()"/>
                                        <span style="padding-left: 10px">{{ __('auto.咖啡来源：') }}</span>
                                        <select class="form-control" name="source" value="{{$source}}" style="color: black">
                                            <option value="">{{ __('auto.选择类别') }}</option>
                                            @foreach($sourceList as $k=>$v)
                                                <option value="{{$k}}" @if ($source == $k)
                                                selected
                                                    @endif>{{$v}}</option>
                                            @endforeach
                                        </select>

                                        <span style="padding-left: 10px">{{ __('auto.咖啡档位筛选：') }}</span>
                                        <select class="form-control" name="chargeMoney" value="" style="color: black">
                                            <option value="">{{ __('auto.选择类别') }}</option>
                                            @foreach($chargeMoneyList as $k=>$v)
                                                <option value="{{$v}}" @if ($chargeMoney == $v)
                                                selected
                                                    @endif>{{$v}}</option>
                                            @endforeach
                                        </select>

                                        <input type="hidden" name="isEmpty" value="{{$isEmpty}}">
                                        <input type="submit" class="btn btn-sm btn-gradient-dark btn-icon-text" value="{{ __('auto.搜索') }}"/>&nbsp;&nbsp;
                                        <a href="?isEmpty=1"
                                           class="btn btn-sm btn-gradient-warning btn-icon-text">{{ __('auto.清空') }}</a>&nbsp;&nbsp;
                                        <a href="?excel=1&start_time={{$start_time}}&end_time={{$end_time}}&recharge_type={{$recharge_type}}&UserID={{$UserID}}&type={{$type}}&order={{$order}}&date={{$date}}&create_start_time={{$create_start_time}}&create_end_time={{$create_end_time}}&updated_start_time={{$updated_start_time}}&updated_end_time={{$updated_end_time}}&isEmpty=1&source={{$source}}&chargeMoney={{$chargeMoney}}&payMethod={{$payMethod}}&operator_admin_id={{ urlencode((string)($operator_admin_id ?? '')) }}"
                                           class="btn btn-sm btn-gradient-light btn-icon-text">{{ __('auto.导出') }}</a>
                                    </div>
                                </div>
                            </form>
                            <table class="table table-bordered" id="tables">
                                <thead>
                                <tr>
                                    <th width="5%" ondblclick="copyText(1)">ID</th>
                                    <th width="8%" ondblclick="copyText(2)">{{ __('auto.订单号') }}</th>
                                    <th width="8%">{{ __('auto.支付完成时间') }}</th>
                                    <th width="10%">
                                        <div class="sort_money">
                                            {{ __('auto.咖啡金额') }}
                                            <svg t="1611284352657" class="icon2" onclick="sort_money_func(this,'asc')"
                                                 viewBox="0 0 1024 1024" version="1.1"
                                                 xmlns="http://www.w3.org/2000/svg" p-id="4118" width="14">
                                                <path
                                                    d="M541.866667 285.866667l345.6 345.6c17.066667 17.066667 17.066667 42.666667 0 59.733333-8.533333 8.533333-19.2 12.8-29.866667 12.8H168.533333c-23.466667 0-42.666667-19.2-42.666666-42.666667 0-10.666667 4.266667-21.333333 12.8-29.866666l343.466666-345.6c17.066667-17.066667 42.666667-17.066667 59.733334 0z"
                                                    p-id="4119" fill="#707072">

                                                </path>
                                            </svg>

                                            <svg t="1611283709864" class="icon1" onclick="sort_money_func(this,'desc')"
                                                 viewBox="0 0 1024 1024" version="1.1"
                                                 xmlns="http://www.w3.org/2000/svg" p-id="3148" width="14">
                                                <path
                                                    d="M482.133333 738.133333L136.533333 392.533333c-17.066667-17.066667-17.066667-42.666667 0-59.733333 8.533333-8.533333 19.2-12.8 29.866667-12.8h689.066667c23.466667 0 42.666667 19.2 42.666666 42.666667 0 10.666667-4.266667 21.333333-12.8 29.866666L541.866667 738.133333c-17.066667 17.066667-42.666667 17.066667-59.733334 0z"
                                                    p-id="3149" fill="#707071">

                                                </path>
                                            </svg>
                                        </div>
                                    </th>
                                    <th width="6%">{{ __('auto.手续费') }}</th>
                                    <th width="8%">{{ __('auto.变化后余额') }}</th>
                                    <th width="8%">{{ __('auto.当前余额') }}</th>

                                    <th width="8%">{{ __('auto.最高分') }}</th>
                                    <th width="8%">{{ __('auto.最多赢分') }}</th>

                                    <th width="8%">{{ __('auto.咖啡来源') }}</th>
                                    <th width="8%">支付渠道</th>
                                    <th width="7%">{{ __('auto.咖啡玩家') }}ID</th>
                                    <th width="8%">{{ __('auto.状态') }}</th>
                                    <th width="8%">{{ __('auto.来源') }}</th>
                                    <th width="7%">{{ __('auto.玩家渠道') }}</th>
                                    <th width="8%">{{ __('auto.订单生成日期') }}</th>
                                    <th width="8%">更新时间</th>
                                    <th width="8%">{{ __('auto.操作') }}</th>
                                    <th width="8%">{{ __('auto.添加备注') }}</th>
                                    <th width="8%">{{ __('auto.操作人') }}</th>
                                </tr>
                                </thead>
                                <tbody>

                                @if (hidden() != 'service')
                                    <div>
                                        @if (!empty($chargeMoney))
                                           <h4> {{$chargeMoney}} {{ __('auto.档位') }}</h4>
                                        @endif
                                        <h4>{{ __('auto.总金额：') }}{{$totalMoney}} &nbsp;&nbsp; {{$payTotalMoney->count_u ?? 0}}{{ __('auto.人') }}&nbsp;&nbsp;{{$payTotalMoney->count_id ?? 0}}{{ __('auto.笔') }}</h4>
                                        <h4>{{ __('auto.已到账：') }}{{$overMoney}} &nbsp;&nbsp;{{$payOverMoney->count_u ?? 0}}{{ __('auto.人') }}&nbsp;&nbsp;{{$payOverMoney->count_id ?? 0}}{{ __('auto.笔') }}</h4>
                                        <h4>退款金额：{{ $refundMoney ?? 0 }} &nbsp;&nbsp;{{ $refundSummary->count_id ?? 0 }}{{ __('auto.笔') }}</h4>
                                        <h4>退款手续费：{{ $refundFee ?? 0 }}</h4>
                                        @if(!empty($viewAll))
                                            <h4>{{ __('auto.手续费汇总：') }}{{ $totalPaymentFee ?? 0 }}</h4>
                                        @endif
                                        <h4>充值成功人数百分比：{{ $successUserRate ?? 0 }}%</h4>
                                        <h4>充值成功笔数百分比：{{ $successOrderRate ?? 0 }}%</h4>
                                    </div>
                                @endif

                                @foreach($list as $k=>$v)
                                    <tr id="hidden_td">
                                        <td class="first_str">{{ $v->id }}</td>
                                        <td>{{ $v->order_sn }}</td>
                                        <td>{{$v->finished_at}}</td>
                                        <td>{{ $v->amount }}</td>
                                        <td>{{ $v->payment_fee ?? 0 }}</td>
                                        <td>{{ $v->after_amount }}</td>
                                        <td>{{ $v->score }}</td>

                                        <td>{{ $v->MaxScore }}</td>
                                        <td>{{ $v->MaxWinScore }}</td>

                                        <td>{{$v->payment_code}}</td>

                                        <td>{{@$payMethods[$v->order_title]??''}}</td>

                                        <td>
                                            <a href="/admin/global/id_find?UserID={{$v->UserID}}">
                                                {{$v->ai_GameID}}
                                            </a>
                                            @if ($v->Phone )
                                                <a  target="_blank"
                                                    href="https://api.whatsapp.com/send?phone={{$v->Phone}}">what's app</a>
                                            @endif
                                        </td>

                                        <td>
                                            @if ($v->pay_status  == 1)
                                                <span style="color: #0b2e13">{{ __('auto.已到账') }}</span>
                                            @elseif($v->pay_status == 9)
                                                <span style="color: #ff9800">{{ __('auto.退款') }}</span>
                                            @elseif($v->pay_status == 0)
                                                <span>{{ __('auto.未支付') }}</span>
                                            @else
                                                <span style="color: red">{{ __('auto.咖啡出错') }}</span>
                                            @endif
                                        </td>
                                        <td>{{$v->GiftsName}}</td>
                                        <td>{{$v->Channel}}</td>
                                        <td>{{$v->created_at}}</td>
                                        <td>{{$v->updated_at}}</td>
                                        <td>
                                            @if (in_array(session('admin')->roles[0]->id,[1,12]) && $v->pay_status != 1 && $v->pay_status != 9)
                                                <button type="button" class="btn-sm btn-primary"
                                                        onclick="supplement({{$v->id}})">{{ __('auto.补单') }}
                                                </button>
                                            @endif
                                            @if (in_array(session('admin')->roles[0]->id,[1,12]) && $v->pay_status == 1)
                                                <button type="button" class="btn-sm btn-warning"
                                                        onclick="setRefund({{$v->id}})">{{ __('auto.标记退款') }}
                                                </button>
                                            @endif
                                            @if (in_array(session('admin')->roles[0]->id,[1,12]) && $v->pay_status != 1 && $v->pay_status != 9)
                                                <button type="button" class="btn-sm btn-info"
                                                        onclick="mockFbReport({{$v->id}})">FB模拟上报
                                                </button>
                                            @endif
                                        </td>
                                        <td contentEditable="true"
                                            onblur="remarks(this,{{$v->id}})">{{$v->ar_remarks}}</td>
                                        <td>
                                            {{$v->account}}
                                        </td>

                                    </tr>
                                @endforeach
                                </tbody>
                            </table>
                            <div class="box-footer clearfix">
                                {{ __('auto.总共') }}
                                <b>{{ $list->appends([
    'start_time'=>$start_time,
    'UserID'=>$UserID,
    'end_time'=>$end_time,
    'order'=>$order,
    'type'=>$type,
    'recharge_type'=>$recharge_type,
    'date'=>$date,
    'create_start_time'=>$create_start_time,
    'create_end_time'=>$create_end_time,
    'updated_start_time'=>$updated_start_time,
    'updated_end_time'=>$updated_end_time,
    'Channel'=>$Channel,
    'isEmpty'=>$isEmpty,
    'register_start_time' => $register_start_time,
    'register_end_time' => $register_end_time,
    'source' => $source,
    'chargeMoney' => $chargeMoney,
    'payMethod' => $payMethod,
    'amountSort' => $amountSort,
    'operator_admin_id' => $operator_admin_id ?? '',

    ])->total() }}</b>
                                {{ __('auto.条,分为') }}<b>{{ $list->lastPage() }}</b>{{ __('auto.页') }}
                                {!! $list->links() !!}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <script>

        var params = {
            'start_time' : '{{$start_time}}',
            'UserID':'{{$UserID}}',
            'end_time':'{{$end_time}}',
            'order':'{{$order}}',
            'type':'{{$type}}',
            'recharge_type':'{{$recharge_type}}',
            'date':'{{$date}}',
            'create_start_time':'{{$create_start_time}}',
            'create_end_time':'{{$create_end_time}}',
            'updated_start_time':'{{$updated_start_time}}',
            'updated_end_time':'{{$updated_end_time}}',
            'Channel':'{{$Channel}}',
            'isEmpty':'{{$isEmpty}}',
            'register_start_time' : '{{$register_start_time}}',
            'register_end_time' :'{{$register_end_time}}',
            'source' : '{{$source}}',
            'chargeMoney' : '{{$chargeMoney}}',
            'payMethod' : '{{$payMethod}}',
            'operator_admin_id' : '{{ $operator_admin_id ?? '' }}',
        }

        function start_times(id) {

            getFormat('00', '00', '00');

            document.getElementById(id).value = format
        }

        function end_times(id) {
            getFormat('23', '59', '59');
            document.getElementById(id).value = format
        }

        function create_start_times() {

            getFormat('00', '00', '00');

            document.getElementById("create_start_time").value = format
        }

        function create_end_times() {
            getFormat('23', '59', '59');
            document.getElementById("create_end_time").value = format
        }

        function register_start_timeFunc(){
            getFormat('00', '00', '00');

            document.getElementById("register_start_time").value = format
        }

        function register_end_timeFunc(){
            getFormat('23', '59', '59');
            document.getElementById("register_end_time").value = format
        }

        function sort_money_func(obj, val) {
            if (val == 'asc') {
                $(".sort_money svg:eq(1)").children('path').attr('fill', '#707071');
                $(obj).children('path').attr('fill', 'red')

            } else {
                $(obj).children('path').attr('fill', 'red')
                $(".sort_money svg:eq(0)").children('path').attr('fill', '#707071');
            }

            params.amountSort = val
            $.ajax({
                type: "get",
                url: "/admin/recharge/list",
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                data: params,
                success: function (msg) {

                    if (msg) {
                        $(".main-panel").html(msg)

                    }
                }
            })
        }
        function remarks(obj, RecordID) {
            let remark = $(obj).html();
            let type = 2
            if (remark != ''){
                myRequest("/admin/withdrawal/remarks/" + RecordID, "post", {remark,type}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                });
            }

        }

        function supplement(id) {
            myConfirm("{{ __('auto.操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/recharge/supplement/" + id, "post", {}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                });
            });
        }

        function setRefund(id) {
            myConfirm("{{ __('auto.操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/recharge/refund/" + id, "post", {}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                });
            });
        }

        function mockFbReport(id) {
            myConfirm("确认模拟上报 FB 事件吗？", function () {
                myRequest("/admin/recharge/fb_report_mock/" + id, "post", {}, function (res) {
                    layer.msg(res.msg)
                });
            });
        }


        $(function () {
            cutStr(50);
        });

        function update(id) {
            myConfirm("{{ __('auto.处理操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/accusation/edit/" + id, "post", {}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                });
            });
        }

        function del(id) {
            myConfirm("{{ __('auto.删除操作不可逆,是否继续') }}?", function () {
                myRequest("/admin/accusation/del/" + id, "post", {}, function (res) {
                    layer.msg(res.msg)
                    setTimeout(function () {
                        window.location.reload();
                    }, 1500)
                });
            });
        }

    </script>
@endsection
