Exemplo n.º 1
0
        /// <summary>
        /// 删除主题帖(layer=0)或是回复时更新用户积分
        /// </summary>
        /// <param name="postInfo">帖子信息</param>
        /// <param name="forumInfo">版块信息</param>
        /// <param name="reserveAttach">是否保留附件</param>
        public static void DeletePost(PostInfo postInfo, ForumInfo forumInfo, bool reserveAttach)
        {
            GeneralConfigInfo configInfo = GeneralConfigs.GetConfig();

            if (configInfo.Losslessdel == 0 || Utils.StrDateDiffHours(postInfo.Postdatetime, configInfo.Losslessdel * 24) < 0)
            {
                CreditsOperationType creditsOperationType = postInfo.Layer == 0 ? CreditsOperationType.PostTopic : CreditsOperationType.PostReply;
                //获取版块积分规则
                float[] creditsValue = Forums.GetValues(
                    creditsOperationType == CreditsOperationType.PostTopic ?
                    forumInfo.Postcredits :
                    forumInfo.Replycredits
                    );

                //如果未定义版块积分规则
                if (creditsValue == null)
                {
                    creditsValue = Scoresets.GetUserExtCredits(creditsOperationType);
                }
                UpdateUserExtCredits(postInfo.Posterid, creditsValue, 1, creditsOperationType, -1, true);
                //当不保留附件时,对附件进行相应的减分操作
                if (!reserveAttach)
                {
                    int attCount = Attachments.GetAttachmentCountByPid(postInfo.Pid);
                    if (attCount != 0)
                    {
                        DeleteAttachments(postInfo.Posterid, attCount);
                    }
                }
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 发主题时更新用户积分
 /// </summary>
 /// <param name="userId">用户id</param>
 /// <param name="forumInfo">版块信息</param>
 /// <param name="isNeedAnimation">是否需要积分动画</param>
 public static void PostTopic(int userId, ForumInfo forumInfo, bool isNeedAnimation)
 {
     if (userId == -1)
     {
         return;
     }
     float[] values = Forums.GetValues(forumInfo.Postcredits);
     if (values != null) ///使用版块内积分
     {
         UpdateUserExtCredits(userId, values, false);
     }
     else ///使用默认积分
     {
         UpdateUserExtCredits(userId, 1, CreditsOperationType.PostTopic, 1, false);
     }
     if (isNeedAnimation)
     {
         WriteUpdateUserExtCreditsCookies(values != null ? values : Scoresets.GetUserExtCredits(CreditsOperationType.PostTopic));
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// 更新用户积分(适用于单用户,单个或多个操作)
 /// </summary>
 /// <param name="uid">用户ID</param>
 /// <param name="mount">更新数量,比如由上传2个附件引发此操作,那么此参数值应为2</param>
 /// <param name="creditsOperationType">积分操作类型,如发帖等</param>
 /// <param name="pos">加或减标志(正数为加,负数为减,通常被传入1或者-1)</param>
 /// <param name="allowMinus">是否允许被扣成负分,true允许,false不允许并且不进行扣分返回-1</param>
 /// <returns></returns>
 public static int UpdateUserExtCredits(int uid, int mount, CreditsOperationType creditsOperationType, int pos, bool allowMinus)
 {
     return(UpdateUserExtCredits(uid, Scoresets.GetUserExtCredits(creditsOperationType), mount, creditsOperationType, pos, allowMinus));
 }
Exemplo n.º 4
0
        /// <summary>
        /// 在数据库中删除指定主题
        /// </summary>
        /// <param name="topiclist">主题列表</param>
        /// <param name="subtractCredits">是否减少用户积分(0不减少,1减少)</param>
        /// <returns>删除个数</returns>
        public static int DeleteTopics(string topicList, int subTractCredits, bool reserveAttach)
        {
            if (!Utils.IsNumericList(topicList))
            {
                return(-1);
            }

            GeneralConfigInfo configinfo = GeneralConfigs.GetConfig();
            DataTable         dt         = Topics.GetTopicList(topicList);

            if (dt == null)
            {
                return(-1);
            }

            foreach (DataRow dr in dt.Rows)
            {
                if (TypeConverter.ObjectToInt(dr["digest"]) > 0)
                {
                    UserCredits.UpdateUserExtCredits(TypeConverter.ObjectToInt(dr["posterid"]), -1, CreditsOperationType.Digest, 1, true);
                    UserCredits.UpdateUserCredits(TypeConverter.ObjectToInt(dr["posterid"]));
                }
            }

            dt = Posts.GetPostList(topicList);
            if (dt != null)
            {
                Hashtable attUidCount = new Hashtable();
                foreach (DataRow dr in dt.Rows)
                {
                    //后台设置的项为多少天外的老帖删除不减积分,而不是多少天内删帖可以不减分
                    if (configinfo.Losslessdel == 0 || Utils.StrDateDiffHours(dr["postdatetime"].ToString(), configinfo.Losslessdel * 24) < 0)
                    {
                        CreditsOperationType creditsOperationType = TypeConverter.ObjectToInt(dr["layer"]) == 0 ? CreditsOperationType.PostTopic : CreditsOperationType.PostReply;
                        //获取版块积分规则
                        float[] creditsValue = Forums.GetValues(
                            creditsOperationType == CreditsOperationType.PostTopic ?
                            Forums.GetForumInfo(TypeConverter.ObjectToInt(dr["fid"])).Postcredits :
                            Forums.GetForumInfo(TypeConverter.ObjectToInt(dr["fid"])).Replycredits
                            );

                        //如果未定义版块积分规则
                        if (creditsValue == null)
                        {
                            creditsValue = Scoresets.GetUserExtCredits(creditsOperationType);
                        }
                        UserCredits.UpdateUserExtCredits(TypeConverter.ObjectToInt(dr["posterid"]), creditsValue, 1, creditsOperationType, -1, true);
                        int attCount = Attachments.GetAttachmentCountByPid(TypeConverter.ObjectToInt(dr["pid"]));
                        if (attCount > 0)
                        {
                            int posterid = TypeConverter.ObjectToInt(dr["posterid"]);
                            if (attUidCount.ContainsKey(posterid))
                            {
                                attUidCount[posterid] = (int)attUidCount[posterid] + attCount;
                            }
                            else
                            {
                                attUidCount.Add(TypeConverter.ObjectToInt(dr["posterid"]), attCount);
                            }
                        }
                    }
                    UserCredits.UpdateUserCredits(TypeConverter.ObjectToInt(dr["posterid"]));
                }

                int   i            = 0;
                int[] tuidlist     = new int[attUidCount.Count];
                int[] attcountlist = new int[attUidCount.Count];
                foreach (DictionaryEntry de in attUidCount)
                {
                    tuidlist[i]     = (int)de.Key;
                    attcountlist[i] = (int)de.Value;
                    i++;
                }

                UserCredits.UpdateUserCredits(tuidlist, attcountlist, CreditsOperationType.UploadAttachment, -1);
            }

            int reval = 0;

            foreach (string posttableid in Posts.GetPostTableIdArray(topicList))
            {
                reval = Discuz.Data.TopicAdmins.DeleteTopicByTidList(topicList, posttableid);
            }
            if (reval > 0 && !reserveAttach)
            {
                Attachments.DeleteAttachmentByTid(topicList);
            }
            return(reval);
        }