RoomMemberModel.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace App\Models\Gteam;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * App\Models\Gteam\RoomMemberModel
  6. *
  7. * @property int $id
  8. * @property \Illuminate\Support\Carbon $created_at 创建时间
  9. * @property \Illuminate\Support\Carbon $updated_at 更新时间
  10. * @property int|null $uid 用户
  11. * @property int $room_id 房间
  12. * @property int $is_comment 是否完成评论
  13. * @property string $type 房间类型cj_wx:吃鸡微信|cj_qq:吃鸡QQ|wz_wx:王者微信|wz_qq王者QQ
  14. * @property int $enter_id 报名id
  15. * @property-read \App\Models\Gteam\EnterModel $enter
  16. * @property-read \App\Models\Gteam\UserModel $user
  17. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel newModelQuery()
  18. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel newQuery()
  19. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel query()
  20. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereCreatedAt($value)
  21. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereEnterId($value)
  22. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereId($value)
  23. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereIsComment($value)
  24. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereRoomId($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereType($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereUid($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Gteam\RoomMemberModel whereUpdatedAt($value)
  28. * @mixin \Eloquent
  29. */
  30. class RoomMemberModel extends Model
  31. {
  32. //
  33. protected $table = 'kdgx_gteam_room_user';
  34. protected $dateFormat = 'U';
  35. protected $fillable = ['uid', 'room_id', 'is_comment', 'type', 'enter_id'];
  36. public function user()
  37. {
  38. return $this->hasOne(UserModel::class, 'uid', 'uid');
  39. }
  40. public function enter()
  41. {
  42. return $this->hasOne(EnterModel::class, 'id', 'enter_id');
  43. }
  44. /**
  45. * 获取两个人的共同房间
  46. * @param int $uid
  47. * @param int $friend_uid
  48. * @return array
  49. */
  50. public function friendRooms($uid, $friend_uid)
  51. {
  52. $rooms = \DB::select("SELECT room_id
  53. FROM(
  54. SELECT `room_id`
  55. FROM `kdgx_gteam_room_user`
  56. WHERE `uid`= ?
  57. UNION ALL
  58. SELECT `room_id`
  59. FROM `kdgx_gteam_room_user`
  60. WHERE `uid`= ?) as t
  61. GROUP BY room_id
  62. HAVING COUNT(*)>= 2", [$uid, $friend_uid]);
  63. $array = [];
  64. $rooms = array_map(function ($value) use (&$array) {
  65. array_push($array, $value->room_id);
  66. }, $rooms);
  67. return $array;
  68. }
  69. }