From f04c23e90ff931261d6f7c37871d5bd7f5d2f91f Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Fri, 28 Jun 2024 08:26:28 +0800 Subject: [PATCH] =?UTF-8?q?1.=E6=B7=BB=E5=8A=A0=E8=AF=BE=E7=A8=8B=E5=92=8C?= =?UTF-8?q?=E7=AB=A0=E8=8A=82=E4=BA=8B=E4=BB=B6=E7=9B=91=E5=90=AC=202.?= =?UTF-8?q?=E4=BC=98=E5=8C=96SEO=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Api/Module.php | 4 +- app/Http/Home/Services/Connect.php | 2 + .../Home/Services/WeChatOfficialAccount.php | 2 + app/Library/Seo.php | 14 +++++ app/Listeners/Chapter.php | 51 +++++++++++++++++++ app/Listeners/Course.php | 51 +++++++++++++++++++ app/Services/Logic/Chapter/ChapterInfo.php | 6 ++- app/Services/Logic/Chapter/ChapterLike.php | 4 ++ app/Services/Logic/Course/CourseFavorite.php | 4 ++ app/Services/Logic/Course/CourseInfo.php | 6 ++- 10 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 app/Listeners/Chapter.php create mode 100644 app/Listeners/Course.php diff --git a/app/Http/Api/Module.php b/app/Http/Api/Module.php index 2efcc423..87146a69 100644 --- a/app/Http/Api/Module.php +++ b/app/Http/Api/Module.php @@ -7,7 +7,7 @@ namespace App\Http\Api; -use App\Services\Auth\Api as AppAuth; +use App\Services\Auth\Api as ApiAuth; use Phalcon\DiInterface; use Phalcon\Mvc\ModuleDefinitionInterface; use Phalcon\Mvc\View; @@ -29,7 +29,7 @@ class Module implements ModuleDefinitionInterface }); $dependencyInjector->setShared('auth', function () { - return new AppAuth(); + return new ApiAuth(); }); } diff --git a/app/Http/Home/Services/Connect.php b/app/Http/Home/Services/Connect.php index 3345c6b0..0d96ddaf 100644 --- a/app/Http/Home/Services/Connect.php +++ b/app/Http/Home/Services/Connect.php @@ -70,6 +70,8 @@ class Connect extends Service $auth = $this->getAppAuth(); $auth->saveAuthInfo($user); + + $this->eventsManager->fire('Account:afterRegister', $this, $user); } public function bindUser(array $openUser) diff --git a/app/Http/Home/Services/WeChatOfficialAccount.php b/app/Http/Home/Services/WeChatOfficialAccount.php index e12ed1a4..1126665d 100644 --- a/app/Http/Home/Services/WeChatOfficialAccount.php +++ b/app/Http/Home/Services/WeChatOfficialAccount.php @@ -103,6 +103,8 @@ class WeChatOfficialAccount extends Service $auth = $this->getAppAuth(); $auth->saveAuthInfo($user); + + $this->eventsManager->fire('Account:afterRegister', $this, $user); } protected function getAppAuth() diff --git a/app/Library/Seo.php b/app/Library/Seo.php index 9976b433..88f617f7 100644 --- a/app/Library/Seo.php +++ b/app/Library/Seo.php @@ -30,6 +30,11 @@ class Seo */ protected $titleSeparator = ' - '; + /** + * @var string 关键字分隔符 + */ + protected $keywordSeparator = ','; + public function setTitle($title) { $this->title = $title; @@ -37,6 +42,10 @@ class Seo public function setKeywords($keywords) { + if (is_array($keywords)) { + $keywords = implode($this->keywordSeparator, $keywords); + } + $this->keywords = $keywords; } @@ -84,4 +93,9 @@ class Seo return $this->titleSeparator; } + public function getKeywordSeparator() + { + return $this->keywordSeparator; + } + } diff --git a/app/Listeners/Chapter.php b/app/Listeners/Chapter.php new file mode 100644 index 00000000..291916f3 --- /dev/null +++ b/app/Listeners/Chapter.php @@ -0,0 +1,51 @@ +setChapterUser($chapter, $user); $this->handleChapterUser($chapter, $user); - return $this->handleChapter($chapter, $user); + $result = $this->handleChapter($chapter, $user); + + $this->eventsManager->fire('Chapter:afterView', $this, $chapter); + + return $result; } protected function handleChapter(ChapterModel $chapter, UserModel $user) diff --git a/app/Services/Logic/Chapter/ChapterLike.php b/app/Services/Logic/Chapter/ChapterLike.php index d9a97774..c4aa84c5 100644 --- a/app/Services/Logic/Chapter/ChapterLike.php +++ b/app/Services/Logic/Chapter/ChapterLike.php @@ -58,11 +58,15 @@ class ChapterLike extends LogicService $this->incrChapterLikeCount($chapter); + $this->eventsManager->fire('Chapter:afterLike', $this, $chapter); + } else { $action = 'undo'; $this->decrChapterLikeCount($chapter); + + $this->eventsManager->fire('Chapter:afterUndoLike', $this, $chapter); } return [ diff --git a/app/Services/Logic/Course/CourseFavorite.php b/app/Services/Logic/Course/CourseFavorite.php index 493a7a5c..021233cf 100644 --- a/app/Services/Logic/Course/CourseFavorite.php +++ b/app/Services/Logic/Course/CourseFavorite.php @@ -57,12 +57,16 @@ class CourseFavorite extends LogicService $this->incrCourseFavoriteCount($course); $this->incrUserFavoriteCount($user); + $this->eventsManager->fire('Course:afterFavorite', $this, $course); + } else { $action = 'undo'; $this->decrCourseFavoriteCount($course); $this->decrUserFavoriteCount($user); + + $this->eventsManager->fire('Course:afterUndoFavorite', $this, $course); } return [ diff --git a/app/Services/Logic/Course/CourseInfo.php b/app/Services/Logic/Course/CourseInfo.php index 45245f27..518755fd 100644 --- a/app/Services/Logic/Course/CourseInfo.php +++ b/app/Services/Logic/Course/CourseInfo.php @@ -27,7 +27,11 @@ class CourseInfo extends LogicService $this->setCourseUser($course, $user); - return $this->handleCourse($course, $user); + $result = $this->handleCourse($course, $user); + + $this->eventsManager->fire('Course:afterView', $this, $course); + + return $result; } protected function handleCourse(CourseModel $course, UserModel $user)