Add 币种获取失败容错

This commit is contained in:
BrettonYe
2023-03-13 23:52:12 +08:00
parent a2d37b0ae9
commit 671743cf83
2 changed files with 10 additions and 6 deletions

View File

@@ -269,7 +269,10 @@ class Helpers
$standard = sysConfig('standard_currency', 'CNY');
$currencyLib = array_column(config('common.currency'), 'symbol', 'code');
if (! empty($currentCurrency) && isset($currencyLib[$currentCurrency]) && $currentCurrency !== $standard) {
return $currencyLib[$currentCurrency].CurrencyExchange::convert($currentCurrency, $amount);
$convert = CurrencyExchange::convert($currentCurrency, $amount);
if ($convert !== false) {
return $currencyLib[$currentCurrency].$convert;
}
}
return $currencyLib[$standard].$amount;
@@ -278,10 +281,7 @@ class Helpers
private static function getRandPort(): int
{ // 获取一个随机端口
$port = random_int(sysConfig('min_port'), sysConfig('max_port'));
$exists_port = array_merge(
User::where('port', '<>', 0)->pluck('port')->toArray(),
self::$denyPorts
);
$exists_port = array_merge(User::where('port', '<>', 0)->pluck('port')->toArray(), self::$denyPorts);
while (in_array($port, $exists_port, true)) {
$port = random_int(sysConfig('min_port'), sysConfig('max_port'));

View File

@@ -113,7 +113,11 @@ class PayPal extends Gateway
protected function getCheckoutData($trade_no, $amount): array
{
$amount = 0.3 + CurrencyExchange::convert('USD', $amount);
$converted = CurrencyExchange::convert('USD', $amount);
if ($converted === false) {
$converted = $amount / 7;
}
$amount = 0.3 + $converted;
return [
'invoice_id' => $trade_no,