| xqd
@@ -177,4 +177,59 @@ class ApiController extends Controller
|
|
|
$student_course->long_leave_times = $student->long_leave_times;
|
|
|
return response()->json(['status' => 'success', 'courseInfo' => $student_course]);
|
|
|
}
|
|
|
+
|
|
|
+ public function getMyLearnInfo(Request $request)
|
|
|
+ {
|
|
|
+ if(empty($request->input('student_id')) || empty($student = Student::find($request->input('student_id')))) {
|
|
|
+ return response()->json(['status' => 'fail', 'info' => '找不到用户信息!']);
|
|
|
+ }
|
|
|
+
|
|
|
+ $now = Carbon::now();
|
|
|
+ $begin_date_time = Carbon::create($now->year, $now->month, 1)->toDateTimeString();
|
|
|
+ $thisMonthLearnTime = 0;
|
|
|
+ $totalLearnTime = 0;
|
|
|
+ $checkCardList = collect();
|
|
|
+ $items = CheckCard::where('student_id', $this['id'])->whereNotNull('begin_date_time')->whereNotNull('end_date_time')->get();
|
|
|
+ foreach($items as $item) {
|
|
|
+ $duration = strtotime($item->end_date_time) - strtotime($item->begin_date_time);
|
|
|
+ $totalLearnTime += $duration;
|
|
|
+ if($item->begin_date_time >= $begin_date_time) {
|
|
|
+ $thisMonthLearnTime += $duration;
|
|
|
+ $day = Carbon::createFromTimestamp(strtotime($item->end_date_time))->day;
|
|
|
+ $checkCardList->push(collect(['month' => 'current', 'day' => $day, 'color' => '#77b9b9']));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $today = $now->day;
|
|
|
+ for($i = 1; $i <= $today; ++$i) {
|
|
|
+ $tmp = $checkCardList->where('day', $i);
|
|
|
+ if(empty($tmp)) {
|
|
|
+ $checkCardList->push(collect(['month' => 'current', 'day' => $i, 'color' => '#f65556']));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $thisMonthLearnTime = $this->getHumanTime($thisMonthLearnTime);
|
|
|
+ $totalLearnTime = $this->getHumanTime($totalLearnTime);
|
|
|
+
|
|
|
+ $checkCardDays = $student->getCheckCardDates()->count();
|
|
|
+ return response()->json(['status' => 'success', 'checkCardList' => $checkCardList, 'thisMonthLearnTime' => $thisMonthLearnTime, 'totalLearnTime' => $totalLearnTime, 'checkCardDays' => $checkCardDays])
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getHumanTime($seconds)
|
|
|
+ {
|
|
|
+ $res = '';
|
|
|
+ $tmp = floor($seconds / 3600);
|
|
|
+ $diff_time = $seconds % 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;
|
|
|
+ }
|
|
|
}
|