getDetail(params: ['room_no' => $room_no])) { return $this->error('直播间已关闭'); } if ($room['user_id'] != $user_id) { return $this->error('未拥有此权限'); } if (!$admin = $this->getDetail(params: ['admin_id' => $admin_id, 'room_no' => $room_no])) { // 没有直播间 创建一个 $insert = [ 'room_id' => $room['id'], 'room_no' => $room_no, 'user_id' => $user_id, 'admin_id' => $admin_id, 'status' => 1, 'create_time' => time(), ]; if (!$this->insertGetId($insert)) { return $this->error('设置失败'); } } else { // 更新状态 if (!$this->where('id', $admin['id'])->update(['status' => 1,'create_time' => time()])) { return $this->error('设置失败'); } } // $im = new TencentIm(); // if (!$im->modify_admin($room_no,im_prefix($user_id))){ // return $this->error($im->getMessage() ?? '设置失败'); // } return $this->success('成功'); } /** * 删除场控 * @param int $user_id 主播ID * @param string $room_no 房间号 * @param int $admin_id 场控ID * @return bool */ public function del(int $user_id, string $room_no, int $admin_id) { $model = new LiveRoomModel(); if (!$room = $model->getDetail(params: ['room_no' => $room_no])) { return $this->error('直播间已关闭'); } if ($room['user_id'] != $user_id) { return $this->error('未拥有此权限'); } if ($admin = $this->getDetail(params: ['admin_id' => $admin_id, 'room_no' => $room_no])) { // 更新状态 if (!$this->where('id', $admin['id'])->update(['status' => 0, 'create_time' => time()])) { return $this->error('删除失败'); } } // $im = new TencentIm(); // if (!$im->modify_admin($room_no,im_prefix($user_id),2)){ // return $this->error($im->getMessage() ?? '设置失败'); // } return $this->success('成功'); } /** * 获取场控信息 * @param $admin_id * @param $room_no * @return array */ public function getAdmin($admin_id, $room_no) { $this->setIsStatusSearchValue(1); return $this->getDetail(params: [ 'admin_id' => $admin_id, 'room_no' => $room_no, ]); } public function searchRoomNoAttribute($query, $value, array $params): mixed { if (empty($value)) { return $query; } return $query->where('room_no', $value); } public function searchAdminIdAttribute($query, $value, array $params): mixed { if (empty($value)) { return $query; } return $query->where('admin_id', $value); } public function user() { return $this->hasOne(UserModel::class, 'id', 'admin_id'); } }