Beispiel #1
0
        public async Task <Tuple <bool, String, int> > AddTasks(string code, TaskItem item)
        {
            // 任务信息
            var taskInfo = await _ITaskInfoRepository.FirstOrDefaultAsync(a => a.TaskCode == code && a.IsEnable == 1);

            var flag    = false;
            var message = "";

            if (taskInfo != null)
            {
                // 任务时效性处理
                if (taskInfo.IsTimeLimit == 0)
                {
                    flag = true;
                }
                else if (taskInfo.IsTimeLimit == 1)
                {
                    if (DateUtil.In(System.DateTime.Now, taskInfo.BeforeTime.Value, taskInfo.AfterTime.Value, RangeMode.Open))
                    {
                        flag = true;
                    }
                    else
                    {
                        message = "任务已过期!";
                    }
                }
                else
                {
                    message = "未设置有效时间!";
                }
                if (flag)
                {
                    // 会员当天收入
                    var memberIncomes = await _IMemberIncomeRepository.Query(a => a.MemberId == item.MemberId &&
                                                                             a.CreateTime.Value.ToString("yyyy-MM-dd") == System.DateTime.Now.ToString("yyyy-MM-dd") &&
                                                                             a.Status == 0)
                                        .OrderBy(a => a.CreateTime)
                                        .ToListAsync();

                    Tuple <bool, string, int> result;
                    switch (code)
                    {
                    case "T0005":
                        result = await SetSign(item, taskInfo, memberIncomes);

                        break;

                    default:
                        result = await SetTask(item, taskInfo, memberIncomes);

                        break;
                    }
                    var beans = 0;
                    if (result.Item1)
                    {
                        beans += result.Item3;
                        if (!string.IsNullOrEmpty(taskInfo.RelatedTasks))
                        {
                            var relatedTaskCodes = taskInfo.RelatedTasks.Split("∮");
                            // 关联任务列表
                            var relatedTasks = await _ITaskInfoRepository.Query(a => relatedTaskCodes.Contains(a.TaskCode) && a.IsEnable == 1).ToListAsync();

                            foreach (var relateds in relatedTasks)
                            {
                                result = await SetTask(item, relateds, memberIncomes);

                                if (result.Item1)
                                {
                                    beans += result.Item3;
                                }
                            }
                        }
                        await _IMemberInfosRepository.UpdateBeans(item.MemberId.Value, beans);

                        flag = await _IMemberIncomeRepository.SaveChangesAsync() > 0;
                    }
                    else
                    {
                        flag    = false;
                        message = result.Item2;
                    }
                    if (flag)
                    {
                        return(new Tuple <bool, string, int>(flag, $"任务奖励为{beans}", beans));
                    }
                    else
                    {
                        return(new Tuple <bool, string, int>(flag, string.IsNullOrEmpty(result.Item2) ? "添加任务奖励失败!" : result.Item2, 0));
                    }
                }
            }
            return(new Tuple <bool, string, int>(false, message, 0));
        }
Beispiel #2
0
        public async Task <IActionResult> GetTaskDayAsync([FromHeader] String source,
                                                          [FromQuery] MemberIdGet item)
        {
            var response = new Response <Object>();
            var taskCode = "T0005";

            try {
                var taskInfo = await _ITaskInfoRepository.FirstOrDefaultAsync(a => a.TaskCode == taskCode && a.IsEnable == 1);

                if (taskInfo == null)
                {
                    return(NotFound());
                }
                var weeks = await _ITaskDetailsRepository.Query(a => a.TaskId == taskInfo.TaskId && a.IsEnable == 1)
                            .OrderBy(a => a.Sequence)
                            .ToListAsync();

                if (weeks.Count <= 0)
                {
                    return(NoContent());
                }
                // 当前日期
                var nows = System.DateTime.Now;
                // 签到天数
                var signNumber = 0;
                // 今日签到数据
                var memberIncome = await _IMemberIncomeRepository.Query(a => a.TaskCode == taskCode &&
                                                                        a.Status == 0 &&
                                                                        a.MemberId == item.MemberId &&
                                                                        a.CreateTime.Value.ToString("yyyy-MM-dd") == nows.ToString("yyyy-MM-dd"))
                                   .SingleOrDefaultAsync();

                if (memberIncome == null)
                {
                    // 昨日签到数据
                    memberIncome = await _IMemberIncomeRepository.Query(a => a.TaskCode == taskCode &&
                                                                        a.Status == 0 &&
                                                                        a.MemberId == item.MemberId &&
                                                                        a.CreateTime.Value.ToString("yyyy-MM-dd") == nows.AddDays(-1).ToString("yyyy-MM-dd"))
                                   .SingleOrDefaultAsync();
                }
                var todaySignin = false;
                if (memberIncome != null)
                {
                    signNumber  = memberIncome.SignNumber.Value;
                    todaySignin = memberIncome.CreateTime.Value.ToString("yyyy-MM-dd") == nows.ToString("yyyy-MM-dd");
                }
                DateTime beforeTime;
                //第一天签到或者签到7天
                if (signNumber >= 7 || (signNumber == 1 && todaySignin))
                {
                    beforeTime = System.DateTime.Now;
                }
                else if (!todaySignin)   //今天未签
                {
                    beforeTime = System.DateTime.Now.AddDays(-signNumber);
                }
                else //今天已签
                {
                    beforeTime = System.DateTime.Now.AddDays(-signNumber + 1);
                }
                var result = new List <Object>();
                for (var i = 0; i < weeks.Count; i++)
                {
                    var time = beforeTime.AddDays(i);
                    result.Add(new {
                        CreateTime = time.ToString("yyyy-MM-dd"),
                        IsSignin   = i < signNumber,
                        Beans      = weeks[i].Beans
                    });
                }
                response.Code = true;
                response.Data = new {
                    TodaySignin = todaySignin,
                    Weeks       = result
                };
            }
            catch (Exception ex) {
                response.SetError(ex, this._ILogger);
            }
            return(response.ToHttpResponse());
        }