private async Task HandleToteFinish(ToteFinishedMessage msg) { var tote = await _getTote.GetAsync(msg.ToteId); if (tote.State != ToteState.Started && tote.State != ToteState.Closed) { MessengerActor.Send(new MessageToChannel(msg.UserId, "Чот не получается завершить тотализатор. А ты случаем не жулик?")); return; } await _finishTote.FinishAsync(tote.Id); var rewards = _rewardsLogic.CalcRewards(tote, msg.OptionId); foreach (var reward in rewards.ProportionalReward) { LedgerActor.Address.Tell(new ValidatedTransferMessage(tote.AccountId(), reward.Account.UserId, reward.Amount, tote.Currency, $"Поздравляем! Тотализатор \"{tote.Description}\" завершён, вот законный выигрыш!", false, $"(Тотализатор *{tote.Description}*)")); } LedgerActor.Address.Tell(new ValidatedTransferAllFundsMessage(tote.AccountId(), tote.Owner, tote.Currency, "Ваше вознаграждение за проведённый тотализатор!", $"(Тотализатор *{tote.Description}*)")); MessengerActor.Address.Tell(new UpdateToteReportsMessage(tote.Id)); MessengerActor.Address.Tell(new ToteWinnersLoosersReportMessage(rewards, tote)); }
public void TestSimpleRewards() { var q = new FinishToteAmountsLogicQuery(); var t = new Tote { Owner = "owner", Options = new[] { new ToteOption { Id = "o1", Bets = new[] { new ToteBet { Amount = 100, User = "******" }, new ToteBet { Amount = 200, User = "******" } } }, new ToteOption { Id = "o2", Bets = new[] { new ToteBet { Amount = 300, User = "******" }, new ToteBet { Amount = 300, User = "******" } } } } }; var r = q.CalcRewards(t, "o1"); decimal total = 900; decimal percent = total / 20m; decimal onethird = ((900 - percent) / 3).Trim(); decimal twothird = (2 * ((900 - percent) / 3)).Trim(); decimal remainder = total - percent - onethird - twothird; Assert.AreEqual(r.OwnerPercent, remainder + percent); Assert.AreEqual(onethird, r.ProportionalReward[0].Amount); Assert.AreEqual(twothird, r.ProportionalReward[1].Amount); Assert.AreEqual("1", r.ProportionalReward[0].Account.UserId); Assert.AreEqual("2", r.ProportionalReward[1].Account.UserId); }