From d94001a4a412cd89806505a9f7297f18262b53c7 Mon Sep 17 00:00:00 2001 From: koogua Date: Wed, 6 Oct 2021 17:01:49 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BC=91=EF=BC=8E=E5=8E=BB=E9=99=A4=E6=A8=A1?= =?UTF-8?q?=E5=9E=8B=E4=B8=AD=E5=88=A0=E9=99=A4=E5=85=B3=E8=81=94=E5=8F=91?= =?UTF-8?q?=E5=B8=83=E6=93=8D=E4=BD=9C=20=EF=BC=92=EF=BC=8E=E6=95=B4?= =?UTF-8?q?=E7=90=86=E6=9F=A5=E8=AF=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Builders/AnswerList.php | 2 +- app/Builders/ArticleList.php | 2 +- app/Builders/CategoryTreeList.php | 2 + app/Builders/CommentList.php | 2 +- app/Builders/ConsultList.php | 2 +- app/Builders/CourseList.php | 2 +- app/Builders/DanmuList.php | 2 +- app/Builders/ImMessageList.php | 2 +- app/Builders/LiveList.php | 2 +- app/Builders/NavTreeList.php | 5 +- app/Builders/NotificationList.php | 2 +- app/Builders/OrderList.php | 2 +- app/Builders/QuestionFavoriteList.php | 2 +- app/Builders/QuestionList.php | 2 +- app/Builders/RefundList.php | 5 +- app/Builders/ReportList.php | 2 +- app/Builders/ReviewList.php | 2 +- app/Builders/TradeList.php | 5 +- app/Caches/CategoryList.php | 1 + app/Caches/CourseRecommendedList.php | 4 +- app/Caches/CourseTeacherList.php | 1 + app/Caches/HelpList.php | 5 +- app/Caches/HotQuestionList.php | 3 +- app/Caches/ImActiveGroupList.php | 2 + app/Caches/ImNewGroupList.php | 1 + app/Caches/IndexArticleList.php | 5 +- app/Caches/IndexFeaturedCourseList.php | 7 +- app/Caches/IndexFreeCourseList.php | 7 +- app/Caches/IndexLiveList.php | 2 + app/Caches/IndexNewCourseList.php | 5 +- app/Caches/IndexQuestionList.php | 5 +- app/Caches/IndexSimpleFeaturedCourseList.php | 5 +- app/Caches/IndexSimpleFreeCourseList.php | 5 +- app/Caches/IndexSimpleNewCourseList.php | 1 + app/Caches/IndexSimpleVipCourseList.php | 5 +- app/Caches/IndexSlideList.php | 1 + app/Caches/IndexTeacherList.php | 1 + app/Caches/IndexVipCourseList.php | 7 +- app/Caches/PointHotGiftList.php | 1 + app/Caches/TaggedArticleList.php | 1 + app/Caches/TaggedQuestionList.php | 1 + app/Console/Tasks/ArticleIndexTask.php | 1 + app/Console/Tasks/CourseIndexTask.php | 1 + app/Console/Tasks/GroupIndexTask.php | 1 + app/Console/Tasks/QuestionIndexTask.php | 1 + app/Console/Tasks/UserIndexTask.php | 1 + app/Http/Api/Controllers/AnswerController.php | 12 +++ .../Api/Controllers/ArticleController.php | 17 ++++ .../Api/Controllers/ChapterController.php | 10 ++- .../Api/Controllers/ConsultController.php | 12 +++ app/Http/Api/Controllers/CourseController.php | 8 ++ app/Http/Api/Controllers/HelpController.php | 8 ++ .../Api/Controllers/ImGroupController.php | 8 ++ app/Http/Api/Controllers/OrderController.php | 4 + app/Http/Api/Controllers/PageController.php | 8 ++ .../Api/Controllers/QuestionController.php | 12 +++ app/Http/Api/Controllers/RefundController.php | 8 ++ app/Http/Api/Controllers/ReviewController.php | 12 +++ app/Http/Api/Controllers/TradeController.php | 8 ++ app/Http/Api/Controllers/UserController.php | 4 + .../Home/Controllers/AnswerController.php | 11 ++- .../Home/Controllers/ArticleController.php | 12 ++- .../Home/Controllers/ChapterController.php | 22 ++--- .../Home/Controllers/ConsultController.php | 12 +++ .../Home/Controllers/CourseController.php | 6 +- app/Http/Home/Controllers/HelpController.php | 6 +- .../Home/Controllers/ImGroupController.php | 6 +- app/Http/Home/Controllers/OrderController.php | 8 ++ .../Home/Controllers/PackageController.php | 2 +- app/Http/Home/Controllers/PageController.php | 6 +- .../Home/Controllers/PointGiftController.php | 6 +- .../Home/Controllers/QuestionController.php | 11 ++- .../Home/Controllers/RefundController.php | 8 ++ .../Home/Controllers/ReviewController.php | 12 +++ app/Http/Home/Controllers/TopicController.php | 2 +- app/Http/Home/Controllers/UserController.php | 2 +- app/Http/Home/Views/refund/info.volt | 2 +- app/Models/Category.php | 4 - app/Models/Chapter.php | 4 - app/Models/Consult.php | 4 - app/Models/Course.php | 4 - app/Models/Danmu.php | 4 - app/Models/FlashSale.php | 4 - app/Models/Help.php | 4 - app/Models/ImGroup.php | 4 - app/Models/Nav.php | 4 - app/Models/Package.php | 4 - app/Models/Page.php | 4 - app/Models/PointGift.php | 4 - app/Models/Review.php | 4 - app/Models/Slide.php | 4 - app/Models/Tag.php | 4 - app/Models/Topic.php | 4 - app/Models/WeChatSubscribe.php | 7 ++ app/Repos/Comment.php | 5 +- app/Repos/Consult.php | 5 +- app/Repos/ImGroup.php | 4 +- app/Repos/Package.php | 5 +- app/Repos/Review.php | 5 +- app/Repos/Topic.php | 5 +- app/Repos/User.php | 33 +++++++- app/Services/Logic/Answer/AnswerInfo.php | 44 ++++------ app/Services/Logic/Article/ArticleInfo.php | 70 +++++----------- app/Services/Logic/Comment/CommentInfo.php | 56 +++++++------ app/Services/Logic/Consult/ConsultInfo.php | 80 ++++++++++--------- app/Services/Logic/Danmu/DanmuInfo.php | 20 ++--- app/Services/Logic/Order/OrderInfo.php | 32 +++++--- app/Services/Logic/Question/AnswerList.php | 7 +- app/Services/Logic/Question/QuestionInfo.php | 31 ++----- app/Services/Logic/Refund/RefundInfo.php | 46 +++++++++-- app/Services/Logic/Review/ReviewInfo.php | 61 +++++++++----- app/Services/Logic/Trade/TradeInfo.php | 74 ++++++++++++++++- app/Services/Logic/UserTrait.php | 14 ++++ app/Traits/Response.php | 29 +------ 114 files changed, 708 insertions(+), 380 deletions(-) diff --git a/app/Builders/AnswerList.php b/app/Builders/AnswerList.php index 7e47e5b4..0c3b0b99 100644 --- a/app/Builders/AnswerList.php +++ b/app/Builders/AnswerList.php @@ -58,7 +58,7 @@ class AnswerList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/ArticleList.php b/app/Builders/ArticleList.php index 7edf86f8..7ef8ca46 100644 --- a/app/Builders/ArticleList.php +++ b/app/Builders/ArticleList.php @@ -71,7 +71,7 @@ class ArticleList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/CategoryTreeList.php b/app/Builders/CategoryTreeList.php index ab23e991..6944aea8 100644 --- a/app/Builders/CategoryTreeList.php +++ b/app/Builders/CategoryTreeList.php @@ -69,6 +69,7 @@ class CategoryTreeList extends Builder $query->where('parent_id = 0'); $query->andWhere('published = 1'); + $query->andWhere('deleted = 0'); $query->andWhere('type = :type:', ['type' => $type]); $query->orderBy('priority ASC'); @@ -84,6 +85,7 @@ class CategoryTreeList extends Builder $query = CategoryModel::query(); $query->where('published = 1'); + $query->where('deleted = 0'); $query->andWhere('parent_id = :parent_id:', ['parent_id' => $parentId]); $query->orderBy('priority ASC'); diff --git a/app/Builders/CommentList.php b/app/Builders/CommentList.php index f300ecda..e0eb0059 100644 --- a/app/Builders/CommentList.php +++ b/app/Builders/CommentList.php @@ -32,7 +32,7 @@ class CommentList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/ConsultList.php b/app/Builders/ConsultList.php index b356276b..a06e667c 100644 --- a/app/Builders/ConsultList.php +++ b/app/Builders/ConsultList.php @@ -79,7 +79,7 @@ class ConsultList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/CourseList.php b/app/Builders/CourseList.php index 25c821e4..e5a3c383 100644 --- a/app/Builders/CourseList.php +++ b/app/Builders/CourseList.php @@ -62,7 +62,7 @@ class CourseList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/DanmuList.php b/app/Builders/DanmuList.php index 8adf3c09..2ee29569 100644 --- a/app/Builders/DanmuList.php +++ b/app/Builders/DanmuList.php @@ -87,7 +87,7 @@ class DanmuList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/ImMessageList.php b/app/Builders/ImMessageList.php index 0026bfbc..03fce797 100644 --- a/app/Builders/ImMessageList.php +++ b/app/Builders/ImMessageList.php @@ -29,7 +29,7 @@ class ImMessageList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/LiveList.php b/app/Builders/LiveList.php index 734e4d2d..8f8102e2 100644 --- a/app/Builders/LiveList.php +++ b/app/Builders/LiveList.php @@ -48,7 +48,7 @@ class LiveList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($teacherIds, ['id', 'name', 'title', 'avatar', 'about']); + $users = $userRepo->findShallowUserByIds($teacherIds); $baseUrl = kg_cos_url(); diff --git a/app/Builders/NavTreeList.php b/app/Builders/NavTreeList.php index 185e3fa7..6801c2a5 100644 --- a/app/Builders/NavTreeList.php +++ b/app/Builders/NavTreeList.php @@ -68,6 +68,7 @@ class NavTreeList extends Builder return NavModel::query() ->where('parent_id = :parent_id:', ['parent_id' => $navId]) ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->execute(); } @@ -80,7 +81,9 @@ class NavTreeList extends Builder { return NavModel::query() ->where('position = :position:', ['position' => $position]) - ->andWhere('level = 1 AND published = 1') + ->andWhere('level = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->execute(); } diff --git a/app/Builders/NotificationList.php b/app/Builders/NotificationList.php index 73067c4a..6670553d 100644 --- a/app/Builders/NotificationList.php +++ b/app/Builders/NotificationList.php @@ -32,7 +32,7 @@ class NotificationList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/OrderList.php b/app/Builders/OrderList.php index cfcdae2d..d317d604 100644 --- a/app/Builders/OrderList.php +++ b/app/Builders/OrderList.php @@ -186,7 +186,7 @@ class OrderList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name']); + $users = $userRepo->findShallowUserByIds($ids); $result = []; diff --git a/app/Builders/QuestionFavoriteList.php b/app/Builders/QuestionFavoriteList.php index c7675389..7d5185de 100644 --- a/app/Builders/QuestionFavoriteList.php +++ b/app/Builders/QuestionFavoriteList.php @@ -72,7 +72,7 @@ class QuestionFavoriteList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/QuestionList.php b/app/Builders/QuestionList.php index 3cb04d76..10a40a3c 100644 --- a/app/Builders/QuestionList.php +++ b/app/Builders/QuestionList.php @@ -74,7 +74,7 @@ class QuestionList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/RefundList.php b/app/Builders/RefundList.php index 4328431d..396bdd44 100644 --- a/app/Builders/RefundList.php +++ b/app/Builders/RefundList.php @@ -58,11 +58,14 @@ class RefundList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name']); + $users = $userRepo->findShallowUserByIds($ids); + + $baseUrl = kg_cos_url(); $result = []; foreach ($users->toArray() as $user) { + $user['avatar'] = $baseUrl . $user['avatar']; $result[$user['id']] = $user; } diff --git a/app/Builders/ReportList.php b/app/Builders/ReportList.php index f858ede8..89c67218 100644 --- a/app/Builders/ReportList.php +++ b/app/Builders/ReportList.php @@ -29,7 +29,7 @@ class ReportList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/ReviewList.php b/app/Builders/ReviewList.php index 2cbb354a..5a931902 100644 --- a/app/Builders/ReviewList.php +++ b/app/Builders/ReviewList.php @@ -58,7 +58,7 @@ class ReviewList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); + $users = $userRepo->findShallowUserByIds($ids); $baseUrl = kg_cos_url(); diff --git a/app/Builders/TradeList.php b/app/Builders/TradeList.php index aa62d73d..40d17a92 100644 --- a/app/Builders/TradeList.php +++ b/app/Builders/TradeList.php @@ -58,11 +58,14 @@ class TradeList extends Builder $userRepo = new UserRepo(); - $users = $userRepo->findByIds($ids, ['id', 'name']); + $users = $userRepo->findShallowUserByIds($ids); + + $baseUrl = kg_cos_url(); $result = []; foreach ($users->toArray() as $user) { + $user['avatar'] = $baseUrl . $user['avatar']; $result[$user['id']] = $user; } diff --git a/app/Caches/CategoryList.php b/app/Caches/CategoryList.php index 8f7b6b59..5d436aa8 100644 --- a/app/Caches/CategoryList.php +++ b/app/Caches/CategoryList.php @@ -38,6 +38,7 @@ class CategoryList extends Cache ->columns(['id', 'parent_id', 'name', 'priority', 'level', 'path']) ->where('type = :type:', ['type' => $type]) ->andWhere('published = 1') + ->andWhere('deleted = 0') ->execute(); if ($categories->count() == 0) { diff --git a/app/Caches/CourseRecommendedList.php b/app/Caches/CourseRecommendedList.php index b9c27f20..51ed746d 100644 --- a/app/Caches/CourseRecommendedList.php +++ b/app/Caches/CourseRecommendedList.php @@ -70,7 +70,9 @@ class CourseRecommendedList extends Cache public function findCourses($limit = 5) { return CourseModel::query() - ->where('published = 1 AND market_price > 0') + ->where('market_price > 0') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('RAND()') ->limit($limit) ->execute(); diff --git a/app/Caches/CourseTeacherList.php b/app/Caches/CourseTeacherList.php index f6a3c583..70314edc 100644 --- a/app/Caches/CourseTeacherList.php +++ b/app/Caches/CourseTeacherList.php @@ -51,6 +51,7 @@ class CourseTeacherList extends Cache 'id' => $user->id, 'name' => $user->name, 'avatar' => $user->avatar, + 'vip' => $user->vip, 'title' => $user->title, 'about' => $user->about, ]; diff --git a/app/Caches/HelpList.php b/app/Caches/HelpList.php index a253c3d5..2899bbd8 100644 --- a/app/Caches/HelpList.php +++ b/app/Caches/HelpList.php @@ -73,7 +73,9 @@ class HelpList extends Cache { return CategoryModel::query() ->where('type = :type:', ['type' => CategoryModel::TYPE_HELP]) - ->andWhere('level = 1 AND published = 1') + ->andWhere('level = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->execute(); } @@ -87,6 +89,7 @@ class HelpList extends Cache return HelpModel::query() ->where('category_id = :category_id:', ['category_id' => $categoryId]) ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->execute(); } diff --git a/app/Caches/HotQuestionList.php b/app/Caches/HotQuestionList.php index e09b517d..dea5c8a4 100644 --- a/app/Caches/HotQuestionList.php +++ b/app/Caches/HotQuestionList.php @@ -111,7 +111,8 @@ class HotQuestionList extends Cache { return QuestionModel::query() ->where('create_time > :create_time:', ['create_time' => $createTime]) - ->andWhere('published = 1 AND deleted = 0') + ->andWhere('published = :published:', ['published' => QuestionModel::PUBLISH_APPROVED]) + ->andWhere('deleted = 0') ->orderBy('score DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/ImActiveGroupList.php b/app/Caches/ImActiveGroupList.php index 24a0759d..581d3044 100644 --- a/app/Caches/ImActiveGroupList.php +++ b/app/Caches/ImActiveGroupList.php @@ -72,6 +72,8 @@ class ImActiveGroupList extends Cache ->orderBy('total_count DESC') ->where('receiver_type = :type:', ['type' => ImMessageModel::TYPE_GROUP]) ->betweenWhere('create_time', $startTime, $endTime) + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->limit($limit) ->execute(); diff --git a/app/Caches/ImNewGroupList.php b/app/Caches/ImNewGroupList.php index 03cb1f5f..b76e0495 100644 --- a/app/Caches/ImNewGroupList.php +++ b/app/Caches/ImNewGroupList.php @@ -70,6 +70,7 @@ class ImNewGroupList extends Cache { return ImGroupModel::query() ->where('published = 1') + ->andWhere('deleted = 0') ->orderBy('id DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexArticleList.php b/app/Caches/IndexArticleList.php index 0f03cc0f..6b6f20cc 100644 --- a/app/Caches/IndexArticleList.php +++ b/app/Caches/IndexArticleList.php @@ -30,7 +30,10 @@ class IndexArticleList extends Cache { $articleRepo = new ArticleRepo(); - $where = ['published' => ArticleModel::PUBLISH_APPROVED]; + $where = [ + 'published' => ArticleModel::PUBLISH_APPROVED, + 'deleted' => 0, + ]; $pager = $articleRepo->paginate($where, 'latest', 1, 10); diff --git a/app/Caches/IndexFeaturedCourseList.php b/app/Caches/IndexFeaturedCourseList.php index 7fe31e94..9ef38676 100644 --- a/app/Caches/IndexFeaturedCourseList.php +++ b/app/Caches/IndexFeaturedCourseList.php @@ -94,7 +94,9 @@ class IndexFeaturedCourseList extends Cache { return CategoryModel::query() ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) - ->andWhere('level = 1 AND published = 1') + ->andWhere('level = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->limit($limit) ->execute(); @@ -113,8 +115,9 @@ class IndexFeaturedCourseList extends Cache return CourseModel::query() ->inWhere('category_id', $categoryIds) - ->andWhere('published = 1') ->andWhere('featured = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('id DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexFreeCourseList.php b/app/Caches/IndexFreeCourseList.php index 071ba74c..ecd23215 100644 --- a/app/Caches/IndexFreeCourseList.php +++ b/app/Caches/IndexFreeCourseList.php @@ -94,7 +94,9 @@ class IndexFreeCourseList extends Cache { return CategoryModel::query() ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) - ->andWhere('level = 1 AND published = 1') + ->andWhere('level = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->limit($limit) ->execute(); @@ -113,8 +115,9 @@ class IndexFreeCourseList extends Cache return CourseModel::query() ->inWhere('category_id', $categoryIds) - ->andWhere('published = 1') ->andWhere('market_price = 0') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('score DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexLiveList.php b/app/Caches/IndexLiveList.php index 6eaab7bf..6d5d0836 100644 --- a/app/Caches/IndexLiveList.php +++ b/app/Caches/IndexLiveList.php @@ -132,6 +132,8 @@ class IndexLiveList extends Cache ->addFrom(ChapterLiveModel::class, 'cl') ->join(ChapterModel::class, 'cl.chapter_id = c.id', 'c') ->betweenWhere('start_time', $startTime, $endTime) + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('start_time ASC') ->getQuery() ->execute(); diff --git a/app/Caches/IndexNewCourseList.php b/app/Caches/IndexNewCourseList.php index 6f4c9f50..1049d2c2 100644 --- a/app/Caches/IndexNewCourseList.php +++ b/app/Caches/IndexNewCourseList.php @@ -94,7 +94,9 @@ class IndexNewCourseList extends Cache { return CategoryModel::query() ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) - ->andWhere('level = 1 AND published = 1') + ->andWhere('level = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->limit($limit) ->execute(); @@ -114,6 +116,7 @@ class IndexNewCourseList extends Cache return CourseModel::query() ->inWhere('category_id', $categoryIds) ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('id DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexQuestionList.php b/app/Caches/IndexQuestionList.php index 9c301b1a..b79db98b 100644 --- a/app/Caches/IndexQuestionList.php +++ b/app/Caches/IndexQuestionList.php @@ -30,7 +30,10 @@ class IndexQuestionList extends Cache { $questionRepo = new QuestionRepo(); - $where = ['published' => QuestionModel::PUBLISH_APPROVED]; + $where = [ + 'published' => QuestionModel::PUBLISH_APPROVED, + 'deleted' => 0, + ]; $pager = $questionRepo->paginate($where, 'latest', 1, 10); diff --git a/app/Caches/IndexSimpleFeaturedCourseList.php b/app/Caches/IndexSimpleFeaturedCourseList.php index a933b7cc..f3588fed 100644 --- a/app/Caches/IndexSimpleFeaturedCourseList.php +++ b/app/Caches/IndexSimpleFeaturedCourseList.php @@ -65,8 +65,9 @@ class IndexSimpleFeaturedCourseList extends Cache protected function findCourses($limit = 8) { return CourseModel::query() - ->where('published = 1') - ->andWhere('featured = 1') + ->where('featured = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('id DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexSimpleFreeCourseList.php b/app/Caches/IndexSimpleFreeCourseList.php index b7f187ea..a37e8779 100644 --- a/app/Caches/IndexSimpleFreeCourseList.php +++ b/app/Caches/IndexSimpleFreeCourseList.php @@ -65,8 +65,9 @@ class IndexSimpleFreeCourseList extends Cache protected function findCourses($limit = 8) { return CourseModel::query() - ->where('published = 1') - ->andWhere('market_price = 0') + ->where('market_price = 0') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('score DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexSimpleNewCourseList.php b/app/Caches/IndexSimpleNewCourseList.php index 94c0b5e2..b43166a9 100644 --- a/app/Caches/IndexSimpleNewCourseList.php +++ b/app/Caches/IndexSimpleNewCourseList.php @@ -66,6 +66,7 @@ class IndexSimpleNewCourseList extends Cache { return CourseModel::query() ->where('published = 1') + ->andWhere('deleted = 0') ->orderBy('id DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexSimpleVipCourseList.php b/app/Caches/IndexSimpleVipCourseList.php index cda3478f..d4474287 100644 --- a/app/Caches/IndexSimpleVipCourseList.php +++ b/app/Caches/IndexSimpleVipCourseList.php @@ -65,9 +65,10 @@ class IndexSimpleVipCourseList extends Cache protected function findCourses($limit = 8) { return CourseModel::query() - ->where('published = 1') - ->andWhere('market_price > vip_price') + ->where('market_price > vip_price') ->andWhere('vip_price >= 0') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('score DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexSlideList.php b/app/Caches/IndexSlideList.php index e8ca5e71..abc7d28c 100644 --- a/app/Caches/IndexSlideList.php +++ b/app/Caches/IndexSlideList.php @@ -68,6 +68,7 @@ class IndexSlideList extends Cache { return SlideModel::query() ->where('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexTeacherList.php b/app/Caches/IndexTeacherList.php index 2decb09d..df9d2056 100644 --- a/app/Caches/IndexTeacherList.php +++ b/app/Caches/IndexTeacherList.php @@ -60,6 +60,7 @@ class IndexTeacherList extends Cache { return UserModel::query() ->where('edu_role = :edu_role:', ['edu_role' => UserModel::EDU_ROLE_TEACHER]) + ->andWhere('deleted = 0') ->orderBy('RAND()') ->limit($limit) ->execute(); diff --git a/app/Caches/IndexVipCourseList.php b/app/Caches/IndexVipCourseList.php index 201edb71..163bff1f 100644 --- a/app/Caches/IndexVipCourseList.php +++ b/app/Caches/IndexVipCourseList.php @@ -94,7 +94,9 @@ class IndexVipCourseList extends Cache { return CategoryModel::query() ->where('type = :type:', ['type' => CategoryModel::TYPE_COURSE]) - ->andWhere('level = 1 AND published = 1') + ->andWhere('level = 1') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('priority ASC') ->limit($limit) ->execute(); @@ -113,9 +115,10 @@ class IndexVipCourseList extends Cache return CourseModel::query() ->inWhere('category_id', $categoryIds) - ->andWhere('published = 1') ->andWhere('market_price > vip_price') ->andWhere('vip_price >= 0') + ->andWhere('published = 1') + ->andWhere('deleted = 0') ->orderBy('score DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/PointHotGiftList.php b/app/Caches/PointHotGiftList.php index 7b89f3cf..5fe9213a 100644 --- a/app/Caches/PointHotGiftList.php +++ b/app/Caches/PointHotGiftList.php @@ -76,6 +76,7 @@ class PointHotGiftList extends Cache { return PointGiftModel::query() ->where('published = 1') + ->andWhere('deleted = 0') ->orderBy('redeem_count DESC') ->limit($limit) ->execute(); diff --git a/app/Caches/TaggedArticleList.php b/app/Caches/TaggedArticleList.php index 88ad3f5d..8113b4f8 100644 --- a/app/Caches/TaggedArticleList.php +++ b/app/Caches/TaggedArticleList.php @@ -34,6 +34,7 @@ class TaggedArticleList extends Cache $where = [ 'tag_id' => $id, 'published' => ArticleModel::PUBLISH_APPROVED, + 'deleted' => 0, ]; $pager = $articleRepo->paginate($where); diff --git a/app/Caches/TaggedQuestionList.php b/app/Caches/TaggedQuestionList.php index ee7ef9c9..d563dabe 100644 --- a/app/Caches/TaggedQuestionList.php +++ b/app/Caches/TaggedQuestionList.php @@ -35,6 +35,7 @@ class TaggedQuestionList extends Cache $where = [ 'tag_id' => $id, 'published' => QuestionModel::PUBLISH_APPROVED, + 'deleted' => 0, ]; $pager = $questionRepo->paginate($where); diff --git a/app/Console/Tasks/ArticleIndexTask.php b/app/Console/Tasks/ArticleIndexTask.php index 77b5ff2d..017a2577 100644 --- a/app/Console/Tasks/ArticleIndexTask.php +++ b/app/Console/Tasks/ArticleIndexTask.php @@ -124,6 +124,7 @@ class ArticleIndexTask extends Task { return ArticleModel::query() ->where('published = :published:', ['published' => ArticleModel::PUBLISH_APPROVED]) + ->andWhere('deleted = 0') ->execute(); } diff --git a/app/Console/Tasks/CourseIndexTask.php b/app/Console/Tasks/CourseIndexTask.php index f757883b..ed568faf 100644 --- a/app/Console/Tasks/CourseIndexTask.php +++ b/app/Console/Tasks/CourseIndexTask.php @@ -124,6 +124,7 @@ class CourseIndexTask extends Task { return CourseModel::query() ->where('published = 1') + ->where('deleted = 0') ->execute(); } diff --git a/app/Console/Tasks/GroupIndexTask.php b/app/Console/Tasks/GroupIndexTask.php index 8147ef37..cad23dbf 100644 --- a/app/Console/Tasks/GroupIndexTask.php +++ b/app/Console/Tasks/GroupIndexTask.php @@ -124,6 +124,7 @@ class GroupIndexTask extends Task { return GroupModel::query() ->where('published = 1') + ->andWhere('deleted = 0') ->execute(); } diff --git a/app/Console/Tasks/QuestionIndexTask.php b/app/Console/Tasks/QuestionIndexTask.php index 6594881c..886d0aea 100644 --- a/app/Console/Tasks/QuestionIndexTask.php +++ b/app/Console/Tasks/QuestionIndexTask.php @@ -124,6 +124,7 @@ class QuestionIndexTask extends Task { return QuestionModel::query() ->where('published = :published:', ['published' => QuestionModel::PUBLISH_APPROVED]) + ->andWhere('deleted = 0') ->execute(); } diff --git a/app/Console/Tasks/UserIndexTask.php b/app/Console/Tasks/UserIndexTask.php index 674d12ee..77b0db5d 100644 --- a/app/Console/Tasks/UserIndexTask.php +++ b/app/Console/Tasks/UserIndexTask.php @@ -139,6 +139,7 @@ class UserIndexTask extends Task protected function findUsers($limit, $offset) { return UserModel::query() + ->where('deleted = 0') ->limit($limit, $offset) ->execute(); } diff --git a/app/Http/Api/Controllers/AnswerController.php b/app/Http/Api/Controllers/AnswerController.php index 979f5827..d49ed3ae 100644 --- a/app/Http/Api/Controllers/AnswerController.php +++ b/app/Http/Api/Controllers/AnswerController.php @@ -7,6 +7,7 @@ namespace App\Http\Api\Controllers; +use App\Models\Answer as AnswerModel; use App\Services\Logic\Answer\AnswerAccept as AnswerAcceptService; use App\Services\Logic\Answer\AnswerCreate as AnswerCreateService; use App\Services\Logic\Answer\AnswerDelete as AnswerDeleteService; @@ -30,6 +31,17 @@ class AnswerController extends Controller $answer = $service->handle($id); + if ($answer['deleted'] == 1) { + $this->notFound(); + } + + $approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED; + $owned = $answer['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); + } + return $this->jsonSuccess(['answer' => $answer]); } diff --git a/app/Http/Api/Controllers/ArticleController.php b/app/Http/Api/Controllers/ArticleController.php index 0ad2e498..c61ac491 100644 --- a/app/Http/Api/Controllers/ArticleController.php +++ b/app/Http/Api/Controllers/ArticleController.php @@ -7,6 +7,7 @@ namespace App\Http\Api\Controllers; +use App\Models\Article as ArticleModel; use App\Services\Logic\Article\ArticleClose as ArticleCloseService; use App\Services\Logic\Article\ArticleDelete as ArticleDeleteService; use App\Services\Logic\Article\ArticleFavorite as ArticleFavoriteService; @@ -56,6 +57,22 @@ class ArticleController extends Controller $article = $service->handle($id); + if ($article['deleted'] == 1) { + $this->notFound(); + } + + $approved = $article['published'] == ArticleModel::PUBLISH_APPROVED; + $owned = $article['me']['owned'] == 1; + $private = $article['private'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); + } + + if ($private && !$owned) { + $this->forbidden(); + } + return $this->jsonSuccess(['article' => $article]); } diff --git a/app/Http/Api/Controllers/ChapterController.php b/app/Http/Api/Controllers/ChapterController.php index 63ca974f..1b96f7c5 100644 --- a/app/Http/Api/Controllers/ChapterController.php +++ b/app/Http/Api/Controllers/ChapterController.php @@ -65,8 +65,16 @@ class ChapterController extends Controller $chapter = $service->handle($id); + if ($chapter['deleted'] == 1) { + $this->notFound(); + } + + if ($chapter['published'] == 0) { + $this->notFound(); + } + if ($chapter['me']['owned'] == 0) { - return $this->jsonError(['msg' => '没有访问章节权限']); + $this->forbidden(); } return $this->jsonSuccess(['chapter' => $chapter]); diff --git a/app/Http/Api/Controllers/ConsultController.php b/app/Http/Api/Controllers/ConsultController.php index 4a9b1386..45db1c0e 100644 --- a/app/Http/Api/Controllers/ConsultController.php +++ b/app/Http/Api/Controllers/ConsultController.php @@ -7,6 +7,7 @@ namespace App\Http\Api\Controllers; +use App\Models\Consult as ConsultModel; use App\Services\Logic\Consult\ConsultCreate as ConsultCreateService; use App\Services\Logic\Consult\ConsultDelete as ConsultDeleteService; use App\Services\Logic\Consult\ConsultInfo as ConsultInfoService; @@ -28,6 +29,17 @@ class ConsultController extends Controller $consult = $service->handle($id); + if ($consult['deleted'] == 1) { + $this->notFound(); + } + + $approved = $consult['published'] == ConsultModel::PUBLISH_APPROVED; + $owned = $consult['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); + } + return $this->jsonSuccess(['consult' => $consult]); } diff --git a/app/Http/Api/Controllers/CourseController.php b/app/Http/Api/Controllers/CourseController.php index 5c449652..62c8596b 100644 --- a/app/Http/Api/Controllers/CourseController.php +++ b/app/Http/Api/Controllers/CourseController.php @@ -55,6 +55,14 @@ class CourseController extends Controller $course = $service->handle($id); + if ($course['deleted'] == 1) { + $this->notFound(); + } + + if ($course['published'] == 0) { + $this->notFound(); + } + return $this->jsonSuccess(['course' => $course]); } diff --git a/app/Http/Api/Controllers/HelpController.php b/app/Http/Api/Controllers/HelpController.php index e944dc47..06dc00c1 100644 --- a/app/Http/Api/Controllers/HelpController.php +++ b/app/Http/Api/Controllers/HelpController.php @@ -37,6 +37,14 @@ class HelpController extends Controller $help = $service->handle($id); + if ($help['deleted'] == 1) { + $this->notFound(); + } + + if ($help['published'] == 0) { + $this->notFound(); + } + return $this->jsonSuccess(['help' => $help]); } diff --git a/app/Http/Api/Controllers/ImGroupController.php b/app/Http/Api/Controllers/ImGroupController.php index e8d53e2f..5e199b08 100644 --- a/app/Http/Api/Controllers/ImGroupController.php +++ b/app/Http/Api/Controllers/ImGroupController.php @@ -39,6 +39,14 @@ class ImGroupController extends Controller $group = $service->handle($id); + if ($group['deleted'] == 1) { + $this->notFound(); + } + + if ($group['published'] == 0) { + $this->notFound(); + } + return $this->jsonSuccess(['group' => $group]); } diff --git a/app/Http/Api/Controllers/OrderController.php b/app/Http/Api/Controllers/OrderController.php index dbd9dc47..cd5fb1f3 100644 --- a/app/Http/Api/Controllers/OrderController.php +++ b/app/Http/Api/Controllers/OrderController.php @@ -29,6 +29,10 @@ class OrderController extends Controller $order = $service->handle($sn); + if ($order['deleted'] == 1) { + $this->notFound(); + } + return $this->jsonSuccess(['order' => $order]); } diff --git a/app/Http/Api/Controllers/PageController.php b/app/Http/Api/Controllers/PageController.php index 7ef38905..e8094151 100644 --- a/app/Http/Api/Controllers/PageController.php +++ b/app/Http/Api/Controllers/PageController.php @@ -24,6 +24,14 @@ class PageController extends Controller $page = $service->handle($id); + if ($page['deleted'] == 1) { + $this->notFound(); + } + + if ($page['published'] == 0) { + $this->notFound(); + } + return $this->jsonSuccess(['page' => $page]); } diff --git a/app/Http/Api/Controllers/QuestionController.php b/app/Http/Api/Controllers/QuestionController.php index 3ba26c90..a3e402d3 100644 --- a/app/Http/Api/Controllers/QuestionController.php +++ b/app/Http/Api/Controllers/QuestionController.php @@ -7,6 +7,7 @@ namespace App\Http\Api\Controllers; +use App\Models\Question as QuestionModel; use App\Services\Logic\Question\AnswerList as AnswerListService; use App\Services\Logic\Question\CategoryList as CategoryListService; use App\Services\Logic\Question\CommentList as CommentListService; @@ -55,6 +56,17 @@ class QuestionController extends Controller $question = $service->handle($id); + if ($question['deleted'] == 1) { + $this->notFound(); + } + + $approved = $question['published'] == QuestionModel::PUBLISH_APPROVED; + $owned = $question['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); + } + return $this->jsonSuccess(['question' => $question]); } diff --git a/app/Http/Api/Controllers/RefundController.php b/app/Http/Api/Controllers/RefundController.php index 8f5249d3..17c8e692 100644 --- a/app/Http/Api/Controllers/RefundController.php +++ b/app/Http/Api/Controllers/RefundController.php @@ -43,6 +43,14 @@ class RefundController extends Controller $refund = $service->handle($sn); + if ($refund['deleted'] == 1) { + $this->notFound(); + } + + if ($refund['me']['owned'] == 0) { + $this->forbidden(); + } + return $this->jsonSuccess(['refund' => $refund]); } diff --git a/app/Http/Api/Controllers/ReviewController.php b/app/Http/Api/Controllers/ReviewController.php index 1c88a173..2f6d0e9d 100644 --- a/app/Http/Api/Controllers/ReviewController.php +++ b/app/Http/Api/Controllers/ReviewController.php @@ -7,6 +7,7 @@ namespace App\Http\Api\Controllers; +use App\Models\Review as ReviewModel; use App\Services\Logic\Review\ReviewCreate as ReviewCreateService; use App\Services\Logic\Review\ReviewDelete as ReviewDeleteService; use App\Services\Logic\Review\ReviewInfo as ReviewInfoService; @@ -28,6 +29,17 @@ class ReviewController extends Controller $review = $service->handle($id); + if ($review['deleted'] == 1) { + $this->notFound(); + } + + $approved = $review['published'] == ReviewModel::PUBLISH_APPROVED; + $owned = $review['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); + } + return $this->jsonSuccess(['review' => $review]); } diff --git a/app/Http/Api/Controllers/TradeController.php b/app/Http/Api/Controllers/TradeController.php index bb03665d..99cd5b13 100644 --- a/app/Http/Api/Controllers/TradeController.php +++ b/app/Http/Api/Controllers/TradeController.php @@ -27,6 +27,14 @@ class TradeController extends Controller $trade = $service->handle($sn); + if ($trade['deleted'] == 1) { + $this->notFound(); + } + + if ($trade['me']['owned'] == 0) { + $this->forbidden(); + } + return $this->jsonSuccess(['trade' => $trade]); } diff --git a/app/Http/Api/Controllers/UserController.php b/app/Http/Api/Controllers/UserController.php index 6bb5ecfa..13d3a078 100644 --- a/app/Http/Api/Controllers/UserController.php +++ b/app/Http/Api/Controllers/UserController.php @@ -30,6 +30,10 @@ class UserController extends Controller $user = $service->handle($id); + if ($user['deleted'] == 1) { + $this->notFound(); + } + return $this->jsonSuccess(['user' => $user]); } diff --git a/app/Http/Home/Controllers/AnswerController.php b/app/Http/Home/Controllers/AnswerController.php index 0a09e4d7..a833382b 100644 --- a/app/Http/Home/Controllers/AnswerController.php +++ b/app/Http/Home/Controllers/AnswerController.php @@ -57,8 +57,15 @@ class AnswerController extends Controller $answer = $service->handle($id); - if ($answer['published'] != AnswerModel::PUBLISH_APPROVED) { - return $this->notFound(); + if ($answer['deleted'] == 1) { + $this->notFound(); + } + + $approved = $answer['published'] != AnswerModel::PUBLISH_APPROVED; + $owned = $answer['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); } $questionId = $answer['question']['id']; diff --git a/app/Http/Home/Controllers/ArticleController.php b/app/Http/Home/Controllers/ArticleController.php index 9f199c3c..cbd48b8f 100644 --- a/app/Http/Home/Controllers/ArticleController.php +++ b/app/Http/Home/Controllers/ArticleController.php @@ -105,16 +105,20 @@ class ArticleController extends Controller $article = $service->handle($id); - if ($article['published'] != ArticleModel::PUBLISH_APPROVED) { - return $this->notFound(); + if ($article['deleted'] == 1) { + $this->notFound(); } + $approved = $article['published'] == ArticleModel::PUBLISH_APPROVED; + $owned = $article['me']['owned'] == 1; $private = $article['private'] == 1; - $owned = $this->authUser->id == $article['owner']['id']; + if (!$approved && !$owned) { + $this->notFound(); + } if ($private && !$owned) { - return $this->forbidden(); + $this->forbidden(); } $this->seo->prependTitle(['专栏', $article['title']]); diff --git a/app/Http/Home/Controllers/ChapterController.php b/app/Http/Home/Controllers/ChapterController.php index c1a75bff..6e2ba588 100644 --- a/app/Http/Home/Controllers/ChapterController.php +++ b/app/Http/Home/Controllers/ChapterController.php @@ -39,20 +39,24 @@ class ChapterController extends Controller */ public function showAction($id) { - $service = new ChapterInfoService(); - - $chapter = $service->handle($id); - - if ($chapter['published'] == 0) { - return $this->notFound(); - } - if ($this->authUser->id == 0) { return $this->response->redirect(['for' => 'home.account.login']); } + $service = new ChapterInfoService(); + + $chapter = $service->handle($id); + + if ($chapter['deleted'] == 1) { + $this->notFound(); + } + + if ($chapter['published'] == 0) { + $this->notFound(); + } + if ($chapter['me']['owned'] == 0) { - return $this->forbidden(); + $this->forbidden(); } $service = new CourseInfoService(); diff --git a/app/Http/Home/Controllers/ConsultController.php b/app/Http/Home/Controllers/ConsultController.php index d1d78730..dfacf179 100644 --- a/app/Http/Home/Controllers/ConsultController.php +++ b/app/Http/Home/Controllers/ConsultController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Models\Consult as ConsultModel; use App\Services\Logic\Consult\ConsultCreate as ConsultCreateService; use App\Services\Logic\Consult\ConsultDelete as ConsultDeleteService; use App\Services\Logic\Consult\ConsultInfo as ConsultInfoService; @@ -37,6 +38,17 @@ class ConsultController extends Controller $consult = $service->handle($id); + if ($consult['deleted'] == 1) { + $this->notFound(); + } + + $approved = $consult['published'] == ConsultModel::PUBLISH_APPROVED; + $owned = $consult['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); + } + $this->view->setVar('consult', $consult); } diff --git a/app/Http/Home/Controllers/CourseController.php b/app/Http/Home/Controllers/CourseController.php index ec180bb5..bc1ae450 100644 --- a/app/Http/Home/Controllers/CourseController.php +++ b/app/Http/Home/Controllers/CourseController.php @@ -77,8 +77,12 @@ class CourseController extends Controller $course = $service->handle($id); + if ($course['deleted'] == 1) { + $this->notFound(); + } + if ($course['published'] == 0) { - return $this->notFound(); + $this->notFound(); } $service = new CourseChapterListService(); diff --git a/app/Http/Home/Controllers/HelpController.php b/app/Http/Home/Controllers/HelpController.php index db5cbe88..e41ccb9a 100644 --- a/app/Http/Home/Controllers/HelpController.php +++ b/app/Http/Home/Controllers/HelpController.php @@ -40,8 +40,12 @@ class HelpController extends Controller $help = $service->handle($id); + if ($help['deleted'] == 1) { + $this->notFound(); + } + if ($help['published'] == 0) { - return $this->notFound(); + $this->notFound(); } $featuredCourses = $this->getFeaturedCourses(); diff --git a/app/Http/Home/Controllers/ImGroupController.php b/app/Http/Home/Controllers/ImGroupController.php index 858c9374..fdabf072 100644 --- a/app/Http/Home/Controllers/ImGroupController.php +++ b/app/Http/Home/Controllers/ImGroupController.php @@ -51,8 +51,12 @@ class ImGroupController extends Controller $group = $service->getGroup($id); + if ($group['deleted'] == 1) { + $this->notFound(); + } + if ($group['published'] == 0) { - return $this->notFound(); + $this->notFound(); } $this->seo->prependTitle(['群组', $group['name']]); diff --git a/app/Http/Home/Controllers/OrderController.php b/app/Http/Home/Controllers/OrderController.php index 70a74c56..98310103 100644 --- a/app/Http/Home/Controllers/OrderController.php +++ b/app/Http/Home/Controllers/OrderController.php @@ -45,6 +45,14 @@ class OrderController extends Controller $order = $service->handle($sn); + if ($order['deleted'] == 1) { + $this->notFound(); + } + + if ($order['me']['owned'] == 0) { + $this->forbidden(); + } + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('order', $order); } diff --git a/app/Http/Home/Controllers/PackageController.php b/app/Http/Home/Controllers/PackageController.php index 67e739f1..0baf6299 100644 --- a/app/Http/Home/Controllers/PackageController.php +++ b/app/Http/Home/Controllers/PackageController.php @@ -27,7 +27,7 @@ class PackageController extends Controller $package = $service->handle($id); if ($package['published'] == 0) { - return $this->notFound(); + $this->notFound(); } $this->seo->prependTitle(['套餐', $package['title']]); diff --git a/app/Http/Home/Controllers/PageController.php b/app/Http/Home/Controllers/PageController.php index 286d63fe..5689b2c9 100644 --- a/app/Http/Home/Controllers/PageController.php +++ b/app/Http/Home/Controllers/PageController.php @@ -25,8 +25,12 @@ class PageController extends Controller $page = $service->handle($id); + if ($page['deleted'] == 1) { + $this->notFound(); + } + if ($page['published'] == 0) { - return $this->notFound(); + $this->notFound(); } $featuredCourses = $this->getFeaturedCourses(); diff --git a/app/Http/Home/Controllers/PointGiftController.php b/app/Http/Home/Controllers/PointGiftController.php index 2023605b..f6c50caa 100644 --- a/app/Http/Home/Controllers/PointGiftController.php +++ b/app/Http/Home/Controllers/PointGiftController.php @@ -68,8 +68,12 @@ class PointGiftController extends Controller $gift = $service->handle($id); + if ($gift['deleted'] == 1) { + $this->notFound(); + } + if ($gift['published'] == 0) { - return $this->notFound(); + $this->notFound(); } $hotGifts = $this->getHotGifts(); diff --git a/app/Http/Home/Controllers/QuestionController.php b/app/Http/Home/Controllers/QuestionController.php index a2f406fb..7c92df29 100644 --- a/app/Http/Home/Controllers/QuestionController.php +++ b/app/Http/Home/Controllers/QuestionController.php @@ -102,8 +102,15 @@ class QuestionController extends Controller $question = $service->handle($id); - if ($question['published'] != QuestionModel::PUBLISH_APPROVED) { - return $this->notFound(); + if ($question['deleted'] == 1) { + $this->notFound(); + } + + $approved = $question['published'] == QuestionModel::PUBLISH_APPROVED; + $owned = $question['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); } $this->seo->prependTitle(['问答', $question['title']]); diff --git a/app/Http/Home/Controllers/RefundController.php b/app/Http/Home/Controllers/RefundController.php index 591f579e..ba01b011 100644 --- a/app/Http/Home/Controllers/RefundController.php +++ b/app/Http/Home/Controllers/RefundController.php @@ -63,6 +63,14 @@ class RefundController extends Controller $refund = $service->handle($sn); + if ($refund['deleted'] == 1) { + $this->notFound(); + } + + if ($refund['me']['owned'] == 0) { + $this->forbidden(); + } + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); $this->view->setVar('refund', $refund); } diff --git a/app/Http/Home/Controllers/ReviewController.php b/app/Http/Home/Controllers/ReviewController.php index 5b3db66c..2b6ab9f6 100644 --- a/app/Http/Home/Controllers/ReviewController.php +++ b/app/Http/Home/Controllers/ReviewController.php @@ -7,6 +7,7 @@ namespace App\Http\Home\Controllers; +use App\Models\Review as ReviewModel; use App\Services\Logic\Review\ReviewCreate as ReviewCreateService; use App\Services\Logic\Review\ReviewDelete as ReviewDeleteService; use App\Services\Logic\Review\ReviewInfo as ReviewInfoService; @@ -50,6 +51,17 @@ class ReviewController extends Controller $review = $service->handle($id); + if ($review['deleted'] == 1) { + $this->notFound(); + } + + $approved = $review['published'] == ReviewModel::PUBLISH_APPROVED; + $owned = $review['me']['owned'] == 1; + + if (!$approved && !$owned) { + $this->notFound(); + } + return $this->jsonSuccess(['review' => $review]); } diff --git a/app/Http/Home/Controllers/TopicController.php b/app/Http/Home/Controllers/TopicController.php index c6098c64..33ff9ad7 100644 --- a/app/Http/Home/Controllers/TopicController.php +++ b/app/Http/Home/Controllers/TopicController.php @@ -27,7 +27,7 @@ class TopicController extends Controller $topic = $service->handle($id); if ($topic['published'] == 0) { - return $this->notFound(); + $this->notFound(); } $this->seo->prependTitle(['专题', $topic['title']]); diff --git a/app/Http/Home/Controllers/UserController.php b/app/Http/Home/Controllers/UserController.php index 80a09280..6870b2db 100644 --- a/app/Http/Home/Controllers/UserController.php +++ b/app/Http/Home/Controllers/UserController.php @@ -32,7 +32,7 @@ class UserController extends Controller $user = $service->handle($id); if ($user['deleted'] == 1) { - return $this->notFound(); + $this->notFound(); } $this->seo->prependTitle(['空间', $user['name']]); diff --git a/app/Http/Home/Views/refund/info.volt b/app/Http/Home/Views/refund/info.volt index d2365231..400c00c5 100644 --- a/app/Http/Home/Views/refund/info.volt +++ b/app/Http/Home/Views/refund/info.volt @@ -21,7 +21,7 @@
- {% if refund.status == 3 %} + {% if refund.me.allow_cancel == 1 %} {% endif %}
diff --git a/app/Models/Category.php b/app/Models/Category.php index b3f125c4..8b182ef5 100644 --- a/app/Models/Category.php +++ b/app/Models/Category.php @@ -144,10 +144,6 @@ class Category extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Chapter.php b/app/Models/Chapter.php index 870c4a7d..4cbfaac0 100644 --- a/app/Models/Chapter.php +++ b/app/Models/Chapter.php @@ -253,10 +253,6 @@ class Chapter extends Model $this->attrs = kg_json_encode($this->attrs); } - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Consult.php b/app/Models/Consult.php index 2281e6a5..469cb8eb 100644 --- a/app/Models/Consult.php +++ b/app/Models/Consult.php @@ -183,10 +183,6 @@ class Consult extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Course.php b/app/Models/Course.php index 72ee81a6..957451f1 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -342,10 +342,6 @@ class Course extends Model $this->attrs = kg_json_encode($this->attrs); } - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Danmu.php b/app/Models/Danmu.php index 76449a17..7e0e0bb1 100644 --- a/app/Models/Danmu.php +++ b/app/Models/Danmu.php @@ -149,10 +149,6 @@ class Danmu extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/FlashSale.php b/app/Models/FlashSale.php index b43cd117..e82eeab0 100644 --- a/app/Models/FlashSale.php +++ b/app/Models/FlashSale.php @@ -135,10 +135,6 @@ class FlashSale extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Help.php b/app/Models/Help.php index a9c2f574..75226fde 100644 --- a/app/Models/Help.php +++ b/app/Models/Help.php @@ -100,10 +100,6 @@ class Help extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/ImGroup.php b/app/Models/ImGroup.php index cac13b16..f9aeab4a 100644 --- a/app/Models/ImGroup.php +++ b/app/Models/ImGroup.php @@ -142,10 +142,6 @@ class ImGroup extends Model $sync->addItem($this->id); } - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Nav.php b/app/Models/Nav.php index 5041d9d4..34cb6c57 100644 --- a/app/Models/Nav.php +++ b/app/Models/Nav.php @@ -146,10 +146,6 @@ class Nav extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Package.php b/app/Models/Package.php index c609d8a7..0432529d 100644 --- a/app/Models/Package.php +++ b/app/Models/Package.php @@ -115,10 +115,6 @@ class Package extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Page.php b/app/Models/Page.php index eff9ad4c..4318e8f8 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -93,10 +93,6 @@ class Page extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/PointGift.php b/app/Models/PointGift.php index 19a27098..7efcce29 100644 --- a/app/Models/PointGift.php +++ b/app/Models/PointGift.php @@ -180,10 +180,6 @@ class PointGift extends Model $this->attrs = kg_json_encode($this->attrs); } - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Review.php b/app/Models/Review.php index 46c30a9f..57564009 100644 --- a/app/Models/Review.php +++ b/app/Models/Review.php @@ -169,10 +169,6 @@ class Review extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Slide.php b/app/Models/Slide.php index cf8f703e..b7dffd17 100644 --- a/app/Models/Slide.php +++ b/app/Models/Slide.php @@ -135,10 +135,6 @@ class Slide extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index bbcc6a7f..c33d8b56 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -143,10 +143,6 @@ class Tag extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/Topic.php b/app/Models/Topic.php index 114afed6..8b672d1f 100644 --- a/app/Models/Topic.php +++ b/app/Models/Topic.php @@ -93,10 +93,6 @@ class Topic extends Model public function beforeUpdate() { - if ($this->deleted == 1) { - $this->published = 0; - } - $this->update_time = time(); } diff --git a/app/Models/WeChatSubscribe.php b/app/Models/WeChatSubscribe.php index ae51cc9a..b6b0234a 100644 --- a/app/Models/WeChatSubscribe.php +++ b/app/Models/WeChatSubscribe.php @@ -31,6 +31,13 @@ class WeChatSubscribe extends Model */ public $open_id = ''; + /** + * 删除标识 + * + * @var int + */ + public $deleted = 0; + /** * 创建时间 * diff --git a/app/Repos/Comment.php b/app/Repos/Comment.php index d70b31d9..aaec7d90 100644 --- a/app/Repos/Comment.php +++ b/app/Repos/Comment.php @@ -103,7 +103,10 @@ class Comment extends Repository public function countComments() { - return (int)CommentModel::count(['conditions' => 'deleted = 0']); + return (int)CommentModel::count([ + 'conditions' => 'published = :published: AND deleted = 0', + 'bind' => ['published' => CommentModel::PUBLISH_APPROVED], + ]); } } diff --git a/app/Repos/Consult.php b/app/Repos/Consult.php index 45f71fb6..6ceb5fac 100644 --- a/app/Repos/Consult.php +++ b/app/Repos/Consult.php @@ -118,7 +118,10 @@ class Consult extends Repository public function countConsults() { - return (int)ConsultModel::count(['conditions' => 'deleted = 0']); + return (int)ConsultModel::count([ + 'conditions' => 'published = :published: AND deleted = 0', + 'bind' => ['published' => ConsultModel::PUBLISH_APPROVED], + ]); } public function countLikes($consultId) diff --git a/app/Repos/ImGroup.php b/app/Repos/ImGroup.php index b0985645..d3ef2b96 100644 --- a/app/Repos/ImGroup.php +++ b/app/Repos/ImGroup.php @@ -128,7 +128,9 @@ class ImGroup extends Repository public function countGroups() { - return (int)ImGroupModel::count(['conditions' => 'published = 1']); + return (int)ImGroupModel::count([ + 'conditions' => 'published = 1 AND deleted = 0', + ]); } public function countUsers($groupId) diff --git a/app/Repos/Package.php b/app/Repos/Package.php index 81105f63..cac9bf52 100644 --- a/app/Repos/Package.php +++ b/app/Repos/Package.php @@ -111,13 +111,16 @@ class Package extends Repository ->join(CoursePackageModel::class, 'c.id = cp.course_id', 'cp') ->where('cp.package_id = :package_id:', ['package_id' => $packageId]) ->andWhere('c.published = 1') + ->andWhere('c.deleted = 0') ->getQuery() ->execute(); } public function countPackages() { - return (int)PackageModel::count(['conditions' => 'deleted = 0']); + return (int)PackageModel::count([ + 'conditions' => 'published = 1 AND deleted = 0', + ]); } public function countCourses($packageId) diff --git a/app/Repos/Review.php b/app/Repos/Review.php index 49aee2d4..3abc4e53 100644 --- a/app/Repos/Review.php +++ b/app/Repos/Review.php @@ -116,7 +116,10 @@ class Review extends Repository public function countReviews() { - return (int)ReviewModel::count(['conditions' => 'deleted = 0']); + return (int)ReviewModel::count([ + 'conditions' => 'published = :published: AND deleted = 0', + 'bind' => ['published' => ReviewModel::PUBLISH_APPROVED], + ]); } public function countLikes($reviewId) diff --git a/app/Repos/Topic.php b/app/Repos/Topic.php index 771768cf..c6e80a91 100644 --- a/app/Repos/Topic.php +++ b/app/Repos/Topic.php @@ -96,12 +96,15 @@ class Topic extends Repository ->join(CourseTopicModel::class, 'c.id = ct.course_id', 'ct') ->where('ct.topic_id = :topic_id:', ['topic_id' => $topicId]) ->andWhere('c.published = 1') + ->andWhere('c.deleted = 0') ->getQuery()->execute(); } public function countTopics() { - return (int)TopicModel::count(['conditions' => 'deleted = 0']); + return (int)TopicModel::count([ + 'conditions' => 'published = 1 AND deleted = 0', + ]); } public function countCourses($topicId) diff --git a/app/Repos/User.php b/app/Repos/User.php index 2858e4e8..917c18ff 100644 --- a/app/Repos/User.php +++ b/app/Repos/User.php @@ -102,6 +102,19 @@ class User extends Repository ]); } + /** + * @param int $id + * @return UserModel|Model|bool + */ + public function findShallowUserById($id) + { + return UserModel::findFirst([ + 'conditions' => 'id = :id:', + 'columns' => ['id', 'name', 'avatar', 'vip', 'title', 'about'], + 'bind' => ['id' => $id], + ]); + } + /** * @param array $ids * @param array|string $columns @@ -115,6 +128,18 @@ class User extends Repository ->execute(); } + /** + * @param array $ids + * @return ResultsetInterface|Resultset|UserModel[] + */ + public function findShallowUserByIds($ids) + { + return UserModel::query() + ->columns(['id', 'name', 'avatar', 'vip', 'title', 'about']) + ->inWhere('id', $ids) + ->execute(); + } + /** * @param int $userId * @return UserBalanceModel|Model @@ -163,12 +188,16 @@ class User extends Repository public function countUsers() { - return (int)UserModel::count(); + return (int)UserModel::count([ + 'conditions' => 'deleted = 0', + ]); } public function countVipUsers() { - return (int)UserModel::count(['conditions' => 'vip = 1']); + return (int)UserModel::count([ + 'conditions' => 'vip = 1 AND deleted = 0', + ]); } public function countCourses($userId) diff --git a/app/Services/Logic/Answer/AnswerInfo.php b/app/Services/Logic/Answer/AnswerInfo.php index 98e52b24..959ea1a3 100644 --- a/app/Services/Logic/Answer/AnswerInfo.php +++ b/app/Services/Logic/Answer/AnswerInfo.php @@ -11,14 +11,15 @@ use App\Models\Answer as AnswerModel; use App\Models\User as UserModel; use App\Repos\AnswerLike as AnswerLikeRepo; use App\Repos\Question as QuestionRepo; -use App\Repos\User as UserRepo; use App\Services\Logic\AnswerTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class AnswerInfo extends LogicService { use AnswerTrait; + use UserTrait; public function handle($id) { @@ -31,11 +32,15 @@ class AnswerInfo extends LogicService protected function handleAnswer(AnswerModel $answer, UserModel $user) { - $answer->content = kg_parse_markdown($answer->content); + $content = kg_parse_markdown($answer->content); - $result = [ + $question = $this->handleQuestionInfo($answer->question_id); + $owner = $this->handleShallowUserInfo($answer->owner_id); + $me = $this->handleMeInfo($answer, $user); + + return [ 'id' => $answer->id, - 'content' => $answer->content, + 'content' => $content, 'anonymous' => $answer->anonymous, 'accepted' => $answer->accepted, 'published' => $answer->published, @@ -44,20 +49,17 @@ class AnswerInfo extends LogicService 'like_count' => $answer->like_count, 'create_time' => $answer->create_time, 'update_time' => $answer->update_time, + 'question' => $question, + 'owner' => $owner, + 'me' => $me, ]; - - $result['question'] = $this->handleQuestionInfo($answer); - $result['owner'] = $this->handleOwnerInfo($answer); - $result['me'] = $this->handleMeInfo($answer, $user); - - return $result; } - protected function handleQuestionInfo(AnswerModel $answer) + protected function handleQuestionInfo($questionId) { $questionRepo = new QuestionRepo(); - $question = $questionRepo->findById($answer->question_id); + $question = $questionRepo->findById($questionId); return [ 'id' => $question->id, @@ -65,19 +67,6 @@ class AnswerInfo extends LogicService ]; } - protected function handleOwnerInfo(AnswerModel $answer) - { - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($answer->owner_id); - - return [ - 'id' => $owner->id, - 'name' => $owner->name, - 'avatar' => $owner->avatar, - ]; - } - protected function handleMeInfo(AnswerModel $answer, UserModel $user) { $me = [ @@ -85,10 +74,7 @@ class AnswerInfo extends LogicService 'owned' => 0, ]; - $isOwner = $user->id == $answer->owner_id; - $approved = $answer->published = AnswerModel::PUBLISH_APPROVED; - - if ($isOwner || $approved) { + if ($user->id == $answer->owner_id) { $me['owned'] = 1; } diff --git a/app/Services/Logic/Article/ArticleInfo.php b/app/Services/Logic/Article/ArticleInfo.php index 3bd32656..dfe8fdf8 100644 --- a/app/Services/Logic/Article/ArticleInfo.php +++ b/app/Services/Logic/Article/ArticleInfo.php @@ -8,7 +8,6 @@ namespace App\Services\Logic\Article; use App\Caches\Category as CategoryCache; -use App\Caches\User as UserCache; use App\Models\Article as ArticleModel; use App\Models\Category as CategoryModel; use App\Models\User as UserModel; @@ -16,11 +15,13 @@ use App\Repos\ArticleFavorite as ArticleFavoriteRepo; use App\Repos\ArticleLike as ArticleLikeRepo; use App\Services\Logic\ArticleTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class ArticleInfo extends LogicService { use ArticleTrait; + use UserTrait; public function handle($id) { @@ -41,8 +42,8 @@ class ArticleInfo extends LogicService { $content = kg_parse_markdown($article->content); - $category = $this->handleCategoryInfo($article); - $owner = $this->handleOwnerInfo($article); + $category = $this->handleCategoryInfo($article->category_id); + $owner = $this->handleShallowUserInfo($article->owner_id); $me = $this->handleMeInfo($article, $user); return [ @@ -71,6 +72,23 @@ class ArticleInfo extends LogicService ]; } + protected function handleCategoryInfo($categoryId) + { + $cache = new CategoryCache(); + + /** + * @var CategoryModel $category + */ + $category = $cache->get($categoryId); + + if (!$category) return new \stdClass(); + + return [ + 'id' => $category->id, + 'name' => $category->name, + ]; + } + protected function handleMeInfo(ArticleModel $article, UserModel $user) { $me = [ @@ -79,14 +97,8 @@ class ArticleInfo extends LogicService 'owned' => 0, ]; - $isOwner = $user->id == $article->owner_id; - $approved = $article->published == ArticleModel::PUBLISH_APPROVED; - $public = $article->private == 0; - - if ($approved && $public) { + if ($user->id == $article->owner_id) { $me['owned'] = 1; - } else { - $me['owned'] = $isOwner ? 1 : 0; } if ($user->id > 0) { @@ -111,44 +123,6 @@ class ArticleInfo extends LogicService return $me; } - protected function handleCategoryInfo(ArticleModel $article) - { - $cache = new CategoryCache(); - - /** - * @var CategoryModel $category - */ - $category = $cache->get($article->category_id); - - if (!$category) return new \stdClass(); - - return [ - 'id' => $category->id, - 'name' => $category->name, - ]; - } - - protected function handleOwnerInfo(ArticleModel $article) - { - $cache = new UserCache(); - - /** - * @var UserModel $owner - */ - $owner = $cache->get($article->owner_id); - - if (!$owner) return new \stdClass(); - - return [ - 'id' => $owner->id, - 'name' => $owner->name, - 'avatar' => $owner->avatar, - 'title' => $owner->title, - 'about' => $owner->about, - 'vip' => $owner->vip, - ]; - } - protected function incrArticleViewCount(ArticleModel $article) { $article->view_count += 1; diff --git a/app/Services/Logic/Comment/CommentInfo.php b/app/Services/Logic/Comment/CommentInfo.php index 848c305d..b7887b5a 100644 --- a/app/Services/Logic/Comment/CommentInfo.php +++ b/app/Services/Logic/Comment/CommentInfo.php @@ -8,26 +8,32 @@ namespace App\Services\Logic\Comment; use App\Models\Comment as CommentModel; -use App\Repos\User as UserRepo; +use App\Models\User as UserModel; +use App\Repos\AnswerLike as AnswerLikeRepo; use App\Services\Logic\CommentTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class CommentInfo extends LogicService { use CommentTrait; + use UserTrait; public function handle($id) { $comment = $this->checkComment($id); - return $this->handleComment($comment); + $user = $this->getCurrentUser(true); + + return $this->handleComment($comment, $user); } - protected function handleComment(CommentModel $comment) + protected function handleComment(CommentModel $comment, UserModel $user) { - $owner = $comment->owner_id > 0 ? $this->handleOwnerInfo($comment) : new \stdClass(); - $toUser = $comment->to_user_id > 0 ? $this->handleToUserInfo($comment) : new \stdClass(); + $toUser = $this->handleShallowUserInfo($comment->to_user_id); + $owner = $this->handleShallowUserInfo($comment->owner_id); + $me = $this->handleMeInfo($comment, $user); return [ 'id' => $comment->id, @@ -39,35 +45,35 @@ class CommentInfo extends LogicService 'reply_count' => $comment->reply_count, 'create_time' => $comment->create_time, 'update_time' => $comment->update_time, - 'owner' => $owner, 'to_user' => $toUser, + 'owner' => $owner, + 'me' => $me, ]; } - protected function handleOwnerInfo(CommentModel $comment) + protected function handleMeInfo(CommentModel $comment, UserModel $user) { - $userRepo = new UserRepo(); - - $user = $userRepo->findById($comment->owner_id); - - return [ - 'id' => $user->id, - 'name' => $user->name, - 'avatar' => $user->avatar, + $me = [ + 'liked' => 0, + 'owned' => 0, ]; - } - protected function handleToUserInfo(CommentModel $comment) - { - $userRepo = new UserRepo(); + if ($user->id == $comment->owner_id) { + $me['owned'] = 1; + } - $user = $userRepo->findById($comment->to_user_id); + if ($user->id > 0) { - return [ - 'id' => $user->id, - 'name' => $user->name, - 'avatar' => $user->avatar, - ]; + $likeRepo = new AnswerLikeRepo(); + + $like = $likeRepo->findAnswerLike($comment->id, $user->id); + + if ($like && $like->deleted == 0) { + $me['liked'] = 1; + } + } + + return $me; } } diff --git a/app/Services/Logic/Consult/ConsultInfo.php b/app/Services/Logic/Consult/ConsultInfo.php index 15dc4e0f..cae47fc1 100644 --- a/app/Services/Logic/Consult/ConsultInfo.php +++ b/app/Services/Logic/Consult/ConsultInfo.php @@ -8,30 +8,41 @@ namespace App\Services\Logic\Consult; use App\Models\Consult as ConsultModel; +use App\Models\User as UserModel; use App\Repos\Chapter as ChapterRepo; +use App\Repos\ConsultLike as ConsultLikeRepo; use App\Repos\Course as CourseRepo; -use App\Repos\User as UserRepo; use App\Services\Logic\ConsultTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class ConsultInfo extends LogicService { use ConsultTrait; + use UserTrait; public function handle($id) { $consult = $this->checkConsult($id); - return $this->handleConsult($consult); + $user = $this->getCurrentUser(true); + + return $this->handleConsult($consult, $user); } - protected function handleConsult(ConsultModel $consult) + protected function handleConsult(ConsultModel $consult, UserModel $user) { - $result = [ + $course = $this->handleCourseInfo($consult->course_id); + $chapter = $this->handleChapterInfo($consult->chapter_id); + $replier = $this->handleShallowUserInfo($consult->replier_id); + $owner = $this->handleShallowUserInfo($consult->owner_id); + $me = $this->handleMeInfo($consult, $user); + + return [ 'id' => $consult->id, 'question' => $consult->question, - 'answer' => $consult->answer, + 'consult' => $consult->consult, 'rating' => $consult->rating, 'private' => $consult->private, 'published' => $consult->published, @@ -39,21 +50,19 @@ class ConsultInfo extends LogicService 'like_count' => $consult->like_count, 'create_time' => $consult->create_time, 'update_time' => $consult->update_time, + 'course' => $course, + 'chapter' => $chapter, + 'replier' => $replier, + 'owner' => $owner, + 'me' => $me, ]; - - $result['course'] = $this->handleCourseInfo($consult); - $result['chapter'] = $this->handleChapterInfo($consult); - $result['owner'] = $this->handleOwnerInfo($consult); - $result['replier'] = $this->handleReplierInfo($consult); - - return $result; } - protected function handleCourseInfo(ConsultModel $consult) + protected function handleCourseInfo($courseId) { $courseRepo = new CourseRepo(); - $course = $courseRepo->findById($consult->course_id); + $course = $courseRepo->findById($courseId); if (!$course) return new \stdClass(); @@ -64,11 +73,11 @@ class ConsultInfo extends LogicService ]; } - protected function handleChapterInfo(ConsultModel $consult) + protected function handleChapterInfo($chapterId) { $chapterRepo = new ChapterRepo(); - $chapter = $chapterRepo->findById($consult->chapter_id); + $chapter = $chapterRepo->findById($chapterId); if (!$chapter) return new \stdClass(); @@ -78,34 +87,29 @@ class ConsultInfo extends LogicService ]; } - protected function handleOwnerInfo(ConsultModel $consult) + protected function handleMeInfo(ConsultModel $consult, UserModel $user) { - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($consult->owner_id); - - if (!$owner) return new \stdClass(); - - return [ - 'id' => $owner->id, - 'name' => $owner->name, - 'avatar' => $owner->avatar, + $me = [ + 'liked' => 0, + 'owned' => 0, ]; - } - protected function handleReplierInfo(ConsultModel $consult) - { - $userRepo = new UserRepo(); + if ($user->id == $consult->owner_id) { + $me['owned'] = 1; + } - $replier = $userRepo->findById($consult->replier_id); + if ($user->id > 0) { - if (!$replier) return new \stdClass(); + $likeRepo = new ConsultLikeRepo(); - return [ - 'id' => $replier->id, - 'name' => $replier->name, - 'avatar' => $replier->avatar, - ]; + $like = $likeRepo->findConsultLike($consult->id, $user->id); + + if ($like && $like->deleted == 0) { + $me['liked'] = 1; + } + } + + return $me; } } diff --git a/app/Services/Logic/Danmu/DanmuInfo.php b/app/Services/Logic/Danmu/DanmuInfo.php index 54ec09a4..9095e23a 100644 --- a/app/Services/Logic/Danmu/DanmuInfo.php +++ b/app/Services/Logic/Danmu/DanmuInfo.php @@ -8,14 +8,15 @@ namespace App\Services\Logic\Danmu; use App\Models\Danmu as DanmuModel; -use App\Repos\User as UserRepo; use App\Services\Logic\DanmuTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class DanmuInfo extends LogicService { use DanmuTrait; + use UserTrait; public function handle($id) { @@ -26,26 +27,17 @@ class DanmuInfo extends LogicService protected function handleDanmu(DanmuModel $danmu) { - $result = [ + $owner = $this->handleShallowUserInfo($danmu->owner_id); + + return [ 'id' => $danmu->id, 'text' => $danmu->text, 'color' => $danmu->color, 'size' => $danmu->size, 'position' => $danmu->position, 'time' => $danmu->time, + 'owner' => $owner, ]; - - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($danmu->user_id); - - $result['owner'] = [ - 'id' => $owner->id, - 'name' => $owner->name, - 'avatar' => $owner->avatar, - ]; - - return $result; } } diff --git a/app/Services/Logic/Order/OrderInfo.php b/app/Services/Logic/Order/OrderInfo.php index 6e63de78..60d59789 100644 --- a/app/Services/Logic/Order/OrderInfo.php +++ b/app/Services/Logic/Order/OrderInfo.php @@ -9,37 +9,38 @@ namespace App\Services\Logic\Order; use App\Models\Course as CourseModel; use App\Models\Order as OrderModel; +use App\Models\User as UserModel; use App\Repos\Order as OrderRepo; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; use App\Validators\Order as OrderValidator; class OrderInfo extends LogicService { + use UserTrait; + public function handle($sn) { $validator = new OrderValidator(); $order = $validator->checkOrderBySn($sn); - return $this->handleOrder($order); + $user = $this->getLoginUser(); + + return $this->handleOrder($order, $user); } - protected function handleOrder(OrderModel $order) + protected function handleOrder(OrderModel $order, UserModel $user) { $order->item_info = $this->handleItemInfo($order); - $statusHistory = $this->handleStatusHistory($order->id); - - $me = $this->handleMeInfo($order); - - return [ - 'me' => $me, + $result = [ 'sn' => $order->sn, 'subject' => $order->subject, 'amount' => $order->amount, 'status' => $order->status, - 'status_history' => $statusHistory, + 'deleted' => $order->deleted, 'item_id' => $order->item_id, 'item_type' => $order->item_type, 'item_info' => $order->item_info, @@ -49,6 +50,12 @@ class OrderInfo extends LogicService 'create_time' => $order->create_time, 'update_time' => $order->update_time, ]; + + $result['status_history'] = $this->handleStatusHistory($order->id); + $result['owner'] = $this->handleShallowUserInfo($order->owner_id); + $result['me'] = $this->handleMeInfo($order, $user); + + return $result; } protected function handleStatusHistory($orderId) @@ -71,14 +78,19 @@ class OrderInfo extends LogicService return $result; } - protected function handleMeInfo(OrderModel $order) + protected function handleMeInfo(OrderModel $order, UserModel $user) { $result = [ + 'owned' => 0, 'allow_pay' => 0, 'allow_cancel' => 0, 'allow_refund' => 0, ]; + if ($user->id == $order->owner_id) { + $result['owned'] = 1; + } + if ($order->status == OrderModel::STATUS_PENDING) { $result['allow_pay'] = 1; $result['allow_cancel'] = 1; diff --git a/app/Services/Logic/Question/AnswerList.php b/app/Services/Logic/Question/AnswerList.php index 71a79a3d..7e614348 100644 --- a/app/Services/Logic/Question/AnswerList.php +++ b/app/Services/Logic/Question/AnswerList.php @@ -9,7 +9,7 @@ namespace App\Services\Logic\Question; use App\Builders\AnswerList as AnswerListBuilder; use App\Library\Paginator\Query as PagerQuery; -use App\Models\Question as QuestionModel; +use App\Models\Answer as AnswerModel; use App\Repos\Answer as AnswerRepo; use App\Repos\AnswerLike as AnswerLikeRepo; use App\Services\Logic\QuestionTrait; @@ -29,7 +29,7 @@ class AnswerList extends LogicService $params = $pagerQuery->getParams(); $params['question_id'] = $question->id; - $params['published'] = QuestionModel::PUBLISH_APPROVED; + $params['published'] = AnswerModel::PUBLISH_APPROVED; $params['deleted'] = 0; $sort = $pagerQuery->getSort(); @@ -63,7 +63,8 @@ class AnswerList extends LogicService $answer['content'] = kg_parse_markdown($answer['content']); - $owner = $users[$answer['owner_id']] ?? new \stdClass(); + $owner = $users[$answer['owner_id']]; + $me = $meMappings[$answer['id']]; $items[] = [ diff --git a/app/Services/Logic/Question/QuestionInfo.php b/app/Services/Logic/Question/QuestionInfo.php index 07c8ba47..37ea2e06 100644 --- a/app/Services/Logic/Question/QuestionInfo.php +++ b/app/Services/Logic/Question/QuestionInfo.php @@ -14,14 +14,15 @@ use App\Models\User as UserModel; use App\Repos\Question as QuestionRepo; use App\Repos\QuestionFavorite as QuestionFavoriteRepo; use App\Repos\QuestionLike as QuestionLikeRepo; -use App\Repos\User as UserRepo; use App\Services\Logic\QuestionTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class QuestionInfo extends LogicService { use QuestionTrait; + use UserTrait; public function handle($id) { @@ -42,9 +43,9 @@ class QuestionInfo extends LogicService { $content = kg_parse_markdown($question->content); - $lastReplier = $this->handleUserInfo($question->last_replier_id); - $category = $this->handleCategoryInfo($question); - $owner = $this->handleUserInfo($question->owner_id); + $lastReplier = $this->handleShallowUserInfo($question->last_replier_id); + $category = $this->handleCategoryInfo($question->category_id); + $owner = $this->handleShallowUserInfo($question->owner_id); $me = $this->handleMeInfo($question, $user); return [ @@ -74,14 +75,14 @@ class QuestionInfo extends LogicService ]; } - protected function handleCategoryInfo(QuestionModel $question) + protected function handleCategoryInfo($categoryId) { $cache = new CategoryCache(); /** * @var CategoryModel $category */ - $category = $cache->get($question->category_id); + $category = $cache->get($categoryId); if (!$category) return new \stdClass(); @@ -138,24 +139,6 @@ class QuestionInfo extends LogicService return $me; } - protected function handleUserInfo($userId) - { - $userRepo = new UserRepo(); - - $user = $userRepo->findById($userId); - - if (!$user) return new \stdClass(); - - return [ - 'id' => $user->id, - 'name' => $user->name, - 'avatar' => $user->avatar, - 'title' => $user->title, - 'about' => $user->about, - 'vip' => $user->vip, - ]; - } - protected function incrQuestionViewCount(QuestionModel $question) { $question->view_count += 1; diff --git a/app/Services/Logic/Refund/RefundInfo.php b/app/Services/Logic/Refund/RefundInfo.php index d1343b69..f5f3c7cb 100644 --- a/app/Services/Logic/Refund/RefundInfo.php +++ b/app/Services/Logic/Refund/RefundInfo.php @@ -8,38 +8,49 @@ namespace App\Services\Logic\Refund; use App\Models\Refund as RefundModel; +use App\Models\User as UserModel; use App\Repos\Order as OrderRepo; use App\Repos\Refund as RefundRepo; use App\Services\Logic\RefundTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class RefundInfo extends LogicService { use RefundTrait; + use UserTrait; public function handle($sn) { $refund = $this->checkRefundBySn($sn); - return $this->handleRefund($refund); + $user = $this->getLoginUser(); + + return $this->handleRefund($refund, $user); } - protected function handleRefund(RefundModel $refund) + protected function handleRefund(RefundModel $refund, UserModel $user) { - $order = $this->handleOrderInfo($refund->order_id); - $statusHistory = $this->handleStatusHistory($refund->id); + $order = $this->handleOrderInfo($refund->order_id); + $owner = $this->handleShallowUserInfo($refund->owner_id); + $me = $this->handleMeInfo($refund, $user); return [ - 'order' => $order, 'sn' => $refund->sn, 'subject' => $refund->subject, 'amount' => $refund->amount, 'status' => $refund->status, - 'status_history' => $statusHistory, + 'deleted' => $refund->deleted, 'apply_note' => $refund->apply_note, 'review_note' => $refund->review_note, + 'create_time' => $refund->create_time, + 'update_time' => $refund->update_time, + 'status_history' => $statusHistory, + 'order' => $order, + 'owner' => $owner, + 'me' => $me, ]; } @@ -79,4 +90,27 @@ class RefundInfo extends LogicService return $result; } + protected function handleMeInfo(RefundModel $refund, UserModel $user) + { + $result = [ + 'owned' => 0, + 'allow_cancel' => 0, + ]; + + if ($user->id == $refund->owner_id) { + $result['owned'] = 1; + } + + $statusTypes = [ + RefundModel::STATUS_PENDING, + RefundModel::STATUS_APPROVED, + ]; + + if (in_array($refund->status, $statusTypes)) { + $result['allow_cancel'] = 1; + } + + return $result; + } + } diff --git a/app/Services/Logic/Review/ReviewInfo.php b/app/Services/Logic/Review/ReviewInfo.php index 08f717aa..7a2ac9c9 100644 --- a/app/Services/Logic/Review/ReviewInfo.php +++ b/app/Services/Logic/Review/ReviewInfo.php @@ -8,26 +8,35 @@ namespace App\Services\Logic\Review; use App\Models\Review as ReviewModel; +use App\Models\User as UserModel; use App\Repos\Course as CourseRepo; -use App\Repos\User as UserRepo; +use App\Repos\ReviewLike as ReviewLikeRepo; use App\Services\Logic\ReviewTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\UserTrait; class ReviewInfo extends LogicService { use ReviewTrait; + use UserTrait; public function handle($id) { $review = $this->checkReview($id); - return $this->handleReview($review); + $user = $this->getCurrentUser(); + + return $this->handleReview($review, $user); } - protected function handleReview(ReviewModel $review) + protected function handleReview(ReviewModel $review, UserModel $user) { - $result = [ + $course = $this->handleCourseInfo($review->course_id); + $owner = $this->handleShallowUserInfo($review->owner_id); + $me = $this->handleMeInfo($review, $user); + + return [ 'id' => $review->id, 'content' => $review->content, 'reply' => $review->reply, @@ -40,19 +49,17 @@ class ReviewInfo extends LogicService 'like_count' => $review->like_count, 'create_time' => $review->create_time, 'update_time' => $review->update_time, + 'course' => $course, + 'owner' => $owner, + 'me' => $me, ]; - - $result['course'] = $this->handleCourseInfo($review); - $result['owner'] = $this->handleOwnerInfo($review); - - return $result; } - protected function handleCourseInfo(ReviewModel $review) + protected function handleCourseInfo($courseId) { $courseRepo = new CourseRepo(); - $course = $courseRepo->findById($review->course_id); + $course = $courseRepo->findById($courseId); if (!$course) return new \stdClass(); @@ -63,19 +70,29 @@ class ReviewInfo extends LogicService ]; } - protected function handleOwnerInfo(ReviewModel $review) + protected function handleMeInfo(ReviewModel $review, UserModel $user) { - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($review->owner_id); - - if (!$owner) return new \stdClass(); - - return [ - 'id' => $owner->id, - 'name' => $owner->name, - 'avatar' => $owner->avatar, + $me = [ + 'liked' => 0, + 'owned' => 0, ]; + + if ($user->id == $review->owner_id) { + $me['owned'] = 1; + } + + if ($user->id > 0) { + + $likeRepo = new ReviewLikeRepo(); + + $like = $likeRepo->findReviewLike($review->id, $user->id); + + if ($like && $like->deleted == 0) { + $me['liked'] = 1; + } + } + + return $me; } } diff --git a/app/Services/Logic/Trade/TradeInfo.php b/app/Services/Logic/Trade/TradeInfo.php index 873ae91f..d6dc3986 100644 --- a/app/Services/Logic/Trade/TradeInfo.php +++ b/app/Services/Logic/Trade/TradeInfo.php @@ -8,31 +8,101 @@ namespace App\Services\Logic\Trade; use App\Models\Trade as TradeModel; +use App\Models\User as UserModel; +use App\Repos\Order as OrderRepo; +use App\Repos\Trade as TradeRepo; use App\Services\Logic\Service as LogicService; use App\Services\Logic\TradeTrait; +use App\Services\Logic\UserTrait; class TradeInfo extends LogicService { use TradeTrait; + use UserTrait; public function handle($sn) { $trade = $this->checkTradeBySn($sn); - return $this->handleTrade($trade); + $user = $this->getCurrentUser(true); + + return $this->handleTrade($trade, $user); } - protected function handleTrade(TradeModel $trade) + protected function handleTrade(TradeModel $trade, UserModel $user) { + $statusHistory = $this->handleStatusHistory($trade->id); + $owner = $this->handleShallowUserInfo($trade->owner_id); + $me = $this->handleMeInfo($trade, $user); + return [ 'sn' => $trade->sn, 'subject' => $trade->subject, 'amount' => $trade->amount, 'channel' => $trade->channel, 'status' => $trade->status, + 'deleted' => $trade->deleted, 'create_time' => $trade->create_time, + 'update_time' => $trade->update_time, + 'status_history' => $statusHistory, + 'owner' => $owner, + 'me' => $me, ]; } + protected function handleOrderInfo($orderId) + { + $orderRepo = new OrderRepo(); + + $order = $orderRepo->findById($orderId); + + return [ + 'id' => $order->id, + 'sn' => $order->sn, + 'subject' => $order->subject, + 'amount' => $order->amount, + ]; + } + + protected function handleStatusHistory($tradeId) + { + $tradeRepo = new TradeRepo(); + + $records = $tradeRepo->findStatusHistory($tradeId); + + if ($records->count() == 0) { + return []; + } + + $result = []; + + foreach ($records as $record) { + $result[] = [ + 'status' => $record->status, + 'create_time' => $record->create_time, + ]; + } + + return $result; + } + + protected function handleMeInfo(TradeModel $trade, UserModel $user) + { + $result = [ + 'owned' => 0, + 'allow_cancel' => 0, + ]; + + if ($user->id == $trade->owner_id) { + $result['owned'] = 1; + } + + if ($trade->status == TradeModel::STATUS_PENDING) { + $result['allow_cancel'] = 1; + } + + return $result; + } + } diff --git a/app/Services/Logic/UserTrait.php b/app/Services/Logic/UserTrait.php index 6631cd2b..68dbf048 100644 --- a/app/Services/Logic/UserTrait.php +++ b/app/Services/Logic/UserTrait.php @@ -7,6 +7,7 @@ namespace App\Services\Logic; +use App\Repos\User as UserRepo; use App\Validators\User as UserValidator; trait UserTrait @@ -26,4 +27,17 @@ trait UserTrait return $validator->checkUserCache($id); } + public function handleShallowUserInfo($id) + { + $userRepo = new UserRepo(); + + $user = $userRepo->findShallowUserById($id); + + $result = $user->toArray(); + + $result['avatar'] = kg_cos_user_avatar_url($user->avatar); + + return $result; + } + } diff --git a/app/Traits/Response.php b/app/Traits/Response.php index 77f7363c..9ba736c2 100644 --- a/app/Traits/Response.php +++ b/app/Traits/Response.php @@ -7,45 +7,24 @@ namespace App\Traits; +use App\Exceptions\Forbidden as ForbiddenException; +use App\Exceptions\NotFound as NotFoundException; use Phalcon\Config; use Phalcon\Di; use Phalcon\Http\Request as HttpRequest; use Phalcon\Http\Response as HttpResponse; -use Phalcon\Mvc\Dispatcher; trait Response { public function forbidden() { - /** - * @var Dispatcher $dispatcher - */ - $dispatcher = Di::getDefault()->getShared('dispatcher'); - - $dispatcher->forward([ - 'module' => 'home', - 'controller' => 'error', - 'action' => 'show403', - ]); - - return false; + throw new ForbiddenException('sys.forbidden'); } public function notFound() { - /** - * @var Dispatcher $dispatcher - */ - $dispatcher = Di::getDefault()->getShared('dispatcher'); - - $dispatcher->forward([ - 'module' => 'home', - 'controller' => 'error', - 'action' => 'show404', - ]); - - return false; + throw new NotFoundException('sys.not_found'); } public function setCors()