示例#1
0
        private async Task SetModal(TaskItem item, TaskInfo taskInfo, MemberIncome thisIncome = null)
        {
            thisIncome = thisIncome == null ? new MemberIncome() : thisIncome;
            //判断来源类型
            if (taskInfo.TaskCode == "T0009" || taskInfo.TaskCode == "T0008")
            {
                thisIncome.FromType = 1;//视频
            }
            else if (taskInfo.TaskCode == "T0007" || taskInfo.TaskCode == "T0006")
            {
                thisIncome.FromType = 2;//文章
            }
            else
            {
                thisIncome.FromType = 0;//默认
            }
            thisIncome.MemberId = item.MemberId;
            thisIncome.TaskId   = taskInfo.TaskId;

            thisIncome.InvitedId = item.InvitedId;
            thisIncome.FromId    = item.FromId;
            thisIncome.FromMark  = item.FromMark;

            thisIncome.TaskCode      = taskInfo.TaskCode;
            thisIncome.TaskName      = taskInfo.TaskName;
            thisIncome.CategoryDay   = taskInfo.CategoryDay;
            thisIncome.CategoryFixed = taskInfo.CategoryFixed;

            //thisIncome.Title = taskInfo.SaveDesc;
            thisIncome.CreateTime = System.DateTime.Now;
            thisIncome.ReadTime   = taskInfo.Seconds;

            var before = Convert.ToDouble(_Before);

            thisIncome.Beans             = thisIncome.Beans.HasValue ? thisIncome.Beans.Value : 0;
            thisIncome.UpperSecondsBeans = thisIncome.UpperSecondsBeans.HasValue ? thisIncome.UpperSecondsBeans.Value : 0;
            var beans = thisIncome.Beans.Value + thisIncome.UpperSecondsBeans.Value;

            if (beans >= 20000)
            {
                thisIncome.BeansText = $"+{Math.Round(beans / before, 2)}元";
            }
            else
            {
                thisIncome.BeansText = $"+{ beans }金币";
            }

            thisIncome.Proportion = $"{_Before}/{_After}";

            thisIncome.Status    = 0;
            thisIncome.AuditBy   = 1;
            thisIncome.AuditName = "admin";
            thisIncome.AuditTime = System.DateTime.Now;
            if (!thisIncome.IsDisplay.HasValue && beans > 0)
            {
                thisIncome.IsDisplay = 1;
            }
            await _IMemberIncomeRepository.AddAsync(thisIncome);
        }
示例#2
0
        /// <summary>
        /// 签到任务特殊处理
        /// </summary>
        /// <param name="item"></param>
        /// <param name="memberIncomes"></param>
        /// <param name="taskInfo"></param>
        /// <returns></returns>
        private async Task <Tuple <bool, string, int> > SetSign(TaskItem item, TaskInfo taskInfo, List <MemberIncome> memberIncomes)
        {
            var nows    = System.DateTime.Now;
            var flag    = false;
            var message = "";
            // 今日签到数据
            var memberIncome = memberIncomes.FirstOrDefault(a => a.TaskCode == taskInfo.TaskCode);

            if (memberIncome == null)
            {
                // 昨日签到数据
                memberIncome = await _IMemberIncomeRepository.Query(a => a.TaskCode == taskInfo.TaskCode &&
                                                                    a.Status == 0 &&
                                                                    a.MemberId == item.MemberId &&
                                                                    a.CreateTime.Value.ToString("yyyy-MM-dd") == nows.AddDays(-1).ToString("yyyy-MM-dd"))
                               .SingleOrDefaultAsync();
            }

            var weeks = await _ITaskDetailsRepository.Query(a => a.TaskId == taskInfo.TaskId && a.IsEnable == 1)
                        .OrderBy(a => a.Sequence)
                        .ToListAsync();

            var beans  = 0;
            var number = 0;
            var week   = new TaskDetails();

            // 当天收入
            if (memberIncome == null)
            {
                week  = weeks.FirstOrDefault();
                beans = week.Beans.Value;
            }
            // 昨天收入
            else if (memberIncome.CreateTime.Value.ToString("yyyy-MM-dd") == nows.AddDays(-1).ToString("yyyy-MM-dd"))
            {
                number += memberIncome.SignNumber.Value;
                week    = weeks[number];
                beans   = week.Beans.Value;
            }
            if (beans > 0 && number < taskInfo.UpperNumber)
            {
                var thisIncome = new MemberIncome();
                thisIncome.SignNumber = number + 1;
                thisIncome.Beans      = beans = item.AdvanceSing == 1? beans * 2:beans;
                thisIncome.Title      = week.SaveDesc;
                // 添加签到数据
                await SetModal(item, taskInfo, thisIncome);

                flag = true;
            }
            else
            {
                flag    = false;
                message = "签到失败!";
                beans   = 0;
            }
            return(new Tuple <bool, string, int>(flag, message, beans));
        }
示例#3
0
        private async Task <Tuple <bool, string, int> > SetTask(TaskItem item, TaskInfo taskInfo, List <MemberIncome> memberIncomes)
        {
            // 当前任务收入列表
            var          codeIncomes = memberIncomes.Where(a => a.TaskCode == taskInfo.TaskCode).ToList();
            MemberIncome lastIncomes;

            lastIncomes = codeIncomes.LastOrDefault();
            var tempBeans = 0;

            //间隔10秒调用一次
            if (lastIncomes != null && System.DateTime.Now.Subtract(lastIncomes.CreateTime.Value).TotalSeconds < 10)
            {
                return(new Tuple <bool, string, int>(false, $"未到10秒!", 0));
            }
            if (taskInfo.IsDisposable == 1)
            {
                if (await _IMemberIncomeRepository.IsExistAsync(a => a.Status == 0 && a.TaskCode == taskInfo.TaskCode && a.MemberId == item.MemberId))
                {
                    return(new Tuple <bool, string, int>(false, "当前任务只能执行一次!", 0));
                }
            }
            // fromId
            var fromIds = new List <MemberIncome>();

            if (taskInfo.UpperCount.HasValue)
            {
                fromIds = codeIncomes.Where(a => a.FromId == item.FromId).ToList();
            }
            // 0.随机豆子(针对所有获取豆子)
            var randomBeans = 0;

            if (taskInfo.IsRandom == 1)
            {
                // 随机豆子
                randomBeans = new Random().Next(taskInfo.RandomBefore.Value, taskInfo.RandomAfter.Value);
            }
            else if (taskInfo.IsRandom == 2)
            {
                // 固定豆子
                randomBeans = taskInfo.FixedBeans.Value;
            }
            if (randomBeans > 0)
            {
                // 当前任务总收益
                var codeBeans = codeIncomes.Sum(a => a.Beans);

                if (codeBeans + randomBeans > taskInfo.MaxBeans)
                {
                    randomBeans = taskInfo.MaxBeans.Value - codeBeans.Value;
                }
            }

            var secondsBeans    = 0;
            var secondsMaxBeans = 0;
            var upperBeans      = 0;
            var beans           = 0;
            var firstBeans      = 0;
            var memberIncome    = new MemberIncome();

            if (taskInfo.Seconds.HasValue && taskInfo.UpperSeconds.HasValue)
            {
                // 3.秒数 + 最大秒数
                var seconds = 0.0;
                if (lastIncomes != null)
                {
                    seconds = System.DateTime.Now.Subtract(lastIncomes.CreateTime.Value).TotalSeconds;
                }
                else
                {
                    seconds = taskInfo.Seconds.Value;
                }
                if (seconds >= taskInfo.Seconds)
                {
                    secondsBeans = GetSecondsBeans(taskInfo, codeIncomes, fromIds, randomBeans);
                    var secondsTotals = codeIncomes.Sum(a => a.ReadTime.Value);
                    if (secondsBeans > 0)
                    {
                        if (taskInfo.UpperCount.HasValue)
                        {
                            if (fromIds.Count + 1 <= taskInfo.UpperCount)
                            {
                                memberIncome.ReadTime = taskInfo.Seconds;
                                memberIncome.Beans    = secondsBeans;
                                memberIncome.Title    = taskInfo.MaxBeansDesc;
                                if (secondsTotals + taskInfo.Seconds == taskInfo.UpperSeconds)
                                {
                                    secondsMaxBeans = taskInfo.UpperSecondsBeans.Value;
                                    memberIncome.UpperSecondsBeans = secondsMaxBeans;
                                    memberIncome.Title             = taskInfo.UpperSecondsDesc;
                                }
                                await SetModal(item, taskInfo, memberIncome);
                            }
                            else
                            {
                                secondsBeans = 0;
                            }
                        }
                        else
                        {
                            memberIncome.ReadTime = taskInfo.Seconds;
                            memberIncome.Beans    = secondsBeans;
                            memberIncome.Title    = taskInfo.MaxBeansDesc;

                            if (secondsTotals + taskInfo.Seconds == taskInfo.UpperSeconds)
                            {
                                secondsMaxBeans = taskInfo.UpperSecondsBeans.Value;
                                memberIncome.UpperSecondsBeans = secondsMaxBeans;
                                memberIncome.Title             = taskInfo.UpperSecondsDesc;
                            }
                            await SetModal(item, taskInfo, memberIncome);
                        }
                    }
                }
                else
                {
                    return(new Tuple <bool, string, int>(false, $"未到{taskInfo.Seconds}秒!", 0));
                }
            }
            else if (taskInfo.Seconds.HasValue)
            {
                // 4.秒数
                lastIncomes = codeIncomes.LastOrDefault();
                var seconds = 0.0;
                if (lastIncomes != null)
                {
                    seconds = System.DateTime.Now.Subtract(lastIncomes.CreateTime.Value).TotalSeconds;
                }
                else
                {
                    seconds = taskInfo.Seconds.Value;
                }

                if (seconds >= taskInfo.Seconds)
                {
                    secondsBeans = GetSecondsBeans(taskInfo, codeIncomes, fromIds, randomBeans);
                    if (secondsBeans > 0)
                    {
                        if (taskInfo.UpperCount.HasValue)
                        {
                            if (fromIds.Count + 1 <= taskInfo.UpperCount)
                            {
                                memberIncome.Beans = secondsBeans;
                                memberIncome.Title = taskInfo.MaxBeansDesc;

                                await SetModal(item, taskInfo, memberIncome);
                            }
                        }
                        else
                        {
                            memberIncome.Beans = secondsBeans;
                            memberIncome.Title = taskInfo.MaxBeansDesc;

                            await SetModal(item, taskInfo, memberIncome);
                        }
                    }
                }
                else
                {
                    return(new Tuple <bool, string, int>(false, $"未到{taskInfo.Seconds}秒!", 0));
                }
            }
            else if (taskInfo.UpperNumber.HasValue)
            {
                // 5.上限次数奖励
                var upperLogs = _ITaskUpperLogRepository.Query(a => a.MemberId == item.MemberId &&
                                                               a.TaskId == taskInfo.TaskId &&
                                                               a.CreateTime.Value.ToString("yyyy-MM-dd") == System.DateTime.Now.ToString("yyyy-MM-dd"))
                                .ToList();
                if (upperLogs.Count <= 0)
                {
                    if (taskInfo.FirstBeans.HasValue)
                    {
                        firstBeans = taskInfo.FirstBeans.Value;
                    }

                    upperBeans         = firstBeans + randomBeans;
                    memberIncome.Beans = upperBeans;
                    memberIncome.Title = taskInfo.MaxBeansDesc;

                    await _ITaskUpperLogRepository.AddAsync(new TaskUpperLog()
                    {
                        TaskId     = taskInfo.TaskId,
                        MemberId   = item.MemberId,
                        NewsId     = item.FromId,
                        CreateTime = System.DateTime.Now
                    });

                    if (upperBeans != 0 || taskInfo.IsRelatedTasks.HasValue)
                    {
                        await SetModal(item, taskInfo, memberIncome);
                    }
                }
                else
                {
                    var newsIds = upperLogs.GroupBy(a => a.NewsId).Select(a => a.First().NewsId).ToList();

                    if (newsIds.Count(a => a == item.FromId) <= 0 && newsIds.Count + 1 < taskInfo.UpperNumber)
                    {
                        await _ITaskUpperLogRepository.AddAsync(new TaskUpperLog()
                        {
                            TaskId     = taskInfo.TaskId,
                            MemberId   = item.MemberId,
                            NewsId     = item.FromId,
                            CreateTime = System.DateTime.Now
                        });

                        await _ITaskUpperLogRepository.SaveChangesAsync();

                        //判断是否增加子级记录
                        if (taskInfo.IsRelatedTasks.HasValue)
                        {
                            memberIncome.Beans = randomBeans;
                            tempBeans          = randomBeans;
                            memberIncome.Title = taskInfo.MaxBeansDesc;
                            await SetModal(item, taskInfo, memberIncome);
                        }
                    }
                    else if (newsIds.Count(a => a == item.FromId) <= 0 && newsIds.Count + 1 == taskInfo.UpperNumber)
                    {
                        await _ITaskUpperLogRepository.AddAsync(new TaskUpperLog()
                        {
                            TaskId     = taskInfo.TaskId,
                            MemberId   = item.MemberId,
                            NewsId     = item.FromId,
                            CreateTime = System.DateTime.Now
                        });

                        if (taskInfo.UpperBeans.HasValue)
                        {
                            upperBeans = taskInfo.UpperBeans.Value;

                            memberIncome.Beans = upperBeans;
                            memberIncome.Title = taskInfo.UpperBeansDesc;

                            await SetModal(item, taskInfo, memberIncome);
                        }
                    }
                }
            }
            else if (taskInfo.MaxBeans.HasValue)
            {
                // 6.默认最大值处理
                beans = taskInfo.MaxBeans.Value;

                memberIncome.Beans = beans;
                memberIncome.Title = taskInfo.MaxBeansDesc;

                await SetModal(item, taskInfo, memberIncome);
            }
            if (secondsBeans > 0 || secondsMaxBeans > 0 || upperBeans > 0 || beans > 0 || tempBeans > 0)
            {
                // 更新新手任务完成状态,只支持一次性任务
                await UpdateTaskNoviceLog(item, taskInfo);

                var benasTotal = secondsBeans + secondsMaxBeans + upperBeans + beans + tempBeans;
                return(new Tuple <bool, string, int>(true, $"任务奖励为{benasTotal}!", benasTotal));
            }
            else
            {
                return(new Tuple <bool, string, int>(false, "任务奖励为0!", 0));
            }
        }