コード例 #1
0
 public function getData()
 {
     /**
      * Get all information and return
      */
     $finalArr = array();
     $asteriskData = AsteriskCarriers::getData();
     $voipInfoRetriever = new BestVOIPInformationRetriever();
     foreach ($asteriskData as $key => $currentAsteriskData) {
         $remoteVoipResult = $voipInfoRetriever->getInfo($currentAsteriskData['main_user'], $currentAsteriskData['main_pass'], $currentAsteriskData['sub_user'], $currentAsteriskData['sub_pass']);
         $currentAsteriskData['id'] = $key;
         $currentAsteriskData['balance'] = doubleval($remoteVoipResult->getBalance());
         $currentAsteriskData['exact_balance'] = doubleval($remoteVoipResult->getSpecificBalance());
         $finalArr[] = $currentAsteriskData;
     }
     return $finalArr;
 }
コード例 #2
0
 public function sync(RemoteDataCache $model)
 {
     if (!$model) {
         throw new Exception("RemoteDataCache cannot be null");
     }
     /* get information from remote api server */
     $voipInfoRetriever = new BestVOIPInformationRetriever();
     $last_balance = $model->balance;
     $remoteVoipResult = $voipInfoRetriever->getInfo($model->main_user, $model->main_pass, $model->sub_user, $model->sub_pass);
     $model->balance = doubleval($remoteVoipResult->getBalance());
     $model->exact_balance = doubleval($remoteVoipResult->getSpecificBalance());
     $model->last_balance = $last_balance;
     $model->save();
     /* check notification */
     // $this->checkNotification($model);
     /* check status */
     // $this->checkStatus($model);
 }
コード例 #3
0
 /**
  *
  * @throws Exception
  * @return integer Returns number of updated accounts
  */
 public function topupAccounts()
 {
     $accountsAffectedInt = 0;
     $accountsArr = explode(",", $this->accounts);
     $groupId = uniqid();
     foreach ($accountsArr as $key => $currentAccountName) {
         /**
          * @var $model RemoteDataCache
          */
         $model = RemoteDataCache::model()->findByAttributes(array('sub_user' => $currentAccountName));
         if ($model) {
             //topup the main account
             /**
              * @var $topUpMainAccount TopUpMainAccount
              */
             $topUpMainAccount = Yii::app()->topUpMainAccount;
             $topUpMainAccount->topUp($this->freeVoipAccountUsername, $this->topupvalue, $model);
             //$this->topUpMainAccount($model); // topup the main account  , old implementation
             //TOPUP the sub accounts
             /**
              * @TODO - use Yii component , put this to yii component
              */
             $remoteAcctUpdated = new ApiRemoteUpdateBalance($model->sub_pass, $model->sub_user, $model->main_pass, $model->main_user, $this->topupvalue);
             /**
              * Logger
              */
             ViciActionLogger::logAction("SUB_ACCOUNT_TOPUP", "Top upping {$model->sub_user} with {$this->topupvalue}", $this->topupvalue, $groupId, time());
             /**
              * @TODO - use Yii component
              */
             if ($remoteAcctUpdated->update()) {
                 if ($this->andActivate) {
                     /**
                      * @TODO - use Yii component
                      */
                     $activator = new ActivationFormModel();
                     $activator->activateAccount($model);
                 }
             }
             /**
              * Force the RemoteDataCache instance to update its current campaign
              */
             $campaignForcer = Yii::app()->campaignForcer;
             $campaignForcer->update($this->forceAgent, $model->sub_user);
             /**
              * Get the latest data from remote api
              */
             $lastBalance = $model->balance;
             $voipInfoRetriever = new BestVOIPInformationRetriever();
             $remoteVoipResult = $voipInfoRetriever->getInfo($model->main_user, $model->main_pass, $model->sub_user, $model->sub_pass);
             /**
              * Checking
              */
             if ($model->last_balance_since_topup !== 0 && !is_null($model->last_balance_since_topup)) {
                 /**
                  * Create a charge log for certain remote data cache
                  */
                 $newChargeLog = new AccountChargeLog();
                 $newChargeLog->account_id = $model->id;
                 $newChargeLog->charge = doubleval($model->last_balance_since_topup) - doubleval($model->exact_balance);
                 if (!$newChargeLog->save()) {
                     throw new Exception(CHtml::errorSummary($newChargeLog));
                 }
             }
             $model->balance = doubleval($remoteVoipResult->getBalance());
             $model->exact_balance = doubleval($remoteVoipResult->getSpecificBalance());
             $model->last_balance = $lastBalance;
             $model->last_balance_since_topup = $remoteVoipResult->getSpecificBalance();
             $model->save();
             /**
              * Update the counter
              */
             $accountsAffectedInt++;
         }
     }
     return $accountsAffectedInt;
 }