예제 #1
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                var vk = VKLogic.GetInstance();
                vk.SendMessage($"QiwiSenderMoney Start<br>Date: {DateTime.Now.ToString()}");
                var date           = DateTime.Now;
                var moneyOutOrders = DataWrapper.GetMoneyOrdersUpToDate(date)
                                     .OrderBy(p => p.OrderDate)
                                     .ToList();
                var qiwi    = new QiwiWallet();
                var balance = qiwi.GetBalance();
                vk.SendMessage($"QiwiSenderMoney Balance: {balance}<br>Amount sum: {moneyOutOrders.Sum(p => p.Amount)} ");

                if (moneyOutOrders != null && moneyOutOrders.Any())
                {
                    foreach (var order in moneyOutOrders)
                    {
                        if ((order.Amount - order.AmountOut > 0) &&
                            (order.Amount - order.AmountOut <= balance))
                        {
                            var amounts = BreakIntoShares(order.Amount - order.AmountOut);

                            foreach (var amount in amounts)
                            {
                                var success = qiwi.SendMoney(order.NumberPurce.Replace("+", ""), amount);
                                if (success)
                                {
                                    order.AmountOut += amount;
                                    var upData = new List <OrderMoneyOut> {
                                        order
                                    };
                                    DataWrapper.UpdateOrderMoneyOutFinished(upData);
                                }
                                //что бы не долбиться без остановки на сервер qiwi
                                Thread.Sleep(50);
                            }
                        }

                        if (order.AmountOut >= order.Amount)
                        {
                            DataWrapper.MarkOrderMoneyOutFinished(order.OrderId);
                        }

                        balance = qiwi.GetBalance();
                    }
                }

                vk.SendMessage($"QiwiSenderMoney End<br>Date: {DateTime.Now.ToString()}<br>Balance: {qiwi.GetBalance()}");
            }
            catch (Exception ex)
            { }
        }
예제 #2
0
        public async Task Execute(IJobExecutionContext context)
        {
            try
            {
                var yesterday      = DateTime.Now.AddDays(-1);
                var moneyOutOrders = DataWrapper.GetMoneyOrdersByDate(yesterday);
                var sumYandex      = moneyOutOrders.Where(p => p.TypePurce == MoneyOutEnum.Yandex).Sum(p => p.Amount);
                var sumQiwi        = moneyOutOrders.Where(p => p.TypePurce == MoneyOutEnum.Qiwi).Sum(p => p.Amount);
                var message        = $"По состоянию на <br>«{ DateTime.Now.ToString("d MMMM yyyy")} г.» нужно пополнить кошельки<br>Qiwi: {sumQiwi} руб.<br>Yandex: {sumYandex} руб.";

                var vk = VKLogic.GetInstance();
                vk.SendMessage(message);
            }
            catch (Exception ex)
            {
            }
        }