hasOne(UserModel::class, 'uid', 'uid'); } public function enter() { return $this->hasOne(EnterModel::class, 'id', 'enter_id'); } /** * 获取两个人的共同房间 * @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_gteam_room_user` WHERE `uid`= ? UNION ALL SELECT `room_id` FROM `kdgx_gteam_room_user` 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; } }