<?php
declare (strict_types = 1);

namespace app\listener\scan;

use app\models\process\NumberTab;
use app\models\table\Table;
use think\swoole\Websocket;

class CheckScanStatus
{
    /**
     * 事件监听处理
     *
     * @return void
     */
    public function handle(array $event, WebSocket $ws)
    {
	
    	$tableId = intval($event['table_id']);
    	$tableInfo = Table::get($tableId);
    	if (!$tableInfo) {
    		$ws->emit('checkScanStatus',['status' => false, 'msg' => 'TableInfo Error']);
    		return;
    	}
    	$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
    	if (!$numberTabInfo){
            $ws->emit('checkScanStatus',['status' => false, 'msg' => 'Not NumberTab Data']);
            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->emit('checkScanStatus',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
    }
}
