|
@@ -514,9 +514,19 @@ class User extends Controller
|
|
|
$page = (int)request()->input('page', 1);
|
|
$page = (int)request()->input('page', 1);
|
|
|
$limit = (int)request()->input('limit', 15);
|
|
$limit = (int)request()->input('limit', 15);
|
|
|
|
|
|
|
|
- $query = UserLogin::query()
|
|
|
|
|
- ->leftJoin('users', function ($join) {
|
|
|
|
|
- $join->on('user_login.user_id', '=', 'users.user_id')
|
|
|
|
|
|
|
+ $query = UserLogin::query();
|
|
|
|
|
+ $grammar = $query->getQuery()->getGrammar();
|
|
|
|
|
+ // 历史表字段可能混用 general_ci / unicode_ci;显式统一比较规则,保留账号大小写不敏感语义。
|
|
|
|
|
+ $collation = in_array($query->getConnection()->getDriverName(), ['mysql', 'mariadb'], true)
|
|
|
|
|
+ ? ' COLLATE utf8mb4_unicode_ci' : '';
|
|
|
|
|
+ $userIdMatch = $grammar->wrap('user_login.user_id') . $collation
|
|
|
|
|
+ . ' = ' . $grammar->wrap('users.user_id') . $collation;
|
|
|
|
|
+ $accountMatch = $grammar->wrap('customer_service_users.account') . $collation
|
|
|
|
|
+ . ' = ' . $grammar->wrap('user_login.login_account') . $collation;
|
|
|
|
|
+
|
|
|
|
|
+ $query
|
|
|
|
|
+ ->leftJoin('users', function ($join) use ($userIdMatch) {
|
|
|
|
|
+ $join->whereRaw($userIdMatch)
|
|
|
// 无用户的失败日志不能关联到同样缺少 ID 的客服账号。
|
|
// 无用户的失败日志不能关联到同样缺少 ID 的客服账号。
|
|
|
->where('user_login.user_id', '<>', '');
|
|
->where('user_login.user_id', '<>', '');
|
|
|
})
|
|
})
|
|
@@ -524,11 +534,11 @@ class User extends Controller
|
|
|
$q->whereNull('users.from')->orWhere('users.from', '<>', '0');
|
|
$q->whereNull('users.from')->orWhere('users.from', '<>', '0');
|
|
|
})
|
|
})
|
|
|
// 失败日志可能没有用户 ID,仍需按输入账号排除客服来源(from=0)。
|
|
// 失败日志可能没有用户 ID,仍需按输入账号排除客服来源(from=0)。
|
|
|
- ->whereNotExists(function ($q) {
|
|
|
|
|
|
|
+ ->whereNotExists(function ($q) use ($accountMatch) {
|
|
|
$q->selectRaw('1')->from('users as customer_service_users')
|
|
$q->selectRaw('1')->from('users as customer_service_users')
|
|
|
->where('customer_service_users.from', '0')
|
|
->where('customer_service_users.from', '0')
|
|
|
->where('user_login.login_account', '<>', '')
|
|
->where('user_login.login_account', '<>', '')
|
|
|
- ->whereColumn('customer_service_users.account', 'user_login.login_account');
|
|
|
|
|
|
|
+ ->whereRaw($accountMatch);
|
|
|
})
|
|
})
|
|
|
->select([
|
|
->select([
|
|
|
'user_login.id',
|
|
'user_login.id',
|