Parcourir la source

refactor(transfer): 重构转账逻辑中的手续费计算

- 将 calculateOutFee 方法从 TransferApp模型移至 FeeService 类- 更新 TransferLogic 中的手续费计算调用
- 修改手续费计算结果的属性名称
- 在 TransferApp 中将 calculateOutFee 方法标记为 deprecated
notfff il y a 6 mois
Parent
commit
e254cc0d13

+ 6 - 4
app/Module/Transfer/Logics/TransferLogic.php

@@ -296,7 +296,8 @@ class TransferLogic
         }
 
         // 计算手续费
-        $feeInfo = $app->calculateOutFee($amount, [ 'user_id' => $data['user_id'] ]);
+
+        $feeInfo = FeeService::calculateOutFee($app, $amount, [ 'user_id' => $data['user_id'] ]);
 
         // 生成外部订单ID
         $outOrderId = self::generateOutOrderId('OUT');
@@ -315,9 +316,10 @@ class TransferLogic
                                            'out_amount'      => $outAmount,
                                            'amount'          => $amount,
                                            'exchange_rate'   => $app->exchange_rate,
-                                           'fee_rate'        => $feeInfo['fee_rate'],
-                                           'fee_amount'      => $feeInfo['fee_amount'],
-                                           'actual_amount'   => $feeInfo['actual_amount'],
+                                           'fee_rate'        => $feeInfo->feeRate,
+                                           'fee_amount'      => $feeInfo->feeAmount,
+                                           'actual_amount'   => $feeInfo->actualAmount,
+                                           'totle_amount'    => $feeInfo->totleAmount,
                                            'callback_data'   => $data['callback_data'] ?? [],
                                            'remark'          => $data['remark'] ?? null,
                                        ]);

+ 11 - 4
app/Module/Transfer/Models/TransferApp.php

@@ -9,7 +9,7 @@ use UCore\ModelCore;
 /**
  * 划转应用配置模型
  *
- * field start 
+ * field start
  * @property  int  $id  主键ID
  * @property  string  $keyname  应用标识符
  * @property  string  $title  应用显示名称
@@ -47,7 +47,7 @@ class TransferApp extends ModelCore
      */
     protected $table = 'transfer_apps';
 
-    // attrlist start 
+    // attrlist start
     protected $fillable = [
         'id',
         'keyname',
@@ -245,8 +245,15 @@ class TransferApp extends ModelCore
     }
 
 
-
-
+    /**
+     * @param string $amount
+     * @return array
+     * @deprecated
+     */
+    public function calculateOutFee(string $amount): array
+    {
+        return $this->calculateFee($amount, $this->fee_in_rate, $this->fee_in_min, $this->fee_in_max);
+    }
 
 
     /**