bool FindInBlackList(string x) { RootLog($"{Tid} [FCHK - strt] {Service}/{Gateway} Num=\"{x}\" поиск в чёрном списке"); // if (TerminalType == 2) // return false; foreach (var item in Settings.CheckedProviders) { // Проверка любой суммы в чёрном списке if (item.Name.ToLower() == Provider.ToLower() && item.Service.ToLower() == Service.ToLower() && item.Gateway.ToLower() == Gateway.ToLower() // && AmountAll >= item.Limit -- не проверяем лимит && Pcdate.AddHours(Settings.AmountDelay) >= DateTime.Now) { // Если номер телефона в списке исключаемых завершить финансовый контроль if (FindInLists(Settings.Lists, x, 2) == 2) // Найден в чёрном списке { state = 12; errCode = 6; errDesc = string.Format("[BLACK] Отменён системой"); UpdateState(Tid, state: State, errCode: ErrCode, errDesc: ErrDesc, locked: 0); RootLog($"{Tid} [BLACK] Num={x} A={Amount.AsCF()} S={AmountAll.AsCF()} - Найден в чёрном списке. Отменён."); // Перепроведение платежа Oldi.Net.Repost.Blacklist blacklist = new Repost.Blacklist(Tid, x, Amount, AmountAll); TaskFactory factory = new TaskFactory(TaskCreationOptions.LongRunning, TaskContinuationOptions.LongRunning); RootLog($"{Tid} [BLACK] Запускается процесс допроведения"); Task blr = factory.StartNew( // Запуск препроведения в другом потоке. Этот поток завершается. () => blacklist.Run() ); RootLog($"{Tid} [BLACK] Передаётся статус в Город"); return(true); } } } // RootLog("{0} [FCHK - strt] {1}/{2} Num=\"{3}\" в чёрном списке не найден", Tid, Service, Gateway, x); return(false); }
/// <summary> /// Допроведение платежа /// </summary> /// <param name="State"></param> /// <param name="ErrCode"></param> /// <param name="ErrDesc"></param> /* * public override void Processing(byte State, int ErrCode, string ErrDesc) * { * state = State; * errCode = ErrCode; * errDesc = ErrDesc; * Processing(false); * } */ /// <summary> /// Выролнить цикл проведения/допроведения платежа /// </summary> public override void Processing(bool New) { int oldstate = State; if (New) // Новый платёж { // QIWI: // Скорретируем AmountAll: + 2.% // Корректировать QIWI больше не будем /* * if (Gateway == qiwiGateway && AmountAll > Amount) * { * RootLog($"{Tid} [CHNG AmountAll] {Service}/{Gateway} корретировка"); * * decimal oldAmount = AmountAll; * /\* * if (TerminalType == 1) * { * amountAll = Amount / (1m - 0.025m); * amountAll = Math.Round(AmountAll / 10m, 0) * 10m; * if ((1m - Amount / AmountAll) * 100m > 3.5m) * amountAll = Amount; * } * else * amountAll = Math.Round(Amount / (1m - 0.035m), 2); *\/ * * if ((1m - Amount / AmountAll) * 100m > 4.4m) * amountAll = Math.Round(Amount / (1m - 4.4m / 100m), 0); * * if (AmountAll > oldAmount) * { * amountAll = oldAmount; // Откат к старому значению. Корретировка не нужна * RootLog($"{Tid} [CHNG AmountAll] {Service}/{Gateway} корретировка не требуется"); * } * else * { * RootLog($"{Tid} [CHNG AmountAll] {Service}/{Gateway} корретировка"); * RootLog($"{Tid} [CHNG] A={Amount.AsCurrency()} Old={oldAmount.AsCurrency()} New={AmountAll.AsCurrency()} Perc={Math.Round(1 - Amount / AmountAll, 2)} TType={TerminalType}"); * } * } */ if (MakePayment() == 0) { // TraceRequest("New"); // Проверка дневного лимита для нового плательщика если это не QIWI. if (DayLimitExceeded(true)) { return; } // Сумма болше лимита и прошло меньше времени задержки отложить обработку запроса if (FinancialCheck(New)) { return; } DoPay(0, 3); } RootLog($"{Tid} [EktProcessing.NEW - start] {Provider} {Service}/{Gateway} {AmountAll.AsCF()} state={State}"); // TraceRequest("End"); } else // Redo { // Сумма болше лимита и прошло меньше времени задержки отложить обработку запроса if (State == 0) { // Проверка дневного лимита для нового плательщика если это не QIWI. if (DayLimitExceeded(false)) { return; } if (FinancialCheck(false)) { return; } } DoPay(state, 6); RootLog($"{Tid} [EktProcessing.REDO - start] oldstate={oldstate} {Provider} {Service}/{Gateway} {AmountAll.AsCF()} state={State}"); } }
/// <summary> /// Финансовы контроль /// </summary> protected virtual bool FinancialCheck(bool newPay) { string x = null; // Если тип терминала не определён: считаем терминал и включаем финюконтроль // if (State == 0 && (tt == 1 || tt == 3)) // Если только новый платёж if (State == 0) { if (!string.IsNullOrEmpty(Phone)) { x = Phone; } else if (!string.IsNullOrEmpty(Account) && string.IsNullOrEmpty(Number) && string.IsNullOrEmpty(Card)) // Если задан Number, то используется он { x = Account; } else if (!string.IsNullOrEmpty(Number) && string.IsNullOrEmpty(Card)) // Если только не задан Card { x = Number; } else if (!string.IsNullOrEmpty(Card)) { x = Card; } else { RootLog($"{Tid} [FCHK] {Provider} {Service}/{Gateway} Не задан номер счёта"); return(false); } // Проверим в чёрном списке (не важно, хоть с сайта) if (FindInBlackList(x)) { return(true); } // Если номер телефона в списке исключаемых завершить финансовый контроль if (FindInLists(Settings.Lists, x, 1) == 1) // Найден в белом списке { RootLog($"{Tid} [FCHK] Provider={Provider} {Service}/{Gateway} Num=\"{x}\" найден в белом списке, завершение проверки"); return(false); } // Получаем тип терминала из БД Город // 1 - Терминал // 2 - Рабочее место // 3 - Сайт List <CheckedProvider> ProviderList = LoadProviderList(); int tt = Terminal == 281 ? 3 : TerminalType; string trm = Terminal != int.MinValue ? Terminal.ToString() : "NOREG"; // Ищем переопределение для агента. GetAgentFromList(); RootLog($"{Tid} [FCHK] Для агента AgentID=\"{AgentId}\" заданы параметры: Limit={AmountLimit.AsCurrency()} Delay={AmountDelay} часов Notify={Notify}"); foreach (var item in ProviderList) { string _provider = string.IsNullOrEmpty(Provider) ? "": Provider.ToLower(); string _service = string.IsNullOrEmpty(Service) ? "" : Service.ToLower(); string _gateway = string.IsNullOrEmpty(Gateway) ? "" : Gateway.ToLower(); if (_provider == item.Name.ToLower() && _service == item.Service.ToLower() && _gateway == item.Gateway.ToLower() && item.TerminalType == tt) { // Переопределяем правило лимитов для провайдера amountLimit = item.Limit > amountLimit? item.Limit: AmountLimit; // check = true; RootLog($"{Tid} [FCHK] Переопределение для {Provider} {Service}/{Gateway} Type={tt}: AmountLimit={AmountLimit.AsCF()}"); break; } } // Строго больше! if (AmountAll > AmountLimit && Pcdate.AddHours(AmountDelay) >= DateTime.Now) // Проверка отправки СМС { // RootLog($"{Tid} [FCHK] {Provider} {Service}/{Gateway} Trm={Terminal} Limit={AmountLimit.AsCF()} Amount{AmountAll.AsCF()}"); // RootLog($"{Tid} [FCHK] {Provider} {Service}/{Gateway} Pcdate+delay={Pcdate.AddHours(AmountDelay).AsCF()} Limit={AmountLimit.AsCF()} Amount{AmountAll.AsCF()}"); state = 0; errCode = 11; errDesc = $"[Фин.кон-ль] Отложен до {Pcdate.AddHours(AmountDelay)}"; UpdateState(Tid, state: State, errCode: ErrCode, errDesc: ErrDesc, locked: 0); RootLog($"{Tid} [FCHK] {Provider} {Service}/{Gateway} Trm={Terminal} Acc={x} A={Amount.AsCF()} S={AmountAll.AsCF()} Limit={AmountLimit.AsCF()} - Отложен до {Pcdate.AddHours(AmountDelay).AsCF()}"); // Отправить СМС-уведомление, усли список уведомлений не пуст // Отправлять СМС только для терминалов if (newPay && !string.IsNullOrEmpty(Notify) && TerminalType == 1) { SendNotification(Notify, $"Num={x} S={AmountAll.AsCF()} Trm={Terminal} блок до {Pcdate.AddHours(AmountDelay).AsCF()}"); } // Не найден в белом списке - на контроль! return(true); } // Если меньше допустимого лимита, не ставить на контроль RootLog($"{Tid} [FCHK - stop] {Service}/{Gateway} Num=\"{x}\" сумма платежа {AmountAll.AsCurrency()} меньше общего лимита {AmountLimit.AsCurrency()}, завершение проверки"); } return(false); }
/// <summary> /// Выролнить цикл проведения/допроведения платежа /// </summary> public override void Processing(bool New) { if (New) // Новый платёж { if (MakePayment() == 0) { // TraceRequest("New"); RootLog($"{Tid} [{Provider}.Processing - NEW start] {Service}/{Gateway} {AmountAll.AsCF()}"); // Проверка дневного лимита для нового плательщика if (DayLimitExceeded(true)) { return; } // Сумма болше лимита и прошло меньше времени задержки отложить обработку запроса if (FinancialCheck(New)) { return; } DoPay(0, 3); } TechInfo = $"state={result.state} substate={result.substate} code={result.code}"; // TraceRequest("End"); } else // Redo { // Сумма болше лимита и прошло меньше времени задержки отложить обработку запроса if (State == 0) { RootLog($"{Tid} [{Provider}.Processing - REDO start] {Service}/{Gateway} {AmountAll.AsCF()}"); // Проверка дневного лимита для нового плательщика if (DayLimitExceeded(false)) { return; } if (FinancialCheck(false)) { return; } } DoPay(state, 6); } }