diff --git a/app/Http/Controllers/Mobile/CourseController.php b/app/Http/Controllers/Mobile/CourseController.php index 6b0b34a..7b594c3 100755 --- a/app/Http/Controllers/Mobile/CourseController.php +++ b/app/Http/Controllers/Mobile/CourseController.php @@ -817,10 +817,17 @@ class CourseController extends CommonController } $startDate = $all['month'] . '-01'; $endDate = date('Y-m-t', strtotime($startDate)); - dd($startDate,$endDate); - - - $list = Calendar::with('course', 'courseContent')->where('date', 'like', $all['month'] . '%')->orderBy('date')->get(); + $range = getDates($startDate, $endDate); + $list = []; + foreach ($range as $date) { + // 查询Calendar模型里start_time和end_time在日期内的数据,其中date是年月日,start_time和end_time是时分秒 + $list[] = [ + 'date' => $date, + 'details' => Calendar::with('course', 'courseContent')->whereDate('start_time', '>=', $date) + ->whereDate('end_time', '<=', $date) + ->get() + ]; + } return $this->success($list); } diff --git a/app/Http/functions.php b/app/Http/functions.php index 8712db0..c57acd3 100755 --- a/app/Http/functions.php +++ b/app/Http/functions.php @@ -702,3 +702,19 @@ function getVar($text) } return ''; } + +/** + * 获取两个日期之间的所有日期 + */ +function getDates($start, $end) +{ + $dt_start = strtotime($start); + $dt_end = strtotime($end); + $temp = []; + while ($dt_start <= $dt_end) { + $re = date('Y-m-d', $dt_start); + $temp[] = $re; + $dt_start = strtotime('+1 day', $dt_start); + } + return $temp; // 返回data型数据 +}