master
cody 3 weeks ago
parent 435f8d01eb
commit eb28e66b3b

@ -219,7 +219,7 @@ class OtherController extends CommonController
*/ */
public function coursesHome() public function coursesHome()
{ {
$start_date = request('start_date', '2020-01-01'); $start_date = request('start_date', CourseType::START_DATE);
$end_date = request('end_date', date('Y-m-d')); $end_date = request('end_date', date('Y-m-d'));
$course_type_id = request('course_type_id', ''); $course_type_id = request('course_type_id', '');
if ($course_type_id) { if ($course_type_id) {
@ -230,10 +230,7 @@ class OtherController extends CommonController
$course_type_id = CourseType::pluck('id')->toArray(); $course_type_id = CourseType::pluck('id')->toArray();
} }
// 课程 // 课程
$courses = Course::whereIn('type', $course_type_id) $courses = Course::whereIn('type', $course_type_id)->get();
// ->where('start_date', '<=', $end_date)
// ->where('start_date', '>=', $start_date)
->get();
// 被投企业数 // 被投企业数
$list['course_signs_invested'] = CourseSign::yhInvested($start_date, $end_date); $list['course_signs_invested'] = CourseSign::yhInvested($start_date, $end_date);
// 报名人数 // 报名人数
@ -246,19 +243,13 @@ class OtherController extends CommonController
$calendar = Calendar::whereIn('course_id', $courses->pluck('id'))->whereBetween('date', [$start_date, $end_date])->get(); $calendar = Calendar::whereIn('course_id', $courses->pluck('id'))->whereBetween('date', [$start_date, $end_date])->get();
$list['course_total'] = $calendar->count(); $list['course_total'] = $calendar->count();
// 开课天数 // 开课天数
$list['course_day_total'] = $calendar->sum(function ($course) { $list['course_day_total'] = $calendar->sum('days');
$start = Carbon::parse($course->start_time);
$end = Carbon::parse($course->end_time);
return $end->diffInDays($start) + 1; // 包含起始和结束日期
});
// 课程分类明细统计 // 课程分类明细统计
$courseTypesSum = []; $courseTypesSum = [];
$courseTypes = CourseType::whereIn('id', $course_type_id)->get(); $courseTypes = CourseType::whereIn('id', $course_type_id)->get();
foreach ($courseTypes as $courseType) { foreach ($courseTypes as $courseType) {
// 获取课程 // 获取课程
$courses2 = Course::where('type', $courseType->id) $courses2 = Course::where('type', $courseType->id)
// ->where('start_date', '<=', $end_date)
// ->where('start_date', '>=', $start_date)
->get(); ->get();
foreach ($courses2 as $course) { foreach ($courses2 as $course) {
$courseTypesSum[] = [ $courseTypesSum[] = [

@ -146,18 +146,11 @@ class CourseSign extends SoftDeletesModel
/** /**
* 指定时间内的被投企业 * 指定时间内的被投企业
*/ */
public static function yhInvested($start_date, $end_date, $status = null, $course_ids = null) public static function yhInvested($start_date, $end_date)
{ {
$courseSignByType = CourseSign::whereDate('created_at', '>=', $start_date) $courseSignByType = CourseSign::whereDate('created_at', '>=', $start_date)
->whereDate('created_at', '<=', $end_date) ->whereDate('created_at', '<=', $end_date)
->where(function ($query) use ($status, $course_ids) { ->whereNotIn('status', [4, 5])
if (isset($status)) {
$query->where('status', $status);
}
if (isset($course_ids)) {
$query->whereIn('course_id', $course_ids);
}
})->whereNotIn('status', [4, 5])
->get(); ->get();
return Company::whereHas('users', function ($query) use ($courseSignByType) { return Company::whereHas('users', function ($query) use ($courseSignByType) {
$query->whereIn('id', $courseSignByType->pluck('user_id')); $query->whereIn('id', $courseSignByType->pluck('user_id'));

Loading…
Cancel
Save