コード例 #1
0
 public function bonusCourtesy(Request\BonusCourtesy $request)
 {
     $result = new Response\BonusCourtesy();
     $courtesyPercent = $request->getCourtesyBonusPercent();
     $datePerformed = $request->getDatePerformed();
     $dateApplied = $request->getDateApplied();
     $this->_logger->info("'Courtesy Bonus' calculation is started.");
     $reqGetPeriod = new PeriodGetForDependentCalcRequest();
     $reqGetPeriod->setBaseCalcTypeCode(Cfg::CODE_TYPE_CALC_VALUE_TV);
     $reqGetPeriod->setDependentCalcTypeCode(Cfg::CODE_TYPE_CALC_BONUS_COURTESY);
     $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();
             /* get PTC Compression calculation ID for this period */
             $ptcCompressCalcId = $this->_subDb->getLastCalculationIdForPeriod(Cfg::CODE_TYPE_CALC_COMPRESS_FOR_PTC, $baseDsBegin, $baseDsEnd);
             /* calculation itself */
             $this->_logger->info("Processing period #{$thisPeriodId} ({$baseDsBegin}-{$baseDsEnd})");
             /* get compressed data by calculation ID */
             $compressPtc = $this->_subDb->getCompressedPtcData($ptcCompressCalcId);
             /* get levels to calculate Personal and Team bonuses */
             $levelsPersonal = $this->_subDb->getBonusLevels(Cfg::CODE_TYPE_CALC_BONUS_PERSONAL_DEF);
             $levelsTeam = $this->_subDb->getBonusLevels(Cfg::CODE_TYPE_CALC_BONUS_TEAM_DEF);
             /* calculates bonus and save operation with transactions */
             $updates = $this->_subCalc->bonusCourtesy($compressPtc, $courtesyPercent, $levelsPersonal, $levelsTeam);
             /* prepare data for updates */
             $updatesForWallets = [];
             foreach ($updates as $custId => $items) {
                 foreach ($items as $item) {
                     $bonus = $item[Calc::A_VALUE];
                     $childId = $item[Calc::A_OTHER_ID];
                     if ($bonus > Cfg::DEF_ZERO) {
                         $updatesForWallets[] = [Calc::A_CUST_ID => $custId, Calc::A_VALUE => $bonus, Calc::A_OTHER_ID => $childId];
                     }
                 }
             }
             $respAdd = $this->_subDb->saveOperationWalletActive($updatesForWallets, Cfg::CODE_TYPE_OPER_BONUS_COURTESY, $datePerformed, $dateApplied);
             $operId = $respAdd->getOperationId();
             $transIds = $respAdd->getTransactionsIds();
             /* save orders and correspondent transactions into the log */
             $this->_subDb->saveLogCustomers($updatesForWallets, $transIds);
             /* 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("'Courtesy Bonus' calculation is completed.");
     return $result;
 }
コード例 #2
0
 public function test_bonusCourtesy()
 {
     /** === Test Data === */
     $COMPRESSED = [[PtcCompress::ATTR_CUSTOMER_ID => 1, Customer::ATTR_HUMAN_REF => 'ref01', Customer::ATTR_COUNTRY_CODE => 'LV', PtcCompress::ATTR_PARENT_ID => 1, PtcCompress::ATTR_PV => 25, PtcCompress::ATTR_TV => 205], [PtcCompress::ATTR_CUSTOMER_ID => 2, Customer::ATTR_HUMAN_REF => 'ref02', Customer::ATTR_COUNTRY_CODE => 'LV', PtcCompress::ATTR_PARENT_ID => 1, PtcCompress::ATTR_PV => 60, PtcCompress::ATTR_TV => 0], [PtcCompress::ATTR_CUSTOMER_ID => 3, Customer::ATTR_HUMAN_REF => 'ref03', Customer::ATTR_COUNTRY_CODE => 'LV', PtcCompress::ATTR_PARENT_ID => 1, PtcCompress::ATTR_PV => 120, PtcCompress::ATTR_TV => 0]];
     /** === Mocks === */
     $mLogger = $this->_mockLogger();
     $mToolFormat = new ToolFormat();
     $mToolScheme = $this->_mockFor('\\Praxigento\\Bonus\\Hybrid\\Lib\\Tool\\IScheme');
     $mToolbox = $this->_mockToolbox(null, null, $mToolFormat, null, $mToolScheme);
     $mCallDownlineSnap = $this->_mockFor('\\Praxigento\\Downline\\Service\\ISnap');
     // $custScheme = $this->_toolScheme->getSchemeByCustomer($item);
     $mToolScheme->expects($this->any())->method('getSchemeByCustomer')->willReturn(Def::SCHEMA_DEFAULT);
     // $tv = $this->_toolScheme->getForcedTv($custId, $custScheme, $tv);
     $mToolScheme->expects($this->any())->method('getForcedTv')->willReturnArgument(2);
     /**
      * Prepare request and perform call.
      */
     /** @var  $sub Calc */
     $sub = new Calc($mLogger, $mToolbox, $mCallDownlineSnap);
     $res = $sub->bonusCourtesy($COMPRESSED, $this->COURTESY_PERCENT, $this->LEVELS_PERS, $this->LEVELS_TEAM);
     $this->assertTrue(is_array($res));
 }