diff --git a/README.md b/README.md index a9d3c94d..ab93e614 100644 --- a/README.md +++ b/README.md @@ -84,5 +84,5 @@ Tips: 请用手机注册一个新账号,用户中心 -> 关注订阅,扫码 ### 开源助力 -毫无保留的真开源不容易,如果对你有帮助,请给我们 **STAR** !!! +毫无保留的真开源不容易,不要吝啬您的赞许和鼓励,请给我们 **STAR** !!! diff --git a/app/Caches/App.php b/app/Caches/App.php deleted file mode 100644 index 479ca191..00000000 --- a/app/Caches/App.php +++ /dev/null @@ -1,31 +0,0 @@ -lifetime; - } - - public function getKey($id = null) - { - return "app:{$id}"; - } - - public function getContent($id = null) - { - $appRepo = new AppRepo(); - - $result = $appRepo->findByAppKey($id); - - return $result ?: null; - } - -} diff --git a/app/Caches/AppInfo.php b/app/Caches/AppInfo.php new file mode 100644 index 00000000..ec5dfd00 --- /dev/null +++ b/app/Caches/AppInfo.php @@ -0,0 +1,32 @@ +lifetime; + } + + public function getKey($id = null) + { + return "_APP_INFO_"; + } + + public function getContent($id = null) + { + $appInfo = new \App\Library\AppInfo(); + + return [ + 'name' => $appInfo->name, + 'alias' => $appInfo->alias, + 'link' => $appInfo->link, + 'version' => $appInfo->version, + ]; + } + +} diff --git a/app/Console/Tasks/VodEventTask.php b/app/Console/Tasks/VodEventTask.php index 49d86fc7..d752c46a 100644 --- a/app/Console/Tasks/VodEventTask.php +++ b/app/Console/Tasks/VodEventTask.php @@ -44,10 +44,12 @@ class VodEventTask extends Task protected function handleNewFileUploadEvent($event) { - $fileId = $event['FileUploadEvent']['FileId']; - $width = $event['FileUploadEvent']['MetaData']['Height']; - $height = $event['FileUploadEvent']['MetaData']['Width']; - $duration = $event['FileUploadEvent']['MetaData']['Duration']; + $fileId = $event['FileUploadEvent']['FileId'] ?? 0; + $width = $event['FileUploadEvent']['MetaData']['Height'] ?? 0; + $height = $event['FileUploadEvent']['MetaData']['Width'] ?? 0; + $duration = $event['FileUploadEvent']['MetaData']['Duration'] ?? 0; + + if ($fileId == 0) return; $chapterRepo = new ChapterRepo(); @@ -55,6 +57,18 @@ class VodEventTask extends Task if (!$chapter) return; + $attrs = $chapter->attrs; + + /** + * 获取不到时长视为失败 + */ + if ($duration == 0) { + $attrs['file']['id'] = $fileId; + $attrs['file']['status'] = ChapterModel::FS_FAILED; + $chapter->update(['attrs' => $attrs]); + return; + } + $vodService = new VodService(); if ($width == 0 && $height == 0) { @@ -63,13 +77,8 @@ class VodEventTask extends Task $vodService->createTransVideoTask($fileId); } - /** - * @var array $attrs - */ - $attrs = $chapter->attrs; - + $attrs['file']['id'] = $fileId; $attrs['file']['status'] = ChapterModel::FS_TRANSLATING; - $attrs['duration'] = (int)$duration; $chapter->update(['attrs' => $attrs]); @@ -79,9 +88,9 @@ class VodEventTask extends Task protected function handleProcedureStateChangedEvent($event) { - $fileId = $event['ProcedureStateChangeEvent']['FileId']; + $fileId = $event['ProcedureStateChangeEvent']['FileId'] ?? 0; - $processResult = $event['ProcedureStateChangeEvent']['MediaProcessResultSet']; + if ($fileId == 0) return; $chapterRepo = new ChapterRepo(); @@ -89,6 +98,20 @@ class VodEventTask extends Task if (!$chapter) return; + $attrs = $chapter->attrs; + + $processResult = $event['ProcedureStateChangeEvent']['MediaProcessResultSet'] ?? []; + + /** + * 获取不到处理结果视为失败 + */ + if (empty($processResult)) { + $attrs['file']['id'] = $fileId; + $attrs['file']['status'] = ChapterModel::FS_FAILED; + $chapter->update(['attrs' => $attrs]); + return; + } + $failCount = $successCount = 0; foreach ($processResult as $item) { @@ -112,15 +135,9 @@ class VodEventTask extends Task $fileStatus = ChapterModel::FS_FAILED; } - if ($fileStatus == ChapterModel::FS_TRANSLATING) { - return; - } - - /** - * @var array $attrs - */ - $attrs = $chapter->attrs; + if ($fileStatus == ChapterModel::FS_TRANSLATING) return; + $attrs['file']['id'] = $fileId; $attrs['file']['status'] = $fileStatus; $chapter->update(['attrs' => $attrs]); diff --git a/app/Http/Admin/Services/Answer.php b/app/Http/Admin/Services/Answer.php index 4eda7f57..ea79042b 100644 --- a/app/Http/Admin/Services/Answer.php +++ b/app/Http/Admin/Services/Answer.php @@ -14,6 +14,7 @@ use App\Repos\Answer as AnswerRepo; use App\Repos\Question as QuestionRepo; use App\Repos\Report as ReportRepo; use App\Repos\User as UserRepo; +use App\Services\Logic\Answer\AnswerDataTrait; use App\Services\Logic\Answer\AnswerInfo as AnswerInfoService; use App\Services\Logic\Notice\System\AnswerApproved as AnswerApprovedNotice; use App\Services\Logic\Notice\System\AnswerRejected as AnswerRejectedNotice; @@ -24,6 +25,8 @@ use App\Validators\Answer as AnswerValidator; class Answer extends Service { + use AnswerDataTrait; + public function getPublishTypes() { return AnswerModel::publishTypes(); @@ -94,13 +97,16 @@ class Answer extends Service $answer = new AnswerModel(); - $answer->owner_id = $user->id; - $answer->question_id = $question->id; $answer->published = AnswerModel::PUBLISH_APPROVED; + $answer->client_type = $this->getClientType(); + $answer->client_ip = $this->getClientIp(); $answer->content = $validator->checkContent($post['content']); + $answer->question_id = $question->id; + $answer->owner_id = $user->id; $answer->create(); + $this->saveDynamicAttrs($answer); $this->recountQuestionAnswers($question); $this->recountUserAnswers($user); $this->handleAnswerPostPoint($answer); @@ -126,20 +132,21 @@ class Answer extends Service } if (isset($post['published'])) { - $data['published'] = $validator->checkPublishStatus($post['published']); - - $question = $this->findQuestion($answer->question_id); - - $this->recountQuestionAnswers($question); - - $user = $this->findUser($answer->owner_id); - - $this->recountUserAnswers($user); } $answer->update($data); + $this->saveDynamicAttrs($answer); + + $question = $this->findQuestion($answer->question_id); + + $this->recountQuestionAnswers($question); + + $owner = $this->findUser($answer->owner_id); + + $this->recountUserAnswers($owner); + $this->eventsManager->fire('Answer:afterUpdate', $this, $answer); return $answer; diff --git a/app/Http/Admin/Services/Article.php b/app/Http/Admin/Services/Article.php index 5af24563..5bbc16eb 100644 --- a/app/Http/Admin/Services/Article.php +++ b/app/Http/Admin/Services/Article.php @@ -15,10 +15,10 @@ use App\Models\User as UserModel; use App\Repos\Article as ArticleRepo; use App\Repos\Category as CategoryRepo; use App\Repos\Report as ReportRepo; -use App\Repos\Tag as TagRepo; use App\Repos\User as UserRepo; use App\Services\Logic\Article\ArticleDataTrait; use App\Services\Logic\Article\ArticleInfo as ArticleInfoService; +use App\Services\Logic\Article\XmTagList as XmTagListService; use App\Services\Logic\Notice\System\ArticleApproved as ArticleApprovedNotice; use App\Services\Logic\Notice\System\ArticleRejected as ArticleRejectedNotice; use App\Services\Logic\Point\History\ArticlePost as ArticlePostPointHistory; @@ -32,33 +32,9 @@ class Article extends Service public function getXmTags($id) { - $tagRepo = new TagRepo(); + $service = new XmTagListService(); - $allTags = $tagRepo->findAll(['published' => 1]); - - if ($allTags->count() == 0) return []; - - $articleTagIds = []; - - if ($id > 0) { - $article = $this->findOrFail($id); - if (!empty($article->tags)) { - $articleTagIds = kg_array_column($article->tags, 'id'); - } - } - - $list = []; - - foreach ($allTags as $tag) { - $selected = in_array($tag->id, $articleTagIds); - $list[] = [ - 'name' => $tag->name, - 'value' => $tag->id, - 'selected' => $selected, - ]; - } - - return $list; + return $service->handle($id); } public function getCategories() @@ -152,11 +128,15 @@ class Article extends Service $article = new ArticleModel(); $article->published = ArticleModel::PUBLISH_APPROVED; + $article->client_type = $this->getClientType(); + $article->client_ip = $this->getClientIp(); $article->owner_id = $user->id; $article->title = $title; $article->create(); + $this->saveDynamicAttrs($article); + $this->recountUserArticles($user); $this->eventsManager->fire('Article:afterCreate', $this, $article); @@ -208,12 +188,7 @@ class Article extends Service } if (isset($post['published'])) { - $data['published'] = $validator->checkPublishStatus($post['published']); - - $owner = $this->findUser($article->owner_id); - - $this->recountUserArticles($owner); } if (isset($post['xm_tag_ids'])) { @@ -222,8 +197,14 @@ class Article extends Service $article->update($data); + $this->saveDynamicAttrs($article); + $this->rebuildArticleIndex($article); + $owner = $this->findUser($article->owner_id); + + $this->recountUserArticles($owner); + $this->eventsManager->fire('Article:afterUpdate', $this, $article); return $article; @@ -237,14 +218,14 @@ class Article extends Service $article->update(); - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($article->owner_id); - - $this->recountUserArticles($owner); + $this->saveDynamicAttrs($article); $this->rebuildArticleIndex($article); + $owner = $this->findUser($article->owner_id); + + $this->recountUserArticles($owner); + $this->eventsManager->fire('Article:afterDelete', $this, $article); return $article; @@ -258,14 +239,14 @@ class Article extends Service $article->update(); - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($article->owner_id); - - $this->recountUserArticles($owner); + $this->saveDynamicAttrs($article); $this->rebuildArticleIndex($article); + $owner = $this->findUser($article->owner_id); + + $this->recountUserArticles($owner); + $this->eventsManager->fire('Article:afterRestore', $this, $article); return $article; diff --git a/app/Http/Admin/Services/AuthMenu.php b/app/Http/Admin/Services/AuthMenu.php index 1d69cd21..89ec4be7 100644 --- a/app/Http/Admin/Services/AuthMenu.php +++ b/app/Http/Admin/Services/AuthMenu.php @@ -10,7 +10,6 @@ class AuthMenu extends Component protected $authInfo; protected $authNodes = []; - protected $ownedRoutes = []; protected $owned1stLevelIds = []; protected $owned2ndLevelIds = []; protected $owned3rdLevelIds = []; diff --git a/app/Http/Admin/Services/AuthNode.php b/app/Http/Admin/Services/AuthNode.php index 952d795b..e2735bc7 100644 --- a/app/Http/Admin/Services/AuthNode.php +++ b/app/Http/Admin/Services/AuthNode.php @@ -530,7 +530,7 @@ class AuthNode extends Service ], ], [ - 'id' => '2-10', + 'id' => '2-11', 'title' => '举报队列', 'type' => 'menu', 'children' => [ diff --git a/app/Http/Admin/Services/Index.php b/app/Http/Admin/Services/Index.php index 32e0e39b..2302b631 100644 --- a/app/Http/Admin/Services/Index.php +++ b/app/Http/Admin/Services/Index.php @@ -2,8 +2,9 @@ namespace App\Http\Admin\Services; -use App\Caches\SiteGlobalStat; -use App\Caches\SiteTodayStat; +use App\Caches\AppInfo as AppInfoCache; +use App\Caches\SiteGlobalStat as SiteGlobalStatCache; +use App\Caches\SiteTodayStat as SiteTodayStatCache; use App\Library\AppInfo; use App\Library\Utils\ServerInfo; use App\Repos\Stat as StatRepo; @@ -28,7 +29,17 @@ class Index extends Service public function getAppInfo() { - return new AppInfo(); + $cache = new AppInfoCache(); + + $content = $cache->get(); + + $appInfo = new AppInfo(); + + if ($appInfo->version != $content['version']) { + $cache->rebuild(); + } + + return $appInfo; } public function getServerInfo() @@ -42,14 +53,14 @@ class Index extends Service public function getGlobalStat() { - $cache = new SiteGlobalStat(); + $cache = new SiteGlobalStatCache(); return $cache->get(); } public function getTodayStat() { - $cache = new SiteTodayStat(); + $cache = new SiteTodayStatCache(); return $cache->get(); } diff --git a/app/Http/Admin/Services/Question.php b/app/Http/Admin/Services/Question.php index 61d7f368..bf0a8249 100644 --- a/app/Http/Admin/Services/Question.php +++ b/app/Http/Admin/Services/Question.php @@ -14,13 +14,13 @@ use App\Models\User as UserModel; use App\Repos\Category as CategoryRepo; use App\Repos\Question as QuestionRepo; use App\Repos\Report as ReportRepo; -use App\Repos\Tag as TagRepo; use App\Repos\User as UserRepo; use App\Services\Logic\Notice\System\QuestionApproved as QuestionApprovedNotice; use App\Services\Logic\Notice\System\QuestionRejected as QuestionRejectedNotice; use App\Services\Logic\Point\History\QuestionPost as QuestionPostPointHistory; use App\Services\Logic\Question\QuestionDataTrait; use App\Services\Logic\Question\QuestionInfo as QuestionInfoService; +use App\Services\Logic\Question\XmTagList as XmTagListService; use App\Services\Sync\QuestionIndex as QuestionIndexSync; use App\Validators\Question as QuestionValidator; @@ -31,33 +31,9 @@ class Question extends Service public function getXmTags($id) { - $tagRepo = new TagRepo(); + $service = new XmTagListService(); - $allTags = $tagRepo->findAll(['published' => 1]); - - if ($allTags->count() == 0) return []; - - $questionTagIds = []; - - if ($id > 0) { - $question = $this->findOrFail($id); - if (!empty($question->tags)) { - $questionTagIds = kg_array_column($question->tags, 'id'); - } - } - - $list = []; - - foreach ($allTags as $tag) { - $selected = in_array($tag->id, $questionTagIds); - $list[] = [ - 'name' => $tag->name, - 'value' => $tag->id, - 'selected' => $selected, - ]; - } - - return $list; + return $service->handle($id); } public function getCategories() @@ -146,11 +122,15 @@ class Question extends Service $question = new QuestionModel(); $question->published = QuestionModel::PUBLISH_APPROVED; + $question->client_type = $this->getClientType(); + $question->client_ip = $this->getClientIp(); $question->owner_id = $user->id; $question->title = $title; $question->create(); + $this->saveDynamicAttrs($question); + $this->recountUserQuestions($user); $this->eventsManager->fire('Question:afterCreate', $this, $question); @@ -190,12 +170,7 @@ class Question extends Service } if (isset($post['published'])) { - $data['published'] = $validator->checkPublishStatus($post['published']); - - $owner = $this->findUser($question->owner_id); - - $this->recountUserQuestions($owner); } if (isset($post['xm_tag_ids'])) { @@ -204,8 +179,14 @@ class Question extends Service $question->update($data); + $this->saveDynamicAttrs($question); + $this->rebuildQuestionIndex($question); + $owner = $this->findUser($question->owner_id); + + $this->recountUserQuestions($owner); + $this->eventsManager->fire('Question:afterUpdate', $this, $question); return $question; @@ -219,14 +200,14 @@ class Question extends Service $question->update(); - $userRepo = new UserRepo(); - - $owner = $userRepo->findById($question->owner_id); - - $this->recountUserQuestions($owner); + $this->saveDynamicAttrs($question); $this->rebuildQuestionIndex($question); + $owner = $this->findUser($question->owner_id); + + $this->recountUserQuestions($owner); + $this->eventsManager->fire('Question:afterDelete', $this, $question); return $question; @@ -240,14 +221,12 @@ class Question extends Service $question->update(); - $userRepo = new UserRepo(); + $this->rebuildQuestionIndex($question); - $owner = $userRepo->findById($question->owner_id); + $owner = $this->findUser($question->owner_id); $this->recountUserQuestions($owner); - $this->rebuildQuestionIndex($question); - $this->eventsManager->fire('Question:afterRestore', $this, $question); return $question; diff --git a/app/Http/Admin/Views/article/edit_basic.volt b/app/Http/Admin/Views/article/edit_basic.volt index ebf4ea31..05659162 100644 --- a/app/Http/Admin/Views/article/edit_basic.volt +++ b/app/Http/Admin/Views/article/edit_basic.volt @@ -50,4 +50,4 @@ - \ No newline at end of file + diff --git a/app/Http/Admin/Views/category/list.volt b/app/Http/Admin/Views/category/list.volt index 1eab62ac..f4d7b5d1 100644 --- a/app/Http/Admin/Views/category/list.volt +++ b/app/Http/Admin/Views/category/list.volt @@ -4,7 +4,7 @@ {% set back_url = url({'for':'admin.category.list'},{'type':type}) %} {% set add_url = url({'for':'admin.category.add'},{'type':type,'parent_id':parent.id}) %} - {% set allow_add = (type == 1 and parent.level < 2) or (type == 2 and parent.level < 1) or (type == 3 and parent.level < 1) %} + {% set allow_add = (type == 1 and parent.level < 2) or (type == 2 and parent.level < 1) %}
@@ -55,14 +55,12 @@ {{ item.id }} {% if item.type == 1 %} {% if item.level == 1 %} - {{ item.name }} + {{ item.name }} {% else %} {{ item.name }} {% endif %} {% elseif item.type == 2 %} {{ item.name }} - {% elseif item.type == 3 %} - {{ item.name }} {% endif %} {{ item.level }} {{ item.child_count }} diff --git a/app/Http/Admin/Views/question/list.volt b/app/Http/Admin/Views/question/list.volt index dca7fe5c..168e7fe9 100644 --- a/app/Http/Admin/Views/question/list.volt +++ b/app/Http/Admin/Views/question/list.volt @@ -87,8 +87,8 @@
  • 审核问题
  • {% elseif item.published == 2 %}
  • 预览问题
  • +
  • 回答问题
  • {% endif %} -
  • 回答问题
  • 编辑问题
  • {% if item.deleted == 0 %}
  • 删除问题
  • @@ -128,7 +128,7 @@ $.ajax({ type: 'POST', url: url, - data: {closed: data.value}, + data: {closed: closed}, success: function (res) { layer.msg(res.msg, {icon: 1}); }, diff --git a/app/Http/Home/Controllers/AnswerController.php b/app/Http/Home/Controllers/AnswerController.php index 04ab77f9..8c711b10 100644 --- a/app/Http/Home/Controllers/AnswerController.php +++ b/app/Http/Home/Controllers/AnswerController.php @@ -47,13 +47,19 @@ class AnswerController extends Controller */ public function showAction($id) { - $service = new AnswerService(); + $service = new AnswerInfoService(); - $answer = $service->getAnswer($id); + $answer = $service->handle($id); + + $questionId = $answer['question']['id']; + + if ($answer['me']['owned'] == 0) { + $this->response->redirect(['for' => 'home.error.403']); + } $location = $this->url->get( - ['for' => 'home.question.show', 'id' => $answer->question_id], - ['answer_id' => $answer->id], + ['for' => 'home.question.show', 'id' => $questionId], + ['answer_id' => $id], ); $this->response->redirect($location); diff --git a/app/Http/Home/Controllers/IndexController.php b/app/Http/Home/Controllers/IndexController.php index 04375285..48daa877 100644 --- a/app/Http/Home/Controllers/IndexController.php +++ b/app/Http/Home/Controllers/IndexController.php @@ -13,7 +13,7 @@ class IndexController extends Controller public function beforeExecuteRoute(Dispatcher $dispatcher) { - if ($this->isMobileBrowser()) { + if ($this->isMobileBrowser() && $this->h5Enabled()) { $this->response->redirect('/h5', true); @@ -66,4 +66,11 @@ class IndexController extends Controller $this->view->setVar('vip_courses', $service->getSimpleVipCourses()); } + protected function h5Enabled() + { + $file = public_path('h5/index.html'); + + return file_exists($file); + } + } diff --git a/app/Http/Home/Controllers/PageController.php b/app/Http/Home/Controllers/PageController.php index 38b31f97..07b2d349 100644 --- a/app/Http/Home/Controllers/PageController.php +++ b/app/Http/Home/Controllers/PageController.php @@ -20,6 +20,10 @@ class PageController extends Controller $page = $service->handle($id); + if ($page['me']['owned'] == 0) { + $this->response->redirect(['for' => 'home.error.403']); + } + $featuredCourses = $this->getFeaturedCourses(); $this->seo->prependTitle($page['title']); diff --git a/app/Http/Home/Controllers/UserController.php b/app/Http/Home/Controllers/UserController.php index 8e113aac..83824167 100644 --- a/app/Http/Home/Controllers/UserController.php +++ b/app/Http/Home/Controllers/UserController.php @@ -2,10 +2,12 @@ namespace App\Http\Home\Controllers; +use App\Services\Logic\User\AnswerList as UserAnswerListService; use App\Services\Logic\User\ArticleList as UserArticleListService; use App\Services\Logic\User\CourseList as UserCourseListService; use App\Services\Logic\User\FriendList as UserFriendListService; use App\Services\Logic\User\GroupList as UserGroupListService; +use App\Services\Logic\User\QuestionList as UserQuestionListService; use App\Services\Logic\User\UserInfo as UserInfoService; use Phalcon\Mvc\View; @@ -61,6 +63,38 @@ class UserController extends Controller $this->view->setVar('pager', $pager); } + /** + * @Get("/{id:[0-9]+}/questions", name="home.user.questions") + */ + public function questionsAction($id) + { + $service = new UserQuestionListService(); + + $pager = $service->handle($id); + + $pager->target = 'tab-questions'; + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('user/questions'); + $this->view->setVar('pager', $pager); + } + + /** + * @Get("/{id:[0-9]+}/answers", name="home.user.answers") + */ + public function answersAction($id) + { + $service = new UserAnswerListService(); + + $pager = $service->handle($id); + + $pager->target = 'tab-answers'; + + $this->view->setRenderLevel(View::LEVEL_ACTION_VIEW); + $this->view->pick('user/answers'); + $this->view->setVar('pager', $pager); + } + /** * @Get("/{id:[0-9]+}/friends", name="home.user.friends") */ diff --git a/app/Http/Home/Services/Article.php b/app/Http/Home/Services/Article.php index 9ec7c15d..60afd566 100644 --- a/app/Http/Home/Services/Article.php +++ b/app/Http/Home/Services/Article.php @@ -6,7 +6,7 @@ use App\Models\Article as ArticleModel; use App\Models\Category as CategoryModel; use App\Models\Reason as ReasonModel; use App\Repos\Category as CategoryRepo; -use App\Repos\Tag as TagRepo; +use App\Services\Logic\Article\XmTagList as XmTagListService; use App\Services\Logic\ArticleTrait; class Article extends Service @@ -25,33 +25,9 @@ class Article extends Service public function getXmTags($id) { - $tagRepo = new TagRepo(); + $service = new XmTagListService(); - $allTags = $tagRepo->findAll(['published' => 1], 'priority'); - - if ($allTags->count() == 0) return []; - - $articleTagIds = []; - - if ($id > 0) { - $article = $this->checkArticle($id); - if (!empty($article->tags)) { - $articleTagIds = kg_array_column($article->tags, 'id'); - } - } - - $list = []; - - foreach ($allTags as $tag) { - $selected = in_array($tag->id, $articleTagIds); - $list[] = [ - 'name' => $tag->name, - 'value' => $tag->id, - 'selected' => $selected, - ]; - } - - return $list; + return $service->handle($id); } public function getCategories() diff --git a/app/Http/Home/Services/Question.php b/app/Http/Home/Services/Question.php index c8af59cc..a719ab54 100644 --- a/app/Http/Home/Services/Question.php +++ b/app/Http/Home/Services/Question.php @@ -5,7 +5,7 @@ namespace App\Http\Home\Services; use App\Models\Category as CategoryModel; use App\Models\Question as QuestionModel; use App\Repos\Category as CategoryRepo; -use App\Repos\Tag as TagRepo; +use App\Services\Logic\Question\XmTagList as XmTagListService; use App\Services\Logic\QuestionTrait; use App\Services\Logic\Service as LogicService; @@ -36,33 +36,9 @@ class Question extends LogicService public function getXmTags($id) { - $tagRepo = new TagRepo(); + $service = new XmTagListService(); - $allTags = $tagRepo->findAll(['published' => 1], 'priority'); - - if ($allTags->count() == 0) return []; - - $questionTagIds = []; - - if ($id > 0) { - $question = $this->checkQuestion($id); - if (!empty($question->tags)) { - $questionTagIds = kg_array_column($question->tags, 'id'); - } - } - - $list = []; - - foreach ($allTags as $tag) { - $selected = in_array($tag->id, $questionTagIds); - $list[] = [ - 'name' => $tag->name, - 'value' => $tag->id, - 'selected' => $selected, - ]; - } - - return $list; + return $service->handle($id); } public function getQuestion($id) diff --git a/app/Http/Home/Views/im/group/edit.volt b/app/Http/Home/Views/im/group/edit.volt index 6803e993..a35d6160 100644 --- a/app/Http/Home/Views/im/group/edit.volt +++ b/app/Http/Home/Views/im/group/edit.volt @@ -2,7 +2,7 @@ {% block content %} - {% set update_url = url({'for':'home.igm.update','id':group.id}) %} + {% set update_url = url({'for':'home.im_group.update','id':group.id}) %} {% set name_readonly = group.type == 1 ? 'readonly="readonly"' : '' %}
    diff --git a/app/Http/Home/Views/search/question.volt b/app/Http/Home/Views/search/question.volt index 6f28739e..4dec9446 100644 --- a/app/Http/Home/Views/search/question.volt +++ b/app/Http/Home/Views/search/question.volt @@ -3,7 +3,6 @@ {% for item in pager.items %} {% set owner_url = url({'for':'home.user.show','id':item.owner.id}) %} {% set question_url = url({'for':'home.question.show','id':item.id}) %} - {% set solved_class = item.solved ? 'column solved' : 'column' %}
    diff --git a/app/Http/Home/Views/user/answers.volt b/app/Http/Home/Views/user/answers.volt new file mode 100644 index 00000000..30dbb919 --- /dev/null +++ b/app/Http/Home/Views/user/answers.volt @@ -0,0 +1,25 @@ +{% if pager.total_pages > 0 %} +
    +
    + {% for item in pager.items %} + {% set answer_url = url({'for':'home.answer.show','id':item.id}) %} +
    +
    +
    + +
    {{ substr(item.summary,0,80) }}
    +
    + {{ item.create_time|time_ago }} + + {{ item.comment_count }} 评论 +
    +
    +
    +
    + {% endfor %} +
    +
    + {{ partial('partials/pager_ajax') }} +{% endif %} \ No newline at end of file diff --git a/app/Http/Home/Views/user/articles.volt b/app/Http/Home/Views/user/articles.volt index e7ba66f4..e6d554df 100644 --- a/app/Http/Home/Views/user/articles.volt +++ b/app/Http/Home/Views/user/articles.volt @@ -1,23 +1,19 @@ {{ partial('macros/article') }} {% if pager.total_pages > 0 %} -
    +
    {% for item in pager.items %} {% set article_url = url({'for':'home.article.show','id':item.id}) %} -
    -
    - {{ source_type(item.source_type) }} -
    - - {{ item.title }} - -
    +
    +
    +
    {{ substr(item.summary,0,80) }}
    + {{ item.create_time|time_ago }} {{ item.view_count }} 浏览 {{ item.comment_count }} 评论 diff --git a/app/Http/Home/Views/user/questions.volt b/app/Http/Home/Views/user/questions.volt new file mode 100644 index 00000000..b83eb067 --- /dev/null +++ b/app/Http/Home/Views/user/questions.volt @@ -0,0 +1,26 @@ +{% if pager.total_pages > 0 %} +
    +
    + {% for item in pager.items %} + {% set question_url = url({'for':'home.question.show','id':item.id}) %} +
    +
    +
    + +
    {{ substr(item.summary,0,80) }}
    +
    + {{ item.create_time|time_ago }} + {{ item.view_count }} 浏览 + + {{ item.answer_count }} 回答 +
    +
    +
    +
    + {% endfor %} +
    +
    + {{ partial('partials/pager_ajax') }} +{% endif %} \ No newline at end of file diff --git a/app/Http/Home/Views/user/show.volt b/app/Http/Home/Views/user/show.volt index 82a50354..f43de825 100644 --- a/app/Http/Home/Views/user/show.volt +++ b/app/Http/Home/Views/user/show.volt @@ -43,11 +43,15 @@ {% set show_tab_courses = user.course_count > 0 %} {% set show_tab_articles = user.article_count > 0 %} + {% set show_tab_questions = user.question_count > 0 %} + {% set show_tab_answers = user.answer_count > 0 %} {% set show_tab_friends = user.friend_count > 0 %} {% set show_tab_groups = user.group_count > 0 %} {% set courses_url = url({'for':'home.user.courses','id':user.id}) %} {% set articles_url = url({'for':'home.user.articles','id':user.id}) %} + {% set questions_url = url({'for':'home.user.questions','id':user.id}) %} + {% set answers_url = url({'for':'home.user.answers','id':user.id}) %} {% set friends_url = url({'for':'home.user.friends','id':user.id}) %} {% set groups_url = url({'for':'home.user.groups','id':user.id}) %} @@ -58,6 +62,12 @@ {% if show_tab_articles %}
  • 文章
  • {% endif %} + {% if show_tab_questions %} +
  • 提问
  • + {% endif %} + {% if show_tab_answers %} +
  • 回答
  • + {% endif %} {% if show_tab_friends %}
  • 好友
  • {% endif %} @@ -70,6 +80,12 @@ {% if show_tab_articles %}
    {% endif %} + {% if show_tab_questions %} +
    + {% endif %} + {% if show_tab_answers %} +
    + {% endif %} {% if show_tab_friends %}
    {% endif %} diff --git a/app/Library/AppInfo.php b/app/Library/AppInfo.php index 3da14655..b0c2f504 100644 --- a/app/Library/AppInfo.php +++ b/app/Library/AppInfo.php @@ -11,7 +11,7 @@ class AppInfo protected $link = 'https://koogua.com'; - protected $version = '1.3.5'; + protected $version = '1.3.6'; public function __get($name) { diff --git a/app/Library/Helper.php b/app/Library/Helper.php index 79eabbdd..7bb4534a 100644 --- a/app/Library/Helper.php +++ b/app/Library/Helper.php @@ -449,6 +449,8 @@ function kg_parse_summary($content, $length = 100) $content = strip_tags($content); + $content = trim($content); + return kg_substr($content, 0, $length); } diff --git a/app/Models/Answer.php b/app/Models/Answer.php index e2fa9a30..40dab0cc 100644 --- a/app/Models/Answer.php +++ b/app/Models/Answer.php @@ -153,27 +153,11 @@ class Answer extends Model public function beforeCreate() { - if (empty($this->cover)) { - $this->cover = kg_parse_first_content_image($this->content); - } - - if (empty($this->summary)) { - $this->summary = kg_parse_summary($this->content); - } - $this->create_time = time(); } public function beforeUpdate() { - if (empty($this->cover)) { - $this->cover = kg_parse_first_content_image($this->content); - } - - if (empty($this->summary)) { - $this->summary = kg_parse_summary($this->content); - } - $this->update_time = time(); } diff --git a/app/Models/Article.php b/app/Models/Article.php index 644696cf..5a69307e 100644 --- a/app/Models/Article.php +++ b/app/Models/Article.php @@ -225,14 +225,6 @@ class Article extends Model public function beforeCreate() { - if (empty($this->cover)) { - $this->cover = kg_parse_first_content_image($this->content); - } - - if (is_array($this->tags) || is_object($this->tags)) { - $this->tags = kg_json_encode($this->tags); - } - $this->create_time = time(); } @@ -246,19 +238,14 @@ class Article extends Model $sync->addItem($this->id); } - if (empty($this->cover)) { - $this->cover = kg_parse_first_content_image($this->content); - } + $this->update_time = time(); + } - if (empty($this->summary)) { - $this->summary = kg_parse_summary($this->content); - } - - if (is_array($this->tags) || is_array($this->tags)) { + public function beforeSave() + { + if (is_array($this->tags) || is_object($this->tags)) { $this->tags = kg_json_encode($this->tags); } - - $this->update_time = time(); } public function afterCreate() diff --git a/app/Models/Course.php b/app/Models/Course.php index 8db6710a..1d9927a8 100644 --- a/app/Models/Course.php +++ b/app/Models/Course.php @@ -313,12 +313,6 @@ class Course extends Model $this->attrs = kg_json_encode($this->attrs); } - if (empty($this->cover)) { - $this->cover = kg_default_course_cover_path(); - } elseif (Text::startsWith($this->cover, 'http')) { - $this->cover = self::getCoverPath($this->cover); - } - $this->create_time = time(); } @@ -332,22 +326,10 @@ class Course extends Model $sync->addItem($this->id); } - if (Text::startsWith($this->cover, 'http')) { - $this->cover = self::getCoverPath($this->cover); - } - - if (empty($this->summary)) { - $this->summary = kg_parse_summary($this->details); - } - if (is_array($this->attrs) || is_object($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } - if (empty($this->origin_price)) { - $this->origin_price = 1.5 * $this->market_price; - } - if ($this->deleted == 1) { $this->published = 0; } @@ -355,6 +337,23 @@ class Course extends Model $this->update_time = time(); } + public function beforeSave() + { + if (empty($this->cover)) { + $this->cover = kg_default_course_cover_path(); + } elseif (Text::startsWith($this->cover, 'http')) { + $this->cover = self::getCoverPath($this->cover); + } + + 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() { $cache = new MaxCourseIdCache(); diff --git a/app/Models/FlashSale.php b/app/Models/FlashSale.php index 81c6ab62..6009d062 100644 --- a/app/Models/FlashSale.php +++ b/app/Models/FlashSale.php @@ -125,18 +125,19 @@ class FlashSale extends Model public function beforeCreate() { - if (is_array($this->item_info) || is_object($this->item_info)) { - $this->item_info = kg_json_encode($this->item_info); - } - - if (is_array($this->schedules) || is_object($this->schedules)) { - $this->schedules = kg_json_encode($this->schedules); - } - $this->create_time = time(); } public function beforeUpdate() + { + if ($this->deleted == 1) { + $this->published = 0; + } + + $this->update_time = time(); + } + + public function beforeSave() { if (is_array($this->item_info) || is_object($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); @@ -145,12 +146,6 @@ class FlashSale extends Model if (is_array($this->schedules) || is_object($this->schedules)) { $this->schedules = kg_json_encode($this->schedules); } - - if ($this->deleted == 1) { - $this->published = 0; - } - - $this->update_time = time(); } public function afterCreate() diff --git a/app/Models/ImGroup.php b/app/Models/ImGroup.php index 677c0308..0ba90945 100644 --- a/app/Models/ImGroup.php +++ b/app/Models/ImGroup.php @@ -127,12 +127,6 @@ class ImGroup extends Model public function beforeCreate() { - if (empty($this->avatar)) { - $this->avatar = kg_default_group_avatar_path(); - } elseif (Text::startsWith($this->avatar, 'http')) { - $this->avatar = self::getAvatarPath($this->avatar); - } - $this->create_time = time(); } @@ -143,10 +137,6 @@ class ImGroup extends Model $sync->addItem($this->id); } - if (Text::startsWith($this->avatar, 'http')) { - $this->avatar = self::getAvatarPath($this->avatar); - } - if ($this->deleted == 1) { $this->published = 0; } @@ -154,6 +144,15 @@ class ImGroup extends Model $this->update_time = time(); } + public function beforeSave() + { + if (empty($this->avatar)) { + $this->avatar = kg_default_group_avatar_path(); + } elseif (Text::startsWith($this->avatar, 'http')) { + $this->avatar = self::getAvatarPath($this->avatar); + } + } + public function afterCreate() { $cache = new MaxImGroupIdCache(); diff --git a/app/Models/ImNotice.php b/app/Models/ImNotice.php index 31b29225..6b26a4cb 100644 --- a/app/Models/ImNotice.php +++ b/app/Models/ImNotice.php @@ -85,20 +85,19 @@ class ImNotice extends Model public function beforeCreate() { - if (is_array($this->item_info)) { - $this->item_info = kg_json_encode($this->item_info); - } - $this->create_time = time(); } public function beforeUpdate() + { + $this->update_time = time(); + } + + public function beforeSave() { if (is_array($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Models/ImUser.php b/app/Models/ImUser.php index 52b5e951..4725f21e 100644 --- a/app/Models/ImUser.php +++ b/app/Models/ImUser.php @@ -112,22 +112,21 @@ class ImUser extends Model public function beforeCreate() { - if (empty($this->avatar)) { - $this->avatar = kg_default_user_avatar_path(); - } elseif (Text::startsWith($this->avatar, 'http')) { - $this->avatar = self::getAvatarPath($this->avatar); - } - $this->create_time = time(); } public function beforeUpdate() { - if (Text::startsWith($this->avatar, 'http')) { + $this->update_time = time(); + } + + public function beforeSave() + { + if (empty($this->avatar)) { + $this->avatar = kg_default_user_avatar_path(); + } elseif (Text::startsWith($this->avatar, 'http')) { $this->avatar = self::getAvatarPath($this->avatar); } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Models/Notification.php b/app/Models/Notification.php index b7cfab4e..defa7c44 100644 --- a/app/Models/Notification.php +++ b/app/Models/Notification.php @@ -180,20 +180,19 @@ class Notification extends Model public function beforeCreate() { - if (is_array($this->event_info) || is_object($this->event_info)) { - $this->event_info = kg_json_encode($this->event_info); - } - $this->create_time = time(); } public function beforeUpdate() + { + $this->update_time = time(); + } + + public function beforeSave() { if (is_array($this->event_info) || is_object($this->event_info)) { $this->event_info = kg_json_encode($this->event_info); } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Models/Order.php b/app/Models/Order.php index 5e6ab4f5..7574d40a 100644 --- a/app/Models/Order.php +++ b/app/Models/Order.php @@ -170,18 +170,15 @@ class Order extends Model { $this->sn = date('YmdHis') . rand(1000, 9999); - if (is_array($this->item_info) || is_object($this->item_info)) { - $this->item_info = kg_json_encode($this->item_info); - } - - if (is_array($this->promotion_info) || is_object($this->promotion_info)) { - $this->promotion_info = kg_json_encode($this->promotion_info); - } - $this->create_time = time(); } public function beforeUpdate() + { + $this->update_time = time(); + } + + public function beforeSave() { if (is_array($this->item_info) || is_object($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); @@ -190,8 +187,6 @@ class Order extends Model if (is_array($this->promotion_info) || is_object($this->promotion_info)) { $this->promotion_info = kg_json_encode($this->promotion_info); } - - $this->update_time = time(); } public function afterSave() diff --git a/app/Models/Package.php b/app/Models/Package.php index b9e27eb5..07c46194 100644 --- a/app/Models/Package.php +++ b/app/Models/Package.php @@ -105,21 +105,11 @@ class Package extends Model public function beforeCreate() { - if (empty($this->cover)) { - $this->cover = kg_default_package_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->cover = self::getCoverPath($this->cover); - } - if ($this->deleted == 1) { $this->published = 0; } @@ -127,6 +117,15 @@ class Package extends Model $this->update_time = time(); } + public function beforeSave() + { + if (empty($this->cover)) { + $this->cover = kg_default_package_cover_path(); + } elseif (Text::startsWith($this->cover, 'http')) { + $this->cover = self::getCoverPath($this->cover); + } + } + public function afterCreate() { $cache = new MaxPackageIdCache(); diff --git a/app/Models/PointGift.php b/app/Models/PointGift.php index 63c1de87..2b567ab4 100644 --- a/app/Models/PointGift.php +++ b/app/Models/PointGift.php @@ -166,21 +166,11 @@ class PointGift extends Model $this->attrs = kg_json_encode($this->attrs); } - if (empty($this->cover)) { - $this->cover = kg_default_gift_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->cover = self::getCoverPath($this->cover); - } - if (is_array($this->attrs) || is_object($this->attrs)) { $this->attrs = kg_json_encode($this->attrs); } @@ -192,6 +182,15 @@ class PointGift extends Model $this->update_time = time(); } + public function beforeSave() + { + if (empty($this->cover)) { + $this->cover = kg_default_gift_cover_path(); + } elseif (Text::startsWith($this->cover, 'http')) { + $this->cover = self::getCoverPath($this->cover); + } + } + public function afterCreate() { $cache = new MaxPointGiftIdCache(); diff --git a/app/Models/PointHistory.php b/app/Models/PointHistory.php index e2688a1b..6aa8de9d 100644 --- a/app/Models/PointHistory.php +++ b/app/Models/PointHistory.php @@ -95,20 +95,19 @@ class PointHistory extends Model public function beforeCreate() { - if (is_array($this->event_info) || is_object($this->event_info)) { - $this->event_info = kg_json_encode($this->event_info); - } - $this->create_time = time(); } public function beforeUpdate() + { + $this->update_time = time(); + } + + public function beforeSave() { if (is_array($this->event_info) || is_object($this->event_info)) { $this->event_info = kg_json_encode($this->event_info); } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Models/Question.php b/app/Models/Question.php index 0b9b2564..ca731b15 100644 --- a/app/Models/Question.php +++ b/app/Models/Question.php @@ -239,14 +239,6 @@ class Question extends Model public function beforeCreate() { - if (is_array($this->tags) || is_object($this->tags)) { - $this->tags = kg_json_encode($this->tags); - } - - if (empty($this->cover)) { - $this->cover = kg_parse_first_content_image($this->content); - } - $this->create_time = time(); } @@ -260,19 +252,14 @@ class Question extends Model $sync->addItem($this->id); } + $this->update_time = time(); + } + + public function beforeSave() + { if (is_array($this->tags) || is_object($this->tags)) { $this->tags = kg_json_encode($this->tags); } - - if (empty($this->cover)) { - $this->cover = kg_parse_first_content_image($this->content); - } - - if (empty($this->summary)) { - $this->summary = kg_parse_summary($this->content); - } - - $this->update_time = time(); } public function afterCreate() diff --git a/app/Models/Review.php b/app/Models/Review.php index 83589aad..c2610eaa 100644 --- a/app/Models/Review.php +++ b/app/Models/Review.php @@ -152,15 +152,11 @@ class Review extends Model public function beforeCreate() { - $this->rating = $this->getAvgRating(); - $this->create_time = time(); } public function beforeUpdate() { - $this->rating = $this->getAvgRating(); - if ($this->deleted == 1) { $this->published = 0; } @@ -168,6 +164,11 @@ class Review extends Model $this->update_time = time(); } + public function beforeSave() + { + $this->rating = $this->getAvgRating(); + } + protected function getAvgRating() { $sumRating = $this->rating1 + $this->rating2 + $this->rating3; diff --git a/app/Models/Role.php b/app/Models/Role.php index faf819fc..2478f9e1 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -103,20 +103,19 @@ class Role extends Model public function beforeCreate() { - if (is_array($this->routes) || is_object($this->routes)) { - $this->routes = kg_json_encode($this->routes); - } - $this->create_time = time(); } public function beforeUpdate() + { + $this->update_time = time(); + } + + public function beforeSave() { if (is_array($this->routes) || is_object($this->routes)) { $this->routes = kg_json_encode($this->routes); } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Models/Slide.php b/app/Models/Slide.php index cbe149bf..1fc5c03a 100644 --- a/app/Models/Slide.php +++ b/app/Models/Slide.php @@ -124,6 +124,20 @@ class Slide extends Model } public function beforeCreate() + { + $this->create_time = time(); + } + + public function beforeUpdate() + { + if ($this->deleted == 1) { + $this->published = 0; + } + + $this->update_time = time(); + } + + public function beforeSave() { if (empty($this->cover)) { $this->cover = kg_default_slide_cover_path(); @@ -134,25 +148,6 @@ class Slide extends Model if (is_array($this->target_attrs) || is_object($this->target_attrs)) { $this->target_attrs = kg_json_encode($this->target_attrs); } - - $this->create_time = time(); - } - - public function beforeUpdate() - { - if (Text::startsWith($this->cover, 'http')) { - $this->cover = self::getCoverPath($this->cover); - } - - if (is_array($this->target_attrs) || is_object($this->target_attrs)) { - $this->target_attrs = kg_json_encode($this->target_attrs); - } - - if ($this->deleted == 1) { - $this->published = 0; - } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Models/Tag.php b/app/Models/Tag.php index eca6f7ab..4d6a957f 100644 --- a/app/Models/Tag.php +++ b/app/Models/Tag.php @@ -98,21 +98,11 @@ class Tag extends Model public function beforeCreate() { - if (empty($this->icon)) { - $this->icon = kg_default_icon_path(); - } elseif (Text::startsWith($this->icon, 'http')) { - $this->icon = self::getIconPath($this->icon); - } - $this->create_time = time(); } public function beforeUpdate() { - if (Text::startsWith($this->icon, 'http')) { - $this->icon = self::getIconPath($this->icon); - } - if ($this->deleted == 1) { $this->published = 0; } @@ -120,6 +110,15 @@ class Tag extends Model $this->update_time = time(); } + public function beforeSave() + { + if (empty($this->icon)) { + $this->icon = kg_default_icon_path(); + } elseif (Text::startsWith($this->icon, 'http')) { + $this->icon = self::getIconPath($this->icon); + } + } + public function afterCreate() { $cache = new MaxTagIdCache(); diff --git a/app/Models/Task.php b/app/Models/Task.php index 8ac27e11..5c2278ce 100644 --- a/app/Models/Task.php +++ b/app/Models/Task.php @@ -126,20 +126,19 @@ class Task extends Model public function beforeCreate() { - if (is_array($this->item_info) || is_object($this->item_info)) { - $this->item_info = kg_json_encode($this->item_info); - } - $this->create_time = time(); } public function beforeUpdate() + { + $this->update_time = time(); + } + + public function beforeSave() { if (is_array($this->item_info) || is_object($this->item_info)) { $this->item_info = kg_json_encode($this->item_info); } - - $this->update_time = time(); } public function afterFetch() diff --git a/app/Models/User.php b/app/Models/User.php index d07fab74..891284e4 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -199,12 +199,6 @@ class User extends Model public function beforeCreate() { - if (empty($this->avatar)) { - $this->avatar = kg_default_user_avatar_path(); - } elseif (Text::startsWith($this->avatar, 'http')) { - $this->avatar = self::getAvatarPath($this->avatar); - } - $this->create_time = time(); } @@ -215,11 +209,16 @@ class User extends Model $sync->addItem($this->id); } - if (Text::startsWith($this->avatar, 'http')) { + $this->update_time = time(); + } + + public function beforeSave() + { + if (empty($this->avatar)) { + $this->avatar = kg_default_user_avatar_path(); + } elseif (Text::startsWith($this->avatar, 'http')) { $this->avatar = self::getAvatarPath($this->avatar); } - - $this->update_time = time(); } public function afterCreate() diff --git a/app/Repos/User.php b/app/Repos/User.php index c6b19ea9..4692118e 100644 --- a/app/Repos/User.php +++ b/app/Repos/User.php @@ -5,8 +5,6 @@ namespace App\Repos; use App\Library\Paginator\Adapter\QueryBuilder as PagerQueryBuilder; use App\Models\Answer as AnswerModel; use App\Models\Article as ArticleModel; -use App\Models\ArticleFavorite as ArticleFavoriteModel; -use App\Models\CourseFavorite as CourseFavoriteModel; use App\Models\CourseUser as CourseUserModel; use App\Models\ImUser as ImUserModel; use App\Models\Notification as NotificationModel; @@ -199,22 +197,6 @@ class User extends Repository ]); } - public function countCourseFavorites($userId) - { - return (int)CourseFavoriteModel::count([ - 'conditions' => 'user_id = :user_id: AND deleted = 0', - 'bind' => ['user_id' => $userId], - ]); - } - - public function countArticleFavorites($userId) - { - return (int)ArticleFavoriteModel::count([ - 'conditions' => 'user_id = :user_id: AND deleted = 0', - 'bind' => ['user_id' => $userId], - ]); - } - public function countUnreadNotifications($userId) { return (int)NotificationModel::count([ diff --git a/app/Services/Logic/Answer/AnswerCreate.php b/app/Services/Logic/Answer/AnswerCreate.php index 5b1871b8..990c4110 100644 --- a/app/Services/Logic/Answer/AnswerCreate.php +++ b/app/Services/Logic/Answer/AnswerCreate.php @@ -22,6 +22,7 @@ class AnswerCreate extends LogicService use ClientTrait; use QuestionTrait; use AnswerTrait; + use AnswerDataTrait; public function handle() { @@ -41,15 +42,15 @@ class AnswerCreate extends LogicService $answer = new AnswerModel(); - $answer->published = $this->getPublishStatus($user); - $answer->content = $validator->checkContent($post['content']); - $answer->client_type = $this->getClientType(); - $answer->client_ip = $this->getClientIp(); - $answer->question_id = $question->id; - $answer->owner_id = $user->id; + $data = $this->handlePostData($post); - $answer->create(); + $data['published'] = $this->getPublishStatus($user); + $data['question_id'] = $question->id; + $data['owner_id'] = $user->id; + $answer->create($data); + + $this->saveDynamicAttrs($answer); $this->incrUserDailyAnswerCount($user); $this->recountQuestionAnswers($question); $this->recountUserAnswers($user); diff --git a/app/Services/Logic/Answer/AnswerDataTrait.php b/app/Services/Logic/Answer/AnswerDataTrait.php new file mode 100644 index 00000000..2bb8b0ad --- /dev/null +++ b/app/Services/Logic/Answer/AnswerDataTrait.php @@ -0,0 +1,37 @@ +getClientType(); + $data['client_ip'] = $this->getClientIp(); + + $validator = new AnswerValidator(); + + $data['content'] = $validator->checkContent($post['content']); + + return $data; + } + + protected function saveDynamicAttrs(AnswerModel $answer) + { + $answer->cover = kg_parse_first_content_image($answer->content); + + $answer->summary = kg_parse_summary($answer->content); + + $answer->update(); + } + +} diff --git a/app/Services/Logic/Answer/AnswerInfo.php b/app/Services/Logic/Answer/AnswerInfo.php index a49a7267..70f74c19 100644 --- a/app/Services/Logic/Answer/AnswerInfo.php +++ b/app/Services/Logic/Answer/AnswerInfo.php @@ -75,8 +75,16 @@ class AnswerInfo extends LogicService { $me = [ 'liked' => 0, + 'owned' => 0, ]; + $isOwner = $user->id == $answer->owner_id; + $approved = $answer->published = AnswerModel::PUBLISH_APPROVED; + + if ($isOwner || $approved) { + $me['owned'] = 1; + } + if ($user->id > 0) { $likeRepo = new AnswerLikeRepo(); diff --git a/app/Services/Logic/Answer/AnswerList.php b/app/Services/Logic/Answer/AnswerList.php new file mode 100644 index 00000000..832132f5 --- /dev/null +++ b/app/Services/Logic/Answer/AnswerList.php @@ -0,0 +1,72 @@ +getParams(); + + $params['deleted'] = 0; + + $sort = $pagerQuery->getSort(); + $page = $pagerQuery->getPage(); + $limit = $pagerQuery->getLimit(); + + $answerRepo = new AnswerRepo(); + + $pager = $answerRepo->paginate($params, $sort, $page, $limit); + + return $this->handleAnswers($pager); + } + + public function handleAnswers($pager) + { + if ($pager->total_items == 0) { + return $pager; + } + + $builder = new AnswerListBuilder(); + + $answers = $pager->items->toArray(); + + $questions = $builder->getQuestions($answers); + + $users = $builder->getUsers($answers); + + $items = []; + + foreach ($answers as $answer) { + + $question = $questions[$answer['question_id']] ?? new \stdClass(); + $owner = $users[$answer['owner_id']] ?? new \stdClass(); + + $items[] = [ + 'id' => $answer['id'], + 'summary' => $answer['summary'], + 'published' => $answer['published'], + 'accepted' => $answer['accepted'], + 'comment_count' => $answer['comment_count'], + 'like_count' => $answer['like_count'], + 'create_time' => $answer['create_time'], + 'update_time' => $answer['update_time'], + 'question' => $question, + 'owner' => $owner, + ]; + } + + $pager->items = $items; + + return $pager; + } + +} diff --git a/app/Services/Logic/Answer/AnswerUpdate.php b/app/Services/Logic/Answer/AnswerUpdate.php index 3cfc159d..3506e15b 100644 --- a/app/Services/Logic/Answer/AnswerUpdate.php +++ b/app/Services/Logic/Answer/AnswerUpdate.php @@ -14,6 +14,7 @@ class AnswerUpdate extends LogicService use ClientTrait; use QuestionTrait; use AnswerTrait; + use AnswerDataTrait; public function handle($id) { @@ -29,11 +30,11 @@ class AnswerUpdate extends LogicService $validator->checkIfAllowEdit($answer); - $answer->content = $validator->checkContent($post['content']); - $answer->client_type = $this->getClientType(); - $answer->client_ip = $this->getClientIp(); + $data = $this->handlePostData($post); - $answer->update(); + $answer->update($data); + + $this->saveDynamicAttrs($answer); $this->eventsManager->fire('Answer:afterUpdate', $this, $answer); diff --git a/app/Services/Logic/Article/ArticleCreate.php b/app/Services/Logic/Article/ArticleCreate.php index 5ab11e4c..39a026ce 100644 --- a/app/Services/Logic/Article/ArticleCreate.php +++ b/app/Services/Logic/Article/ArticleCreate.php @@ -29,7 +29,6 @@ class ArticleCreate extends LogicService $data = $this->handlePostData($post); $data['published'] = $this->getPublishStatus($user); - $data['owner_id'] = $user->id; $article->create($data); @@ -38,6 +37,7 @@ class ArticleCreate extends LogicService $this->saveTags($article, $post['xm_tag_ids']); } + $this->saveDynamicAttrs($article); $this->incrUserDailyArticleCount($user); $this->recountUserArticles($user); diff --git a/app/Services/Logic/Article/ArticleDataTrait.php b/app/Services/Logic/Article/ArticleDataTrait.php index 8dc2bfba..0c005068 100644 --- a/app/Services/Logic/Article/ArticleDataTrait.php +++ b/app/Services/Logic/Article/ArticleDataTrait.php @@ -19,6 +19,9 @@ trait ArticleDataTrait { $data = []; + $data['client_type'] = $this->getClientType(); + $data['client_ip'] = $this->getClientIp(); + $validator = new ArticleValidator(); $data['title'] = $validator->checkTitle($post['title']); @@ -48,6 +51,20 @@ trait ArticleDataTrait return $data; } + protected function saveDynamicAttrs(ArticleModel $article) + { + $article->cover = kg_parse_first_content_image($article->content); + + $article->summary = kg_parse_summary($article->content); + + $article->update(); + + /** + * 重新执行afterFetch + */ + $article->afterFetch(); + } + protected function saveTags(ArticleModel $article, $tagIds) { $originTagIds = []; diff --git a/app/Services/Logic/Article/ArticleList.php b/app/Services/Logic/Article/ArticleList.php index ae58b3ea..684f455a 100644 --- a/app/Services/Logic/Article/ArticleList.php +++ b/app/Services/Logic/Article/ArticleList.php @@ -8,7 +8,6 @@ use App\Models\Article as ArticleModel; use App\Repos\Article as ArticleRepo; use App\Services\Logic\Service as LogicService; use App\Validators\ArticleQuery as ArticleQueryValidator; -use Phalcon\Text; class ArticleList extends LogicService { @@ -52,18 +51,8 @@ class ArticleList extends LogicService $items = []; - $baseUrl = kg_cos_url(); - foreach ($articles as $article) { - if (!empty($article['cover']) && !Text::startsWith($article['cover'], 'http')) { - $article['cover'] = $baseUrl . $article['cover']; - } - - if (empty($article['summary'])) { - $article['summary'] = kg_parse_summary($article['content']); - } - $article['tags'] = json_decode($article['tags'], true); $category = $categories[$article['category_id']] ?? new \stdClass(); diff --git a/app/Services/Logic/Article/ArticleUpdate.php b/app/Services/Logic/Article/ArticleUpdate.php index 9046a313..79b41cf1 100644 --- a/app/Services/Logic/Article/ArticleUpdate.php +++ b/app/Services/Logic/Article/ArticleUpdate.php @@ -44,6 +44,8 @@ class ArticleUpdate extends LogicService $this->saveTags($article, $post['xm_tag_ids']); } + $this->saveDynamicAttrs($article); + $this->eventsManager->fire('Article:afterUpdate', $this, $article); return $article; diff --git a/app/Services/Logic/Article/XmTagList.php b/app/Services/Logic/Article/XmTagList.php new file mode 100644 index 00000000..450a8123 --- /dev/null +++ b/app/Services/Logic/Article/XmTagList.php @@ -0,0 +1,50 @@ +findAll(['published' => 1]); + + if ($allTags->count() == 0) return []; + + $articleTagIds = []; + + if ($id > 0) { + $article = $this->findArticle($id); + if (!empty($article->tags)) { + $articleTagIds = kg_array_column($article->tags, 'id'); + } + } + + $list = []; + + foreach ($allTags as $tag) { + $selected = in_array($tag->id, $articleTagIds); + $list[] = [ + 'name' => $tag->name, + 'value' => $tag->id, + 'selected' => $selected, + ]; + } + + return $list; + } + + protected function findArticle($id) + { + $articleRepo = new ArticleRepo(); + + return $articleRepo->findById($id); + } + +} diff --git a/app/Services/Logic/Comment/CommentReply.php b/app/Services/Logic/Comment/CommentReply.php index 33b7bb45..500ca074 100644 --- a/app/Services/Logic/Comment/CommentReply.php +++ b/app/Services/Logic/Comment/CommentReply.php @@ -40,7 +40,7 @@ class CommentReply extends LogicService 'owner_id' => $user->id, ]; - $item = $validator->checkItem($comment->item_type, $comment->item_id); + $item = $validator->checkItem($comment->item_id, $comment->item_type); /** * 子评论中回复用户 diff --git a/app/Services/Logic/Page/PageInfo.php b/app/Services/Logic/Page/PageInfo.php index 50e0c6a6..7431d923 100644 --- a/app/Services/Logic/Page/PageInfo.php +++ b/app/Services/Logic/Page/PageInfo.php @@ -3,6 +3,7 @@ namespace App\Services\Logic\Page; use App\Models\Page as PageModel; +use App\Models\User as UserModel; use App\Services\Logic\PageTrait; use App\Services\Logic\Service as LogicService; @@ -13,22 +14,38 @@ class PageInfo extends LogicService public function handle($id) { + $user = $this->getCurrentUser(true); + $page = $this->checkPage($id); - return $this->handlePage($page); + return $this->handlePage($page, $user); } - protected function handlePage(PageModel $page) + protected function handlePage(PageModel $page, UserModel $user) { $page->content = kg_parse_markdown($page->content); + $me = $this->handleMeInfo($page, $user); + return [ 'id' => $page->id, 'title' => $page->title, 'content' => $page->content, 'create_time' => $page->create_time, 'update_time' => $page->update_time, + 'me' => $me, ]; } + protected function handleMeInfo(PageModel $page, UserModel $user) + { + $me = ['owned' => 0]; + + if ($page->published == 1) { + $me['owned'] = 1; + } + + return $me; + } + } diff --git a/app/Services/Logic/Question/QuestionCreate.php b/app/Services/Logic/Question/QuestionCreate.php index 54ce8c41..7e756eb5 100644 --- a/app/Services/Logic/Question/QuestionCreate.php +++ b/app/Services/Logic/Question/QuestionCreate.php @@ -28,7 +28,6 @@ class QuestionCreate extends LogicService $data = $this->handlePostData($post); $data['published'] = $this->getPublishStatus($user); - $data['owner_id'] = $user->id; $question->create($data); @@ -37,6 +36,7 @@ class QuestionCreate extends LogicService $this->saveTags($question, $post['xm_tag_ids']); } + $this->saveDynamicAttrs($question); $this->incrUserDailyQuestionCount($user); $this->recountUserQuestions($user); diff --git a/app/Services/Logic/Question/QuestionDataTrait.php b/app/Services/Logic/Question/QuestionDataTrait.php index b412332a..6a92b0c3 100644 --- a/app/Services/Logic/Question/QuestionDataTrait.php +++ b/app/Services/Logic/Question/QuestionDataTrait.php @@ -36,7 +36,21 @@ trait QuestionDataTrait return $data; } - + + protected function saveDynamicAttrs(QuestionModel $question) + { + $question->cover = kg_parse_first_content_image($question->content); + + $question->summary = kg_parse_summary($question->content); + + $question->update(); + + /** + * 重新执行afterFetch + */ + $question->afterFetch(); + } + protected function saveTags(QuestionModel $question, $tagIds) { $originTagIds = []; diff --git a/app/Services/Logic/Question/QuestionList.php b/app/Services/Logic/Question/QuestionList.php index cc90cc02..08c1c9f6 100644 --- a/app/Services/Logic/Question/QuestionList.php +++ b/app/Services/Logic/Question/QuestionList.php @@ -8,7 +8,6 @@ use App\Models\Question as QuestionModel; use App\Repos\Question as QuestionRepo; use App\Services\Logic\Service as LogicService; use App\Validators\QuestionQuery as QuestionQueryValidator; -use Phalcon\Text; class QuestionList extends LogicService { @@ -49,21 +48,12 @@ class QuestionList extends LogicService $items = []; - $baseUrl = kg_cos_url(); - foreach ($questions as $question) { - if (!empty($question['cover']) && !Text::startsWith($question['cover'], 'http')) { - $question['cover'] = $baseUrl . $question['cover']; - } - - if (empty($question['summary'])) { - $question['summary'] = kg_parse_summary($question['content'], 80); - } - $question['tags'] = json_decode($question['tags'], true); $owner = $users[$question['owner_id']] ?? new \stdClass(); + $lastReplier = $users[$question['last_replier_id']] ?? new \stdClass(); $items[] = [ diff --git a/app/Services/Logic/Question/QuestionUpdate.php b/app/Services/Logic/Question/QuestionUpdate.php index ed6979b5..4404ac21 100644 --- a/app/Services/Logic/Question/QuestionUpdate.php +++ b/app/Services/Logic/Question/QuestionUpdate.php @@ -50,6 +50,8 @@ class QuestionUpdate extends LogicService $this->saveTags($question, $post['xm_tag_ids']); } + $this->saveDynamicAttrs($question); + $this->eventsManager->fire('Question:afterUpdate', $this, $question); return $question; diff --git a/app/Services/Logic/Question/XmTagList.php b/app/Services/Logic/Question/XmTagList.php new file mode 100644 index 00000000..65bbb41d --- /dev/null +++ b/app/Services/Logic/Question/XmTagList.php @@ -0,0 +1,50 @@ +findAll(['published' => 1]); + + if ($allTags->count() == 0) return []; + + $questionTagIds = []; + + if ($id > 0) { + $question = $this->findQuestion($id); + if (!empty($question->tags)) { + $questionTagIds = kg_array_column($question->tags, 'id'); + } + } + + $list = []; + + foreach ($allTags as $tag) { + $selected = in_array($tag->id, $questionTagIds); + $list[] = [ + 'name' => $tag->name, + 'value' => $tag->id, + 'selected' => $selected, + ]; + } + + return $list; + } + + protected function findQuestion($id) + { + $questionRepo = new QuestionRepo(); + + return $questionRepo->findById($id); + } + +} diff --git a/app/Services/Logic/User/AnswerList.php b/app/Services/Logic/User/AnswerList.php new file mode 100644 index 00000000..109528a5 --- /dev/null +++ b/app/Services/Logic/User/AnswerList.php @@ -0,0 +1,47 @@ +checkUser($id); + + $pagerQuery = new PagerQuery(); + + $params = $pagerQuery->getParams(); + + $params['owner_id'] = $user->id; + $params['published'] = AnswerModel::PUBLISH_APPROVED; + $params['deleted'] = 0; + + $sort = $pagerQuery->getSort(); + $page = $pagerQuery->getPage(); + $limit = $pagerQuery->getLimit(); + + $answerRepo = new AnswerRepo(); + + $pager = $answerRepo->paginate($params, $sort, $page, $limit); + + return $this->handleAnswers($pager); + } + + protected function handleAnswers($pager) + { + $service = new AnswerListService(); + + return $service->handleAnswers($pager); + } + +} diff --git a/app/Services/Logic/User/Console/AnswerList.php b/app/Services/Logic/User/Console/AnswerList.php index b956f440..24792b9c 100644 --- a/app/Services/Logic/User/Console/AnswerList.php +++ b/app/Services/Logic/User/Console/AnswerList.php @@ -2,9 +2,9 @@ namespace App\Services\Logic\User\Console; -use App\Builders\AnswerList as AnswerListBuilder; use App\Library\Paginator\Query as PagerQuery; use App\Repos\Answer as AnswerRepo; +use App\Services\Logic\Answer\AnswerList as AnswerListService; use App\Services\Logic\Service as LogicService; class AnswerList extends LogicService @@ -34,44 +34,9 @@ class AnswerList extends LogicService protected function handleAnswers($pager) { - if ($pager->total_items == 0) { - return $pager; - } + $service = new AnswerListService(); - $builder = new AnswerListBuilder(); - - $answers = $pager->items->toArray(); - - $questions = $builder->getQuestions($answers); - - $users = $builder->getUsers($answers); - - $items = []; - - foreach ($answers as $answer) { - - $answer['summary'] = kg_parse_summary($answer['content'], 64); - - $question = $questions[$answer['question_id']] ?? new \stdClass(); - $owner = $users[$answer['owner_id']] ?? new \stdClass(); - - $items[] = [ - 'id' => $answer['id'], - 'summary' => $answer['summary'], - 'published' => $answer['published'], - 'accepted' => $answer['accepted'], - 'comment_count' => $answer['comment_count'], - 'like_count' => $answer['like_count'], - 'create_time' => $answer['create_time'], - 'update_time' => $answer['update_time'], - 'question' => $question, - 'owner' => $owner, - ]; - } - - $pager->items = $items; - - return $pager; + return $service->handleAnswers($pager); } } diff --git a/app/Services/Logic/User/QuestionList.php b/app/Services/Logic/User/QuestionList.php new file mode 100644 index 00000000..932d16a6 --- /dev/null +++ b/app/Services/Logic/User/QuestionList.php @@ -0,0 +1,47 @@ +checkUser($id); + + $pagerQuery = new PagerQuery(); + + $params = $pagerQuery->getParams(); + + $params['owner_id'] = $user->id; + $params['published'] = QuestionModel::PUBLISH_APPROVED; + $params['deleted'] = 0; + + $sort = $pagerQuery->getSort(); + $page = $pagerQuery->getPage(); + $limit = $pagerQuery->getLimit(); + + $articleRepo = new QuestionRepo(); + + $pager = $articleRepo->paginate($params, $sort, $page, $limit); + + return $this->handleQuestions($pager); + } + + protected function handleQuestions($pager) + { + $service = new QuestionListService(); + + return $service->handleQuestions($pager); + } + +} diff --git a/app/Services/Logic/User/UserInfo.php b/app/Services/Logic/User/UserInfo.php index d6a6a36f..b5bb88fa 100644 --- a/app/Services/Logic/User/UserInfo.php +++ b/app/Services/Logic/User/UserInfo.php @@ -37,6 +37,8 @@ class UserInfo extends LogicService 'locked' => $user->locked, 'course_count' => $user->course_count, 'article_count' => $user->article_count, + 'question_count' => $user->question_count, + 'answer_count' => $user->answer_count, 'friend_count' => $imUser->friend_count, 'group_count' => $imUser->group_count, 'active_time' => $user->active_time, diff --git a/app/Services/Search/ArticleDocument.php b/app/Services/Search/ArticleDocument.php index 2ac3c4a2..9d2610c3 100644 --- a/app/Services/Search/ArticleDocument.php +++ b/app/Services/Search/ArticleDocument.php @@ -35,10 +35,6 @@ class ArticleDocument extends Component */ public function formatDocument(ArticleModel $article) { - if (empty($article->summary)) { - $article->summary = kg_parse_summary($article->content); - } - if (is_array($article->tags) || is_object($article->tags)) { $article->tags = kg_json_encode($article->tags); } diff --git a/app/Services/Search/CourseDocument.php b/app/Services/Search/CourseDocument.php index 6e8853b9..1a59650e 100644 --- a/app/Services/Search/CourseDocument.php +++ b/app/Services/Search/CourseDocument.php @@ -61,10 +61,6 @@ class CourseDocument extends Component $course->cover = CourseModel::getCoverPath($course->cover); - if (empty($course->summary)) { - $course->summary = kg_parse_summary($course->details); - } - return [ 'id' => $course->id, 'title' => $course->title, diff --git a/app/Services/Search/QuestionDocument.php b/app/Services/Search/QuestionDocument.php index 64b8de41..e056766e 100644 --- a/app/Services/Search/QuestionDocument.php +++ b/app/Services/Search/QuestionDocument.php @@ -36,10 +36,6 @@ class QuestionDocument extends Component */ public function formatDocument(QuestionModel $question) { - if (empty($question->summary)) { - $question->summary = kg_parse_summary($question->content); - } - if (is_array($question->tags) || is_object($question->tags)) { $question->tags = kg_json_encode($question->tags); } diff --git a/public/static/admin/img/default/article_cover.png b/public/static/admin/img/default/article_cover.png deleted file mode 100644 index 45118a54..00000000 Binary files a/public/static/admin/img/default/article_cover.png and /dev/null differ diff --git a/public/static/home/css/common.css b/public/static/home/css/common.css index 7fe806dc..76bc1534 100644 --- a/public/static/home/css/common.css +++ b/public/static/home/css/common.css @@ -265,6 +265,8 @@ .page-info { min-height: 500px; + padding-top: 30px; + padding-bottom: 30px; } .help-list li { @@ -1763,6 +1765,20 @@ padding: 10px 8px; } +.user-tab .article-card { + height: 110px; + overflow: hidden; +} + +.user-tab .article-card .title { + border-bottom: 1px solid #f2f2f2; + padding-bottom: 10px; +} + +.user-tab .article-card .summary { + max-height: 3em; +} + .user-card { float: left; width: 100%; diff --git a/public/static/home/js/chapter.live.player.js b/public/static/home/js/chapter.live.player.js index bcebb321..84bafdfc 100644 --- a/public/static/home/js/chapter.live.player.js +++ b/public/static/home/js/chapter.live.player.js @@ -14,12 +14,11 @@ layui.use(['jquery', 'helper'], function () { var options = { live: true, autoplay: true, - h5_flv: true, width: 760, height: 428, }; - var formats = ['rtmp', 'flv', 'm3u8']; + var formats = ['m3u8']; var rates = ['od', 'hd', 'sd']; $.each(formats, function (i, format) { diff --git a/public/static/home/js/user.console.account.js b/public/static/home/js/user.console.account.js deleted file mode 100644 index f26f703c..00000000 --- a/public/static/home/js/user.console.account.js +++ /dev/null @@ -1,45 +0,0 @@ -layui.use(['jquery', 'layer'], function () { - - var $ = layui.jquery; - var layer = layui.layer; - - $('.btn-edit-pwd').on('click', function () { - var url = $(this).data('url'); - layer.open({ - type: 2, - title: '修改密码', - content: [url, 'no'], - area: ['640px', '320px'], - cancel: function () { - window.location.reload(); - } - }); - }); - - $('.btn-edit-phone').on('click', function () { - var url = $(this).data('url'); - layer.open({ - type: 2, - title: '修改手机', - content: [url, 'no'], - area: ['640px', '420px'], - cancel: function () { - window.location.reload(); - } - }); - }); - - $('.btn-edit-email').on('click', function () { - var url = $(this).data('url'); - layer.open({ - type: 2, - title: '修改邮箱', - content: [url, 'no'], - area: ['640px', '420px'], - cancel: function () { - window.location.reload(); - } - }); - }); - -}); \ No newline at end of file diff --git a/public/static/home/js/user.console.js b/public/static/home/js/user.console.js index d30afa58..41ceb461 100644 --- a/public/static/home/js/user.console.js +++ b/public/static/home/js/user.console.js @@ -1,8 +1,7 @@ -layui.use(['jquery', 'layer', 'helper'], function () { +layui.use(['jquery', 'layer'], function () { var $ = layui.jquery; var layer = layui.layer; - var helper = layui.helper; /** * 查看咨询 @@ -124,14 +123,4 @@ layui.use(['jquery', 'layer', 'helper'], function () { }); }); - if ($('#tab-courses').length > 0) { - var $tabCourses = $('#tab-courses'); - helper.ajaxLoadHtml($tabCourses.data('url'), $tabCourses.attr('id')); - } - - if ($('#tab-users').length > 0) { - var $tabUsers = $('#tab-users'); - helper.ajaxLoadHtml($tabUsers.data('url'), $tabUsers.attr('id')); - } - }); \ No newline at end of file diff --git a/public/static/home/js/user.show.js b/public/static/home/js/user.show.js index b5f070a6..7571113b 100644 --- a/public/static/home/js/user.show.js +++ b/public/static/home/js/user.show.js @@ -13,6 +13,16 @@ layui.use(['jquery', 'helper'], function () { helper.ajaxLoadHtml($tabArticles.data('url'), $tabArticles.attr('id')); } + if ($('#tab-questions').length > 0) { + var $tabQuestions = $('#tab-questions'); + helper.ajaxLoadHtml($tabQuestions.data('url'), $tabQuestions.attr('id')); + } + + if ($('#tab-answers').length > 0) { + var $tabAnswers = $('#tab-answers'); + helper.ajaxLoadHtml($tabAnswers.data('url'), $tabAnswers.attr('id')); + } + if ($('#tab-friends').length > 0) { var $tabFriends = $('#tab-friends'); helper.ajaxLoadHtml($tabFriends.data('url'), $tabFriends.attr('id'));