コード例 #1
0
        /// <summary>
        /// 签到
        /// </summary>
        /// <param name="memberId"></param>
        /// <returns>已持续签到天数,0表示签到不成功</returns>
        public int SignIn(long memberId)
        {
            int result = 0;
            SiteSignInConfigInfo config = GetConfig();

            if (CanSignInByToday(memberId))
            {
                MemberSignInInfo signinfo         = GetSignInInfo(memberId);
                DateTime         _oldlastsigntime = signinfo.LastSignTime;
                signinfo.LastSignTime = DateTime.Now;
                signinfo.SignDaySum  += 1;
                //处理积分
                int  needAddIntegral = config.DayIntegral; //需要增加的各分
                bool isReward        = false;

                //连续登录
                if (_oldlastsigntime.Date == (DateTime.Now.AddDays(-1).Date))
                {
                    signinfo.DurationDaySum += 1;

                    if (config.DurationCycle > 0)
                    {
                        signinfo.DurationDay += 1;
                        if (signinfo.DurationDay > config.DurationCycle)
                        {
                            signinfo.DurationDay = 1;
                        }
                        //处理额外积分
                        if (signinfo.DurationDay == config.DurationCycle)
                        {
                            needAddIntegral += config.DurationReward;
                            isReward         = true;
                        }
                    }
                    else
                    {
                        signinfo.DurationDay = 1;
                    }
                }
                else
                {
                    signinfo.DurationDay    = 1;
                    signinfo.DurationDaySum = 1;
                }
                //积分到户
                AddIntegralToUser(memberId, needAddIntegral, isReward);
                result = signinfo.DurationDay;
                //Context.SaveChanges();
                DbFactory.Default.Update(signinfo);
            }
            return(result);
        }
コード例 #2
0
        /// <summary>
        /// 今天是否可以签到
        /// </summary>
        /// <param name="memberId"></param>
        /// <returns></returns>
        public bool CanSignInByToday(long memberId)
        {
            bool result = false;
            SiteSignInConfigInfo config = GetConfig();

            if (config.IsEnable)
            {
                result = true;
                MemberSignInInfo signinfo = GetSignInInfo(memberId);
                if (signinfo.LastSignTime.Date == DateTime.Now.Date)
                {
                    result = false;
                }
            }
            return(result);
        }
コード例 #3
0
        /// <summary>
        /// 获取签到信息
        /// </summary>
        /// <param name="memberId"></param>
        /// <returns></returns>
        public MemberSignInInfo GetSignInInfo(long memberId)
        {
            MemberSignInInfo result = null;

            result = Context.MemberSignInInfo.FirstOrDefault(d => d.UserId == memberId);
            if (result == null)
            {
                result                = new MemberSignInInfo();
                result.UserId         = memberId;
                result.LastSignTime   = DateTime.Now.AddYears(-1);
                result.DurationDay    = 0;
                result.DurationDaySum = 0;
                result.SignDaySum     = 0;
                Context.MemberSignInInfo.Add(result);
                Context.SaveChanges();
            }
            return(result);
        }