您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CurrencyAccessor.php 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace App\Utilities\Currency;
  3. use Akaunting\Money\Currency as ISOCurrencies;
  4. use App\Facades\Forex;
  5. use App\Models\Setting\Currency;
  6. use Illuminate\Support\Facades\Cache;
  7. class CurrencyAccessor
  8. {
  9. public static function getForexSupportedCurrencies(): ?array
  10. {
  11. return Forex::getSupportedCurrencies();
  12. }
  13. public static function getSupportedCurrencies(): array
  14. {
  15. $forexSupportedCurrencies = self::getForexSupportedCurrencies();
  16. $allCurrencies = self::getAllCurrencies();
  17. if (empty($forexSupportedCurrencies)) {
  18. return array_keys($allCurrencies);
  19. }
  20. return array_intersect($forexSupportedCurrencies, array_keys($allCurrencies));
  21. }
  22. public static function getAllCurrencies(): array
  23. {
  24. return ISOCurrencies::getCurrencies();
  25. }
  26. public static function getAllCurrencyOptions(): array
  27. {
  28. $allCurrencies = self::getSupportedCurrencies();
  29. return array_combine($allCurrencies, $allCurrencies);
  30. }
  31. public static function getAvailableCurrencies(): array
  32. {
  33. $supportedCurrencies = self::getSupportedCurrencies();
  34. $storedCurrencies = Currency::query()
  35. ->pluck('code')
  36. ->toArray();
  37. $availableCurrencies = array_diff($supportedCurrencies, $storedCurrencies);
  38. return array_combine($availableCurrencies, $availableCurrencies);
  39. }
  40. public static function getDefaultCurrency(): ?string
  41. {
  42. $companyId = auth()->user()->currentCompany->id;
  43. $cacheKey = "default_currency_{$companyId}";
  44. return Cache::rememberForever($cacheKey, function () {
  45. return Currency::query()
  46. ->where('enabled', true)
  47. ->value('code');
  48. });
  49. }
  50. }