/** * 获取汇率 * 雅虎YQL https://developer.yahoo.com/yql/console/ * 请求语句 select * from yahoo.finance.xchange where pair="CNYUSD,CNYHKD" * 示例 https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22CNYUSD%2CCNYHKD%22%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback= */ public function actionExrates() { $units = tools::getUnits(); unset($units['CNY']); $arr = array(); foreach ($units as $k => $v) { $arr[] = 'CNY' . $k; } $str = join(',', $arr); $url = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.xchange%20where%20pair%3D%22{$str}%22%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback="; $output = zmf::curlget($url); if (!$output) { exit('Failed'); } $rateArr = CJSON::decode($output); $rateArr = $rateArr['query']['results']['rate']; foreach ($rateArr as $val) { $_key = str_replace('CNY', '', $val['id']); $rates[$_key] = array('rate' => $val['Rate'], 'title' => tools::getUnits($_key)); } $detailDir = Yii::app()->basePath . '/runtime/rates/'; zmf::createUploadDir($detailDir); $dir = $detailDir . 'detail.log'; file_put_contents($dir, CJSON::encode($rates)); exit('well done'); }
<?php echo $form->error($model, 'score'); ?> </div> <div class="clearfix"></div> <div class="form-group"> <?php echo $form->labelEx($model, 'cost'); ?> <div class="input-group" style='width: 300px;'> <?php echo $form->textField($model, 'cost', array('size' => 16, 'maxlength' => 16, 'class' => 'form-control', 'disabled' => 'disabled')); ?> <span class="input-group-addon"><?php echo tools::getUnits($info['units']); ?> </span> </div> <?php echo $form->error($model, 'cost'); ?> </div> <div class="form-group"> <?php echo $form->labelEx($model, 'content'); ?> <?php echo $form->textArea($model, 'content', array('rows' => 6, 'cols' => 50, 'class' => 'form-control', 'disabled' => 'disabled')); ?> <?php