diff --git a/app/Services/WechatBot/WechatNotificationService.php b/app/Services/WechatBot/WechatNotificationService.php index 9d5cf8a..644708a 100644 --- a/app/Services/WechatBot/WechatNotificationService.php +++ b/app/Services/WechatBot/WechatNotificationService.php @@ -227,17 +227,23 @@ class WechatNotificationService protected function getUserFriends(int $userId) { - // 假定有好友表 - if (\Illuminate\Support\Facades\Schema::hasTable('friends')) { - return \Illuminate\Support\Facades\DB::table('friends') - ->join('users', 'users.id', '=', 'friends.friend_id') - ->where('friends.user_id', $userId) - ->whereNotNull('users.wxid') - ->select('users.*') - ->get(); + $user = User::find($userId); + if (! $user) { + return collect([]); } - return collect([]); + // 谁把当前用户加为了好友(当前用户是 towho),谁就应该收到上线通知 + $watcherNames = \App\Models\FriendRequest::where('towho', $user->username) + ->pluck('who'); + + if ($watcherNames->isEmpty()) { + return collect([]); + } + + return User::whereIn('username', $watcherNames) + ->whereNotNull('wxid') + ->where('wxid', '!=', '') + ->get(); } protected function getUserSpouse(User $user)