当前位置: 首页>>代码示例>>PHP>>正文


PHP Currency::getRateById方法代码示例

本文整理汇总了PHP中app\models\Currency::getRateById方法的典型用法代码示例。如果您正苦于以下问题:PHP Currency::getRateById方法的具体用法?PHP Currency::getRateById怎么用?PHP Currency::getRateById使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Currency的用法示例。


在下文中一共展示了Currency::getRateById方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: updatingcbr

 public function updatingcbr(Currency $currencyModel, History $historyModel)
 {
     $currency_bank = array();
     //$today = date("d/m/Y");
     $ch = curl_init();
     /*curl_setopt($ch, CURLOPT_URL,
       'http://www.cbr.ru/scripts/XML_daily.asp?date_req='.$today);*/
     curl_setopt($ch, CURLOPT_URL, 'http://www.cbr.ru/scripts/XML_daily.asp');
     curl_setopt($ch, CURLOPT_HEADER, false);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
     $xml = curl_exec($ch);
     curl_close($ch);
     if ($xml) {
         $sxml = simplexml_load_string($xml);
         foreach ($sxml->Valute as $item) {
             $charCode = (string) $item->CharCode;
             $rate = (string) $item->Value;
             $nominal = (string) $item->Nominal;
             if ($nominal > 1) {
                 $rate = $rate / $nominal;
             }
             $rate = (double) str_replace(',', '.', $rate);
             $currency_bank[$charCode] = array('rate' => $rate);
         }
         unset($sxml);
     }
     if (count($currency_bank) < 1) {
         Session::flash('message', GetMessages("ERROR"));
         return redirect()->route('currency.index');
     }
     $currenciesList = $currencyModel->getListCurrencies();
     if (isset($_REQUEST['user_id'])) {
         $user_id = $_REQUEST['user_id'];
     } else {
         $user_id = 1;
     }
     foreach ($currenciesList as $currency) {
         if (array_key_exists($currency->currency, $currency_bank)) {
             $arFields = array('currency_id' => $currency->id, 'rate' => $currency_bank[$currency->currency]['rate'], 'old_rate' => $currencyModel->getRateById($currency->id), 'user_id' => $user_id);
             $currencyModel->updateCurrency($arFields);
         }
     }
     $historyModel->saveHistory('auto_update_currency', $user_id);
     if (isset($_REQUEST['user_id'])) {
         Session::flash('message', GetMessages("SUCCESS_AUTO_UPDATING_CURR"));
         return redirect()->route('currency.index');
     } else {
         return "success updating";
     }
 }
开发者ID:enotsokolov,项目名称:vp_plus,代码行数:50,代码来源:CurrencyController.php


注:本文中的app\models\Currency::getRateById方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。