diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fc4f338..4f375381 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,11 @@ +### [v1.7.5](https://gitee.com/koogua/course-tencent-cloud/releases/v1.7.5)(2024-01-10) + +- 去除一些过度的设计 +- 优化bootstrap +- 优化logger +- 优化contact +- 精简空判断 + ### [v1.7.4](https://gitee.com/koogua/course-tencent-cloud/releases/v1.7.4)(2024-12-10) - 更新layui-v2.9.20 diff --git a/app/Builders/AnswerList.php b/app/Builders/AnswerList.php index 0c3b0b99..f12ef425 100644 --- a/app/Builders/AnswerList.php +++ b/app/Builders/AnswerList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Question as QuestionRepo; -use App\Repos\User as UserRepo; class AnswerList extends Builder { @@ -18,7 +17,7 @@ class AnswerList extends Builder $questions = $this->getQuestions($answers); foreach ($answers as $key => $answer) { - $answers[$key]['question'] = $questions[$answer['question_id']] ?? new \stdClass(); + $answers[$key]['question'] = $questions[$answer['question_id']] ?? null; } return $answers; @@ -29,7 +28,7 @@ class AnswerList extends Builder $users = $this->getUsers($answers); foreach ($answers as $key => $answer) { - $answers[$key]['owner'] = $users[$answer['owner_id']] ?? new \stdClass(); + $answers[$key]['owner'] = $users[$answer['owner_id']] ?? null; } return $answers; @@ -56,20 +55,7 @@ class AnswerList extends Builder { $ids = kg_array_column($answers, 'owner_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/ArticleFavoriteList.php b/app/Builders/ArticleFavoriteList.php index 897f0f0e..9b1e03cc 100644 --- a/app/Builders/ArticleFavoriteList.php +++ b/app/Builders/ArticleFavoriteList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Article as ArticleRepo; -use App\Repos\User as UserRepo; use Phalcon\Text; class ArticleFavoriteList extends Builder @@ -19,7 +18,7 @@ class ArticleFavoriteList extends Builder $articles = $this->getArticles($relations); foreach ($relations as $key => $value) { - $relations[$key]['article'] = $articles[$value['article_id']] ?? new \stdClass(); + $relations[$key]['article'] = $articles[$value['article_id']] ?? null; } return $relations; @@ -30,7 +29,7 @@ class ArticleFavoriteList extends Builder $users = $this->getUsers($relations); foreach ($relations as $key => $value) { - $relations[$key]['user'] = $users[$value['user_id']] ?? new \stdClass(); + $relations[$key]['user'] = $users[$value['user_id']] ?? null; } return $relations; @@ -70,20 +69,7 @@ class ArticleFavoriteList extends Builder { $ids = kg_array_column($relations, 'user_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/ArticleList.php b/app/Builders/ArticleList.php index 68a78f5d..7efba66e 100644 --- a/app/Builders/ArticleList.php +++ b/app/Builders/ArticleList.php @@ -9,7 +9,6 @@ namespace App\Builders; use App\Caches\CategoryAllList as CategoryAllListCache; use App\Models\Category as CategoryModel; -use App\Repos\User as UserRepo; class ArticleList extends Builder { @@ -28,7 +27,7 @@ class ArticleList extends Builder $categories = $this->getCategories(); foreach ($articles as $key => $article) { - $articles[$key]['category'] = $categories[$article['category_id']] ?? new \stdClass(); + $articles[$key]['category'] = $categories[$article['category_id']] ?? null; } return $articles; @@ -39,7 +38,7 @@ class ArticleList extends Builder $users = $this->getUsers($articles); foreach ($articles as $key => $article) { - $articles[$key]['owner'] = $users[$article['owner_id']] ?? new \stdClass(); + $articles[$key]['owner'] = $users[$article['owner_id']] ?? null; } return $articles; @@ -69,20 +68,7 @@ class ArticleList extends Builder { $ids = kg_array_column($articles, 'owner_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/Builder.php b/app/Builders/Builder.php index 11c29f62..eecb7f88 100644 --- a/app/Builders/Builder.php +++ b/app/Builders/Builder.php @@ -7,6 +7,7 @@ namespace App\Builders; +use App\Repos\User as UserRepo; use Phalcon\Di\Injectable; class Builder extends Injectable @@ -17,4 +18,22 @@ class Builder extends Injectable return kg_array_object($items); } + protected function getShallowUserByIds(array $ids) + { + $userRepo = new UserRepo(); + + $users = $userRepo->findShallowUserByIds($ids); + + $baseUrl = kg_cos_url(); + + $result = []; + + foreach ($users->toArray() as $user) { + $user['avatar'] = $baseUrl . $user['avatar']; + $result[$user['id']] = $user; + } + + return $result; + } + } diff --git a/app/Builders/CommentList.php b/app/Builders/CommentList.php index e0eb0059..9cbc98d5 100644 --- a/app/Builders/CommentList.php +++ b/app/Builders/CommentList.php @@ -7,8 +7,6 @@ namespace App\Builders; -use App\Repos\User as UserRepo; - class CommentList extends Builder { @@ -17,8 +15,8 @@ class CommentList extends Builder $users = $this->getUsers($comments); foreach ($comments as $key => $comment) { - $comments[$key]['owner'] = $users[$comment['owner_id']] ?? new \stdClass(); - $comments[$key]['to_user'] = $users[$comment['to_user_id']] ?? new \stdClass(); + $comments[$key]['owner'] = $users[$comment['owner_id']] ?? null; + $comments[$key]['to_user'] = $users[$comment['to_user_id']] ?? null; } return $comments; @@ -30,20 +28,7 @@ class CommentList extends Builder $toUserIds = kg_array_column($comments, 'to_user_id'); $ids = array_merge($ownerIds, $toUserIds); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/ConsultList.php b/app/Builders/ConsultList.php index 6427f979..702a1933 100644 --- a/app/Builders/ConsultList.php +++ b/app/Builders/ConsultList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Course as CourseRepo; -use App\Repos\User as UserRepo; class ConsultList extends Builder { @@ -18,7 +17,7 @@ class ConsultList extends Builder $courses = $this->getCourses($consults); foreach ($consults as $key => $consult) { - $consults[$key]['course'] = $courses[$consult['course_id']] ?? new \stdClass(); + $consults[$key]['course'] = $courses[$consult['course_id']] ?? null; } return $consults; @@ -29,8 +28,8 @@ class ConsultList extends Builder $users = $this->getUsers($consults); foreach ($consults as $key => $consult) { - $consults[$key]['owner'] = $users[$consult['owner_id']] ?? new \stdClass(); - $consults[$key]['replier'] = $users[$consult['replier_id']] ?? new \stdClass(); + $consults[$key]['owner'] = $users[$consult['owner_id']] ?? null; + $consults[$key]['replier'] = $users[$consult['replier_id']] ?? null; } return $consults; @@ -59,20 +58,7 @@ class ConsultList extends Builder $replierIds = kg_array_column($consults, 'replier_id'); $ids = array_merge($ownerIds, $replierIds); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/CourseFavoriteList.php b/app/Builders/CourseFavoriteList.php index 4acd5df8..1f3550bc 100644 --- a/app/Builders/CourseFavoriteList.php +++ b/app/Builders/CourseFavoriteList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Course as CourseRepo; -use App\Repos\User as UserRepo; class CourseFavoriteList extends Builder { @@ -18,7 +17,7 @@ class CourseFavoriteList extends Builder $courses = $this->getCourses($relations); foreach ($relations as $key => $value) { - $relations[$key]['course'] = $courses[$value['course_id']] ?? new \stdClass(); + $relations[$key]['course'] = $courses[$value['course_id']] ?? null; } return $relations; @@ -29,7 +28,7 @@ class CourseFavoriteList extends Builder $users = $this->getUsers($relations); foreach ($relations as $key => $value) { - $relations[$key]['user'] = $users[$value['user_id']] ?? new \stdClass(); + $relations[$key]['user'] = $users[$value['user_id']] ?? null; } return $relations; @@ -70,20 +69,7 @@ class CourseFavoriteList extends Builder { $ids = kg_array_column($relations, 'user_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/CourseList.php b/app/Builders/CourseList.php index d0dffdf4..cd0aa53d 100644 --- a/app/Builders/CourseList.php +++ b/app/Builders/CourseList.php @@ -9,7 +9,6 @@ namespace App\Builders; use App\Caches\CategoryAllList as CategoryAllListCache; use App\Models\Category as CategoryModel; -use App\Repos\User as UserRepo; class CourseList extends Builder { @@ -19,7 +18,7 @@ class CourseList extends Builder $categories = $this->getCategories(); foreach ($courses as $key => $course) { - $courses[$key]['category'] = $categories[$course['category_id']] ?? new \stdClass(); + $courses[$key]['category'] = $categories[$course['category_id']] ?? null; } return $courses; @@ -30,7 +29,7 @@ class CourseList extends Builder $teachers = $this->getTeachers($courses); foreach ($courses as $key => $course) { - $courses[$key]['teacher'] = $teachers[$course['teacher_id']] ?? new \stdClass(); + $courses[$key]['teacher'] = $teachers[$course['teacher_id']] ?? null; } return $courses; @@ -60,20 +59,7 @@ class CourseList extends Builder { $ids = kg_array_column($courses, 'teacher_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/CourseTopicList.php b/app/Builders/CourseTopicList.php index 6a7ebf2d..aaa49ca0 100644 --- a/app/Builders/CourseTopicList.php +++ b/app/Builders/CourseTopicList.php @@ -18,7 +18,7 @@ class CourseTopicList extends Builder $courses = $this->getCourses($relations); foreach ($relations as $key => $value) { - $relations[$key]['course'] = $courses[$value['course_id']] ?? new \stdClass(); + $relations[$key]['course'] = $courses[$value['course_id']] ?? null; } return $relations; @@ -29,7 +29,7 @@ class CourseTopicList extends Builder $topics = $this->getTopics($relations); foreach ($relations as $key => $value) { - $relations[$key]['topic'] = $topics[$value['topic_id']] ?? new \stdClass(); + $relations[$key]['topic'] = $topics[$value['topic_id']] ?? null; } return $relations; diff --git a/app/Builders/CourseUserList.php b/app/Builders/CourseUserList.php index ea3a3d09..c8d1051f 100644 --- a/app/Builders/CourseUserList.php +++ b/app/Builders/CourseUserList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Course as CourseRepo; -use App\Repos\User as UserRepo; class CourseUserList extends Builder { @@ -18,7 +17,7 @@ class CourseUserList extends Builder $courses = $this->getCourses($relations); foreach ($relations as $key => $value) { - $relations[$key]['course'] = $courses[$value['course_id']] ?? new \stdClass(); + $relations[$key]['course'] = $courses[$value['course_id']] ?? null; } return $relations; @@ -29,7 +28,7 @@ class CourseUserList extends Builder $users = $this->getUsers($relations); foreach ($relations as $key => $value) { - $relations[$key]['user'] = $users[$value['user_id']] ?? new \stdClass(); + $relations[$key]['user'] = $users[$value['user_id']] ?? null; } return $relations; @@ -74,20 +73,7 @@ class CourseUserList extends Builder { $ids = kg_array_column($relations, 'user_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/HelpList.php b/app/Builders/HelpList.php index bc0ee1c2..6a25be60 100644 --- a/app/Builders/HelpList.php +++ b/app/Builders/HelpList.php @@ -18,7 +18,7 @@ class HelpList extends Builder $categories = $this->getCategories(); foreach ($helps as $key => $help) { - $helps[$key]['category'] = $categories[$help['category_id']] ?? new \stdClass(); + $helps[$key]['category'] = $categories[$help['category_id']] ?? null; } return $helps; diff --git a/app/Builders/LearningList.php b/app/Builders/LearningList.php index a9ce81f6..7c526c8d 100644 --- a/app/Builders/LearningList.php +++ b/app/Builders/LearningList.php @@ -9,7 +9,6 @@ namespace App\Builders; use App\Repos\Chapter as ChapterRepo; use App\Repos\Course as CourseRepo; -use App\Repos\User as UserRepo; class LearningList extends Builder { @@ -19,7 +18,7 @@ class LearningList extends Builder $courses = $this->getCourses($relations); foreach ($relations as $key => $value) { - $relations[$key]['course'] = $courses[$value['course_id']] ?? new \stdClass(); + $relations[$key]['course'] = $courses[$value['course_id']] ?? null; } return $relations; @@ -30,7 +29,7 @@ class LearningList extends Builder $chapters = $this->getChapters($relations); foreach ($relations as $key => $value) { - $relations[$key]['chapter'] = $chapters[$value['chapter_id']] ?? new \stdClass(); + $relations[$key]['chapter'] = $chapters[$value['chapter_id']] ?? null; } return $relations; @@ -41,7 +40,7 @@ class LearningList extends Builder $users = $this->getUsers($relations); foreach ($relations as $key => $value) { - $relations[$key]['user'] = $users[$value['user_id']] ?? new \stdClass(); + $relations[$key]['user'] = $users[$value['user_id']] ?? null; } return $relations; @@ -85,17 +84,7 @@ class LearningList extends Builder { $ids = kg_array_column($relations, 'user_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findByIds($ids, ['id', 'name']); - - $result = []; - - foreach ($users->toArray() as $user) { - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/LiveList.php b/app/Builders/LiveList.php index 8f8102e2..3feda859 100644 --- a/app/Builders/LiveList.php +++ b/app/Builders/LiveList.php @@ -19,7 +19,7 @@ class LiveList extends Builder $courses = $this->getCourses($lives); foreach ($lives as $key => $live) { - $lives[$key]['course'] = $courses[$live['course_id']] ?? new \stdClass(); + $lives[$key]['course'] = $courses[$live['course_id']] ?? null; } return $lives; @@ -30,7 +30,7 @@ class LiveList extends Builder $chapters = $this->getChapters($lives); foreach ($lives as $key => $live) { - $lives[$key]['chapter'] = $chapters[$live['chapter_id']] ?? new \stdClass(); + $lives[$key]['chapter'] = $chapters[$live['chapter_id']] ?? null; } return $lives; @@ -63,7 +63,7 @@ class LiveList extends Builder foreach ($courses->toArray() as $course) { $course['cover'] = $baseUrl . $course['cover']; - $course['teacher'] = $teachers[$course['teacher_id']] ?? new \stdClass(); + $course['teacher'] = $teachers[$course['teacher_id']] ?? null; $result[$course['id']] = [ 'id' => $course['id'], 'title' => $course['title'], diff --git a/app/Builders/NotificationList.php b/app/Builders/NotificationList.php index 6670553d..35c2b913 100644 --- a/app/Builders/NotificationList.php +++ b/app/Builders/NotificationList.php @@ -7,8 +7,6 @@ namespace App\Builders; -use App\Repos\User as UserRepo; - class NotificationList extends Builder { @@ -17,8 +15,8 @@ class NotificationList extends Builder $users = $this->getUsers($notifications); foreach ($notifications as $key => $notification) { - $notifications[$key]['sender'] = $users[$notification['sender_id']] ?? new \stdClass(); - $notifications[$key]['receiver'] = $users[$notification['receiver_id']] ?? new \stdClass(); + $notifications[$key]['sender'] = $users[$notification['sender_id']] ?? null; + $notifications[$key]['receiver'] = $users[$notification['receiver_id']] ?? null; } return $notifications; @@ -30,20 +28,7 @@ class NotificationList extends Builder $receiverIds = kg_array_column($notifications, 'receiver_id'); $ids = array_merge($senderIds, $receiverIds); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/OrderList.php b/app/Builders/OrderList.php index 72a62b2a..b808eb29 100644 --- a/app/Builders/OrderList.php +++ b/app/Builders/OrderList.php @@ -9,7 +9,6 @@ namespace App\Builders; use App\Models\Course as CourseModel; use App\Models\Order as OrderModel; -use App\Repos\User as UserRepo; class OrderList extends Builder { @@ -30,7 +29,7 @@ class OrderList extends Builder $users = $this->getUsers($orders); foreach ($orders as $key => $order) { - $orders[$key]['owner'] = $users[$order['owner_id']] ?? new \stdClass(); + $orders[$key]['owner'] = $users[$order['owner_id']] ?? null; } return $orders; @@ -175,17 +174,7 @@ class OrderList extends Builder { $ids = kg_array_column($orders, 'owner_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $result = []; - - foreach ($users->toArray() as $user) { - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/QuestionFavoriteList.php b/app/Builders/QuestionFavoriteList.php index 7d5185de..befd764a 100644 --- a/app/Builders/QuestionFavoriteList.php +++ b/app/Builders/QuestionFavoriteList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Question as QuestionRepo; -use App\Repos\User as UserRepo; use Phalcon\Text; class QuestionFavoriteList extends Builder @@ -19,7 +18,7 @@ class QuestionFavoriteList extends Builder $questions = $this->getQuestions($relations); foreach ($relations as $key => $value) { - $relations[$key]['question'] = $questions[$value['question_id']] ?? new \stdClass(); + $relations[$key]['question'] = $questions[$value['question_id']] ?? null; } return $relations; @@ -30,7 +29,7 @@ class QuestionFavoriteList extends Builder $users = $this->getUsers($relations); foreach ($relations as $key => $value) { - $relations[$key]['user'] = $users[$value['user_id']] ?? new \stdClass(); + $relations[$key]['user'] = $users[$value['user_id']] ?? null; } return $relations; @@ -70,20 +69,7 @@ class QuestionFavoriteList extends Builder { $ids = kg_array_column($relations, 'user_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/QuestionList.php b/app/Builders/QuestionList.php index b4d25292..1d14a5e2 100644 --- a/app/Builders/QuestionList.php +++ b/app/Builders/QuestionList.php @@ -9,7 +9,6 @@ namespace App\Builders; use App\Caches\CategoryAllList as CategoryAllListCache; use App\Models\Category as CategoryModel; -use App\Repos\User as UserRepo; class QuestionList extends Builder { @@ -28,7 +27,7 @@ class QuestionList extends Builder $categories = $this->getCategories(); foreach ($questions as $key => $question) { - $questions[$key]['category'] = $categories[$question['category_id']] ?? new \stdClass(); + $questions[$key]['category'] = $categories[$question['category_id']] ?? null; } return $questions; @@ -39,8 +38,8 @@ class QuestionList extends Builder $users = $this->getUsers($questions); foreach ($questions as $key => $question) { - $questions[$key]['owner'] = $users[$question['owner_id']] ?? new \stdClass(); - $questions[$key]['last_replier'] = $users[$question['last_replier_id']] ?? new \stdClass(); + $questions[$key]['owner'] = $users[$question['owner_id']] ?? null; + $questions[$key]['last_replier'] = $users[$question['last_replier_id']] ?? null; } return $questions; @@ -72,20 +71,7 @@ class QuestionList extends Builder $lastReplierIds = kg_array_column($questions, 'last_replier_id'); $ids = array_merge($ownerIds, $lastReplierIds); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/RefundList.php b/app/Builders/RefundList.php index 6452288d..5a71734d 100644 --- a/app/Builders/RefundList.php +++ b/app/Builders/RefundList.php @@ -9,7 +9,6 @@ namespace App\Builders; use App\Models\Refund as RefundModel; use App\Repos\Order as OrderRepo; -use App\Repos\User as UserRepo; class RefundList extends Builder { @@ -19,7 +18,7 @@ class RefundList extends Builder $orders = $this->getOrders($trades); foreach ($trades as $key => $trade) { - $trades[$key]['order'] = $orders[$trade['order_id']] ?? new \stdClass(); + $trades[$key]['order'] = $orders[$trade['order_id']] ?? null; } return $trades; @@ -30,7 +29,7 @@ class RefundList extends Builder $users = $this->getUsers($refunds); foreach ($refunds as $key => $refund) { - $refunds[$key]['owner'] = $users[$refund['owner_id']] ?? new \stdClass(); + $refunds[$key]['owner'] = $users[$refund['owner_id']] ?? null; } return $refunds; @@ -75,20 +74,7 @@ class RefundList extends Builder { $ids = kg_array_column($refunds, 'owner_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/ReportList.php b/app/Builders/ReportList.php index 89c67218..a0a2311e 100644 --- a/app/Builders/ReportList.php +++ b/app/Builders/ReportList.php @@ -7,8 +7,6 @@ namespace App\Builders; -use App\Repos\User as UserRepo; - class ReportList extends Builder { @@ -17,7 +15,7 @@ class ReportList extends Builder $users = $this->getUsers($reports); foreach ($reports as $key => $report) { - $reports[$key]['owner'] = $users[$report['owner_id']] ?? new \stdClass(); + $reports[$key]['owner'] = $users[$report['owner_id']] ?? null; } return $reports; @@ -27,20 +25,7 @@ class ReportList extends Builder { $ids = kg_array_column($reports, 'owner_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/ResourceList.php b/app/Builders/ResourceList.php index f767cef5..8f9b7e3d 100644 --- a/app/Builders/ResourceList.php +++ b/app/Builders/ResourceList.php @@ -17,7 +17,7 @@ class ResourceList extends Builder $uploads = $this->getUploads($relations); foreach ($relations as $key => $value) { - $relations[$key]['upload'] = $uploads[$value['upload_id']] ?? new \stdClass(); + $relations[$key]['upload'] = $uploads[$value['upload_id']] ?? null; } return $relations; diff --git a/app/Builders/ReviewList.php b/app/Builders/ReviewList.php index 5a931902..56caef33 100644 --- a/app/Builders/ReviewList.php +++ b/app/Builders/ReviewList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Course as CourseRepo; -use App\Repos\User as UserRepo; class ReviewList extends Builder { @@ -18,7 +17,7 @@ class ReviewList extends Builder $courses = $this->getCourses($reviews); foreach ($reviews as $key => $review) { - $reviews[$key]['course'] = $courses[$review['course_id']] ?? new \stdClass(); + $reviews[$key]['course'] = $courses[$review['course_id']] ?? null; } return $reviews; @@ -29,7 +28,7 @@ class ReviewList extends Builder $users = $this->getUsers($reviews); foreach ($reviews as $key => $review) { - $reviews[$key]['owner'] = $users[$review['owner_id']] ?? new \stdClass(); + $reviews[$key]['owner'] = $users[$review['owner_id']] ?? null; } return $reviews; @@ -56,20 +55,7 @@ class ReviewList extends Builder { $ids = kg_array_column($reviews, 'owner_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/TagFollowList.php b/app/Builders/TagFollowList.php index c69d9ec2..13e0c009 100644 --- a/app/Builders/TagFollowList.php +++ b/app/Builders/TagFollowList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Tag as TagRepo; -use App\Repos\User as UserRepo; class TagFollowList extends Builder { @@ -18,7 +17,7 @@ class TagFollowList extends Builder $tags = $this->getTags($relations); foreach ($relations as $key => $value) { - $relations[$key]['tag'] = $tags[$value['tag_id']] ?? new \stdClass(); + $relations[$key]['tag'] = $tags[$value['tag_id']] ?? null; } return $relations; @@ -29,7 +28,7 @@ class TagFollowList extends Builder $users = $this->getUsers($relations); foreach ($relations as $key => $value) { - $relations[$key]['user'] = $users[$value['user_id']] ?? new \stdClass(); + $relations[$key]['user'] = $users[$value['user_id']] ?? null; } return $relations; @@ -61,20 +60,7 @@ class TagFollowList extends Builder { $ids = kg_array_column($relations, 'user_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findByIds($ids, ['id', 'name', 'avatar']); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/TradeList.php b/app/Builders/TradeList.php index 40d17a92..f4177e60 100644 --- a/app/Builders/TradeList.php +++ b/app/Builders/TradeList.php @@ -8,7 +8,6 @@ namespace App\Builders; use App\Repos\Order as OrderRepo; -use App\Repos\User as UserRepo; class TradeList extends Builder { @@ -18,7 +17,7 @@ class TradeList extends Builder $orders = $this->getOrders($trades); foreach ($trades as $key => $trade) { - $trades[$key]['order'] = $orders[$trade['order_id']] ?? new \stdClass(); + $trades[$key]['order'] = $orders[$trade['order_id']] ?? null; } return $trades; @@ -29,7 +28,7 @@ class TradeList extends Builder $users = $this->getUsers($trades); foreach ($trades as $key => $trade) { - $trades[$key]['owner'] = $users[$trade['owner_id']] ?? new \stdClass(); + $trades[$key]['owner'] = $users[$trade['owner_id']] ?? null; } return $trades; @@ -56,20 +55,7 @@ class TradeList extends Builder { $ids = kg_array_column($trades, 'owner_id'); - $userRepo = new UserRepo(); - - $users = $userRepo->findShallowUserByIds($ids); - - $baseUrl = kg_cos_url(); - - $result = []; - - foreach ($users->toArray() as $user) { - $user['avatar'] = $baseUrl . $user['avatar']; - $result[$user['id']] = $user; - } - - return $result; + return $this->getShallowUserByIds($ids); } } diff --git a/app/Builders/UserList.php b/app/Builders/UserList.php index fcee87c5..15301f63 100644 --- a/app/Builders/UserList.php +++ b/app/Builders/UserList.php @@ -30,7 +30,7 @@ class UserList extends Builder $accounts = $this->getAccounts($users); foreach ($users as $key => $user) { - $users[$key]['account'] = $accounts[$user['id']] ?? new \stdClass(); + $users[$key]['account'] = $accounts[$user['id']] ?? null; } return $users; diff --git a/app/Caches/Help.php b/app/Caches/Help.php deleted file mode 100644 index bb16649c..00000000 --- a/app/Caches/Help.php +++ /dev/null @@ -1,36 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "help:{$id}"; - } - - public function getContent($id = null) - { - $helpRepo = new HelpRepo(); - - $help = $helpRepo->findById($id); - - return $help ?: null; - } - -} diff --git a/app/Caches/HelpList.php b/app/Caches/HelpList.php deleted file mode 100644 index 5c30bea4..00000000 --- a/app/Caches/HelpList.php +++ /dev/null @@ -1,97 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'help_list'; - } - - public function getContent($id = null) - { - - $categories = $this->findCategories(); - - if ($categories->count() == 0) { - return []; - } - - $result = []; - - foreach ($categories as $category) { - - $item = []; - - $item['category'] = [ - 'id' => $category->id, - 'name' => $category->name, - ]; - - $item['helps'] = []; - - $helps = $this->findHelps($category->id); - - if ($helps->count() > 0) { - foreach ($helps as $help) { - $item['helps'][] = [ - 'id' => $help->id, - 'title' => $help->title, - ]; - } - } - - $result[] = $item; - } - - return $result; - } - - /** - * @return ResultsetInterface|Resultset|CategoryModel[] - */ - protected function findCategories() - { - return CategoryModel::query() - ->where('type = :type:', ['type' => CategoryModel::TYPE_HELP]) - ->andWhere('level = 1') - ->andWhere('published = 1') - ->andWhere('deleted = 0') - ->orderBy('priority ASC') - ->execute(); - } - - /** - * @param int $categoryId - * @return ResultsetInterface|Resultset|CategoryModel[] - */ - protected function findHelps($categoryId) - { - 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/MaxAnswerId.php b/app/Caches/MaxAnswerId.php deleted file mode 100644 index f10d5f01..00000000 --- a/app/Caches/MaxAnswerId.php +++ /dev/null @@ -1,34 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'max_answer_id'; - } - - public function getContent($id = null) - { - $answer = AnswerModel::findFirst(['order' => 'id DESC']); - - return $answer->id ?? 0; - } - -} diff --git a/app/Caches/MaxCommentId.php b/app/Caches/MaxCommentId.php deleted file mode 100644 index 23367441..00000000 --- a/app/Caches/MaxCommentId.php +++ /dev/null @@ -1,34 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'max_comment_id'; - } - - public function getContent($id = null) - { - $comment = CommentModel::findFirst(['order' => 'id DESC']); - - return $comment->id ?? 0; - } - -} diff --git a/app/Caches/MaxHelpId.php b/app/Caches/MaxHelpId.php deleted file mode 100644 index 75679247..00000000 --- a/app/Caches/MaxHelpId.php +++ /dev/null @@ -1,34 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'max_help_id'; - } - - public function getContent($id = null) - { - $help = HelpModel::findFirst(['order' => 'id DESC']); - - return $help->id ?? 0; - } - -} diff --git a/app/Caches/MaxPageId.php b/app/Caches/MaxPageId.php deleted file mode 100644 index 004faff2..00000000 --- a/app/Caches/MaxPageId.php +++ /dev/null @@ -1,34 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'max_page_id'; - } - - public function getContent($id = null) - { - $page = PageModel::findFirst(['order' => 'id DESC']); - - return $page->id ?? 0; - } - -} diff --git a/app/Caches/MaxPointGiftId.php b/app/Caches/MaxPointGiftId.php deleted file mode 100644 index f68994e0..00000000 --- a/app/Caches/MaxPointGiftId.php +++ /dev/null @@ -1,34 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'max_point_gift_id'; - } - - public function getContent($id = null) - { - $gift = PointGiftModel::findFirst(['order' => 'id DESC']); - - return $gift->id ?? 0; - } - -} diff --git a/app/Caches/MaxUploadId.php b/app/Caches/MaxUploadId.php deleted file mode 100644 index 2c623ecd..00000000 --- a/app/Caches/MaxUploadId.php +++ /dev/null @@ -1,34 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return 'max_upload_id'; - } - - public function getContent($id = null) - { - $upload = UploadModel::findFirst(['order' => 'id DESC']); - - return $upload->id ?? 0; - } - -} diff --git a/app/Caches/Page.php b/app/Caches/Page.php deleted file mode 100644 index 9d2554c7..00000000 --- a/app/Caches/Page.php +++ /dev/null @@ -1,36 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "page:{$id}"; - } - - public function getContent($id = null) - { - $pageRepo = new PageRepo(); - - $page = $pageRepo->findById($id); - - return $page ?: null; - } - -} diff --git a/app/Caches/PointGift.php b/app/Caches/PointGift.php deleted file mode 100644 index 07f5afa0..00000000 --- a/app/Caches/PointGift.php +++ /dev/null @@ -1,36 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "point_gift:{$id}"; - } - - public function getContent($id = null) - { - $giftRepo = new PointGiftRepo(); - - $gift = $giftRepo->findById($id); - - return $gift ?: null; - } - -} diff --git a/app/Console/Tasks/ServerMonitorTask.php b/app/Console/Tasks/ServerMonitorTask.php index 8f054931..9c4eeaad 100644 --- a/app/Console/Tasks/ServerMonitorTask.php +++ b/app/Console/Tasks/ServerMonitorTask.php @@ -177,13 +177,13 @@ class ServerMonitorTask extends Task $searcher = new CourseSearcher(); - $user = $searcher->search('id:1'); + $course = $searcher->search('id:1'); $benchmark->stop(); $elapsedTime = $benchmark->getElapsedTime(); - if (empty($user)) { + if (empty($course)) { return "xunsearch搜索失败"; } @@ -242,4 +242,4 @@ class ServerMonitorTask extends Task return $coreCount * $processorCount; } -} \ No newline at end of file +} diff --git a/app/Http/Admin/Services/Course.php b/app/Http/Admin/Services/Course.php index 24fb1d61..6540bc0d 100644 --- a/app/Http/Admin/Services/Course.php +++ b/app/Http/Admin/Services/Course.php @@ -168,14 +168,12 @@ class Course extends Service } } - if (isset($post['category_id']) && !empty($post['category_id'])) { - $category = $validator->checkCategory($post['category_id']); - $data['category_id'] = $category->id; + if (isset($post['category_id'])) { + $data['category_id'] = $validator->checkCategoryId($post['category_id']); } - if (isset($post['teacher_id']) && !empty($post['teacher_id'])) { - $teacher = $validator->checkTeacher($post['teacher_id']); - $data['teacher_id'] = $teacher->id; + if (isset($post['teacher_id'])) { + $data['teacher_id'] = $validator->checkTeacherId($post['teacher_id']); } if (isset($post['xm_tag_ids'])) { diff --git a/app/Http/Admin/Services/Help.php b/app/Http/Admin/Services/Help.php index 4fb16999..0a681b20 100644 --- a/app/Http/Admin/Services/Help.php +++ b/app/Http/Admin/Services/Help.php @@ -8,8 +8,6 @@ namespace App\Http\Admin\Services; use App\Builders\HelpList as HelpListBuilder; -use App\Caches\Help as HelpCache; -use App\Caches\HelpList as HelpListCache; use App\Models\Category as CategoryModel; use App\Models\Help as HelpModel; use App\Repos\Category as CategoryRepo; @@ -76,9 +74,6 @@ class Help extends Service $help->create($data); - $this->rebuildHelpCache($help); - $this->rebuildHelpListCache(); - return $help; } @@ -119,9 +114,6 @@ class Help extends Service $help->update($data); - $this->rebuildHelpCache($help); - $this->rebuildHelpListCache(); - return $help; } @@ -133,9 +125,6 @@ class Help extends Service $help->update(); - $this->rebuildHelpCache($help); - $this->rebuildHelpListCache(); - return $help; } @@ -147,9 +136,6 @@ class Help extends Service $help->update(); - $this->rebuildHelpCache($help); - $this->rebuildHelpListCache(); - return $help; } @@ -160,20 +146,6 @@ class Help extends Service return $validator->checkHelp($id); } - protected function rebuildHelpCache(HelpModel $help) - { - $cache = new HelpCache(); - - $cache->rebuild($help->id); - } - - protected function rebuildHelpListCache() - { - $cache = new HelpListCache(); - - $cache->rebuild(); - } - /** * @param Resultset $helps * @return array|object diff --git a/app/Http/Admin/Services/Package.php b/app/Http/Admin/Services/Package.php index ce8552b0..f4119294 100644 --- a/app/Http/Admin/Services/Package.php +++ b/app/Http/Admin/Services/Package.php @@ -59,9 +59,8 @@ class Package extends Service $result = []; foreach ($items as $item) { - $price = $item->market_price > 0 ? sprintf("¥%0.2f", $item->market_price) : '免费'; $result[] = [ - 'name' => sprintf('%s - %s(¥%0.2f)', $item->id, $item->title, $price), + 'name' => sprintf('%s - %s(¥%0.2f)', $item->id, $item->title, $item->market_price), 'value' => $item->id, 'selected' => in_array($item->id, $courseIds), ]; @@ -152,7 +151,7 @@ class Package extends Service $package->update($data); $this->handlePackagedCourses($package->id); - $this->updatePackageCourseCount($package->id); + $this->recountPackageCourses($package->id); $this->rebuildPackageCache($package->id); return $package; @@ -217,7 +216,7 @@ class Package extends Service 'course_id' => $courseId, 'package_id' => $package->id, ]); - $this->updateCoursePackageCount($courseId); + $this->recountCoursePackages($courseId); $this->rebuildCoursePackageCache($courseId); } } @@ -229,7 +228,7 @@ class Package extends Service foreach ($deletedCourseIds as $courseId) { $coursePackage = $coursePackageRepo->findCoursePackage($courseId, $package->id); $coursePackage->delete(); - $this->updateCoursePackageCount($courseId); + $this->recountCoursePackages($courseId); $this->rebuildCoursePackageCache($courseId); } } @@ -249,7 +248,7 @@ class Package extends Service } } - protected function updatePackageCourseCount($packageId) + protected function recountPackageCourses($packageId) { $packageRepo = new PackageRepo(); @@ -262,7 +261,7 @@ class Package extends Service $package->update(); } - protected function updateCoursePackageCount($courseId) + protected function recountCoursePackages($courseId) { $courseRepo = new CourseRepo(); @@ -293,15 +292,4 @@ class Package extends Service $cache->rebuild($courseId); } - protected function recountCoursePackages($courseId) - { - $courseRepo = new CourseRepo(); - - $course = $courseRepo->findById($courseId); - - $course->package_count = $courseRepo->countPackages($courseId); - - $course->update(); - } - } diff --git a/app/Http/Admin/Services/Page.php b/app/Http/Admin/Services/Page.php index 4684f8bb..3ed047c3 100644 --- a/app/Http/Admin/Services/Page.php +++ b/app/Http/Admin/Services/Page.php @@ -7,7 +7,6 @@ namespace App\Http\Admin\Services; -use App\Caches\Page as PageCache; use App\Library\Paginator\Query as PagerQuery; use App\Models\Page as PageModel; use App\Repos\Page as PageRepo; @@ -53,8 +52,6 @@ class Page extends Service $page->create($data); - $this->rebuildPageCache($page); - return $page; } @@ -96,8 +93,6 @@ class Page extends Service $page->update($data); - $this->rebuildPageCache($page); - return $page; } @@ -109,8 +104,6 @@ class Page extends Service $page->update(); - $this->rebuildPageCache($page); - return $page; } @@ -122,8 +115,6 @@ class Page extends Service $page->update(); - $this->rebuildPageCache($page); - return $page; } @@ -134,11 +125,4 @@ class Page extends Service return $validator->checkPage($id); } - protected function rebuildPageCache(PageModel $page) - { - $cache = new PageCache(); - - $cache->rebuild($page->id); - } - } diff --git a/app/Http/Admin/Services/PointGift.php b/app/Http/Admin/Services/PointGift.php index 545092c8..d92502bb 100644 --- a/app/Http/Admin/Services/PointGift.php +++ b/app/Http/Admin/Services/PointGift.php @@ -7,7 +7,6 @@ namespace App\Http\Admin\Services; -use App\Caches\PointGift as PointGiftCache; use App\Library\Paginator\Query as PagerQuery; use App\Models\PointGift as PointGiftModel; use App\Repos\Course as CourseRepo; @@ -116,8 +115,6 @@ class PointGift extends Service break; } - $this->rebuildPointGiftCache($gift); - return $gift; } @@ -165,8 +162,6 @@ class PointGift extends Service $gift->update($data); - $this->rebuildPointGiftCache($gift); - return $gift; } @@ -178,8 +173,6 @@ class PointGift extends Service $gift->update(); - $this->rebuildPointGiftCache($gift); - return $gift; } @@ -191,8 +184,6 @@ class PointGift extends Service $gift->update(); - $this->rebuildPointGiftCache($gift); - return $gift; } @@ -203,13 +194,6 @@ class PointGift extends Service return $validator->checkPointGift($id); } - protected function rebuildPointGiftCache(PointGiftModel $gift) - { - $cache = new PointGiftCache(); - - $cache->rebuild($gift->id); - } - protected function createCoursePointGift($post) { $validator = new PointGiftValidator(); diff --git a/app/Http/Admin/Views/article/edit.volt b/app/Http/Admin/Views/article/edit.volt index db2ca7aa..6c8adbd5 100644 --- a/app/Http/Admin/Views/article/edit.volt +++ b/app/Http/Admin/Views/article/edit.volt @@ -49,7 +49,7 @@ name: 'xm_tag_ids', max: 5, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_tags|json_encode }} @@ -71,4 +71,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/consult/search.volt b/app/Http/Admin/Views/consult/search.volt index 91f8959f..7e515682 100644 --- a/app/Http/Admin/Views/consult/search.volt +++ b/app/Http/Admin/Views/consult/search.volt @@ -84,7 +84,7 @@ name: 'course_id', filterable: true, radio: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_courses|json_encode }} @@ -102,4 +102,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/course/edit.volt b/app/Http/Admin/Views/course/edit.volt index 572c90b3..1896a946 100644 --- a/app/Http/Admin/Views/course/edit.volt +++ b/app/Http/Admin/Views/course/edit.volt @@ -65,7 +65,7 @@ name: 'xm_tag_ids', max: 5, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_tags|json_encode }} @@ -77,7 +77,7 @@ max: 10, autoRow: true, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_courses|json_encode }} @@ -107,4 +107,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/macros/flash_sale.volt b/app/Http/Admin/Views/macros/flash_sale.volt deleted file mode 100644 index 4a63a320..00000000 --- a/app/Http/Admin/Views/macros/flash_sale.volt +++ /dev/null @@ -1,31 +0,0 @@ -{%- macro item_type_info(value) %} - {% if value == 1 %} - 课程 - {% elseif value == 2 %} - 套餐 - {% elseif value == 3 %} - 会员 - {% endif %} -{%- endmacro %} - -{%- macro item_full_info(item_type,item_info) %} - {% if item_type == 1 %} - {% set course = item_info.course %} -

名称:{{ course.title }}({{ course.id }})

-

类型:{{ item_type_info(item_type) }} 价格:{{ '¥%0.2f'|format(course.market_price) }}

- {% elseif item_type == 2 %} - {% set package = item_info.package %} -

名称:{{ package.title }}({{ package.id }})

-

类型:{{ item_type_info(item_type) }} 价格:{{ '¥%0.2f'|format(package.market_price) }}

- {% elseif item_type == 3 %} - {% set vip = item_info.vip %} -

期限:{{ '%d个月'|format(vip.expiry) }}({{ vip.id }})

-

类型:{{ item_type_info(item_type) }} 价格:{{ '¥%0.2f'|format(vip.price) }}

- {% endif %} -{%- endmacro %} - -{%- macro schedules_info(schedules) %} - {% for value in schedules %} - {{ value }}点 - {% endfor %} -{%- endmacro %} \ No newline at end of file diff --git a/app/Http/Admin/Views/package/edit.volt b/app/Http/Admin/Views/package/edit.volt index c7c97b97..2380c6c2 100644 --- a/app/Http/Admin/Views/package/edit.volt +++ b/app/Http/Admin/Views/package/edit.volt @@ -82,7 +82,7 @@ max: 15, autoRow: true, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_courses|json_encode }} @@ -92,4 +92,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/point_gift/add.volt b/app/Http/Admin/Views/point_gift/add.volt index 298f822d..926a7540 100644 --- a/app/Http/Admin/Views/point_gift/add.volt +++ b/app/Http/Admin/Views/point_gift/add.volt @@ -69,7 +69,7 @@ name: 'xm_course_id', radio: true, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_courses|json_encode }} @@ -91,4 +91,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/question/edit.volt b/app/Http/Admin/Views/question/edit.volt index 4ad70bf6..4e878a8d 100644 --- a/app/Http/Admin/Views/question/edit.volt +++ b/app/Http/Admin/Views/question/edit.volt @@ -48,7 +48,7 @@ name: 'xm_tag_ids', max: 5, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_tags|json_encode }} @@ -58,4 +58,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/review/search.volt b/app/Http/Admin/Views/review/search.volt index 8e62a8ef..cca0a9c9 100644 --- a/app/Http/Admin/Views/review/search.volt +++ b/app/Http/Admin/Views/review/search.volt @@ -84,7 +84,7 @@ name: 'course_id', filterable: true, radio: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_courses|json_encode }} @@ -102,4 +102,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/slide/add.volt b/app/Http/Admin/Views/slide/add.volt index 81250ed2..1654cf3a 100644 --- a/app/Http/Admin/Views/slide/add.volt +++ b/app/Http/Admin/Views/slide/add.volt @@ -75,7 +75,7 @@ name: 'xm_course_id', radio: true, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_courses|json_encode }} @@ -86,7 +86,7 @@ name: 'xm_page_id', radio: true, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_pages|json_encode }} @@ -101,4 +101,4 @@ -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Admin/Views/topic/edit.volt b/app/Http/Admin/Views/topic/edit.volt index cd1bfdd7..29803769 100644 --- a/app/Http/Admin/Views/topic/edit.volt +++ b/app/Http/Admin/Views/topic/edit.volt @@ -44,7 +44,7 @@ max: 15, autoRow: true, filterable: true, - filterMethod: function (val, item, index, prop) { + filterMethod: function (val, item) { return item.name.toLowerCase().indexOf(val.toLowerCase()) !== -1; }, data: {{ xm_courses|json_encode }} @@ -55,4 +55,3 @@ {% endblock %} - diff --git a/app/Http/Home/Controllers/PointGiftController.php b/app/Http/Home/Controllers/PointGiftController.php index 1b7a8c0d..5b2c4b16 100644 --- a/app/Http/Home/Controllers/PointGiftController.php +++ b/app/Http/Home/Controllers/PointGiftController.php @@ -87,7 +87,7 @@ class PointGiftController extends Controller $hotGifts = $this->getHotGifts(); $userBalance = $this->getUserBalance(); - $this->seo->prependTitle(['积分兑换', $gift['name']]); + $this->seo->prependTitle(['积分商城', $gift['name']]); $this->view->pick('point/gift/show'); $this->view->setVar('gift', $gift); diff --git a/app/Http/Home/Views/partials/footer.volt b/app/Http/Home/Views/partials/footer.volt index 0091c574..ddd34157 100644 --- a/app/Http/Home/Views/partials/footer.volt +++ b/app/Http/Home/Views/partials/footer.volt @@ -38,11 +38,11 @@ {% endif %} {% if contact_info.weibo %} {% set link_url = 'https://weibo.com/u/%s'|format(contact_info.weibo) %} - + {% endif %} {% if contact_info.zhihu %} {% set link_url = 'https://www.zhihu.com/people/%s'|format(contact_info.zhihu) %} - + {% endif %} {% if contact_info.email %} {% set link_url = 'mailto:%s'|format(contact_info.email) %} @@ -53,8 +53,8 @@ {% endif %} {% if contact_info.address %} {% set link_url = 'https://map.baidu.com/search/%s?querytype=s&wd=%s'|format(contact_info.address,contact_info.address) %} - + {% endif %} {% endif %} - \ No newline at end of file + diff --git a/app/Http/Home/Views/point/gift/list.volt b/app/Http/Home/Views/point/gift/list.volt index 6db04fc4..e6ca49e4 100644 --- a/app/Http/Home/Views/point/gift/list.volt +++ b/app/Http/Home/Views/point/gift/list.volt @@ -6,7 +6,7 @@
@@ -17,4 +17,4 @@ {{ js_include('home/js/point.gift.list.js') }} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Http/Home/Views/point/gift/show.volt b/app/Http/Home/Views/point/gift/show.volt index ae94d2e9..48d84652 100644 --- a/app/Http/Home/Views/point/gift/show.volt +++ b/app/Http/Home/Views/point/gift/show.volt @@ -10,7 +10,7 @@ @@ -55,7 +55,23 @@
物品详情
-
{{ gift.details }}
+
+ {% if gift.type == 1 %} + {% set course_url = url({'for':'home.course.show','id':gift.attrs.id}) %} +

+ {{ gift.name }} + 查看 +

+ {% elseif gift.type == 3 %} + {% set vip_url = url({'for':'home.vip.index'}) %} +

+ {{ gift.name }} + 查看 +

+ {% else %} + {{ gift.details }} + {% endif %} +
@@ -124,4 +140,4 @@ {{ js_include('home/js/point.gift.show.js') }} -{% endblock %} \ No newline at end of file +{% endblock %} diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index 7ffc39ad..b804bac0 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -16,7 +16,7 @@ class AppInfo protected $link = 'https://www.koogua.com'; - protected $version = '1.7.4'; + protected $version = '1.7.5'; public function __get($name) { @@ -32,4 +32,4 @@ class AppInfo return null; } -} \ No newline at end of file +} diff --git a/app/Library/CsrfToken.php b/app/Library/CsrfToken.php index fe09c600..25fd24c8 100644 --- a/app/Library/CsrfToken.php +++ b/app/Library/CsrfToken.php @@ -70,9 +70,9 @@ class CsrfToken */ $config = Di::getDefault()->getShared('config'); - $lifetime = $config->path('csrf_token.lifetime') ?: $this->lifetime; + $lifetime = $config->path('csrf_token.lifetime', $this->lifetime); return $lifetime + time(); } -} \ No newline at end of file +} diff --git a/app/Library/Logger.php b/app/Library/Logger.php index 0b7cc17b..645d5719 100644 --- a/app/Library/Logger.php +++ b/app/Library/Logger.php @@ -19,15 +19,13 @@ class Logger * @param string $channel * @return FileLogger */ - public function getInstance($channel = null) + public function getInstance($channel = 'common') { /** * @var Config $config */ $config = Di::getDefault()->getShared('config'); - $channel = $channel ? $channel : 'common'; - $filename = sprintf('%s-%s.log', $channel, date('Y-m-d')); $path = log_path($filename); diff --git a/app/Library/Mvc/View.php b/app/Library/Mvc/View.php index f2ceff25..d3d69647 100644 --- a/app/Library/Mvc/View.php +++ b/app/Library/Mvc/View.php @@ -42,4 +42,4 @@ class View extends PhView return $var; } -} \ No newline at end of file +} diff --git a/app/Models/Answer.php b/app/Models/Answer.php index 0fd88c51..49e97aad 100644 --- a/app/Models/Answer.php +++ b/app/Models/Answer.php @@ -7,7 +7,6 @@ namespace App\Models; -use App\Caches\MaxAnswerId as MaxAnswerIdCache; use Phalcon\Mvc\Model\Behavior\SoftDelete; class Answer extends Model @@ -166,13 +165,6 @@ class Answer extends Model $this->update_time = time(); } - public function afterCreate() - { - $cache = new MaxAnswerIdCache(); - - $cache->rebuild(); - } - public static function publishTypes() { return [ diff --git a/app/Models/Article.php b/app/Models/Article.php index 4fac85c1..78a1dbd5 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -253,7 +253,7 @@ class Article extends Model $this->cover = self::getCoverPath($this->cover); } - if (is_array($this->tags) || is_object($this->tags)) { + if (is_array($this->tags)) { $this->tags = kg_json_encode($this->tags); } } diff --git a/app/Models/Chapter.php b/app/Models/Chapter.php index a136081f..30c52862 100644 --- a/app/Models/Chapter.php +++ b/app/Models/Chapter.php @@ -232,7 +232,7 @@ class Chapter extends Model } } - if (is_array($this->attrs) || is_object($this->attrs)) { + if (is_array($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } @@ -241,7 +241,7 @@ class Chapter extends Model public function beforeUpdate() { - if (is_array($this->attrs) || is_object($this->attrs)) { + if (is_array($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } diff --git a/app/Models/ChapterVod.php b/app/Models/ChapterVod.php index 32913975..148fb891 100644 --- a/app/Models/ChapterVod.php +++ b/app/Models/ChapterVod.php @@ -75,11 +75,11 @@ class ChapterVod extends Model public function beforeCreate() { - if (is_array($this->file_transcode) || is_object($this->file_transcode)) { + if (is_array($this->file_transcode)) { $this->file_transcode = kg_json_encode($this->file_transcode); } - if (is_array($this->file_remote) || is_object($this->file_remote)) { + if (is_array($this->file_remote)) { $this->file_remote = kg_json_encode($this->file_remote); } @@ -88,11 +88,11 @@ class ChapterVod extends Model public function beforeUpdate() { - if (is_array($this->file_transcode) || is_object($this->file_transcode)) { + if (is_array($this->file_transcode)) { $this->file_transcode = kg_json_encode($this->file_transcode); } - if (is_array($this->file_remote) || is_object($this->file_remote)) { + if (is_array($this->file_remote)) { $this->file_remote = kg_json_encode($this->file_remote); } diff --git a/app/Models/Comment.php b/app/Models/Comment.php index 5b67874b..e0cb209b 100644 --- a/app/Models/Comment.php +++ b/app/Models/Comment.php @@ -7,7 +7,6 @@ namespace App\Models; -use App\Caches\MaxCommentId as MaxCommentIdCache; use Phalcon\Mvc\Model\Behavior\SoftDelete; class Comment extends Model @@ -167,18 +166,12 @@ class Comment extends Model $this->update_time = time(); } - public function afterCreate() - { - $cache = new MaxCommentIdCache(); - - $cache->rebuild(); - } - public static function itemTypes() { return [ self::ITEM_CHAPTER => '章节', self::ITEM_ARTICLE => '文章', + self::ITEM_QUESTION => '问题', self::ITEM_ANSWER => '回答', ]; } diff --git a/app/Models/Course.php b/app/Models/Course.php index 56bb3219..38531f77 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -321,7 +321,7 @@ class Course extends Model } } - if (is_array($this->attrs) || is_object($this->attrs)) { + if (is_array($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } @@ -338,7 +338,7 @@ class Course extends Model $sync->addItem($this->id); } - if (is_array($this->attrs) || is_object($this->attrs)) { + if (is_array($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } @@ -355,17 +355,13 @@ class Course extends Model $this->cover = self::getCoverPath($this->cover); } - if (is_array($this->tags) || is_object($this->tags)) { + if (is_array($this->tags)) { $this->tags = kg_json_encode($this->tags); } if (empty($this->summary)) { $this->summary = kg_parse_summary($this->details); } - - if (empty($this->origin_price)) { - $this->origin_price = 1.5 * $this->market_price; - } } public function afterCreate() diff --git a/app/Models/Help.php b/app/Models/Help.php index 236c1732..35197a18 100644 --- a/app/Models/Help.php +++ b/app/Models/Help.php @@ -7,7 +7,6 @@ namespace App\Models; -use App\Caches\MaxHelpId as MaxHelpIdCache; use Phalcon\Mvc\Model\Behavior\SoftDelete; class Help extends Model @@ -117,11 +116,4 @@ class Help extends Model $this->update_time = time(); } - public function afterCreate() - { - $cache = new MaxHelpIdCache(); - - $cache->rebuild(); - } - } diff --git a/app/Models/Notification.php b/app/Models/Notification.php index 8f589960..d67aab75 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -186,7 +186,7 @@ class Notification extends Model public function beforeSave() { - if (is_array($this->event_info) || is_object($this->event_info)) { + if (is_array($this->event_info)) { $this->event_info = kg_json_encode($this->event_info); } } diff --git a/app/Models/Order.php b/app/Models/Order.php index dcc8668c..84d1ede2 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -161,7 +161,7 @@ class Order extends Model public function beforeSave() { - if (is_array($this->item_info) || is_object($this->item_info)) { + if (is_array($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); } } diff --git a/app/Models/Page.php b/app/Models/Page.php index 31ac25d8..4493991e 100644 --- a/app/Models/Page.php +++ b/app/Models/Page.php @@ -7,7 +7,6 @@ namespace App\Models; -use App\Caches\MaxPageId as MaxPageIdCache; use Phalcon\Mvc\Model\Behavior\SoftDelete; class Page extends Model @@ -110,11 +109,4 @@ class Page extends Model $this->update_time = time(); } - public function afterCreate() - { - $cache = new MaxPageIdCache(); - - $cache->rebuild(); - } - } diff --git a/app/Models/PointGift.php b/app/Models/PointGift.php index ae424730..3278e1f3 100644 --- a/app/Models/PointGift.php +++ b/app/Models/PointGift.php @@ -7,7 +7,6 @@ namespace App\Models; -use App\Caches\MaxPointGiftId as MaxPointGiftIdCache; use Phalcon\Mvc\Model\Behavior\SoftDelete; use Phalcon\Text; @@ -181,7 +180,7 @@ class PointGift extends Model } } - if (is_array($this->attrs) || is_object($this->attrs)) { + if (is_array($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } @@ -190,7 +189,7 @@ class PointGift extends Model public function beforeUpdate() { - if (is_array($this->attrs) || is_object($this->attrs)) { + if (is_array($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } @@ -206,13 +205,6 @@ class PointGift extends Model } } - public function afterCreate() - { - $cache = new MaxPointGiftIdCache(); - - $cache->rebuild(); - } - public function afterFetch() { if (!Text::startsWith($this->cover, 'http')) { diff --git a/app/Models/PointHistory.php b/app/Models/PointHistory.php index 24b6d122..abaaad3e 100644 --- a/app/Models/PointHistory.php +++ b/app/Models/PointHistory.php @@ -110,7 +110,7 @@ class PointHistory extends Model public function beforeSave() { - if (is_array($this->event_info) || is_object($this->event_info)) { + if (is_array($this->event_info)) { $this->event_info = kg_json_encode($this->event_info); } } diff --git a/app/Models/Question.php b/app/Models/Question.php index 47a6be3d..3039a851 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -281,7 +281,7 @@ class Question extends Model $this->cover = self::getCoverPath($this->cover); } - if (is_array($this->tags) || is_object($this->tags)) { + if (is_array($this->tags)) { $this->tags = kg_json_encode($this->tags); } } @@ -295,6 +295,9 @@ class Question extends Model public function afterFetch() { + /** + * 问题封面非必要,有则处理,无则略过 + */ if (!empty($this->cover) && !Text::startsWith($this->cover, 'http')) { $this->cover = kg_cos_article_cover_url($this->cover); } diff --git a/app/Models/Role.php b/app/Models/Role.php index 262e6145..6e152b6b 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -118,7 +118,7 @@ class Role extends Model public function beforeSave() { - if (is_array($this->routes) || is_object($this->routes)) { + if (is_array($this->routes)) { $this->routes = kg_json_encode($this->routes); } } diff --git a/app/Models/Slide.php b/app/Models/Slide.php index b7dffd17..b95f9b31 100644 --- a/app/Models/Slide.php +++ b/app/Models/Slide.php @@ -146,7 +146,7 @@ class Slide extends Model $this->cover = self::getCoverPath($this->cover); } - if (is_array($this->target_attrs) || is_object($this->target_attrs)) { + if (is_array($this->target_attrs)) { $this->target_attrs = kg_json_encode($this->target_attrs); } } diff --git a/app/Models/Tag.php b/app/Models/Tag.php index a294e00c..6a63f929 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -154,7 +154,7 @@ class Tag extends Model $this->icon = self::getIconPath($this->icon); } - if (is_array($this->scopes) || is_object($this->scopes)) { + if (is_array($this->scopes)) { $this->scopes = kg_json_encode($this->scopes); } } diff --git a/app/Models/Task.php b/app/Models/Task.php index 2a0851dd..fcd819a2 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -141,7 +141,7 @@ class Task extends Model public function beforeSave() { - if (is_array($this->item_info) || is_object($this->item_info)) { + if (is_array($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); } } diff --git a/app/Models/Upload.php b/app/Models/Upload.php index 33a09b25..98db82ad 100644 --- a/app/Models/Upload.php +++ b/app/Models/Upload.php @@ -7,7 +7,6 @@ namespace App\Models; -use App\Caches\MaxUploadId as MaxUploadIdCache; use Phalcon\Mvc\Model\Behavior\SoftDelete; class Upload extends Model @@ -122,11 +121,4 @@ class Upload extends Model $this->update_time = time(); } - public function afterCreate() - { - $cache = new MaxUploadIdCache(); - - $cache->rebuild(); - } - } diff --git a/app/Models/Vip.php b/app/Models/Vip.php index 5aa4bfbd..d709ce6d 100644 --- a/app/Models/Vip.php +++ b/app/Models/Vip.php @@ -95,22 +95,21 @@ class Vip extends Model public function beforeCreate() { - if (empty($this->cover)) { - $this->cover = kg_default_vip_cover_path(); - } elseif (Text::startsWith($this->cover, 'http')) { - $this->cover = self::getCoverPath($this->cover); - } - $this->create_time = time(); } public function beforeUpdate() { - if (Text::startsWith($this->cover, 'http')) { + $this->update_time = time(); + } + + public function beforeSave() + { + if (empty($this->cover)) { + $this->cover = kg_default_vip_cover_path(); + } elseif (Text::startsWith($this->cover, 'http')) { $this->cover = self::getCoverPath($this->cover); } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Services/Logic/Article/ArticleInfo.php b/app/Services/Logic/Article/ArticleInfo.php index 47c03f90..97d5020e 100644 --- a/app/Services/Logic/Article/ArticleInfo.php +++ b/app/Services/Logic/Article/ArticleInfo.php @@ -7,12 +7,11 @@ namespace App\Services\Logic\Article; -use App\Caches\Category as CategoryCache; use App\Models\Article as ArticleModel; -use App\Models\Category as CategoryModel; use App\Models\User as UserModel; use App\Repos\ArticleFavorite as ArticleFavoriteRepo; use App\Repos\ArticleLike as ArticleLikeRepo; +use App\Services\Category as CategoryService; use App\Services\Logic\ArticleTrait; use App\Services\Logic\Service as LogicService; use App\Services\Logic\User\ShallowUserInfo; @@ -39,7 +38,7 @@ class ArticleInfo extends LogicService protected function handleArticle(ArticleModel $article, UserModel $user) { - $category = $this->handleCategoryInfo($article->category_id); + $categoryPaths = $this->handleCategoryPaths($article->category_id); $owner = $this->handleOwnerInfo($article->owner_id); $me = $this->handleMeInfo($article, $user); @@ -63,27 +62,19 @@ class ArticleInfo extends LogicService 'favorite_count' => $article->favorite_count, 'create_time' => $article->create_time, 'update_time' => $article->update_time, - 'category' => $category, + 'category_paths' => $categoryPaths, 'owner' => $owner, 'me' => $me, ]; } - protected function handleCategoryInfo($categoryId) + protected function handleCategoryPaths($categoryId) { - $cache = new CategoryCache(); + if ($categoryId == 0) return null; - /** - * @var CategoryModel $category - */ - $category = $cache->get($categoryId); + $service = new CategoryService(); - if (!$category) return new \stdClass(); - - return [ - 'id' => $category->id, - 'name' => $category->name, - ]; + return $service->getCategoryPaths($categoryId); } protected function handleOwnerInfo($userId) diff --git a/app/Services/Logic/Chapter/ChapterInfo.php b/app/Services/Logic/Chapter/ChapterInfo.php index a5221e81..49d223a9 100644 --- a/app/Services/Logic/Chapter/ChapterInfo.php +++ b/app/Services/Logic/Chapter/ChapterInfo.php @@ -31,8 +31,9 @@ class ChapterInfo extends LogicService protected $user; use CourseTrait; - use CourseUserTrait; use ChapterTrait; + use CourseUserTrait; + use ChapterUserTrait; public function handle($id) { diff --git a/app/Services/Logic/Chapter/ChapterUserTrait.php b/app/Services/Logic/Chapter/ChapterUserTrait.php new file mode 100644 index 00000000..6a30056f --- /dev/null +++ b/app/Services/Logic/Chapter/ChapterUserTrait.php @@ -0,0 +1,57 @@ +id == 0) return; + + $chapterUser = null; + + $courseUser = $this->courseUser; + + if ($courseUser) { + $chapterUserRepo = new ChapterUserRepo(); + $chapterUser = $chapterUserRepo->findChapterUser($chapter->id, $user->id); + } + + $this->chapterUser = $chapterUser; + + if ($chapterUser) { + $this->joinedChapter = true; + } + + if ($this->ownedCourse || $chapter->free) { + $this->ownedChapter = true; + } + } + +} diff --git a/app/Services/Logic/ChapterTrait.php b/app/Services/Logic/ChapterTrait.php index 877c111c..933b96cd 100644 --- a/app/Services/Logic/ChapterTrait.php +++ b/app/Services/Logic/ChapterTrait.php @@ -7,31 +7,11 @@ namespace App\Services\Logic; -use App\Models\Chapter as ChapterModel; -use App\Models\ChapterUser as ChapterUserModel; -use App\Models\CourseUser as CourseUserModel; -use App\Models\User as UserModel; -use App\Repos\ChapterUser as ChapterUserRepo; use App\Validators\Chapter as ChapterValidator; trait ChapterTrait { - /** - * @var bool - */ - protected $ownedChapter = false; - - /** - * @var bool - */ - protected $joinedChapter = false; - - /** - * @var ChapterUserModel|null - */ - protected $chapterUser; - public function checkChapterVod($id) { $validator = new ChapterValidator(); @@ -67,31 +47,4 @@ trait ChapterTrait return $validator->checkChapterCache($id); } - public function setChapterUser(ChapterModel $chapter, UserModel $user) - { - if ($user->id == 0) return; - - $chapterUser = null; - - /** - * @var CourseUserModel $courseUser - */ - $courseUser = $this->courseUser; - - if ($courseUser) { - $chapterUserRepo = new ChapterUserRepo(); - $chapterUser = $chapterUserRepo->findChapterUser($chapter->id, $user->id); - } - - $this->chapterUser = $chapterUser; - - if ($chapterUser) { - $this->joinedChapter = true; - } - - if ($this->ownedCourse || $chapter->free) { - $this->ownedChapter = true; - } - } - } diff --git a/app/Services/Logic/Comment/CommentInfo.php b/app/Services/Logic/Comment/CommentInfo.php index 0101b33f..f301dcca 100644 --- a/app/Services/Logic/Comment/CommentInfo.php +++ b/app/Services/Logic/Comment/CommentInfo.php @@ -54,7 +54,7 @@ class CommentInfo extends LogicService protected function handleToUserInfo($userId) { - if ($userId == 0) return new \stdClass(); + if ($userId == 0) return null; $service = new ShallowUserInfo(); diff --git a/app/Services/Logic/Consult/ConsultCreate.php b/app/Services/Logic/Consult/ConsultCreate.php index 402ddb5c..a88d1110 100644 --- a/app/Services/Logic/Consult/ConsultCreate.php +++ b/app/Services/Logic/Consult/ConsultCreate.php @@ -23,6 +23,7 @@ class ConsultCreate extends LogicService use ClientTrait; use CourseTrait; + use ConsultDataTrait; public function handle() { @@ -34,10 +35,6 @@ class ConsultCreate extends LogicService $validator->checkDailyConsultLimit($user); - $validator = new UserLimitValidator(); - - $validator->checkDailyConsultLimit($user); - $course = $this->checkCourse($courseId); return $this->handleCourseConsult($course, $user); @@ -47,32 +44,20 @@ class ConsultCreate extends LogicService { $post = $this->request->getPost(); + $data = $this->handlePostData($post); + $validator = new ConsultValidator(); - $question = $validator->checkQuestion($post['question']); - - $private = 0; - - if (isset($post['private'])) { - $private = $validator->checkPrivateStatus($post['private']); - } - - $validator->checkIfDuplicated($course->id, $user->id, $question); - - $priority = $this->getPriority($course, $user); + $validator->checkIfDuplicated($course->id, $user->id, $data['question']); $consult = new ConsultModel(); - $consult->question = $question; - $consult->private = $private; - $consult->priority = $priority; - $consult->course_id = $course->id; - $consult->owner_id = $user->id; - $consult->client_type = $this->getClientType(); - $consult->client_ip = $this->getClientIp(); - $consult->published = ConsultModel::PUBLISH_PENDING; + $data['priority'] = $this->getPriority($course, $user); + $data['published'] = ConsultModel::PUBLISH_PENDING; + $data['course_id'] = $course->id; + $data['owner_id'] = $user->id; - $consult->create(); + $consult->create($data); $this->recountCourseConsults($course); $this->incrUserDailyConsultCount($user); diff --git a/app/Services/Logic/Consult/ConsultDataTrait.php b/app/Services/Logic/Consult/ConsultDataTrait.php new file mode 100644 index 00000000..25ed62b9 --- /dev/null +++ b/app/Services/Logic/Consult/ConsultDataTrait.php @@ -0,0 +1,38 @@ +getClientType(); + $data['client_ip'] = $this->getClientIp(); + + $validator = new ConsultValidator(); + + if (isset($post['question'])) { + $data['question'] = $validator->checkQuestion($post['question']); + } + + if (isset($post['private'])) { + $data['private'] = $validator->checkPrivateStatus($post['private']); + } + + return $data; + } + +} diff --git a/app/Services/Logic/Consult/ConsultInfo.php b/app/Services/Logic/Consult/ConsultInfo.php index 76177ccd..50eff9c8 100644 --- a/app/Services/Logic/Consult/ConsultInfo.php +++ b/app/Services/Logic/Consult/ConsultInfo.php @@ -76,7 +76,7 @@ class ConsultInfo extends LogicService protected function handleReplierInfo($userId) { - if ($userId == 0) return new \stdClass(); + if ($userId == 0) return null; $service = new ShallowUserInfo(); diff --git a/app/Services/Logic/Consult/ConsultUpdate.php b/app/Services/Logic/Consult/ConsultUpdate.php index efb7c775..f9af84df 100644 --- a/app/Services/Logic/Consult/ConsultUpdate.php +++ b/app/Services/Logic/Consult/ConsultUpdate.php @@ -15,6 +15,7 @@ class ConsultUpdate extends LogicService { use ConsultTrait; + use ConsultDataTrait; public function handle($id) { @@ -28,15 +29,7 @@ class ConsultUpdate extends LogicService $validator->checkEditPriv($consult, $user); - $data = []; - - if (isset($post['question'])) { - $data['question'] = $validator->checkQuestion($post['question']); - } - - if (isset($post['private'])) { - $data['private'] = $validator->checkPrivateStatus($post['private']); - } + $data = $this->handlePostData($post); $consult->update($data); diff --git a/app/Services/Logic/ContentTrait.php b/app/Services/Logic/ContentTrait.php new file mode 100644 index 00000000..1ff67c78 --- /dev/null +++ b/app/Services/Logic/ContentTrait.php @@ -0,0 +1,29 @@ +handleCosImageStyle($content); + } + + protected function handleCosImageStyle($content) + { + $style = '!content_800'; + + $pattern = '/src="(.*?)\/img\/content\/(.*?)"/'; + + $replacement = 'src="$1/img/content/$2' . $style . '"'; + + return preg_replace($pattern, $replacement, $content); + } + +} diff --git a/app/Services/Logic/Course/BasicInfo.php b/app/Services/Logic/Course/BasicInfo.php index 81968130..57e6cccd 100644 --- a/app/Services/Logic/Course/BasicInfo.php +++ b/app/Services/Logic/Course/BasicInfo.php @@ -79,7 +79,7 @@ class BasicInfo extends LogicService protected function handleCategoryPaths($categoryId) { - if ($categoryId == 0) return new \stdClass(); + if ($categoryId == 0) return null; $service = new CategoryService(); @@ -88,7 +88,7 @@ class BasicInfo extends LogicService protected function handleTeacherInfo($userId) { - if ($userId == 0) return new \stdClass(); + if ($userId == 0) return null; $service = new ShallowUserInfoService(); diff --git a/app/Services/Logic/Course/ChapterList.php b/app/Services/Logic/Course/ChapterList.php index c94eda71..3d23dae9 100644 --- a/app/Services/Logic/Course/ChapterList.php +++ b/app/Services/Logic/Course/ChapterList.php @@ -50,14 +50,14 @@ class ChapterList extends LogicService protected function handleLoginUserChapters(array $chapters, CourseModel $course, UserModel $user) { - $mapping = $this->getLearningMapping($course->id, $user->id, $this->courseUser->plan_id); + $mappings = $this->getLearningMappings($course->id, $user->id, $this->courseUser->plan_id); foreach ($chapters as &$chapter) { foreach ($chapter['children'] as &$lesson) { $owned = ($this->ownedCourse || $lesson['free'] == 1) && $lesson['published'] == 1; $lesson['me'] = [ - 'progress' => $mapping[$lesson['id']]['progress'] ?? 0, - 'duration' => $mapping[$lesson['id']]['duration'] ?? 0, + 'progress' => $mappings[$lesson['id']]['progress'] ?? 0, + 'duration' => $mappings[$lesson['id']]['duration'] ?? 0, 'owned' => $owned ? 1 : 0, 'logged' => 1, ]; @@ -84,7 +84,7 @@ class ChapterList extends LogicService return $chapters; } - protected function getLearningMapping($courseId, $userId, $planId) + protected function getLearningMappings($courseId, $userId, $planId) { $courseRepo = new CourseRepo(); @@ -92,17 +92,17 @@ class ChapterList extends LogicService if ($userLearnings->count() == 0) return []; - $mapping = []; + $mappings = []; foreach ($userLearnings as $learning) { - $mapping[$learning->chapter_id] = [ + $mappings[$learning->chapter_id] = [ 'progress' => $learning->progress, 'duration' => $learning->duration, 'consumed' => $learning->consumed, ]; } - return $mapping; + return $mappings; } } diff --git a/app/Services/Logic/Help/HelpList.php b/app/Services/Logic/Help/HelpList.php index e9b341aa..f20e6300 100644 --- a/app/Services/Logic/Help/HelpList.php +++ b/app/Services/Logic/Help/HelpList.php @@ -7,7 +7,9 @@ namespace App\Services\Logic\Help; -use App\Caches\HelpList as HelpListCache; +use App\Caches\CategoryList as CategoryListCache; +use App\Models\Category as CategoryModel; +use App\Repos\Help as HelpRepo; use App\Services\Logic\Service as LogicService; class HelpList extends LogicService @@ -15,9 +17,43 @@ class HelpList extends LogicService public function handle() { - $cache = new HelpListCache(); + $cache = new CategoryListCache(); - return $cache->get(); + $categories = $cache->get(CategoryModel::TYPE_HELP); + + $helpRepo = new HelpRepo(); + + $helps = $helpRepo->findAll([ + 'published' => 1, + 'deleted' => 0, + ]); + + $result = []; + + foreach ($categories as $category) { + + $item = []; + + $item['category'] = [ + 'id' => $category['id'], + 'name' => $category['name'], + ]; + + $item['helps'] = []; + + if ($helps->count() > 0) { + foreach ($helps as $help) { + $item['helps'][] = [ + 'id' => $help->id, + 'title' => $help->title, + ]; + } + } + + $result[] = $item; + } + + return $result; } } diff --git a/app/Services/Logic/HelpTrait.php b/app/Services/Logic/HelpTrait.php index da8b73e4..328104f9 100644 --- a/app/Services/Logic/HelpTrait.php +++ b/app/Services/Logic/HelpTrait.php @@ -19,11 +19,4 @@ trait HelpTrait return $validator->checkHelp($id); } - public function checkHelpCache($id) - { - $validator = new HelpValidator(); - - return $validator->checkHelpCache($id); - } - } diff --git a/app/Services/Logic/Notice/External/ConsultReply.php b/app/Services/Logic/Notice/External/ConsultReply.php index 4df0f7ef..a9f89188 100644 --- a/app/Services/Logic/Notice/External/ConsultReply.php +++ b/app/Services/Logic/Notice/External/ConsultReply.php @@ -82,12 +82,7 @@ class ConsultReply extends LogicService $task = new TaskModel(); - $itemInfo = [ - 'consult' => ['id' => $consult->id], - ]; - $task->item_id = $consult->id; - $task->item_info = $itemInfo; $task->item_type = TaskModel::TYPE_NOTICE_CONSULT_REPLY; $task->priority = TaskModel::PRIORITY_LOW; $task->status = TaskModel::STATUS_PENDING; diff --git a/app/Services/Logic/Notice/External/DingTalk/ConsultCreate.php b/app/Services/Logic/Notice/External/DingTalk/ConsultCreate.php index 6ffd9c00..26f176b9 100644 --- a/app/Services/Logic/Notice/External/DingTalk/ConsultCreate.php +++ b/app/Services/Logic/Notice/External/DingTalk/ConsultCreate.php @@ -58,12 +58,7 @@ class ConsultCreate extends DingTalkNotice $task = new TaskModel(); - $itemInfo = [ - 'consult' => ['id' => $consult->id], - ]; - $task->item_id = $consult->id; - $task->item_info = $itemInfo; $task->item_type = TaskModel::TYPE_STAFF_NOTICE_CONSULT_CREATE; $task->priority = TaskModel::PRIORITY_LOW; $task->status = TaskModel::STATUS_PENDING; @@ -71,4 +66,4 @@ class ConsultCreate extends DingTalkNotice $task->create(); } -} \ No newline at end of file +} diff --git a/app/Services/Logic/Notice/External/DingTalk/PointGiftRedeem.php b/app/Services/Logic/Notice/External/DingTalk/PointGiftRedeem.php index 7ca2f9a1..0986f864 100644 --- a/app/Services/Logic/Notice/External/DingTalk/PointGiftRedeem.php +++ b/app/Services/Logic/Notice/External/DingTalk/PointGiftRedeem.php @@ -40,12 +40,7 @@ class PointGiftRedeem extends DingTalkNotice $task = new TaskModel(); - $itemInfo = [ - 'point_gift_redeem' => ['id' => $redeem->id], - ]; - $task->item_id = $redeem->id; - $task->item_info = $itemInfo; $task->item_type = TaskModel::TYPE_STAFF_NOTICE_POINT_GIFT_REDEEM; $task->priority = TaskModel::PRIORITY_MIDDLE; $task->status = TaskModel::STATUS_PENDING; @@ -53,4 +48,4 @@ class PointGiftRedeem extends DingTalkNotice $task->create(); } -} \ No newline at end of file +} diff --git a/app/Services/Logic/Notice/External/DingTalk/TeacherLive.php b/app/Services/Logic/Notice/External/DingTalk/TeacherLive.php index 5f3ac152..2bd196d0 100644 --- a/app/Services/Logic/Notice/External/DingTalk/TeacherLive.php +++ b/app/Services/Logic/Notice/External/DingTalk/TeacherLive.php @@ -42,12 +42,7 @@ class TeacherLive extends DingTalkNotice $task = new TaskModel(); - $itemInfo = [ - 'live' => ['id' => $live->id], - ]; - $task->item_id = $live->id; - $task->item_info = $itemInfo; $task->item_type = TaskModel::TYPE_STAFF_NOTICE_TEACHER_LIVE; $task->priority = TaskModel::PRIORITY_LOW; $task->status = TaskModel::STATUS_PENDING; @@ -55,4 +50,4 @@ class TeacherLive extends DingTalkNotice $task->create(); } -} \ No newline at end of file +} diff --git a/app/Services/Logic/Notice/External/LiveBegin.php b/app/Services/Logic/Notice/External/LiveBegin.php index 0461736c..d3e53144 100644 --- a/app/Services/Logic/Notice/External/LiveBegin.php +++ b/app/Services/Logic/Notice/External/LiveBegin.php @@ -26,7 +26,7 @@ class LiveBegin extends LogicService $smsNoticeEnabled = $this->smsNoticeEnabled(); $courseUser = $task->item_info['course_user']; - $chapterId = $task->item_info['chapter']['id']; + $chapterId = $task->item_id; $courseRepo = new CourseRepo(); @@ -84,9 +84,6 @@ class LiveBegin extends LogicService 'course_id' => $courseUser->course_id, 'user_id' => $courseUser->user_id, ], - 'chapter' => [ - 'id' => $chapter->id, - ], ]; $task->item_id = $chapter->id; diff --git a/app/Services/Logic/Notice/External/OrderFinish.php b/app/Services/Logic/Notice/External/OrderFinish.php index 566b3995..26e431fa 100644 --- a/app/Services/Logic/Notice/External/OrderFinish.php +++ b/app/Services/Logic/Notice/External/OrderFinish.php @@ -67,12 +67,7 @@ class OrderFinish extends LogicService $task = new TaskModel(); - $itemInfo = [ - 'order' => ['id' => $order->id], - ]; - $task->item_id = $order->id; - $task->item_info = $itemInfo; $task->item_type = TaskModel::TYPE_NOTICE_ORDER_FINISH; $task->priority = TaskModel::PRIORITY_HIGH; $task->status = TaskModel::STATUS_PENDING; diff --git a/app/Services/Logic/Notice/External/PointGoodsDeliver.php b/app/Services/Logic/Notice/External/PointGoodsDeliver.php index ab104179..59ccf324 100644 --- a/app/Services/Logic/Notice/External/PointGoodsDeliver.php +++ b/app/Services/Logic/Notice/External/PointGoodsDeliver.php @@ -63,12 +63,7 @@ class PointGoodsDeliver extends LogicService $task = new TaskModel(); - $itemInfo = [ - 'redeem' => ['id' => $redeem->id], - ]; - $task->item_id = $redeem->id; - $task->item_info = $itemInfo; $task->item_type = TaskModel::TYPE_NOTICE_POINT_GOODS_DELIVER; $task->priority = TaskModel::PRIORITY_MIDDLE; $task->status = TaskModel::STATUS_PENDING; diff --git a/app/Services/Logic/Notice/External/RefundFinish.php b/app/Services/Logic/Notice/External/RefundFinish.php index ac9b8a21..bb46c73a 100644 --- a/app/Services/Logic/Notice/External/RefundFinish.php +++ b/app/Services/Logic/Notice/External/RefundFinish.php @@ -67,12 +67,7 @@ class RefundFinish extends LogicService $task = new TaskModel(); - $itemInfo = [ - 'refund' => ['id' => $refund->id], - ]; - $task->item_id = $refund->id; - $task->item_info = $itemInfo; $task->item_type = TaskModel::TYPE_NOTICE_REFUND_FINISH; $task->priority = TaskModel::PRIORITY_MIDDLE; $task->status = TaskModel::STATUS_PENDING; diff --git a/app/Services/Logic/PageTrait.php b/app/Services/Logic/PageTrait.php index ffc6330e..23b1351d 100644 --- a/app/Services/Logic/PageTrait.php +++ b/app/Services/Logic/PageTrait.php @@ -19,11 +19,4 @@ trait PageTrait return $validator->checkPage($id); } - public function checkPageCache($id) - { - $validator = new PageValidator(); - - return $validator->checkPageCache($id); - } - } diff --git a/app/Services/Logic/Point/GiftInfo.php b/app/Services/Logic/Point/GiftInfo.php index 1be4eef6..aa2a4769 100644 --- a/app/Services/Logic/Point/GiftInfo.php +++ b/app/Services/Logic/Point/GiftInfo.php @@ -7,33 +7,44 @@ namespace App\Services\Logic\Point; -use App\Models\PointGift; +use App\Models\PointGift as PointGiftModel; +use App\Models\User as UserModel; use App\Repos\User as UserRepo; +use App\Services\Logic\ContentTrait; use App\Services\Logic\CourseTrait; use App\Services\Logic\PointGiftTrait; use App\Services\Logic\Service as LogicService; +use App\Services\Logic\VipTrait; class GiftInfo extends LogicService { use CourseTrait; + use ContentTrait; use PointGiftTrait; + use VipTrait; public function handle($id) { $gift = $this->checkPointGift($id); - if ($gift->type == PointGift::TYPE_COURSE) { - $gift = $this->getCourseGift($gift); + $user = $this->getCurrentUser(); + + if ($gift->type == PointGiftModel::TYPE_COURSE) { + $gift = $this->handleCoursePointGift($gift); + } elseif ($gift->type == PointGiftModel::TYPE_VIP) { + $gift = $this->handleVipPointGift($gift); } - $meInfo = $this->handleMeInfo($gift); + $details = $this->handleContent($gift->details); + + $meInfo = $this->handleMeInfo($gift, $user); return [ 'id' => $gift->id, 'name' => $gift->name, 'cover' => $gift->cover, - 'details' => $gift->details, + 'details' => $details, 'attrs' => $gift->attrs, 'type' => $gift->type, 'stock' => $gift->stock, @@ -48,43 +59,53 @@ class GiftInfo extends LogicService ]; } - protected function getCourseGift(PointGift $gift) + protected function handleCoursePointGift(PointGiftModel $gift) { - $courseId = $gift->attrs['id'] ?? 0; + $id = $gift->attrs['id'] ?? 0; - $course = $this->checkCourse($courseId); + if ($id == 0) return $gift; + + $course = $this->checkCourse($id); $gift->name = $course->title; $gift->cover = $course->cover; $gift->details = $course->details; - $gift->attrs = [ - 'id' => $course->id, - 'title' => $course->title, - 'price' => $course->market_price, - ]; return $gift; } - protected function handleMeInfo(PointGift $gift) + protected function handleVipPointGift(PointGiftModel $gift) + { + $id = $gift->attrs['id'] ?? 0; + + if ($id == 0) return $gift; + + $vip = $this->checkVip($id); + + $gift->name = sprintf('会员服务(%d个月)', $vip->expiry); + $gift->cover = $vip->cover; + + return $gift; + } + + protected function handleMeInfo(PointGiftModel $gift, UserModel $user) { $me = [ 'allow_redeem' => 0, 'logged' => 0, ]; - $user = $this->getLoginUser(true); + if ($user->id > 0) { - if ($user->id == 0) return $me; + $me['logged'] = 1; - $me['logged'] = 1; + $userRepo = new UserRepo(); - $userRepo = new UserRepo(); + $balance = $userRepo->findUserBalance($user->id); - $balance = $userRepo->findUserBalance($user->id); - - if ($gift->stock > 0 && $balance->point > $gift->point) { - $me['allow_redeem'] = 1; + if ($gift->stock > 0 && $balance->point > $gift->point) { + $me['allow_redeem'] = 1; + } } return $me; diff --git a/app/Services/Logic/PointGiftTrait.php b/app/Services/Logic/PointGiftTrait.php index c81a577e..4390457f 100644 --- a/app/Services/Logic/PointGiftTrait.php +++ b/app/Services/Logic/PointGiftTrait.php @@ -19,11 +19,4 @@ trait PointGiftTrait return $validator->checkPointGift($id); } - public function checkPointGiftCache($id) - { - $validator = new PointGiftValidator(); - - return $validator->checkPointGiftCache($id); - } - } diff --git a/app/Services/Logic/Question/QuestionInfo.php b/app/Services/Logic/Question/QuestionInfo.php index c72d8dcd..cce63e06 100644 --- a/app/Services/Logic/Question/QuestionInfo.php +++ b/app/Services/Logic/Question/QuestionInfo.php @@ -7,13 +7,12 @@ namespace App\Services\Logic\Question; -use App\Caches\Category as CategoryCache; -use App\Models\Category as CategoryModel; use App\Models\Question as QuestionModel; 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\Services\Category as CategoryService; use App\Services\Logic\QuestionTrait; use App\Services\Logic\Service as LogicService; use App\Services\Logic\User\ShallowUserInfo; @@ -41,7 +40,7 @@ class QuestionInfo extends LogicService protected function handleQuestion(QuestionModel $question, UserModel $user) { $lastReplier = $this->handleLastReplierInfo($question->last_replier_id); - $category = $this->handleCategoryInfo($question->category_id); + $categoryPaths = $this->handleCategoryPaths($question->category_id); $owner = $this->handleOwnerInfo($question->owner_id); $me = $this->handleMeInfo($question, $user); @@ -67,32 +66,24 @@ class QuestionInfo extends LogicService 'create_time' => $question->create_time, 'update_time' => $question->update_time, 'last_replier' => $lastReplier, - 'category' => $category, + 'category_paths' => $categoryPaths, 'owner' => $owner, 'me' => $me, ]; } - protected function handleCategoryInfo($categoryId) + protected function handleCategoryPaths($categoryId) { - $cache = new CategoryCache(); + if ($categoryId == 0) return null; - /** - * @var CategoryModel $category - */ - $category = $cache->get($categoryId); + $service = new CategoryService(); - if (!$category) return new \stdClass(); - - return [ - 'id' => $category->id, - 'name' => $category->name, - ]; + return $service->getCategoryPaths($categoryId); } protected function handleLastReplierInfo($userId) { - if ($userId == 0) return new \stdClass(); + if ($userId == 0) return null; $service = new ShallowUserInfo(); diff --git a/app/Services/Logic/Refund/RefundCreate.php b/app/Services/Logic/Refund/RefundCreate.php index b8867dfc..b74f6867 100644 --- a/app/Services/Logic/Refund/RefundCreate.php +++ b/app/Services/Logic/Refund/RefundCreate.php @@ -23,8 +23,6 @@ class RefundCreate extends LogicService public function handle() { - $logger = $this->getLogger('refund'); - $post = $this->request->getPost(); $order = $this->checkOrderBySn($post['order_sn']); @@ -74,13 +72,8 @@ class RefundCreate extends LogicService $task = new TaskModel(); - $itemInfo = [ - 'refund' => ['id' => $refund->id], - ]; - $task->item_id = $refund->id; $task->item_type = TaskModel::TYPE_REFUND; - $task->item_info = $itemInfo; $task->priority = TaskModel::PRIORITY_MIDDLE; $task->status = TaskModel::STATUS_PENDING; @@ -96,6 +89,8 @@ class RefundCreate extends LogicService $this->db->rollback(); + $logger = $this->getLogger('refund'); + $logger->error('Create Refund Exception ' . kg_json_encode([ 'file' => $e->getFile(), 'line' => $e->getLine(), diff --git a/app/Services/Logic/Review/ReviewInfo.php b/app/Services/Logic/Review/ReviewInfo.php index afd811af..77172e04 100644 --- a/app/Services/Logic/Review/ReviewInfo.php +++ b/app/Services/Logic/Review/ReviewInfo.php @@ -63,8 +63,6 @@ class ReviewInfo extends LogicService $course = $courseRepo->findById($courseId); - if (!$course) return new \stdClass(); - return [ 'id' => $course->id, 'title' => $course->title, diff --git a/app/Services/Logic/Search/Article.php b/app/Services/Logic/Search/Article.php index 0197a3ac..fc49f0a5 100644 --- a/app/Services/Logic/Search/Article.php +++ b/app/Services/Logic/Search/Article.php @@ -68,12 +68,6 @@ class Article extends Handler $owner = json_decode($item['owner'], true); $tags = json_decode($item['tags'], true); - $owner['avatar'] = $owner['avatar'] ?: kg_default_user_avatar_path(); - - if (!empty($owner['avatar']) && !Text::startsWith($owner['avatar'], 'http')) { - $owner['avatar'] = $baseUrl . $owner['avatar']; - } - if (!empty($item['cover']) && !Text::startsWith($item['cover'], 'http')) { $item['cover'] = $baseUrl . $item['cover']; } diff --git a/app/Services/Logic/Search/Course.php b/app/Services/Logic/Search/Course.php index 0926573f..1ee9e493 100644 --- a/app/Services/Logic/Search/Course.php +++ b/app/Services/Logic/Search/Course.php @@ -73,12 +73,6 @@ class Course extends Handler $teacher = json_decode($item['teacher'], true); $tags = json_decode($item['tags'], true); - $teacher['avatar'] = $teacher['avatar'] ?: kg_default_user_avatar_path(); - - if (!empty($teacher['avatar']) && !Text::startsWith($teacher['avatar'], 'http')) { - $teacher['avatar'] = $baseUrl . $teacher['avatar']; - } - if (!empty($item['cover']) && !Text::startsWith($item['cover'], 'http')) { $item['cover'] = $baseUrl . $item['cover']; } diff --git a/app/Services/Logic/Search/Question.php b/app/Services/Logic/Search/Question.php index a8788988..0f6db7d4 100644 --- a/app/Services/Logic/Search/Question.php +++ b/app/Services/Logic/Search/Question.php @@ -64,33 +64,17 @@ class Question extends Handler foreach ($pager->items as $item) { + $lastAnswer = json_decode($item['last_answer'], true); + $acceptAnswer = json_decode($item['accept_answer'], true); $lastReplier = json_decode($item['last_replier'], true); $category = json_decode($item['category'], true); $owner = json_decode($item['owner'], true); $tags = json_decode($item['tags'], true); - $owner['avatar'] = $owner['avatar'] ?: kg_default_user_avatar_path(); - - if (!empty($owner['avatar']) && !Text::startsWith($owner['avatar'], 'http')) { - $owner['avatar'] = $baseUrl . $owner['avatar']; - } - if (!empty($item['cover']) && !Text::startsWith($item['cover'], 'http')) { $item['cover'] = $baseUrl . $item['cover']; } - $lastAnswer = json_decode($item['last_answer'], true); - - if (!empty($lastAnswer['cover']) && !Text::startsWith($lastAnswer['cover'], 'http')) { - $lastAnswer['cover'] = $baseUrl . $lastAnswer['cover']; - } - - $acceptAnswer = json_decode($item['accept_answer'], true); - - if (!empty($acceptAnswer['cover']) && !Text::startsWith($acceptAnswer['cover'], 'http')) { - $acceptAnswer['cover'] = $baseUrl . $acceptAnswer['cover']; - } - $items[] = [ 'id' => (int)$item['id'], 'title' => (string)$item['title'], diff --git a/app/Services/Logic/Trade/TradeInfo.php b/app/Services/Logic/Trade/TradeInfo.php index bd06ffe4..c8d51873 100644 --- a/app/Services/Logic/Trade/TradeInfo.php +++ b/app/Services/Logic/Trade/TradeInfo.php @@ -26,7 +26,7 @@ class TradeInfo extends LogicService { $trade = $this->checkTradeBySn($sn); - $user = $this->getCurrentUser(); + $user = $this->getLoginUser(true); return $this->handleTrade($trade, $user); } diff --git a/app/Services/Logic/User/Console/ProfileInfo.php b/app/Services/Logic/User/Console/ProfileInfo.php index 3fdafc7b..910a5938 100644 --- a/app/Services/Logic/User/Console/ProfileInfo.php +++ b/app/Services/Logic/User/Console/ProfileInfo.php @@ -22,8 +22,6 @@ class ProfileInfo extends LogicService protected function handleUser(UserModel $user) { - $user->avatar = kg_cos_user_avatar_url($user->avatar); - $user->area = $this->handleArea($user->area); return [ diff --git a/app/Services/Logic/VipTrait.php b/app/Services/Logic/VipTrait.php new file mode 100644 index 00000000..76c42883 --- /dev/null +++ b/app/Services/Logic/VipTrait.php @@ -0,0 +1,22 @@ +checkVip($id); + } + +} diff --git a/app/Services/Search/ArticleDocument.php b/app/Services/Search/ArticleDocument.php index 659044f4..9e5a8ae2 100644 --- a/app/Services/Search/ArticleDocument.php +++ b/app/Services/Search/ArticleDocument.php @@ -41,7 +41,7 @@ class ArticleDocument extends Injectable */ public function formatDocument(ArticleModel $article) { - if (is_array($article->tags) || is_object($article->tags)) { + if (is_array($article->tags)) { $article->tags = kg_json_encode($article->tags); } @@ -57,6 +57,8 @@ class ArticleDocument extends Injectable $category = $this->handleCategory($article->category_id); } + $article->cover = ArticleModel::getCoverPath($article->cover); + return [ 'id' => $article->id, 'title' => $article->title, @@ -81,12 +83,9 @@ class ArticleDocument extends Injectable $user = $userRepo->findById($id); - $user->avatar = UserModel::getAvatarPath($user->avatar); - return kg_json_encode([ 'id' => $user->id, 'name' => $user->name, - 'avatar' => $user->avatar, ]); } diff --git a/app/Services/Search/CourseDocument.php b/app/Services/Search/CourseDocument.php index b38d356f..23cd55f4 100644 --- a/app/Services/Search/CourseDocument.php +++ b/app/Services/Search/CourseDocument.php @@ -41,11 +41,11 @@ class CourseDocument extends Injectable */ public function formatDocument(CourseModel $course) { - if (is_array($course->attrs) || is_object($course->attrs)) { + if (is_array($course->attrs)) { $course->attrs = kg_json_encode($course->attrs); } - if (is_array($course->tags) || is_object($course->tags)) { + if (is_array($course->tags)) { $course->tags = kg_json_encode($course->tags); } @@ -102,12 +102,9 @@ class CourseDocument extends Injectable $user = $userRepo->findById($id); - $user->avatar = UserModel::getAvatarPath($user->avatar); - return kg_json_encode([ 'id' => $user->id, 'name' => $user->name, - 'avatar' => $user->avatar, ]); } diff --git a/app/Services/Search/QuestionDocument.php b/app/Services/Search/QuestionDocument.php index 3c8a5e2a..7920f542 100644 --- a/app/Services/Search/QuestionDocument.php +++ b/app/Services/Search/QuestionDocument.php @@ -42,7 +42,7 @@ class QuestionDocument extends Injectable */ public function formatDocument(QuestionModel $question) { - if (is_array($question->tags) || is_object($question->tags)) { + if (is_array($question->tags)) { $question->tags = kg_json_encode($question->tags); } @@ -76,6 +76,8 @@ class QuestionDocument extends Injectable $acceptAnswer = $this->handleAnswer($question->accept_answer_id); } + $question->cover = QuestionModel::getCoverPath($question->cover); + return [ 'id' => $question->id, 'title' => $question->title, @@ -108,12 +110,9 @@ class QuestionDocument extends Injectable $user = $userRepo->findById($id); - $user->avatar = UserModel::getAvatarPath($user->avatar); - return kg_json_encode([ 'id' => $user->id, 'name' => $user->name, - 'avatar' => $user->avatar, ]); } @@ -138,7 +137,6 @@ class QuestionDocument extends Injectable return kg_json_encode([ 'id' => $answer->id, 'summary' => $answer->summary, - 'cover' => $answer->cover, ]); } diff --git a/app/Validators/Answer.php b/app/Validators/Answer.php index 73cfe297..b71a5dd5 100644 --- a/app/Validators/Answer.php +++ b/app/Validators/Answer.php @@ -7,11 +7,9 @@ namespace App\Validators; -use App\Caches\MaxAnswerId as MaxAnswerIdCache; use App\Exceptions\BadRequest as BadRequestException; use App\Models\Answer as AnswerModel; use App\Models\Question as QuestionModel; -use App\Models\Reason as ReasonModel; use App\Models\User as UserModel; use App\Repos\Answer as AnswerRepo; use App\Repos\Question as QuestionRepo; @@ -22,8 +20,6 @@ class Answer extends Validator public function checkAnswer($id) { - $this->checkId($id); - $answerRepo = new AnswerRepo(); $answer = $answerRepo->findById($id); @@ -35,19 +31,6 @@ class Answer extends Validator return $answer; } - public function checkId($id) - { - $id = intval($id); - - $maxIdCache = new MaxAnswerIdCache(); - - $maxId = $maxIdCache->get(); - - if ($id < 1 || $id > $maxId) { - throw new BadRequestException('answer.not_found'); - } - } - public function checkQuestion($id) { $validator = new Question(); diff --git a/app/Validators/Course.php b/app/Validators/Course.php index 5b8d521a..2a3ad61c 100644 --- a/app/Validators/Course.php +++ b/app/Validators/Course.php @@ -66,18 +66,26 @@ class Course extends Validator } } - public function checkCategory($id) + public function checkCategoryId($id) { - $validator = new Category(); - - return $validator->checkCategory($id); + if ($id > 0) { + $validator = new Category(); + $category = $validator->checkCategory($id); + return $category->id; + } else { + return 0; + } } - public function checkTeacher($id) + public function checkTeacherId($id) { - $validator = new User(); - - return $validator->checkUser($id); + if ($id > 0) { + $validator = new User(); + $user = $validator->checkTeacher($id); + return $user->id; + } else { + return 0; + } } public function checkModel($model) diff --git a/app/Validators/Help.php b/app/Validators/Help.php index a1356f5a..63b715f7 100644 --- a/app/Validators/Help.php +++ b/app/Validators/Help.php @@ -7,36 +7,13 @@ namespace App\Validators; -use App\Caches\Help as HelpCache; -use App\Caches\MaxHelpId as MaxHelpIdCache; use App\Exceptions\BadRequest as BadRequestException; -use App\Models\Help as HelpModel; use App\Repos\Help as HelpRepo; use App\Services\EditorStorage as EditorStorageService; class Help extends Validator { - /** - * @param int $id - * @return HelpModel - * @throws BadRequestException - */ - public function checkHelpCache($id) - { - $this->checkId($id); - - $helpCache = new HelpCache(); - - $help = $helpCache->get($id); - - if (!$help) { - throw new BadRequestException('help.not_found'); - } - - return $help; - } - public function checkHelp($id) { $helpRepo = new HelpRepo(); @@ -50,19 +27,6 @@ class Help extends Validator return $help; } - public function checkId($id) - { - $id = intval($id); - - $maxIdCache = new MaxHelpIdCache(); - - $maxId = $maxIdCache->get(); - - if ($id < 1 || $id > $maxId) { - throw new BadRequestException('help.not_found'); - } - } - public function checkCategory($id) { $validator = new Category(); diff --git a/app/Validators/Page.php b/app/Validators/Page.php index 7bf04814..bd9740f0 100644 --- a/app/Validators/Page.php +++ b/app/Validators/Page.php @@ -7,37 +7,14 @@ namespace App\Validators; -use App\Caches\MaxPageId as MaxPageIdCache; -use App\Caches\Page as PageCache; use App\Exceptions\BadRequest as BadRequestException; use App\Library\Validators\Common as CommonValidator; -use App\Models\Page as PageModel; use App\Repos\Page as PageRepo; use App\Services\EditorStorage as EditorStorageService; class Page extends Validator { - /** - * @param int $id - * @return PageModel - * @throws BadRequestException - */ - public function checkPageCache($id) - { - $this->checkId($id); - - $pageCache = new PageCache(); - - $page = $pageCache->get($id); - - if (!$page) { - throw new BadRequestException('page.not_found'); - } - - return $page; - } - public function checkPage($id) { $pageRepo = new PageRepo(); @@ -55,19 +32,6 @@ class Page extends Validator return $page; } - public function checkId($id) - { - $id = intval($id); - - $maxIdCache = new MaxPageIdCache(); - - $maxId = $maxIdCache->get(); - - if ($id < 1 || $id > $maxId) { - throw new BadRequestException('page.not_found'); - } - } - public function checkTitle($title) { $value = $this->filter->sanitize($title, ['trim', 'string']); diff --git a/app/Validators/PointGift.php b/app/Validators/PointGift.php index 99d7de0f..0f0c7995 100644 --- a/app/Validators/PointGift.php +++ b/app/Validators/PointGift.php @@ -7,8 +7,6 @@ namespace App\Validators; -use App\Caches\MaxPointGiftId as MaxPointGiftIdCache; -use App\Caches\PointGift as PointGiftCache; use App\Exceptions\BadRequest as BadRequestException; use App\Library\Validators\Common as CommonValidator; use App\Models\PointGift as PointGiftModel; @@ -18,30 +16,8 @@ use App\Services\EditorStorage as EditorStorageService; class PointGift extends Validator { - /** - * @param int $id - * @return PointGiftModel - * @throws BadRequestException - */ - public function checkPointGiftCache($id) - { - $this->checkId($id); - - $giftCache = new PointGiftCache(); - - $gift = $giftCache->get($id); - - if (!$gift) { - throw new BadRequestException('point_gift.not_found'); - } - - return $gift; - } - public function checkPointGift($id) { - $this->checkId($id); - $giftRepo = new PointGiftRepo(); $gift = $giftRepo->findById($id); @@ -53,19 +29,6 @@ class PointGift extends Validator return $gift; } - public function checkId($id) - { - $id = intval($id); - - $maxGiftIdCache = new MaxPointGiftIdCache(); - - $maxId = $maxGiftIdCache->get(); - - if ($id < 1 || $id > $maxId) { - throw new BadRequestException('point_gift.not_found'); - } - } - public function checkName($name) { $value = $this->filter->sanitize($name, ['trim', 'string']); diff --git a/app/Validators/Resource.php b/app/Validators/Resource.php index 1dde9981..ee02329c 100644 --- a/app/Validators/Resource.php +++ b/app/Validators/Resource.php @@ -33,13 +33,6 @@ class Resource extends Validator return $validator->checkCourse($id); } - public function checkChapter($id) - { - $validator = new Chapter(); - - return $validator->checkChapter($id); - } - public function checkUpload($id) { $validator = new Upload(); diff --git a/app/Validators/Upload.php b/app/Validators/Upload.php index e7530738..257a9e88 100644 --- a/app/Validators/Upload.php +++ b/app/Validators/Upload.php @@ -7,7 +7,6 @@ namespace App\Validators; -use App\Caches\MaxUploadId as MaxUploadIdCache; use App\Exceptions\BadRequest as BadRequestException; use App\Repos\Upload as UploadRepo; @@ -16,8 +15,6 @@ class Upload extends Validator public function checkUpload($id) { - $this->checkId($id); - $uploadRepo = new UploadRepo(); $upload = $uploadRepo->findById($id); @@ -29,19 +26,6 @@ class Upload extends Validator return $upload; } - public function checkId($id) - { - $id = intval($id); - - $maxIdCache = new MaxUploadIdCache(); - - $maxId = $maxIdCache->get(); - - if ($id < 1 || $id > $maxId) { - throw new BadRequestException('upload.not_found'); - } - } - public function checkName($name) { $value = $this->filter->sanitize($name, ['trim', 'string']); diff --git a/app/Validators/User.php b/app/Validators/User.php index 40155790..e070d383 100644 --- a/app/Validators/User.php +++ b/app/Validators/User.php @@ -53,6 +53,19 @@ class User extends Validator return $user; } + public function checkTeacher($id) + { + $validator = new User(); + + $user = $validator->checkUser($id); + + if ($user->edu_role != UserModel::EDU_ROLE_TEACHER) { + throw new BadRequestException('user.not_found'); + } + + return $user; + } + public function checkId($id) { $id = intval($id); diff --git a/bootstrap/ConsoleKernel.php b/bootstrap/ConsoleKernel.php index d44470d0..63546f64 100644 --- a/bootstrap/ConsoleKernel.php +++ b/bootstrap/ConsoleKernel.php @@ -31,10 +31,9 @@ class ConsoleKernel extends Kernel $this->loader = new Loader(); $this->initAppEnv(); - $this->initAppConfig(); - $this->initAppSetting(); $this->registerLoaders(); $this->registerServices(); + $this->registerSettings(); $this->registerErrorHandler(); } diff --git a/bootstrap/HttpKernel.php b/bootstrap/HttpKernel.php index 06aa8ba4..7ab1a463 100644 --- a/bootstrap/HttpKernel.php +++ b/bootstrap/HttpKernel.php @@ -40,11 +40,10 @@ class HttpKernel extends Kernel $this->loader = new Loader(); $this->initAppEnv(); - $this->initAppConfig(); - $this->initAppSetting(); $this->registerLoaders(); $this->registerServices(); $this->registerModules(); + $this->registerSettings(); $this->registerErrorHandler(); } diff --git a/bootstrap/Kernel.php b/bootstrap/Kernel.php index e4650f57..fe84b175 100644 --- a/bootstrap/Kernel.php +++ b/bootstrap/Kernel.php @@ -8,6 +8,7 @@ namespace Bootstrap; use Phalcon\Application; +use Phalcon\Config; use Phalcon\Di; use Phalcon\Loader; @@ -29,36 +30,21 @@ abstract class Kernel */ protected $loader; - /** - * @var array - */ - protected $config = []; - - public function getApp() - { - return $this->app; - } - - public function getDI() - { - return $this->di; - } - protected function initAppEnv() { require __DIR__ . '/Helper.php'; } - protected function initAppConfig() + protected function registerSettings() { - $this->config = require config_path('config.php'); - } + /** + * @var Config $config + */ + $config = $this->di->getShared('config'); - protected function initAppSetting() - { - ini_set('date.timezone', $this->config['timezone']); + ini_set('date.timezone', $config->get('timezone')); - if ($this->config['env'] == ENV_DEV) { + if ($config->get('env') == ENV_DEV) { ini_set('display_errors', 1); error_reporting(E_ALL); } else {