From 8abe4d1e8e7e2e10a4adaf20084333dafc223dc8 Mon Sep 17 00:00:00 2001 From: koogua Date: Thu, 7 Oct 2021 15:58:06 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E9=97=AE=E9=A2=98me=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Home/Views/question/show.volt | 7 ++++++- app/Services/Logic/Question/QuestionInfo.php | 15 +++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/Http/Home/Views/question/show.volt b/app/Http/Home/Views/question/show.volt index edd6de95..e7d9f36b 100644 --- a/app/Http/Home/Views/question/show.volt +++ b/app/Http/Home/Views/question/show.volt @@ -64,11 +64,16 @@ {% endif %}
- {% if question.me.answered == 0 and question.published == 2 %} + {% if question.me.allow_answer == 1 %}
{% endif %} + {% if question.closed == 1 %} +
+ +
+ {% endif %} {% if answer_id > 0 %}
diff --git a/app/Services/Logic/Question/QuestionInfo.php b/app/Services/Logic/Question/QuestionInfo.php index 37ea2e06..ac11829a 100644 --- a/app/Services/Logic/Question/QuestionInfo.php +++ b/app/Services/Logic/Question/QuestionInfo.php @@ -95,18 +95,19 @@ class QuestionInfo extends LogicService protected function handleMeInfo(QuestionModel $question, UserModel $user) { $me = [ + 'allow_answer' => 0, 'liked' => 0, 'favorited' => 0, 'answered' => 0, 'owned' => 0, ]; - $isOwner = $user->id == $question->owner_id; + $approved = $question->published == QuestionModel::PUBLISH_APPROVED; + $closed = $question->closed == 1; + $solved = $question->solved == 1; - if ($question->published == QuestionModel::PUBLISH_APPROVED) { + if ($user->id == $question->owner_id) { $me['owned'] = 1; - } else { - $me['owned'] = $isOwner ? 1 : 0; } if ($user->id > 0) { @@ -134,6 +135,12 @@ class QuestionInfo extends LogicService if ($userAnswers->count() > 0) { $me['answered'] = 1; } + + $answered = $me['answered'] == 1; + + if ($approved && !$closed && !$solved && !$answered) { + $me['allow_answer'] = 1; + } } return $me;