]> git.stg.codes - stg.git/commitdiff
Merge branch 'stg-2.409'
authorMaksym Mamontov <madf@madf.info>
Wed, 1 Jan 2020 19:11:53 +0000 (21:11 +0200)
committerMaksym Mamontov <madf@madf.info>
Wed, 1 Jan 2020 19:11:53 +0000 (21:11 +0200)
1  2 
projects/stargazer/plugins/store/firebird/firebird_store_users.cpp
projects/stargazer/plugins/store/postgresql/postgresql_store_users.cpp
projects/stargazer/user_impl.cpp

index fbeacae5332e115fc6d7d3092fa78863eaea16b0,d98d7929922bc2ac02a3372757c50e753622e92f..ab18a40a9a1914b11bd0970d1779666be5fe4a31
@@@ -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<std::string>::const_iterator it = conf.service.begin(); it != conf.service.end(); ++it)
 +    for(std::vector<std::string>::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
                   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();
      }
index 1ab5d0e8c2c806e28974c30065975727efc9bfa4,47999efc5e0ad63ef403f1b71f5f30d94216c341..b4c449fb32b4603464b7267924988d625bdca8be
@@@ -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);
  
index bd3f060770fd0afda8f38678c305e20a19392862,d530108b95e7f225b42e32ce544662559aba6ac3..09e71a35bc2051a006f755eff573c967a3097335
@@@ -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)