Beispiel #1
0
        /// <summary>
        /// 结束悬赏并给分
        /// </summary>
        /// <param name="topicinfo">主题信息</param>
        /// <param name="userid">当前执行此操作的用户Id</param>
        /// <param name="postIdArray">帖子Id数组</param>
        /// <param name="winerIdArray">获奖者Id数组</param>
        /// <param name="winnerNameArray">获奖者的用户名数组</param>
        /// <param name="costBonusArray">奖励积分数组</param>
        /// <param name="valuableAnswerArray">有价值答案的pid数组</param>
        /// <param name="bestAnswer">最佳答案的pid</param>
        public static void CloseBonus(TopicInfo topicinfo, int userid, int[] postIdArray, int[] winerIdArray, string[] winnerNameArray, string[] costBonusArray, string[] valuableAnswerArray, int bestAnswer)
        {
            int isbest = 0, bonus = 0;

            topicinfo.Special = 3;         //标示为悬赏主题
            Topics.UpdateTopic(topicinfo); //更新标志位为已结帖状态

            //开始给分和记录
            for (int i = 0; i < winerIdArray.Length; i++)
            {
                bonus = TypeConverter.StrToInt(costBonusArray[i]);
                if (winerIdArray[i] > 0 && bonus > 0)
                {
                    Users.UpdateUserExtCredits(winerIdArray[i], Scoresets.GetBonusCreditsTrans(), bonus);
                }

                if (Utils.InArray(postIdArray[i].ToString(), valuableAnswerArray))
                {
                    isbest = 1;
                }

                if (postIdArray[i] == bestAnswer)
                {
                    isbest = 2;
                }

                Discuz.Data.Bonus.AddLog(topicinfo.Tid, topicinfo.Posterid, winerIdArray[i], winnerNameArray[i], postIdArray[i], bonus, Scoresets.GetBonusCreditsTrans(), isbest);
            }
        }
Beispiel #2
0
        /// <summary>
        /// 合并主题
        /// </summary>
        /// <param name="topiclist">主题id列表</param>
        /// <param name="othertid">被合并tid</param>
        /// <returns>更新记录数</returns>
        public static int MerrgeTopics(string topicId, int othertid)
        {
            int tid   = TypeConverter.StrToInt(topicId);
            int reval = 0;
            //获得要被合并的主题的信息
            TopicInfo topicinfo    = Topics.GetTopicInfo(othertid);
            TopicInfo newTopicInfo = Topics.GetTopicInfo(tid);

            //TODO: Move them to posts
            Discuz.Data.TopicAdmins.UpdatePostTidToAnotherTopic(othertid, tid);
            Discuz.Data.TopicAdmins.UpdatePostTidToAnotherTopic(tid, tid);
            //更新附件从属
            Discuz.Data.TopicAdmins.UpdateAttachmentTidToAnotherTopic(othertid, tid);

            reval = Discuz.Data.Topics.DeleteTopic(othertid);

            if (topicinfo != null)
            {
                if (newTopicInfo.Lastpostid < topicinfo.Lastpostid)
                {
                    newTopicInfo.Lastpostid   = topicinfo.Lastpostid;
                    newTopicInfo.Lastposterid = topicinfo.Lastposterid;
                    newTopicInfo.Lastpost     = topicinfo.Lastpost;
                    newTopicInfo.Lastposter   = topicinfo.Lastposter;
                    newTopicInfo.Replies     += topicinfo.Replies;
                }
                else
                {
                    newTopicInfo.Replies += topicinfo.Replies;
                }
            }

            //更新主题信息
            PostInfo topicPost = Posts.GetPostInfo(tid, Posts.GetFirstPostId(tid));

            Discuz.Data.Topics.SetPrimaryPost(topicPost.Title, tid, new string[] { topicPost.Pid.ToString() });

            newTopicInfo.Title    = topicPost.Title;
            newTopicInfo.Posterid = topicPost.Posterid;
            newTopicInfo.Poster   = topicPost.Poster;
            Topics.UpdateTopic(newTopicInfo);

            if (topicinfo.Lastpostid == 0)
            {
                Discuz.Data.Topics.UpdateTopicLastPosterId(topicinfo.Tid);
            }

            if (newTopicInfo.Lastpostid == 0)
            {
                Discuz.Data.Topics.UpdateTopicLastPosterId(newTopicInfo.Tid);
            }

            return(reval);
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="topicinfo"></param>
 /// <returns></returns>
 public static bool UpdateTopicAllInfo(TopicInfo topicinfo)
 {
     try
     {
         Topics.UpdateTopic(topicinfo);
         return(true);
     }
     catch
     {
         return(false);
     }
 }
Beispiel #4
0
        /// <summary>
        /// 分割主题
        /// </summary>
        /// <param name="postidlist">帖子id列表</param>
        /// <param name="subject">主题</param>
        /// <param name="topicId">主题id列表</param>
        /// <returns>更新记录数</returns>
        public static int SplitTopics(string postidlist, string subject, string topicId)
        {
            //验证要分割的帖子是否为有效PID号
            string[] postIdArray = postidlist.Split(',');
            if (Utils.StrIsNullOrEmpty(postidlist) || !Utils.IsNumericArray(postIdArray))
            {
                return(-1);
            }

            int tid        = 0;
            int lastPostId = TypeConverter.StrToInt(postIdArray[postIdArray.Length - 1]);

            //将要被分割主题的tid
            TopicInfo originalTopicInfo = Topics.GetTopicInfo(TypeConverter.StrToInt(topicId)); //原主题信息
            TopicInfo newTopicInfo      = new TopicInfo();                                      //新主题信息
            PostInfo  lastPostInfo      = Posts.GetPostInfo(originalTopicInfo.Tid, lastPostId);
            PostInfo  firstPostInfo     = Posts.GetPostInfo(originalTopicInfo.Tid, TypeConverter.StrToInt(postIdArray[0]));

            newTopicInfo.Poster       = firstPostInfo.Poster;
            newTopicInfo.Posterid     = firstPostInfo.Posterid;
            newTopicInfo.Postdatetime = Utils.GetDateTime();
            newTopicInfo.Displayorder = 0;
            newTopicInfo.Highlight    = "";
            newTopicInfo.Digest       = 0;
            newTopicInfo.Rate         = 0;
            newTopicInfo.Hide         = 0;
            newTopicInfo.Special      = 0;
            newTopicInfo.Attachment   = 0;
            newTopicInfo.Moderated    = 0;
            newTopicInfo.Closed       = 0;
            newTopicInfo.Views        = 0;
            newTopicInfo.Fid          = originalTopicInfo.Fid;
            newTopicInfo.Forumname    = originalTopicInfo.Forumname;
            newTopicInfo.Iconid       = originalTopicInfo.Iconid;
            newTopicInfo.Typeid       = originalTopicInfo.Typeid;
            newTopicInfo.Replies      = postIdArray.Length - 1;
            newTopicInfo.Title        = Utils.HtmlEncode(subject);
            newTopicInfo.Lastposterid = lastPostInfo.Posterid;
            newTopicInfo.Lastpost     = lastPostInfo.Postdatetime;
            newTopicInfo.Lastposter   = lastPostInfo.Poster;

            tid = Topics.CreateTopic(newTopicInfo);
            DatabaseProvider.GetInstance().UpdatePostTid(postidlist, tid, Data.PostTables.GetPostTableId(tid));
            DatabaseProvider.GetInstance().SetPrimaryPost(subject, tid, postIdArray, Discuz.Data.PostTables.GetPostTableId(tid));

            newTopicInfo.Tid        = tid;
            newTopicInfo.Lastpostid = lastPostId;
            if (originalTopicInfo.Lastpostid == lastPostId)//当需要将原主题的最后一个发帖分割走时(即分割列表中有和原主题Lastpostid相同的值)
            {
                newTopicInfo.Lastposterid = originalTopicInfo.Posterid;
                newTopicInfo.Lastpost     = originalTopicInfo.Lastpost;
                newTopicInfo.Lastposter   = originalTopicInfo.Poster;
                DataTable dt = DatabaseProvider.GetInstance().GetLastPostNotInPidList(postidlist, originalTopicInfo.Tid, int.Parse(Posts.GetPostTableId()));
                originalTopicInfo.Lastpostid   = TypeConverter.ObjectToInt(dt.Rows[0]["pid"]);
                originalTopicInfo.Lastposterid = TypeConverter.ObjectToInt(dt.Rows[0]["Posterid"].ToString());
                originalTopicInfo.Lastpost     = dt.Rows[0]["Postdatetime"].ToString();
                originalTopicInfo.Lastposter   = dt.Rows[0]["Poster"].ToString();
            }
            originalTopicInfo.Replies = originalTopicInfo.Replies - postIdArray.Length;

            Topics.UpdateTopic(originalTopicInfo);//更新原主题的信息
            Topics.UpdateTopicReplyCount(originalTopicInfo.Tid);

            Topics.UpdateTopic(newTopicInfo);//由于数据库中对lastpostid有list约束,所以不能有重复值,则必须在原主题的lastpostid修改之后再次修改才能将数据最终修正完毕
            Topics.UpdateTopicReplyCount(tid);

            return(tid);
        }