1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <?php
- declare(strict_types=1);
- namespace App\Model\Arts;
- use App\Master\Enum\RedisKeyEnum;
- use App\Master\Framework\Library\Tencent\TencentIm;
- use App\Model\Model;
- use App\Utils\RedisUtil;
- use Hyperf\DbConnection\Db;
- class LiveRoomKeywordModel extends Model
- {
- /**
- * The table associated with the model.
- *
- * @var ?string
- */
- protected ?string $table = 'live_room_keyword';
- protected ?string $dateFormat = 'U';
- public bool $timestamps = false;
- protected int $is_status_search = 0;// 是否使用 1=是 0=否 默认使用 status = 1 筛选
- protected int $is_delete_search = 0;// 是否使用 1=是 0=否 默认使用 is_delete = 0 筛选
- /**
- * 默认查询字段
- *
- * @var array|string[]
- */
- public array $select = [
- '*'
- ];
- public function searchRoomNoAttribute($query, $value, array $params): mixed
- {
- if (empty($value)) {
- return $query;
- }
- return $query->where('room_no', $value);
- }
- public function searchUserIdAttribute($query, $value, array $params): mixed
- {
- if (empty($value)) {
- return $query;
- }
- return $query->where('user_id', $value);
- }
- /**
- * 添加关键词
- * @param int $user_id
- * @param int $room_id
- * @param string $room_no
- * @param string $keyword
- * @return bool
- */
- public function add(int $user_id,int $room_id, string $room_no, string $keyword): bool
- {
- $data = [
- 'user_id' => $user_id,
- 'room_id' => $room_id,
- 'room_no' => $room_no,
- 'keyword' => $keyword,
- ];
- if (!$this->query()->insert($data)){
- return $this->error('添加失败');
- }
- return $this->success('添加成功');
- }
- /**
- * 添加关键词
- * @param int $id
- * @return bool
- */
- public function del(int $id): bool
- {
- if (!$this->query()->where('id',$id)->delete()){
- return $this->error('删除失败');
- }
- return $this->success('删除成功');
- }
- // 主播信息
- public function user()
- {
- return $this->hasOne(UserModel::class, 'id', 'user_id');
- }
- }
|