diff --git a/app/Http/Controllers/Admin/OtherController.php b/app/Http/Controllers/Admin/OtherController.php index 5a5d2b5..029bef6 100755 --- a/app/Http/Controllers/Admin/OtherController.php +++ b/app/Http/Controllers/Admin/OtherController.php @@ -235,7 +235,7 @@ class OtherController extends CommonController ->orWhereBetween('end_time', [$start_date, $end_date]); })->where(function ($query) use ($courses) { if (request('course_type_id')) { - $query->whereIn('course_id', $courses->pluck('id')); + $query->whereIn('course_type_id', request('course_type_id')); } }); $list['course_total'] = (clone $calendar)->count(); @@ -732,7 +732,7 @@ class OtherController extends CommonController $calendars = Calendar::whereBetween('date', [$start_date, $end_date]) ->where(function ($query) use ($course_ids) { if (request('course_type_id')) { - $query->whereIn('course_id', $course_ids); + $query->whereIn('course_type_id', request('course_type_id')); } })->where('is_count_days', 1) ->with('course') diff --git a/app/Models/Calendar.php b/app/Models/Calendar.php index 9cde227..e9bd64f 100755 --- a/app/Models/Calendar.php +++ b/app/Models/Calendar.php @@ -47,5 +47,10 @@ class Calendar extends SoftDeletesModel return $this->hasMany(HistoryCourse::class, 'calendar_id', 'id'); } + public function courseType() + { + return $this->belongsTo(CourseType::class, 'course_type_id', 'id'); + } + } diff --git a/database/migrations/2025_11_27_110000_add_course_type_id_to_calendars_table.php b/database/migrations/2025_11_27_110000_add_course_type_id_to_calendars_table.php new file mode 100644 index 0000000..aebf023 --- /dev/null +++ b/database/migrations/2025_11_27_110000_add_course_type_id_to_calendars_table.php @@ -0,0 +1,35 @@ +unsignedBigInteger('course_type_id')->nullable()->after('id')->comment('课程类型ID'); + $table->index('course_type_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('calendars', function (Blueprint $table) { + $table->dropIndex(['course_type_id']); + $table->dropColumn('course_type_id'); + }); + } +} +