diff --git a/app/Services/Logic/Chapter/ChapterInfo.php b/app/Services/Logic/Chapter/ChapterInfo.php index 58a01eea..cc7e34a4 100644 --- a/app/Services/Logic/Chapter/ChapterInfo.php +++ b/app/Services/Logic/Chapter/ChapterInfo.php @@ -75,47 +75,7 @@ class ChapterInfo extends LogicService $result['course'] = $service->handleCourseInfo($this->course); - $me = [ - 'role_type' => 0, - 'plan_id' => 0, - 'position' => 0, - 'logged' => 0, - 'joined' => 0, - 'owned' => 0, - 'liked' => 0, - ]; - - if ($this->joinedChapter) { - $me['joined'] = 1; - } - - if ($this->ownedChapter) { - $me['owned'] = 1; - } - - if ($user->id > 0) { - - $me['logged'] = 1; - - $likeRepo = new ChapterLikeRepo(); - - $like = $likeRepo->findChapterLike($chapter->id, $user->id); - - if ($like && $like->deleted == 0) { - $me['liked'] = 1; - } - - if ($this->courseUser) { - $me['role_type'] = $this->courseUser->role_type; - $me['plan_id'] = $this->courseUser->plan_id; - } - - if ($this->chapterUser) { - $me['position'] = $this->chapterUser->position; - } - } - - $result['me'] = $me; + $result['me'] = $this->handleMeInfo($chapter, $user); return $result; } @@ -179,6 +139,51 @@ class ChapterInfo extends LogicService $this->incrChapterUserCount($chapter); } + protected function handleMeInfo(ChapterModel $chapter, UserModel $user) + { + $me = [ + 'role_type' => 0, + 'plan_id' => 0, + 'position' => 0, + 'logged' => 0, + 'joined' => 0, + 'owned' => 0, + 'liked' => 0, + ]; + + if ($user->id > 0) { + + if ($this->joinedChapter) { + $me['joined'] = 1; + } + + if ($this->ownedChapter) { + $me['owned'] = 1; + } + + $me['logged'] = 1; + + $likeRepo = new ChapterLikeRepo(); + + $like = $likeRepo->findChapterLike($chapter->id, $user->id); + + if ($like && $like->deleted == 0) { + $me['liked'] = 1; + } + + if ($this->courseUser) { + $me['role_type'] = $this->courseUser->role_type; + $me['plan_id'] = $this->courseUser->plan_id; + } + + if ($this->chapterUser) { + $me['position'] = $this->chapterUser->position; + } + } + + return $me; + } + protected function incrUserCourseCount(UserModel $user) { $user->course_count += 1; diff --git a/app/Services/Logic/Course/CourseInfo.php b/app/Services/Logic/Course/CourseInfo.php index d3d822f3..35132017 100644 --- a/app/Services/Logic/Course/CourseInfo.php +++ b/app/Services/Logic/Course/CourseInfo.php @@ -35,6 +35,13 @@ class CourseInfo extends LogicService $result = $service->handleBasicInfo($course); + $result['me'] = $this->handleMeInfo($course, $user); + + return $result; + } + + protected function handleMeInfo(CourseModel $course, UserModel $user) + { $me = [ 'plan_id' => 0, 'allow_order' => 0, @@ -47,14 +54,6 @@ class CourseInfo extends LogicService 'favorited' => 0, ]; - if ($this->joinedCourse) { - $me['joined'] = 1; - } - - if ($this->ownedCourse) { - $me['owned'] = 1; - } - $caseOwned = $this->ownedCourse == false; $casePrice = $course->market_price > 0; $caseModel = true; @@ -76,6 +75,22 @@ class CourseInfo extends LogicService if ($user->id > 0) { + if ($caseOwned && $casePrice && $caseModel) { + $me['allow_order'] = 1; + } + + if ($course->market_price == 0) { + $me['allow_reward'] = 1; + } + + if ($this->joinedCourse) { + $me['joined'] = 1; + } + + if ($this->ownedCourse) { + $me['owned'] = 1; + } + $me['logged'] = 1; $favoriteRepo = new CourseFavoriteRepo(); @@ -93,9 +108,7 @@ class CourseInfo extends LogicService } } - $result['me'] = $me; - - return $result; + return $me; } }