mirror of
https://gitee.com/koogua/course-tencent-cloud.git
synced 2025-06-18 18:16:55 +08:00
180 lines
4.2 KiB
PHP
180 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Home\Controllers;
|
|
|
|
use App\Http\Home\Services\Answer as AnswerService;
|
|
use App\Http\Home\Services\Question as QuestionService;
|
|
use App\Services\Logic\Answer\AnswerAccept as AnswerAcceptService;
|
|
use App\Services\Logic\Answer\AnswerCreate as AnswerCreateService;
|
|
use App\Services\Logic\Answer\AnswerDelete as AnswerDeleteService;
|
|
use App\Services\Logic\Answer\AnswerInfo as AnswerInfoService;
|
|
use App\Services\Logic\Answer\AnswerLike as AnswerLikeService;
|
|
use App\Services\Logic\Answer\AnswerUpdate as AnswerUpdateService;
|
|
use Phalcon\Mvc\View;
|
|
|
|
/**
|
|
* @RoutePrefix("/answer")
|
|
*/
|
|
class AnswerController extends Controller
|
|
{
|
|
|
|
/**
|
|
* @Get("/tips", name="home.answer.tips")
|
|
*/
|
|
public function tipsAction()
|
|
{
|
|
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
|
|
}
|
|
|
|
/**
|
|
* @Get("/add", name="home.answer.add")
|
|
*/
|
|
public function addAction()
|
|
{
|
|
$id = $this->request->getQuery('question_id', 'int', 0);
|
|
|
|
$service = new QuestionService();
|
|
|
|
$question = $service->getQuestion($id);
|
|
|
|
$this->seo->prependTitle('回答问题');
|
|
|
|
$this->view->setVar('question', $question);
|
|
}
|
|
|
|
/**
|
|
* @Get("/{id:[0-9]+}/edit", name="home.answer.edit")
|
|
*/
|
|
public function editAction($id)
|
|
{
|
|
$service = new AnswerService();
|
|
|
|
$answer = $service->getAnswer($id);
|
|
|
|
$service = new QuestionService();
|
|
|
|
$question = $service->getQuestion($answer->question_id);
|
|
|
|
$this->seo->prependTitle('编辑回答');
|
|
|
|
$referer = $this->request->getHTTPReferer();
|
|
|
|
$this->view->setVar('question', $question);
|
|
$this->view->setVar('answer', $answer);
|
|
$this->view->setVar('referer', $referer);
|
|
}
|
|
|
|
/**
|
|
* @Get("/{id:[0-9]+}", name="home.answer.show")
|
|
*/
|
|
public function showAction($id)
|
|
{
|
|
$service = new AnswerInfoService();
|
|
|
|
$answer = $service->handle($id);
|
|
|
|
$this->view->setVar('answer', $answer);
|
|
}
|
|
|
|
/**
|
|
* @Post("/create", name="home.answer.create")
|
|
*/
|
|
public function createAction()
|
|
{
|
|
$service = new AnswerCreateService();
|
|
|
|
$answer = $service->handle();
|
|
|
|
$location = $this->url->get([
|
|
'for' => 'home.question.show',
|
|
'id' => $answer->question_id,
|
|
]);
|
|
|
|
$content = [
|
|
'location' => $location,
|
|
'msg' => '创建回答成功',
|
|
];
|
|
|
|
return $this->jsonSuccess($content);
|
|
}
|
|
|
|
/**
|
|
* @Post("/{id:[0-9]+}/update", name="home.answer.update")
|
|
*/
|
|
public function updateAction($id)
|
|
{
|
|
$service = new AnswerUpdateService();
|
|
|
|
$service->handle($id);
|
|
|
|
$location = $this->request->getPost('referer');
|
|
|
|
if (empty($location)) {
|
|
$location = $this->url->get(['for' => 'home.uc.answers']);
|
|
}
|
|
|
|
$content = [
|
|
'location' => $location,
|
|
'msg' => '更新回答成功',
|
|
];
|
|
|
|
return $this->jsonSuccess($content);
|
|
}
|
|
|
|
/**
|
|
* @Post("/{id:[0-9]+}/delete", name="home.answer.delete")
|
|
*/
|
|
public function deleteAction($id)
|
|
{
|
|
$service = new AnswerDeleteService();
|
|
|
|
$service->handle($id);
|
|
|
|
$location = $this->request->getHTTPReferer();
|
|
|
|
$content = [
|
|
'location' => $location,
|
|
'msg' => '删除回答成功',
|
|
];
|
|
|
|
return $this->jsonSuccess($content);
|
|
}
|
|
|
|
/**
|
|
* @Post("/{id:[0-9]+}/like", name="home.answer.like")
|
|
*/
|
|
public function likeAction($id)
|
|
{
|
|
$service = new AnswerLikeService();
|
|
|
|
$data = $service->handle($id);
|
|
|
|
$msg = $data['action'] == 'do' ? '点赞成功' : '取消点赞成功';
|
|
|
|
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
|
}
|
|
|
|
/**
|
|
* @Post("/{id:[0-9]+}/accept", name="home.answer.accept")
|
|
*/
|
|
public function acceptAction($id)
|
|
{
|
|
$service = new AnswerAcceptService();
|
|
|
|
$data = $service->handle($id);
|
|
|
|
$msg = $data['action'] == 'do' ? '采纳成功' : '取消采纳成功';
|
|
|
|
return $this->jsonSuccess(['data' => $data, 'msg' => $msg]);
|
|
}
|
|
|
|
/**
|
|
* @Route("/{id:[0-9]+}/report", name="home.answer.report")
|
|
*/
|
|
public function reportAction($id)
|
|
{
|
|
|
|
}
|
|
|
|
}
|