public function detail($queryString)
 {
     $thread = Thread::threadById($queryString);
     require_once ROOT . DS . 'application' . DS . 'view' . DS . 'detail.php';
     require_once ROOT . DS . 'application' . DS . 'model' . DS . 'class.answer.php';
     require_once ROOT . DS . 'application' . DS . 'controller' . DS . 'class.answercontroller.php';
     $answerController = new AnswerController();
     $answerController->show($queryString);
 }
 /**
  * AnswerReply
  * 定时执行问答的回复 loop 问题不需要定时任务
  */
 public function answer_reply()
 {
     set_time_limit(0);
     $db = M('AnswerReply');
     $log = M('RunLog');
     $problem = M('AnswerProblem');
     $atten = M('AnswerAttention');
     $data = $db->where(array('status' => 1, 'addtime' => array('lt', time())))->select();
     $save['status'] = 0;
     if (!empty($data)) {
         foreach ($data as $key => $row) {
             $attention = $atten->where(array('issue_id' => $row['issue_id']))->field('system_user_id as belong ')->select();
             $auth = $problem->where(array('id' => $row['issue_id']))->find();
             if (empty($row['pid'])) {
                 //顶层回复
                 $data = $db->where(array('id' => $row['id']))->save($save);
                 if ($data) {
                     $problem->where(array('id' => $row['issue_id']))->setInc('answer_num');
                     if ($attention) {
                         foreach ($attention as $k => $r) {
                             AnswerController::addMessage($r['belong'], $row['issue_id'], $auth['title'], 3, $row['reply_id'], $auth['system_user_id'], $row['reply_content'], $row['id']);
                         }
                     }
                     //问题所有者 收到回答消息提示
                     AnswerController::addMessage($auth['system_user_id'], $row['issue_id'], $auth['title'], 1, $row['reply_id'], $auth['system_user_id'], $row['reply_content'], $row['id']);
                 } else {
                     $log->add(array('position' => 'cronAnswer', 'msg' => '执行id为' . $row['id'] . '的定时任务更新数据库(AnswerReply)失败', 'addtime' => date('Y-m-d H:i:s', time()), 'status' => 1));
                 }
             } else {
                 //验证上级回复是否存在
                 $pidData = $db->where(array('id' => $row['pid']))->field('issue_id,reply_id')->find();
                 if ($pidData['issue_id'] != $row['issue_id'] || empty($pidData)) {
                     $log->add(array('position' => 'cron', 'msg' => '执行id为' . $row['id'] . '的定时任务,获取上级回复失败(AnswerReply)', 'addtime' => date('Y-m-d H:i:s', time()), 'status' => 1));
                 }
                 $data = $db->where(array('id' => $row['id']))->save($save);
                 if ($data) {
                     if ($attention) {
                         foreach ($attention as $k => $r) {
                             AnswerController::addMessage($r['belong'], $row['issue_id'], $auth['title'], 4, $row['reply_id'], $pidData['reply_id'], $row['reply_content'], $row['id']);
                         }
                     }
                     //问题所有者 收到评论消息提示
                     AnswerController::addMessage($auth['system_user_id'], $row['issue_id'], $auth['title'], 2, $row['reply_id'], $pidData['reply_id'], $row['reply_content'], $row['id']);
                     //答案者 收到评价的消息提示
                     AnswerController::addMessage($pidData['reply_id'], $row['issue_id'], $auth['title'], 2, $row['reply_id'], $pidData['reply_id'], $row['reply_content'], $row['id']);
                 } else {
                     $log->add(array('position' => 'cronAnswer', 'msg' => '执行id为' . $row['id'] . '的定时任务更新数据库(AnswerReply)失败', 'addtime' => date('Y-m-d H:i:s', time()), 'status' => 1));
                 }
             }
         }
         $log->add(array('position' => 'cronAnswer', 'msg' => '(AnswerReply)执行定时任务成功', 'addtime' => date('Y-m-d H:i:s', time()), 'status' => 0));
     } else {
         $log->add(array('position' => 'cronAnswer', 'msg' => '(AnswerReply)执行定时任务成功', 'addtime' => date('Y-m-d H:i:s', time()), 'status' => 0));
     }
 }
Exemple #3
0
<?php

require_once 'vendor/autoload.php';
include 'AnswerController.php';
use Silex\Application;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
$app = new Silex\Application();
$answerController = new AnswerController();
$app->get('/suggestion', function (Application $app, Request $request) use($app) {
    $question = $request->query->get('question');
    global $answerController;
    return createResponse($answerController->getAnswer($question));
});
$app->get('/suggestion/add', function (Application $app, Request $request) use($app) {
    $question = $request->query->get('question');
    $answer = $request->query->get('answer');
    global $answerController;
    return createResponse($answerController->addSuggestion($question, $answer));
});
function createResponse($object)
{
    $response = new Response();
    $response->setContent(json_encode($object));
    $response->setStatusCode(200);
    $response->headers->set("Access-Control-Allow-Origin", "*");
    $response->headers->set("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
    $response->headers->set("Content-Type", "application/json; charset=UTF-8 ");
    return $response;
}
$app->run();