public async Task AddPlatformFriend(string platformAccount, int type, FriendInfo friendInfo) { //查询该玩家是否是注册玩家 var response = await _mqGetIdCleint.GetResponseExt <GetIdByPlatformMqCommand, BodyResponse <GetIdByPlatformMqResponse> > (new GetIdByPlatformMqCommand(platformAccount, type)); if (response.Message.StatusCode != StatusCodeDefines.Success) { return; } long friendId = response.Message.Body.Id; if (friendInfo._friends == null || !friendInfo._friends.TryGetValue(friendId, out var info)) { using (var locker = _redis.Locker(KeyGenHelper.GenUserKey(friendId, "FriendInfo"))) { await AddFriend(friendInfo.Id, friendId, FriendTypes.PlatformFriend); return; } } if (info.Type != FriendTypes.PlatformFriend) { using (var locker = _redis.Locker(KeyGenHelper.GenUserKey(friendId, "FriendInfo"))) { await _redis.DeleteFriend(friendInfo.Id, friendId); await Task.WhenAll(_redis.AddFriend(friendInfo.Id, friendId, FriendTypes.PlatformFriend), _friendRepository.UpdateFriend(friendInfo.Id, friendId, FriendTypes.PlatformFriend)); } } }
private async Task <AccountDetail> GetAccountDetail(long id) { var tAccount = _redis.GetAccountInfo(id); var tMoney = _moneyClient.GetResponseExt <GetMoneyMqCommand, BodyResponse <MoneyMqResponse> > (new GetMoneyMqCommand(id)); var tLevel = _bus.SendCommand(new GetLevelInfoCommand(id)); var tGame = _bus.SendCommand(new GetGameInfoCommand(id)); await Task.WhenAll(tAccount, tMoney, tLevel, tGame); var accountInfo = tAccount.Result; var moneyInfores = tMoney.Result; var moneyInfo = new MoneyInfo(moneyInfores.Message.Body.CurCoins + moneyInfores.Message.Body.Carry, moneyInfores.Message.Body.CurDiamonds, moneyInfores.Message.Body.MaxCoins, moneyInfores.Message.Body.MaxDiamonds); var levelInfo = tLevel.Result.Body; var gameInfo = tGame.Result.Body; if (accountInfo == null || moneyInfo == null || levelInfo == null || gameInfo == null) { return(null); } return(new AccountDetail(accountInfo.Id, accountInfo.PlatformAccount, accountInfo.UserName, accountInfo.Sex, accountInfo.HeadUrl, accountInfo.Type, levelInfo, gameInfo, moneyInfo)); }
private async Task <AccountDetailVm> GetAccountDetail(long id) { var accountInfo = await AccountRepositoryHelper.GetAccountInfo(id, _accountRep, _redisRep); if (accountInfo == null) { return(null); } var tMoney = _moneyClient.GetResponseExt <GetMoneyMqCmd, WrappedResponse <MoneyMqResponse> > (new GetMoneyMqCmd(id)); var tLevel = _bus.SendCommand(new GetLevelInfoCommand(id)); var tGame = _bus.SendCommand(new GetGameInfoCommand(id)); await Task.WhenAll(tMoney, tLevel, tGame); var moneyResponse = tMoney.Result; var moneyInfo = new MoneyInfoVm(moneyResponse.Message.Body.CurCoins + moneyResponse.Message.Body.Carry, moneyResponse.Message.Body.CurDiamonds, moneyResponse.Message.Body.MaxCoins, moneyResponse.Message.Body.MaxDiamonds); var levelInfo = _mapper.Map <LevelInfoVm>(tLevel.Result.Body); var gameInfo = _mapper.Map <GameInfoVm>(tGame.Result.Body); if (accountInfo == null || moneyInfo == null || levelInfo == null || gameInfo == null) { return(null); } return(new AccountDetailVm(accountInfo.PlatformAccount, accountInfo.UserName, accountInfo.Sex, accountInfo.HeadUrl, accountInfo.Type, levelInfo, gameInfo, moneyInfo)); }
public async Task <BodyResponse <FriendVM> > Handle(GetFriendsCommand request, CancellationToken cancellationToken) { var info = await _redis.GetFriendInfo(request.Id); if (info == null) { info = await _friendRepository.GetByIdAsync(request.Id); using (var locker = _redis.Locker(KeyGenHelper.GenUserKey(request.Id, "FriendInfo"))) { await _redis.SetFriendInfo(info); } } if (info == null) { return(new BodyResponse <FriendVM>(StatusCodeDefines.Success)); } List <Task <Response <BodyResponse <GetAccountBaseInfoMqResponse> > > > getTasks = new List <Task <Response <BodyResponse <GetAccountBaseInfoMqResponse> > > >(); foreach (var oneFriend in info._friends) { //获取好友信息 getTasks.Add(_mqCleint.GetResponseExt <GetAccountBaseInfoMqCommand, BodyResponse <GetAccountBaseInfoMqResponse> > (new GetAccountBaseInfoMqCommand(oneFriend.Key))); } var allTask = await Task.WhenAll(getTasks); FriendVM friendInfos = new FriendVM() { Friends = new List <OneFriendVM>() }; foreach (var one in allTask) { var response = one.Message; if (response.StatusCode == StatusCodeDefines.Success) { var friendType = info._friends[response.Body.Id].Type; friendInfos.Friends.Add(new OneFriendVM(response.Body.Id, response.Body.PlatformAccount, response.Body.UserName, response.Body.Sex, response.Body.HeadUrl, response.Body.Type, friendType)); } } return(new BodyResponse <FriendVM>(StatusCodeDefines.Success, null, friendInfos)); }
public async Task <BodyResponse <DummyMatchingResponseInfo> > Handle(DummyPlaynowCommand request, CancellationToken cancellationToken) { //获取玩家金币 //根据金币判断玩家的场次 var moneyResponse = await _moneyClient.GetResponseExt <GetMoneyMqCommand, BodyResponse <MoneyMqResponse> >(new GetMoneyMqCommand(request.Id)); if (moneyResponse.Message.StatusCode != StatusCodeDefines.Success) { return(new BodyResponse <DummyMatchingResponseInfo>(moneyResponse.Message.StatusCode, null)); } long curCoins = moneyResponse.Message.Body.CurCoins; if (!_matchingManager.GetBlindFromCoins(curCoins, out var blind)) { return(new BodyResponse <DummyMatchingResponseInfo>(StatusCodeDefines.NoEnoughMoney, null, null)); } var response = await _matchingManager.MatchingRoom(request.Id, blind, ""); //BodyResponse<DummyMatchingResponseInfo> response = new BodyResponse<DummyMatchingResponseInfo>(StatusCodeDefines.LoginError, null, null); return(response); }
public async Task <WrappedResponse <RoomMatchResponseVm> > Handle(PlaynowCommand request, CancellationToken cancellationToken) { //获取玩家金币 //根据金币判断玩家的场次 var moneyResponse = await _moneyClient.GetResponseExt <GetMoneyMqCmd, WrappedResponse <MoneyMqResponse> >(new GetMoneyMqCmd(request.Id)); if (moneyResponse.Message.ResponseStatus != ResponseStatus.Success) { return(new WrappedResponse <RoomMatchResponseVm>(moneyResponse.Message.ResponseStatus, null)); } long curCoins = moneyResponse.Message.Body.CurCoins; if (!MatchManager.GetBlindFromCoins(curCoins, out var blind)) { return(new WrappedResponse <RoomMatchResponseVm> (ResponseStatus.NoEnoughMoney, null, null)); } var response = await MatchManager.MatchRoom(request.Id, blind, ""); //BodyResponse<SangongMatchingResponseInfo> response = new BodyResponse<SangongMatchingResponseInfo>(StatusCodeDefines.LoginError, null, null); return(response); }
public async Task <MoneyMqResponse> GetMoneyInfo(long id) { try { var response = await _moneyClient.GetResponseExt <GetMoneyMqCmd, WrappedResponse <MoneyMqResponse> >(new GetMoneyMqCmd(id)); return(response.Message.Body); } catch (Exception ex) { Log.Error($"user {id} GetMoneyInfo failed: {ex}"); return(null); } }
public async Task <GetAccountInfoMqResponse> GetAccountInfo(long id) { try { var response = await _accountClient.GetResponseExt <GetAccountInfoMqCommand, BodyResponse <GetAccountInfoMqResponse> >(new GetAccountInfoMqCommand(id)); return(response.Message.Body); } catch (Exception ex) { Log.Error($"user {id} GetMoneyInfo failed: {ex}"); return(null); } }
public async Task <WrappedResponse <NullBody> > UserApplySit(long id, string roomId, string gameKey, long blind) { try { var response = await _sitClient.GetResponseExt <UserApplySitMqCmd, WrappedResponse <NullBody> >( new UserApplySitMqCmd(id, roomId, gameKey, blind)); return(response.Message); } catch (Exception) { return(null); } }
public async Task <MoneyMqResponse> BuyIn(long id, long min, long max) { try { var response = await _buyInClient.GetResponseExt <BuyInMqCmd, WrappedResponse <MoneyMqResponse> >( new BuyInMqCmd(id, min, max, AddReason.BuyIn)); return(response.Message.Body); } catch (Exception ex) { Log.Error($"user {id} BuyIn failed: {ex}"); return(null); } }
public async Task <WrappedResponse <BankruptcyInfoVm> > Handle(QueryBankruptcyCommand request, CancellationToken cancellationToken) { //查询当天redis记录 DateTime tnow = DateTime.Now; var bankruptcyInfo = await _rewardRedis.GetBankruptcyInfo(tnow, request.Id); int totalTimes = RewardManager.BankruptcyConf.BankruptcyRewards.Count; int curTimes; if (bankruptcyInfo == null) { curTimes = 0; } else { curTimes = bankruptcyInfo.CurTimes; } var getMoneyResponse = await _getMoneyClient. GetResponseExt <GetMoneyMqCmd, WrappedResponse <MoneyMqResponse> > (new GetMoneyMqCmd(request.Id)); var moneyInfo = getMoneyResponse.Message; bool isAvailable = false; if (moneyInfo.ResponseStatus == ResponseStatus.Success) { if (moneyInfo.Body.CurCoins < RewardManager.BankruptcyConf.BankruptcyLimit) { isAvailable = true; } } return(new WrappedResponse <BankruptcyInfoVm>(ResponseStatus.Success, null, new BankruptcyInfoVm(BankruptcyInfoVm.BankruptcyRewardType.Day, totalTimes, curTimes, RewardManager.BankruptcyConf.BankruptcyRewards, isAvailable))); }
public async Task <BodyResponse <OtherAccountDetail> > Handle(GetOtherAccountCommand request, CancellationToken cancellationToken) { var accountInfo = await GetAccountDetail(request.OtherId); if (accountInfo == null) { return(new BodyResponse <OtherAccountDetail>(StatusCodeDefines.AccountError, null)); } var otherinfo = _mapper.Map <OtherAccountDetail>(accountInfo); var response = await _friednClient.GetResponseExt <GetFriendInfoMqCommand, BodyResponse <GetFriendInfoMqResponse> >( new GetFriendInfoMqCommand(request.Id, request.OtherId)); if (response.Message.Body != null) { otherinfo.FriendType = response.Message.Body.FriendType; } return(new BodyResponse <OtherAccountDetail>(StatusCodeDefines.Success, null, otherinfo)); }
public async void AddMoney() { IRequestClient <AddMoneyMqCommand> client = _mqBus.CreateRequestClient <AddMoneyMqCommand> (new Uri("rabbitmq://localhost/SkyWatch/Money")); IRequestClient <GetMoneyMqCommand> getClient = _mqBus.CreateRequestClient <GetMoneyMqCommand> (new Uri("rabbitmq://localhost/SkyWatch/Money")); var getResponse = getClient.GetResponseExt <GetMoneyMqCommand, BodyResponse <MoneyMqResponse> >(new GetMoneyMqCommand(10000000002)); getResponse.Wait(); _testOutputHelper.WriteLine($"GetMoney:{getResponse.Result.Message.Body.CurCoins} --02"); await client.GetResponseExt <AddMoneyMqCommand, BodyResponse <MoneyMqResponse> >(new AddMoneyMqCommand(10000000002, 10000000, 0, 0)); Assert.Equal(StatusCodeDefines.Success, getResponse.Result.Message.StatusCode); /*for (int i = 0; i < 36000000; ++i) * { * await client.GetResponseExt<AddMoneyMqCommand, BodyResponse<MoneyMqResponse>>(new AddMoneyMqCommand(10000000002, 10000, 10000)); * await client.GetResponseExt<AddMoneyMqCommand, BodyResponse<MoneyMqResponse>>(new AddMoneyMqCommand(10000000002, -10000, -10000)); * _testOutputHelper.WriteLine($"GetMoney....."); * Thread.Sleep(1); * //var response1 = _mqBus.Publish(new AddMoneyMqCommand(10000000002, 10000, 10000)); * //var response2 = _mqBus.Publish(new AddMoneyMqCommand(10000000002, -10000, -10000)); * * /*Assert.Equal(StatusCodeDefines.Success, moneyRes.Message.StatusCode); * Assert.Equal(moneyResponse.Body.CurCoins + 10000, response.Result.Message.Body.CurCoins); * Assert.Equal(moneyResponse.Body.Carry + 10000, response.Result.Message.Body.Carry); * * Assert.Equal(StatusCodeDefines.Success, moneyRes.Message.StatusCode); * Assert.Equal(moneyResponse.Body.CurCoins, moneyRes.Message.Body.CurCoins); * Assert.Equal(moneyResponse.Body.Carry, moneyRes.Message.Body.Carry); * }*/ /*var getResponse2 = getClient.GetResponseExt<GetMoneyMqCommand, BodyResponse<MoneyMqResponse>>(new GetMoneyMqCommand(10000000002)); * await getResponse2; * _testOutputHelper.WriteLine($"GetMoney:{getResponse2.Result.Message.Body.CurCoins} --03"); * Assert.Equal(StatusCodeDefines.Success, getResponse2.Result.Message.StatusCode); * Assert.Equal(80000, getResponse2.Result.Message.Body.CurCoins); * Assert.Equal(80000, getResponse2.Result.Message.Body.Carry); * Assert.Equal(getResponse.Result.Message.Body.CurCoins, getResponse2.Result.Message.Body.CurCoins); * Assert.Equal(getResponse.Result.Message.Body.Carry, getResponse2.Result.Message.Body.Carry);*/ }
public void BuyIn() { IRequestClient <BuyInMqCommand> client = _mqBus.CreateRequestClient <BuyInMqCommand> (new Uri("rabbitmq://localhost/SkyWatch/Money")); IRequestClient <GetMoneyMqCommand> getClient = _mqBus.CreateRequestClient <GetMoneyMqCommand> (new Uri("rabbitmq://localhost/SkyWatch/Money")); var getResponse = getClient.GetResponseExt <GetMoneyMqCommand, BodyResponse <MoneyMqResponse> >(new GetMoneyMqCommand(10000000002)); getResponse.Wait(); Assert.Equal(StatusCodeDefines.Success, getResponse.Result.Message.StatusCode); var moneyResponse = getResponse.Result.Message; var response = client.GetResponseExt <BuyInMqCommand, BodyResponse <MoneyMqResponse> >(new BuyInMqCommand(10000000002, 1000, 10000, 0)); response.Wait(); var moneyRes = response.Result; Assert.Equal(StatusCodeDefines.Success, moneyRes.Message.StatusCode); Assert.True(10000 <= response.Result.Message.Body.Carry); }
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))); }
public async Task <WrappedResponse <AccountResponse> > Handle(LoginCommand request, CancellationToken cancellationToken) { var newAccountInfo = request.Info; //判断该平台ID是否已经注册, 先从redis查找 var loginCheckInfo = await _redisRep.GetLoginCheckInfo(newAccountInfo.PlatformAccount); bool isRegister = false; AccountInfo accountInfo; if (loginCheckInfo != null) { //直接通过ID去查找这个玩家信息 accountInfo = await _redisRep.GetAccountInfo(loginCheckInfo.Id); //为空从数据库读取 if (accountInfo == null) { accountInfo = await _accountRep.GetByIdAsync(loginCheckInfo.Id); } } else { //查找数据库中是否有这个账号 accountInfo = await _accountRep.GetByPlatform(newAccountInfo.PlatformAccount); if (accountInfo == null) { //注册新账号 isRegister = true; long newUid = await _genRepository.GenNewId(); accountInfo = new AccountInfo(newUid, newAccountInfo.PlatformAccount, newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl, newAccountInfo.Type, DateTime.Now); await _accountRep.AddAsync(accountInfo); } } if (accountInfo != null) { newAccountInfo.Id = accountInfo.Id; string token = TokenTool.GenToken(accountInfo.Id); AccountResponse accounResponse; bool isNeedUpdate = false; if (!isRegister && accountInfo.IsNeedUpdate(newAccountInfo)) { isNeedUpdate = true; } if (isRegister) { var mqResponse = await _moneyAddClient.GetResponseExt <AddMoneyMqCmd, WrappedResponse <MoneyMqResponse> > (new AddMoneyMqCmd(accountInfo.Id, InitRewardInfo.RewardCoins, 0, AddReason.InitReward)); var moneyInfo = mqResponse.Message.Body; accounResponse = new AccountResponse(newAccountInfo.Id, newAccountInfo.PlatformAccount, newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl, token, new MoneyInfo(moneyInfo.CurCoins + moneyInfo.Carry, moneyInfo.CurDiamonds, moneyInfo.MaxCoins, moneyInfo.MaxDiamonds), WSHostManager.GetOneHost(), true, newAccountInfo.Type); } else { var mqResponse = await _moneyClient.GetResponseExt <GetMoneyMqCmd, WrappedResponse <MoneyMqResponse> > (new GetMoneyMqCmd(accountInfo.Id)); var moneyInfo = mqResponse.Message.Body; accounResponse = new AccountResponse(newAccountInfo.Id, newAccountInfo.PlatformAccount, newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl, token, new MoneyInfo(moneyInfo.CurCoins + moneyInfo.Carry, moneyInfo.CurDiamonds, moneyInfo.MaxCoins, moneyInfo.MaxDiamonds), WSHostManager.GetOneHost(), false, newAccountInfo.Type); } _ = _bus.RaiseEvent <LoginEvent>(new LoginEvent(Guid.NewGuid(), accounResponse, isRegister, isNeedUpdate, newAccountInfo)); WrappedResponse <AccountResponse> retRresponse = new WrappedResponse <AccountResponse>(ResponseStatus.Success, null, accounResponse); return(retRresponse); } WrappedResponse <AccountResponse> response = new WrappedResponse <AccountResponse>(ResponseStatus.LoginError, null, null); return(response); }
public async Task <BodyResponse <AccountResponse> > Handle(LoginCommand request, CancellationToken cancellationToken) { var newAccountInfo = request.Info; //根据PlatformAccount字段读取redis,判断该账号是否已经注册 var loginCheckInfo = await _redis.GetLoginCheckInfo(request.Info.PlatformAccount); AccountInfo accountInfo = null; bool isRegister = false; if (loginCheckInfo != null) { //直接通过ID去查找这个玩家信息 accountInfo = await _redis.GetAccountInfo(loginCheckInfo.Id); if (accountInfo == null) { accountInfo = await _accountRepository.GetByIdAsync(loginCheckInfo.Id); } } else { //查找数据库中是否有这个账号 accountInfo = await _accountRepository.GetByPlatform(newAccountInfo.PlatformAccount); if (accountInfo == null) { //注册新账号 isRegister = true; long newUid = await _genRepository.GenNewId(); accountInfo = new AccountInfo(newUid, newAccountInfo.PlatformAccount, newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl, newAccountInfo.Type, DateTime.Now, GetAccountBaseInfoMqResponse.SomeFlags.None); await _accountRepository.AddAsync(accountInfo); } } if (accountInfo != null) { newAccountInfo.Id = accountInfo.Id; string token = TokenHelper.GenToken(accountInfo.Id); AccountResponse accounResponse = null; bool isNeedUpdate = false; //如果登录信息有更新, 那么更新数据库 if (!isRegister && accountInfo != newAccountInfo) { isNeedUpdate = true; } if (isRegister) { var mqResponse = await _moneyAddClient.GetResponseExt <AddMoneyMqCommand, BodyResponse <MoneyMqResponse> > (new AddMoneyMqCommand(accountInfo.Id, _initRewardInfo.RewardCoins, 0, AddReason.InitReward)); var moneyInfo = mqResponse.Message.Body; accounResponse = new AccountResponse(newAccountInfo.Id, newAccountInfo.PlatformAccount, newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl, token, new MoneyInfo(moneyInfo.CurCoins + moneyInfo.Carry, moneyInfo.CurDiamonds, moneyInfo.MaxCoins, moneyInfo.MaxDiamonds), _hostManager.GetOneHost(), true, newAccountInfo.Type); } else { //查询玩家金币 MoneyMqResponse moneyResponse = null; var mqResponse = await _moneyClient.GetResponseExt <GetMoneyMqCommand, BodyResponse <MoneyMqResponse> > (new GetMoneyMqCommand(accountInfo.Id)); moneyResponse = mqResponse.Message.Body; accounResponse = new AccountResponse(newAccountInfo.Id, newAccountInfo.PlatformAccount, newAccountInfo.UserName, newAccountInfo.Sex, newAccountInfo.HeadUrl, token, new MoneyInfo(moneyResponse.CurCoins + moneyResponse.Carry, moneyResponse.CurDiamonds, moneyResponse.MaxCoins, moneyResponse.MaxDiamonds), _hostManager.GetOneHost(), false, newAccountInfo.Type); } _ = _bus.RaiseEvent <LoginEvent>(new LoginEvent(Guid.NewGuid(), accounResponse, isRegister, isNeedUpdate, newAccountInfo)); BodyResponse <AccountResponse> retRresponse = new BodyResponse <AccountResponse>(StatusCodeDefines.Success, null, accounResponse); return(retRresponse); } BodyResponse <AccountResponse> response = new BodyResponse <AccountResponse>(StatusCodeDefines.LoginError, null, null); return(response); }
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))); }