diff --git a/app/Caches/IndexHotTeacherList.php b/app/Caches/IndexHotTeacherList.php deleted file mode 100644 index ce412a8f..00000000 --- a/app/Caches/IndexHotTeacherList.php +++ /dev/null @@ -1,30 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'hot_teacher_list'; - } - - public function getContent($id = null) - { - - } - - protected function handleContent($users) - { - - } - -} diff --git a/app/Http/Admin/Controllers/TestController.php b/app/Http/Admin/Controllers/TestController.php index 02990141..eceb1ca3 100644 --- a/app/Http/Admin/Controllers/TestController.php +++ b/app/Http/Admin/Controllers/TestController.php @@ -26,9 +26,21 @@ class TestController extends Controller { $storageService = new StorageService(); - $result = $storageService->uploadTestFile(); + $result = []; - if ($result) { + $result['hello'] = $storageService->uploadTestFile(); + + $avatarPath = public_path('static/admin/img/default_avatar.png'); + $avatarKey = '/img/avatar/default.png'; + + $result['avatar'] = $storageService->putFile($avatarKey, $avatarPath); + + $coverPath = public_path('static/admin/img/default_cover.png'); + $coverKey = '/img/cover/default.png'; + + $result['cover'] = $storageService->putFile($coverKey, $coverPath); + + if ($result['hello'] && $result['avatar'] && $result['cover']) { return $this->jsonSuccess(['msg' => '上传文件成功,请到控制台确认']); } else { return $this->jsonError(['msg' => '上传文件失败,请检查相关配置']); diff --git a/app/Library/Helper.php b/app/Library/Helper.php index 743871fd..779ef6da 100644 --- a/app/Library/Helper.php +++ b/app/Library/Helper.php @@ -172,9 +172,7 @@ function kg_ci_base_url() */ function kg_ci_img_url($path, $width = 0, $height = 0) { - if (empty($path)) { - return ''; - } + if (!$path) return ''; if (Text::startsWith($path, 'http')) { return $path; diff --git a/app/Models/Course.php b/app/Models/Course.php index 33413df1..e1499ff6 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -306,7 +306,7 @@ class Course extends Model $this->score = (float)$this->score; if (!Text::startsWith($this->cover, 'http')) { - $this->cover = kg_ci_img_url($this->cover); + $this->cover = kg_ci_cover_img_url($this->cover); } if (!empty($this->attrs)) { diff --git a/app/Models/Slide.php b/app/Models/Slide.php index 4f46fc20..9c52a0b7 100644 --- a/app/Models/Slide.php +++ b/app/Models/Slide.php @@ -130,7 +130,7 @@ class Slide extends Model public function afterFetch() { if (!Text::startsWith($this->cover, 'http')) { - $this->cover = kg_ci_img_url($this->cover); + $this->cover = kg_ci_cover_img_url($this->cover); } } diff --git a/app/Models/User.php b/app/Models/User.php index 1b83e22b..b12d9c9a 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -193,7 +193,7 @@ class User extends Model public function afterFetch() { if (!Text::startsWith($this->avatar, 'http')) { - $this->avatar = kg_ci_img_url($this->avatar); + $this->avatar = kg_ci_avatar_img_url($this->avatar); } } diff --git a/app/Providers/ProviderInterface.php b/app/Providers/ProviderInterface.php index d87b6eff..8baab3db 100644 --- a/app/Providers/ProviderInterface.php +++ b/app/Providers/ProviderInterface.php @@ -8,7 +8,7 @@ interface ProviderInterface extends InjectionAwareInterface { /** - * Register application service. + * RegisterByPhone application service. * * @return mixed */ diff --git a/app/Services/Frontend/Account/EmailUpdate.php b/app/Services/Frontend/Account/EmailUpdate.php index c856716f..5da85521 100644 --- a/app/Services/Frontend/Account/EmailUpdate.php +++ b/app/Services/Frontend/Account/EmailUpdate.php @@ -10,7 +10,7 @@ use App\Validators\Security as SecurityValidator; class EmailUpdate extends Service { - public function updateEmail() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Account/PasswordReset.php b/app/Services/Frontend/Account/PasswordReset.php index ffe5f835..32ed2278 100644 --- a/app/Services/Frontend/Account/PasswordReset.php +++ b/app/Services/Frontend/Account/PasswordReset.php @@ -9,7 +9,7 @@ use App\Validators\Security as SecurityValidator; class PasswordReset extends Service { - public function resetPassword() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Account/PasswordUpdate.php b/app/Services/Frontend/Account/PasswordUpdate.php index a1eae84b..b96e185f 100644 --- a/app/Services/Frontend/Account/PasswordUpdate.php +++ b/app/Services/Frontend/Account/PasswordUpdate.php @@ -9,7 +9,7 @@ use App\Validators\Account as AccountValidator; class PasswordUpdate extends Service { - public function updatePassword() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Account/PhoneUpdate.php b/app/Services/Frontend/Account/PhoneUpdate.php index c92d85f2..274a246f 100644 --- a/app/Services/Frontend/Account/PhoneUpdate.php +++ b/app/Services/Frontend/Account/PhoneUpdate.php @@ -10,7 +10,7 @@ use App\Validators\Security as SecurityValidator; class PhoneUpdate extends Service { - public function updatePhone() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Account/Register.php b/app/Services/Frontend/Account/RegisterByEmail.php similarity index 54% rename from app/Services/Frontend/Account/Register.php rename to app/Services/Frontend/Account/RegisterByEmail.php index 2aa95df8..1c3e3d9f 100644 --- a/app/Services/Frontend/Account/Register.php +++ b/app/Services/Frontend/Account/RegisterByEmail.php @@ -7,34 +7,10 @@ use App\Services\Frontend\Service; use App\Validators\Account as AccountValidator; use App\Validators\Security as SecurityValidator; -class Register extends Service +class RegisterByEmail extends Service { - public function registerByPhone() - { - $post = $this->request->getPost(); - - $securityValidator = new SecurityValidator(); - - $securityValidator->checkVerifyCode($post['phone'], $post['verify_code']); - - $accountValidator = new AccountValidator(); - - $data = []; - - $data['phone'] = $accountValidator->checkPhone($post['phone']); - $data['password'] = $accountValidator->checkPassword($post['password']); - - $accountValidator->checkIfPhoneTaken($post['phone']); - - $account = new AccountModel(); - - $account->create($data); - - return $account; - } - - public function registerByEmail() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Account/RegisterByPhone.php b/app/Services/Frontend/Account/RegisterByPhone.php new file mode 100644 index 00000000..4d5f3fc8 --- /dev/null +++ b/app/Services/Frontend/Account/RegisterByPhone.php @@ -0,0 +1,37 @@ +request->getPost(); + + $securityValidator = new SecurityValidator(); + + $securityValidator->checkVerifyCode($post['phone'], $post['verify_code']); + + $accountValidator = new AccountValidator(); + + $data = []; + + $data['phone'] = $accountValidator->checkPhone($post['phone']); + $data['password'] = $accountValidator->checkPassword($post['password']); + + $accountValidator->checkIfPhoneTaken($post['phone']); + + $account = new AccountModel(); + + $account->create($data); + + return $account; + } + +} diff --git a/app/Services/Frontend/Chapter/AgreeVote.php b/app/Services/Frontend/Chapter/AgreeVote.php new file mode 100644 index 00000000..68de2b3a --- /dev/null +++ b/app/Services/Frontend/Chapter/AgreeVote.php @@ -0,0 +1,73 @@ +checkChapter($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkChapterVoteLimit($user); + + $chapterVoteRepo = new ChapterVoteRepo(); + + $chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id); + + if (!$chapterVote) { + + $chapterVote = new ChapterVoteModel(); + + $chapterVote->chapter_id = $chapter->id; + $chapterVote->user_id = $user->id; + $chapterVote->type = ChapterVoteModel::TYPE_AGREE; + + $chapterVote->create(); + + $this->incrAgreeCount($chapter); + + } else { + + if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) { + + $chapterVote->type = ChapterVoteModel::TYPE_NONE; + + $this->decrAgreeCount($chapter); + + } elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) { + + $chapterVote->type = ChapterVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($chapter); + + $this->decrOpposeCount($chapter); + + } elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) { + + $chapterVote->type = ChapterVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($chapter); + } + + $chapterVote->update(); + } + + $this->incrUserDailyChapterVoteCount($user); + + return $chapter; + } + +} diff --git a/app/Services/Frontend/Chapter/ChapterInfo.php b/app/Services/Frontend/Chapter/ChapterInfo.php index af759546..513efee8 100644 --- a/app/Services/Frontend/Chapter/ChapterInfo.php +++ b/app/Services/Frontend/Chapter/ChapterInfo.php @@ -32,7 +32,7 @@ class ChapterInfo extends Service use CourseTrait, ChapterTrait; - public function getChapter($id) + public function handle($id) { $chapter = $this->checkChapter($id); diff --git a/app/Services/Frontend/Chapter/ChapterVote.php b/app/Services/Frontend/Chapter/ChapterVote.php deleted file mode 100644 index 374b06fd..00000000 --- a/app/Services/Frontend/Chapter/ChapterVote.php +++ /dev/null @@ -1,157 +0,0 @@ -checkChapter($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkChapterVoteLimit($user); - - $chapterVoteRepo = new ChapterVoteRepo(); - - $chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id); - - if (!$chapterVote) { - - $chapterVote = new ChapterVoteModel(); - - $chapterVote->chapter_id = $chapter->id; - $chapterVote->user_id = $user->id; - $chapterVote->type = ChapterVoteModel::TYPE_AGREE; - - $chapterVote->create(); - - $this->incrAgreeCount($chapter); - - } else { - - if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) { - - $chapterVote->type = ChapterVoteModel::TYPE_NONE; - - $this->decrAgreeCount($chapter); - - } elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) { - - $chapterVote->type = ChapterVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($chapter); - - $this->decrOpposeCount($chapter); - - } elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) { - - $chapterVote->type = ChapterVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($chapter); - } - - $chapterVote->update(); - } - - $this->incrUserDailyChapterVoteCount($user); - - return $chapter; - } - - public function oppose($id) - { - $chapter = $this->checkChapter($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkChapterVoteLimit($user); - - $chapterVoteRepo = new ChapterVoteRepo(); - - $chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id); - - if (!$chapterVote) { - - $chapterVote = new ChapterVoteModel(); - - $chapterVote->chapter_id = $chapter->id; - $chapterVote->user_id = $user->id; - $chapterVote->type = ChapterVoteModel::TYPE_OPPOSE; - - $chapterVote->create(); - - $this->incrOpposeCount($chapter); - - } else { - - if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) { - - $chapterVote->type = ChapterVoteModel::TYPE_OPPOSE; - - $this->decrAgreeCount($chapter); - - $this->incrOpposeCount($chapter); - - } elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) { - - $chapterVote->type = ChapterVoteModel::TYPE_NONE; - - $this->decrOpposeCount($chapter); - - } elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) { - - $chapterVote->type = ChapterVoteModel::TYPE_OPPOSE; - - $this->incrOpposeCount($chapter); - } - - $chapterVote->update(); - } - - $this->incrUserDailyChapterVoteCount($user); - - return $chapter; - } - - protected function incrAgreeCount(ChapterModel $chapter) - { - $this->eventsManager->fire('chapterCounter:incrAgreeCount', $this, $chapter); - } - - protected function decrAgreeCount(ChapterModel $chapter) - { - $this->eventsManager->fire('chapterCounter:decrAgreeCount', $this, $chapter); - } - - protected function incrOpposeCount(ChapterModel $chapter) - { - $this->eventsManager->fire('chapterCounter:incrOpposeCount', $this, $chapter); - } - - protected function decrOpposeCount(ChapterModel $chapter) - { - $this->eventsManager->fire('chapterCounter:decrOpposeCount', $this, $chapter); - } - - protected function incrUserDailyChapterVoteCount(UserModel $user) - { - $this->eventsManager->fire('userDailyCounter:incrChapterVoteCount', $this, $user); - } - -} diff --git a/app/Services/Frontend/Chapter/CommentList.php b/app/Services/Frontend/Chapter/CommentList.php index e33f82c1..8676642d 100644 --- a/app/Services/Frontend/Chapter/CommentList.php +++ b/app/Services/Frontend/Chapter/CommentList.php @@ -27,7 +27,7 @@ class CommentList extends Service use ChapterTrait; - public function getComments($chapterId) + public function handle($chapterId) { $this->chapter = $this->checkChapter($chapterId); diff --git a/app/Services/Frontend/Chapter/OpposeVote.php b/app/Services/Frontend/Chapter/OpposeVote.php new file mode 100644 index 00000000..ac1d91bc --- /dev/null +++ b/app/Services/Frontend/Chapter/OpposeVote.php @@ -0,0 +1,73 @@ +checkChapter($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkChapterVoteLimit($user); + + $chapterVoteRepo = new ChapterVoteRepo(); + + $chapterVote = $chapterVoteRepo->findChapterVote($chapter->id, $user->id); + + if (!$chapterVote) { + + $chapterVote = new ChapterVoteModel(); + + $chapterVote->chapter_id = $chapter->id; + $chapterVote->user_id = $user->id; + $chapterVote->type = ChapterVoteModel::TYPE_OPPOSE; + + $chapterVote->create(); + + $this->incrOpposeCount($chapter); + + } else { + + if ($chapterVote->type == ChapterVoteModel::TYPE_AGREE) { + + $chapterVote->type = ChapterVoteModel::TYPE_OPPOSE; + + $this->decrAgreeCount($chapter); + + $this->incrOpposeCount($chapter); + + } elseif ($chapterVote->type == ChapterVoteModel::TYPE_OPPOSE) { + + $chapterVote->type = ChapterVoteModel::TYPE_NONE; + + $this->decrOpposeCount($chapter); + + } elseif ($chapterVote->type == ChapterVoteModel::TYPE_NONE) { + + $chapterVote->type = ChapterVoteModel::TYPE_OPPOSE; + + $this->incrOpposeCount($chapter); + } + + $chapterVote->update(); + } + + $this->incrUserDailyChapterVoteCount($user); + + return $chapter; + } + +} diff --git a/app/Services/Frontend/Chapter/VoteTrait.php b/app/Services/Frontend/Chapter/VoteTrait.php new file mode 100644 index 00000000..bf695512 --- /dev/null +++ b/app/Services/Frontend/Chapter/VoteTrait.php @@ -0,0 +1,36 @@ +getEventsManager->fire('chapterCounter:incrAgreeCount', $this, $chapter); + } + + protected function decrAgreeCount(ChapterModel $chapter) + { + $this->getEventsManager->fire('chapterCounter:decrAgreeCount', $this, $chapter); + } + + protected function incrOpposeCount(ChapterModel $chapter) + { + $this->getEventsManager->fire('chapterCounter:incrOpposeCount', $this, $chapter); + } + + protected function decrOpposeCount(ChapterModel $chapter) + { + $this->getEventsManager->fire('chapterCounter:decrOpposeCount', $this, $chapter); + } + + protected function incrUserDailyChapterVoteCount(UserModel $user) + { + $this->getEventsManager->fire('userDailyCounter:incrChapterVoteCount', $this, $user); + } + +} \ No newline at end of file diff --git a/app/Services/Frontend/Comment/AgreeVote.php b/app/Services/Frontend/Comment/AgreeVote.php new file mode 100644 index 00000000..ea3fa5d2 --- /dev/null +++ b/app/Services/Frontend/Comment/AgreeVote.php @@ -0,0 +1,73 @@ +checkComment($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkCommentVoteLimit($user); + + $commentVoteRepo = new CommentVoteRepo(); + + $commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id); + + if (!$commentVote) { + + $commentVote = new CommentVoteModel(); + + $commentVote->comment_id = $comment->id; + $commentVote->user_id = $user->id; + $commentVote->type = CommentVoteModel::TYPE_AGREE; + + $commentVote->create(); + + $this->incrAgreeCount($comment); + + } else { + + if ($commentVote->type == CommentVoteModel::TYPE_AGREE) { + + $commentVote->type = CommentVoteModel::TYPE_NONE; + + $this->decrAgreeCount($comment); + + } elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) { + + $commentVote->type = CommentVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($comment); + + $this->decrOpposeCount($comment); + + } elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) { + + $commentVote->type = CommentVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($comment); + } + + $commentVote->update(); + } + + $this->incrUserDailyCommentVoteCount($user); + + return $comment; + } + +} diff --git a/app/Services/Frontend/Comment/CommentCreate.php b/app/Services/Frontend/Comment/CommentCreate.php index 7e7e0202..8838a340 100644 --- a/app/Services/Frontend/Comment/CommentCreate.php +++ b/app/Services/Frontend/Comment/CommentCreate.php @@ -17,7 +17,7 @@ class CommentCreate extends Service use ChapterTrait, CourseTrait; - public function createComment() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Comment/CommentDelete.php b/app/Services/Frontend/Comment/CommentDelete.php index 4f8d9ac2..9dd3250c 100644 --- a/app/Services/Frontend/Comment/CommentDelete.php +++ b/app/Services/Frontend/Comment/CommentDelete.php @@ -15,7 +15,7 @@ class CommentDelete extends Service use CommentTrait, ChapterTrait, CourseTrait; - public function deleteComment($id) + public function handle($id) { $comment = $this->checkComment($id); diff --git a/app/Services/Frontend/Comment/CommentVote.php b/app/Services/Frontend/Comment/CommentVote.php deleted file mode 100644 index 4e56ed52..00000000 --- a/app/Services/Frontend/Comment/CommentVote.php +++ /dev/null @@ -1,157 +0,0 @@ -checkComment($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkCommentVoteLimit($user); - - $commentVoteRepo = new CommentVoteRepo(); - - $commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id); - - if (!$commentVote) { - - $commentVote = new CommentVoteModel(); - - $commentVote->comment_id = $comment->id; - $commentVote->user_id = $user->id; - $commentVote->type = CommentVoteModel::TYPE_AGREE; - - $commentVote->create(); - - $this->incrAgreeCount($comment); - - } else { - - if ($commentVote->type == CommentVoteModel::TYPE_AGREE) { - - $commentVote->type = CommentVoteModel::TYPE_NONE; - - $this->decrAgreeCount($comment); - - } elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) { - - $commentVote->type = CommentVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($comment); - - $this->decrOpposeCount($comment); - - } elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) { - - $commentVote->type = CommentVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($comment); - } - - $commentVote->update(); - } - - $this->incrUserDailyCommentVoteCount($user); - - return $comment; - } - - public function oppose($id) - { - $comment = $this->checkComment($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkCommentVoteLimit($user); - - $commentVoteRepo = new CommentVoteRepo(); - - $commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id); - - if (!$commentVote) { - - $commentVote = new CommentVoteModel(); - - $commentVote->comment_id = $comment->id; - $commentVote->user_id = $user->id; - $commentVote->type = CommentVoteModel::TYPE_OPPOSE; - - $commentVote->create(); - - $this->incrOpposeCount($comment); - - } else { - - if ($commentVote->type == CommentVoteModel::TYPE_AGREE) { - - $commentVote->type = CommentVoteModel::TYPE_OPPOSE; - - $this->decrAgreeCount($comment); - - $this->incrOpposeCount($comment); - - } elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) { - - $commentVote->type = CommentVoteModel::TYPE_NONE; - - $this->decrOpposeCount($comment); - - } elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) { - - $commentVote->type = CommentVoteModel::TYPE_OPPOSE; - - $this->incrOpposeCount($comment); - } - - $commentVote->update(); - } - - $this->incrUserDailyCommentVoteCount($user); - - return $comment; - } - - protected function incrAgreeCount(CommentModel $comment) - { - $this->eventsManager->fire('commentCounter:incrAgreeCount', $this, $comment); - } - - protected function decrAgreeCount(CommentModel $comment) - { - $this->eventsManager->fire('commentCounter:decrAgreeCount', $this, $comment); - } - - protected function incrOpposeCount(CommentModel $comment) - { - $this->eventsManager->fire('commentCounter:incrOpposeCount', $this, $comment); - } - - protected function decrOpposeCount(CommentModel $comment) - { - $this->eventsManager->fire('commentCounter:decrOpposeCount', $this, $comment); - } - - protected function incrUserDailyCommentVoteCount(UserModel $user) - { - $this->eventsManager->fire('userDailyCounter:incrCommentVoteCount', $this, $user); - } - -} diff --git a/app/Services/Frontend/Comment/OpposeVote.php b/app/Services/Frontend/Comment/OpposeVote.php new file mode 100644 index 00000000..87914693 --- /dev/null +++ b/app/Services/Frontend/Comment/OpposeVote.php @@ -0,0 +1,73 @@ +checkComment($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkCommentVoteLimit($user); + + $commentVoteRepo = new CommentVoteRepo(); + + $commentVote = $commentVoteRepo->findCommentVote($comment->id, $user->id); + + if (!$commentVote) { + + $commentVote = new CommentVoteModel(); + + $commentVote->comment_id = $comment->id; + $commentVote->user_id = $user->id; + $commentVote->type = CommentVoteModel::TYPE_OPPOSE; + + $commentVote->create(); + + $this->incrOpposeCount($comment); + + } else { + + if ($commentVote->type == CommentVoteModel::TYPE_AGREE) { + + $commentVote->type = CommentVoteModel::TYPE_OPPOSE; + + $this->decrAgreeCount($comment); + + $this->incrOpposeCount($comment); + + } elseif ($commentVote->type == CommentVoteModel::TYPE_OPPOSE) { + + $commentVote->type = CommentVoteModel::TYPE_NONE; + + $this->decrOpposeCount($comment); + + } elseif ($commentVote->type == CommentVoteModel::TYPE_NONE) { + + $commentVote->type = CommentVoteModel::TYPE_OPPOSE; + + $this->incrOpposeCount($comment); + } + + $commentVote->update(); + } + + $this->incrUserDailyCommentVoteCount($user); + + return $comment; + } + +} diff --git a/app/Services/Frontend/Comment/VoteTrait.php b/app/Services/Frontend/Comment/VoteTrait.php new file mode 100644 index 00000000..7e17ea67 --- /dev/null +++ b/app/Services/Frontend/Comment/VoteTrait.php @@ -0,0 +1,36 @@ +getEventsManager->fire('commentCounter:incrAgreeCount', $this, $comment); + } + + protected function decrAgreeCount(CommentModel $comment) + { + $this->getEventsManager->fire('commentCounter:decrAgreeCount', $this, $comment); + } + + protected function incrOpposeCount(CommentModel $comment) + { + $this->getEventsManager->fire('commentCounter:incrOpposeCount', $this, $comment); + } + + protected function decrOpposeCount(CommentModel $comment) + { + $this->getEventsManager->fire('commentCounter:decrOpposeCount', $this, $comment); + } + + protected function incrUserDailyCommentVoteCount(UserModel $user) + { + $this->getEventsManager->fire('userDailyCounter:incrCommentVoteCount', $this, $user); + } + +} diff --git a/app/Services/Frontend/Consult/AgreeVote.php b/app/Services/Frontend/Consult/AgreeVote.php new file mode 100644 index 00000000..050dca52 --- /dev/null +++ b/app/Services/Frontend/Consult/AgreeVote.php @@ -0,0 +1,73 @@ +checkConsult($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkConsultVoteLimit($user); + + $consultVoteRepo = new ConsultVoteRepo(); + + $consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id); + + if (!$consultVote) { + + $consultVote = new ConsultVoteModel(); + + $consultVote->consult_id = $consult->id; + $consultVote->user_id = $user->id; + $consultVote->type = ConsultVoteModel::TYPE_AGREE; + + $consultVote->create(); + + $this->incrAgreeCount($consult); + + } else { + + if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) { + + $consultVote->type = ConsultVoteModel::TYPE_NONE; + + $this->decrAgreeCount($consult); + + } elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) { + + $consultVote->type = ConsultVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($consult); + + $this->decrOpposeCount($consult); + + } elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) { + + $consultVote->type = ConsultVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($consult); + } + + $consultVote->update(); + } + + $this->incrUserDailyConsultVoteCount($user); + + return $consult; + } + +} diff --git a/app/Services/Frontend/Consult/ConsultCreate.php b/app/Services/Frontend/Consult/ConsultCreate.php index 75323b6f..8de800ca 100644 --- a/app/Services/Frontend/Consult/ConsultCreate.php +++ b/app/Services/Frontend/Consult/ConsultCreate.php @@ -15,7 +15,7 @@ class ConsultCreate extends Service use CourseTrait; - public function createConsult() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Consult/ConsultVote.php b/app/Services/Frontend/Consult/ConsultVote.php deleted file mode 100644 index ddb41f21..00000000 --- a/app/Services/Frontend/Consult/ConsultVote.php +++ /dev/null @@ -1,157 +0,0 @@ -checkConsult($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkConsultVoteLimit($user); - - $consultVoteRepo = new ConsultVoteRepo(); - - $consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id); - - if (!$consultVote) { - - $consultVote = new ConsultVoteModel(); - - $consultVote->consult_id = $consult->id; - $consultVote->user_id = $user->id; - $consultVote->type = ConsultVoteModel::TYPE_AGREE; - - $consultVote->create(); - - $this->incrAgreeCount($consult); - - } else { - - if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) { - - $consultVote->type = ConsultVoteModel::TYPE_NONE; - - $this->decrAgreeCount($consult); - - } elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) { - - $consultVote->type = ConsultVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($consult); - - $this->decrOpposeCount($consult); - - } elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) { - - $consultVote->type = ConsultVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($consult); - } - - $consultVote->update(); - } - - $this->incrUserDailyConsultVoteCount($user); - - return $consult; - } - - public function oppose($id) - { - $consult = $this->checkConsult($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkConsultVoteLimit($user); - - $consultVoteRepo = new ConsultVoteRepo(); - - $consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id); - - if (!$consultVote) { - - $consultVote = new ConsultVoteModel(); - - $consultVote->consult_id = $consult->id; - $consultVote->user_id = $user->id; - $consultVote->type = ConsultVoteModel::TYPE_OPPOSE; - - $consultVote->create(); - - $this->incrOpposeCount($consult); - - } else { - - if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) { - - $consultVote->type = ConsultVoteModel::TYPE_OPPOSE; - - $this->decrAgreeCount($consult); - - $this->incrOpposeCount($consult); - - } elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) { - - $consultVote->type = ConsultVoteModel::TYPE_NONE; - - $this->decrOpposeCount($consult); - - } elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) { - - $consultVote->type = ConsultVoteModel::TYPE_OPPOSE; - - $this->incrOpposeCount($consult); - } - - $consultVote->update(); - } - - $this->incrUserDailyConsultVoteCount($user); - - return $consult; - } - - protected function incrAgreeCount(ConsultModel $consult) - { - $this->eventsManager->fire('consultCounter:incrAgreeCount', $this, $consult); - } - - protected function decrAgreeCount(ConsultModel $consult) - { - $this->eventsManager->fire('consultCounter:decrAgreeCount', $this, $consult); - } - - protected function incrOpposeCount(ConsultModel $consult) - { - $this->eventsManager->fire('consultCounter:incrOpposeCount', $this, $consult); - } - - protected function decrOpposeCount(ConsultModel $consult) - { - $this->eventsManager->fire('consultCounter:decrOpposeCount', $this, $consult); - } - - protected function incrUserDailyConsultVoteCount(UserModel $user) - { - $this->eventsManager->fire('userDailyCounter:incrConsultVoteCount', $this, $user); - } - -} diff --git a/app/Services/Frontend/Consult/OpposeVote.php b/app/Services/Frontend/Consult/OpposeVote.php new file mode 100644 index 00000000..bec67c03 --- /dev/null +++ b/app/Services/Frontend/Consult/OpposeVote.php @@ -0,0 +1,73 @@ +checkConsult($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkConsultVoteLimit($user); + + $consultVoteRepo = new ConsultVoteRepo(); + + $consultVote = $consultVoteRepo->findConsultVote($consult->id, $user->id); + + if (!$consultVote) { + + $consultVote = new ConsultVoteModel(); + + $consultVote->consult_id = $consult->id; + $consultVote->user_id = $user->id; + $consultVote->type = ConsultVoteModel::TYPE_OPPOSE; + + $consultVote->create(); + + $this->incrOpposeCount($consult); + + } else { + + if ($consultVote->type == ConsultVoteModel::TYPE_AGREE) { + + $consultVote->type = ConsultVoteModel::TYPE_OPPOSE; + + $this->decrAgreeCount($consult); + + $this->incrOpposeCount($consult); + + } elseif ($consultVote->type == ConsultVoteModel::TYPE_OPPOSE) { + + $consultVote->type = ConsultVoteModel::TYPE_NONE; + + $this->decrOpposeCount($consult); + + } elseif ($consultVote->type == ConsultVoteModel::TYPE_NONE) { + + $consultVote->type = ConsultVoteModel::TYPE_OPPOSE; + + $this->incrOpposeCount($consult); + } + + $consultVote->update(); + } + + $this->incrUserDailyConsultVoteCount($user); + + return $consult; + } + +} diff --git a/app/Services/Frontend/Consult/VoteTrait.php b/app/Services/Frontend/Consult/VoteTrait.php new file mode 100644 index 00000000..0873776b --- /dev/null +++ b/app/Services/Frontend/Consult/VoteTrait.php @@ -0,0 +1,36 @@ +getEventsManager->fire('consultCounter:incrAgreeCount', $this, $consult); + } + + protected function decrAgreeCount(ConsultModel $consult) + { + $this->getEventsManager->fire('consultCounter:decrAgreeCount', $this, $consult); + } + + protected function incrOpposeCount(ConsultModel $consult) + { + $this->getEventsManager->fire('consultCounter:incrOpposeCount', $this, $consult); + } + + protected function decrOpposeCount(ConsultModel $consult) + { + $this->getEventsManager->fire('consultCounter:decrOpposeCount', $this, $consult); + } + + protected function incrUserDailyConsultVoteCount(UserModel $user) + { + $this->getEventsManager->fire('userDailyCounter:incrConsultVoteCount', $this, $user); + } + +} diff --git a/app/Services/Frontend/Course/ConsultList.php b/app/Services/Frontend/Course/ConsultList.php index 0e900899..618dd12a 100644 --- a/app/Services/Frontend/Course/ConsultList.php +++ b/app/Services/Frontend/Course/ConsultList.php @@ -28,7 +28,7 @@ class ConsultList extends Service use CourseTrait; - public function getConsults($courseId) + public function handle($courseId) { $this->course = $this->checkCourse($courseId); diff --git a/app/Services/Frontend/Course/CourseFavorite.php b/app/Services/Frontend/Course/CourseFavorite.php index 9d1282f9..38080552 100644 --- a/app/Services/Frontend/Course/CourseFavorite.php +++ b/app/Services/Frontend/Course/CourseFavorite.php @@ -15,7 +15,7 @@ class CourseFavorite extends Service use CourseTrait; - public function saveFavorite($id) + public function handle($id) { $course = $this->checkCourse($id); diff --git a/app/Services/Frontend/Course/CourseInfo.php b/app/Services/Frontend/Course/CourseInfo.php index 089c6bbf..46b0a776 100644 --- a/app/Services/Frontend/Course/CourseInfo.php +++ b/app/Services/Frontend/Course/CourseInfo.php @@ -17,7 +17,7 @@ class CourseInfo extends Service use CourseTrait; - public function getCourse($id) + public function handle($id) { $course = $this->checkCourseCache($id); diff --git a/app/Services/Frontend/Course/CourseList.php b/app/Services/Frontend/Course/CourseList.php index 11759fa0..54ff96a0 100644 --- a/app/Services/Frontend/Course/CourseList.php +++ b/app/Services/Frontend/Course/CourseList.php @@ -10,7 +10,7 @@ use App\Services\Frontend\Service; class CourseList extends Service { - public function getCourses() + public function handle() { $pagerQuery = new PagerQuery(); diff --git a/app/Services/Frontend/Course/CourseRelated.php b/app/Services/Frontend/Course/CourseRelated.php index a9e87a56..de60931d 100644 --- a/app/Services/Frontend/Course/CourseRelated.php +++ b/app/Services/Frontend/Course/CourseRelated.php @@ -11,7 +11,7 @@ class CourseRelated extends Service use CourseTrait; - public function getRelated($id) + public function handle($id) { $course = $this->checkCourse($id); diff --git a/app/Services/Frontend/Course/PackageList.php b/app/Services/Frontend/Course/PackageList.php index 98497772..327a905d 100644 --- a/app/Services/Frontend/Course/PackageList.php +++ b/app/Services/Frontend/Course/PackageList.php @@ -6,25 +6,21 @@ use App\Caches\CoursePackageList as CoursePackageListCache; use App\Caches\PackageCourseList as PackageCourseListCache; use App\Services\Frontend\CourseTrait; use App\Services\Frontend\Service; -use Yansongda\Supports\Collection; class PackageList extends Service { use CourseTrait; - public function getPackages($id) + public function handle($id) { $course = $this->checkCourseCache($id); $cache = new CoursePackageListCache(); - /** - * @var Collection $packages - */ $packages = $cache->get($course->id); - if ($packages->count() == 0) { + if (!$packages) { return []; } @@ -34,12 +30,9 @@ class PackageList extends Service foreach ($packages->toArray() as $package) { - /** - * @var Collection $courses - */ $courses = $cache->get($package['id']); - $package['courses'] = $courses->count() > 0 ? $courses->toArray() : []; + $package['courses'] = $courses ?: []; $result[] = $package; } diff --git a/app/Services/Frontend/Course/ReviewList.php b/app/Services/Frontend/Course/ReviewList.php index 4ae0171f..69f913a3 100644 --- a/app/Services/Frontend/Course/ReviewList.php +++ b/app/Services/Frontend/Course/ReviewList.php @@ -27,7 +27,7 @@ class ReviewList extends Service use CourseTrait; - public function getReviews($id) + public function handle($id) { $this->course = $this->checkCourse($id); diff --git a/app/Services/Frontend/Package/CourseList.php b/app/Services/Frontend/Package/CourseList.php index 3ff43f13..630e1290 100644 --- a/app/Services/Frontend/Package/CourseList.php +++ b/app/Services/Frontend/Package/CourseList.php @@ -9,4 +9,10 @@ class CourseList extends Service { use PackageTrait; + + public function handle() + { + + } + } diff --git a/app/Services/Frontend/Package/PackageInfo.php b/app/Services/Frontend/Package/PackageInfo.php index 09720e77..68a28cec 100644 --- a/app/Services/Frontend/Package/PackageInfo.php +++ b/app/Services/Frontend/Package/PackageInfo.php @@ -11,7 +11,7 @@ class PackageInfo extends Service use PackageTrait; - public function getPackage($id) + public function handle($id) { $package = $this->checkPackageCache($id); diff --git a/app/Services/Frontend/Review/AgreeVote.php b/app/Services/Frontend/Review/AgreeVote.php new file mode 100644 index 00000000..603eb15d --- /dev/null +++ b/app/Services/Frontend/Review/AgreeVote.php @@ -0,0 +1,73 @@ +checkReview($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkReviewVoteLimit($user); + + $reviewVoteRepo = new ReviewVoteRepo(); + + $reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id); + + if (!$reviewVote) { + + $reviewVote = new ReviewVoteModel(); + + $reviewVote->review_id = $review->id; + $reviewVote->user_id = $user->id; + $reviewVote->type = ReviewVoteModel::TYPE_AGREE; + + $reviewVote->create(); + + $this->incrAgreeCount($review); + + } else { + + if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) { + + $reviewVote->type = ReviewVoteModel::TYPE_NONE; + + $this->decrAgreeCount($review); + + } elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) { + + $reviewVote->type = ReviewVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($review); + + $this->decrOpposeCount($review); + + } elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) { + + $reviewVote->type = ReviewVoteModel::TYPE_AGREE; + + $this->incrAgreeCount($review); + } + + $reviewVote->update(); + } + + $this->incrUserDailyReviewVoteCount($user); + + return $review; + } + +} diff --git a/app/Services/Frontend/Review/OpposeVote.php b/app/Services/Frontend/Review/OpposeVote.php new file mode 100644 index 00000000..be8d129e --- /dev/null +++ b/app/Services/Frontend/Review/OpposeVote.php @@ -0,0 +1,73 @@ +checkReview($id); + + $user = $this->getLoginUser(); + + $validator = new UserDailyLimitValidator(); + + $validator->checkReviewVoteLimit($user); + + $reviewVoteRepo = new ReviewVoteRepo(); + + $reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id); + + if (!$reviewVote) { + + $reviewVote = new ReviewVoteModel(); + + $reviewVote->review_id = $review->id; + $reviewVote->user_id = $user->id; + $reviewVote->type = ReviewVoteModel::TYPE_OPPOSE; + + $reviewVote->create(); + + $this->incrOpposeCount($review); + + } else { + + if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) { + + $reviewVote->type = ReviewVoteModel::TYPE_OPPOSE; + + $this->decrAgreeCount($review); + + $this->incrOpposeCount($review); + + } elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) { + + $reviewVote->type = ReviewVoteModel::TYPE_NONE; + + $this->decrOpposeCount($review); + + } elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) { + + $reviewVote->type = ReviewVoteModel::TYPE_OPPOSE; + + $this->incrOpposeCount($review); + } + + $reviewVote->update(); + } + + $this->incrUserDailyReviewVoteCount($user); + + return $review; + } + +} diff --git a/app/Services/Frontend/Review/ReviewCreate.php b/app/Services/Frontend/Review/ReviewCreate.php index 81902321..2a3b12a6 100644 --- a/app/Services/Frontend/Review/ReviewCreate.php +++ b/app/Services/Frontend/Review/ReviewCreate.php @@ -15,7 +15,7 @@ class ReviewCreate extends Service use CourseTrait; - public function createReview() + public function handle() { $post = $this->request->getPost(); diff --git a/app/Services/Frontend/Review/ReviewVote.php b/app/Services/Frontend/Review/ReviewVote.php deleted file mode 100644 index 61c21f9f..00000000 --- a/app/Services/Frontend/Review/ReviewVote.php +++ /dev/null @@ -1,157 +0,0 @@ -checkReview($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkReviewVoteLimit($user); - - $reviewVoteRepo = new ReviewVoteRepo(); - - $reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id); - - if (!$reviewVote) { - - $reviewVote = new ReviewVoteModel(); - - $reviewVote->review_id = $review->id; - $reviewVote->user_id = $user->id; - $reviewVote->type = ReviewVoteModel::TYPE_AGREE; - - $reviewVote->create(); - - $this->incrAgreeCount($review); - - } else { - - if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) { - - $reviewVote->type = ReviewVoteModel::TYPE_NONE; - - $this->decrAgreeCount($review); - - } elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) { - - $reviewVote->type = ReviewVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($review); - - $this->decrOpposeCount($review); - - } elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) { - - $reviewVote->type = ReviewVoteModel::TYPE_AGREE; - - $this->incrAgreeCount($review); - } - - $reviewVote->update(); - } - - $this->incrUserDailyReviewVoteCount($user); - - return $review; - } - - public function oppose($id) - { - $review = $this->checkReview($id); - - $user = $this->getLoginUser(); - - $validator = new UserDailyLimitValidator(); - - $validator->checkReviewVoteLimit($user); - - $reviewVoteRepo = new ReviewVoteRepo(); - - $reviewVote = $reviewVoteRepo->findReviewVote($review->id, $user->id); - - if (!$reviewVote) { - - $reviewVote = new ReviewVoteModel(); - - $reviewVote->review_id = $review->id; - $reviewVote->user_id = $user->id; - $reviewVote->type = ReviewVoteModel::TYPE_OPPOSE; - - $reviewVote->create(); - - $this->incrOpposeCount($review); - - } else { - - if ($reviewVote->type == ReviewVoteModel::TYPE_AGREE) { - - $reviewVote->type = ReviewVoteModel::TYPE_OPPOSE; - - $this->decrAgreeCount($review); - - $this->incrOpposeCount($review); - - } elseif ($reviewVote->type == ReviewVoteModel::TYPE_OPPOSE) { - - $reviewVote->type = ReviewVoteModel::TYPE_NONE; - - $this->decrOpposeCount($review); - - } elseif ($reviewVote->type == ReviewVoteModel::TYPE_NONE) { - - $reviewVote->type = ReviewVoteModel::TYPE_OPPOSE; - - $this->incrOpposeCount($review); - } - - $reviewVote->update(); - } - - $this->incrUserDailyReviewVoteCount($user); - - return $review; - } - - protected function incrAgreeCount(ReviewModel $review) - { - $this->eventsManager->fire('reviewCounter:incrAgreeCount', $this, $review); - } - - protected function decrAgreeCount(ReviewModel $review) - { - $this->eventsManager->fire('reviewCounter:decrAgreeCount', $this, $review); - } - - protected function incrOpposeCount(ReviewModel $review) - { - $this->eventsManager->fire('reviewCounter:incrOpposeCount', $this, $review); - } - - protected function decrOpposeCount(ReviewModel $review) - { - $this->eventsManager->fire('reviewCounter:decrOpposeCount', $this, $review); - } - - protected function incrUserDailyReviewVoteCount(UserModel $user) - { - $this->eventsManager->fire('userDailyCounter:incrReviewVoteCount', $this, $user); - } - -} diff --git a/app/Services/Frontend/Review/VoteTrait.php b/app/Services/Frontend/Review/VoteTrait.php new file mode 100644 index 00000000..2e1747c1 --- /dev/null +++ b/app/Services/Frontend/Review/VoteTrait.php @@ -0,0 +1,36 @@ +getEventsManager->fire('reviewCounter:incrAgreeCount', $this, $review); + } + + protected function decrAgreeCount(ReviewModel $review) + { + $this->getEventsManager->fire('reviewCounter:decrAgreeCount', $this, $review); + } + + protected function incrOpposeCount(ReviewModel $review) + { + $this->getEventsManager->fire('reviewCounter:incrOpposeCount', $this, $review); + } + + protected function decrOpposeCount(ReviewModel $review) + { + $this->getEventsManager->fire('reviewCounter:decrOpposeCount', $this, $review); + } + + protected function incrUserDailyReviewVoteCount(UserModel $user) + { + $this->getEventsManager->fire('userDailyCounter:incrReviewVoteCount', $this, $user); + } + +} diff --git a/app/Services/Frontend/Topic/CourseList.php b/app/Services/Frontend/Topic/CourseList.php index a9a28742..7f6a7c0e 100644 --- a/app/Services/Frontend/Topic/CourseList.php +++ b/app/Services/Frontend/Topic/CourseList.php @@ -11,7 +11,7 @@ class CourseList extends Service use TopicTrait; - public function getCourses($id) + public function handle($id) { $topic = $this->checkTopicCache($id); diff --git a/app/Services/Frontend/Topic/TopicInfo.php b/app/Services/Frontend/Topic/TopicInfo.php index a18f728f..a2a6dd5a 100644 --- a/app/Services/Frontend/Topic/TopicInfo.php +++ b/app/Services/Frontend/Topic/TopicInfo.php @@ -11,7 +11,7 @@ class TopicInfo extends Service use TopicTrait; - public function getTopic($id) + public function handle($id) { $topic = $this->checkTopicCache($id); diff --git a/app/Services/Frontend/User/CourseList.php b/app/Services/Frontend/User/CourseList.php index 1db6f957..b5207cbb 100644 --- a/app/Services/Frontend/User/CourseList.php +++ b/app/Services/Frontend/User/CourseList.php @@ -14,7 +14,7 @@ class CourseList extends Service use UserTrait; - public function getCourses($id) + public function handle($id) { $user = $this->checkUser($id); diff --git a/app/Services/Frontend/User/UserInfo.php b/app/Services/Frontend/User/UserInfo.php index ef900ed0..7d2eff76 100644 --- a/app/Services/Frontend/User/UserInfo.php +++ b/app/Services/Frontend/User/UserInfo.php @@ -11,7 +11,7 @@ class UserInfo extends Service use UserTrait; - public function getUser($id) + public function handle($id) { $user = $this->checkUser($id); diff --git a/app/Services/Storage.php b/app/Services/Storage.php index 5e0bd82a..963a1fda 100644 --- a/app/Services/Storage.php +++ b/app/Services/Storage.php @@ -179,46 +179,12 @@ class Storage extends Service } /** - * 上传对象 + * 删除文件 * * @param string $key - * @param resource|string $body - * @return bool + * @return string|bool */ - public function putObject($key, $body) - { - $bucket = $this->settings['bucket_name']; - - try { - - $response = $this->client->putObject([ - 'Bucket' => $bucket, - 'Key' => $key, - 'Body' => $body, - ]); - - $result = $response['Location'] ? $key : false; - - } catch (\Exception $e) { - - $this->logger->error('Put Object Exception ' . kg_json_encode([ - 'code' => $e->getCode(), - 'message' => $e->getMessage(), - ])); - - $result = false; - } - - return $result; - } - - /** - * 删除对象 - * - * @param string $key - * @return bool - */ - public function deleteObject($key) + public function deleteFile($key) { $bucket = $this->settings['bucket_name'];