public async Task <WrappedResponse <RegisterRewardVm> > Handle(QueryRegisterRewardCommand request, CancellationToken cancellationToken)
        {
            //获取列表

            //获取该玩家的注册时间,从注册的第二天起才能领取注册奖励
            var accountResponse = await _accountClient.
                                  GetResponseExt <GetAccountBaseInfoMqCmd, WrappedResponse <GetAccountBaseInfoMqResponse> >
                                      (new GetAccountBaseInfoMqCmd(request.Id));

            var accountInfo = accountResponse.Message;

            if (accountInfo.ResponseStatus != ResponseStatus.Success)
            {
                return(new WrappedResponse <RegisterRewardVm>(ResponseStatus.Error));
            }
            if ((accountInfo.Body.Flags & GetAccountBaseInfoMqResponse.SomeFlags.RegisterReward) != 0)
            {
                return(new WrappedResponse <RegisterRewardVm>(ResponseStatus.Success,
                                                              null, new RegisterRewardVm(RegisterRewardVm.RewardState.Over, 0, RewardManager.RegisterRewardConf.DayRewards)));
            }
            if (RewardManager.RegisterRewardConf.DayRewards.Count == 0)
            {
                return(new WrappedResponse <RegisterRewardVm>(ResponseStatus.Success,
                                                              null, new RegisterRewardVm(RegisterRewardVm.RewardState.None, 0, null)));
            }
            DateTime registerDate = accountInfo.Body.RegisterDate.DateOfDayBegin();
            DateTime nowDate      = DateTime.Now.DateOfDayBegin();

            if (registerDate == nowDate)
            {
                return(new WrappedResponse <RegisterRewardVm>(ResponseStatus.Success,
                                                              null, new RegisterRewardVm(RegisterRewardVm.RewardState.NotBegin, 0, RewardManager.RegisterRewardConf.DayRewards)));
            }

            int dayIndex   = 0;
            var rewardInfo = await _redis.GetUserRegiserReward(request.Id);

            if (rewardInfo == null)
            {
                rewardInfo = await _registerRepository.GetByIdAsync(request.Id);
            }

            if (rewardInfo == null)
            {
                dayIndex = 0;
            }
            else
            {
                if (rewardInfo.DayIndex >= RewardManager.RegisterRewardConf.DayRewards.Count - 1)
                {
                    if (dayIndex >= RewardManager.RegisterRewardConf.DayRewards.Count - 1)
                    {
                        _ = _mqBus.Publish(new FinishedRegisterRewardMqEvent(request.Id));
                    }
                    return(new WrappedResponse <RegisterRewardVm>(ResponseStatus.Success,
                                                                  null, new RegisterRewardVm(RegisterRewardVm.RewardState.Over, 0, RewardManager.RegisterRewardConf.DayRewards)));
                }
                else if (rewardInfo.GetDate.DateOfDayBegin() == nowDate)
                {
                    return(new WrappedResponse <RegisterRewardVm>(ResponseStatus.Success,
                                                                  null, new RegisterRewardVm(RegisterRewardVm.RewardState.Getted, rewardInfo.DayIndex, RewardManager.RegisterRewardConf.DayRewards)));
                }
                else
                {
                    dayIndex = rewardInfo.DayIndex + 1;
                }
            }
            return(new WrappedResponse <RegisterRewardVm>(ResponseStatus.Success, null,
                                                          new RegisterRewardVm(RegisterRewardVm.RewardState.Available, dayIndex, RewardManager.RegisterRewardConf.DayRewards)));
        }
Пример #2
0
        public async Task <BodyResponse <RegisterRewardVM> > Handle(QueryRegisterRewardCommand request, CancellationToken cancellationToken)
        {
            //获取列表

            //获取该玩家的注册时间,从注册的第二天起才能领取注册奖励
            var accountResponse = await _accountClient.GetResponseExt <GetAccountBaseInfoMqCommand, BodyResponse <GetAccountBaseInfoMqResponse> >
                                      (new GetAccountBaseInfoMqCommand(request.Id));

            var accountInfo = accountResponse.Message;

            if (accountInfo.StatusCode != StatusCodeDefines.Success)
            {
                return(new BodyResponse <RegisterRewardVM>(StatusCodeDefines.Error));
            }
            if ((accountInfo.Body.Flags & GetAccountBaseInfoMqResponse.SomeFlags.RegisterReward) ==
                GetAccountBaseInfoMqResponse.SomeFlags.RegisterReward)
            {
                return(new BodyResponse <RegisterRewardVM>(StatusCodeDefines.Success,
                                                           null, new RegisterRewardVM(RegisterRewardVM.RewardState.Over, 0, _regsterConfig.DayRewards)));
            }
            if (_regsterConfig.DayRewards.Count == 0)
            {
                return(new BodyResponse <RegisterRewardVM>(StatusCodeDefines.Success,
                                                           null, new RegisterRewardVM(RegisterRewardVM.RewardState.None, 0, null)));
            }
            DateTime registerDate = accountInfo.Body.RegisterDate.DateOfDayBegin();
            DateTime nowDate      = DateTime.Now.DateOfDayBegin();

            if (registerDate == nowDate)
            {
                return(new BodyResponse <RegisterRewardVM>(StatusCodeDefines.Success,
                                                           null, new RegisterRewardVM(RegisterRewardVM.RewardState.NotBegin, 0, _regsterConfig.DayRewards)));
            }

            int  dayIndex    = 0;
            long rewardCoins = 0;
            var  rewardInfo  = await _redis.GetUserRegiserReward(request.Id);

            if (rewardInfo == null)
            {
                rewardInfo = await _registerRepository.GetByIdAsync(request.Id);
            }
            if (rewardInfo == null)
            {
                rewardCoins = _regsterConfig.DayRewards[dayIndex];
                dayIndex    = 0;
            }
            else
            {
                if (rewardInfo.DayIndex >= _regsterConfig.DayRewards.Count - 1)
                {
                    if (dayIndex >= _regsterConfig.DayRewards.Count - 1)
                    {
                        _ = _mqBus.Publish(new FinishedRegisterRewardMqEvent(request.Id));
                    }
                    return(new BodyResponse <RegisterRewardVM>(StatusCodeDefines.Success,
                                                               null, new RegisterRewardVM(RegisterRewardVM.RewardState.Over, 0, _regsterConfig.DayRewards)));
                }
                else if (rewardInfo.GetDate.DateOfDayBegin() == nowDate)
                {
                    return(new BodyResponse <RegisterRewardVM>(StatusCodeDefines.Success,
                                                               null, new RegisterRewardVM(RegisterRewardVM.RewardState.Getted, rewardInfo.DayIndex, _regsterConfig.DayRewards)));
                }
                else
                {
                    dayIndex    = rewardInfo.DayIndex + 1;
                    rewardCoins = _regsterConfig.DayRewards[dayIndex];
                }
            }
            return(new BodyResponse <RegisterRewardVM>(StatusCodeDefines.Success, null,
                                                       new RegisterRewardVM(RegisterRewardVM.RewardState.Available, dayIndex, _regsterConfig.DayRewards)));
        }