<?php
declare (strict_types = 1);

namespace app\listener\user;

use app\services\bet\ToSeatService;
use freedom\utils\SocketSession;
use think\swoole\Websocket;

class ToSeat
{
    /**
     * 事件监听处理
     *
     * @return void
     */
    public function handle(array $event, Websocket $ws)
    {
        $preliminaryCheckRes = SocketSession::preliminaryCheck($event,'user');
        $fd = $ws->getSender();
        if($preliminaryCheckRes['status'] == true){
            $tableInfo = $preliminaryCheckRes['data'];
            if(SocketSession::checkRepeat($fd,'user','isToSeat')){
                ToSeatService::toSeat($event,$tableInfo);
            }else{
                $ws->emit('toSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'notice_repeat']);
            }
        }
    }
}