Exemplo n.º 1
0
 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();
             }
         }
     }
 }
Exemplo n.º 2
0
 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();
             }
         }
     }
 }