diff --git a/app/Builders/CategoryTreeList.php b/app/Builders/CategoryTreeList.php index 82f22690..dfb524d1 100644 --- a/app/Builders/CategoryTreeList.php +++ b/app/Builders/CategoryTreeList.php @@ -58,7 +58,8 @@ class CategoryTreeList extends Builder { return CategoryModel::query() ->where('parent_id = :parent_id:', ['parent_id' => $categoryId]) - ->andWhere('deleted = 0') + ->andWhere('published = 1') + ->orderBy('priority ASC') ->execute(); } diff --git a/app/Caches/CategoryList.php b/app/Caches/CategoryList.php index 0c792f9d..e73ad4cf 100644 --- a/app/Caches/CategoryList.php +++ b/app/Caches/CategoryList.php @@ -31,7 +31,7 @@ class CategoryList extends Cache */ $categories = CategoryModel::query() ->columns(['id', 'parent_id', 'name', 'priority', 'level', 'path']) - ->where('published = 1 AND deleted = 0') + ->where('published = 1') ->execute(); if ($categories->count() == 0) { diff --git a/app/Caches/ImChatGroup.php b/app/Caches/ImChatGroup.php index c1a41d1a..8c7d7ec1 100644 --- a/app/Caches/ImChatGroup.php +++ b/app/Caches/ImChatGroup.php @@ -16,7 +16,7 @@ class ImGroup extends Cache public function getKey($id = null) { - return "im_chat_group:{$id}"; + return "im_group:{$id}"; } public function getContent($id = null) diff --git a/app/Console/Tasks/CleanLogTask.php b/app/Console/Tasks/CleanLogTask.php index 7cc0287a..4e171edb 100644 --- a/app/Console/Tasks/CleanLogTask.php +++ b/app/Console/Tasks/CleanLogTask.php @@ -18,6 +18,7 @@ class CleanLogTask extends Task $this->cleanMailerLog(); $this->cleanSmserLog(); $this->cleanVodLog(); + $this->cleanLiveLog(); $this->cleanStorageLog(); $this->cleanAlipayLog(); $this->cleanWxpayLog(); @@ -81,6 +82,14 @@ class CleanLogTask extends Task $this->cleanLog('vod', 7); } + /** + * 清理直播服务日志 + */ + protected function cleanLiveLog() + { + $this->cleanLog('live', 7); + } + /** * 清理存储服务日志 */ diff --git a/app/Console/Tasks/SyncChapterCounterTask.php b/app/Console/Tasks/SyncChapterCounterTask.php index 61c3b3de..cce2bcf6 100644 --- a/app/Console/Tasks/SyncChapterCounterTask.php +++ b/app/Console/Tasks/SyncChapterCounterTask.php @@ -50,13 +50,11 @@ class SyncChapterCounterTask extends Task $chapterCache = new ChapterCache(); - $hour = date('H'); - - $recount = $this->checkEnableRecount(); + $allowRecount = $this->allowRecount(); foreach ($chapters as $chapter) { - if ($recount && $hour % 3 == 0) { + if ($allowRecount) { $chapter->user_count = $chapterRepo->countUsers($chapter->id); $chapter->lesson_count = $chapterRepo->countLessons($chapter->id); @@ -94,11 +92,9 @@ class SyncChapterCounterTask extends Task return $syncer->getSyncKey(); } - protected function checkEnableRecount() + protected function allowRecount() { - $config = $this->getDI()->get('config'); - - return $config->syncer->recount_chapter ?? false; + return date('H') % 2 == 0; } } diff --git a/app/Console/Tasks/SyncCommentCounterTask.php b/app/Console/Tasks/SyncCommentCounterTask.php index 7485430d..f63321f3 100644 --- a/app/Console/Tasks/SyncCommentCounterTask.php +++ b/app/Console/Tasks/SyncCommentCounterTask.php @@ -47,13 +47,11 @@ class SyncCommentCounterTask extends Task $counterCache = new CommentCounterCache(); - $hour = date('H'); - - $recount = $this->checkEnableRecount(); + $allowRecount = $this->allowRecount(); foreach ($comments as $comment) { - if ($recount && $hour % 3 == 0) { + if ($allowRecount) { $comment->reply_count = $commentRepo->countReplies($comment->id); $comment->like_count = $commentRepo->countLikes($comment->id); @@ -83,11 +81,9 @@ class SyncCommentCounterTask extends Task return $syncer->getSyncKey(); } - protected function checkEnableRecount() + protected function allowRecount() { - $config = $this->getDI()->get('config'); - - return $config->syncer->recount_comment ?? false; + return date('H') == 5; } } diff --git a/app/Console/Tasks/SyncConsultCounterTask.php b/app/Console/Tasks/SyncConsultCounterTask.php index 834e2250..46fc53cc 100644 --- a/app/Console/Tasks/SyncConsultCounterTask.php +++ b/app/Console/Tasks/SyncConsultCounterTask.php @@ -47,13 +47,11 @@ class SyncConsultCounterTask extends Task $counterCache = new ConsultCounterCache(); - $hour = date('H'); - - $recount = $this->checkEnableRecount(); + $allowRecount = $this->allowRecount(); foreach ($consults as $consult) { - if ($recount && $hour % 3 == 0) { + if ($allowRecount) { $consult->like_count = $consultRepo->countLikes($consult->id); $consult->update(); @@ -81,11 +79,9 @@ class SyncConsultCounterTask extends Task return $syncer->getSyncKey(); } - protected function checkEnableRecount() + protected function allowRecount() { - $config = $this->getDI()->get('config'); - - return $config->syncer->recount_consult ?? false; + return date('H') == 1; } } diff --git a/app/Console/Tasks/SyncCourseCounterTask.php b/app/Console/Tasks/SyncCourseCounterTask.php index 07313476..51bc25b7 100644 --- a/app/Console/Tasks/SyncCourseCounterTask.php +++ b/app/Console/Tasks/SyncCourseCounterTask.php @@ -50,16 +50,13 @@ class SyncCourseCounterTask extends Task $courseCache = new CourseCache(); - $hour = date('H'); - - $recount = $this->checkEnableRecount(); + $allowRecount = $this->allowRecount(); foreach ($courses as $course) { - if ($recount && $hour % 3 == 0) { + if ($allowRecount) { $course->user_count = $courseRepo->countUsers($course->id); - $course->lesson_count = $courseRepo->countLessons($course->id); $course->comment_count = $courseRepo->countComments($course->id); $course->consult_count = $courseRepo->countConsults($course->id); $course->review_count = $courseRepo->countReviews($course->id); @@ -75,7 +72,6 @@ class SyncCourseCounterTask extends Task if ($counter) { $course->user_count = $counter['user_count']; - $course->lesson_count = $counter['lesson_count']; $course->comment_count = $counter['comment_count']; $course->consult_count = $counter['consult_count']; $course->review_count = $counter['review_count']; @@ -95,11 +91,9 @@ class SyncCourseCounterTask extends Task return $syncer->getSyncKey(); } - protected function checkEnableRecount() + protected function allowRecount() { - $config = $this->getDI()->get('config'); - - return $config->syncer->recount_course ?? false; + return date('H') % 2 == 0; } } diff --git a/app/Console/Tasks/SyncReviewCounterTask.php b/app/Console/Tasks/SyncReviewCounterTask.php index b6d512d4..ca67c0dc 100644 --- a/app/Console/Tasks/SyncReviewCounterTask.php +++ b/app/Console/Tasks/SyncReviewCounterTask.php @@ -47,13 +47,11 @@ class SyncReviewCounterTask extends Task $counterCache = new ReviewCounterCache(); - $hour = date('H'); - - $recount = $this->checkEnableRecount(); + $allowRecount = $this->allowRecount(); foreach ($reviews as $review) { - if ($recount && $hour % 3 == 0) { + if ($allowRecount) { $review->like_count = $reviewRepo->countLikes($review->id); $review->update(); @@ -81,11 +79,9 @@ class SyncReviewCounterTask extends Task return $syncer->getSyncKey(); } - protected function checkEnableRecount() + protected function allowRecount() { - $config = $this->getDI()->get('config'); - - return $config->syncer->recount_review ?? false; + return date('H') == 2; } } diff --git a/app/Http/Web/Services/ImGroupTrait.php b/app/Http/Web/Services/ImGroupTrait.php index 045024db..00600206 100644 --- a/app/Http/Web/Services/ImGroupTrait.php +++ b/app/Http/Web/Services/ImGroupTrait.php @@ -72,6 +72,8 @@ Trait ImGroupTrait 'group_id' => $group->id, 'user_id' => $applicant->id, ]); + $group->user_count += 1; + $group->update(); } $itemInfo = $message->item_info; diff --git a/app/Models/Category.php b/app/Models/Category.php index 1e48b380..dc0fe2ed 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -117,6 +117,10 @@ class Category extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public function afterCreate() diff --git a/app/Models/Chapter.php b/app/Models/Chapter.php index 26a99523..669df6c4 100644 --- a/app/Models/Chapter.php +++ b/app/Models/Chapter.php @@ -216,6 +216,10 @@ class Chapter extends Model { $this->update_time = time(); + if ($this->deleted == 1) { + $this->published = 0; + } + if (is_array($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } diff --git a/app/Models/Comment.php b/app/Models/Comment.php index cfb44bd0..35c5758d 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -123,6 +123,10 @@ class Comment extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } } diff --git a/app/Models/Consult.php b/app/Models/Consult.php index cd5979cf..4e1d803f 100644 --- a/app/Models/Consult.php +++ b/app/Models/Consult.php @@ -109,6 +109,10 @@ class Consult extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } } diff --git a/app/Models/Course.php b/app/Models/Course.php index a90766c0..a6144f5d 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -284,6 +284,10 @@ class Course extends Model { $this->update_time = time(); + if ($this->deleted == 1) { + $this->published = 0; + } + if (Text::startsWith($this->cover, 'http')) { $this->cover = self::getCoverPath($this->cover); } diff --git a/app/Models/Danmu.php b/app/Models/Danmu.php index 3a4334f1..aa08629d 100644 --- a/app/Models/Danmu.php +++ b/app/Models/Danmu.php @@ -145,6 +145,10 @@ class Danmu extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public static function sizeTypes() diff --git a/app/Models/Help.php b/app/Models/Help.php index 6ee09917..455a98f2 100644 --- a/app/Models/Help.php +++ b/app/Models/Help.php @@ -89,6 +89,10 @@ class Help extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public function afterCreate() diff --git a/app/Models/Nav.php b/app/Models/Nav.php index 293d9607..626781b9 100644 --- a/app/Models/Nav.php +++ b/app/Models/Nav.php @@ -142,6 +142,10 @@ class Nav extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public static function positionTypes() diff --git a/app/Models/Package.php b/app/Models/Package.php index eaf5919b..d929b49c 100644 --- a/app/Models/Package.php +++ b/app/Models/Package.php @@ -103,6 +103,10 @@ class Package extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public function afterCreate() diff --git a/app/Models/Page.php b/app/Models/Page.php index a5390a87..dee6684a 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -29,6 +29,13 @@ class Page extends Model */ public $content; + /** + * 发布标识 + * + * @var int + */ + public $published; + /** * 删除标识 * @@ -75,6 +82,10 @@ class Page extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public function afterCreate() diff --git a/app/Models/Review.php b/app/Models/Review.php index b0bf7366..3df6c879 100644 --- a/app/Models/Review.php +++ b/app/Models/Review.php @@ -134,6 +134,10 @@ class Review extends Model $this->update_time = time(); $this->rating = $this->getAvgRating(); + + if ($this->deleted == 1) { + $this->published = 0; + } } protected function getAvgRating() diff --git a/app/Models/Slide.php b/app/Models/Slide.php index 88dd82eb..c7f957e5 100644 --- a/app/Models/Slide.php +++ b/app/Models/Slide.php @@ -135,6 +135,10 @@ class Slide extends Model { $this->update_time = time(); + if ($this->deleted == 1) { + $this->published = 0; + } + if (Text::startsWith($this->cover, 'http')) { $this->cover = self::getCoverPath($this->cover); } diff --git a/app/Models/Topic.php b/app/Models/Topic.php index 9294fef0..097a364f 100644 --- a/app/Models/Topic.php +++ b/app/Models/Topic.php @@ -89,6 +89,10 @@ class Topic extends Model public function beforeUpdate() { $this->update_time = time(); + + if ($this->deleted == 1) { + $this->published = 0; + } } public function afterCreate() diff --git a/app/Repos/Category.php b/app/Repos/Category.php index a00c5bfc..27ee9249 100644 --- a/app/Repos/Category.php +++ b/app/Repos/Category.php @@ -72,7 +72,6 @@ class Category extends Repository { return CategoryModel::query() ->where('parent_id = 0') - ->andWhere('deleted = 0') ->andWhere('published = 1') ->execute(); } @@ -85,7 +84,6 @@ class Category extends Repository { return CategoryModel::query() ->where('parent_id = :parent_id:', ['parent_id' => $categoryId]) - ->andWhere('deleted = 0') ->andWhere('published = 1') ->execute(); } @@ -93,7 +91,7 @@ class Category extends Repository public function countChildCategories($categoryId) { return CategoryModel::count([ - 'conditions' => 'parent_id = :parent_id: AND deleted = 0 AND published = 1', + 'conditions' => 'parent_id = :parent_id: AND published = 1', 'bind' => ['parent_id' => $categoryId], ]); } @@ -101,7 +99,7 @@ class Category extends Repository public function countCourses($categoryId) { $phql = 'SELECT COUNT(*) AS total FROM %s cc JOIN %s c ON cc.course_id = c.id - WHERE cc.category_id = :category_id: AND c.published = 1 AND c.deleted = 0'; + WHERE cc.category_id = :category_id: AND c.published = 1 AND c.published = 1'; $phql = sprintf($phql, CourseCategoryModel::class, CourseModel::class); diff --git a/app/Repos/Course.php b/app/Repos/Course.php index 76485636..f0cd5cd7 100644 --- a/app/Repos/Course.php +++ b/app/Repos/Course.php @@ -146,7 +146,6 @@ class Course extends Repository ->join(CourseUserModel::class, 'u.id = cu.user_id', 'cu') ->where('cu.course_id = :course_id:', ['course_id' => $courseId]) ->andWhere('cu.role_type = :role_type:', ['role_type' => $roleType]) - ->andWhere('u.deleted = 0') ->getQuery()->execute(); } @@ -161,7 +160,7 @@ class Course extends Repository ->addFrom(CategoryModel::class, 'c') ->join(CourseCategoryModel::class, 'c.id = cc.category_id', 'cc') ->where('cc.course_id = :course_id:', ['course_id' => $courseId]) - ->andWhere('c.deleted = 0') + ->andWhere('c.published = 1') ->getQuery()->execute(); } @@ -176,7 +175,7 @@ class Course extends Repository ->addFrom(PackageModel::class, 'p') ->join(CoursePackageModel::class, 'p.id = cp.package_id', 'cp') ->where('cp.course_id = :course_id:', ['course_id' => $courseId]) - ->andWhere('p.deleted = 0') + ->andWhere('p.published = 1') ->getQuery()->execute(); } @@ -191,7 +190,7 @@ class Course extends Repository ->addFrom(CourseModel::class, 'c') ->join(CourseRelatedModel::class, 'c.id = cr.related_id', 'cr') ->where('cr.course_id = :course_id:', ['course_id' => $courseId]) - ->andWhere('c.deleted = 0') + ->andWhere('c.published = 1') ->getQuery()->execute(); } diff --git a/app/Repos/Package.php b/app/Repos/Package.php index d75cabc2..4450e4fc 100644 --- a/app/Repos/Package.php +++ b/app/Repos/Package.php @@ -87,7 +87,7 @@ class Package extends Repository ->addFrom(CourseModel::class, 'c') ->join(CoursePackageModel::class, 'c.id = cp.course_id', 'cp') ->where('cp.package_id = :package_id:', ['package_id' => $packageId]) - ->andWhere('c.deleted = 0') + ->andWhere('c.published = 1') ->getQuery() ->execute(); } diff --git a/app/Repos/Topic.php b/app/Repos/Topic.php index b76f0394..6b87f1fd 100644 --- a/app/Repos/Topic.php +++ b/app/Repos/Topic.php @@ -83,7 +83,7 @@ class Topic extends Repository ->addFrom(CourseModel::class, 'c') ->join(CourseTopicModel::class, 'c.id = ct.course_id', 'ct') ->where('ct.topic_id = :topic_id:', ['topic_id' => $topicId]) - ->andWhere('c.deleted = 0') + ->andWhere('c.published = 1') ->getQuery()->execute(); } diff --git a/app/Services/Captcha.php b/app/Services/Captcha.php index 26278718..c5b98dc1 100644 --- a/app/Services/Captcha.php +++ b/app/Services/Captcha.php @@ -59,7 +59,7 @@ class Captcha extends Service $request = new DescribeCaptchaResultRequest(); /** - * 注意:CaptchaType 和 CaptchaAppId 强类型要求 + * 注意:CaptchaType和CaptchaAppId强类型要求 */ $params = json_encode([ 'Ticket' => $ticket, diff --git a/app/Services/Frontend/Chapter/ChapterBasic.php b/app/Services/Frontend/Chapter/ChapterBasic.php index 25966e2c..309d9194 100644 --- a/app/Services/Frontend/Chapter/ChapterBasic.php +++ b/app/Services/Frontend/Chapter/ChapterBasic.php @@ -48,11 +48,6 @@ class ChapterBasic extends FrontendService $playUrls = $chapterVodService->getPlayUrls($chapter->id); - /** - * @var array $attrs - */ - $attrs = $chapter->attrs; - return [ 'id' => $chapter->id, 'title' => $chapter->title, @@ -83,11 +78,6 @@ class ChapterBasic extends FrontendService $live = $chapterRepo->findChapterLive($chapter->id); - /** - * @var array $attrs - */ - $attrs = $chapter->attrs; - return [ 'id' => $chapter->id, 'title' => $chapter->title, diff --git a/app/Services/Frontend/Chapter/Learning.php b/app/Services/Frontend/Chapter/Learning.php index d87300cb..ee217ddc 100644 --- a/app/Services/Frontend/Chapter/Learning.php +++ b/app/Services/Frontend/Chapter/Learning.php @@ -28,6 +28,7 @@ class Learning extends FrontendService 'course_id' => $chapter->course_id, 'chapter_id' => $chapter->id, 'user_id' => $user->id, + 'position' => 0, ]; $data['request_id'] = $validator->checkRequestId($post['request_id']); diff --git a/app/Services/Frontend/Course/Favorite.php b/app/Services/Frontend/Course/Favorite.php index d350e0bc..c561bca6 100644 --- a/app/Services/Frontend/Course/Favorite.php +++ b/app/Services/Frontend/Course/Favorite.php @@ -5,9 +5,9 @@ namespace App\Services\Frontend\Course; use App\Models\Course as CourseModel; use App\Models\CourseFavorite as CourseFavoriteModel; use App\Models\User as UserModel; -use App\Repos\CourseFavorite as CourseFavoriteRepo; use App\Services\Frontend\CourseTrait; use App\Services\Frontend\Service as FrontendService; +use App\Validators\Course as CourseValidator; use App\Validators\UserDailyLimit as UserDailyLimitValidator; class Favorite extends FrontendService @@ -25,18 +25,18 @@ class Favorite extends FrontendService $validator->checkFavoriteLimit($user); - $favoriteRepo = new CourseFavoriteRepo(); + $validator = new CourseValidator(); - $favorite = $favoriteRepo->findCourseFavorite($course->id, $user->id); + $favorite = $validator->checkIfFavorited($course->id, $user->id); if (!$favorite) { $favorite = new CourseFavoriteModel(); - $favorite->course_id = $course->id; - $favorite->user_id = $user->id; - - $favorite->create(); + $favorite->create([ + 'course_id' => $course->id, + 'user_id' => $user->id, + ]); $this->incrCourseFavoriteCount($course); @@ -44,18 +44,16 @@ class Favorite extends FrontendService if ($favorite->deleted == 0) { - $favorite->deleted = 1; + $favorite->update(['deleted' => 1]); $this->decrCourseFavoriteCount($course); } else { - $favorite->deleted = 0; + $favorite->update(['deleted' => 0]); $this->incrCourseFavoriteCount($course); } - - $favorite->update(); } $this->incrUserDailyFavoriteCount($user); diff --git a/app/Services/Frontend/Messenger/ContactList.php b/app/Services/Frontend/Messenger/ContactList.php deleted file mode 100644 index b0bbbfe7..00000000 --- a/app/Services/Frontend/Messenger/ContactList.php +++ /dev/null @@ -1,19 +0,0 @@ -getLoginUser(); - - $mine = [ - - ]; - } - -} diff --git a/app/Validators/Chapter.php b/app/Validators/Chapter.php index 7b9599d9..073c5a6e 100644 --- a/app/Validators/Chapter.php +++ b/app/Validators/Chapter.php @@ -137,7 +137,7 @@ class Chapter extends Validator return $status; } - public function checkPublishAbility($chapter) + public function checkPublishAbility(ChapterModel $chapter) { $courseRepo = new CourseRepo(); @@ -160,7 +160,7 @@ class Chapter extends Validator } } - public function checkDeleteAbility($chapter) + public function checkDeleteAbility(ChapterModel $chapter) { $chapterRepo = new ChapterRepo(); @@ -178,13 +178,13 @@ class Chapter extends Validator { $repo = new ChapterLikeRepo(); - $chapterLike = $repo->findChapterLike($chapterId, $userId); + $like = $repo->findChapterLike($chapterId, $userId); - if ($chapterLike && time() - $chapterLike->create_time > 5 * 60) { + if ($like && time() - $like->create_time > 5 * 60) { throw new BadRequestException('chapter.has_liked'); } - return $chapterLike; + return $like; } } diff --git a/app/Validators/Comment.php b/app/Validators/Comment.php index f76743f8..50508370 100644 --- a/app/Validators/Comment.php +++ b/app/Validators/Comment.php @@ -80,13 +80,13 @@ class Comment extends Validator { $repo = new CommentLikeRepo(); - $commentLike = $repo->findCommentLike($chapterId, $userId); + $like = $repo->findCommentLike($chapterId, $userId); - if ($commentLike && time() - $commentLike->create_time > 5 * 60) { + if ($like && time() - $like->create_time > 5 * 60) { throw new BadRequestException('comment.has_liked'); } - return $commentLike; + return $like; } } diff --git a/app/Validators/Consult.php b/app/Validators/Consult.php index 6bf2a922..51a42ed8 100644 --- a/app/Validators/Consult.php +++ b/app/Validators/Consult.php @@ -85,13 +85,13 @@ class Consult extends Validator { $repo = new ConsultLikeRepo(); - $consultLike = $repo->findConsultLike($chapterId, $userId); + $like = $repo->findConsultLike($chapterId, $userId); - if ($consultLike && time() - $consultLike->create_time > 5 * 60) { + if ($like && time() - $like->create_time > 5 * 60) { throw new BadRequestException('consult.has_liked'); } - return $consultLike; + return $like; } } diff --git a/app/Validators/Course.php b/app/Validators/Course.php index a97d5ee6..a149343f 100644 --- a/app/Validators/Course.php +++ b/app/Validators/Course.php @@ -8,6 +8,7 @@ use App\Exceptions\BadRequest as BadRequestException; use App\Library\Validators\Common as CommonValidator; use App\Models\Course as CourseModel; use App\Repos\Course as CourseRepo; +use App\Repos\CourseFavorite as CourseFavoriteRepo; class Course extends Validator { @@ -217,7 +218,7 @@ class Course extends Validator return $status; } - public function checkPublishAbility($course) + public function checkPublishAbility(CourseModel $course) { $courseRepo = new CourseRepo(); @@ -242,4 +243,17 @@ class Course extends Validator } } + public function checkIfFavorited($courseId, $userId) + { + $repo = new CourseFavoriteRepo(); + + $favorite = $repo->findCourseFavorite($courseId, $userId); + + if ($favorite && time() - $favorite->create_time > 5 * 60) { + throw new BadRequestException('course.has_favorited'); + } + + return $favorite; + } + } diff --git a/app/Validators/Review.php b/app/Validators/Review.php index 6e59bc4d..89755dfa 100644 --- a/app/Validators/Review.php +++ b/app/Validators/Review.php @@ -69,13 +69,13 @@ class Review extends Validator { $repo = new ReviewLikeRepo(); - $reviewLike = $repo->findReviewLike($reviewId, $userId); + $like = $repo->findReviewLike($reviewId, $userId); - if ($reviewLike && time() - $reviewLike->create_time > 5 * 60) { + if ($like && time() - $like->create_time > 5 * 60) { throw new BadRequestException('review.has_liked'); } - return $reviewLike; + return $like; } } diff --git a/config/errors.php b/config/errors.php index 173a04cd..4c5321da 100644 --- a/config/errors.php +++ b/config/errors.php @@ -112,6 +112,7 @@ $error['course.invalid_refund_expiry'] = '无效的退款期限'; $error['course.invalid_publish_status'] = '无效的发布状态'; $error['course.pub_chapter_not_found'] = '尚未发现已发布的课时'; $error['course.pub_chapter_not_enough'] = '已发布的课时太少(小于30%)'; +$error['course.has_favorited'] = '你已收藏过该课程啦'; /** * 话题相关 diff --git a/public/static/web/css/common.css b/public/static/web/css/common.css index c075d058..8c8499fd 100644 --- a/public/static/web/css/common.css +++ b/public/static/web/css/common.css @@ -84,6 +84,12 @@ bottom: 60px; } +body { + display: flex; + flex-flow: column; + min-height: 100vh; +} + #header { left: 0; top: 0; @@ -96,14 +102,15 @@ #main { margin-top: 80px; margin-bottom: 30px; - min-height: 550px; + flex: 1; } #footer { + width: 100%; padding: 30px 0; + background: #474443; text-align: center; font-size: 12px; - background: #474443; } .logo { @@ -137,11 +144,15 @@ color: #fff; } -.bottom-nav, .copyright { +.bottom-nav { margin-bottom: 10px; line-height: 18px; } +.copyright { + line-height: 18px; +} + .bottom-nav a, .copyright span, .copyright a { margin-right: 10px; }