<?php
declare (strict_types = 1);

namespace app\listener\user;

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

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