@extends('Public.index')
@section('admin')

<div class="content-wrapper" style="min-height: 810px;">
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h4>优惠券详情</h4>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="/admin/index">首页</a></li>
              <li class="breadcrumb-item active">优惠券管理</li>
              <li class="breadcrumb-item active">优惠券详情</li>
            </ol>
          </div>
        </div>
      </div>
    </section>
                <form class="form">
                    <div class="form-group m-4">
                        <label for="exampleInputName2" class="col-md-12"> 优惠券名称:　{{ $you -> name }}</label>
                    </div>
                </form>
                <form class="form">
                    <div class="form-group m-4">
                    @if($you -> vip)
                        <label for="exampleInputName2" class="col-md-12">
                            总领取数量:{{ DB::table('user_you') -> where('youhui_id',$you -> id) -> count() }}
                        </label>
                        @else
                        <label for="exampleInputName2" class="col-md-12"> 已领取/名额:　
                            {{ $you -> use_num }}
                            /
                            @if($you -> send_type == 1)
                            无限制
                            @else
                            {{ $you -> send_num }}
                            @endif
                        </label>
                    @endif
                    </div>
                </form>
                <form class="form">
                    <div class="form-group m-4">
                        @if($you -> vip)
                        <label for="exampleInputName2" class="col-md-6"> 优惠券有效期:自领取后{{ $you -> end_date }}天内有效</label>
                        @else
                        <label for="exampleInputName2" class="col-md-6"> 优惠券过期时间:　{{ date('Y年m月d日 H:i:s',$you -> end_date) }}</label>
                        @endif
                    </div>
                </form>
                <div class="col-xs-3">
                    <button class="btn btn-danger back" style="margin-left:17px;margin-bottom:15px"> 返回列表</button>
                </div>
    <section class="content">
      <div class="container-fluid">
        <div class="row">
          <div class="col-md-12">

            <div class="card">
              <div class="card-body p-0">
                <table class="table table-condensed">
                  <tbody>
                  
                  <tr style="text-align:center">
                    <th>领取用户</th>
                    <th>领取时间</th>
                    <th>使用状况</th> 
                    <th>操作</th>
                  </tr>
                  @foreach($uyou as $key => $val)
                  <tr style="text-align:center">
                    <td>{{ DB::table('user') -> where('id',$val -> user_id) -> value('nickname') }}</td>
                    <td>{{ date('Y年m月d日 H:i',$val -> addtime) }}</td>
                    <td>
                            @php 
                            if($val -> status == 0) {
                              echo '<span style="color:orange">未使用</span>';
                            }elseif($val -> status == 1){
                              echo '<span style="color:green">已使用</span>';
                            }else{
                              echo '<span style="color:red">已过期</span>';
                            }
                            @endphp
                    </td>
                    <td><a href="javascript:void(0);" onclick="back({{ $val -> user_id }},{{ $val -> youhui_id }})">撤回</a></td>
                  </tr>
                  @endforeach
                </tbody></table>
              </div>
            </div>
          </div>
        </div>
    </section>
  </div>
<script src="/admin/plugins/jquery/jquery.min.js"></script>
<script src="/admin/layer-v3.1.1/layer/layer.js"></script>
<script>
    //撤回优惠券
    function back(id,yhid)
    {
        if(!id || !yhid){
            layer.msg('参数不全');
            return false;
        }
        layer.confirm('确认撤回该用户的当前优惠券吗？', {
            btn: ['确认','取消'] //按钮
            }, function(){
                $.get('/admin/you/back',{id:id,yhid:yhid},function(res){
                    if(res.code == '1000'){
                        layer.msg(res.msg);
                        window.location.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                })
        });
    }
    $('.back').click(function(){
        window.location.href="/admin/you/list";
    })
        
</script>
@endsection
@section('title','优惠券详情')
@section('youhui','menu-open')
@section('youhui2','active')
@section('youhui-list','active')