|
@@ -41,15 +41,16 @@ class OnlineUserService
|
|
|
$hasCountry = Schema::hasColumn('user_login', 'country');
|
|
$hasCountry = Schema::hasColumn('user_login', 'country');
|
|
|
|
|
|
|
|
// 先筛在线用户 ID(避免 join 干扰 count / 前缀别名问题)
|
|
// 先筛在线用户 ID(避免 join 干扰 count / 前缀别名问题)
|
|
|
|
|
+ // user_session.user_id 与 users.user_id 排序规则可能不一致(unicode_ci vs general_ci),比较时统一 COLLATE
|
|
|
$onlineIdsQuery = DB::table('users')
|
|
$onlineIdsQuery = DB::table('users')
|
|
|
->where(function ($q) use ($now, $activeSince) {
|
|
->where(function ($q) use ($now, $activeSince) {
|
|
|
$q->whereExists(function ($sub) use ($now) {
|
|
$q->whereExists(function ($sub) use ($now) {
|
|
|
$sub->select(DB::raw(1))
|
|
$sub->select(DB::raw(1))
|
|
|
->from('user_session')
|
|
->from('user_session')
|
|
|
- ->where(function ($w) {
|
|
|
|
|
- $w->whereColumn('user_session.user_id', 'users.user_id')
|
|
|
|
|
- ->orWhereColumn('user_session.user_id', 'users.member_id');
|
|
|
|
|
- })
|
|
|
|
|
|
|
+ ->whereRaw(
|
|
|
|
|
+ '(user_session.user_id COLLATE utf8mb4_general_ci = users.user_id COLLATE utf8mb4_general_ci'
|
|
|
|
|
+ . ' OR user_session.user_id COLLATE utf8mb4_general_ci = users.member_id COLLATE utf8mb4_general_ci)'
|
|
|
|
|
+ )
|
|
|
->where('user_session.expire_time', '>', $now);
|
|
->where('user_session.expire_time', '>', $now);
|
|
|
})->orWhere(function ($q2) use ($activeSince) {
|
|
})->orWhere(function ($q2) use ($activeSince) {
|
|
|
$q2->where('users.last_active_time', '>', 1000000000)
|
|
$q2->where('users.last_active_time', '>', 1000000000)
|
|
@@ -119,9 +120,11 @@ class OnlineUserService
|
|
|
->groupBy('user_id');
|
|
->groupBy('user_id');
|
|
|
|
|
|
|
|
$detailQuery = DB::table('users')
|
|
$detailQuery = DB::table('users')
|
|
|
- ->leftJoin('wallets', 'wallets.member_id', '=', 'users.member_id')
|
|
|
|
|
|
|
+ ->leftJoin('wallets', function ($join) {
|
|
|
|
|
+ $join->whereRaw('wallets.member_id COLLATE utf8mb4_general_ci = users.member_id COLLATE utf8mb4_general_ci');
|
|
|
|
|
+ })
|
|
|
->leftJoinSub($latestLoginSql, 'll', function ($join) {
|
|
->leftJoinSub($latestLoginSql, 'll', function ($join) {
|
|
|
- $join->on('ll.user_id', '=', 'users.user_id');
|
|
|
|
|
|
|
+ $join->whereRaw('ll.user_id COLLATE utf8mb4_general_ci = users.user_id COLLATE utf8mb4_general_ci');
|
|
|
})
|
|
})
|
|
|
->leftJoin('user_login as ul', 'ul.id', '=', 'll.max_id')
|
|
->leftJoin('user_login as ul', 'ul.id', '=', 'll.max_id')
|
|
|
->whereIn('users.id', $pageIds);
|
|
->whereIn('users.id', $pageIds);
|