UserGift.php 969 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace app\common\model\plus\live;
  3. use app\common\model\BaseModel;
  4. /**
  5. * 房间用户礼物模型
  6. */
  7. class UserGift extends BaseModel
  8. {
  9. protected $name = 'live_user_gift';
  10. protected $pk = 'user_gift_id';
  11. /**
  12. * 关联用户
  13. */
  14. public function user()
  15. {
  16. return $this->belongsTo('app\\common\\model\\user\\User', 'user_id', 'user_id')
  17. ->field(['user_id', 'nickName', 'avatarUrl']);
  18. }
  19. /**
  20. * 详情
  21. */
  22. public static function detail($room_id, $user_id)
  23. {
  24. return (new static())->where('room_id', '=', $room_id)
  25. ->where('user_id', '=', $user_id)
  26. ->find();
  27. }
  28. /**
  29. * 获取列表
  30. */
  31. public function getList($data)
  32. {
  33. return $this->with(['user'])
  34. ->where('room_id', '=', $data['room_id'])
  35. ->where('gift_num', '>', 0)
  36. ->order(['gift_num' => 'desc'])
  37. ->paginate($data);
  38. }
  39. }