|
|
@@ -9,16 +9,17 @@ FeeService 新增了 `transfer` 方法,用于将手续费从指定应用的手
|
|
|
```php
|
|
|
/**
|
|
|
* 转移手续费到指定用户
|
|
|
- *
|
|
|
+ *
|
|
|
* 将手续费从指定应用的手续费账户转移到目标用户账户
|
|
|
*
|
|
|
* @param int $appId 出钱的应用ID(从该应用的手续费账户扣除)
|
|
|
* @param int $targetUserId 目标用户ID(收钱的)
|
|
|
* @param float $amount 金额(钱数)
|
|
|
* @param int $orderId 订单ID(划转依据)
|
|
|
+ * @param string $transferType 转移类型(默认为'fee_transfer')
|
|
|
* @return bool|string 成功返回true,失败返回错误信息
|
|
|
*/
|
|
|
-public static function transfer(int $appId, int $targetUserId, float $amount, int $orderId)
|
|
|
+public static function transfer(int $appId, int $targetUserId, float $amount, int $orderId, string $transferType = 'fee_transfer')
|
|
|
```
|
|
|
|
|
|
## 参数说明
|
|
|
@@ -27,6 +28,7 @@ public static function transfer(int $appId, int $targetUserId, float $amount, in
|
|
|
- **$targetUserId**: 目标用户ID,接收转移资金的用户
|
|
|
- **$amount**: 转移金额,必须大于0
|
|
|
- **$orderId**: 订单ID,作为转移的依据和日志记录
|
|
|
+- **$transferType**: 转移类型,用于标识转移的业务类型(默认为'fee_transfer')
|
|
|
|
|
|
## 使用示例
|
|
|
|
|
|
@@ -35,7 +37,7 @@ public static function transfer(int $appId, int $targetUserId, float $amount, in
|
|
|
```php
|
|
|
use App\Module\Transfer\Services\FeeService;
|
|
|
|
|
|
-// 从应用ID为1的手续费账户转移10元到用户ID为123的账户
|
|
|
+// 从应用ID为1的手续费账户转移10元到用户ID为123的账户(使用默认转移类型)
|
|
|
$result = FeeService::transfer(
|
|
|
appId: 1,
|
|
|
targetUserId: 123,
|
|
|
@@ -48,6 +50,15 @@ if ($result === true) {
|
|
|
} else {
|
|
|
echo "转移失败: " . $result;
|
|
|
}
|
|
|
+
|
|
|
+// 使用自定义转移类型
|
|
|
+$result = FeeService::transfer(
|
|
|
+ appId: 1,
|
|
|
+ targetUserId: 123,
|
|
|
+ amount: 10.0,
|
|
|
+ orderId: 12345,
|
|
|
+ transferType: 'refund'
|
|
|
+);
|
|
|
```
|
|
|
|
|
|
### 2. 在业务流程中使用
|
|
|
@@ -69,7 +80,8 @@ $result = FeeService::transfer(
|
|
|
appId: $app->id,
|
|
|
targetUserId: $order->user_id,
|
|
|
amount: $refundAmount,
|
|
|
- orderId: $order->id
|
|
|
+ orderId: $order->id,
|
|
|
+ transferType: 'fee_refund'
|
|
|
);
|
|
|
|
|
|
if ($result === true) {
|
|
|
@@ -94,9 +106,9 @@ if ($result === true) {
|
|
|
use App\Module\Transfer\Services\FeeService;
|
|
|
|
|
|
$transfers = [
|
|
|
- ['app_id' => 1, 'user_id' => 123, 'amount' => 10.0, 'order_id' => 1001],
|
|
|
- ['app_id' => 1, 'user_id' => 124, 'amount' => 15.0, 'order_id' => 1002],
|
|
|
- ['app_id' => 2, 'user_id' => 125, 'amount' => 8.0, 'order_id' => 1003],
|
|
|
+ ['app_id' => 1, 'user_id' => 123, 'amount' => 10.0, 'order_id' => 1001, 'type' => 'fee_refund'],
|
|
|
+ ['app_id' => 1, 'user_id' => 124, 'amount' => 15.0, 'order_id' => 1002, 'type' => 'bonus'],
|
|
|
+ ['app_id' => 2, 'user_id' => 125, 'amount' => 8.0, 'order_id' => 1003, 'type' => 'compensation'],
|
|
|
];
|
|
|
|
|
|
$results = [];
|
|
|
@@ -105,7 +117,8 @@ foreach ($transfers as $transfer) {
|
|
|
appId: $transfer['app_id'],
|
|
|
targetUserId: $transfer['user_id'],
|
|
|
amount: $transfer['amount'],
|
|
|
- orderId: $transfer['order_id']
|
|
|
+ orderId: $transfer['order_id'],
|
|
|
+ transferType: $transfer['type']
|
|
|
);
|
|
|
|
|
|
$results[] = [
|