<?php


namespace app\services\connect;


use app\models\process\NumberTab;
use app\models\table\Table;
use freedom\utils\SocketSession;
use think\Request;

/**
 * TODO 扫描登录服务
 * Class SpaceConnectService
 * @package app\services\connect
 */
class ScanConnectService
{
    /**
     * TODO 控制台登录处理
     * @param Request $event
     * @return void
     */
    public static function doScanConnect(Request $event){
        $ws = app('\think\swoole\WebSocket');
        $tableId = intval($event->get('table_id'));
        $tableInfo = Table::get($tableId);
        $numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
        if (!$numberTabInfo){
            $ws->emit('onlineLogin',['status' => false, 'msg' => 'Not NumberTab Data']);
            $ws->close();
            return;
        }
        $round = array();
        $round['tid'] = $tableId;
        $round['boot_id'] = intval($numberTabInfo['boot_id']);
        $round['boot_num'] = intval($numberTabInfo['boot_num']);
        $round['number_tab_id'] = intval($numberTabInfo['id']);
        $round['number_tab_number'] = intval($numberTabInfo['number']);
        if ($numberTabInfo['bet_status'] == 2){
            $round['is_scan'] = true;
        }else{
            $round['is_scan'] = false;
        }
        $ws->join(SocketSession::HOUSE_NAME);
        $ws->emit('onlineLogin',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
    }
}
