1
0
mirror of https://gitee.com/koogua/course-tencent-cloud.git synced 2025-06-26 20:52:44 +08:00

优化课程章节handleMeInfo

This commit is contained in:
xiaochong0302 2023-06-15 18:55:31 +08:00
parent a72f44225f
commit 36ef6ca37b
2 changed files with 70 additions and 52 deletions

View File

@ -75,47 +75,7 @@ class ChapterInfo extends LogicService
$result['course'] = $service->handleCourseInfo($this->course); $result['course'] = $service->handleCourseInfo($this->course);
$me = [ $result['me'] = $this->handleMeInfo($chapter, $user);
'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;
return $result; return $result;
} }
@ -179,6 +139,51 @@ class ChapterInfo extends LogicService
$this->incrChapterUserCount($chapter); $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) protected function incrUserCourseCount(UserModel $user)
{ {
$user->course_count += 1; $user->course_count += 1;

View File

@ -35,6 +35,13 @@ class CourseInfo extends LogicService
$result = $service->handleBasicInfo($course); $result = $service->handleBasicInfo($course);
$result['me'] = $this->handleMeInfo($course, $user);
return $result;
}
protected function handleMeInfo(CourseModel $course, UserModel $user)
{
$me = [ $me = [
'plan_id' => 0, 'plan_id' => 0,
'allow_order' => 0, 'allow_order' => 0,
@ -47,14 +54,6 @@ class CourseInfo extends LogicService
'favorited' => 0, 'favorited' => 0,
]; ];
if ($this->joinedCourse) {
$me['joined'] = 1;
}
if ($this->ownedCourse) {
$me['owned'] = 1;
}
$caseOwned = $this->ownedCourse == false; $caseOwned = $this->ownedCourse == false;
$casePrice = $course->market_price > 0; $casePrice = $course->market_price > 0;
$caseModel = true; $caseModel = true;
@ -76,6 +75,22 @@ class CourseInfo extends LogicService
if ($user->id > 0) { 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; $me['logged'] = 1;
$favoriteRepo = new CourseFavoriteRepo(); $favoriteRepo = new CourseFavoriteRepo();
@ -93,9 +108,7 @@ class CourseInfo extends LogicService
} }
} }
$result['me'] = $me; return $me;
return $result;
} }
} }