<?php

declare (strict_types = 1);

namespace app\handle\controller;
use app\models\process\NumberTab;
use think\facade\Db;
use think\facade\Env;
use think\facade\Session;
use think\facade\View;

class Scan extends Common{
    public function index(){
        // 用户信息
        $userInfo = Session::get('user_info');
        $user = Db::name('user_controller')->where(array('id' => $userInfo['id']))->find();
        if(!$user) exit('用户不存在');
        // 获取桌子信息
        $table = Db::name('table')->where(array('id' => $userInfo['table_id']))->find();
        $numberTab = NumberTab::getByTableIdOrderByIdDesc($table);

        // 渲染参数和模板
        View::assign('table',$table);
        View::assign('user',$user);
        View::assign('numberTab', $numberTab);
        View::assign('websocketUrl',Env::get('system.WEBSOCKET'));
        View::assign('websocketProtocol',Env::get('system.PROTOCOL'));
        if ($table['scanner_type'] == 2) {
            View::assign('localSbServer', $table['media_near_rtmp']);
            return View::fetch('/scan/index_sb');
        } else {
            return View::fetch();
        }
    }

    public function dt_index(){
        // 用户信息
        $userInfo = Session::get('user_info');
        $user = Db::name('user_controller')->where(array('id' => $userInfo['id']))->find();
        if(!$user) exit('用户不存在');
        // 获取桌子信息
        $table = Db::name('table')->where(array('id' => $userInfo['table_id']))->find();
        $numberTab = NumberTab::getByTableIdOrderByIdDesc($table);

        // 渲染参数和模板
        View::assign('table',$table);
        View::assign('user',$user);
        View::assign('numberTab', $numberTab);
        View::assign('websocketUrl',Env::get('system.WEBSOCKET'));
        View::assign('websocketProtocol',Env::get('system.PROTOCOL'));
        if ($table['scanner_type'] == 2) {
            View::assign('localSbServer', $table['media_near_rtmp']);
            return View::fetch('/scan/dt_sb');
        } else {
            return View::fetch();
        }
    }
    public function nn_index(){
        // 用户信息
        $userInfo = Session::get('user_info');
        $user = Db::name('user_controller')->where(array('id' => $userInfo['id']))->find();
        if(!$user) exit('用户不存在');
        // 获取桌子信息
        $table = Db::name('table')->where(array('id' => $userInfo['table_id']))->find();
        $numberTab = NumberTab::getByTableIdOrderByIdDesc($table);

        // 渲染参数和模板
        View::assign('table',$table);
        View::assign('user',$user);
        View::assign('numberTab', $numberTab);
        View::assign('websocketUrl',Env::get('system.WEBSOCKET'));
        View::assign('websocketProtocol',Env::get('system.PROTOCOL'));
        if ($table['scanner_type'] == 2) {
            View::assign('localSbServer', $table['media_near_rtmp']);
            return View::fetch('/scan/nn_sb');
        } else {
            return View::fetch();
        }
        
    }

    public function tc_index(){
        // 用户信息
        $userInfo = Session::get('user_info');
        $user = Db::name('user_controller')->where(array('id' => $userInfo['id']))->find();
        if(!$user) exit('用户不存在');
        // 获取桌子信息
        $table = Db::name('table')->where(array('id' => $userInfo['table_id']))->find();
        $numberTab = NumberTab::getByTableIdOrderByIdDesc($table);

        // 渲染参数和模板
        View::assign('table',$table);
        View::assign('user',$user);
        View::assign('numberTab', $numberTab);
        View::assign('websocketUrl',Env::get('system.WEBSOCKET'));
        View::assign('websocketProtocol',Env::get('system.PROTOCOL'));
        return View::fetch();
    }
}