hasOne(UserModel::class, 'uid', 'uid')->select('nickname', 'headimgurl', 'sex'); } /** * 获取两个人的共同房间 * @param int $uid * @param int $friend_uid * @return array */ public function friendRooms($uid, $friend_uid) { $rooms = \DB::select("SELECT room_id FROM( SELECT `room_id` FROM `kdgx_goodnight_room_members` WHERE `uid`= ? UNION ALL SELECT `room_id` FROM `kdgx_goodnight_room_members` WHERE `uid`= ?) as t GROUP BY room_id HAVING COUNT(*)>= 2", [$uid, $friend_uid]); $array = []; $rooms = array_map(function ($value) use (&$array) { array_push($array, $value->room_id); }, $rooms); return $array; } }