优化 currency 读取
This commit is contained in:
parent
edb860774d
commit
a45406aec2
|
|
@ -401,7 +401,7 @@ function language_packages(): array
|
|||
*/
|
||||
function currencies()
|
||||
{
|
||||
return CurrencyRepo::all()->where('status', true);
|
||||
return CurrencyRepo::listEnabled();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -11,15 +11,16 @@
|
|||
|
||||
namespace Beike\Repositories;
|
||||
|
||||
use Beike\Models\Country;
|
||||
use Beike\Models\Currency;
|
||||
|
||||
class CurrencyRepo
|
||||
{
|
||||
private static $enabledCurrencies;
|
||||
|
||||
/**
|
||||
* 创建一个currency记录
|
||||
* @param $data
|
||||
* @return int
|
||||
* @return mixed
|
||||
*/
|
||||
public static function create($data)
|
||||
{
|
||||
|
|
@ -29,7 +30,8 @@ class CurrencyRepo
|
|||
/**
|
||||
* @param $id
|
||||
* @param $data
|
||||
* @return bool|int
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function update($id, $data)
|
||||
{
|
||||
|
|
@ -43,7 +45,7 @@ class CurrencyRepo
|
|||
|
||||
/**
|
||||
* @param $id
|
||||
* @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
|
||||
* @return mixed
|
||||
*/
|
||||
public static function find($id)
|
||||
{
|
||||
|
|
@ -67,9 +69,11 @@ class CurrencyRepo
|
|||
return Currency::query()->get();
|
||||
}
|
||||
|
||||
public static function enabled()
|
||||
public static function listEnabled()
|
||||
{
|
||||
return Currency::query()->where('status', true)->get();
|
||||
if (self::$enabledCurrencies !== null) {
|
||||
return self::$enabledCurrencies;
|
||||
}
|
||||
return self::$enabledCurrencies = Currency::query()->where('status', true)->get();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,4 @@
|
|||
<?php
|
||||
/*
|
||||
* @copyright 2022 opencart.cn - All Rights Reserved.
|
||||
* @link https://www.guangdawangluo.com
|
||||
* @Author Pu Shuo <pushuo@opencart.cn>
|
||||
* @Date 2022-08-02 19:19:52
|
||||
* @LastEditTime 2022-08-06 12:52:21
|
||||
*/
|
||||
|
||||
/**
|
||||
* CurrencyService.php
|
||||
*
|
||||
|
|
@ -19,9 +11,6 @@
|
|||
|
||||
namespace Beike\Services;
|
||||
|
||||
use Beike\Models\Address;
|
||||
use Beike\Models\TaxRate;
|
||||
use Beike\Models\TaxRule;
|
||||
use Beike\Repositories\CurrencyRepo;
|
||||
|
||||
class CurrencyService
|
||||
|
|
@ -30,7 +19,7 @@ class CurrencyService
|
|||
private $currencies = array();
|
||||
|
||||
public function __construct() {
|
||||
foreach (CurrencyRepo::enabled() as $result) {
|
||||
foreach (CurrencyRepo::listEnabled() as $result) {
|
||||
$this->currencies[$result->code] = $result;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue