Beispiel #1
0
        /// <summary>
        /// 审核任务
        /// </summary>
        /// <param name="user"></param>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ResponseMessage> ExaminetaskAsync(UserInfo user, ExamineTaskRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var response = new ResponseMessage();

            if (!user.IsAdmin)
            {
                response.Code    = ResponseCodeDefines.NotAllow;
                response.Message = "不是管理员,没有权限";
                return(response);
            }
            var taskInfo = await _iTaskStore.GetTaskInfos().Where(a => !a.IsDelete && a.Id == request.TaskId).FirstOrDefaultAsync(cancellationToken);

            var periodInfo = await _iTaskStore.GetScorePeriods().Where(w => !w.IsDelete && w.Id == taskInfo.PeriodId).FirstOrDefaultAsync();

            if (periodInfo == null || periodInfo.State != 1)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "只有进行中的赛季才能操作";
                return(response);
            }
            //修改审核状态 时间 审核人 备注
            taskInfo.ExamineState = request.IsOk == true ? 2 : 3;
            taskInfo.ExamineMemo  = request.ExamineMemo;
            taskInfo.ExamineTime  = DateTime.Now;
            taskInfo.ExamineUser  = user.Id;
            var taskPushUserInfo = await _iUserStore.GetUserInfos().Where(w => !w.IsDelete && w.Id == taskInfo.CreateUser).FirstOrDefaultAsync();

            if (taskInfo.LootTime > DateTime.Now)
            {
                #region << 调度中心添加计划任务:刷新任务状态从未开抢(0)到未认领(1) >>
                var task = await _iTaskStore.GetTaskInfos().Where(a => a.IsDelete == false && a.Id == request.TaskId).FirstOrDefaultAsync(cancellationToken);

                var args = new Dictionary <string, string>();
                args.Add(nameof(task.Id), task.Id);
                var schedulerRequest = new ApiCore.Dto.ScheduleSubmitRequest
                {
                    JobGroup    = "KcoinTaskGrab",
                    JobName     = task.Id,
                    CronStr     = "",
                    StarRunTime = task.LootTime,
                    EndRunTime  = null,
                    Callback    = $"{_config["PointGameUrl"]}/api/task/state/refresh/callback",
                    Args        = args,
                };
                string schedulerUrl = $"{_config["ScheduleServerUrl"]}/api/scheduler/start";
                var    re           = await _restClient.Post <ResponseMessage>(schedulerUrl, schedulerRequest);

                if (re.Code != ResponseCodeDefines.SuccessCode)
                {
                    response.Code    = re.Code;
                    response.Message = "调度中心添加计划任务失败:" + re.Message;
                    return(response);
                }
                #endregion
            }
            else
            {
                taskInfo.TaskState = 1;
            }
            var dynamicContent = string.Empty;
            //事务保存
            using (var trans = await _transaction.BeginTransaction())
            {
                try
                {
                    await _iTaskStore.UpdateTaskInfoAsync(taskInfo);

                    // 添加动态
                    dynamicContent = await _dynamicHelper.AddDynamicContent(
                        DynamicType.TaskPublish,
                        taskInfo.PeriodId,
                        taskInfo.Id,
                        "",
                        "",
                        taskPushUserInfo?.UserName,
                        taskPushUserInfo?.GroupName,
                        taskInfo.CreateUser,
                        taskInfo.TaskName,
                        taskInfo.Score,
                        taskInfo.UserNumber,
                        taskInfo.LootTime);

                    trans.Commit();
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    throw new Exception("保存事务失败", e);
                }
            }

            #region 发送新任务提醒
            if (request.IsOk)
            {
                //通过发所有人
                var usersIds = await _iUserStore.GetUserInfos().Where(w => !w.IsDelete && !string.IsNullOrWhiteSpace(w.UserId)).Select(s => s.UserId).ToListAsync();

                if (usersIds.Any())
                {
                    _hellperEmail.SendEmpPush($"《{periodInfo.Caption}》中有新任务发布啦![{taskInfo.TaskState == 0}]",
                                              $"尊敬的勇士您好:{dynamicContent}{taskInfo.LootTime.ToString("yyyy-MM-dd HH:mm:ss")}开抢,赶紧去看看吧。",
                                              usersIds);
                }
            }
            else
            {   //驳回发给发起人
                var usersIds = await _iUserStore.GetUserInfos().Where(w => !w.IsDelete && taskInfo.CreateUser == w.Id && !string.IsNullOrWhiteSpace(w.UserId)).Select(s => s.UserId).ToListAsync();

                if (usersIds.Any())
                {
                    _hellperEmail.SendEmpPush($"您发布的任务《{(taskInfo.TaskName.Length>10? taskInfo.TaskName.Substring(0, 10)+"...":taskInfo.TaskName.Substring(0,10))}》被驳回",
                                              $"尊敬的勇士您好:您发布的任务《{taskInfo.TaskName}》被驳回,因为:{taskInfo.ExamineMemo},赶紧去看看吧。",
                                              usersIds);
                }
            }
            #endregion

            return(response);
        }
Beispiel #2
0
        /// <summary>
        /// 自由交易-发起交易
        /// </summary>
        /// <param name="user"></param>
        /// <param name="dealSubmitRequest"></param>
        /// <param name="requestAborted"></param>
        /// <returns></returns>
        public async Task <ResponseMessage> DealSubmitAsync(UserInfo user, DealSubmitRequest dealSubmitRequest, CancellationToken requestAborted)
        {
            var response   = new ResponseMessage();
            var periodInfo = await _iDealStore.GetScorePeriods().Where(w => !w.IsDelete && w.Id == dealSubmitRequest.PeriodId).FirstOrDefaultAsync();

            if (periodInfo == null || periodInfo.State != 1)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "只有进行中的赛季才能操作";
                return(response);
            }
            var submitUserScoreInfo = await _iDealStore.GetScoreInfos().Where(w => !w.IsDelete && w.PeriodId == dealSubmitRequest.PeriodId && w.UserId == user.Id).FirstOrDefaultAsync();

            var dealUserScoreInfo = await _iDealStore.GetScoreInfos().Where(w => !w.IsDelete && w.PeriodId == dealSubmitRequest.PeriodId && w.UserId == dealSubmitRequest.DealUserId).FirstOrDefaultAsync();

            if (submitUserScoreInfo == null || dealUserScoreInfo == null)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "没有找到对应的积分信息";
                return(response);
            }
            if (submitUserScoreInfo.ConsumableScore < dealSubmitRequest.Score)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "交易K币数不能大于自己的可消费K币数";
                return(response);
            }
            var userInfodGet = await _iDealStore.GetUserInfos().Where(w => w.Id == dealSubmitRequest.DealUserId).FirstOrDefaultAsync();

            if (userInfodGet == null)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "交易对象用户不存在";
                return(response);
            }
            if (userInfodGet.Id == user.Id)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "兄die,还是不要自己跟自己玩了吧,把积分交易给别人吧。";
                return(response);
            }

            var nowTime    = DateTime.Now;
            var dealNumber = Guid.NewGuid().ToString();                  //支出收入两条记录同一个编号

            dealSubmitRequest.Score = Math.Abs(dealSubmitRequest.Score); //防止反向交易
            #region 当前用户的支出信息
            var scoreDetailedOut = new ScoreDetailed
            {
                Id         = Guid.NewGuid().ToString(),
                PeriodId   = dealSubmitRequest.PeriodId,
                DealNumber = dealNumber,
                DealType   = 1,
                UserId     = user.Id,
                DealUserId = dealSubmitRequest.DealUserId,
                Theme      = dealSubmitRequest.Theme,
                Memo       = dealSubmitRequest.Memo,
                Score      = dealSubmitRequest.Score,
                ScoreId    = submitUserScoreInfo.Id,
                CreateTime = nowTime,
                CreateUser = user.Id,
                IsDelete   = false,
            };
            //submitUserScoreInfo.Score = submitUserScoreInfo.Score - dealSubmitRequest.Score;//等级积分减少
            submitUserScoreInfo.ConsumableScore = submitUserScoreInfo.ConsumableScore - dealSubmitRequest.Score;//消费积分减少
            #endregion

            #region 交易对象的收入信息
            var scoreDetailedGet = new ScoreDetailed
            {
                Id         = Guid.NewGuid().ToString(),
                PeriodId   = dealSubmitRequest.PeriodId,
                DealNumber = dealNumber,
                DealType   = 2,
                UserId     = dealSubmitRequest.DealUserId,
                DealUserId = user.Id,
                Theme      = dealSubmitRequest.Theme,
                Memo       = dealSubmitRequest.Memo,
                Score      = dealSubmitRequest.Score,
                ScoreId    = dealUserScoreInfo.Id,
                CreateTime = nowTime,
                CreateUser = user.Id,
                IsDelete   = false,
            };
            //dealUserScoreInfo.Score = dealUserScoreInfo.Score + dealSubmitRequest.Score;//等级积分增加
            dealUserScoreInfo.ConsumableScore = dealUserScoreInfo.ConsumableScore + dealSubmitRequest.Score;//消费积分增加
            #endregion

            var dynamicContent = string.Empty;

            //事务保存
            using (var trans = await _transaction.BeginTransaction())
            {
                try
                {
                    await _iDealStore.CreateScoreDetailedList(new List <ScoreDetailed> {
                        scoreDetailedOut, scoreDetailedGet
                    }, requestAborted);

                    await _iDealStore.UpdateScoreInfoList(new List <ScoreInfo> {
                        submitUserScoreInfo, dealUserScoreInfo
                    }, requestAborted);

                    //添加支出动态
                    await _dynamicHelper.AddDynamicContent(
                        DynamicType.DealExpenditure,
                        dealSubmitRequest.PeriodId,
                        scoreDetailedOut.Id,
                        user.UserName,
                        user.GroupName,
                        userInfodGet.UserName,
                        userInfodGet.GroupName,
                        user.Id,
                        dealSubmitRequest.Theme,
                        dealSubmitRequest.Score,
                        null,
                        null
                        );

                    //添加收入动态
                    dynamicContent = await _dynamicHelper.AddDynamicContent(
                        DynamicType.DealIncome,
                        dealSubmitRequest.PeriodId,
                        scoreDetailedOut.Id,
                        user.UserName,
                        user.GroupName,
                        userInfodGet.UserName,
                        userInfodGet.GroupName,
                        userInfodGet.Id,
                        dealSubmitRequest.Theme,
                        dealSubmitRequest.Score,
                        null,
                        null
                        );

                    trans.Commit();
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    throw new Exception("保存事务失败", e);
                }
            }
            // 触发个人信息,动态变化
            await _sendClientMessageManager.SendInfos(new List <Dto.Common.SendClientType>()
            {
                Dto.Common.SendClientType.Dynamic,
                Dto.Common.SendClientType.User
            });

            #region K币交易发送提醒

            _hellperEmail.SendEmpPush($"您在《{periodInfo.Caption}》收到了K币,快去看看吧!",
                                      $"尊敬的勇士您好:{dynamicContent}赶紧去看看吧。",
                                      new List <string> {
                userInfodGet.UserId
            });

            #endregion

            return(response);
        }
Beispiel #3
0
        /// <summary>
        /// 派发K币-提交
        /// </summary>
        /// <param name="user"></param>
        /// <param name="allocateSubmitRequest"></param>
        /// <param name="requestAborted"></param>
        /// <param name="isEgg">是否彩蛋,默认不是,主要控制邮件发送</param>
        /// <returns></returns>
        public async Task <ResponseMessage> AllocateSubmitAsync(UserInfo user, AllocateSubmitRequest allocateSubmitRequest, CancellationToken requestAborted, bool isEgg = false)
        {
            var response = new ResponseMessage();

            var periodInfo = await _iAllocateStore.GetScorePeriods().Where(w => !w.IsDelete && w.Id == allocateSubmitRequest.PeriodId).FirstOrDefaultAsync();

            if (periodInfo == null || periodInfo.State != 1)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "只有进行中的赛季才能操作";
                return(response);
            }
            var scoreInfo = await _iAllocateStore.GetScoreInfos().Where(w => !w.IsDelete && w.PeriodId == allocateSubmitRequest.PeriodId && w.UserId == allocateSubmitRequest.AllocateUserId).FirstOrDefaultAsync();

            if (scoreInfo == null)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "没有找到派发对象的积分信息";
                return(response);
            }

            var allocateUserInfo = await _iAllocateStore.GetUserInfos().Where(w => w.Id == allocateSubmitRequest.AllocateUserId).FirstOrDefaultAsync();

            if (allocateUserInfo == null)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = "派发对象用户不存在";
                return(response);
            }

            #region 派发对象的收入信息
            var scoreDetailed = new ScoreDetailed
            {
                Id         = Guid.NewGuid().ToString(),
                PeriodId   = allocateSubmitRequest.PeriodId,
                DealType   = 4,
                UserId     = user.Id,//派发人的ID
                DealUserId = allocateSubmitRequest.AllocateUserId,
                Theme      = allocateSubmitRequest.Theme,
                Memo       = allocateSubmitRequest.Memo,
                Score      = allocateSubmitRequest.Score ?? 1,
                ScoreId    = scoreInfo.Id,
                CreateTime = DateTime.Now,
                CreateUser = user.Id,
                IsDelete   = false,
                Labels     = allocateSubmitRequest.Labels
            };
            scoreInfo.Score           = scoreInfo.Score + allocateSubmitRequest.Score ?? 0;
            scoreInfo.ConsumableScore = scoreInfo.ConsumableScore + allocateSubmitRequest.Score ?? 0;
            #endregion

            #region 派发对象的印象标签
            var userLabelList = new List <UserLabel>();
            if (!string.IsNullOrWhiteSpace(allocateSubmitRequest.Labels))
            {
                //标签处理,现在只是去重做存储
                var labelList = allocateSubmitRequest.Labels.Replace(",", ",").Split(",").Where(w => !string.IsNullOrWhiteSpace(w)).Select(s => s.ToLower()).Distinct().ToList();//请求的标签
                if (labelList.Where(w => w.Length > 12).Count() > 0)
                {
                    response.Code    = ResponseCodeDefines.NotAllow;
                    response.Message = "单个标签必须小于6个字";
                    return(response);
                }
                foreach (var lable in labelList)
                {
                    userLabelList.Add(new UserLabel
                    {
                        Id     = Guid.NewGuid().ToString(),
                        UserId = allocateUserInfo.Id,
                        Label  = lable,
                    });
                }
            }
            #endregion
            //事务保存
            using (var trans = await _transaction.BeginTransaction())
            {
                try
                {
                    await _iAllocateStore.CreateScoreDetailed(scoreDetailed, requestAborted);

                    await _iAllocateStore.UpdateScoreInfo(scoreInfo, requestAborted);

                    if (userLabelList != null && userLabelList.Count != 0)
                    {
                        await _iAllocateStore.CreateUserLabelList(userLabelList, requestAborted);
                    }

                    //添加派发动态
                    await _dynamicHelper.AddDynamicContent(
                        DynamicType.DistributeIncome,
                        allocateSubmitRequest.PeriodId,
                        scoreDetailed.Id,
                        null,
                        null,
                        allocateUserInfo.UserName,
                        allocateUserInfo.GroupName,
                        allocateUserInfo.Id,
                        allocateSubmitRequest.Theme,
                        allocateSubmitRequest.Score ?? 1,
                        null,
                        null
                        );

                    trans.Commit();
                }
                catch (Exception e)
                {
                    trans.Rollback();
                    throw new Exception("保存事务失败", e);
                }
            }
            #region 派发积分发送提醒

            if (isEgg)
            {
                //一个彩蛋一个用户只会提醒一次
                var isSend = await _iAllocateStore.GetScoreDetaileds().AnyAsync(w => !w.IsDelete && w.Memo == allocateSubmitRequest.Memo && w.DealUserId == allocateSubmitRequest.AllocateUserId);

                if (isSend)
                {
                    return(response);
                }
            }
            _hellperEmail.SendEmpPush("您收到了新的积分,快去看看吧!",
                                      $"尊敬的勇士您好:您在《{periodInfo.Caption}》因为《{allocateSubmitRequest.Theme}》获得了{allocateSubmitRequest.Score ?? 1}K币,赶紧去看看吧。",
                                      new List <string> {
                allocateUserInfo.UserId
            });

            #endregion

            // 触发排行榜,个人信息,动态变化
            await _sendClientMessageManager.SendInfos(new List <Dto.Common.SendClientType>()
            {
                Dto.Common.SendClientType.Rank,
                Dto.Common.SendClientType.Dynamic,
                Dto.Common.SendClientType.User
            });

            return(response);
        }