本文整理汇总了PHP中app\models\Currency类的典型用法代码示例。如果您正苦于以下问题:PHP Currency类的具体用法?PHP Currency怎么用?PHP Currency使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Currency类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: globalData
/**
* Prepare global variables.
* @return array
*/
public static function globalData()
{
if (!Auth::check()) {
$rows = null;
$cart = null;
$grandTotal = null;
} else {
$rows = Cart::instance(auth()->id())->count(false);
$cart = Cart::instance(auth()->id())->content();
$grandTotal = Cart::instance(auth()->id())->total();
}
$data = array('menu' => self::getMenuData(self::$parent_id), 'header' => Setting::findOrFail(1), 'rows' => $rows, 'cart' => $cart, 'grand_total' => $grandTotal, 'currencies' => Currency::all());
return $data;
}
示例2: fakeCurrency
protected function fakeCurrency()
{
$fakeCurrency = new Currency();
$fakeCurrency->currency_code = "USD";
$fakeCurrency->currency_name = "Dollar";
$fakeCurrency->save();
return $fakeCurrency;
}
示例3: __construct
public function __construct(Currency $currencyModel, Note $noteModel)
{
$notes = $noteModel->getLastNote();
if (count($notes) < 1) {
$notes = false;
}
//GLOBAL SETTINGS
$this->_glob = array('_note' => $notes, '_curr' => $currencyModel->getRate(), '_baseCurrency' => 'RUB', '_precision' => 2, '_countProductsOfPage' => Auth::User() ? Auth::User()->count_products : 100, '_maxCountProductsOfPage' => 500, '_alerts' => AbsentController::shortView());
View::share('_glob', $this->_glob);
}
示例4: initCurrenciesToDb
private function initCurrenciesToDb()
{
for ($day = 3000; $day > 0; $day--) {
$currency = new Currency();
$date = date('Y-m-d', strtotime('-' . $day . ' day'));
$currency->date = $date;
$currency->usd = $this->getCurrencyForDate($date);
$currency->save();
echo $day . PHP_EOL;
}
}
示例5: actionGetCurrencies
public function actionGetCurrencies()
{
$billing_id = Yii::$app->request->post('billing_id');
$currencies = ArrayHelper::map(Currency::find()->where("billing_id = :billing_id", [':billing_id' => $billing_id])->with('billing')->asArray()->all(), 'id', 'name');
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
return $currencies;
}
示例6: show
/**
* Change the currency.
*
* @return Redirect
*/
public function show(Request $request, string $currency)
{
$request->session()->put('currency', $currency);
$currency = Currency::where('currency', $currency)->first()->toArray();
$request->session()->put('currency_rate', $currency['rate']);
// we need to update the basket
$basket = $request->session()->get('basket');
foreach ($basket['items'] as $id => $item) {
if (isset($item['parent_sku'])) {
// its an option
$product = Product::where('sku', $item['parent_sku'])->first();
$price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
foreach ($product->option_values as $option) {
if ($option['sku'] == $id) {
$price = number_format($option['price'] * $request->session()->get('currency_rate'), 2, '.', '');
}
}
} else {
$product = Product::find($id);
$price = isset($product->salePrice) && !empty($product->salePrice) ? $product->salePrice : $product->price;
}
$basket['items'][$id]['price'] = $price;
}
$request->session()->put('basket', $basket);
return redirect()->back();
}
示例7: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
DB::table('course')->delete();
Model::unguard();
$faker = Faker\Factory::create();
$currencies = Currency::all()->toArray();
DB::table('course')->insert([['currency_id' => $currencies[0]['id'], 'course_purchase' => 5.4, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[1]['id'], 'course_purchase' => 5.0, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[2]['id'], 'course_purchase' => 1.03, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[3]['id'], 'course_purchase' => 1.7, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[4]['id'], 'course_purchase' => 1.7, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[5]['id'], 'course_purchase' => 1.0, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[6]['id'], 'course_purchase' => 0.1, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[7]['id'], 'course_purchase' => 0.3, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[8]['id'], 'course_purchase' => 0.1, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[9]['id'], 'course_purchase' => 0.00014, 'wallet' => $faker->creditCardNumber], ['currency_id' => $currencies[10]['id'], 'course_purchase' => 0.0, 'wallet' => $faker->creditCardNumber]]);
Model::reguard();
}
示例8: exchangeRates
public function exchangeRates()
{
$currency = new Currency();
$url = 'https://api.privatbank.ua/p24api/pubinfo?exchange&coursid=3';
$xml = new SimpleXMLElement($url, NULL, true);
$eur = (array) $xml->row[0]->exchangerate['sale'];
$rur = (array) $xml->row[1]->exchangerate['sale'];
$usd = (array) $xml->row[2]->exchangerate['sale'];
$currency->uan = 1;
$currency->eur = $eur[0];
$currency->rur = $rur[0];
$currency->usd = $usd[0];
$currency->date = 86400 * ceil(time() / 86400);
if ($currency->save()) {
return false;
}
return true;
}
示例9: getActiveCurrency
public static function getActiveCurrency($chCode = false)
{
$attr = 'name';
$query = Currency::find()->andWhere(['active' => true])->all();
if ($chCode) {
$attr = 'chCode';
}
return ArrayHelper::map($query, 'id', $attr);
}
示例10: actionUpdate
/**
* Updates an existing Rate model.
* If update is successful, the browser will be redirected to the 'view' page.
* @param integer $id
* @return mixed
*/
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
$currency_list = Currency::getCurrencyList();
return $this->render('update', ['model' => $model, 'currency' => $currency_list]);
}
}
示例11: currency
/**
*
* Helper Currency Class
*
* @package ecommerce-cms
* @category Helper Class
* @author Tihomir Blazhev <raylight75@gmail.com>
* @link https://raylight75@bitbucket.org/raylight75/ecommerce-cms.git
*/
public static function currency($input)
{
$var = session('currency');
if (isset($var)) {
$currency = Currency::where('name', '=', $var)->first();
$rate = $currency->rate;
} else {
$rate = 1;
}
$total = (double) $input * (double) $rate;
return number_format((double) $total, 2);
}
示例12: actionCreate
/**
* Creates a new Account model.
* If creation is successful, the browser will be redirected to the 'index' page.
* @return mixed
*/
public function actionCreate()
{
$model = new Account();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
Yii::$app->session->setFlash("Account-success", Yii::t("app", "Account successfully created"));
return $this->redirect(['index']);
} else {
$currencyItems = Currency::find()->select(['id', 'name'])->where(['user_id' => Yii::$app->user->id])->asArray()->all();
$currencyItems = ArrayHelper::map($currencyItems, 'id', 'name');
return $this->render('create', ['model' => $model, 'currencyItems' => $currencyItems]);
}
}
示例13: postSetActive
public function postSetActive()
{
$id = Input::get('id');
Currency::where('active', 1)->update(['active' => 0]);
$currency = Currency::find($id);
if ($currency) {
$currency->active = 1;
$currency->save();
return Redirect::back()->with('message', "Курс валюты '{$currency->title}' обновлён");
}
return Redirect::back()->with('message', 'Ошибка обновления');
}
示例14: price
public function price()
{
$active_currency = Currency::active();
$price = $this->price * $active_currency->rate_ue * $active_currency->rate_rub;
if ($this->is_default_discount > 0) {
$default_discount_sum = $price / 100 * $this->default_discount;
$price -= $default_discount_sum;
}
if (Auth::check()) {
$price -= $this->personal_discount($price);
}
return $price;
}
示例15: search
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params)
{
$query = Currency::find();
$dataProvider = new ActiveDataProvider(['query' => $query]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
$query->andFilterWhere(['id' => $this->id]);
$query->andFilterWhere(['like', 'iso', $this->iso])->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}