LiveRoomBlackModel.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Model\Arts;
  4. use App\Master\Framework\Library\Tencent\TencentIm;
  5. use App\Model\Model;
  6. use Hyperf\DbConnection\Db;
  7. class LiveRoomBlackModel extends Model
  8. {
  9. /**
  10. * The table associated with the model.
  11. *
  12. * @var ?string
  13. */
  14. protected ?string $table = 'live_room_black';
  15. protected ?string $dateFormat = 'U';
  16. public bool $timestamps = false;
  17. protected int $is_status_search = 0;// 是否使用 1=是 0=否 默认使用 status = 1 筛选
  18. protected int $is_delete_search = 0;// 是否使用 1=是 0=否 默认使用 is_delete = 0 筛选
  19. /**
  20. * 默认查询字段
  21. *
  22. * @var array|string[]
  23. */
  24. public array $select = [
  25. '*'
  26. ];
  27. public function searchRoomNoAttribute($query, $value, array $params): mixed
  28. {
  29. if (empty($value)) {
  30. return $query;
  31. }
  32. return $query->where('room_no', $value);
  33. }
  34. public function searchUserIdAttribute($query, $value, array $params): mixed
  35. {
  36. if (empty($value)) {
  37. return $query;
  38. }
  39. return $query->where('user_id', $value);
  40. }
  41. public function searchKeywordAttribute($query, $value, array $params): mixed
  42. {
  43. if (empty($value)) {
  44. return $query;
  45. }
  46. return $query->withWhereHas('user',function ($query) use($value) {
  47. $query->where('nickname','like',"%{$value}%");
  48. });
  49. }
  50. // 用户信息
  51. public function user()
  52. {
  53. return $this->hasOne(UserModel::class, 'id', 'user_id');
  54. }
  55. }