Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
5.3 kB
5
Indexable
Never
private function storeListPointInRelearnOnline($arr_data, $available_service_id, $retest_plan_id)
    {
        try {
            $log_order_ids = " ";
            DB::connection(session('campus_db'))->beginTransaction();
            foreach ($arr_data as $data) {
                $this->storeSinglePointInRelearnOnline($data);
                $log_order_ids = $log_order_ids . $data->online_service_id . ", ";
            }
            RetestPlanLog::create([
                'available_service_id' => $available_service_id,
                'retest_plan_id' => $retest_plan_id,
                'action_note' => "[Nhập điểm] Order ID: " . $log_order_ids,
                'updated_by' => auth()->user()->user_login
            ]);
            DB::connection(session('campus_db'))->commit();
        } catch (\Throwable $th) {
            error_log($th);
            DB::connection(session('campus_db'))->rollBack();
            throw new Exception('------Err RetestRepository storeSinglePointInRelearnOnline ---------');
        }
    }

private function storeSinglePointInRelearnOnline($data)
    {
        try {
            $relearn_online_calendar_user = RelearnOnlineCalendarUser::where(['online_service_id' => $data->online_service_id])->firstOrFail();

            if ($data->is_skip_exam == 1) {
                $relearn_online_calendar_user->is_skip_exam = 1;
                $relearn_online_calendar_user->note = $data->note;
            } else {
                $relearn_online_calendar_user->is_skip_exam = 0;
                $relearn_online_calendar_user->note = "";
            }

            $relearn_online_calendar_user->point = $data->point;
            $relearn_online_calendar_user->save();
            $relearn_online = RelearnOnline::where(['user_code' => $data->student_user_code])
                ->where(['skill_code' => $data->skill_code])
                ->where(['type' => $data->type])
                ->first();

            if ($relearn_online != null) {
                error_log("NULL");
                $relearn_online->point = $data->point;
                if ($relearn_online->luot_thi < 0) {
                    $relearn_online->luot_thi = 1;
                } else {
                    if ($relearn_online->online_service_id != $data->online_service_id) {
                        $relearn_online->luot_thi = $relearn_online->luot_thi + 1;
                        $relearn_online->online_service_id = $data->online_service_id;
                    }
                }
                $relearn_online->grade_id = $data->grade_id;
                $relearn_online->grade_name = $data->grade_name;
                $relearn_online->course_id = $data->course_id;
                $relearn_online->syllabus_id = $data->syllabus_id;
                $relearn_online->subject_id = $data->subject_id;
                $relearn_online->group_id = $relearn_online_calendar_user->new_group_id;
                $relearn_online->updated_by = auth()->user()->user_login;
                $relearn_online->relearn_online_calendar_id = $data->relearn_online_calendar_id;
                $relearn_online->save();
            } else {
                error_log("CREATE");
                $relearn_online = RelearnOnline::insertGetId([
                    'online_service_id' => $data->online_service_id,
                    'relearn_online_calendar_id' => $data->relearn_online_calendar_id,
                    'user_code' => $data->student_user_code,
                    'user_login' => $data->student_user_login,
                    'term_name' => $data->tern_name,
                    'term_name_pass' => $data->term_name_pass,
                    'campus_code' => session('campus_db'),
                    'point' => $data->point,
                    'skill_code' => $data->skill_code,
                    'subject_id' => $data->subject_id,
                    'subject_code' => $data->subject_code,
                    'subject_name' => $data->subject_name,
                    'type' => $data->type,
                    'course_id' => $data->course_id,
                    'syllabus_id' => $data->syllabus_id,
                    'check_progress' => 0,
                    'check_final' => 1,
                    'grade_id' => $data->grade_id,
                    'grade_name' => $data->grade_name,
                    'luot_hoc' => 1,
                    'luot_thi' => 1,
                    'payment_status' => 0,
                    'xep_lop' => 0,
                    'group_id' => $relearn_online_calendar_user->new_group_id,
                    'created_by' => auth()->user()->user_login,
                    'updated_by' => auth()->user()->user_login,
                    'status' => 0
                ]);
            }

            if ($relearn_online == null || $relearn_online < 1) {
                throw new Exception('------Err RetestRepository storeSinglePointInRelearnOnline error ID' . $data->online_service_id . ' ---------');
            }
            $this->updateStatusGraded($data);
        } catch (\Throwable $th) {
            error_log($th);
            throw new Exception('------Err RetestRepository storeSinglePointInRelearnOnline ---------');
            Log::error($th);
        }
    }