|
|
@@ -7,6 +7,7 @@ use App\Module\Transfer\Dtos\TransferOrderDto;
|
|
|
use App\Module\Transfer\Logics\TransferLogic;
|
|
|
use App\Module\Transfer\Models\TransferApp;
|
|
|
use App\Module\Transfer\Models\TransferOrder;
|
|
|
+use App\Module\Transfer\Services\FeeService;
|
|
|
|
|
|
/**
|
|
|
* Transfer模块对外服务接口
|
|
|
@@ -16,14 +17,40 @@ class TransferService
|
|
|
{
|
|
|
/**
|
|
|
* 创建转出订单
|
|
|
- *
|
|
|
- * @param array $data 订单数据
|
|
|
+ *
|
|
|
+ * @param int $transferAppId 划转应用ID
|
|
|
+ * @param int $userId 用户ID
|
|
|
+ * @param string $amount 转出金额
|
|
|
+ * @param string $password 安全密码
|
|
|
+ * @param string|null $googleCode 谷歌验证码
|
|
|
+ * @param string|null $outUserId 外部用户ID
|
|
|
+ * @param string|null $remark 备注
|
|
|
+ * @param array $callbackData 回调数据
|
|
|
* @return TransferOrderDto|string 成功返回DTO,失败返回错误信息
|
|
|
*/
|
|
|
- public static function createTransferOut(array $data): TransferOrderDto|string
|
|
|
- {
|
|
|
+ public static function createTransferOut(
|
|
|
+ int $transferAppId,
|
|
|
+ int $userId,
|
|
|
+ string $amount,
|
|
|
+ string $password,
|
|
|
+ ?string $googleCode = null,
|
|
|
+ ?string $outUserId = null,
|
|
|
+ ?string $remark = null,
|
|
|
+ array $callbackData = []
|
|
|
+ ): TransferOrderDto|string {
|
|
|
try {
|
|
|
- $order = TransferLogic::createTransferOut($data);
|
|
|
+ $data = [
|
|
|
+ 'transfer_app_id' => $transferAppId,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'password' => $password,
|
|
|
+ 'google_code' => $googleCode,
|
|
|
+ 'out_user_id' => $outUserId,
|
|
|
+ 'remark' => $remark,
|
|
|
+ 'callback_data' => $callbackData,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $order = TransferLogic::createTransferOutFromArray($data);
|
|
|
return TransferOrderDto::fromModel($order);
|
|
|
} catch (\Exception $e) {
|
|
|
return $e->getMessage();
|
|
|
@@ -32,14 +59,37 @@ class TransferService
|
|
|
|
|
|
/**
|
|
|
* 创建转入订单
|
|
|
- *
|
|
|
- * @param array $data 订单数据
|
|
|
+ *
|
|
|
+ * @param int $transferAppId 划转应用ID
|
|
|
+ * @param int $userId 用户ID
|
|
|
+ * @param string $businessId 业务订单ID
|
|
|
+ * @param string $amount 转入金额
|
|
|
+ * @param string|null $outUserId 外部用户ID
|
|
|
+ * @param string|null $remark 备注
|
|
|
+ * @param array $callbackData 回调数据
|
|
|
* @return TransferOrderDto|string 成功返回DTO,失败返回错误信息
|
|
|
*/
|
|
|
- public static function createTransferIn(array $data): TransferOrderDto|string
|
|
|
- {
|
|
|
+ public static function createTransferIn(
|
|
|
+ int $transferAppId,
|
|
|
+ int $userId,
|
|
|
+ string $businessId,
|
|
|
+ string $amount,
|
|
|
+ ?string $outUserId = null,
|
|
|
+ ?string $remark = null,
|
|
|
+ array $callbackData = []
|
|
|
+ ): TransferOrderDto|string {
|
|
|
try {
|
|
|
- $order = TransferLogic::createTransferIn($data);
|
|
|
+ $data = [
|
|
|
+ 'transfer_app_id' => $transferAppId,
|
|
|
+ 'user_id' => $userId,
|
|
|
+ 'business_id' => $businessId,
|
|
|
+ 'amount' => $amount,
|
|
|
+ 'out_user_id' => $outUserId,
|
|
|
+ 'remark' => $remark,
|
|
|
+ 'callback_data' => $callbackData,
|
|
|
+ ];
|
|
|
+
|
|
|
+ $order = TransferLogic::createTransferInFromArray($data);
|
|
|
return TransferOrderDto::fromModel($order);
|
|
|
} catch (\Exception $e) {
|
|
|
return $e->getMessage();
|
|
|
@@ -175,7 +225,7 @@ class TransferService
|
|
|
|
|
|
/**
|
|
|
* 处理回调结果
|
|
|
- *
|
|
|
+ *
|
|
|
* @param array $callbackData 回调数据
|
|
|
* @return bool
|
|
|
*/
|
|
|
@@ -191,4 +241,199 @@ class TransferService
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 快速创建转出订单(简化版本,用于测试或内部调用)
|
|
|
+ *
|
|
|
+ * @param int $transferAppId 划转应用ID
|
|
|
+ * @param int $userId 用户ID
|
|
|
+ * @param string $amount 转出金额
|
|
|
+ * @param string $password 安全密码
|
|
|
+ * @return TransferOrderDto|string
|
|
|
+ */
|
|
|
+ public static function quickCreateTransferOut(
|
|
|
+ int $transferAppId,
|
|
|
+ int $userId,
|
|
|
+ string $amount,
|
|
|
+ string $password
|
|
|
+ ): TransferOrderDto|string {
|
|
|
+ return self::createTransferOut(
|
|
|
+ transferAppId: $transferAppId,
|
|
|
+ userId: $userId,
|
|
|
+ amount: $amount,
|
|
|
+ password: $password
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 快速创建转入订单(简化版本,用于测试或内部调用)
|
|
|
+ *
|
|
|
+ * @param int $transferAppId 划转应用ID
|
|
|
+ * @param int $userId 用户ID
|
|
|
+ * @param string $businessId 业务订单ID
|
|
|
+ * @param string $amount 转入金额
|
|
|
+ * @return TransferOrderDto|string
|
|
|
+ */
|
|
|
+ public static function quickCreateTransferIn(
|
|
|
+ int $transferAppId,
|
|
|
+ int $userId,
|
|
|
+ string $businessId,
|
|
|
+ string $amount
|
|
|
+ ): TransferOrderDto|string {
|
|
|
+ return self::createTransferIn(
|
|
|
+ transferAppId: $transferAppId,
|
|
|
+ userId: $userId,
|
|
|
+ businessId: $businessId,
|
|
|
+ amount: $amount
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从数组创建转出订单(向后兼容方法)
|
|
|
+ *
|
|
|
+ * @param array $data 订单数据
|
|
|
+ * @return TransferOrderDto|string
|
|
|
+ * @deprecated 建议使用 createTransferOut() 方法
|
|
|
+ */
|
|
|
+ public static function createTransferOutFromArray(array $data): TransferOrderDto|string
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $order = TransferLogic::createTransferOutFromArray($data);
|
|
|
+ return TransferOrderDto::fromModel($order);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $e->getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 从数组创建转入订单(向后兼容方法)
|
|
|
+ *
|
|
|
+ * @param array $data 订单数据
|
|
|
+ * @return TransferOrderDto|string
|
|
|
+ * @deprecated 建议使用 createTransferIn() 方法
|
|
|
+ */
|
|
|
+ public static function createTransferInFromArray(array $data): TransferOrderDto|string
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $order = TransferLogic::createTransferInFromArray($data);
|
|
|
+ return TransferOrderDto::fromModel($order);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return $e->getMessage();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算转入手续费
|
|
|
+ *
|
|
|
+ * @param int $transferAppId 划转应用ID
|
|
|
+ * @param string $amount 转入金额
|
|
|
+ * @return array ['fee_rate' => 手续费率, 'fee_amount' => 手续费金额, 'actual_amount' => 实际到账金额]
|
|
|
+ */
|
|
|
+ public static function calculateInFee(int $transferAppId, string $amount): array
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $app = TransferApp::findOrFail($transferAppId);
|
|
|
+ return FeeService::calculateInFee($app, $amount);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return [
|
|
|
+ 'fee_rate' => 0.0000,
|
|
|
+ 'fee_amount' => '0.0000',
|
|
|
+ 'actual_amount' => $amount,
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 计算转出手续费
|
|
|
+ *
|
|
|
+ * @param int $transferAppId 划转应用ID
|
|
|
+ * @param string $amount 转出金额
|
|
|
+ * @return array ['fee_rate' => 手续费率, 'fee_amount' => 手续费金额, 'actual_amount' => 实际到账金额]
|
|
|
+ */
|
|
|
+ public static function calculateOutFee(int $transferAppId, string $amount): array
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $app = TransferApp::findOrFail($transferAppId);
|
|
|
+ return FeeService::calculateOutFee($app, $amount);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return [
|
|
|
+ 'fee_rate' => 0.0000,
|
|
|
+ 'fee_amount' => '0.0000',
|
|
|
+ 'actual_amount' => $amount,
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取应用的手续费配置
|
|
|
+ *
|
|
|
+ * @param int $transferAppId 划转应用ID
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function getFeeConfig(int $transferAppId): array
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ $app = TransferApp::findOrFail($transferAppId);
|
|
|
+ return FeeService::getFeeConfig($app);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return [
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'in' => ['rate' => 0, 'min' => 0, 'max' => 0, 'enabled' => false],
|
|
|
+ 'out' => ['rate' => 0, 'min' => 0, 'max' => 0, 'enabled' => false],
|
|
|
+ 'account_uid' => 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取手续费统计信息
|
|
|
+ *
|
|
|
+ * @param int $appId 应用ID(0表示所有应用)
|
|
|
+ * @param string $startDate 开始日期
|
|
|
+ * @param string $endDate 结束日期
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function getFeeStatistics(int $appId = 0, string $startDate = '', string $endDate = ''): array
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ return FeeService::getFeeStatistics($appId, $startDate, $endDate);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return [
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'total_orders' => 0,
|
|
|
+ 'total_fee' => 0,
|
|
|
+ 'avg_fee_rate' => 0,
|
|
|
+ 'in_orders' => 0,
|
|
|
+ 'in_fee' => 0,
|
|
|
+ 'out_orders' => 0,
|
|
|
+ 'out_fee' => 0,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取应用的手续费收入统计
|
|
|
+ *
|
|
|
+ * @param int $appId 应用ID
|
|
|
+ * @param int $days 统计天数
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public static function getAppFeeIncome(int $appId, int $days = 30): array
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ return FeeService::getAppFeeIncome($appId, $days);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return [
|
|
|
+ 'error' => $e->getMessage(),
|
|
|
+ 'app_id' => $appId,
|
|
|
+ 'days' => $days,
|
|
|
+ 'total_fee' => 0,
|
|
|
+ 'total_orders' => 0,
|
|
|
+ 'avg_daily_fee' => 0,
|
|
|
+ 'daily_stats' => [],
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|