Quellcode durchsuchen

refactor(fund): 优化币种检查和金额精度验证逻辑

notfff vor 7 Monaten
Ursprung
Commit
a9c25cc0d8

+ 3 - 3
app/Module/Fund/Services/CurrencyService.php

@@ -35,8 +35,8 @@ class CurrencyService
     static public function check($fund_id, $fund_id2): bool
     {
         // 获取两个账户种类对应的币种
-        $currency1 = self::getCurrencyByFundId($fund_id);
-        $currency2 = self::getCurrencyByFundId($fund_id2);
+        $currency1 = self::getCurrency2ByFundId($fund_id);
+        $currency2 = self::getCurrency2ByFundId($fund_id2);
 
         // 如果任一币种信息获取失败,返回false
         if (!$currency1 || !$currency2) {
@@ -44,7 +44,7 @@ class CurrencyService
         }
 
         // 检查两个币种ID是否一致(使用币种枚举值,不是数据库表ID)
-        return $currency1->currencyId === $currency2->currencyId;
+        return $currency1 === $currency2;
     }
 
     /**

+ 3 - 3
app/Module/Fund/Services/FundService.php

@@ -226,16 +226,16 @@ class FundService
     public function trade(int $toUserId, float $amount, $transfer_type, $transfer_id, string $remark)
     {
         # 验证金额精度
-        $currency = CurrencyService::getCurrencyByFundId($this->fundId);
+        $currency = CurrencyService::getCurrency2ByFundId($this->fundId);
         if (!$currency) {
             return '无法获取币种信息';
         }
 
         # 验证并格式化金额精度
-        if (!CurrencyService::validateAmountPrecision($amount, $currency->currencyId)) {
+        if (!CurrencyService::validateAmountPrecision($amount, $currency->value)) {
             return '金额精度超出币种支持范围';
         }
-        $formattedAmount = CurrencyService::formatAmountToPrecision($amount, $currency->currencyId);
+        $formattedAmount = CurrencyService::formatAmountToPrecision($amount, $currency->value);
 
         # 检查事务开启
         Helper::check_tr();