Example #1
0
 public static function getDepartments($checkCache = true)
 {
     $response = new ApiResponseModel();
     $data = array();
     if ($checkCache) {
         $data = ApiCache::get(Yii::app()->params['cache']['keys']['departments']);
     }
     if (!$data) {
         $availableBanks = BankCourses::model()->findAvailableBanks()->findAll();
         if (count($availableBanks) > 0) {
             $ids = array();
             foreach ($availableBanks as $bankInfo) {
                 $ids[] = $bankInfo['bank_id'];
             }
             $answer = new DepartmentApiModel();
             $banks = Bank::model()->getBankToAPI($ids)->findAll();
             foreach ($banks as $bank) {
                 $answer->setBank($bank);
                 $departments = BankBranches::model()->getBankDepartment($bank->id)->findAll();
                 foreach ($departments as $department) {
                     $answer->setDepartment($department);
                     $answer->add();
                 }
             }
             $data = $answer->getResult();
             $response->setHash(ApiCache::set(Yii::app()->params['cache']['keys']['departments'], $data, Yii::app()->params['cache']['time']));
             $response->setData($data);
         }
     } else {
         $response->setData($data);
         $response->setHash(ApiCache::getCheck(Yii::app()->params['cache']['keys']['departments']));
     }
     return $response->getApiResponse();
 }
 public function actionView()
 {
     $bankId = Yii::app()->request->getQuery('id');
     $bank = Bank::model()->findByPk($bankId);
     $departments = BankBranches::model()->getBankDepartment($bankId)->findAll();
     $rates = BankCourses::model()->getBankRates($bankId)->findAll();
     $this->render('view', array('bank' => $bank, 'departments' => $departments, 'rates' => $rates));
 }
 public function save()
 {
     foreach ($this->banks as $key => $bankInfo) {
         $bank = False;
         $bankResource = BankResources::model()->getBankResource($this->sourceType, $key)->find();
         if ($bankResource) {
             $bank = Bank::model()->findByPk($bankResource->bank_id);
         }
         if (!$bank) {
             $bank = new Bank();
         }
         foreach ($bankInfo as $sum => $info) {
             if (!$bank->id) {
                 //                    $bank->phone = $info['info']['tel'];
                 $bank->address = $info['info']['address'];
                 $bank->name = $info['name'];
                 $bank->save();
                 $bankResource = new BankResources();
                 $bankResource->bank_id = $bank->id;
                 $bankResource->source_id = $this->sourceType;
                 $bankResource->source_alias = $key;
                 $bankResource->save();
                 $newBranch = new BankBranches();
                 $newBranch->address = $info['info']['address'];
                 $yandexGeoDecode = @file_get_contents('http://geocode-maps.yandex.ru/1.x/?format=json&results=1&geocode=город Москва, ' . $newBranch->address);
                 if ($yandexGeoDecode) {
                     $answer = json_decode($yandexGeoDecode, True);
                     if (!isset($answer['response']) && count($answer['response']['GeoObjectCollection']['featureMember']) == 0) {
                         continue;
                     }
                     $pos = $answer['response']['GeoObjectCollection']['featureMember'][0]['GeoObject']['Point']['pos'];
                     $pos = explode(' ', $pos);
                     $newBranch->latitude = $pos[1];
                     $newBranch->longtitude = $pos[0];
                     $newBranch->preparePhone($info['info']['tel']);
                     $newBranch->save();
                     $newBranch->bank_id = $bank->id;
                     $newBranch->save();
                 }
             }
             if ($bank->id) {
                 $cur = new BankCourses();
                 $cur->bank_id = $bank->id;
                 $cur->buy = $info['pok'];
                 $cur->sale = $info['prod'];
                 $cur->sum = $sum;
                 $cur->currency = $this->siteCurrencyType;
                 $cur->save();
             }
         }
     }
 }
 public function save()
 {
     foreach ($this->banks as $site_bank_id => $bankInfo) {
         $bank = Bank::model()->getBankByNameLike($bankInfo['name'])->find();
         if ($bank) {
             foreach ($bankInfo['rates'] as $currency => $info) {
                 $cur = new BankCourses();
                 $cur->bank_id = $bank->id;
                 $cur->buy = $info['buy'];
                 $cur->sale = $info['sell'];
                 $cur->currency = $currency;
                 $cur->save();
             }
         }
     }
 }
Example #5
0
 /**
  * @return Bank[]
  */
 protected function _getOldBanks()
 {
     return Bank::model()->findAll(array('index' => 'license'));
 }
Example #6
0
 /**
  * @return Bank[]
  */
 protected function _getBanks($bank)
 {
     return Bank::model()->findAll(array('condition' => $bank ? 'name="' . $bank . '"' : 'name is not null'));
 }
Example #7
0
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return Bank the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = Bank::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
Example #8
0
 private function updatebank($client, $grid, $tt = 1)
 {
     $it = TmpXml::model()->findAll("ctype=:ctype AND ckey=:ckey AND user=:user", array(':ctype' => $tt == 1 ? 12 : 13, ':ckey' => $client, ':user' => Yii::app()->user->uid));
     if (!($it === null)) {
         $new_bank = false;
         $bank_ps = array();
         foreach ($it as $valu) {
             if ($valu->cname == 'id') {
                 $bank_id = $valu->lname;
                 $bank = Bank::model()->find("longname=:longname", array(':longname' => $bank_id));
                 if ($bank === null) {
                     $new_bank = true;
                     $bank = new Bank();
                     $bank->type_id = $tt;
                     $bank->department_id = $grid;
                     $bank->longname = $bank_id;
                     $bank->name = $bank_id;
                     $bank->save();
                 }
             } elseif ($valu->cname == 'host') {
             } else {
                 $bank_ps[$valu->cname] = $valu->lname;
             }
         }
         if ($new_bank) {
             foreach ($bank_ps as $key => $valu) {
                 $prop = new BankProp();
                 $prop->id = $bank->id;
                 $prop->_key = $key;
                 $prop->_value = $valu;
                 $prop->save();
             }
         } else {
             foreach ($bank_ps as $key => $valu) {
                 if (!($prop = BankProp::model()->findByPk(array('id' => $bank->id, '_key' => $key)))) {
                     $prop = new BankProp();
                 }
                 $prop->id = $bank->id;
                 $prop->_key = $key;
                 $prop->_value = $valu;
                 $prop->save();
             }
         }
     }
 }
 public function run($args)
 {
     $mem_start = memory_get_usage();
     $url = 'http://www.banki.ru/api/';
     $data = array('id' => '1', 'method' => 'bankInfo/getBankList', 'jsonrpc' => '2.0', 'params' => array('region_id' => array(4), 'show_on_banki' => array(0, 1, 2)));
     $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data)));
     $context = stream_context_create($options);
     $result = file_get_contents($url, false, $context);
     $banks = json_decode($result, True);
     if (isset($banks['error'])) {
         print $banks['error'];
         die;
     }
     $banksData = array();
     $bankNewId = array();
     foreach ($banks['result']['data'] as $bankInfo) {
         switch ($bankInfo['region']) {
             case 'Москва':
                 $source_bank_id = $bankInfo['bank_id'];
                 $bank = Bank::model()->getBankResource(Yii::app()->params['sourceId']['bankiRu'], $source_bank_id)->find();
                 if (!$bank) {
                     $bank = new Bank();
                     $bank->name = $bankInfo['bank_name'];
                     $bank->source_id = Yii::app()->params['sourceId']['bankiRu'];
                     $bank->source_alias = $source_bank_id;
                     $bank->save();
                 }
                 $bankNewId[$source_bank_id] = $bank->id;
                 $banksData[$bank->id] = $bank;
                 break;
             default:
                 break;
         }
     }
     $data = array('id' => '2', 'method' => 'bankGeo/getObjectsByFilter', 'jsonrpc' => '2.0', 'params' => array('bank_id' => array_keys($bankNewId), 'limit' => 100000000, 'region_id' => array(4), 'type' => array('office', 'branch', 'cash'), 'with_empty_coordinates' => true));
     $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data)));
     $context = stream_context_create($options);
     $result = file_get_contents($url, false, $context);
     $branchData = json_decode($result, True);
     if (isset($branchData['error'])) {
         print_r($branchData['error']);
         die;
     }
     foreach ($branchData['result']['data'] as $branch) {
         $newBranch = BankBranches::model()->getBranchesResource(Yii::app()->params['sourceId']['bankiRu'], $branch['id'])->find();
         if (!$newBranch) {
             $newBranch = new BankBranches();
             $newBranch->address = $branch['address'];
             $data = array('id' => '3', 'method' => 'bank/getBankObjectsData', 'jsonrpc' => '2.0', 'params' => array('id_list' => array($branch['id'])));
             $options = array('http' => array('header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => json_encode($data)));
             $context = stream_context_create($options);
             $result = json_decode(file_get_contents($url, false, $context), true);
             $newBranch->latitude = $branch['latitude'];
             $newBranch->longtitude = $branch['longitude'];
             $newBranch->bank_id = $bankNewId[$branch['bank_id']];
             if (!isset($result['error'])) {
                 $ph = $newBranch->preparePhone($result['result']['data'][0]['phone']);
                 if ($result['result']['data'][0]['is_main_office'] == 1) {
                     if (isset($banksData[$bankNewId[$branch['bank_id']]])) {
                         $b = $banksData[$bankNewId[$branch['bank_id']]];
                         $b->phone = $ph;
                         $b->save();
                     }
                 }
             }
             $newBranch->save();
         }
     }
     echo memory_get_usage() - $mem_start;
 }