修复订单汇率问题

This commit is contained in:
Edward Yang 2022-08-29 17:30:10 +08:00
parent 8f72766115
commit 4b0f31ad52
2 changed files with 30 additions and 2 deletions

View File

@ -12,6 +12,8 @@
namespace Beike\Repositories;
use Beike\Models\Currency;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
class CurrencyRepo
{
@ -64,11 +66,23 @@ class CurrencyRepo
}
}
/**
* 获取所有货币列表
*
* @return Builder[]|Collection
*/
public static function all()
{
return Currency::query()->get();
}
/**
* 查找所有已开启货币
*
* @return Builder[]|Collection
*/
public static function listEnabled()
{
if (self::$enabledCurrencies !== null) {
@ -76,4 +90,14 @@ class CurrencyRepo
}
return self::$enabledCurrencies = Currency::query()->where('status', true)->get();
}
/**
* 根据code查找货币
* @return Builder[]|Collection
*/
public static function findByCode($code)
{
return self::listEnabled()->where('code', $code)->firstOrFail();
}
}

View File

@ -184,6 +184,10 @@ class OrderRepo
$shippingMethodCode = $current['shipping_method_code'] ?? '';
$paymentMethodCode = $current['payment_method_code'] ?? '';
$currencyCode = current_currency_code();
$currency = CurrencyRepo::findByCode($currencyCode);
$currencyValue = $currency->value ?? 1;
$order = new Order([
'number' => self::generateOrderNumber(),
'customer_id' => $customer->id,
@ -196,8 +200,8 @@ class OrderRepo
'telephone' => $customer->telephone ?? '',
'total' => $orderTotal['amount'],
'locale' => locale(),
'currency_code' => current_currency_code(),
'currency_value' => 1,
'currency_code' => $currencyCode,
'currency_value' => $currencyValue,
'ip' => request()->getClientIp(),
'user_agent' => request()->userAgent(),
'status' => StateMachineService::CREATED,