/// <summary> /// 给指定帖子评分 /// </summary> /// <param name="postidlist">帖子列表</param> /// <param name="score">要加/减的分值列表</param> /// <param name="extcredits">对应的扩展积分列表</param> /// <returns>更新数量</returns> public static int RatePosts(int tid, string postidlist, string score, string extcredits, int userid, string username, string reason) { if (!Utils.IsNumericList(postidlist)) { return(0); } float[] extcreditslist = new float[] { 0, 0, 0, 0, 0, 0, 0, 0 }; string[] tmpScorelist = Utils.SplitString(score, ","); string[] tmpExtcreditslist = Utils.SplitString(extcredits, ","); int tempExtc = 0; string posttableid = Data.PostTables.GetPostTableId(tid); for (int i = 0; i < tmpExtcreditslist.Length; i++) { tempExtc = TypeConverter.StrToInt(tmpExtcreditslist[i], -1); if (tempExtc > 0 && tempExtc < extcreditslist.Length) { extcreditslist[tempExtc - 1] = TypeConverter.StrToInt(tmpScorelist[i]); //更新相应帖子的积分数 foreach (string pid in Utils.SplitString(postidlist, ",")) { if (pid.Trim() != string.Empty) { SetPostRate(posttableid, TypeConverter.StrToInt(pid), TypeConverter.StrToInt(tmpExtcreditslist[i]), TypeConverter.StrToFloat(tmpScorelist[i]), true); } } AdminRateLogs.InsertLog(postidlist, userid, username, tempExtc, TypeConverter.StrToFloat(tmpScorelist[i]), reason); } } return(UserCredits.UpdateUserExtCredits(GetUserListWithPostlist(tid, postidlist), extcreditslist)); }
/// <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); }