|
@@ -284,8 +284,10 @@ class ThirdGameOrderService
|
|
|
$requested[(int) $userId][$playerId] = true;
|
|
$requested[(int) $userId][$playerId] = true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ $result = $this->usersByLegacyPlayerId($playerIds);
|
|
|
if ($requested === []) {
|
|
if ($requested === []) {
|
|
|
- return [];
|
|
|
|
|
|
|
+ return $result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$rows = DB::table('users')
|
|
$rows = DB::table('users')
|
|
@@ -293,7 +295,6 @@ class ThirdGameOrderService
|
|
|
->whereIn('id', array_keys($requested))
|
|
->whereIn('id', array_keys($requested))
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
|
- $result = [];
|
|
|
|
|
foreach ($rows as $row) {
|
|
foreach ($rows as $row) {
|
|
|
foreach (array_keys($requested[(int) $row->id] ?? []) as $playerId) {
|
|
foreach (array_keys($requested[(int) $row->id] ?? []) as $playerId) {
|
|
|
$result[$playerId] = $row;
|
|
$result[$playerId] = $row;
|
|
@@ -303,6 +304,59 @@ class ThirdGameOrderService
|
|
|
return $result;
|
|
return $result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 2026-08-24 之前的三方账号为 p + md5(sn_member_id) 前10位,历史订单仍使用该账号。
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return array<string, object>
|
|
|
|
|
+ */
|
|
|
|
|
+ private function usersByLegacyPlayerId(array $playerIds): array
|
|
|
|
|
+ {
|
|
|
|
|
+ $legacy = [];
|
|
|
|
|
+ foreach ($playerIds as $playerId) {
|
|
|
|
|
+ $playerId = trim((string) $playerId);
|
|
|
|
|
+ if (preg_match('/^p[0-9a-f]{10}$/D', $playerId)) $legacy[$playerId] = true;
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($legacy === []) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $sn = (string) config('third_game.sn');
|
|
|
|
|
+ $expression = "CONCAT('p', SUBSTRING(MD5(CONCAT(?, '_', `member_id`)), 1, 10))";
|
|
|
|
|
+ $placeholders = implode(',', array_fill(0, count($legacy), '?'));
|
|
|
|
|
+ $rows = DB::table('users')
|
|
|
|
|
+ ->select(['id', 'member_id', 'username', 'first_name'])
|
|
|
|
|
+ ->selectRaw($expression . ' AS legacy_player_id', [$sn])
|
|
|
|
|
+ ->whereRaw($expression . " IN ({$placeholders})", array_merge([$sn], array_keys($legacy)))
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ $result = [];
|
|
|
|
|
+ foreach ($rows as $row) {
|
|
|
|
|
+ $result[(string) $row->legacy_player_id] = $row;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /** 补齐同步时未能识别旧账号而缺少会员信息的订单。 */
|
|
|
|
|
+ public function backfillLegacyPlayers(): int
|
|
|
|
|
+ {
|
|
|
|
|
+ $updated = 0;
|
|
|
|
|
+ $playerIds = ThirdGameOrderModel::query()->whereNull('user_id')->where('player_id', 'like', 'p%')
|
|
|
|
|
+ ->distinct()->pluck('player_id')->all();
|
|
|
|
|
+ foreach (array_chunk($playerIds, 200) as $chunk) {
|
|
|
|
|
+ foreach ($this->usersByLegacyPlayerId($chunk) as $playerId => $user) {
|
|
|
|
|
+ $updated += ThirdGameOrderModel::query()->whereNull('user_id')->where('player_id', $playerId)->update([
|
|
|
|
|
+ 'user_id' => $user->id,
|
|
|
|
|
+ 'member_id' => $user->member_id,
|
|
|
|
|
+ 'username' => (string) ($user->username ?? ''),
|
|
|
|
|
+ 'first_name' => (string) ($user->first_name ?? ''),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return $updated;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* @return array<string, ThirdGameOrderModel>
|
|
* @return array<string, ThirdGameOrderModel>
|
|
|
*/
|
|
*/
|