Exemplo n.º 1
0
 public function sendcomment($data)
 {
     $user = Yii::app()->db->createCommand('select a.title,a.portrait,a.nickName,b.name as companyName,c.name as location from user a left join company b on a.company=b.id left join hub c on a.location=c.id where a.status!=0 and a.id=' . $data['userId'])->queryRow();
     $comment = new Comment();
     $comment->postId = $data['postId'];
     $comment->userId = $data['userId'];
     $comment->content = $data['content'];
     $comment->createTime = $data['createTime'];
     $posterId = Posts::model()->findByAttributes(array('id' => $data['postId']))->userId;
     $userName = User::model()->findByAttributes(array('id' => $data['userId']))->nickName;
     $messageRe = MessageRelation::model()->findByAttributes(array('id1' => $posterId, 'id2' => 0));
     if ($messageRe) {
         $messageRe->utime = date('U');
     } else {
         $messageRe = new MessageRelation();
         $messageRe->id1 = $posterId;
         $messageRe->id2 = 0;
         $messageRe->utime = date('u');
     }
     if ($posterId != $data['userId']) {
         $message = new Message();
         $message->senderID = 0;
         $message->RecID = $posterId;
         $message->body = $userName . ' commented on your post.';
         $message->data = $data['postId'];
         $message->type = 1;
         $message->status = 0;
         $message->ctime = date('U');
         $message->commenterId = $data['userId'];
         $message->save();
         $messageRe->save();
     }
     $post = Posts::model()->findByAttributes(array('id' => $data['postId']));
     $post->comment_num++;
     if ($comment->save() && $post->save()) {
         return array('code' => 200, 'mes' => 'success', 'data' => array('newcomment' => Comment::model()->findByAttributes(array('createTime' => $data['createTime'])), 'user' => $user));
     }
 }
Exemplo n.º 2
0
 public static function addAFriend($fid)
 {
     if ($fid == 0) {
         $mr = MessageRelation::model()->findBySql('select * from messageRelation where id1=:senderId and id2=0', array(':senderId' => Yii::app()->user->id));
         $senderID = Yii::app()->user->id;
         $RecID = 0;
     } else {
         $mr = MessageRelation::model()->findBySql('select * from messageRelation where (id1=:senderId and id2=:recId) or (id1=:recId and id2=:senderId)', array(':senderId' => Yii::app()->user->id, ':recId' => $fid));
         $senderID = Yii::app()->user->id;
         $RecID = $fid;
     }
     if (!$mr) {
         $mrelation = new MessageRelation();
         $mrelation->id1 = $senderID;
         $mrelation->id2 = $RecID;
         $mrelation->lastMsg = '';
         $mrelation->utime = time();
         $mrelation->save();
         //新建用户关系时添加对方为当前登录用户的好友
         usleep(200 * 1000);
         if ($RecID == 0) {
             self::getInstance()->addFriend(Yii::app()->user->id, Yii::app()->params['partner']['emchat']['sysAccount']['name']);
         } else {
             self::getInstance()->addFriend($senderID, $RecID);
         }
     }
 }