LiveRoomKeywordModel.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Model\Arts;
  4. use App\Master\Enum\RedisKeyEnum;
  5. use App\Master\Framework\Library\Tencent\TencentIm;
  6. use App\Model\Model;
  7. use App\Utils\RedisUtil;
  8. use Hyperf\DbConnection\Db;
  9. class LiveRoomKeywordModel extends Model
  10. {
  11. /**
  12. * The table associated with the model.
  13. *
  14. * @var ?string
  15. */
  16. protected ?string $table = 'live_room_keyword';
  17. protected ?string $dateFormat = 'U';
  18. public bool $timestamps = false;
  19. protected int $is_status_search = 0;// 是否使用 1=是 0=否 默认使用 status = 1 筛选
  20. protected int $is_delete_search = 0;// 是否使用 1=是 0=否 默认使用 is_delete = 0 筛选
  21. /**
  22. * 默认查询字段
  23. *
  24. * @var array|string[]
  25. */
  26. public array $select = [
  27. '*'
  28. ];
  29. public function searchRoomNoAttribute($query, $value, array $params): mixed
  30. {
  31. if (empty($value)) {
  32. return $query;
  33. }
  34. return $query->where('room_no', $value);
  35. }
  36. public function searchUserIdAttribute($query, $value, array $params): mixed
  37. {
  38. if (empty($value)) {
  39. return $query;
  40. }
  41. return $query->where('user_id', $value);
  42. }
  43. /**
  44. * 添加关键词
  45. * @param int $user_id
  46. * @param int $room_id
  47. * @param string $room_no
  48. * @param string $keyword
  49. * @return bool
  50. */
  51. public function add(int $user_id,int $room_id, string $room_no, string $keyword): bool
  52. {
  53. $data = [
  54. 'user_id' => $user_id,
  55. 'room_id' => $room_id,
  56. 'room_no' => $room_no,
  57. 'keyword' => $keyword,
  58. ];
  59. if (!$this->query()->insert($data)){
  60. return $this->error('添加失败');
  61. }
  62. return $this->success('添加成功');
  63. }
  64. /**
  65. * 添加关键词
  66. * @param int $id
  67. * @return bool
  68. */
  69. public function del(int $id): bool
  70. {
  71. if (!$this->query()->where('id',$id)->delete()){
  72. return $this->error('删除失败');
  73. }
  74. return $this->success('删除成功');
  75. }
  76. // 主播信息
  77. public function user()
  78. {
  79. return $this->hasOne(UserModel::class, 'id', 'user_id');
  80. }
  81. }