|
|
@@ -11,7 +11,9 @@ use App\Module\Mex\Enums\OrderStatus;
|
|
|
use App\Module\Mex\Enums\TransactionType;
|
|
|
use App\Module\Fund\Services\FundService;
|
|
|
use App\Module\Fund\Enums\FUND_TYPE;
|
|
|
+use App\Module\Fund\Enums\FUND_CURRENCY_TYPE;
|
|
|
use App\Module\GameItems\Services\ItemService;
|
|
|
+use App\Module\Mex\Logic\FundLogic;
|
|
|
use App\Module\GameItems\Enums\FREEZE_REASON_TYPE;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
@@ -397,7 +399,7 @@ class MexMatchLogic
|
|
|
|
|
|
// 执行账户流转逻辑
|
|
|
// 1. 用户冻结资金转入仓库账户
|
|
|
- $fundResult = self::transferFrozenFundsToWarehouse($order->user_id, $totalAmount, $order->id);
|
|
|
+ $fundResult = self::transferFrozenFundsToWarehouse($order->user_id, $totalAmount, $order->id, $order->currency_type);
|
|
|
if (!$fundResult['success']) {
|
|
|
throw new \Exception('资金流转失败:' . $fundResult['message']);
|
|
|
}
|
|
|
@@ -474,6 +476,7 @@ class MexMatchLogic
|
|
|
'buyer_id' => self::WAREHOUSE_USER_ID, // 仓库账户作为买方
|
|
|
'seller_id' => $order->user_id,
|
|
|
'item_id' => $order->item_id,
|
|
|
+ 'currency_type' => $order->currency_type->value,
|
|
|
'quantity' => $order->quantity,
|
|
|
'price' => $order->price,
|
|
|
'total_amount' => $totalAmount,
|
|
|
@@ -489,7 +492,7 @@ class MexMatchLogic
|
|
|
}
|
|
|
|
|
|
// 2. 仓库账户资金转出到用户账户
|
|
|
- $fundResult = self::transferFundsFromWarehouseToUser($order->user_id, $totalAmount, $order->id);
|
|
|
+ $fundResult = self::transferFundsFromWarehouseToUser($order->user_id, $totalAmount, $order->id, $order->currency_type);
|
|
|
if (!$fundResult['success']) {
|
|
|
throw new \Exception('资金流转失败:' . $fundResult['message']);
|
|
|
}
|
|
|
@@ -739,19 +742,32 @@ class MexMatchLogic
|
|
|
* @param int $userId 用户ID
|
|
|
* @param string $amount 金额
|
|
|
* @param int $orderId 订单ID
|
|
|
+ * @param FUND_CURRENCY_TYPE|null $currencyType 币种类型,默认使用钻石
|
|
|
* @return array 转移结果
|
|
|
*/
|
|
|
- private static function transferFrozenFundsToWarehouse(int $userId, string $amount, int $orderId): array
|
|
|
+ private static function transferFrozenFundsToWarehouse(int $userId, string $amount, int $orderId, ?FUND_CURRENCY_TYPE $currencyType = null): array
|
|
|
{
|
|
|
try {
|
|
|
- // TODO: 这里需要根据实际的资金类型进行调整
|
|
|
- // 假设使用钻石币种(FUND_TYPE::FUND2)和冻结账户(FUND_TYPE::FUND3)
|
|
|
+ // 获取币种类型,默认使用钻石
|
|
|
+ $currencyType = $currencyType ?? FundLogic::getDefaultCurrency();
|
|
|
+
|
|
|
+ // 获取对应的冻结账户类型
|
|
|
+ $frozenAccountType = FundLogic::getFrozenAccountType($currencyType);
|
|
|
+ if (!$frozenAccountType) {
|
|
|
+ return [
|
|
|
+ 'success' => false,
|
|
|
+ 'message' => '不支持的币种类型',
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
// 从用户冻结账户转移到仓库账户
|
|
|
- $fundService = new FundService($userId, FUND_TYPE::FUND3->value); // 冻结账户
|
|
|
+ $fundService = new FundService($userId, $frozenAccountType->value);
|
|
|
+ $precision = $currencyType->getPrecision();
|
|
|
+ $fundAmount = (int)bcmul($amount, bcpow('10', $precision), 0); // 根据币种精度转换
|
|
|
+
|
|
|
$result = $fundService->trade(
|
|
|
self::WAREHOUSE_USER_ID,
|
|
|
- (int)bcmul($amount, '100', 0), // 转换为整数存储
|
|
|
+ $fundAmount,
|
|
|
'MEX_ORDER',
|
|
|
$orderId,
|
|
|
'用户买入物品撮合-资金转移'
|
|
|
@@ -865,19 +881,32 @@ class MexMatchLogic
|
|
|
* @param int $userId 用户ID
|
|
|
* @param string $amount 金额
|
|
|
* @param int $orderId 订单ID
|
|
|
+ * @param FUND_CURRENCY_TYPE|null $currencyType 币种类型,默认使用钻石
|
|
|
* @return array 转移结果
|
|
|
*/
|
|
|
- private static function transferFundsFromWarehouseToUser(int $userId, string $amount, int $orderId): array
|
|
|
+ private static function transferFundsFromWarehouseToUser(int $userId, string $amount, int $orderId, ?FUND_CURRENCY_TYPE $currencyType = null): array
|
|
|
{
|
|
|
try {
|
|
|
- // TODO: 这里需要根据实际的资金类型进行调整
|
|
|
- // 假设使用钻石币种(FUND_TYPE::FUND2)
|
|
|
+ // 获取币种类型,默认使用钻石
|
|
|
+ $currencyType = $currencyType ?? FundLogic::getDefaultCurrency();
|
|
|
+
|
|
|
+ // 获取对应的可用账户类型
|
|
|
+ $availableAccountType = FundLogic::getAvailableAccountType($currencyType);
|
|
|
+ if (!$availableAccountType) {
|
|
|
+ return [
|
|
|
+ 'success' => false,
|
|
|
+ 'message' => '不支持的币种类型',
|
|
|
+ ];
|
|
|
+ }
|
|
|
|
|
|
// 从仓库账户转移到用户账户
|
|
|
- $fundService = new FundService(self::WAREHOUSE_USER_ID, FUND_TYPE::FUND2->value); // 仓库账户
|
|
|
+ $fundService = new FundService(self::WAREHOUSE_USER_ID, $availableAccountType->value);
|
|
|
+ $precision = $currencyType->getPrecision();
|
|
|
+ $fundAmount = (int)bcmul($amount, bcpow('10', $precision), 0); // 根据币种精度转换
|
|
|
+
|
|
|
$result = $fundService->trade(
|
|
|
$userId,
|
|
|
- (int)bcmul($amount, '100', 0), // 转换为整数存储
|
|
|
+ $fundAmount,
|
|
|
'MEX_ORDER',
|
|
|
$orderId,
|
|
|
'用户卖出物品撮合-资金转移'
|