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

CurrencyAccessor.php 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. class CurrencyAccessor
  7. {
  8. public static function getForexSupportedCurrencies(): ?array
  9. {
  10. return Forex::getSupportedCurrencies();
  11. }
  12. public static function getSupportedCurrencies(): array
  13. {
  14. $forexSupportedCurrencies = self::getForexSupportedCurrencies();
  15. $allCurrencies = self::getAllCurrencies();
  16. if (empty($forexSupportedCurrencies)) {
  17. return array_keys($allCurrencies);
  18. }
  19. return array_intersect($forexSupportedCurrencies, array_keys($allCurrencies));
  20. }
  21. public static function getAllCurrencies(): array
  22. {
  23. return ISOCurrencies::getCurrencies();
  24. }
  25. public static function getAllCurrencyOptions(): array
  26. {
  27. $allCurrencies = self::getSupportedCurrencies();
  28. return array_combine($allCurrencies, $allCurrencies);
  29. }
  30. public static function getAvailableCurrencies(): array
  31. {
  32. $supportedCurrencies = self::getSupportedCurrencies();
  33. $storedCurrencies = Currency::query()
  34. ->pluck('code')
  35. ->toArray();
  36. $availableCurrencies = array_diff($supportedCurrencies, $storedCurrencies);
  37. return array_combine($availableCurrencies, $availableCurrencies);
  38. }
  39. public static function getDefaultCurrency(): ?string
  40. {
  41. return Currency::query()
  42. ->where('enabled', true)
  43. ->value('code');
  44. }
  45. }