本文整理汇总了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";
}
}