Пример #1
0
        public async Task <IActionResult> GetTaskNovicesAsync([FromHeader] String source,
                                                              [FromQuery] MemberIdGet item)
        {
            var response = new Response <Object>();

            try {
                if (await _ITaskNoviceLogRepository.IsExistAsync(a => a.MemberId == item.MemberId && a.IsEnable == 1))
                {
                    var noviceLogIds = await _ITaskNoviceLogRepository.Query(a => a.MemberId == item.MemberId && a.CategoryDay == 1 && a.IsEnable == 1)
                                       .Select(a => a.TaskId)
                                       .ToListAsync();

                    var tasks = await _ITaskInfoRepository.Query(a => noviceLogIds.Contains(a.TaskId) &&
                                                                 a.IsDisplay == 1 &&
                                                                 a.IsEnable == 1)
                                .OrderBy(a => a.Sequence)
                                .Select(a => new TaskInfoDto {
                        TaskId        = a.TaskId,
                        TaskName      = a.TaskName,
                        TaskCode      = a.TaskCode,
                        ShowDesc      = a.ShowDesc,
                        BeansText     = a.BeansText,
                        Tips          = a.Tips,
                        CategoryDay   = a.CategoryDay,
                        IconType      = a.IconType,
                        JumpType      = a.JumpType,
                        JumpTitle     = a.JumpTitle,
                        JumpUrl       = a.JumpUrl,
                        AlreadyNumber = a.UpperNumber.HasValue ? a.MemberIncomes.Count(b => b.TaskCode == a.TaskCode && b.MemberId == item.MemberId) : (a.UpperSeconds.HasValue ? a.MemberIncomes.Sum(b => b.ReadTime) / 60 : 0),
                        UpperNumber   = a.UpperNumber.HasValue ? a.UpperNumber : (a.UpperSeconds.HasValue ? a.UpperSeconds / 60 : 0),
                        UpperBeans    = a.UpperBeans.HasValue ? a.UpperBeans : (a.UpperSeconds.HasValue ? a.UpperSecondsBeans : 0)
                    })
                                .ToListAsync();

                    response.Code = true;
                    response.Data = tasks;
                }
                else
                {
                    return(NoContent());
                }
            }
            catch (Exception ex) {
                response.SetError(ex, this._ILogger);
            }
            return(response.ToHttpResponse());
        }
Пример #2
0
        public async Task <IActionResult> PostUserRegisterAsync([FromHeader] String source,
                                                                [FromHeader] String authorization,
                                                                [FromBody] RegisterPost item)
        {
            var response = new Response <JwtAuthorData>();
            var message  = string.Empty;

            try {
                var entity = await _IMemberInfosRepository.FirstOrDefaultAsync(a => a.Uid == item.uid && a.OpenId == item.openid && a.IsEnable == 1);

                if (entity == null)
                {
                    entity             = new MemberInfos();
                    entity.Code        = SnowFlake.GetInstance().GetUniqueShortId(8);
                    entity.NickName    = item.name;
                    entity.Name        = item.name;
                    entity.Sex         = item.gender == "男" ? 1 : 0;
                    entity.Avatar      = item.iconurl;
                    entity.Uid         = item.uid;
                    entity.OpenId      = item.openid;
                    entity.Phone       = item.phone;
                    entity.Password    = Tools.Md5("000000");
                    entity.Beans       = 0;
                    entity.BeansTotals = 0;

                    entity.NewsNumber      = 0;
                    entity.FollowNumber    = 0;
                    entity.FavoritesNumber = 0;
                    entity.FansNumber      = 0;

                    entity.IsNoviceTask  = 0;
                    entity.IsEnable      = 1;
                    entity.LastLoginTime = System.DateTime.Now;
                    entity.CreateTime    = System.DateTime.Now;
                    entity.Remarks       = "微信首次登录注册。";

                    await _IMemberInfosRepository.AddAsync(entity);

                    await _IMemberInfosRepository.SaveChangesAsync();

                    message = "初始登录密码为【000000】";

                    var taskNoviceLogs = await _ITaskInfoRepository.Query(a => a.IsNoviceTask == 1 && a.IsEnable == 1)
                                         .Select(a => new TaskNoviceLog()
                    {
                        TaskId        = a.TaskId,
                        CategoryFixed = a.CategoryFixed,
                        CategoryDay   = a.CategoryDay,
                        MemberId      = entity.MemberId,
                        IsEnable      = 1
                    })
                                         .ToListAsync();

                    await _ITaskNoviceLogRepository.BatchAddAsync(taskNoviceLogs);
                }
                else
                {
                    message = "已注册,初始登录密码为【000000】";
                }
                var result = _IJwtRedis.Create(entity);
                if (result != null)
                {
                    //await _IJwtRedis.DeactivateAsync(authorization);
                    response.Code    = true;
                    response.Message = message;
                    response.Data    = result;
                }
                else
                {
                    return(BadRequest("授权失败!"));
                }
            }
            catch (Exception ex) {
                response.SetError(ex, this._ILogger);
            }
            return(response.ToHttpResponse());
        }
Пример #3
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));
        }