<?php


namespace app\services\process;

use app\models\process\NumberTab;
use app\services\connect\InitTableService;
use freedom\utils\SocketSession;

/**
 * TODO 开始倒计时(Rob)
 * Class StartRobService
 * @package app\services\process
 */
class StartRobService
{
    /**
     * TODO 处理开始倒计时(Rob)
     * @param int $numberTabId
     * @param array $tableInfo
     * @return void
     */
    public static function startRob(int $numberTabId, array $tableInfo){
        $ws = app('\think\swoole\WebSocket');
        $modelRes = NumberTab::startRob($numberTabId);
        if ($modelRes['status'] == true){
            $numberTabInfo = $modelRes['data'];
            $ws->to(SocketSession::HOUSE_NAME)->emit('startRob',[
                'status' => true,
                'table_id' => $tableInfo['id'],
                'round' => [
                    'boot_id' => $numberTabInfo['boot_id'],
                    'boot_num' => $numberTabInfo['boot_num'],
                    'number_tab_id' => $numberTabInfo['id'],
                    'number_tab_number' => $numberTabInfo['number'],
                    'in_checkout' => $tableInfo['in_checkout'],
                    'number_tab_status' => InitTableService::numberTabStatus($numberTabInfo)
                ]
            ]);
            //启动倒计时(该处以后会废弃掉)
            CountdownService::countdownRob($numberTabId,$tableInfo,$modelRes['data']);
        }else{
            $ws->emit('startBet', ['status' => false, 'msg' => $modelRes['msg']]);
        }
    }
}