Beispiel #1
0
        /// <summary>
        /// 搜索文章
        /// </summary>
        /// <param name="key"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        private List <S> SearchArticles(string key, Paging page)
        {
            long             userId       = UserID;
            bool             islogin      = IsLogin;
            var              models       = new List <S>();
            ArticleViewModel articleModel = new ArticleViewModel();
            var              list         = ArticleBLL.Instance.GetAllArticles(page, key);

            //内容付费记录
            List <ContentBuyLog> contentBuyLogs = null;

            if (islogin)
            {
                List <long> aids     = list.Select(a => a.ArticleId).ToList();
                int         maintype = ContentFeeMainEnumType.Article.GetHashCode();
                contentBuyLogs = DB.ContentBuyLog.Where(a => a.BuyerId == userId && a.MainType == maintype && aids.Contains(a.MainID)).ToList();
            }
            list.ForEach(a =>
            {
                var s       = new S();
                string body = HtmlRegexHelper.ToText(a.Body);
                s.Desc      = body;
                s.Title     = a.Title;
                s.Id        = a.ArticleId.ToString();
                s.type      = 2;
                if (a.ContentNeedPay.HasValue && a.ContentNeedPay.Value)
                {
                    if (islogin)
                    {
                        //如果已登录,且不是该作者并用没有付费
                        if (a.UserID != userId && contentBuyLogs.FirstOrDefault(t => t.MainID == a.ArticleId) == null)
                        {
                            s.Desc = "该贴内容需要付费,<span style='color:red;'>{0}{1}</span>,请付费后查看。".FormatWith(a.ContentFee, a.ContentFeeType == ContentFeeTypeEnum.score.GetHashCode() ? "积分" : "金钱");
                        }
                        else
                        {
                            if (body.Length > 200)
                            {
                                s.Desc = body.Substring(0, 200);
                            }
                        }
                    }
                    else
                    {
                        s.Desc = "该贴内容需要付费,<span style='color:red;'>{0}{1}</span>,请付费后查看。".FormatWith(a.ContentFee, a.ContentFeeType == ContentFeeTypeEnum.score.GetHashCode() ? "积分" : "金钱");
                    }
                }
                else
                {
                    if (body.Length > 200)
                    {
                        s.Desc = body.Substring(0, 200);
                    }
                }
                models.Add(s);
            });
            return(models);
        }
        public ActionResult Publish(string title, string body)
        {
            ResultInfo ri = new ResultInfo();

            if (!string.IsNullOrEmpty(title))
            {
                if (!string.IsNullOrEmpty(body))
                {
                    //是否匿名、
                    bool isanonymous = GetRequest <bool>("isanonymous");

                    bool   contentNeedFee = GetRequest <bool>("contentNeedFee");
                    int    contentFeeType = GetRequest <int>("contentFeeType");
                    int    contentFee     = GetRequest <int>("contentFee");
                    string attachIndex    = GetRequest("attachIndexs");
                    var    fileFee        = JsonHelper.JsonToModel <List <FileFee> >("[" + GetRequest("fees") + "]");//附件费用

                    string   tagsrequest = GetRequest("tags");
                    string[] tags        = tagsrequest.IsNotNullOrEmpty() ? tagsrequest.Split(',') : null;

                    List <AttachMent> attachMents = new List <AttachMent>();
                    try
                    {
                        var fileOk = true;

                        #region 先上传附件再生成数据
                        if (attachIndex.IsNotNullOrEmpty())
                        {
                            var attachIndexs = attachIndex.Split(',');
                            attachIndexs.ForEach(i =>
                            {
                                var file       = Request.Files["file" + i];
                                var fileResult = UpLoadFile(file, "/Content/U/Art/FuJian", needValidatFile: false, rename: false);
                                fileOk         = fileResult.Ok;
                                if (fileResult.Ok)
                                {
                                    var attachment = new AttachMent
                                    {
                                        AttachMentId = Guid.NewGuid(),
                                        CreateTime   = DateTime.Now,
                                        CreateUser   = UserID,
                                        DownCount    = 0,
                                        FileName     = fileResult.Data.FileName,
                                        FilePath     = fileResult.Data.FilePath,
                                        FileSize     = fileResult.Data.FileSize,
                                        MainType     = AttachEnumType.Article.GetHashCode(),
                                        IsDelete     = 0
                                    };
                                    int _index        = i.ToInt32();
                                    var attachFeeInfo = fileFee.FirstOrDefault(a => a.Index == _index);
                                    if (attachFeeInfo != null)
                                    {
                                        attachment.FeeType = attachFeeInfo.FeeType;
                                        attachment.Fee     = attachFeeInfo.Fee;
                                        attachment.IsFee   = attachFeeInfo.FeeType != 0;
                                    }
                                    attachMents.Add(attachment);
                                }
                            });
                        }
                        #endregion

                        if (fileOk)
                        {
                            BeginTran();
                            Article model = new Article()
                            {
                                Body       = HttpUtility.UrlDecode(body),
                                CreateTime = DateTime.Now,
                                IsDelete   = 0,
                                Title      = title,
                                UserID     = UserID,
                                PVCount    = 0,
                                //FilePath = fileResultInfo.Url,
                                EditCount  = 0,
                                CreateUser = UserID.ToString(),
                                UpdateUser = UserID.ToString(),
                                UpdateTime = DateTime.Now,

                                IsAnonymous = isanonymous,
                            };

                            model.ContentNeedPay = contentNeedFee;
                            //内容付费
                            if (contentNeedFee)
                            {
                                model.ContentFeeType = contentFeeType;
                                model.ContentFee     = contentFee;
                            }

                            UserExt userext = UserExtBLL.Instance.GetExtInfo(UserID);

                            //先判断该用户是否被设置成了需要审核,如果没设置的话,再判断系统系统
                            if (userext.CheckBBS == 1)
                            {
                                model.IsChecked = 1;
                            }
                            else
                            {
                                //判断是否触发审核机制:积分大于1000分时,必须要参加审核
                                int mustcheckscore = Convert.ToInt32(ConfigHelper.AppSettings("MustCheckByScore"));
                                //积分大于多少时自动审核
                                int autocheckscore = Convert.ToInt32(ConfigHelper.AppSettings("AutoCheck_NeedScore"));
                                model.IsChecked = userext.TotalScore >= mustcheckscore ? userext.TotalScore <= autocheckscore ? 1 : 2 : 2;
                            }
                            int result = ArticleBLL.Instance.Add(model, Tran);
                            if (result > 0)
                            {
                                //创建成功后 第一时间 添加附件数据
                                attachMents.ForEach(attach => attach.MainId = result);
                                if (QuestionBLL.Instance.AddAttachMent(attachMents, Tran))
                                {
                                    //处理标签
                                    //如果用户没有添加标签,则根据算法匹配
                                    if (tags == null || tags.Length == 0)
                                    {
                                        List <string> newTags = new List <string>();
                                        //获取目前所有标签
                                        var currentTags = DB.Tag.Where(a => a.IsDelete == 0).Select(a => new { tagId = a.TagId, name = a.TagName }).ToList();
                                        var fittler     = HtmlRegexHelper.ToText(HttpUtility.UrlDecode(body)) + HtmlRegexHelper.ToText(title);
                                        var segObj      = new JiebaSegmenter();
                                        var segs        = segObj.Cut(fittler, cutAll: true).GroupBy(a => a).Select(a => a.Key).ToList();
                                        foreach (var seg in segs)
                                        {
                                            var match = currentTags.FirstOrDefault(a => a.name == seg);
                                            if (match != null)
                                            {
                                                if (newTags.Count < 3)
                                                {
                                                    newTags.Add(match.tagId.ToString());
                                                }
                                            }
                                            if (newTags.Count == 3)
                                            {
                                                break;
                                            }
                                        }
                                        if (newTags.Count == 0)
                                        {
                                            //如果没有匹配到,则创建
                                            var tagName = WordSpliterHelper.GetKeyword(fittler, true);
                                            if (tagName.Length > 6)
                                            {
                                                tagName = tagName.Substring(0, 6);
                                            }
                                            Tag tag = new Tag()
                                            {
                                                CreateTime    = DateTime.Now,
                                                CreateUser    = UserID.ToString(),
                                                TagBelongId   = 1038,
                                                TagName       = tagName,
                                                TagCreateType = 3,
                                                IsDelete      = 0,
                                            };
                                            var resultTag = TagBLL.Instance.Add(tag);
                                            newTags.Add(resultTag.ToString());
                                        }
                                        tags = newTags.ToArray();
                                    }

                                    if (MenuBelongTagBLL.Instance.HandleTags(result, CommentEnumType.Article, 1038, tags, Tran))
                                    {
                                        string uri = ConfigHelper.AppSettings("ArticleDetail").FormatWith(result);
                                        if (model.IsChecked == 1)
                                        {
                                            //通知发布用户 和 管理员
                                            noticeService.On_BBS_Article_Publish_Success_Notice(UserInfo, uri, title, 2);
                                            ri.Msg = "文章发表成功,您发布的文章成功触发系统审核机制,等待管理员审核成功后即可在页面里查看";
                                            ri.Url = "/Article";
                                        }
                                        else
                                        {
                                            ri.Msg = "文章发表成功";
                                            ri.Url = uri;
                                        }
                                        //异步通知关注者
                                        NoticeBLL.Instance.OnAdd_Notice_Liker(UserInfo.UserName, UserID, uri, model.Title, NoticeTypeEnum.Article_Add, GetDomainName);
                                        _scoreService.AddScoreOnPublish_BBS_Article(UserID, result, ScoreBeloneMainEnumType.Publish_Article, CoinSourceEnum.NewArticle);
                                        Commit();
                                        ri.Ok = true;
                                    }
                                    else
                                    {
                                        RollBack();
                                    }
                                }
                                else
                                {
                                    ri.Msg = "添加附件时失败,请重试";
                                    RollBack();
                                    //删除附件
                                    attachMents.ForEach(attach =>
                                    {
                                        UploadHelper.DeleteUpFile(attach.FilePath);
                                    });
                                }
                            }
                            else
                            {
                                RollBack();
                                ri.Msg = "文章发表失败";
                                //删除附件
                                attachMents.ForEach(attach =>
                                {
                                    UploadHelper.DeleteUpFile(attach.FilePath);
                                });
                            }
                        }
                        else
                        {
                            //删除附件
                            attachMents.ForEach(attach =>
                            {
                                UploadHelper.DeleteUpFile(attach.FilePath);
                            });
                        }
                    }
                    catch (Exception e)
                    {
                        ri.Msg = "新增文章失败";
                        RollBack();
                        //删除附件
                        attachMents.ForEach(attach =>
                        {
                            UploadHelper.DeleteUpFile(attach.FilePath);
                        });
                    }
                }
                else
                {
                    ri.Msg = "文章内容不能为空";
                }
            }
            else
            {
                ri.Msg = "文章标题不能为空";
            }
            return(Result(ri));
        }
Beispiel #3
0
        /// <summary>
        /// 搜索帖子
        /// </summary>
        /// <param name="key"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        private List <S> SearchQuestion(string key, Paging page)
        {
            var  models = new List <S>();
            int  normalUserSee_Score = ConfigHelper.AppSettings("normalUserSee_Score").ToInt32();//普通用户查看 other 版块 所需积分
            long userId  = UserID;
            bool islogin = IsLogin;
            bool isVip   = islogin ? UserBaseBLL.Instance.IsVIP(userId) : false;//当前用户是否VIP用户
            var  list    = QuestionBLL.Instance.SearchQuestion(key, page);

            //获取 1037 是否付费
            List <BuyOtherLog>   payFor1037logs = null;
            List <ContentBuyLog> contentBuyLogs = null;

            if (islogin)
            {
                List <long> qids     = list.Select(a => a.QuestionId).ToList();
                int         maintype = ContentFeeMainEnumType.BBS.GetHashCode();
                payFor1037logs = DB.BuyOtherLog.Where(a => a.CreateUser == userId && qids.Contains(a.MainID)).ToList();
                contentBuyLogs = DB.ContentBuyLog.Where(a => a.BuyerId == userId && a.MainType == maintype && qids.Contains(a.MainID)).ToList();
            }

            list.ForEach(q =>
            {
                var s       = new S();
                string body = HtmlRegexHelper.ToText(q.Body);
                s.Desc      = body;
                s.type      = 1;
                s.Title     = q.Title;
                s.Id        = q.QuestionId.ToString();
                if (q.TopicID == 1037)
                {
                    if (islogin)
                    {
                        //q.HideForNoVipUserOrNotBuy = !isVip && DB.BuyOtherLog.FirstOrDefault(buyother => buyother.CreateUser == userId && buyother.MainID == q.QuestionId) == null;
                        q.HideForNoVipUserOrNotBuy = !isVip && payFor1037logs.FirstOrDefault(a => a.MainID == q.QuestionId) == null;
                    }
                    else
                    {
                        q.HideForNoVipUserOrNotBuy = true;
                    }

                    if (q.HideForNoVipUserOrNotBuy)
                    {
                        s.Desc = "本条<a class='btn-buyOtherItem' data-id='{0}' data-c='{1}'>查看</a>需要 {1} 积分,<a href='/user/scoreexchange#scoreexchange' target='_self'>会员</a>可享受免费查看".FormatWith(q.QuestionId, normalUserSee_Score);
                    }
                    else
                    {
                        //判断是否内容付费
                        if (q.ContentNeedPay.HasValue && q.ContentNeedPay.Value)
                        {
                            if (contentBuyLogs.FirstOrDefault(a => a.MainID == q.QuestionId) == null)
                            {
                                s.Desc = "该贴内容需要付费,{0}{1},请付费后查看。".FormatWith(q.ContentFee, q.ContentFeeType == 1 ? "积分" : "金钱");
                            }
                            else
                            {
                                if (body.Length > 200)
                                {
                                    s.Desc = body.Substring(0, 200);
                                }
                            }
                        }
                        else
                        {
                            if (body.Length > 200)
                            {
                                s.Desc = body.Substring(0, 200);
                            }
                        }
                    }
                }
                else
                {
                    //判断是否需要内容付费
                    if (q.ContentNeedPay.HasValue && q.ContentNeedPay.Value)
                    {
                        if (islogin)
                        {
                            if (q.UserID != userId && contentBuyLogs.FirstOrDefault(a => a.MainID == q.QuestionId) == null)
                            {
                                s.Desc = "该贴内容需要付费,<span style='color:red;'>{0}{1}</span>,请付费后查看。".FormatWith(q.ContentFee, q.ContentFeeType == ContentFeeTypeEnum.score.GetHashCode() ? "积分" : "金钱");
                            }
                            else
                            {
                                if (body.Length > 200)
                                {
                                    s.Desc = body.Substring(0, 200);
                                }
                            }
                        }
                        else
                        {
                            s.Desc = "该贴内容需要付费,<span style='color:red;'>{0}{1}</span>,请付费后查看。".FormatWith(q.ContentFee, q.ContentFeeType == ContentFeeTypeEnum.score.GetHashCode() ? "积分" : "金钱");
                        }
                    }
                    else
                    {
                        if (body.Length > 200)
                        {
                            s.Desc = body.Substring(0, 200);
                        }
                    }
                }
                models.Add(s);
            });
            return(models);
        }