add
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\process;
|
||||
|
||||
|
||||
use freedom\utils\RedisUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* TODO 倒计时服务
|
||||
* Class CountdownService
|
||||
* @package app\services\process
|
||||
*/
|
||||
class CountdownService
|
||||
{
|
||||
/**
|
||||
* TODO 倒计时发送
|
||||
* @param int $numberTabId
|
||||
* @param array $tableInfo
|
||||
* @param array $numberTabInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function countdown(int $numberTabId, array $tableInfo, array $numberTabInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
//处理倒计时
|
||||
$waitTime = intval($tableInfo['wait_time']);
|
||||
//将倒计时用作是redis的过期时间
|
||||
RedisUtil::save('countdown_'.$numberTabInfo['id'],$waitTime,$waitTime);
|
||||
while($waitTime >= 0){
|
||||
$countdown = Cache::store('redis')->get('countdown_'.$numberTabInfo['id']);
|
||||
if ($countdown){
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('startBetCountDown',['status' => true, 'table_id' => $tableInfo['id'], 'count_down' => $waitTime]);
|
||||
$waitTime--;
|
||||
sleep(1);
|
||||
if ($waitTime == 0){
|
||||
//关闭倒计时
|
||||
EndBetService::endBet($numberTabId,$tableInfo);
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 倒计时发送(Rob)
|
||||
* @param int $numberTabId
|
||||
* @param array $tableInfo
|
||||
* @param array $numberTabInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function countdownRob(int $numberTabId, array $tableInfo, array $numberTabInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
//处理倒计时
|
||||
$waitTime = intval($tableInfo['rob_time']);
|
||||
//将倒计时用作是redis的过期时间
|
||||
RedisUtil::save('countdownRob_'.$numberTabInfo['id'],$waitTime,$waitTime);
|
||||
while($waitTime >= 0){
|
||||
$countdown = Cache::store('redis')->get('countdownRob_'.$numberTabInfo['id']);
|
||||
if ($countdown){
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('startRobCountDown',['status' => true, 'table_id' => $tableInfo['id'], 'count_down' => $waitTime]);
|
||||
$waitTime--;
|
||||
sleep(1);
|
||||
if ($waitTime == 0){
|
||||
//关闭倒计时
|
||||
EndRobService::endRob($numberTabId,$tableInfo);
|
||||
}
|
||||
}else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\process;
|
||||
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\RedisUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO 结束倒计时
|
||||
* Class EndBetService
|
||||
* @package app\services\process
|
||||
*/
|
||||
class EndBetService
|
||||
{
|
||||
/**
|
||||
* TODO 处理结束倒计时
|
||||
* @param int $numberTabId
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function endBet(int $numberTabId, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$modelRes = NumberTab::endBet($numberTabId);
|
||||
if ($modelRes['status'] == true){
|
||||
$numberTabInfo = $modelRes['data'];
|
||||
//清除Redis
|
||||
RedisUtil::delete('countdown_'.$numberTabInfo['id']);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('endBet',[
|
||||
'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('endBet', ['status' => false, 'msg' => $modelRes['msg']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?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']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\process;
|
||||
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO 作废
|
||||
* Class ResetNumberTabService
|
||||
* @package app\services\process
|
||||
*/
|
||||
class ResetNumberTabService
|
||||
{
|
||||
/**
|
||||
* TODO 处理作废
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function resetNumberTabService(array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo){
|
||||
$ws->emit('resetNumberTab', ['status' => false, 'msg' => 'not_number_tab_data']);
|
||||
return;
|
||||
}
|
||||
if($numberTabInfo['bet_status'] == 1 || $numberTabInfo['bet_status'] == 2 || ($numberTabInfo['bet_status'] == 0 || $numberTabInfo['rob_status'] == 1) || ($numberTabInfo['bet_status'] == 0 || $numberTabInfo['rob_status'] == 2)){
|
||||
//事务处理
|
||||
$res = NumberTab::resetNumberTab($numberTabInfo);
|
||||
if (!$res){
|
||||
$ws->emit('resetNumberTab', ['status' => false, 'msg' => 'reset_number_fail']);
|
||||
return;
|
||||
}
|
||||
$numberTabInfo['bet_status'] = 0;
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('resetNumberTab',[
|
||||
'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('resetNumberTab', ['status' => false, 'msg' => 'reset_number_fail']);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\process;
|
||||
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO 开始倒计时
|
||||
* Class StartBetService
|
||||
* @package app\services\process
|
||||
*/
|
||||
class StartBetService
|
||||
{
|
||||
/**
|
||||
* TODO 处理开始倒计时
|
||||
* @param int $numberTabId
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function startBet(int $numberTabId, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$modelRes = NumberTab::startBet($numberTabId);
|
||||
if ($modelRes['status'] == true){
|
||||
$numberTabInfo = $modelRes['data'];
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('startBet',[
|
||||
'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)
|
||||
]
|
||||
]);
|
||||
//启动倒计时(该处以后会废弃掉)
|
||||
CountdownService::countdown($numberTabId,$tableInfo,$modelRes['data']);
|
||||
}else{
|
||||
$ws->emit('startBet', ['status' => false, 'msg' => $modelRes['msg']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\process;
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO 开始倒计时(Rob)
|
||||
* Class StartRobService
|
||||
* @package app\services\process
|
||||
*/
|
||||
class StartRobService
|
||||
{
|
||||
/**
|
||||
* TODO 处理开始倒计时(Rob)
|
||||
* @param int $numberTabId
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function startRob(int $numberTabId, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$modelRes = NumberTab::startRob($numberTabId);
|
||||
if ($modelRes['status'] == true){
|
||||
$numberTabInfo = $modelRes['data'];
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('startRob',[
|
||||
'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)
|
||||
]
|
||||
]);
|
||||
//启动倒计时(该处以后会废弃掉)
|
||||
CountdownService::countdownRob($numberTabId,$tableInfo,$modelRes['data']);
|
||||
}else{
|
||||
$ws->emit('startBet', ['status' => false, 'msg' => $modelRes['msg']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user