/** * 列出选课情况交叉比较信息 * @author FuRongxin * @date 2016-05-13 * @version 2.1 * @return \Illuminate\Http\Response 选课交叉比较信息 */ public function match() { $credits = []; $plan_total = 0; $selected_total = 0; $score_total = 0; // 获取教学计划学分 $plans = Plan::with(['course' => function ($query) { $query->select('kch', 'kcmc', 'kcywmc'); }])->whereNj(Auth::user()->profile->nj)->whereZy(Auth::user()->profile->zy)->whereZsjj(Auth::user()->profile->zsjj)->orderBy('kch', 'asc')->get(); foreach ($plans as $plan) { $credits[$plan->kch] = ['kch' => $plan->kch, 'kcmc' => $plan->course->kcmc, 'plan_credit' => $plan->zxf, 'selected_credit' => 0, 'score_credit' => 0]; $plan_total += $plan->zxf; } // 获取选课学分 $selects = Selcourse::with(['course' => function ($query) { $query->select('kch', 'kcmc', 'kcywmc'); }])->whereXh(Auth::user()->xh)->orderBy('kch', 'asc')->get(); foreach ($selects as $select) { if (array_key_exists($select->kch, $credits)) { $credits[$select->kch]['selected_credit'] = $select->xf; } else { $credits[$select->kch] = ['kch' => $select->kch, 'kcmc' => $select->course->kcmc, 'plan_credit' => 0, 'selected_credit' => $select->xf, 'score_credit' => 0]; } $selected_total += $select->xf; } // 获取成绩学分 $scores = Score::with(['course' => function ($query) { $query->select('kch', 'kcmc', 'kcywmc'); }])->whereXh(Auth::user()->xh)->orderBy('kch', 'asc')->get(); foreach ($scores as $score) { if (array_key_exists($score->kch, $credits)) { $credits[$score->kch]['score_credit'] = $score->xf; } else { $credits[$select->kch] = ['kch' => $score->kch, 'kcmc' => $score->course->kcmc, 'plan_credit' => 0, 'selected_credit' => 0, 'score_credit' => $score->xf]; } $score_total += $score->xf; } $title = '选课学分交叉对比表'; return view('course.match', compact('title', 'credits', 'plan_total', 'selected_total', 'score_total')); }
/** * 选课时间冲突检测 * @author FuRongxin * @date 2016-03-02 * @version 2.0 * @param string $kcxh 12位课程序号 * @return array 冲突返回冲突的课程序号,否则返回空数组 */ public function checktime($kcxh) { $currents = Timetable::whereNd(session('year'))->whereXq(session('term'))->whereKcxh($kcxh)->get(); $selcourses = Selcourse::with('timetables')->whereNd(session('year'))->whereXq(session('term'))->whereXh(Auth::user()->xh)->get(); foreach ($currents as $current) { foreach ($selcourses as $selcourse) { foreach ($selcourse->timetables as $compare) { if ($current->zc == $compare->zc) { if ($current->ksj >= $compare->ksj && $current->ksj <= $compare->jsj) { if ($current->ksz >= $compare->ksz && $current->ksz <= $compare->jsz) { $conflicts[] = $compare['kcxh']; } } } } } } $conflicts = isset($conflicts) ? array_unique($conflicts) : []; return request()->ajax() ? response()->json($conflicts) : $conflicts; }