diff --git a/app/Services/Logic/Chapter/ChapterInfo.php b/app/Services/Logic/Chapter/ChapterInfo.php index b6cd75b5..3311e644 100644 --- a/app/Services/Logic/Chapter/ChapterInfo.php +++ b/app/Services/Logic/Chapter/ChapterInfo.php @@ -126,6 +126,7 @@ class ChapterInfo extends LogicService $chapterUser = new ChapterUserModel(); + $chapterUser->plan_id = $this->courseUser->plan_id; $chapterUser->course_id = $chapter->course_id; $chapterUser->chapter_id = $chapter->id; $chapterUser->user_id = $user->id; diff --git a/db/migrations/20240111185633.php b/db/migrations/20240111185633.php new file mode 100644 index 00000000..75e433d9 --- /dev/null +++ b/db/migrations/20240111185633.php @@ -0,0 +1,32 @@ +handleChapterUsers(); + } + + /** + * 纠正 chapter_user 表中 plan_id = 0 的数据 + * + * @return void + */ + protected function handleChapterUsers() + { + $sql = 'UPDATE kg_chapter_user AS a JOIN kg_course_user AS b + ON a.course_id = b.course_id AND a.user_id = b.user_id + SET a.plan_id = b.plan_id WHERE a.plan_id = 0'; + + $this->query($sql); + } + +}