包含所有线上运行的改动: - 荷官端倒计时卡顿修复(CountdownService TTL+10/前端watchdog) - 停止下注debounce防重复(8个handle.js) - 洗码量规则重写(单边/双边/开和不计/百家乐+龙虎) - 龙虎和局不杀庄闲(全额退回) - 日志系统(Logger工具类/日志查看/清理脚本) - 好路提醒异常处理(WaybillRemindService try-catch) - 扫牌器连接改进(ScanConnectService) - 牛牛/三卡开牌修复 - .gitignore更新/.DS_Store清理
111 lines
4.7 KiB
PHP
111 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace app\services\bet;
|
|
|
|
use app\models\bet\Bet;
|
|
use app\utils\Logger;
|
|
use freedom\utils\DiceUtil;
|
|
use freedom\utils\SocketSession;
|
|
|
|
/**
|
|
* TODO ToBetDiceService
|
|
* Class ToBetDiceService
|
|
* @package app\services\bet
|
|
*/
|
|
|
|
class ToBetDiceService{
|
|
|
|
/**
|
|
* TODO 处理骰宝下注
|
|
* @param array $event
|
|
* @param array $tableInfo
|
|
* @return void
|
|
*/
|
|
public static function toBetDice(array $event, array $tableInfo){
|
|
$ws = app('\think\swoole\WebSocket');
|
|
$fd = $ws->getSender();
|
|
$data = array();
|
|
foreach ($event['amount'] as $k => $v){
|
|
if (intval($v) > 0){
|
|
$data[$k] = intval($v);
|
|
}
|
|
}
|
|
$seat_num = isset($event['seat_num']) && intval($event['seat_num']) > 0 ? intval($event['seat_num']) : 0;
|
|
$time = time();
|
|
$toBetCheck = ToBetCommonService::toBetCheck($tableInfo,$event,$data);
|
|
if ($toBetCheck['status'] == false){
|
|
Logger::warn(Logger::CAT_BET, 'dice_bet_fail', ['table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
|
|
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => $toBetCheck['msg']]);
|
|
SocketSession::resetRepeat($fd,'user','isToBet');
|
|
return;
|
|
}
|
|
$numberTabInfo = $toBetCheck['numberTabInfo'];
|
|
$userInfo = $toBetCheck['userInfo'];
|
|
$amount = array_sum($data);
|
|
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
|
if($prevBetInfo){
|
|
$beforeAmount = string_to_array($prevBetInfo['dice_amount']);
|
|
$betTotalAmount = DiceUtil::amountInc($beforeAmount, $data);
|
|
}else{
|
|
$betTotalAmount = $data;
|
|
}
|
|
|
|
/***** User Limit Start *****/
|
|
$totalAmount = array_sum($betTotalAmount);
|
|
if ($totalAmount > $userInfo['limit_high']){
|
|
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_user']);
|
|
SocketSession::resetRepeat($fd,'user','isToBet');
|
|
return;
|
|
}
|
|
if ($totalAmount > 0 && $totalAmount < $userInfo['limit_low']){
|
|
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'under_limit_user']);
|
|
SocketSession::resetRepeat($fd,'user','isToBet');
|
|
return;
|
|
}
|
|
/***** User Limit End *****/
|
|
|
|
/***** Table Limit Start *****/
|
|
$totalAmount = array_sum($betTotalAmount);
|
|
$limitMoneyArray = explode('-',$tableInfo['limit_money']);
|
|
if($totalAmount > $limitMoneyArray[1]){
|
|
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
|
SocketSession::resetRepeat($fd,'user','isToBet');
|
|
return;
|
|
}
|
|
if(($totalAmount > 0 && $totalAmount < $limitMoneyArray[0]) ){
|
|
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'under_limit_table']);
|
|
SocketSession::resetRepeat($fd,'user','isToBet');
|
|
return;
|
|
}
|
|
|
|
//如果桌子设置了单口最高下注,则所有的下注不能超过桌子单口下注限红
|
|
if(($tableInfo['limit_money_total'] > 0 && $totalAmount > $tableInfo['limit_money_total'])){
|
|
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
|
SocketSession::resetRepeat($fd,'user','isToBet');
|
|
return;
|
|
}
|
|
|
|
/***** Table Limit End *****/
|
|
|
|
|
|
|
|
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
|
|
$numberTabAmount = string_to_array($numberTabInfo['dice_amount']);
|
|
if($res){
|
|
Logger::info(Logger::CAT_BET, 'dice_bet_success', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
|
|
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
|
|
$totalAmountArray = DiceUtil::amountInc($numberTabAmount, $data);
|
|
$round = [
|
|
'amount_total' => $totalAmountArray,
|
|
'amount_item' => $data
|
|
];
|
|
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
|
}else{
|
|
Logger::warn(Logger::CAT_BET, 'dice_bet_db_fail', ['user_id' => $userInfo['id'], 'table_id' => $tableInfo['id'], 'amount' => $amount]);
|
|
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
|
}
|
|
SocketSession::resetRepeat($fd,'user','isToBet');
|
|
}
|
|
|
|
}
|