Silent 6 years ago
parent
commit
7dc0fc831a
2 changed files with 24 additions and 2 deletions
  1. 5 2
      app/Http/Controllers/Admin/CheckCardController.php
  2. 19 0
      app/Models/Student.php

+ 5 - 2
app/Http/Controllers/Admin/CheckCardController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\Admin;
 namespace App\Http\Controllers\Admin;
 
 
 use App\Models\CheckCard;
 use App\Models\CheckCard;
+use App\Models\Student;
 use Carbon\Carbon;
 use Carbon\Carbon;
 use Illuminate\Http\Request;
 use Illuminate\Http\Request;
 
 
@@ -61,7 +62,6 @@ class CheckCardController extends Controller
         }
         }
 
 
         $list = $this->paginate($list);
         $list = $this->paginate($list);
-        dd($list);
 
 
         foreach($list as $item) {
         foreach($list as $item) {
             $item->duration = $item->getDuration();
             $item->duration = $item->getDuration();
@@ -73,6 +73,9 @@ class CheckCardController extends Controller
 
 
     public function rank(Request $request)
     public function rank(Request $request)
     {
     {
-
+        $students = Student::all();
+        foreach($students as $student) {
+            $student->totalTime = $student->getCheckCardTime($request->input('begin_date'), $request->input('end_date'));
+        }
     }
     }
 }
 }

+ 19 - 0
app/Models/Student.php

@@ -143,4 +143,23 @@ class Student extends Model
         }
         }
         return floor($total / 60);
         return floor($total / 60);
     }
     }
+
+    public function getCheckCardTime($begin_date = null, $end_date = null)
+    {
+        $now = Carbon::now();
+        $begin_date_time = empty($begin_date) ? $now->subYears(10)->toDateTimeString() : Carbon::createFromTimestamp(strtotime($begin_date))->toDateTimeString();
+        $end_date_time = empty($end_date) ? $now->addYears(10)->toDateTimeString() : Carbon::createFromTimestamp(strtotime($end_date))->toDateTimeString();
+        $check_cards = CheckCard::where([
+            ['student_id', '=', $this['id']],
+            ['begin_date_time', '>=', $begin_date_time],
+            ['begin_date_time', '<', $end_date_time],
+        ])->get();
+        $total = 0;
+        foreach($check_cards as $check_card) {
+            if(!empty($check_card->begin_date_time) && !empty($check_card->end_date_time) && $check_card->end_date_time > $check_card->begin_date_time) {
+                $total += (strtotime($check_card->end_date_time) - strtotime($check_card->begin_date_time));
+            }
+        }
+        return
+    }
 }
 }