Exemple #1
0
        /// <summary>
        /// 根据cat_ctrl获得新闻列表
        /// 获取图片新闻下方的新闻
        /// </summary>
        /// <param name="cat_ctrl"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public List <NewsInfo> News_SelectPaged(string cat_ctrl, string page, string pagesize)
        {
            //var list = DataAccess_News.News_SelectPaged("qiye_show", page, pagesize);
            var list = DataAccess_News.News_Page_Select("538", page, pagesize);

            return(list);
        }
Exemple #2
0
        /// <summary>
        /// 缓存Dictionary<cat_id, NewsCateInfo>对象
        /// </summary>
        /// <returns></returns>
        public static Dictionary <string, NewsCateInfo> GetNewsCates()
        {
            object o    = CacheHelper.Cache_Get(Constants.CN_NewsCates_All);
            var    dict = o as Dictionary <string, NewsCateInfo>;

            if (dict != null && dict.Count > 0)
            {
                return(dict);
            }

            Dictionary <string, NewsCateInfo> cates;
            var search = new NewsCateSearchInfo();
            List <NewsCateInfo> list = DataAccess_News.NewsCates_SelectPaged(false);

            cates = new Dictionary <string, NewsCateInfo>(list.Count);
            list.ForEach(t =>
            {
                string cat_id = t.cat_id.ToString();
                if (!cates.ContainsKey(cat_id))
                {
                    cates.Add(cat_id, t);
                }
            });

            CacheHelper.Cache_Store(Constants.CN_NewsCates_All, cates, TimeSpan.FromMinutes(10));
            return(cates);
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pg_uid">"Corp_Page_News"</param>
        /// <param name="blk_name">"Focus"</param>
        /// <param name="topn">"5"</param>
        /// <returns></returns>
        public Stream CMSItems_SelectPaged(string pg_uid, string blk_name, string topn)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            // 设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            CMSBlocksInfo block = CacheMarker.GetCMSBlocksInfo(pg_uid, blk_name);

            if (block == null)
            {
                return(null);
            }
            // 获得发布过的前topn条数据
            List <CMSItemsInfo> cmsItems = new List <CMSItemsInfo>();

            cmsItems = DataAccess_News.CMSItems_SelectTopN2(block.blk_id, int.Parse(topn), "" /*" and n_publish = 1"*/);

            var jsonSerialiser = new JavaScriptSerializer();

            json = string.Format("{{\"AppTop\":{0}}}", jsonSerialiser.Serialize(cmsItems));

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Exemple #4
0
        /// <summary>
        /// 加载个人评论(个人中心:我的跟帖)
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public Stream LoadUserContent(string userId, string page, string pagesize)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            // 设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            // 根据条件获得评论
            List <CommentInfo> cmtLst = DataAccess_News.Comments_SelectPaged(userId, page, pagesize);

            // 在评论里加上作者、发表时间、以及文章标题
            List <CommentInfoApp> cmtLst2 = new List <CommentInfoApp>();

            if (cmtLst != null)
            {
                for (int i = 0; i < cmtLst.Count; i++)
                {
                    var item    = cmtLst[i];
                    var infoApp = new CommentInfoApp();
                    infoApp.cmt_content      = item.cmt_content;
                    infoApp.cmt_id           = item.cmt_id;
                    infoApp.cmt_sourceId     = item.cmt_sourceId;
                    infoApp.cmt_sourceType   = item.cmt_sourceType;
                    infoApp.cmt_uid          = item.cmt_uid;
                    infoApp.cmt_sourceCateId = item.cmt_sourceCateId;

                    int catId = 0;
                    if (!int.TryParse(item.cmt_sourceCateId, out catId))
                    {
                        continue;
                    }

                    var cate = CacheMarker.GetNewsCatesBycat_id(catId.ToString());
                    if (cate == null)
                    {
                        continue;
                    }
                    NewsInfo news = CacheMarker.News_Selectbyn_gid(item.cmt_sourceId, "News_" + cate.cat_tableIndex.ToString());
                    if (news != null)
                    {
                        infoApp.n_authors = news.n_authors;
                        infoApp.n_date    = news.n_date;
                        infoApp.n_title   = news.n_title;
                    }

                    cmtLst2.Add(infoApp);
                }
            }
            var jsonSerialiser = new JavaScriptSerializer();

            json = "{\"list\":" + jsonSerialiser.Serialize(cmtLst2) + "}";
            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Exemple #5
0
        /// <summary>
        /// 获得某条新闻的详细内容
        /// </summary>
        /// <param name="rData"></param>
        /// <returns></returns>
        public Stream NewsContent_Selectbync_n_gid(NewsContentInfo_RD rData)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json;charset=utf-8";
            string json = "";
            // 获取某条新闻的详细内容
            List <NewsContentInfo> list = DataAccess_News.GetNewsContent(rData.n_gid);

            if (list.Count == 0)
            {
                json = string.Format("{{\"contents\":{0},\"shareUrl\":\"{1}\",\"imgs\":{2}}}", string.Empty,
                                     string.Empty, string.Empty);
            }
            else
            {
                string       shareUrl = ""; // 分享文章的地址
                NewsCateInfo cateInfo = null;
                string       n_gid    = "";
                // 获取文章分类的相关字段信息,并拼接得到文章分享地址
                if (list != null && list.Count > 0)
                {
                    // 分类ID
                    string cat_id = rData.vl_cateId.ToSafety();
                    // 根据分类ID获取分类信息
                    cateInfo = CacheMarker.GetNewsCatesBycat_id(cat_id);

                    string cat_ctrl = (cateInfo != null) ? cateInfo.cat_ctrl : "";
                    n_gid    = list[0].nc_n_gid;
                    shareUrl = "http://qiye.qianzhan.com/show/detail/" + rData.n_gid + ".html";
                    //ServiceHandler.GetDetailURL(cat_ctrl, cat_id, n_gid, 1, false);
                }

                // 存放图片数据
                List <ImgsInfo> imgs = new List <ImgsInfo>();
                // 自定义文章内容
                list = CustomContent(list, n_gid, "News_" + cateInfo.cat_tableIndex, out imgs, rData.vl_screenSize);

                // 插入浏览记录
                int logIndex = VisitLog_Insert(rData, shareUrl);
                if (logIndex == -1)
                {
                    return(null);
                }

                var jsonSerialiser = new JavaScriptSerializer();
                json = string.Format("{{\"contents\":{0},\"shareUrl\":\"{1}\",\"imgs\":{2}}}", jsonSerialiser.Serialize(list), shareUrl, jsonSerialiser.Serialize(imgs));
            }

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Exemple #6
0
        public static Response Process_Index_Pics()
        {
            var pics_mb = CacheMarker.GetCMSBlocksInfo("App_Header_Pic", "Focus").ToMaybe()     // get info of the block with a path of 'App_Header_Pic.Focus'. Refer to behind website for more details
                          .Select(block => DataAccess_News.CMSItems_SelectTopN2(block.blk_id, 5, "").ToMaybe())
                          .Select(items => items.Select(item => new Index_Pic()
            {
                href = item.n_linkUrl, img_src = item.n_imageUrl, title = item.n_title
            }).ToList().ToMaybe());

            var body     = pics_mb.HasValue ? pics_mb.Value.ToJson() : new List <Index_Pic>().ToJson();
            var response = Util.Normal_Resp_Create(body, EncryptType.PT);

            return(response);
        }
Exemple #7
0
        /// <summary>
        /// 获得评论总条数
        /// </summary>
        /// <param name="n_gid"></param>
        /// <returns></returns>
        public Stream GetCommentCount(string n_gid)
        {
            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            //设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            int commentCount = DataAccess_News.GetCommentCount(n_gid);

            json = "{\"commentCount\":\"" + commentCount + "\"}";
            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Exemple #8
0
        /// <summary>
        /// 根据文章id获得文章信息
        /// </summary>
        /// <param name="n_gid"></param>
        /// <param name="tableName"></param>
        /// <returns></returns>
        public static NewsInfo News_Selectbyn_gid(string n_gid, string tableName)
        {
            object o    = CacheHelper.Cache_Get(Constants.CN_News_Info + n_gid + tableName);
            var    info = o as NewsInfo;

            if (info != null)
            {
                return(info);
            }

            // 从数据库获取,并加入缓存后再返回
            NewsInfo newsInfo = DataAccess_News.News_Selectbyn_gid(n_gid, tableName);

            CacheHelper.Cache_Store(Constants.CN_News_Info + n_gid + tableName, TimeSpan.FromMinutes(10));
            return(newsInfo);
        }
Exemple #9
0
        /// <summary>
        /// 插入评论
        /// </summary>
        /// <param name="rData"></param>
        /// <returns></returns>
        private int InsertComments(CommentsData rData)
        {
            string puid       = rData.puid ?? string.Empty;
            string sourceId   = rData.srcid ?? string.Empty;
            string content    = rData.content ?? string.Empty;
            string sourceType = rData.type ?? string.Empty;
            string url        = rData.url ?? string.Empty;
            int    us_id      = int.Parse(rData.us_id);
            string us_name    = rData.us_name;

            CommentInfo cmt = new CommentInfo();

            cmt.cmt_accept       = 0;
            cmt.cmt_checkRemark  = string.Empty;
            cmt.cmt_checkTime    = string.Empty;
            cmt.cmt_checkUser    = string.Empty;
            cmt.cmt_content      = content;
            cmt.cmt_createTime   = DateTime.Now;
            cmt.cmt_createUser   = us_name;
            cmt.cmt_createUserID = us_id;
            cmt.cmt_id           = 0;

            OperationContext              context           = OperationContext.Current;
            MessageProperties             messageProperties = context.IncomingMessageProperties;
            RemoteEndpointMessageProperty endpointProperty  =
                messageProperties[RemoteEndpointMessageProperty.Name] as RemoteEndpointMessageProperty;

            cmt.cmt_ip = endpointProperty.Address;

            cmt.cmt_ipArea     = string.Empty;
            cmt.cmt_parentIds  = string.Empty;
            cmt.cmt_sourceId   = sourceId;
            cmt.cmt_sourceType = sourceType;
            cmt.cmt_status     = 1;
            cmt.cmt_title      = string.Empty;
            cmt.cmt_uid        = GetCmtUID(sourceId);

            cmt.cmt_sourceCateId = rData.cmt_sourceCateId;
            cmt.cmt_platform     = rData.cmt_platform;
            cmt.cmt_device       = rData.cmt_device;
            cmt.cmt_title        = rData.cmt_title;

            return(DataAccess_News.Comments_Insert(cmt, puid, url));
        }
Exemple #10
0
        public static NewsCateInfo NewsCates_FromId_Get(string catId)
        {
            string cacheName = "NewsCates_" + catId;

            object o = CacheHelper.Cache_Get(cacheName);

            if (o != null)
            {
                return((NewsCateInfo)o);
            }

            NewsCateInfo cate = DataAccess_News.NewsCates_Selectbycat_id(int.Parse(catId));

            if (cate != null)
            {
                CacheHelper.Cache_Store(cacheName, cate, TimeSpan.FromMinutes(10));
            }

            return(cate);
        }
Exemple #11
0
        /// <summary>
        /// 根据文章ID获得该文章的热门评论
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static string GetRecommendComments(string sourceId, string page, string limit)
        {
            int rowcount = 0;
            List <CommentInfo> cmtLst = DataAccess_News.RecommendComments_SelectPaged(sourceId, page, limit,
                                                                                      out rowcount);
            List <string> cmtIds = new List <string>();

            foreach (var cmt in cmtLst)
            {
                cmtIds.Add(cmt.cmt_uid);
                if (!string.IsNullOrEmpty(cmt.cmt_parentIds))
                {
                    cmtIds.AddRange(cmt.cmt_parentIds.Split(','));
                }
            }
            cmtIds = cmtIds.Distinct().ToList();

            var jsonSerializer = new JavaScriptSerializer();
            var json           = "";

            // 设置没有登录的用户为匿名用户
            List <CommentInfo> comments = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmtIds.ToArray());

            foreach (CommentInfo comment in comments)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n");
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);  //存放用户头像
                comment.cmt_checkTime   = Util.Get_Gentle_Time(comment.cmt_createTime); // 存放友好时间
            }
            json = jsonSerializer.Serialize(comments);


            json = "{\"list\":" + json + ",\"ids\":" + jsonSerializer.Serialize(cmtLst) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            //CacheHelper.Cache_Store(Constants.CN_RecommendComments + sourceId + page + limit, json, TimeSpan.FromMinutes(10));

            return(json);
        }
Exemple #12
0
        /// <summary>
        /// 获取头条下所有分类 Dictionary<cat_ctrl, NewsCateInfo>
        /// </summary>
        /// <returns></returns>
        public static List <NewsCateInfo> GetCNNewsCates()
        {
            object o = CacheHelper.Cache_Get(Constants.CN_NewsCates);

            if ((o != null) && (o is List <NewsCateInfo>) && (((List <NewsCateInfo>)o).Count > 0))
            {
                return((List <NewsCateInfo>)o);
            }
            List <NewsCateInfo> cates = null;
            List <NewsCateInfo> list  = DataAccess_News.NewsCates_SelectPaged(false);

            cates = new List <NewsCateInfo>(list.Count);
            foreach (NewsCateInfo item in list)
            {
                if (cates.All(i => i.cat_id != item.cat_id))
                {
                    cates.Add(item);
                }
            }
            CacheHelper.Cache_Store(Constants.CN_NewsCates, cates, TimeSpan.FromMinutes(10));
            return(cates);
        }
Exemple #13
0
        /// <summary>
        /// 获得某文章的所有评论(最新评论在前面)
        /// </summary>
        /// <param name="sourceId">w文章ID</param>
        /// <param name="page">第几页评论</param>
        /// <param name="limit">每页最大评论数</param>
        /// <returns></returns>
        public Stream Comments_SelectPaged(string sourceId, string page, string limit)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json; charset=utf-8";

            int rowcount = 0;
            List <CommentInfo> comments = DataAccess_News.Comments_SelectPaged(sourceId, page, limit, out rowcount);

            // 获取评论cmt_uid集合
            List <string> cmt_Uids = new List <string>();

            comments.ForEach(m =>
            {
                cmt_Uids.Add(m.cmt_uid);
                if (!string.IsNullOrEmpty(m.cmt_parentIds))
                {
                    cmt_Uids.AddRange(m.cmt_parentIds.Split(','));
                }
            });
            cmt_Uids = cmt_Uids.Distinct().ToList();

            var jsonSerialiser             = new JavaScriptSerializer();
            var json                       = "";
            List <CommentInfo> commentList = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmt_Uids.ToArray());

            foreach (var comment in commentList)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n"); // 解析编码后的危险字符
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);                                    // 存放用户头像
                comment.cmt_checkTime   = Util.Get_Gentle_Time(comment.cmt_createTime);                                   // 存放友好时间
            }
            json = jsonSerialiser.Serialize(commentList);
            json = "{\"list\":" + json + ",\"ids\":" + jsonSerialiser.Serialize(comments) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Exemple #14
0
        /// <summary>
        /// 插入访问日志或分享日志
        /// </summary>
        /// <param name="rData"></param>
        /// <param name="shareUrl"></param>
        /// <param name="preTableName"></param>
        /// <returns></returns>
        private int VisitLog_Insert(NewsContentInfo_RD rData, string shareUrl, string preTableName = "VisitLog_")
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            VisitLogInfo vlog = new VisitLogInfo();
            IncomingWebRequestContext inContext = context.IncomingRequest;
            UserAgent ua = UserAgentCache.CreateOrGetCacheItem(inContext.UserAgent);

            vlog.vl_browser    = ua.GetBrowser();
            vlog.vl_cookieId   = string.Empty;
            vlog.vl_createTime = DateTime.Now;
            vlog.vl_gid        = rData.n_gid;
            vlog.vl_id         = 0;
            vlog.vl_ip         = Util.Get_RemoteIp();
            vlog.vl_remoteAddr = vlog.vl_ip;
            vlog.vl_osName     = ua.GetPlatform();  // todo 操作系统的获取可能需要重新实现
            //UserAgent.KeyItem ki = ua.Spider();
            vlog.vl_spiderName = rData.vl_spiderName != null?ShareFlatform(rData.vl_spiderName) : string.Empty;

            vlog.vl_referrer = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.OriginalString + "/" + rData.n_gid;
            vlog.vl_url      = shareUrl;// 拼接成PC端地址
            vlog.vl_cateId   = rData.vl_cateId;
            //vlog.vl_screenSize = string.Empty;
            vlog.vl_totalTime = 0;
            vlog.vl_type      = rData.vl_type;
            string userName = rData.vl_userId;

            vlog.vl_userName   = (userName == "|") ? "" : userName;
            vlog.vl_screenSize = rData.vl_screenSize;
            vlog.vl_host       = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.RequestUri.Host; // 主域名
            string tblName = preTableName + vlog.vl_createTime.ToString("yyyyMMdd");                           // 插入表的表名
            // 插入浏览记录
            int logIndex = DataAccess_News.VisitLog_Insert(vlog, tblName);

            return(logIndex);
        }
Exemple #15
0
        /// <summary>
        /// 根据cat_ctrl,cat_id获得新闻列表
        /// 获取图片新闻下方的新闻
        /// </summary>
        /// <param name="cat_ctrl"></param>
        /// <param name="cat_id"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public List <NewsInfo> News_SelectPagedBycat_id(string cat_ctrl, string cat_id, string page, string pagesize)
        {
            var list = DataAccess_News.News_SelectPaged(cat_ctrl, cat_id, page, pagesize);

            return(list);
        }
Exemple #16
0
        /// <summary>
        /// 获取指定分类下的最新新闻
        /// </summary>
        /// <param name="cat_ctrl">qiye_show</param>
        /// <returns></returns>
        public NewsInfo LastNews_Select(string cat_ctrl)
        {
            var info = DataAccess_News.LastNews_Select("qiye_show");

            return(info);
        }
Exemple #17
0
        /// <summary>
        /// 根据文章ID获得该文章的热门评论(最新接口)
        /// </summary>
        /// <param name="sourceId"></param>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public static string GetRecommendComments2(string sourceId, string page, string limit)
        {
            int rowcount = 0;
            List <CommentInfo> cmtLst = DataAccess_News.RecommendComments_SelectPaged(sourceId, page, limit,
                                                                                      out rowcount);

            List <string> cmtIds = new List <string>();

            foreach (var cmt in cmtLst)
            {
                cmtIds.Add(cmt.cmt_uid);
                if (!string.IsNullOrEmpty(cmt.cmt_parentIds))
                {
                    cmtIds.AddRange(cmt.cmt_parentIds.Split(','));
                }
            }
            cmtIds = cmtIds.Distinct().ToList();

            var jsonSerialiser = new JavaScriptSerializer();
            var json           = "";

            // 设置没有登录的用户为匿名用户
            List <CommentInfo> comments = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmtIds.ToArray());

            foreach (CommentInfo comment in comments)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n");
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);  //存放用户头像
                comment.cmt_checkTime   = Util.Get_Gentle_Time(comment.cmt_createTime); // 存放友好时间
            }

            /*
             * 组装成网易盖楼形式
             */
            int idCount = cmtLst.Count; // 楼层数
            List <List <CommentInfo> > newPosts = new List <List <CommentInfo> >();

            for (int index = 0; (comments != null) && index < idCount; index++)
            {
                string        cmt_parentIds = cmtLst[index].cmt_parentIds; // 获得所有的父楼层Id
                List <string> idList        = new List <string>();
                if (!string.IsNullOrEmpty(cmt_parentIds))
                {
                    idList.AddRange(cmt_parentIds.Split(','));
                }

                idList.Add(cmtLst[index].cmt_uid); // 加上主楼,这样最后一楼为主楼

                Dictionary <string, CommentInfo> cmt = comments.ToDictionary(a => a.cmt_uid);
                List <CommentInfo> result            = new List <CommentInfo>();
                CommentInfo        comment           = null;
                for (int idIndex = 0; idIndex < idList.Count; idIndex++)
                {
                    if (!cmt.TryGetValue(idList[idIndex], out comment))
                    {
                        continue;
                    }

                    result.Add(comment);
                }

                newPosts.Add(result);
            }

            json = "{\"list\":" + jsonSerialiser.Serialize(newPosts) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            //CacheHelper.Cache_Store(Constants.CN_RecommendComments_New + sourceId + page + limit, json, TimeSpan.FromMinutes(10));

            return(json);
        }
Exemple #18
0
        /// <summary>
        /// 评论顶操作
        /// </summary>
        /// <param name="rData"></param>
        /// <returns></returns>
        public Stream DoAgree(RequestData rData)
        {
            // 解析得到评论ID
            var    data    = rData.details.Split('|');
            string cmt_uid = data[0].ToSafety();

            // 得到上下文
            WebOperationContext woc = WebOperationContext.Current;

            //设置响应格式,消除了返回为string的有反斜杠情况
            woc.OutgoingResponse.ContentType = "application/json; charset=utf-8";
            string json = "";

            if (cmt_uid == string.Empty)
            {
                json = Util.GetResultStr("“顶”失败:参数错误!");
                return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
            }
            //
            int result = DataAccess_News.FavorLog_Insert(cmt_uid);

            if (result > 0)
            {
                int relt = DataAccess_News.Comments_AddAccept(cmt_uid);       // 评论记录中评论“支持”字段值增1
                if (relt > 0)
                {
                    json = " { \"success\" : true, \"errors\" :  { \"text\" : \"“顶”成功!\", \"num\" : 1 } }";

                    CommentInfo comment = DataAccess_News.Comments_Selectbycmt_uid(cmt_uid);
                    if ((comment != null) && (comment.cmt_accept > 10)) // 顶超过10设为热评
                    {
                        // 判断是否已设为热评
                        List <CommentInfo> comments = DataAccess_News.RecommendComments_Selectbycmt_uid(cmt_uid);
                        if ((comments == null) || (comments.Count < 1))
                        {
                            // 设为热评
                            RecommendCommentInfo rcomment = new RecommendCommentInfo();
                            rcomment.cmt_accept       = comment.cmt_accept;
                            rcomment.cmt_checkRemark  = comment.cmt_checkRemark;
                            rcomment.cmt_checkTime    = comment.cmt_checkTime;
                            rcomment.cmt_checkUser    = comment.cmt_checkUser;
                            rcomment.cmt_content      = comment.cmt_content;
                            rcomment.cmt_createTime   = comment.cmt_createTime;
                            rcomment.cmt_createUser   = comment.cmt_createUser;
                            rcomment.cmt_createUserID = comment.cmt_createUserID;
                            rcomment.cmt_id           = comment.cmt_id;
                            rcomment.cmt_ip           = comment.cmt_ip;
                            rcomment.cmt_ipArea       = comment.cmt_ipArea;
                            rcomment.cmt_parentIds    = comment.cmt_parentIds;
                            rcomment.cmt_sourceId     = comment.cmt_sourceId;
                            rcomment.cmt_sourceType   = comment.cmt_sourceType;
                            rcomment.cmt_status       = comment.cmt_status;
                            rcomment.cmt_title        = comment.cmt_title;
                            rcomment.cmt_uid          = comment.cmt_uid;
                            rcomment.rcmt_createUser  = comment.cmt_createUser;
                            rcomment.rcmt_createTime  = DateTime.Now;
                            DataAccess_News.RecommendComments_Insert(rcomment);
                        }
                    }

                    return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
                }

                json = Util.GetResultStr("“顶”失败,请稍候再试");
                return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
            }

            json = " { \"success\" : true, \"errors\" :  { \"text\" : \"“顶”已成功!\", \"num\" : 0 } }";
            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }
Exemple #19
0
        /// <summary>
        /// 获得某文章的所有评论(最新接口)
        /// </summary>
        /// <param name="sourceId">文章Id</param>
        /// <param name="page">评论所在的页码</param>
        /// <param name="limit">页最大评论数</param>
        /// <returns></returns>
        public Stream Comments_SelectPaged2(string sourceId, string page, string limit)
        {
            WebOperationContext context = WebOperationContext.Current;

            context.OutgoingResponse.ContentType = "application/json; charset=utf-8";

            // 设置评论搜索条件
            CommentsSearchInfo search = new CommentsSearchInfo();

            search.cmt_sourceId = sourceId.ToSafetyStr();
            search.cmt_status   = 1;
            search.page         = int.Parse(page);
            search.pagesize     = int.Parse(limit);

            // 获取评论
            int rowcount = 0;
            List <CommentInfo> comments = DataAccess_News.Comments_SelectPaged(search.columns, search.ToWhereString(), search.DefOrder,
                                                                               search.page, search.pagesize, true, out rowcount);


            // 评论uid集合
            List <string> cmt_uids = new List <string>();

            foreach (var cmt in comments)
            {
                cmt_uids.Add(cmt.cmt_uid);
                if (!string.IsNullOrEmpty(cmt.cmt_parentIds))
                {
                    cmt_uids.AddRange(cmt.cmt_parentIds.Split(','));
                }
            }
            cmt_uids = cmt_uids.Distinct().ToList();

            var jsonSerializer = new JavaScriptSerializer();
            var json           = "";

            // 获取所有评论uid的评论
            List <CommentInfo> commentList = null;

            commentList = DataAccess_News.Comments_Selectbycmt_uidStrs(sourceId, cmt_uids.ToArray());
            foreach (CommentInfo comment in commentList)
            {
                comment.cmt_createUser  = (comment.cmt_createUserID == -1) ? "匿名用户" : comment.cmt_createUser;
                comment.cmt_content     = HtmlHelper.DecodeHTMLString(comment.cmt_content, false).Replace("<br/>", "\n"); // 解析编码后的危险字符
                comment.cmt_checkRemark = Util.UserFace_Get(comment.cmt_createUserID);                                    //存放用户头像
            }
            json = jsonSerializer.Serialize(comments);

            /*
             * 组装成网易盖楼形式
             */
            int idCount = comments.Count;   // 楼层数
            List <List <CommentInfo> > newPosts = new List <List <CommentInfo> >();

            for (int index = 0; index < idCount; index++)
            {
                string        cmt_parentIds = comments[index].cmt_parentIds; // 获取所有父楼层Id
                List <string> idList        = new List <string>();           // 所有楼层id列表
                if (!string.IsNullOrEmpty(cmt_parentIds))
                {
                    idList.AddRange(cmt_parentIds.Split(','));
                }
                // 加上主楼
                idList.Add(comments[index].cmt_uid);

                Dictionary <string, CommentInfo> cmt = commentList.ToDictionary(a => a.cmt_uid);
                List <CommentInfo> result            = new List <CommentInfo>();
                CommentInfo        info = null;
                for (int idIndex = 0; idIndex < idList.Count; idIndex++)
                {
                    if (!cmt.TryGetValue(idList[idIndex], out info))
                    {
                        continue;
                    }
                    result.Add(info);
                }
                newPosts.Add(result);
            }
            json = "{\"list\":" + jsonSerializer.Serialize(newPosts) + ",\"page\":" + page + ",\"pageSize\":" + limit + ",\"total\":" + rowcount + ",\"sourceId\":\"" + sourceId + "\"}";

            return(new MemoryStream(Encoding.UTF8.GetBytes(json)));
        }