|
|
@@ -15,6 +15,8 @@ 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\Mex\Logic\MexMatchLogLogic;
|
|
|
+use App\Module\Mex\Enums\MatchType;
|
|
|
use App\Module\GameItems\Enums\FREEZE_REASON_TYPE;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Log;
|
|
|
@@ -208,17 +210,26 @@ class MexMatchLogic
|
|
|
*/
|
|
|
public static function executeUserBuyItemMatchForItem(int $itemId, int $batchSize = 100): array
|
|
|
{
|
|
|
+ $startTime = microtime(true);
|
|
|
+
|
|
|
try {
|
|
|
// 注意:根据文档要求,Logic层不应该开启事务,事务应该在Service层处理
|
|
|
// 检查用户买入物品撮合条件
|
|
|
$conditionCheck = self::checkUserBuyItemMatchConditions($itemId);
|
|
|
if (!$conditionCheck['can_match']) {
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => false,
|
|
|
'message' => $conditionCheck['message'],
|
|
|
'matched_orders' => 0,
|
|
|
'total_amount' => '0.00000',
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_BUY, $itemId, $batchSize, $result, $executionTimeMs);
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
$warehouse = $conditionCheck['warehouse'];
|
|
|
@@ -236,12 +247,19 @@ class MexMatchLogic
|
|
|
->get();
|
|
|
|
|
|
if ($buyOrders->isEmpty()) {
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => true,
|
|
|
'message' => '没有符合条件的用户买入物品订单',
|
|
|
'matched_orders' => 0,
|
|
|
'total_amount' => '0.00000',
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_BUY, $itemId, $batchSize, $result, $executionTimeMs);
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
$matchedOrders = 0;
|
|
|
@@ -267,19 +285,33 @@ class MexMatchLogic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => true,
|
|
|
'message' => "成功撮合 {$matchedOrders} 个用户买入物品订单",
|
|
|
'matched_orders' => $matchedOrders,
|
|
|
'total_amount' => $totalAmount,
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_BUY, $itemId, $batchSize, $result, $executionTimeMs);
|
|
|
+
|
|
|
+ return $result;
|
|
|
} catch (\Exception $e) {
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => false,
|
|
|
'message' => '用户买入物品撮合执行失败:' . $e->getMessage(),
|
|
|
'matched_orders' => 0,
|
|
|
'total_amount' => '0.00000',
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志(包含错误信息)
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_BUY, $itemId, $batchSize, $result, $executionTimeMs, $e->getMessage());
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -292,17 +324,26 @@ class MexMatchLogic
|
|
|
*/
|
|
|
public static function executeUserSellItemMatchForItem(int $itemId, int $batchSize = 100): array
|
|
|
{
|
|
|
+ $startTime = microtime(true);
|
|
|
+
|
|
|
try {
|
|
|
// 注意:根据文档要求,Logic层不应该开启事务,事务应该在Service层处理
|
|
|
// 检查用户卖出物品撮合条件
|
|
|
$conditionCheck = self::checkUserSellItemMatchConditions($itemId);
|
|
|
if (!$conditionCheck['can_match']) {
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => false,
|
|
|
'message' => $conditionCheck['message'],
|
|
|
'matched_orders' => 0,
|
|
|
'total_amount' => '0.00000',
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_SELL, $itemId, $batchSize, $result, $executionTimeMs);
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
$priceConfig = $conditionCheck['price_config'];
|
|
|
@@ -315,12 +356,19 @@ class MexMatchLogic
|
|
|
->get();
|
|
|
|
|
|
if ($sellOrders->isEmpty()) {
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => true,
|
|
|
'message' => '没有待撮合的用户卖出物品订单',
|
|
|
'matched_orders' => 0,
|
|
|
'total_amount' => '0.00000',
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_SELL, $itemId, $batchSize, $result, $executionTimeMs);
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
|
|
|
$matchedOrders = 0;
|
|
|
@@ -340,19 +388,33 @@ class MexMatchLogic
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => true,
|
|
|
'message' => "成功撮合 {$matchedOrders} 个用户卖出物品订单",
|
|
|
'matched_orders' => $matchedOrders,
|
|
|
'total_amount' => $totalAmount,
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_SELL, $itemId, $batchSize, $result, $executionTimeMs);
|
|
|
+
|
|
|
+ return $result;
|
|
|
} catch (\Exception $e) {
|
|
|
- return [
|
|
|
+ $result = [
|
|
|
'success' => false,
|
|
|
'message' => '用户卖出物品撮合执行失败:' . $e->getMessage(),
|
|
|
'matched_orders' => 0,
|
|
|
'total_amount' => '0.00000',
|
|
|
];
|
|
|
+
|
|
|
+ // 记录撮合日志(包含错误信息)
|
|
|
+ $endTime = microtime(true);
|
|
|
+ $executionTimeMs = round(($endTime - $startTime) * 1000);
|
|
|
+ MexMatchLogLogic::logMatch(MatchType::USER_SELL, $itemId, $batchSize, $result, $executionTimeMs, $e->getMessage());
|
|
|
+
|
|
|
+ return $result;
|
|
|
}
|
|
|
}
|
|
|
|