From: Maksym Mamontov Date: Wed, 1 Jan 2020 19:11:53 +0000 (+0200) Subject: Merge branch 'stg-2.409' X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/a6680ce3d763763a6010c81c8a5a8f7a1ce052db?hp=-c Merge branch 'stg-2.409' --- a6680ce3d763763a6010c81c8a5a8f7a1ce052db diff --combined projects/stargazer/plugins/store/firebird/firebird_store_users.cpp index fbeacae5,d98d7929..ab18a40a --- a/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp +++ b/projects/stargazer/plugins/store/firebird/firebird_store_users.cpp @@@ -302,7 -302,7 +302,7 @@@ tr st->Prepare("insert into tb_users_services (fk_user, fk_service) \ values (?, (select pk_service from tb_services \ where name = ?))"); - for(std::vector::const_iterator it = conf.service.begin(); it != conf.service.end(); ++it) + for(std::vector::const_iterator it = conf.services.begin(); it != conf.services.end(); ++it) { st->Set(1, uid); st->Set(2, *it); @@@ -516,7 -516,7 +516,7 @@@ tr { std::string name; st->Get(1, name); - conf->service.push_back(name); + conf->services.push_back(name); } // User data @@@ -537,14 -537,15 +537,15 @@@ where fk_user = ?"); st->Set(1, uid); st->Execute(); - conf->ips.Erase(); + USER_IPS ips; while (st->Fetch()) { IP_MASK im; st->Get(1, (int32_t &)im.ip); st->Get(2, (int32_t &)im.mask); - conf->ips.Add(im); + ips.Add(im); } + conf->ips = ips; tr->Commit(); } diff --combined projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp index 1ab5d0e8,47999efc..b4c449fb --- a/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp +++ b/projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp @@@ -565,7 -565,7 +565,7 @@@ if (PQresultStatus(result) != PGRES_COM PQclear(result); -if (SaveUserServices(uid, conf.service)) +if (SaveUserServices(uid, conf.services)) { printfd(__FILE__, "POSTGRESQL_STORE::SaveUserConf(): 'Failed to save user's services'\n"); if (RollbackTransaction()) @@@ -884,7 -884,7 +884,7 @@@ tuples = PQntuples(result) for (int i = 0; i < tuples; ++i) { - conf->service.push_back(PQgetvalue(result, i, 0)); + conf->services.push_back(PQgetvalue(result, i, 0)); } PQclear(result); @@@ -954,26 -954,22 +954,22 @@@ if (PQresultStatus(result) != PGRES_TUP tuples = PQntuples(result); - conf->ips.Erase(); + USER_IPS ips; for (int i = 0; i < tuples; ++i) { - IP_MASK ipm; + IP_MASK im; - int ip, mask; + im.ip = inet_strington(PQgetvalue(result, i, 0)); - ip = inet_strington(PQgetvalue(result, i, 0)); - - if (str2x(PQgetvalue(result, i, 1), mask)) + if (str2x(PQgetvalue(result, i, 1), im.mask)) { printfd(__FILE__, "POSTGRESQL_STORE::RestoreUserConf(): 'Failed to fetch mask'\n"); continue; } - ipm.ip = ip; - ipm.mask = mask; - - conf->ips.Add(ipm); + ips.Add(im); } + conf->ips = ips; PQclear(result); diff --combined projects/stargazer/user_impl.cpp index bd3f0607,d530108b..09e71a35 --- a/projects/stargazer/user_impl.cpp +++ b/projects/stargazer/user_impl.cpp @@@ -222,6 -222,7 +222,7 @@@ void USER_IMPL::Init( { password = "*_EMPTY_PASSWORD_*"; tariffName = NO_TARIFF_NAME; + tariff = tariffs->FindByName(tariffName); ips = StrToIPS("*"); lastWriteStat = stgTime + random() % settings->GetStatWritePeriod(); lastWriteDetailedStat = stgTime; @@@ -1348,75 -1349,6 +1349,75 @@@ switch (settings->GetFeeChargeType() ResetPassiveTime(); } //----------------------------------------------------------------------------- +void USER_IMPL::ProcessServices() +{ +struct tm tms; +time_t t = stgTime; +localtime_r(&t, &tms); + +double passiveTimePart = 1.0; +if (!settings->GetFullFee()) + { + passiveTimePart = GetPassiveTimePart(); + } +else + { + if (passive.ConstData()) + { + printfd(__FILE__, "Don't charge fee `cause we are passive\n"); + return; + } + } + +for (size_t i = 0; i < property.Conf().services.size(); ++i) + { + SERVICE_CONF conf; + if (m_services.Find(property.Conf().services[i], &conf)) + continue; + if (conf.payDay == tms.tm_mday || + (conf.payDay == 0 && tms.tm_mday == DaysInCurrentMonth())) + { + double c = cash; + double fee = conf.cost * passiveTimePart; + printfd(__FILE__, "Service fee. login: %8s Cash=%f Credit=%f Fee=%f PassiveTimePart=%f fee=%f\n", + login.c_str(), + cash.ConstData(), + credit.ConstData(), + tariff->GetFee(), + passiveTimePart, + fee); + switch (settings->GetFeeChargeType()) + { + case 0: + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + SetPrepaidTraff(); + break; + case 1: + if (c + credit >= 0) + { + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + SetPrepaidTraff(); + } + break; + case 2: + if (c + credit >= fee) + { + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + SetPrepaidTraff(); + } + break; + case 3: + if (c >= 0) + { + property.cash.Set(c - fee, sysAdmin, login, store, "Subscriber fee charge"); + SetPrepaidTraff(); + } + break; + } + } + } +} +//----------------------------------------------------------------------------- void USER_IMPL::SetPrepaidTraff() { if (tariff != NULL)