<?php
declare (strict_types = 1);

namespace app\listener\user;

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

class ToLeaveSeat
{
    /**
     * 事件监听处理
     *
     * @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','isToLeaveSeat')){
                ToLeaveSeatService::toLeaveSeat($event,$tableInfo);
            }else{
                $ws->emit('toLeaveSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'notice_repeat']);
            }
        }
    }
}