Silent 6 vuotta sitten
vanhempi
commit
693dd74d5d

+ 13 - 1
app/Http/Controllers/Admin/CheckCardController.php

@@ -75,7 +75,19 @@ class CheckCardController extends Controller
     {
     {
         $students = Student::all();
         $students = Student::all();
         foreach($students as $student) {
         foreach($students as $student) {
-            $student->totalTime = $student->getCheckCardTime($request->input('begin_date'), $request->input('end_date'));
+            $tmp = $student->getCheckCardTime($request->input('begin_date'), $request->input('end_date'));
+            $student->total = (int)$tmp['total'];
+            $student->totalHuman = (int)$tmp['totalHuman'];
+            $student->couseName = $student->getCourseName();
         }
         }
+
+        $students = $students->sortBy('total');
+        $rank = 0;
+        foreach($students as $student) {
+            $student->rank = ++$rank;
+        }
+        $list = $this->paginate($students);
+        list($pre_uri, $model_name) = array($this->pre_uri, $this->model_name);
+        return view($this->view_path . 'index', compact('list', 'pre_uri', 'model_name'));
     }
     }
 }
 }

+ 23 - 1
app/Models/Student.php

@@ -160,6 +160,28 @@ class Student extends Model
                 $total += (strtotime($check_card->end_date_time) - strtotime($check_card->begin_date_time));
                 $total += (strtotime($check_card->end_date_time) - strtotime($check_card->begin_date_time));
             }
             }
         }
         }
-        return '';
+        return [
+            'total' => $total,
+            'totalHuman' => $this->getHumanTime($total)
+        ];
+    }
+
+    public function getHumanTime($total)
+    {
+        $res = '';
+        $tmp = floor($total / 3600);
+        $diff_time = $total % 3600;
+        if(!empty($tmp)) {
+            $res .= $tmp . '小时';
+        }
+        $tmp = floor($diff_time / 3600);
+        $diff_time = $diff_time % 60;
+        if(!empty($tmp)) {
+            $res .= $tmp . '分钟';
+        }
+        if(!empty($diff_time)) {
+            $res .= $diff_time . '秒';
+        }
+        return $res;
     }
     }
 }
 }

+ 101 - 0
resources/views/admin/check-cards/rank.blade.php

@@ -0,0 +1,101 @@
+@extends('admin.layout')
+<style type="text/css">
+
+</style>
+@section('header')
+
+@endsection
+
+@section('content')
+<div id="sg-main-container-sg">
+    <div class="wrapper wrapper-content animated fadeInRight">
+        <div class="row">
+            <div class="col-sm-12">
+                <div class="ibox float-e-margins">
+                    <div class="ibox-title">
+                        <h5>{{ $model_name . '排行' }}</h5>
+                        <div class="ibox-tools">
+                            <a class="collapse-link"> <i class="fa fa-chevron-up"></i>
+                            </a>
+                        </div>
+                    </div>
+                    <div class="ibox-content">
+                        <div class="row">
+                            <form>
+                                <div class="col-sm-3 form-group">
+                                    <input type="text" class="form-control datepicker" name="begin_date" value="{{ request('begin_date') }}" placeholder="开始时间" autocomplete="off">
+                                </div>
+                                <div class="col-sm-3 form-group">
+                                    <input type="text" class="form-control datepicker" name="end_date" value="{{ request('end_date') }}" placeholder="截止时间" autocomplete="off">
+                                </div>
+                                <div class="col-sm-3">
+                                    <button type="submit" class="btn btn-sm btn-primary">搜索</button>
+                                </div>
+                            </form>
+                        </div>
+                        <table class="table table-striped table-bordered table-hover dataTables-example dataTable" id="sg-main-table">
+                            <thead>
+                                <tr>
+                                    <th>排名</th>
+                                    <th>姓名</th>
+                                    <th>课程名称</th>
+                                    <th>累计时间</th>
+                                </tr>
+                            </thead>
+                            <tbody>
+                                @if($list->count() <= 0)
+                                    <tr>
+                                        <td colspan="4" style="text-align: center;">暂无{{ $model_name }}</td>
+                                    </tr>
+                                @else
+                                    @foreach($list as $item)
+                                        <tr>
+                                            <td>{{ $item->rank }}</td>
+                                            <td>{{ $item->name }}</td>
+                                            <td>{{ $item->courseName }}</td>
+                                            <td>{{ $item->totalHuman }}</td>
+                                        </tr>
+                                    @endforeach
+                                @endif
+                            </tbody>
+                        </table>
+                        <div class="row">
+                            <div class="col-sm-12">{{ $list->links() }}</div>
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+</div>
+<div class="modal fade" id="delete-modal" tabindex="-1" role="dialog" aria-labelledby="delete-label" aria-hidden="true">
+    <div class="modal-dialog">
+        <form id="delete-form" method="POST" action="{{ $pre_uri . 'delete' }}">
+            {{ csrf_field() }}
+
+            <input type="hidden" name="id" id="delete-input-id">
+            <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="delete-label">确定要删除吗?</h4>
+                </div>
+                <div class="modal-footer">
+                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
+                    <button type="submit" class="btn btn-danger">删除</button>
+                </div>
+            </div>
+        </form>
+    </div>
+</div>
+@endsection
+
+@section('footer')
+<script type="text/javascript">
+$(function () {
+    $('#sg-main-table').on('click', '.btn-delete', function () {
+        $('#delete-input-id').val($(this).attr('data-id'));
+        $('#delete-modal').modal('show');
+    });
+})
+</script>
+@endsection