first(); $comment_user_id = $comment_modal->user_id; $likeIsExists = Model::where('user_id',$uid) ->where('comment_id',$comment_id)->exists(); // 判断是否已经点过赞 if($likeIsExists){ return true; } $post_id = $comment_modal->posts_id; $CommentLikeModel = new Model(); $CommentLikeModel->user_id = $uid; $CommentLikeModel->comment_id = $comment_id; $CommentLikeModel->comment_user_id = $comment_user_id; $CommentLikeModel->save(); $user = WxUser::where('id', $uid)->first(FieldUtils::userInfoColums()); $comment = WxComment::where('id', $comment_id)->first(); if($comment_user_id != $user['id']){ UserUtils::add_user_notice(3003, $comment_user_id, '您的评论收到了一个喜欢', '「'.$user['user_name'].'」' . '喜欢了您的评论。', 101, $comment['posts_id']); } Cache::forget($uid.':islike:comment:'.$comment->id); Cache::forget('comment:likecount:'.$comment->id); Redis::sadd('realtime:post:set', $post_id); DB::commit(); return true; } catch (\Exception $e) { DB::rollBack(); _logger_(__file__, __line__, $e->getMessage()); return false; } } public static function unlike($uid, $comment_id) { DB::beginTransaction(); try { Model::where('user_id',$uid) ->where('comment_id',$comment_id)->delete(); $post_id = WxComment::where('id', $comment_id)->value('posts_id'); Redis::sadd('realtime:post:set', $post_id); Cache::forget($uid.':islike:comment:'.$comment_id); Cache::forget('comment:likecount:'.$comment_id); DB::commit(); return true; } catch (\Exception $e) { DB::rollBack(); _logger_(__file__, __line__, $e->getMessage()); return false; } } }