lion 2 weeks ago
commit 355cc205e2

@ -75,7 +75,21 @@ class CalendarsController extends BaseController
$query->where('start_time', 'like', $year . '%');
}
})->where('is_count_days', 1)->sum('days');
return $this->success(compact('list', 'monthDayCalendar', 'yearDayCalendar'));
// 本月开课场次
$monthCourseCount = Calendar::where(function ($query) use ($all) {
if (isset($all['month'])) {
$query->where('start_time', 'like', $all['month'] . '%');
}
})->count();
// 本年开课场次
$yearCourseCount = Calendar::where(function ($query) use ($all) {
if (isset($all['month'])) {
// 获取$all['month']的年份部分
$year = date('Y', strtotime($all['month']));
$query->where('start_time', 'like', $year . '%');
}
})->count();
return $this->success(compact('list', 'monthDayCalendar', 'yearDayCalendar', 'monthCourseCount', 'yearCourseCount'));
}
/**

@ -233,9 +233,11 @@ class OtherController extends CommonController
$calendar = Calendar::where(function ($query) use ($start_date, $end_date) {
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
})->where(function ($query) use ($courses) {
if (request('course_type_id')) {
$query->whereIn('course_id', $courses->pluck('id'));
})->where(function ($query) {
$course_type_id = request('course_type_id');
if ($course_type_id) {
$course_type_id = explode(',', $course_type_id);
$query->whereIn('course_type_id1', $course_type_id);
}
});
$list['course_total'] = (clone $calendar)->count();
@ -308,7 +310,13 @@ class OtherController extends CommonController
// 开始结束日期的筛选。or查询
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
})->where('type', $course_type_id)->get();
})->where(function ($query) {
$course_type_id = request('course_type_id', '');
$course_type_id = explode(',', $course_type_id);
if ($course_type_id) {
$query->whereIn('type', $course_type_id);
}
})->get();
foreach ($historyCourses as $historyCourse) {
$courseTypesSum[] = [
'course_type' => $historyCourse->typeDetail->name,
@ -699,11 +707,12 @@ class OtherController extends CommonController
// 开课场次明细 - 与coursesHome算法一致
$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);
$course_type_id = request('course_type_id');
if ($course_type_id) {
$course_type_id = explode(',', $course_type_id);
$query->whereIn('course_type_id', $course_type_id);
}
})
->with('course')
})->with('course')
->get();
foreach ($calendars as $calendar) {
@ -731,8 +740,10 @@ class OtherController extends CommonController
// 开课天数明细 - 与coursesHome算法一致
$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);
$course_type_id = request('course_type_id');
if ($course_type_id) {
$course_type_id = explode(',', $course_type_id);
$query->whereIn('course_type_id', $course_type_id);
}
})->where('is_count_days', 1)
->with('course')

@ -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');
}
}

@ -116,7 +116,13 @@ class CourseSign extends SoftDeletesModel
// 开始结束日期的筛选。or查询
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
})->where('type', request('course_type_id', 0))->sum('course_type_signs_pass');
})->where(function ($query) {
$course_type_id = request('course_type_id', '');
$course_type_id = explode(',', $course_type_id);
if ($course_type_id) {
$query->whereIn('type', $course_type_id);
}
})->sum('course_type_signs_pass');
// 返回统计数据
return $historyTotal + $baseTotal;
}
@ -141,7 +147,13 @@ class CourseSign extends SoftDeletesModel
// 开始结束日期的筛选。or查询
$query->whereBetween('start_time', [$start_date, $end_date])
->orWhereBetween('end_time', [$start_date, $end_date]);
})->where('type', request('course_type_id', 0))->sum('course_type_signs_pass_unique');
})->where(function ($query) {
$course_type_id = request('course_type_id', '');
$course_type_id = explode(',', $course_type_id);
if ($course_type_id) {
$query->whereIn('type', $course_type_id);
}
})->sum('course_type_signs_pass_unique');
// 统计数据
return $baseTotal + $historyTotal;
}

@ -0,0 +1,35 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddCourseTypeIdToCalendarsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('calendars', function (Blueprint $table) {
$table->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');
});
}
}
Loading…
Cancel
Save