<?php


namespace app\services\process;

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

/**
 * TODO 结束倒计时(Rob)
 * Class EndRobService
 * @package app\services\process
 */
class EndRobService
{
    /**
     * TODO 处理结束倒计时(Rob)
     * @param int $numberTabId
     * @param array $tableInfo
     * @return void
     */
    public static function endRob(int $numberTabId, array $tableInfo){
        $ws = app('\think\swoole\WebSocket');
        $modelRes = NumberTab::endRob($numberTabId);
        if ($modelRes['status'] == true){
            $numberTabInfo = $modelRes['data'];
            //清除Redis
            RedisUtil::delete('countdownRob_'.$numberTabInfo['id']);
            $ws->to(SocketSession::HOUSE_NAME)->emit('endRob',[
                '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)
                ]
            ]);
        }else{
            $ws->emit('endRob', ['status' => false, 'msg' => $modelRes['msg']]);
        }
    }
}