/** * 批量操作 * */ public function actionBatch() { if (XUtils::method() == 'GET') { $command = trim($_GET['command']); $ids = intval($_GET['id']); } elseif (XUtils::method() == 'POST') { $command = trim($_POST['command']); $ids = $_POST['id']; is_array($ids) && ($ids = implode(',', $ids)); } else { XUtils::message('errorBack', '只支持POST,GET数据'); } empty($ids) && XUtils::message('error', '未选择记录'); switch ($command) { case 'delete': parent::_acl('exchangeRate_delete'); $cityModel = new ExchangeRate(); $cityModel->deleteAll('id IN(' . $ids . ')'); AdminLogger::_create(array('catalog' => 'delete', 'intro' => '删除内汇率,ID:' . $ids)); parent::_delete(new ExchangeRate(), $ids, array('index')); break; default: throw new CHttpException(404, '错误的操作类型:' . $command); break; } }
public static function Update($code, $to) { $from = 1 / $to; try { $sRate = ExchangeRate::CreateFromQuery("SELECT * FROM exchange_rates WHERE `Code` = :Code", array(":Code" => $code), 0, true); } catch (NotFoundException $e) { $sRate = new ExchangeRate(0); $sRate->uCurrencyCode = $code; } $sRate->uToRate = $to; $sRate->uFromRate = $from; $sRate->uUpdateDate = time(); $sRate->InsertIntoDatabase(); }
public static function UpdateRates() { global $cphp_config; $json = json_decode(file_get_contents("http://openexchangerates.org/api/latest.json?app_id={$cphp_config->openexchangerates->app_id}"), true); $rates = $json["rates"]; foreach ($rates as $currency => $rate) { ExchangeRate::Update($currency, $rate); } }
public function getCurrencyPrice() { if ($currentCurrency = Session::get('Currency')) { $currencyRate = ExchangeRate::get()->filter(array("Currency" => $currentCurrency))->first(); if ($currencyRate && $currencyRate->exists()) { $convertedPrice = $this->owner->getField('BasePrice') * $currencyRate->Rate; return $convertedPrice; } } // no currency other than base return false; }
public function beforeSave() { if ($this->pk()) { $cur = ExchangeRate::get($this->pk()); if ($cur->rate != $this->rate) { $history = new ExchangeRate\History(); $history->currency_exchangerate_id = $this->pk(); $history->old = $cur->rate; $history->new = $this->rate; $history->save(); } } }
function toUAH_update() { $realty_ = new Realty(); //получаем актуальный курс $er = new ExchangeRate(); $data = $er->getExchangeRateByChar3('USD'); $usd = floatval($data->rate) / floatval($data->size); $data = $er->getExchangeRateByChar3('EUR'); $eur = floatval($data->rate) / floatval($data->size); $data = $er->getExchangeRateByChar3('RUB'); $rur = floatval($data->rate) / floatval($data->size); //SELECT * FROM `realty` where id = '37844731-3aaa-65b0-e84b-51b36762ab81' //UPDATE `realty` SET `currency_uah` = ( `totalcost` * 0.25 ) WHERE id = '37844731-3aaa-65b0-e84b-51b36762ab81' $query_usd = "UPDATE `realty` SET `currency_uah` = ( `totalcost` * {$usd} ) WHERE UPPER(currency) = 'USD'"; $query_eur = "UPDATE `realty` SET `currency_uah` = ( `totalcost` * {$eur} ) WHERE UPPER(currency) = 'EUR'"; $query_rur = "UPDATE `realty` SET `currency_uah` = ( `totalcost` * {$rur} ) WHERE UPPER(currency) = 'RUR'"; $query_uah = "UPDATE `realty` SET `currency_uah` = `totalcost` WHERE UPPER(currency) = 'UAH'"; $result = $realty_->db->query($query_usd, true); $result = $realty_->db->query($query_eur, true); $result = $realty_->db->query($query_rur, true); $result = $realty_->db->query($query_uah, true); }
public function doChangeCurrency($data, Form $form) { // validate here again $currencyIsValid = ExchangeRate::get()->filter(array("ID" => $data['Currency'], "Status" => 1))->first(); if ($currencyIsValid && $currencyIsValid->exists()) { // clear it just incase Session::clear('Currency'); // trigger set currenct function $this->setCurrentCurrency($currencyIsValid->Currency); } // return the user to where they were return Controller::curr()->redirectBack(); }
/** * Generated from @assert ("USD", "JPY") < 130. * * @covers ExchangeRate::doGetRate */ public function testDoGetRate2() { $this->assertLessThan(130, $this->object->doGetRate("USD", "JPY")); }
<?php include_once "Config.php"; include_once BASE_PATH . '/Lib/ExchangeRate.php'; include_once BASE_PATH . '/Lib/AidstreamConnector.php'; $exchange = new ExchangeRate(); $aidConnector = new AidstreamConnector(); define('DEFAULT_CURRENCY', 'USD'); define('DEFAULT_ORG', 'All'); $filename = INPUT_FILE_DIR . COMBINED_ORG_FILENAME; $outputDir = INPUT_JSON_DIR; exec('rm -r ' . $outputDir . '*.json'); if (!file_exists($outputDir)) { mkdir($outputDir); } $fp = fopen($filename, 'r'); $reportingOrg = array(); $title = fgetcsv($fp); $title = preg_replace('/-/', '_', $title); $keys = array_flip($title); $outputData = array(); while (($data = fgetcsv($fp)) !== FALSE) { foreach ($keys as $key => $keyValue) { $out[$key] = $data[$keyValue]; } // Organisation Name $reportingOrgName = $out['reporting_organisation']; // Activity Status $activityStatus = array('Completion', 'Post-completion', 'Implementation', 'Pipeline/identification', 'Cancelled'); foreach ($activityStatus as $element) { $statusCode = $out['activity_status_code'];
/** * 房源详情 */ public function actionView($id) { Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/house.css'); Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/flowplayer-3.2.11.min.js'); $cookies = Yii::app()->request->getCookies(); if (!empty($cookies['fzd_house'])) { $house_ids = explode(',', $cookies['fzd_house']->value); array_push($house_ids, $id); $house_ids = array_unique($house_ids); $cookie_str = implode(',', $house_ids); $cookie = new CHttpCookie('fzd_house', $cookie_str); $cookie->expire = time() + 60 * 60 * 24 * 30; //有限期30天 Yii::app()->request->cookies['fzd_house'] = $cookie; } else { $cookie = new CHttpCookie('fzd_house', $id); $cookie->expire = time() + 60 * 60 * 24 * 30; //有限期30天 Yii::app()->request->cookies['fzd_house'] = $cookie; } $criteria = new CDbCriteria(); $criteria->addCondition('t.id="' . $id . '"'); $criteria->with = array('mname', 'propertyType'); //$house = House::model()->find('id=:id',array(':id'=>$id)); $house = House::model()->find($criteria); $layouts = Layout::model()->findAll('house_id=:house_id', array(':house_id' => $id)); $matches = Match::model()->findAll(); $collection_list = array(); if ($this->_account['userId']) { $collect_model = Collect::model()->find('user_id=:user_id', array(':user_id' => $this->_account['userId'])); if (!empty($collect_model)) { $collection_list = explode(',', $collect_model->collection); } } //附件房源 $criteria = new CDbCriteria(); $criteria->select = 'id,addr,lp_dol,house_image'; $criteria->condition = 'zip=:zip AND id<>:id'; $criteria->params = array(':zip' => $house->zip, ':id' => $id); $criteria->order = 'id DESC'; $nearby_houses = House::model()->findAll($criteria); //浏览记录 $cookies = Yii::app()->request->getCookies(); $house_ids = explode(',', $cookies['addr']->value); $criteria = new CDbCriteria(); $criteria->select = 'id,addr,lp_dol,house_image'; $criteria->addInCondition('id', $house_ids); $view_history = House::model()->findAll($criteria); $exchangeRate = 0; $exchangeRateList = ExchangeRate::model()->findAll(); if (!empty($exchangeRateList)) { $exchangeRate = $exchangeRateList[0]->rate; } $data = array('house' => $house, 'layouts' => $layouts, 'matches' => $matches, 'collection_list' => $collection_list, 'nearby_houses' => $nearby_houses, 'view_history' => $view_history, 'exchangeRate' => $exchangeRate); $this->render('view', $data); }
public function updatePrice($amount) { //If the order is processed and the currency saved, use that //If the order is processed and no currency saved, do nothing //If the order is not processed and the currency in Session, use that $order = $this->owner->Order(); if ($order->Status != 'Cart') { if ($order->Currency && $order->ExchangeRate) { $amount->setAmount($amount->getAmount() * $order->ExchangeRate); $amount->setCurrency($order->Currency); $amount->setSymbol($order->CurrencySymbol); } } else { if ($currency = Session::get('SWS.Currency')) { //Get the exchange rate, alter the amount $rate = ExchangeRate::get()->where("\"Currency\" = '{$currency}'")->limit(1)->first(); if ($rate && $rate->exists()) { $amount->setAmount($amount->getAmount() * $rate->Rate); $amount->setCurrency($rate->Currency); $amount->setSymbol($rate->CurrencySymbol); } } } }
public function __construct() { ExchangeRate::getInstance()->registerObserver($this); }
/** * 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 ExchangeRate the loaded model * @throws CHttpException */ public function loadModel($id) { $model = ExchangeRate::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function actionGetHouseDetail() { $_POST = (array) json_decode(file_get_contents('php://input'), true); $postParms = !empty($_POST['parms']) ? $_POST['parms'] : array(); $id = $postParms['id']; $username = $postParms['username']; error_log("id=" . $id); //$id='W3589143'; $criteria = new CDbCriteria(); //$criteria->addCondition('t.id="'.$id.'"'); $criteria->addCondition('t.ml_num="' . $id . '"'); $criteria->with = array('mname', 'propertyType'); //$house = House::model()->find('id=:id',array(':id'=>$id)); $house = House::model()->find($criteria); //$house = House::model()->find($criteria)->asArray()->all(); //error_log(print_r($house)); $exchangeRate = 0; $exchangeRateList = ExchangeRate::model()->findAll(); if (!empty($exchangeRateList)) { $exchangeRate = $exchangeRateList[0]->rate; } $county = $house->county; $county = preg_replace('/\\s+/', '', $county); $county = str_replace("&", "", $county); //$dir="mlspic/crea/creamid/".$county."/Photo".$house->ml_num."/"; $rdir = $county . "/Photo" . $house->ml_num . "/"; $dir = "mlspic/crea/" . $rdir; $num_files = 0; $photos = array(); if (is_dir($dir)) { $picfiles = scandir($dir); $num_files = count(scandir($dir)) - 2; } if ($num_files > 0) { for ($x = 2; $x <= $num_files + 1; $x++) { $photos[] = $rdir . $picfiles[$x]; } } $isFav = 0; if ($username != 'NO') { if ($this->isValidIdToken()) { //error_log("Token is valid:".$username); $isFav = $this->checkfav($username, $id); } } $data = array('house' => $house->getAttributes(), 'house_mname' => $house->mname->getAttributes(), 'house_propertyType' => $house->propertyType->getAttributes(), 'exchangeRate' => $exchangeRate, 'photos' => $photos, 'isFav' => $isFav); echo json_encode($data); }