// +---------------------------------------------------------------------- declare (strict_types=1); namespace app\store\controller\live; use think\response\Json; use app\store\controller\Controller; use app\store\model\wxapp\LiveRoom as LiveRoomModel; use cores\exception\BaseException; /** * 小程序直播间管理 * Class Room * @package app\store\controller\apps\live */ class Room extends Controller { /** * 直播间列表页 * @param string $search 检索词 * @return Json * @throws \think\db\exception\DbException */ public function list(string $search = ''): Json { $model = new LiveRoomModel; $list = $model->getList($search); return $this->renderSuccess(compact('list')); } /** * 同步刷新直播间列表 * @return Json * @throws BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function sync(): Json { $model = new LiveRoomModel; if ($model->refreshLiveList()) { return $this->renderSuccess('直播间同步成功'); } return $this->renderError($model->getError() ?: '同步失败'); } /** * 修改直播间置顶状态 * @param int $id 直播间ID * @param int $isTop 是否置顶(1置顶 0取消) * @return Json */ public function setTop(int $id, int $isTop): Json { // 直播间详情 $model = LiveRoomModel::detail($id); if (!$model->setIsTop($isTop)) { return $this->renderError('操作失败'); } return $this->renderSuccess('操作成功'); } }