/// <summary> /// 检查用户积分是否足够被减(适用于单用户, 单个或多个积分) /// </summary> /// <param name="uid">用户ID</param> /// <param name="mount">更新数量,比如由上传2个附件引发此操作,那么此参数值应为2</param> /// <param name="creditsOperationType">积分操作类型,如发帖等</param> /// <param name="pos">加或减标志(正数为加,负数为减,通常被传入1或者-1)</param> /// <returns></returns> public static bool CheckUserCreditsIsEnough(int uid, int mount, CreditsOperationType creditsOperationType, int pos) { DataTable dt = Scoresets.GetScoreSet(); dt.PrimaryKey = new DataColumn[1] { dt.Columns["id"] }; float[] extCredits = new float[8]; for (int i = 0; i < 8; i++) { extCredits[i] = TypeConverter.ObjectToFloat(dt.Rows[(int)creditsOperationType]["extcredits" + (i + 1)]); } if (pos < 0) { for (int i = 0; i < 8; i++) { if (Utils.StrToFloat(extCredits[i], 0) < 0)//只要任何一项要求减分,就去数据库检查 { return(Discuz.Data.UserCredits.CheckUserCreditsIsEnough(uid, extCredits, pos, mount)); } } } return(true); }
/// <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> private static int UpdateUserCredits(int uid, int mount, CreditsOperationType creditsOperationType, int pos, bool allowMinus) { if (!Users.Exists(uid)) { return(0); } DataTable dt = Scoresets.GetScoreSet(); DataColumn[] keys = new DataColumn[1]; keys[0] = dt.Columns["id"]; dt.PrimaryKey = keys; DataRow dr = dt.Rows[(int)creditsOperationType]; // 如果要减扩展积分, 首先判断扩展积分是否足够被减 if (pos < 0) { //当不是删除主题或回复时 if (creditsOperationType != CreditsOperationType.PostTopic && creditsOperationType != CreditsOperationType.PostReply) { if (!allowMinus && !DatabaseProvider.GetInstance().CheckUserCreditsIsEnough(uid, dr, pos, mount)) { return(-1); } } } DatabaseProvider.GetInstance().UpdateUserCredits(uid, dr, pos, mount); ///更新用户积分 return(UpdateUserCredits(uid)); }
/// <summary> /// 检查用户积分是否足够被减(适用于单用户, 单个或多个积分) /// </summary> /// <param name="uid">用户ID</param> /// <param name="mount">更新数量,比如由上传2个附件引发此操作,那么此参数值应为2</param> /// <param name="creditsOperationType">积分操作类型,如发帖等</param> /// <param name="pos">加或减标志(正数为加,负数为减,通常被传入1或者-1)</param> /// <returns></returns> public static bool CheckUserCreditsIsEnough(int uid, int mount, CreditsOperationType creditsOperationType, int pos) { DataTable dt = Scoresets.GetScoreSet(); DataColumn[] keys = new DataColumn[1]; keys[0] = dt.Columns["id"]; dt.PrimaryKey = keys; DataRow dr = dt.Rows[(int)creditsOperationType]; for (int i = 2; i < 10; i++) { if (Utils.StrToFloat(dr[i], 0) < 0)//只要任何一项要求减分,就去数据库检查 { return(DatabaseProvider.GetInstance().CheckUserCreditsIsEnough(uid, dr, pos, mount)); } } return(true); }
/// <summary> /// 创建临时用户组积分表 /// </summary> /// <returns></returns> private static DataTable CreateGroupScoreTable() { DataTable templateDT = new DataTable("templateDT"); templateDT.Columns.Add("id", Type.GetType("System.Int32")); templateDT.Columns.Add("available", Type.GetType("System.Boolean")); //是否参与积分字段 templateDT.Columns.Add("ScoreCode", Type.GetType("System.Int32")); //积分代号 templateDT.Columns.Add("ScoreName", Type.GetType("System.String")); //积分名称 templateDT.Columns.Add("Min", Type.GetType("System.String")); //评分最小值 templateDT.Columns.Add("Max", Type.GetType("System.String")); //评分最大值 templateDT.Columns.Add("MaxInDay", Type.GetType("System.String")); //24小时最大评分数 templateDT.Columns.Add("Options", Type.GetType("System.String")); //options HTML代码 //向表中加载默认设置 for (int rowcount = 0; rowcount < 8; rowcount++) { DataRow dr = templateDT.NewRow(); dr["id"] = rowcount + 1; dr["available"] = false; dr["ScoreCode"] = rowcount + 1; dr["ScoreName"] = ""; dr["Min"] = ""; dr["Max"] = ""; dr["MaxInDay"] = ""; templateDT.Rows.Add(dr); } //通过CONFIG文件得到相关的ScoreName名称设置 DataRow scoresetname = Scoresets.GetScoreSet().Rows[0]; for (int count = 0; count < 8; count++) { if ((!Utils.StrIsNullOrEmpty(scoresetname[count + 2].ToString())) && (scoresetname[count + 2].ToString().Trim() != "0")) { templateDT.Rows[count]["ScoreName"] = scoresetname[count + 2].ToString().Trim(); } } return(templateDT); }
/// <summary> /// 通过组ID得到允许的评分范围,如果无设置则返回空表 /// </summary> /// <param name="groupid">组ID</param> /// <returns>评分范围</returns> public static DataTable GroupParticipateScore(int groupid) { DataTable dt = DatabaseProvider.GetInstance().GetUserGroupRateRange(groupid); if (dt.Rows.Count > 0) { if (dt.Rows[0][0].ToString().Trim() == "") { //当用户组未设置允许的评分范围时返回空表 return((DataTable)null); } else { //创建并初始化表结构 DataTable templateDT = new DataTable("templateDT"); templateDT.Columns.Add("id", Type.GetType("System.Int32")); //是否参与积分字段 templateDT.Columns.Add("available", Type.GetType("System.Boolean")); //积分代号 templateDT.Columns.Add("ScoreCode", Type.GetType("System.Int32")); //积分名称 templateDT.Columns.Add("ScoreName", Type.GetType("System.String")); //评分最小值 templateDT.Columns.Add("Min", Type.GetType("System.String")); //评分最大值 templateDT.Columns.Add("Max", Type.GetType("System.String")); //24小时最大评分数 templateDT.Columns.Add("MaxInDay", Type.GetType("System.String")); //options HTML代码 templateDT.Columns.Add("Options", Type.GetType("System.String")); //templateDT.Columns["Options"].MaxLength = 2000; //向表中加载默认设置 for (int rowcount = 0; rowcount < 8; rowcount++) { DataRow dr = templateDT.NewRow(); dr["id"] = rowcount + 1; dr["available"] = false; dr["ScoreCode"] = rowcount + 1; dr["ScoreName"] = ""; dr["Min"] = ""; dr["Max"] = ""; dr["MaxInDay"] = ""; templateDT.Rows.Add(dr); } //通过CONFIG文件得到相关的ScoreName名称设置 DataRow scoresetname = Scoresets.GetScoreSet().Rows[0]; for (int count = 0; count < 8; count++) { if ((scoresetname[count + 2].ToString().Trim() != "") && (scoresetname[count + 2].ToString().Trim() != "0")) { templateDT.Rows[count]["ScoreName"] = scoresetname[count + 2].ToString().Trim(); } } //用数据库中的记录更新已装入的默认数据 int i = 0; foreach (string raterangestr in dt.Rows[0][0].ToString().Trim().Split('|')) { if (raterangestr.Trim() != "") { string[] scoredata = raterangestr.Split(','); //判断是否参与积分字段的数据判断 if (scoredata[1].Trim() == "True") { templateDT.Rows[i]["available"] = true; } //更新其它字段 templateDT.Rows[i]["Min"] = scoredata[4].Trim(); templateDT.Rows[i]["Max"] = scoredata[5].Trim(); templateDT.Rows[i]["MaxInDay"] = scoredata[6].Trim(); } i++; } return(templateDT); } } //当用户组不存在时返回空 return(null); }