public function bonusInfinity(Request\BonusInfinity $request) { $result = new Response\BonusInfinity(); $scheme = $this->_getCalculationsScheme($request->getScheme()); $datePerformed = $request->getDatePerformed(); $dateApplied = $request->getDateApplied(); $this->_logger->info("'Infinity Bonus' calculation is started ({$scheme} scheme)."); if ($scheme == Def::SCHEMA_EU) { $calcTypeBase = Cfg::CODE_TYPE_CALC_COMPRESS_FOR_OI_EU; $calcType = Cfg::CODE_TYPE_CALC_BONUS_INFINITY_EU; } else { $calcTypeBase = Cfg::CODE_TYPE_CALC_COMPRESS_FOR_OI_DEF; $calcType = Cfg::CODE_TYPE_CALC_BONUS_INFINITY_DEF; } $reqGetPeriod = new PeriodGetForDependentCalcRequest(); $reqGetPeriod->setBaseCalcTypeCode($calcTypeBase); $reqGetPeriod->setDependentCalcTypeCode($calcType); $respGetPeriod = $this->_callPeriod->getForDependentCalc($reqGetPeriod); if ($respGetPeriod->isSucceed()) { $def = $this->_manTrans->begin(); try { /* working vars */ $thisPeriodData = $respGetPeriod->getDependentPeriodData(); $thisPeriodId = $thisPeriodData[Period::ATTR_ID]; $thisCalcData = $respGetPeriod->getDependentCalcData(); $thisCalcId = $thisCalcData[Calculation::ATTR_ID]; $basePeriodData = $respGetPeriod->getBasePeriodData(); $baseDsBegin = $basePeriodData->getDstampBegin(); $baseDsEnd = $basePeriodData->getDstampEnd(); $baseCalcData = $respGetPeriod->getBaseCalcData(); $baseCalcId = $baseCalcData->getId(); /* calculation itself */ $this->_logger->info("Processing period #{$thisPeriodId} ({$baseDsBegin}-{$baseDsEnd})"); /* get compressed data by calculation ID */ $compressOi = $this->_subDb->getCompressedOiData($baseCalcId); /* get configuration for Override and Infinity bonuses */ $cfgParams = $this->_subDb->getCfgParams(); /* calculate bonus amounts */ $updates = $this->_subCalc->bonusInfinity($compressOi, $scheme, $cfgParams); /* prepare update data */ $updatesForWallets = []; $updatesForPvInf = []; foreach ($updates as $custId => $item) { $pv = $item[Calc::A_PV]; $bonusEntries = $item[Calc::A_ENTRIES]; $updatesForPvInf[$custId] = [OiCompress::ATTR_PV_INF => $pv]; foreach ($bonusEntries as $entry) { $bonus = $entry[Calc::A_VALUE]; $childId = $entry[Calc::A_OTHER_ID]; if ($bonus > Cfg::DEF_ZERO) { $updatesForWallets[] = [Calc::A_CUST_ID => $custId, Calc::A_VALUE => $bonus, Calc::A_OTHER_ID => $childId]; } } } unset($updates); /* update wallets */ $respAdd = $this->_subDb->saveOperationWalletActive($updatesForWallets, Cfg::CODE_TYPE_OPER_BONUS_INFINITY, $datePerformed, $dateApplied); $operId = $respAdd->getOperationId(); $transIds = $respAdd->getTransactionsIds(); /* save orders and correspondent transactions into the log */ $this->_subDb->saveLogCustomers($updatesForWallets, $transIds); unset($updatesForWallets); /* update OI Compressed data */ $this->_subDb->saveUpdatesOiCompress($updatesForPvInf, $baseCalcId); /* save processed operation to calculations log and mark calculation as complete */ $this->_subDb->saveLogOperations($operId, $thisCalcId); $this->_subDb->markCalcComplete($thisCalcId); /* finalize response as succeed */ $this->_manTrans->commit($def); $result->markSucceed(); $result->setPeriodId($thisPeriodId); $result->setCalcId($thisCalcId); } finally { $this->_manTrans->end($def); } } $this->_logMemoryUsage(); $this->_logger->info("'Infinity Bonus' calculation is completed."); return $result; }