示例#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);
            }
        }
示例#2
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)
        {
            topicinfo.Special = 3;

            Topics.UpdateSpecial(topicinfo);//更新标志位为已结帖状态

            //开始给分和记录
            int    winerId = 0, isbest = 0, postid = 0, bonus = 0;
            string winnerName = string.Empty;

            for (int i = 0; i < winerIdArray.Length; i++)
            {
                winerId    = winerIdArray[i];
                bonus      = Utils.StrToInt(costBonusArray[i], 0);
                winnerName = winnerNameArray[i];
                postid     = postIdArray[i];

                if (winerId > 0 && bonus > 0)
                {
                    Users.UpdateUserExtCredits(winerId, Scoresets.GetCreditsTrans(), bonus);
                }
                if (Utils.InArray(postid.ToString(), valuableAnswerArray))
                {
                    isbest = 1;
                }
                if (postid == bestAnswer)
                {
                    isbest = 2;
                }


                AddLog(topicinfo.Tid, topicinfo.Posterid, winerId, winnerName, postid, bonus, isbest);
            }
        }
示例#3
0
        /// <summary>
        /// 根据用户信息重新计算用户积分
        /// </summary>
        /// <param name="shortUserInfo">用户信息</param>
        /// <returns>用户积分</returns>
        public static int GetUserCreditsByUserInfo(ShortUserInfo shortUserInfo)
        {
            string ArithmeticStr = Scoresets.GetScoreCalFormula();

            if (Utils.StrIsNullOrEmpty(ArithmeticStr))
            {
                return(0);
            }

            ArithmeticStr = ArithmeticStr.Replace("digestposts", shortUserInfo.Digestposts.ToString());
            ArithmeticStr = ArithmeticStr.Replace("posts", shortUserInfo.Posts.ToString());
            ArithmeticStr = ArithmeticStr.Replace("oltime", shortUserInfo.Oltime.ToString());
            ArithmeticStr = ArithmeticStr.Replace("pageviews", shortUserInfo.Pageviews.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits1", shortUserInfo.Extcredits1.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits2", shortUserInfo.Extcredits2.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits3", shortUserInfo.Extcredits3.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits4", shortUserInfo.Extcredits4.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits5", shortUserInfo.Extcredits5.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits6", shortUserInfo.Extcredits6.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits7", shortUserInfo.Extcredits7.ToString());
            ArithmeticStr = ArithmeticStr.Replace("extcredits8", shortUserInfo.Extcredits8.ToString());

            object expression = Arithmetic.ComputeExpression(ArithmeticStr);

            return(Utils.StrToInt(Math.Floor(Utils.StrToFloat(expression, 0)), 0));
        }
示例#4
0
        /// <summary>
        /// 购买主题
        /// </summary>
        /// <param name="uid">用户id</param>
        /// <param name="tid">主题id</param>
        /// <param name="posterid">发帖者用户id</param>
        /// <param name="price">价格</param>
        /// <param name="netamount"></param>
        /// <returns></returns>
        public static int BuyTopic(int uid, int tid, int posterid, int price, float netamount)
        {
            int tmpprice = price;

            if (price > Scoresets.GetMaxIncPerTopic())
            {
                tmpprice = Scoresets.GetMaxIncPerTopic();
            }

            ShortUserInfo userInfo = Discuz.Data.Users.GetShortUserInfo(uid);

            if (userInfo == null)
            {
                return(-2);
            }

            if (GetUserExtCredits(userInfo, Scoresets.GetTopicAttachCreditsTrans()) < price)
            {
                return(-1);
            }

            Discuz.Data.Users.BuyTopic(uid, tid, posterid, price, netamount, Scoresets.GetTopicAttachCreditsTrans());
            UserCredits.UpdateUserCredits(uid);
            UserCredits.UpdateUserCredits(posterid);
            return(Discuz.Data.PaymentLogs.CreatePaymentLog(uid, tid, posterid, price, netamount));
        }
示例#5
0
        /// <summary>
        /// 根据积分公式更新用户积分,并且受分数变动影响有可能会更改用户所属的用户组
        /// <param name="uid">用户ID</param>
        /// </summary>
        public static int UpdateUserCredits(int uid)
        {
            UserInfo tmpUserInfo = Users.GetUserInfo(uid);

            if (tmpUserInfo == null)
            {
                return(0);
            }

            DatabaseProvider.GetInstance().UpdateUserCredits(uid, Scoresets.GetScoreCalFormula());
            tmpUserInfo = Users.GetUserInfo(uid);
            UserGroupInfo tmpUserGroupInfo = UserGroups.GetUserGroupInfo(tmpUserInfo.Groupid);

            if (tmpUserGroupInfo != null && tmpUserGroupInfo.System == 0 && tmpUserGroupInfo.Radminid == 0)
            {
                tmpUserGroupInfo = GetCreditsUserGroupID(tmpUserInfo.Credits);
                DatabaseProvider.GetInstance().UpdateUserGroup(uid, tmpUserGroupInfo.Groupid);
                OnlineUsers.UpdateGroupid(uid, tmpUserGroupInfo.Groupid);
            }
            else
            {
                //当用户是已删除的特殊组成员时,则运算相应积分,并更新该用户所属组信息
                if (tmpUserGroupInfo != null && tmpUserGroupInfo.Groupid == 7 && tmpUserInfo.Adminid == -1)
                {
                    tmpUserGroupInfo = GetCreditsUserGroupID(tmpUserInfo.Credits);
                    DatabaseProvider.GetInstance().UpdateUserGroup(uid, tmpUserGroupInfo.Groupid);
                    OnlineUsers.UpdateGroupid(uid, tmpUserGroupInfo.Groupid);
                }
            }
            return(1);
        }
示例#6
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>
        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));
        }
示例#7
0
        /// <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);
        }
示例#8
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);
                    }
                }
            }
        }
示例#9
0
        /// <summary>
        /// 获得扩展积分排行数组
        /// </summary>
        /// <returns></returns>
        public static ShortUserInfo[][] GetExtsRankUserArray()
        {
#if NET1
            ArrayList list = new ArrayList();
#else
            List <ShortUserInfo[]> list = new List <ShortUserInfo[]>();
#endif
            string[] score = Scoresets.GetValidScoreName();

            for (int i = 1; i < 9; i++)
            {
                if (score[i] == string.Empty)
                {
                    list.Add(new ShortUserInfo[0]);
                }
                else
                {
                    list.Add(GetUserArray("extcredits" + i.ToString()));
                }
            }

#if NET1
            return((ShortUserInfo[][])list.ToArray(typeof(ShortUserInfo[])));
#else
            return(list.ToArray());
#endif
        }
示例#10
0
 /// <summary>
 /// 发主题是否需要审核
 /// </summary>
 /// <param name="forum">主题所在的版块</param>
 /// <param name="useradminid">用户的管理组ID</param>
 /// <param name="userid">用户ID</param>
 /// <param name="userGroup">当前用户的用户组</param>
 /// <returns>true需要审核;false不需要审核</returns>
 public static bool NeedAudit(ForumInfo forum, int useradminid, int userid, UserGroupInfo userGroup)
 {
     if (useradminid == 1 || Moderators.IsModer(useradminid, userid, forum.Fid))
     {
         return(false);
     }
     if (Scoresets.BetweenTime(GeneralConfigs.GetConfig().Postmodperiods) || forum.Modnewtopics == 1 || userGroup.ModNewTopics == 1)
     {
         return(true);
     }
     return(false);
 }
示例#11
0
 /// <summary>
 /// 获取指定用户组和版信息下主题的DisplayOrder
 /// </summary>
 /// <param name="usergroupinfo">用户组信息</param>
 /// <param name="useradminid">管理组ID</param>
 /// <param name="forum">当前版块</param>
 /// <param name="topicInfo">当前主题信息</param>
 /// <param name="message">帖子内容</param>
 /// <param name="disablepost">是否受灌水限制 1,不受限制;0,受限制</param>
 /// <returns>0:正常显示;-2:待审核</returns>
 public static int GetTitleDisplayOrder(UserGroupInfo usergroupinfo, int useradminid, ForumInfo forum, TopicInfo topicInfo, string message, int disablepost)
 {
     if (useradminid == 1 || Moderators.IsModer(useradminid, topicInfo.Posterid, forum.Fid))
     {
         return(topicInfo.Displayorder);
     }
     if (forum.Modnewtopics == 1 || usergroupinfo.ModNewTopics == 1 || Scoresets.BetweenTime(GeneralConfigs.GetConfig().Postmodperiods) && disablepost != 1 || ForumUtils.HasAuditWord(topicInfo.Title) || ForumUtils.HasAuditWord(message))
     {
         return(-2);
     }
     return(topicInfo.Displayorder);
 }
示例#12
0
        /// <summary>
        /// 发回复是否需要审核
        /// </summary>
        /// <param name="forum">主题所在的版块</param>
        /// <param name="useradminid">用户的管理组ID</param>
        ///<param name="topicInfo">所回复的主题信息</param>
        /// <param name="userid">用户ID</param>
        /// <param name="disablepost">是否受灌水限制</param>
        /// <returns>true需要审核;false不需要审核</returns>
        public static bool NeedAudit(ForumInfo forum, int useradminid, TopicInfo topicInfo, int userid, int disablepost, UserGroupInfo userGroup)
        {
            if (useradminid == 1 || Moderators.IsModer(useradminid, userid, forum.Fid))
            {
                return(false);
            }
            if (Scoresets.BetweenTime(GeneralConfigs.GetConfig().Postmodperiods))
            {
                return(true);
            }
            if (forum.Modnewposts == 1 || userGroup.ModNewPosts == 1)
            {
                return(true);
            }
            else if (topicInfo.Displayorder == -2)
            {
                return(true);
            }
            return(false);

            //bool needaudit = false; //是否需要审核
            //if (Scoresets.BetweenTime(GeneralConfigs.GetConfig().Postmodperiods))
            //{
            //    needaudit = true;
            //}
            //else
            //{
            //    if (forum.Modnewposts == 1 && useradminid != 1)
            //    {
            //        if (useradminid > 1)
            //        {
            //            if (disablepost == 1 && topicInfo.Displayorder != -2)
            //            {
            //                if (useradminid == 3 && !Moderators.IsModer(useradminid, userid, forum.Fid))
            //                    needaudit = true;
            //            }
            //            else
            //                needaudit = true;
            //        }
            //        else
            //            needaudit = true;
            //    }
            //    else if (userGroup.ModNewPosts == 1 && !Moderators.IsModer(useradminid, userid, forum.Fid) && useradminid != 1)
            //        needaudit = true;
            //    else if (useradminid != 1 && topicInfo.Displayorder == -2)
            //        needaudit = true;
            //}
            //return needaudit;
        }
示例#13
0
        /// <summary>
        /// 校验用户是否可以访问论坛
        /// </summary>
        /// <returns></returns>
        private bool ValidateUserPermission()
        {
            if (onlineusercount >= config.Maxonlines && useradminid != 1 && pagename != "login.aspx" && pagename != "logout.aspx")
            {
                ShowMessage("抱歉,目前访问人数太多,你暂时无法访问论坛.", 0);
                return(false);
            }

            if (usergroupinfo.Allowvisit != 1 && useradminid != 1 && pagename != "login.aspx" && pagename != "register.aspx" && pagename != "logout.aspx" && pagename != "activationuser.aspx" && pagename != "getpassword.aspx")
            {
                ShowMessage("抱歉, 您所在的用户组不允许访问论坛", 2);
                return(false);
            }

            // 如果IP访问列表有设置则进行判断
            if (config.Ipaccess.Trim() != "")
            {
                string[] regctrl = Utils.SplitString(config.Ipaccess, "\n");
                if (!Utils.InIPArray(DNTRequest.GetIP(), regctrl))
                {
                    ShowMessage("抱歉, 系统设置了IP访问列表限制, 您无法访问本论坛", 0);
                    return(false);
                }
            }


            // 如果IP访问列表有设置则进行判断
            if (config.Ipdenyaccess.Trim() != "")
            {
                string[] regctrl = Utils.SplitString(config.Ipdenyaccess, "\n");
                if (Utils.InIPArray(DNTRequest.GetIP(), regctrl))
                {
                    ShowMessage("由于您严重违反了论坛的相关规定, 已被禁止访问.", 2);
                    return(false);
                }
            }

            // 如果当前用户请求页面不是登录页面并且当前用户非管理员并且论坛设定了时间段,当时间在其中的一个时间段内,则跳转到论坛登录页面
            if (useradminid != 1 && pagename != "login.aspx" && pagename != "logout.aspx" && usergroupinfo.Disableperiodctrl != 1)
            {
                if (Scoresets.BetweenTime(config.Visitbanperiods))
                {
                    ShowMessage("在此时间段内不允许访问本论坛", 2);
                    return(false);
                }
            }
            return(true);
        }
示例#14
0
        /// <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);
        }
示例#15
0
        /// <summary>
        /// 搜索权限判断
        /// </summary>
        /// <param name="userid"></param>
        /// <param name="lastsearchtime"></param>
        /// <param name="useradminid"></param>
        /// <param name="usergroupinfo"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static bool Search(int userid, string lastsearchtime, int useradminid, UserGroupInfo usergroupinfo, ref string msg)
        {
            // 如果当前用户非管理员并且论坛设定了禁止全文搜索时间段,当前时间如果在其中的一个时间段内,不允许全文搜索
            if (useradminid != 1 && DNTRequest.GetInt("keywordtype", 0) == 1 && usergroupinfo.Disableperiodctrl != 1)
            {
                string visittime = "";
                if (Scoresets.BetweenTime(GeneralConfigs.GetConfig().Searchbanperiods, out visittime))
                {
                    msg = "在此时间段( " + visittime + " )内用户不可以进行全文搜索";
                    return(false);
                }
            }

            if (useradminid != 1)
            {
                //判断一分钟内搜索的次数是不是超过限制值
                if (!Statistics.CheckSearchCount(GeneralConfigs.GetConfig().Maxspm))
                {
                    msg = "抱歉,系统在一分钟内搜索的次数超过了系统安全设置的上限,请稍候再试";
                    return(false);
                }

                int Interval = Utils.StrDateDiffSeconds(lastsearchtime, GeneralConfigs.GetConfig().Searchctrl);
                if (Interval <= 0)
                {
                    msg = "系统规定搜索间隔为" + GeneralConfigs.GetConfig().Searchctrl + "秒, 您还需要等待 " + (Interval * -1) + " 秒";
                    return(false);
                }

                //不是管理员,则如果设置搜索扣积分时扣除用户积分
                if (UserCredits.UpdateUserCreditsBySearch(userid) == -1)
                {
                    string addExtCreditsTip = "";
                    if (EPayments.IsOpenEPayments())
                    {
                        addExtCreditsTip = "<br/><span><a href=\"usercpcreditspay.aspx\">点击充值积分</a></span>";
                    }
                    msg = "您的积分不足, 不能执行搜索操作" + addExtCreditsTip;
                    return(false);
                }
            }
            return(true);
        }
示例#16
0
        /// <summary>
        /// 返回有名称和ID组成的一个字符串,例如1|威望|,2|金钱|,3|贡献|
        /// </summary>
        /// <returns></returns>
        public static string GetValidScoreNameAndId()
        {
            string[]      scoreNames = Scoresets.GetValidScoreName();
            StringBuilder validScore = new StringBuilder();

            for (int i = 1; i < 9; i++)
            {
                if (scoreNames[i] == string.Empty)
                {
                    continue;
                }
                validScore.Append(i);
                validScore.Append("|");
                validScore.Append(scoreNames[i]);
                validScore.Append("|");
                validScore.Append(",");
            }
            return(validScore.ToString().TrimEnd(','));
        }
示例#17
0
        /// <summary>
        /// 获得扩展积分排行数组
        /// </summary>
        /// <returns></returns>
        public static ShortUserInfo[][] GetExtsRankUserArray()
        {
            List <ShortUserInfo[]> list = new List <ShortUserInfo[]>();

            string[] score = Scoresets.GetValidScoreName();

            for (int i = 1; i < 9; i++)
            {
                if (score[i] == string.Empty)
                {
                    list.Add(new ShortUserInfo[0]);
                }
                else
                {
                    list.Add(GetUserArray("extcredits" + i.ToString()));
                }
            }

            return(list.ToArray());
        }
示例#18
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));
     }
 }
示例#19
0
        public static bool CheckPostTimeSpan(UserGroupInfo userGroupInfo, AdminGroupInfo admininfo, OnlineUserInfo olUserInfo, ShortUserInfo shortUserInfo, ref string msg)
        {
            // 如果当前用户非管理员并且论坛设定了禁止发帖时间段,当前时间如果在其中的一个时间段内,不允许用户发帖
            if (olUserInfo.Adminid != 1 && userGroupInfo.Disableperiodctrl != 1)
            {
                string visittime = "";
                if (Scoresets.BetweenTime(GeneralConfigs.GetConfig().Postbanperiods, out visittime))
                {
                    msg = "在此时间段( " + visittime + " )内用户不可以发帖";
                    return(false);
                }
            }

            if (admininfo == null || admininfo.Disablepostctrl != 1)
            {
                int Interval = Utils.StrDateDiffSeconds(olUserInfo.Lastposttime, GeneralConfigs.GetConfig().Postinterval);
                if (Interval < 0)
                {
                    msg = "系统规定发帖间隔为" + GeneralConfigs.GetConfig().Postinterval.ToString() + "秒, 您还需要等待 " + (Interval * -1).ToString() + " 秒";
                    return(false);
                }
                else if (olUserInfo.Userid != -1)
                {
                    //ShortUserInfo shortUserInfo = Discuz.Data.Users.GetShortUserInfo(olUserInfo.Userid);
                    string joindate = (shortUserInfo != null) ? shortUserInfo.Joindate : "";
                    if (joindate == "")
                    {
                        msg = "您的用户资料出现错误";
                        return(false);
                    }
                    Interval = Utils.StrDateDiffMinutes(joindate, GeneralConfigs.GetConfig().Newbiespan);
                    if (Interval < 0)
                    {
                        msg = "系统规定新注册用户必须要在" + GeneralConfigs.GetConfig().Newbiespan.ToString() + "分钟后才可以发帖, 您还需要等待 " + (Interval * -1).ToString() + " 分钟";
                        return(false);
                    }
                }
            }
            return(true);
        }
示例#20
0
        /// <summary>
        /// 获得系统设置的总积分计算公式
        /// </summary>
        /// <returns>计算公式</returns>
        private static string GetCreditsArithmetic(int uid)
        {
            string ArithmeticStr = Scoresets.GetScoreCalFormula();

            if (ArithmeticStr.Equals(""))
            {
                return("0");
            }
            string[] para =
            {
                "digestposts",
                "posts",
                "oltime",
                "pageviews",
                "extcredits1",
                "extcredits2",
                "extcredits3",
                "extcredits4",
                "extcredits5",
                "extcredits6",
                "extcredits7",
                "extcredits8"
            };


            IDataReader reader = Users.GetShortUserInfoToReader(uid);

            if (reader != null)
            {
                if (reader.Read())
                {
                    for (int i = 0; i < para.Length; i++)
                    {
                        ArithmeticStr = ArithmeticStr.Replace(para[i], Utils.StrToFloat(reader[para[i]], 0).ToString());
                    }
                }
                reader.Close();
            }
            return(ArithmeticStr);
        }
示例#21
0
        /// <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);
        }
示例#22
0
        /// <summary>
        /// 购买主题
        /// </summary>
        /// <param name="uid">用户id</param>
        /// <param name="tid">主题id</param>
        /// <param name="posterid">发帖者用户id</param>
        /// <param name="price">价格</param>
        /// <param name="netamount"></param>
        /// <returns></returns>
        public static int BuyTopic(int uid, int tid, int posterid, int price, float netamount)
        {
            int tmpprice = price;

            if (price > Scoresets.GetMaxIncPerTopic())
            {
                tmpprice = Scoresets.GetMaxIncPerTopic();
            }



            IDataReader reader = Users.GetShortUserInfoToReader(uid);

            if (reader == null)
            {
                return(-2);
            }

            if (!reader.Read())
            {
                reader.Close();
                return(-2);
            }

            if (Utils.StrToFloat(reader["extcredits" + Scoresets.GetCreditsTrans().ToString()], 0) < price)
            {
                reader.Close();
                return(-1);
            }
            reader.Close();

            DatabaseProvider.GetInstance().BuyTopic(uid, tid, posterid, price, netamount, Scoresets.GetCreditsTrans());
            UserCredits.UpdateUserCredits(uid);
            UserCredits.UpdateUserCredits(posterid);
            return(DatabaseProvider.GetInstance().AddPaymentLog(uid, tid, posterid, price, netamount));
        }
示例#23
0
        public static int BuyTopic(int uid, int tid, int posterid, int price, float netamount)
        {
            if (price > Scoresets.GetMaxIncPerTopic())
            {
                Scoresets.GetMaxIncPerTopic();
            }

            var user = User.FindByID(uid);

            if (user == null)
            {
                return(-2);
            }

            if (PaymentLogs.GetUserExtCredits(user, Scoresets.GetTopicAttachCreditsTrans()) < (float)price)
            {
                return(-1);
            }

            Discuz.Data.Users.BuyTopic(uid, tid, posterid, price, netamount, Scoresets.GetTopicAttachCreditsTrans());
            CreditsFacade.UpdateUserCredits(uid);
            CreditsFacade.UpdateUserCredits(posterid);
            return(Discuz.Data.PaymentLogs.CreatePaymentLog(uid, tid, posterid, price, netamount));
        }
示例#24
0
        /// <summary>
        /// 获得用户排行的html
        /// </summary>
        /// <param name="users"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public static string GetUserRankHtml(ShortUserInfo[] users, string type, int maxrows)
        {
            StringBuilder builder   = new StringBuilder();
            string        unit      = "";
            int           blankrows = maxrows;

            foreach (ShortUserInfo u in users)
            {
                string count = string.Empty;
                switch (type)
                {
                case "credits":
                    count = u.Credits.ToString();
                    break;

                case "extcredits1":
                    count = u.Extcredits1.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[1];
                    break;

                case "extcredits2":
                    count = u.Extcredits2.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[2];
                    break;

                case "extcredits3":
                    count = u.Extcredits3.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[3];
                    break;

                case "extcredits4":
                    count = u.Extcredits4.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[4];
                    break;

                case "extcredits5":
                    count = u.Extcredits5.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[5];
                    break;

                case "extcredits6":
                    count = u.Extcredits6.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[6];
                    break;

                case "extcredits7":
                    count = u.Extcredits7.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[7];
                    break;

                case "extcredits8":
                    count = u.Extcredits8.ToString();
                    unit  = Scoresets.GetValidScoreUnit()[8];
                    break;

                case "digestposts":
                    count = u.Digestposts.ToString();
                    break;

                case "onlinetime":
                    count = Math.Round(((double)u.Oltime) / 60, 2).ToString();
                    unit  = "小时";
                    break;

                default:
                    count = u.Posts.ToString();
                    break;
                }

                builder.AppendFormat("<li><em>{0}</em><a href=\"{1}\" target=\"_blank\">{2}</a></li>", count + (unit == string.Empty ? string.Empty : " " + unit), Urls.UserInfoAspxRewrite(u.Uid), u.Username);
                blankrows--;
            }
            for (int i = 0; i < blankrows; i++)
            {
                builder.Append("<li>&nbsp;</li>");
            }
            return(builder.ToString());
        }
示例#25
0
        /// <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);
        }
示例#26
0
 /// <summary>
 /// 获取主题附件交易积分字段名称
 /// </summary>
 /// <returns></returns>
 public static string GetTopicAttachCreditsTransName()
 {
     return(Scoresets.GetValidScoreName()[Scoresets.GetTopicAttachCreditsTrans()]);
 }
示例#27
0
        /// <summary>
        /// 获取主题帖是否可见信息
        /// </summary>
        /// <param name="forum">版块信息</param>
        /// <param name="useradminid">当前用户adminid</param>
        /// <param name="uid">当前用户id</param>
        /// <param name="userGroup">当前用户组信息</param>
        /// <param name="postinfo">帖子信息</param>
        /// <returns>0显示;1隐藏</returns>
        public static int GetTopicPostInvisible(ForumInfo forum, int useradminid, int uid, UserGroupInfo userGroup, PostInfo postinfo)
        {
            if (useradminid == 1 || Moderators.IsModer(useradminid, uid, forum.Fid))
            {
                return(0);
            }

            if (!ForumUtils.HasAuditWord(postinfo.Message) && forum.Modnewtopics == 0 && userGroup.ModNewTopics == 0 && !Scoresets.BetweenTime(GeneralConfigs.GetConfig().Postmodperiods))
            {
                return(0);
            }

            return(1);
        }
示例#28
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);
        }
示例#29
0
 /// <summary>
 /// 添加悬赏日志
 /// </summary>
 /// <param name="tid">主题Id</param>
 /// <param name="authorid">悬赏者Id</param>
 /// <param name="winerid">获奖者Id</param>
 /// <param name="winnerName">获奖者用户名</param>
 /// <param name="postid">帖子Id</param>
 /// <param name="bonus">奖励积分</param>
 /// <param name="isbest">是否是最佳答案,0=不是,1=是较好的答案,2=最佳答案</param>
 public static void AddLog(int tid, int authorid, int winerid, string winnerName, int postid, int bonus, int isbest)
 {
     DatabaseProvider.GetInstance().AddBonusLog(tid, authorid, winerid, winnerName, postid, bonus, Scoresets.GetCreditsTrans(), isbest);
 }
示例#30
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));
 }