Пример #1
0
 public function plaza()
 {
     if (!$GLOBALS['islogin']) {
         redirect($GLOBALS['s']['urlsite'] . '/member/login');
     }
     $questionModel = D("Question");
     //问问随机展示问题定时器处理start
     $questionModel->trigger();
     //问问随机展示问题定时器处理end
     $q1 = $questionModel->getOne(rand(0, 5));
     $wh = getwh($q1['photo_url'], 320, 320);
     $wh = explode(',', $wh);
     $q1['photo_width'] = $wh[0];
     $q1['photo_height'] = $wh[1];
     $GLOBALS['i']['question_t'] = $q1['timeline'];
     $q2 = $questionModel->getOne();
     $q2['photo_url'] = $GLOBALS['s']['urlupload'] . $q2['photo_url'] . '_480x480.jpg';
     $this->assign("question", $q1);
     $this->assign("question2", $q2);
     $this->display();
 }
Пример #2
0
 public function answer()
 {
     if (!checkpost()) {
         exit;
     }
     $uid = postvar('q_uid', 1);
     $member = M("member");
     $u = $member->getByUid($uid);
     $qid = postvar('q_id', 1);
     $question = M("question");
     $old = $question->where("qh_question.id={$qid}")->find();
     //dump($question->getLastSql());
     if (!$u || !$old) {
         exit('error');
     }
     $vote = intval($_POST['vote']);
     $vote = $vote == 1 ? 1 : 2;
     $answer = M('answer');
     $data['uid'] = $GLOBALS['i']['uid'];
     $data['username'] = $GLOBALS['i']['username'];
     $data['default_pic'] = $GLOBALS['i']['default_pic'];
     $data['q_id'] = $qid;
     $data['answer_cont'] = exp_content(postvar('answer_cont'));
     $data['vote'] = $vote;
     $data['is_anonymity'] = postvar('is_anonymity', 1);
     $data['is_show'] = postvar('is_show', 1);
     $data['answer_time'] = time();
     $a_id = $answer->add($data);
     $member_field = M('member_field');
     $data1['new_answer'] = array('exp', 'new_answer+1');
     $member_field->where("uid={$uid}")->save($data1);
     if ($data['is_anonymity'] != 1 && $old['is_anonymity'] != 1) {
         $data2['answer_num'] = array('exp', 'answer_num+1');
         $uid1 = $GLOBALS['i']['uid'];
         $member_field->where("uid={$uid1}")->save($data2);
     }
     if (!$a_id) {
         exit('unkonw');
     }
     $body = array('q_id' => $qid, 'q_uid' => $old['uid'], 'question' => $old['question'], 'a_id' => $a_id, 'a_uid' => $GLOBALS['i']['uid'], 'sex' => $GLOBALS['i']['sex'], 'a_username' => $GLOBALS['i']['username'], 'answer' => $data['answer_cont'], 'photo_url' => $old['photo_url']);
     $body_arr[$a_id] = $body;
     //feed_publish(4, $body_arr);
     $feedModel = D('Feed');
     $feedModel->feed_publish(4, $body_arr);
     $edit['answer_count'] = array('exp', 'answer_count+1');
     $edit['new_answer'] = array('exp', 'new_answer+1');
     if ($vote == 1) {
         $edit['agree_count'] = array('exp', 'agree_count+1');
     } else {
         $edit['against_count'] = array('exp', 'against_count+1');
     }
     $edit['answer_news'] = array('exp', 'answer_news+1');
     $edit['answer_count'] = array('exp', 'answer_count+1');
     if (!empty($_POST['answer_cont'])) {
         $edit['answer_cont_num'] = array('exp', 'answer_cont_num+1');
     }
     //问问随机展示问题处理start
     if ($old['answer_count'] == 19) {
         $edit['timeline'] = time();
     }
     $GLOBALS['i']['question_t'] = $old['timeline'];
     //问问随机展示问题处理end
     $question->where("id={$qid}")->save($edit);
     $questionModel = D("Question");
     $new = $questionModel->getOne(1);
     //问问随机展示问题处理start
     $questionModel->answerTrigger($old);
     //问问随机展示问题处理start
     $wh = getwh($new['photo_url'], 320, 320);
     $wh = explode(',', $wh);
     $new['photo_width'] = $wh[0];
     $new['photo_height'] = $wh[1];
     $new['photo_url'] = $GLOBALS['s']['urlupload'] . $new['photo_url'] . '_480x480.jpg';
     $array = array("code" => 1, "msg" => "回答成功", "answer" => array("uid" => $GLOBALS['i']['uid'], "question_id" => $qid, "question_uid" => $u['uid'], "answer_cont" => $_POST['answer_cont'], "answer_time" => $data['answer_time'], "vote" => $vote, "star_count" => 0, "status" => 0, "is_anonymity" => $old['is_anonymity'], "is_show" => 0), "m_anwer_num" => 41, "question" => $new, "q_code" => NULL, "prev_userinfo" => array("nickname" => $u['username'], "question_uid" => $u['uid'], "location_prov" => $u['hometown_prov'], "location_city" => "", "is_anonymity" => $old['is_anonymity'], "birth_y" => date("Y") - $u['birth_y'], "sex" => $u['sex'], "u_sex" => $u['sex'] == 1 ? '他' : '她', "face" => $GLOBALS['s']['urlupload'] . $u['default_pic'] . '_120x120.jpg', "question_type" => $old['type_name']));
     echo json_encode($array);
 }