function comment() { \Swoole::$php->session->start(); if (!$_SESSION['isLogin']) { return 'nologin'; } $uid = $_SESSION['user_id']; $post['aid'] = (int) $_POST['aid']; $post['app'] = $_POST['app']; $post['content'] = $_POST['content']; $post['uid'] = $uid; $post['uname'] = $_SESSION['user']['nickname']; if ($post['app'] === 'mblog') { $m = createModel('MicroBlog'); $entity = $m->get($post['aid']); $entity->reply_count++; $entity->save(); if ($entity->uid != $uid) { App\Api::sendmail($entity->uid, $uid, "【系统】{$post['uname']}评论了你的微博", $post['content']); } } elseif ($post['app'] === 'blog') { $m = createModel('UserLogs'); $entity = $m->get($post['aid']); $entity->reply_count++; $entity->save(); if ($entity->uid != $uid) { App\Api::sendmail($entity->uid, $uid, "【系统】{$post['uname']}评论了你的日志.({$entity['title']})", $post['content']); } } createModel('UserComment')->put($post); $return = array('id' => $_SESSION['user']['id'], 'addtime' => Swoole\Tool::howLongAgo(date('Y-m-d H:i:s')), 'nickname' => $_SESSION['user']['nickname']); if (empty($_SESSION['user']['avatar'])) { $return['avatar'] = Swoole::$php->config['user']['default_avatar']; } else { $return['avatar'] = $_SESSION['user']['avatar']; } return $return; }
function reply() { $this->session->start(); if (!$_SESSION['isLogin']) { return Swoole\JS::echojs("if(confirm('您还没有登录,是否调整到登录页面(请首先复制您的回答内容)?')) window.parent.location.href='/page/login/?'"); } if (!empty($_POST['reply'])) { $answer['content'] = $_POST['reply']; $answer['uid'] = $this->swoole->user->getUid(); $user = createModel('UserInfo')->get($answer['uid']); $answer['aid'] = (int) $_POST['aid']; $ask = createModel('AskSubject')->get($answer['aid']); //答案数量加1 $ask->qcount += 1; //如果是未答状态,则设置为已答 if ($ask->mstatus == 0) { $ask->mstatus = 1; } $ask->save(); //为用户增加积分,回答即加5分 $user->gold += 5; $user->save(); App\Api::sendmail($ask['uid'], $answer['uid'], "【系统】" . $user['nickname'] . "回答了你的提问.({$ask['title']})", $answer['content']); createModel('AskReply')->put($answer); return Swoole\JS::alert('发布成功') . Swoole\JS::echojs('window.parent.location.href = window.parent.location.href;'); } }