add
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
|
||||
/**
|
||||
* TODO CancelBet处理类
|
||||
* Class CancelBetService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class CancelBetService
|
||||
{
|
||||
/**
|
||||
* TODO 处理cancelBet
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function cancelBet(array $event, array $tableInfo): array{
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'cannot_cancel_bet'];
|
||||
$time = time();
|
||||
if ($numberTabInfo['bet_status'] != 1 || $time > ($numberTabInfo['bet_start_time'] + $tableInfo['wait_time'])) return ['status' => false, 'msg' => 'cannot_cancel_bet'];
|
||||
$userInfo = User::get(intval($event['user_id']));
|
||||
if (!$userInfo) return ['status' => false, 'msg' => 'cannot_cancel_bet'];
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
if(!$prevBetInfo) return ['status' => false, 'msg' => 'not_user_bet'];
|
||||
return Bet::cancelBet($tableInfo,$numberTabInfo,$userInfo,$prevBetInfo);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToBetBaccaratService
|
||||
* Class ToBetBaccaratService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToBetBaccaratService
|
||||
{
|
||||
/**
|
||||
* TODO 处理toBetBaccarat
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toBetBaccarat(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$baccaratType = intval($event['baccarat_type']);
|
||||
$data = array();
|
||||
$data['banker_amount'] = isset($event['banker_amount']) && intval($event['banker_amount']) > 0 ? intval($event['banker_amount']) : 0;
|
||||
$data['player_amount'] = isset($event['player_amount']) && intval($event['player_amount']) > 0 ? intval($event['player_amount']) : 0;
|
||||
$data['tie_amount'] = isset($event['tie_amount']) && intval($event['tie_amount']) > 0 ? intval($event['tie_amount']) : 0;
|
||||
$data['banker_pair_amount'] = isset($event['banker_pair_amount']) && intval($event['banker_pair_amount']) > 0 ? intval($event['banker_pair_amount']) : 0;
|
||||
$data['player_pair_amount'] = isset($event['player_pair_amount']) && intval($event['player_pair_amount']) > 0 ? intval($event['player_pair_amount']) : 0;
|
||||
$data['luck_six_amount'] = isset($event['luck_six_amount']) && intval($event['luck_six_amount']) > 0 ? intval($event['luck_six_amount']) : 0;
|
||||
$data['big_amount'] = isset($event['big_amount']) && intval($event['big_amount']) > 0 ? intval($event['big_amount']) : 0;
|
||||
$data['small_amount'] = isset($event['small_amount']) && intval($event['small_amount']) > 0 ? intval($event['small_amount']) : 0;
|
||||
$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){
|
||||
$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);
|
||||
|
||||
/***** User Limit Start *****/
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
$betTotalAmount = [];
|
||||
if($prevBetInfo){
|
||||
$betTotalAmount['banker_amount'] = $prevBetInfo['banker_amount'] + $data['banker_amount'];
|
||||
$betTotalAmount['player_amount'] = $prevBetInfo['player_amount'] + $data['player_amount'];
|
||||
$betTotalAmount['tie_amount'] = $prevBetInfo['tie_amount'] + $data['tie_amount'];
|
||||
$betTotalAmount['banker_pair_amount'] = $prevBetInfo['banker_pair_amount'] + $data['banker_pair_amount'];
|
||||
$betTotalAmount['player_pair_amount'] = $prevBetInfo['player_pair_amount'] + $data['player_pair_amount'];
|
||||
$betTotalAmount['luck_six_amount'] = $prevBetInfo['luck_six_amount'] + $data['luck_six_amount'];
|
||||
$betTotalAmount['big_amount'] = $prevBetInfo['big_amount'] + $data['big_amount'];
|
||||
$betTotalAmount['small_amount'] = $prevBetInfo['small_amount'] + $data['small_amount'];
|
||||
}else{
|
||||
$betTotalAmount = $data;
|
||||
}
|
||||
foreach ($betTotalAmount AS $value){
|
||||
if ($value > $userInfo['limit_high']){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_user']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
if ($value > 0 && $value < $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 *****/
|
||||
$limitMoneyArray = explode('-',$tableInfo['limit_money']);
|
||||
$limitMoneyTieArray = explode('-',$tableInfo['limit_money_tie']);
|
||||
$limitMoneyPairArray = explode('-',$tableInfo['limit_money_pair']);
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
if($prevBetInfo){
|
||||
$totalBankerAmount = $prevBetInfo['banker_amount'] + $data['banker_amount'];
|
||||
$totalPlayerAmount = $prevBetInfo['player_amount'] + $data['player_amount'];
|
||||
$totalTieAmount = $prevBetInfo['tie_amount'] + $data['tie_amount'];
|
||||
$totalBPAmount = $prevBetInfo['banker_pair_amount'] + $data['banker_pair_amount'];
|
||||
$totalPPAmount = $prevBetInfo['player_pair_amount'] + $data['player_pair_amount'];
|
||||
}else{
|
||||
$totalBankerAmount = $data['banker_amount'];
|
||||
$totalPlayerAmount = $data['player_amount'];
|
||||
$totalTieAmount = $data['tie_amount'];
|
||||
$totalBPAmount = $data['banker_pair_amount'];
|
||||
$totalPPAmount = $data['player_pair_amount'];
|
||||
}
|
||||
$curNumberTabBankerAmount = $numberTabInfo['banker_amount'] + $data['banker_amount'];
|
||||
$curNumberTabPlayerAmount = $numberTabInfo['player_amount'] + $data['player_amount'];
|
||||
$curNumberTabTieAmount = $numberTabInfo['tie_amount'] + $data['tie_amount'];
|
||||
$curNumberTabBPAmount = $numberTabInfo['banker_pair_amount'] + $data['banker_pair_amount'];
|
||||
$curNumberTabPPAmount = $numberTabInfo['player_pair_amount'] + $data['player_pair_amount'];
|
||||
|
||||
//对冲
|
||||
// $difference = abs(round(($curNumberTabBankerAmount - $curNumberTabPlayerAmount),2));
|
||||
// if($difference > $limitMoneyArray[1] || $curNumberTabTieAmount > $limitMoneyTieArray[1] || $curNumberTabBPAmount > $limitMoneyPairArray[1] || $curNumberTabPPAmount > $limitMoneyPairArray[1]){
|
||||
// $ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
||||
// SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
// return;
|
||||
// }
|
||||
// 桌台
|
||||
if($totalBankerAmount > $limitMoneyArray[1] || $totalPlayerAmount > $limitMoneyArray[1] || $totalTieAmount > $limitMoneyTieArray[1] || $totalBPAmount > $limitMoneyPairArray[1] || $totalPPAmount > $limitMoneyPairArray[1]){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
if(($totalBankerAmount > 0 && $totalBankerAmount < $limitMoneyArray[0]) || ($totalPlayerAmount > 0 && $totalPlayerAmount < $limitMoneyArray[0]) || ($totalTieAmount > 0 && $totalTieAmount < $limitMoneyTieArray[0]) || ($totalBPAmount > 0 && $totalBPAmount < $limitMoneyPairArray[0]) || ($totalPPAmount > 0 && $totalPPAmount < $limitMoneyPairArray[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 && $curNumberTabBankerAmount > $tableInfo['limit_money_total']) || ($tableInfo['limit_money_total'] > 0 && $curNumberTabPlayerAmount > $tableInfo['limit_money_total']) || ($tableInfo['limit_money_tie_total'] > 0 && $curNumberTabTieAmount > $tableInfo['limit_money_tie_total']) || ($tableInfo['limit_money_pair_total'] > 0 && $curNumberTabBPAmount > $tableInfo['limit_money_pair_total']) || ($tableInfo['limit_money_pair_total'] > 0 && $curNumberTabPPAmount > $tableInfo['limit_money_pair_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,$baccaratType);
|
||||
if($res){
|
||||
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'user_id' => $userInfo['id'], 'manager_id' => $userInfo['manager_id'] ,'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
|
||||
if($userInfo['bet_type'] == 2){
|
||||
$tableManager = app('swoole.table.manager');
|
||||
$managerSession = $tableManager->get((string) $userInfo['manager_id']);
|
||||
if ($managerSession && is_array($managerSession)){
|
||||
$ws->setSender(0)->to($managerSession['fd'])->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'user_id' => $userInfo['id'], 'manager_id' => $userInfo['manager_id'] ,'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
|
||||
}
|
||||
}
|
||||
$round = array(
|
||||
'banker_amount' => intval($numberTabInfo['banker_amount'] + $data['banker_amount']),
|
||||
'player_amount' => intval($numberTabInfo['player_amount'] + $data['player_amount']),
|
||||
'tie_amount' => intval($numberTabInfo['tie_amount'] + $data['tie_amount']),
|
||||
'banker_pair_amount' => intval($numberTabInfo['banker_pair_amount'] + $data['banker_pair_amount']),
|
||||
'player_pair_amount' => intval($numberTabInfo['player_pair_amount'] + $data['player_pair_amount']),
|
||||
'luck_six_amount' => intval($numberTabInfo['luck_six_amount'] + $data['luck_six_amount']),
|
||||
'big_amount' => intval($numberTabInfo['big_amount'] + $data['big_amount']),
|
||||
'small_amount' => intval($numberTabInfo['small_amount'] + $data['small_amount']),
|
||||
'amount_item' => array(
|
||||
'banker_amount' => intval($data['banker_amount']),
|
||||
'player_amount' => intval($data['player_amount']),
|
||||
'tie_amount' => intval($data['tie_amount']),
|
||||
'banker_pair_amount' => intval($data['banker_pair_amount']),
|
||||
'player_pair_amount' => intval($data['player_pair_amount']),
|
||||
'luck_six_amount' => intval($data['luck_six_amount']),
|
||||
'big_amount' => intval($data['big_amount']),
|
||||
'small_amount' => intval($data['small_amount']),
|
||||
'user_id' => $userInfo['id'],
|
||||
),
|
||||
);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
}else{
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\models\user\Session;
|
||||
|
||||
class ToBetCommonService
|
||||
{
|
||||
/**
|
||||
* TODO toBet检验
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $event socket属性
|
||||
* @param array $data 下注信息
|
||||
* @return array
|
||||
*/
|
||||
public static function toBetCheck(array $tableInfo, array $event, array $data): array
|
||||
{
|
||||
/** 通用检验重复部分开始 */
|
||||
$amount = array_sum($data);
|
||||
if ($amount == 0){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_6'];
|
||||
}
|
||||
$numberTabId = isset($event['number_tab_id']) && intval($event['number_tab_id']) > 0 ? intval($event['number_tab_id']) : 0;
|
||||
$userId = isset($event['user_id']) && intval($event['user_id']) > 0 ? intval($event['user_id']) : 0;
|
||||
$userInfo = User::get(['id' => $userId, 'status' => 1, 'is_delete' => 0]);
|
||||
if (!$userInfo) return ['status' => false, 'msg' => 'to_bet_fail_2'];
|
||||
if($userInfo['bet_type'] == 2){
|
||||
$session_id = $userInfo['api_token'];
|
||||
$sessionInfo = Session::get(['session_id' => $session_id]);
|
||||
if(!$sessionInfo){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_9'];
|
||||
}
|
||||
if(!$sessionInfo['server_status']){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_10'];
|
||||
}
|
||||
}
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if ($numberTabInfo['id'] != $numberTabId){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_5'];
|
||||
}
|
||||
if ($numberTabInfo['bet_status'] != 1 || time() > ($numberTabInfo['bet_start_time'] + $tableInfo['wait_time'])){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_4'];
|
||||
}
|
||||
// 超过50局幸运6禁止下注
|
||||
if ($numberTabInfo['number'] > 50 && isset($event['luck_six_amount']) && $event['luck_six_amount'] > 0){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_7'];
|
||||
}
|
||||
// 超过30局大小禁止下注
|
||||
if ($numberTabInfo['number'] > 30 && isset($event['big_amount']) && $event['big_amount'] > 0){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_8'];
|
||||
}
|
||||
if ($numberTabInfo['number'] > 30 && isset($event['small_amount']) && $event['small_amount'] > 0){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_8'];
|
||||
}
|
||||
if($userInfo['win_limit'] > 0){
|
||||
$winTotalToday = Bet::getWinTotalToday($userInfo['id']);
|
||||
if($winTotalToday >= $userInfo['win_limit']){
|
||||
return ['status' => false, 'msg' => 'win_limit_tip'];
|
||||
}
|
||||
}
|
||||
if ($userInfo['money'] < $amount){
|
||||
return ['status' => false, 'msg' => 'to_bet_fail_1'];
|
||||
}
|
||||
return ['status' => true, 'numberTabInfo' => $numberTabInfo, 'userInfo' => $userInfo];
|
||||
/** 通用检验重复部分结束 */
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
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){
|
||||
$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){
|
||||
$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{
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToBetDtService
|
||||
* Class ToBetDtService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToBetDtService
|
||||
{
|
||||
/**
|
||||
* TODO 处理toBetDt
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toBetDt(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$data = array();
|
||||
$data['banker_amount'] = isset($event['banker_amount']) && intval($event['banker_amount']) > 0 ? intval($event['banker_amount']) : 0;
|
||||
$data['player_amount'] = isset($event['player_amount']) && intval($event['player_amount']) > 0 ? intval($event['player_amount']) : 0;
|
||||
$data['tie_amount'] = isset($event['tie_amount']) && intval($event['tie_amount']) > 0 ? intval($event['tie_amount']) : 0;
|
||||
$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){
|
||||
$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);
|
||||
|
||||
/***** User Limit Start *****/
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
$betTotalAmount = [];
|
||||
if($prevBetInfo){
|
||||
$betTotalAmount['banker_amount'] = $prevBetInfo['banker_amount'] + $data['banker_amount'];
|
||||
$betTotalAmount['player_amount'] = $prevBetInfo['player_amount'] + $data['player_amount'];
|
||||
$betTotalAmount['tie_amount'] = $prevBetInfo['tie_amount'] + $data['tie_amount'];
|
||||
}else{
|
||||
$betTotalAmount = $data;
|
||||
}
|
||||
if($betTotalAmount['banker_amount'] > $userInfo['limit_high'] || $betTotalAmount['player_amount'] > $userInfo['limit_high'] || $betTotalAmount['tie_amount'] > $userInfo['limit_high_tie']){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_user']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
if(($betTotalAmount['banker_amount'] > 0 && $betTotalAmount['banker_amount'] < $userInfo['limit_low']) || ($betTotalAmount['player_amount'] > 0 && $betTotalAmount['player_amount'] < $userInfo['limit_low']) || ($betTotalAmount['tie_amount'] > 0 && $betTotalAmount['tie_amount'] < $userInfo['limit_low_tie'])){
|
||||
$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 *****/
|
||||
$limitMoneyArray = explode('-',$tableInfo['limit_money']);
|
||||
$limitMoneyTieArray = explode('-',$tableInfo['limit_money_tie']);
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
if($prevBetInfo){
|
||||
$totalBankerAmount = $prevBetInfo['banker_amount'] + $data['banker_amount'];
|
||||
$totalPlayerAmount = $prevBetInfo['player_amount'] + $data['player_amount'];
|
||||
$totalTieAmount = $prevBetInfo['tie_amount'] + $data['tie_amount'];
|
||||
}else{
|
||||
$totalBankerAmount = $data['banker_amount'];
|
||||
$totalPlayerAmount = $data['player_amount'];
|
||||
$totalTieAmount = $data['tie_amount'];
|
||||
}
|
||||
$curNumberTabBankerAmount = $numberTabInfo['banker_amount'] + $data['banker_amount'];
|
||||
$curNumberTabPlayerAmount = $numberTabInfo['player_amount'] + $data['player_amount'];
|
||||
$curNumberTabTieAmount = $numberTabInfo['tie_amount'] + $data['tie_amount'];
|
||||
//
|
||||
// $difference = abs(round(($curNumberTabBankerAmount - $curNumberTabPlayerAmount),2));
|
||||
// if($difference > $limitMoneyArray[1] || $curNumberTabTieAmount > $limitMoneyTieArray[1]){
|
||||
// $ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
||||
// SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
// return;
|
||||
// }
|
||||
|
||||
if($totalBankerAmount > $limitMoneyArray[1] || $totalPlayerAmount > $limitMoneyArray[1] || $totalTieAmount > $limitMoneyTieArray[1]){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
if(($totalBankerAmount > 0 && $totalBankerAmount < $limitMoneyArray[0]) || ($totalPlayerAmount > 0 && $totalPlayerAmount < $limitMoneyArray[0]) || ($totalTieAmount > 0 && $totalTieAmount < $limitMoneyTieArray[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 && $curNumberTabBankerAmount > $tableInfo['limit_money_total']) || ($tableInfo['limit_money_total'] > 0 && $curNumberTabPlayerAmount > $tableInfo['limit_money_total']) || ($tableInfo['limit_money_tie_total'] > 0 && $curNumberTabTieAmount > $tableInfo['limit_money_tie_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);
|
||||
if($res){
|
||||
$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']);
|
||||
if($userInfo['bet_type'] == 2){
|
||||
$tableManager = app('swoole.table.manager');
|
||||
$managerSession = $tableManager->get((string) $userInfo['manager_id']);
|
||||
if ($managerSession && is_array($managerSession)){
|
||||
$ws->setSender(0)->to($managerSession['fd'])->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'user_id' => $userInfo['id'], 'manager_id' => $userInfo['manager_id'] ,'bet_amount_msg' => $betTotalAmount, 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
|
||||
}
|
||||
}
|
||||
$round = array(
|
||||
'banker_amount' => intval($numberTabInfo['banker_amount'] + $data['banker_amount']),
|
||||
'player_amount' => intval($numberTabInfo['player_amount'] + $data['player_amount']),
|
||||
'tie_amount' => intval($numberTabInfo['tie_amount'] + $data['tie_amount']),
|
||||
'amount_item' => array(
|
||||
'banker_amount' => intval($data['banker_amount']),
|
||||
'player_amount' => intval($data['player_amount']),
|
||||
'tie_amount' => intval($data['tie_amount']),
|
||||
'user_id' => $userInfo['id'],
|
||||
),
|
||||
);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
}else{
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToBetNnService
|
||||
* Class ToBetNnService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToBetNnService
|
||||
{
|
||||
/**
|
||||
* TODO 处理toBetNn
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toBetNn(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$data = array();
|
||||
|
||||
$data['amount_player_1'] = isset($event['amount_player_1']) && intval($event['amount_player_1']) > 0 ? intval($event['amount_player_1']) : 0;
|
||||
$data['amount_player_1_times'] = isset($event['amount_player_1_times']) && intval($event['amount_player_1_times']) > 0 ? intval($event['amount_player_1_times']) : 0;
|
||||
$data['withhold_player_1_times'] = $data['amount_player_1_times'] * 4;
|
||||
$data['amount_player_1_banker'] = isset($event['amount_player_1_banker']) && intval($event['amount_player_1_banker']) > 0 ? intval($event['amount_player_1_banker']) : 0;
|
||||
$data['amount_player_1_banker_times'] = isset($event['amount_player_1_banker_times']) && intval($event['amount_player_1_banker_times']) > 0 ? intval($event['amount_player_1_banker_times']) : 0;
|
||||
$data['withhold_player_1_banker_times'] = $data['amount_player_1_banker_times'] * 4;
|
||||
|
||||
$data['amount_player_2'] = isset($event['amount_player_2']) && intval($event['amount_player_2']) > 0 ? intval($event['amount_player_2']) : 0;
|
||||
$data['amount_player_2_times'] = isset($event['amount_player_2_times']) && intval($event['amount_player_2_times']) > 0 ? intval($event['amount_player_2_times']) : 0;
|
||||
$data['withhold_player_2_times'] = $data['amount_player_2_times'] * 4;
|
||||
$data['amount_player_2_banker'] = isset($event['amount_player_2_banker']) && intval($event['amount_player_2_banker']) > 0 ? intval($event['amount_player_2_banker']) : 0;
|
||||
$data['amount_player_2_banker_times'] = isset($event['amount_player_2_banker_times']) && intval($event['amount_player_2_banker_times']) > 0 ? intval($event['amount_player_2_banker_times']) : 0;
|
||||
$data['withhold_player_2_banker_times'] = $data['amount_player_2_banker_times'] * 4;
|
||||
|
||||
$data['amount_player_3'] = isset($event['amount_player_3']) && intval($event['amount_player_3']) > 0 ? intval($event['amount_player_3']) : 0;
|
||||
$data['amount_player_3_times'] = isset($event['amount_player_3_times']) && intval($event['amount_player_3_times']) > 0 ? intval($event['amount_player_3_times']) : 0;
|
||||
$data['withhold_player_3_times'] = $data['amount_player_3_times'] * 4;
|
||||
$data['amount_player_3_banker'] = isset($event['amount_player_3_banker']) && intval($event['amount_player_3_banker']) > 0 ? intval($event['amount_player_3_banker']) : 0;
|
||||
$data['amount_player_3_banker_times'] = isset($event['amount_player_3_banker_times']) && intval($event['amount_player_3_banker_times']) > 0 ? intval($event['amount_player_3_banker_times']) : 0;
|
||||
$data['withhold_player_3_banker_times'] = $data['amount_player_3_banker_times'] * 4;
|
||||
$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){
|
||||
$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);
|
||||
|
||||
/***** User Limit Start *****/
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
$betTotalAmount = [];
|
||||
if($prevBetInfo){
|
||||
$betTotalAmount['amount_player_1'] = $prevBetInfo['amount_player_1'] + $data['amount_player_1'];
|
||||
$betTotalAmount['amount_player_2'] = $prevBetInfo['amount_player_2'] + $data['amount_player_2'];
|
||||
$betTotalAmount['amount_player_3'] = $prevBetInfo['amount_player_3'] + $data['amount_player_3'];
|
||||
|
||||
$betTotalAmount['amount_player_1_times'] = $prevBetInfo['amount_player_1_times'] + $data['amount_player_1_times'];
|
||||
$betTotalAmount['amount_player_2_times'] = $prevBetInfo['amount_player_2_times'] + $data['amount_player_2_times'];
|
||||
$betTotalAmount['amount_player_3_times'] = $prevBetInfo['amount_player_3_times'] + $data['amount_player_3_times'];
|
||||
|
||||
$betTotalAmount['withhold_player_1_times'] = $prevBetInfo['withhold_player_1_times'] + $data['withhold_player_1_times'];
|
||||
$betTotalAmount['withhold_player_2_times'] = $prevBetInfo['withhold_player_2_times'] + $data['withhold_player_2_times'];
|
||||
$betTotalAmount['withhold_player_3_times'] = $prevBetInfo['withhold_player_3_times'] + $data['withhold_player_3_times'];
|
||||
|
||||
$betTotalAmount['amount_player_1_banker'] = $prevBetInfo['amount_player_1_banker'] + $data['amount_player_1_banker'];
|
||||
$betTotalAmount['amount_player_2_banker'] = $prevBetInfo['amount_player_2_banker'] + $data['amount_player_2_banker'];
|
||||
$betTotalAmount['amount_player_3_banker'] = $prevBetInfo['amount_player_3_banker'] + $data['amount_player_3_banker'];
|
||||
|
||||
$betTotalAmount['amount_player_1_banker_times'] = $prevBetInfo['amount_player_1_banker_times'] + $data['amount_player_1_banker_times'];
|
||||
$betTotalAmount['amount_player_2_banker_times'] = $prevBetInfo['amount_player_2_banker_times'] + $data['amount_player_2_banker_times'];
|
||||
$betTotalAmount['amount_player_3_banker_times'] = $prevBetInfo['amount_player_3_banker_times'] + $data['amount_player_3_banker_times'];
|
||||
|
||||
$betTotalAmount['withhold_player_1_banker_times'] = $prevBetInfo['withhold_player_1_banker_times'] + $data['withhold_player_1_banker_times'];
|
||||
$betTotalAmount['withhold_player_2_banker_times'] = $prevBetInfo['withhold_player_2_banker_times'] + $data['withhold_player_2_banker_times'];
|
||||
$betTotalAmount['withhold_player_3_banker_times'] = $prevBetInfo['withhold_player_3_banker_times'] + $data['withhold_player_3_banker_times'];
|
||||
}else{
|
||||
$betTotalAmount = $data;
|
||||
}
|
||||
$withholdKeys = [
|
||||
'withhold_player_1_times',
|
||||
'withhold_player_2_times',
|
||||
'withhold_player_3_times',
|
||||
'withhold_player_1_banker_times',
|
||||
'withhold_player_2_banker_times',
|
||||
'withhold_player_3_banker_times',
|
||||
];
|
||||
foreach ($betTotalAmount AS $k => $v){
|
||||
if ($v > $userInfo['limit_high'] && !in_array($k,$withholdKeys)){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_user']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach ($betTotalAmount AS $k => $v){
|
||||
if ($v > 0 && $v < $userInfo['limit_low'] && !in_array($k,$withholdKeys)){
|
||||
$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 *****/
|
||||
$limitMoneyArray = explode('-',$tableInfo['limit_money']);
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
if($prevBetInfo){
|
||||
$total_player_1 = $prevBetInfo['amount_player_1'] + $data['amount_player_1'];
|
||||
$total_player_2 = $prevBetInfo['amount_player_2'] + $data['amount_player_2'];
|
||||
$total_player_3 = $prevBetInfo['amount_player_3'] + $data['amount_player_3'];
|
||||
|
||||
$total_player_1_times = $prevBetInfo['amount_player_1_times'] + $data['amount_player_1_times'];
|
||||
$total_player_2_times = $prevBetInfo['amount_player_2_times'] + $data['amount_player_2_times'];
|
||||
$total_player_3_times = $prevBetInfo['amount_player_3_times'] + $data['amount_player_3_times'];
|
||||
|
||||
$total_player_1_withhold = $prevBetInfo['withhold_player_1_times'] + $data['withhold_player_1_times'];
|
||||
$total_player_2_withhold = $prevBetInfo['withhold_player_2_times'] + $data['withhold_player_2_times'];
|
||||
$total_player_3_withhold = $prevBetInfo['withhold_player_3_times'] + $data['withhold_player_3_times'];
|
||||
|
||||
$total_player_1_banker = $prevBetInfo['amount_player_1_banker'] + $data['amount_player_1_banker'];
|
||||
$total_player_2_banker = $prevBetInfo['amount_player_2_banker'] + $data['amount_player_2_banker'];
|
||||
$total_player_3_banker = $prevBetInfo['amount_player_3_banker'] + $data['amount_player_3_banker'];
|
||||
|
||||
$total_player_1_banker_times = $prevBetInfo['amount_player_1_banker_times'] + $data['amount_player_1_banker_times'];
|
||||
$total_player_2_banker_times = $prevBetInfo['amount_player_2_banker_times'] + $data['amount_player_2_banker_times'];
|
||||
$total_player_3_banker_times = $prevBetInfo['amount_player_3_banker_times'] + $data['amount_player_3_banker_times'];
|
||||
|
||||
$total_player_1_banker_times_withhold = $prevBetInfo['withhold_player_1_banker_times'] + $data['withhold_player_1_banker_times'];
|
||||
$total_player_2_banker_times_withhold = $prevBetInfo['withhold_player_2_banker_times'] + $data['withhold_player_2_banker_times'];
|
||||
$total_player_3_banker_times_withhold = $prevBetInfo['withhold_player_3_banker_times'] + $data['withhold_player_3_banker_times'];
|
||||
|
||||
}else{
|
||||
$total_player_1 = $data['amount_player_1'];
|
||||
$total_player_2 = $data['amount_player_2'];
|
||||
$total_player_3 = $data['amount_player_3'];
|
||||
|
||||
$total_player_1_times = $data['amount_player_1_times'];
|
||||
$total_player_2_times = $data['amount_player_2_times'];
|
||||
$total_player_3_times = $data['amount_player_3_times'];
|
||||
|
||||
$total_player_1_withhold = $data['withhold_player_1_times'];
|
||||
$total_player_2_withhold = $data['withhold_player_2_times'];
|
||||
$total_player_3_withhold = $data['withhold_player_3_times'];
|
||||
|
||||
$total_player_1_banker = $data['amount_player_1_banker'];
|
||||
$total_player_2_banker = $data['amount_player_2_banker'];
|
||||
$total_player_3_banker = $data['amount_player_3_banker'];
|
||||
|
||||
$total_player_1_banker_times = $data['amount_player_1_banker_times'];
|
||||
$total_player_2_banker_times = $data['amount_player_2_banker_times'];
|
||||
$total_player_3_banker_times = $data['amount_player_3_banker_times'];
|
||||
|
||||
$total_player_1_banker_times_withhold = $data['withhold_player_1_banker_times'];
|
||||
$total_player_2_banker_times_withhold = $data['withhold_player_2_banker_times'];
|
||||
$total_player_3_banker_times_withhold = $data['withhold_player_3_banker_times'];
|
||||
}
|
||||
|
||||
if($total_player_1 > $limitMoneyArray[1] || $total_player_2 > $limitMoneyArray[1] || $total_player_3 > $limitMoneyArray[1] || $total_player_1_times > $limitMoneyArray[1] || $total_player_2_times > $limitMoneyArray[1] || $total_player_3_times > $limitMoneyArray[1] || $total_player_1_banker > $limitMoneyArray[1] || $total_player_2_banker > $limitMoneyArray[1] || $total_player_3_banker > $limitMoneyArray[1] || $total_player_1_banker_times > $limitMoneyArray[1] || $total_player_2_banker_times > $limitMoneyArray[1] || $total_player_3_banker_times > $limitMoneyArray[1] ){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
if(($total_player_1 > 0 && $total_player_1 < $limitMoneyArray[0]) || ($total_player_2 > 0 && $total_player_2 < $limitMoneyArray[0]) || ($total_player_3 > 0 && $total_player_3 < $limitMoneyArray[0]) || ($total_player_1_times > 0 && $total_player_1_times < $limitMoneyArray[0]) || ($total_player_2_times > 0 && $total_player_2_times < $limitMoneyArray[0]) || ($total_player_3_times > 0 && $total_player_3_times < $limitMoneyArray[0]) || ($total_player_1_banker > 0 && $total_player_1_banker < $limitMoneyArray[0]) || ($total_player_2_banker > 0 && $total_player_2_banker < $limitMoneyArray[0]) || ($total_player_3_banker > 0 && $total_player_3_banker < $limitMoneyArray[0]) || ($total_player_1_banker_times > 0 && $total_player_1_banker_times < $limitMoneyArray[0]) || ($total_player_2_banker_times > 0 && $total_player_2_banker_times < $limitMoneyArray[0]) || ($total_player_3_banker_times > 0 && $total_player_3_banker_times < $limitMoneyArray[0])){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'under_limit_table']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
/***** Table Limit End *****/
|
||||
|
||||
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
|
||||
if($res){
|
||||
$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']);
|
||||
// 待确定是否推送即时彩池,现不推送
|
||||
}else{
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use freedom\utils\RouletteUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToBetRouletteService
|
||||
* Class ToBetRouletteService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
|
||||
class ToBetRouletteService{
|
||||
|
||||
/**
|
||||
* TODO 处理轮盘下注
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toBetRoulette(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$data = array();
|
||||
$event_amount = $event['amount'];
|
||||
$fieldName = 'roulette_'.$event['roulette_type'].'_amount';
|
||||
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){
|
||||
$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[$fieldName]);
|
||||
$betTotalAmount = RouletteUtil::amountInc($beforeAmount, $data);
|
||||
}else{
|
||||
$betTotalAmount = $data;
|
||||
}
|
||||
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0,$fieldName);
|
||||
$numberTabAmount = string_to_array($numberTabInfo[$fieldName]);
|
||||
if($res){
|
||||
$ws->emit('toBet',['status' => true, 'table_id' => $tableInfo['id'], 'bet_amount_msg' => [$fieldName => $betTotalAmount], 'money' => ($userInfo['money'] - $amount),'seat_num' => $seat_num, 'msg' => 'to_bet_success']);
|
||||
$totalAmountArray = RouletteUtil::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{
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToBetTcService
|
||||
* Class ToBetTcService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToBetTcService
|
||||
{
|
||||
/**
|
||||
* TODO 处理toBetTc
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toBetTc(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$data = array();
|
||||
|
||||
$data['amount_player_1'] = isset($event['amount_player_1']) && intval($event['amount_player_1']) > 0 ? intval($event['amount_player_1']) : 0;
|
||||
$data['amount_player_1_times'] = isset($event['amount_player_1_times']) && intval($event['amount_player_1_times']) > 0 ? intval($event['amount_player_1_times']) : 0;
|
||||
$data['withhold_player_1_times'] = $data['amount_player_1_times'] * 19;
|
||||
$data['amount_player_1_banker'] = isset($event['amount_player_1_banker']) && intval($event['amount_player_1_banker']) > 0 ? intval($event['amount_player_1_banker']) : 0;
|
||||
$data['amount_player_1_banker_times'] = isset($event['amount_player_1_banker_times']) && intval($event['amount_player_1_banker_times']) > 0 ? intval($event['amount_player_1_banker_times']) : 0;
|
||||
$data['withhold_player_1_banker_times'] = $data['amount_player_1_banker_times'] * 19;
|
||||
|
||||
$data['amount_player_2'] = isset($event['amount_player_2']) && intval($event['amount_player_2']) > 0 ? intval($event['amount_player_2']) : 0;
|
||||
$data['amount_player_2_times'] = isset($event['amount_player_2_times']) && intval($event['amount_player_2_times']) > 0 ? intval($event['amount_player_2_times']) : 0;
|
||||
$data['withhold_player_2_times'] = $data['amount_player_2_times'] * 19;
|
||||
$data['amount_player_2_banker'] = isset($event['amount_player_2_banker']) && intval($event['amount_player_2_banker']) > 0 ? intval($event['amount_player_2_banker']) : 0;
|
||||
$data['amount_player_2_banker_times'] = isset($event['amount_player_2_banker_times']) && intval($event['amount_player_2_banker_times']) > 0 ? intval($event['amount_player_2_banker_times']) : 0;
|
||||
$data['withhold_player_2_banker_times'] = $data['amount_player_2_banker_times'] * 19;
|
||||
|
||||
$data['amount_player_3'] = isset($event['amount_player_3']) && intval($event['amount_player_3']) > 0 ? intval($event['amount_player_3']) : 0;
|
||||
$data['amount_player_3_times'] = isset($event['amount_player_3_times']) && intval($event['amount_player_3_times']) > 0 ? intval($event['amount_player_3_times']) : 0;
|
||||
$data['withhold_player_3_times'] = $data['amount_player_3_times'] * 19;
|
||||
$data['amount_player_3_banker'] = isset($event['amount_player_3_banker']) && intval($event['amount_player_3_banker']) > 0 ? intval($event['amount_player_3_banker']) : 0;
|
||||
$data['amount_player_3_banker_times'] = isset($event['amount_player_3_banker_times']) && intval($event['amount_player_3_banker_times']) > 0 ? intval($event['amount_player_3_banker_times']) : 0;
|
||||
$data['withhold_player_3_banker_times'] = $data['amount_player_3_banker_times'] * 19;
|
||||
|
||||
$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){
|
||||
$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);
|
||||
|
||||
/***** User Limit Start *****/
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
$betTotalAmount = [];
|
||||
if($prevBetInfo){
|
||||
$betTotalAmount['amount_player_1'] = $prevBetInfo['amount_player_1'] + $data['amount_player_1'];
|
||||
$betTotalAmount['amount_player_2'] = $prevBetInfo['amount_player_2'] + $data['amount_player_2'];
|
||||
$betTotalAmount['amount_player_3'] = $prevBetInfo['amount_player_3'] + $data['amount_player_3'];
|
||||
|
||||
$betTotalAmount['amount_player_1_times'] = $prevBetInfo['amount_player_1_times'] + $data['amount_player_1_times'];
|
||||
$betTotalAmount['amount_player_2_times'] = $prevBetInfo['amount_player_2_times'] + $data['amount_player_2_times'];
|
||||
$betTotalAmount['amount_player_3_times'] = $prevBetInfo['amount_player_3_times'] + $data['amount_player_3_times'];
|
||||
|
||||
$betTotalAmount['withhold_player_1_times'] = $prevBetInfo['withhold_player_1_times'] + $data['withhold_player_1_times'];
|
||||
$betTotalAmount['withhold_player_2_times'] = $prevBetInfo['withhold_player_2_times'] + $data['withhold_player_2_times'];
|
||||
$betTotalAmount['withhold_player_3_times'] = $prevBetInfo['withhold_player_3_times'] + $data['withhold_player_3_times'];
|
||||
|
||||
$betTotalAmount['amount_player_1_banker'] = $prevBetInfo['amount_player_1_banker'] + $data['amount_player_1_banker'];
|
||||
$betTotalAmount['amount_player_2_banker'] = $prevBetInfo['amount_player_2_banker'] + $data['amount_player_2_banker'];
|
||||
$betTotalAmount['amount_player_3_banker'] = $prevBetInfo['amount_player_3_banker'] + $data['amount_player_3_banker'];
|
||||
|
||||
$betTotalAmount['amount_player_1_banker_times'] = $prevBetInfo['amount_player_1_banker_times'] + $data['amount_player_1_banker_times'];
|
||||
$betTotalAmount['amount_player_2_banker_times'] = $prevBetInfo['amount_player_2_banker_times'] + $data['amount_player_2_banker_times'];
|
||||
$betTotalAmount['amount_player_3_banker_times'] = $prevBetInfo['amount_player_3_banker_times'] + $data['amount_player_3_banker_times'];
|
||||
|
||||
$betTotalAmount['withhold_player_1_banker_times'] = $prevBetInfo['withhold_player_1_banker_times'] + $data['withhold_player_1_banker_times'];
|
||||
$betTotalAmount['withhold_player_2_banker_times'] = $prevBetInfo['withhold_player_2_banker_times'] + $data['withhold_player_2_banker_times'];
|
||||
$betTotalAmount['withhold_player_3_banker_times'] = $prevBetInfo['withhold_player_3_banker_times'] + $data['withhold_player_3_banker_times'];
|
||||
}else{
|
||||
$betTotalAmount = $data;
|
||||
}
|
||||
$withholdKeys = [
|
||||
'withhold_player_1_times',
|
||||
'withhold_player_2_times',
|
||||
'withhold_player_3_times',
|
||||
'withhold_player_1_banker_times',
|
||||
'withhold_player_2_banker_times',
|
||||
'withhold_player_3_banker_times',
|
||||
];
|
||||
foreach ($betTotalAmount AS $k => $v){
|
||||
if ($v > $userInfo['limit_high'] && !in_array($k,$withholdKeys)){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_user']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
}
|
||||
foreach ($betTotalAmount AS $k => $v){
|
||||
if ($v > 0 && $v < $userInfo['limit_low'] && !in_array($k,$withholdKeys)){
|
||||
$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 *****/
|
||||
$limitMoneyArray = explode('-',$tableInfo['limit_money']);
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
if($prevBetInfo){
|
||||
$total_player_1 = $prevBetInfo['amount_player_1'] + $data['amount_player_1'];
|
||||
$total_player_2 = $prevBetInfo['amount_player_2'] + $data['amount_player_2'];
|
||||
$total_player_3 = $prevBetInfo['amount_player_3'] + $data['amount_player_3'];
|
||||
|
||||
$total_player_1_times = $prevBetInfo['amount_player_1_times'] + $data['amount_player_1_times'];
|
||||
$total_player_2_times = $prevBetInfo['amount_player_2_times'] + $data['amount_player_2_times'];
|
||||
$total_player_3_times = $prevBetInfo['amount_player_3_times'] + $data['amount_player_3_times'];
|
||||
|
||||
$total_player_1_withhold = $prevBetInfo['withhold_player_1_times'] + $data['withhold_player_1_times'];
|
||||
$total_player_2_withhold = $prevBetInfo['withhold_player_2_times'] + $data['withhold_player_2_times'];
|
||||
$total_player_3_withhold = $prevBetInfo['withhold_player_3_times'] + $data['withhold_player_3_times'];
|
||||
|
||||
$total_player_1_banker = $prevBetInfo['amount_player_1_banker'] + $data['amount_player_1_banker'];
|
||||
$total_player_2_banker = $prevBetInfo['amount_player_2_banker'] + $data['amount_player_2_banker'];
|
||||
$total_player_3_banker = $prevBetInfo['amount_player_3_banker'] + $data['amount_player_3_banker'];
|
||||
|
||||
$total_player_1_banker_times = $prevBetInfo['amount_player_1_banker_times'] + $data['amount_player_1_banker_times'];
|
||||
$total_player_2_banker_times = $prevBetInfo['amount_player_2_banker_times'] + $data['amount_player_2_banker_times'];
|
||||
$total_player_3_banker_times = $prevBetInfo['amount_player_3_banker_times'] + $data['amount_player_3_banker_times'];
|
||||
|
||||
$total_player_1_banker_times_withhold = $prevBetInfo['withhold_player_1_banker_times'] + $data['withhold_player_1_banker_times'];
|
||||
$total_player_2_banker_times_withhold = $prevBetInfo['withhold_player_2_banker_times'] + $data['withhold_player_2_banker_times'];
|
||||
$total_player_3_banker_times_withhold = $prevBetInfo['withhold_player_3_banker_times'] + $data['withhold_player_3_banker_times'];
|
||||
|
||||
}else{
|
||||
$total_player_1 = $data['amount_player_1'];
|
||||
$total_player_2 = $data['amount_player_2'];
|
||||
$total_player_3 = $data['amount_player_3'];
|
||||
|
||||
$total_player_1_times = $data['amount_player_1_times'];
|
||||
$total_player_2_times = $data['amount_player_2_times'];
|
||||
$total_player_3_times = $data['amount_player_3_times'];
|
||||
|
||||
$total_player_1_withhold = $data['withhold_player_1_times'];
|
||||
$total_player_2_withhold = $data['withhold_player_2_times'];
|
||||
$total_player_3_withhold = $data['withhold_player_3_times'];
|
||||
|
||||
$total_player_1_banker = $data['amount_player_1_banker'];
|
||||
$total_player_2_banker = $data['amount_player_2_banker'];
|
||||
$total_player_3_banker = $data['amount_player_3_banker'];
|
||||
|
||||
$total_player_1_banker_times = $data['amount_player_1_banker_times'];
|
||||
$total_player_2_banker_times = $data['amount_player_2_banker_times'];
|
||||
$total_player_3_banker_times = $data['amount_player_3_banker_times'];
|
||||
|
||||
$total_player_1_banker_times_withhold = $data['withhold_player_1_banker_times'];
|
||||
$total_player_2_banker_times_withhold = $data['withhold_player_2_banker_times'];
|
||||
$total_player_3_banker_times_withhold = $data['withhold_player_3_banker_times'];
|
||||
}
|
||||
|
||||
if($total_player_1 > $limitMoneyArray[1] || $total_player_2 > $limitMoneyArray[1] || $total_player_3 > $limitMoneyArray[1] || $total_player_1_times > $limitMoneyArray[1] || $total_player_2_times > $limitMoneyArray[1] || $total_player_3_times > $limitMoneyArray[1] || $total_player_1_banker > $limitMoneyArray[1] || $total_player_2_banker > $limitMoneyArray[1] || $total_player_3_banker > $limitMoneyArray[1] || $total_player_1_banker_times > $limitMoneyArray[1] || $total_player_2_banker_times > $limitMoneyArray[1] || $total_player_3_banker_times > $limitMoneyArray[1]){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'exceeds_limit_table']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
if(($total_player_1 > 0 && $total_player_1 < $limitMoneyArray[0]) || ($total_player_2 > 0 && $total_player_2 < $limitMoneyArray[0]) || ($total_player_3 > 0 && $total_player_3 < $limitMoneyArray[0]) || ($total_player_1_times > 0 && $total_player_1_times < $limitMoneyArray[0]) || ($total_player_2_times > 0 && $total_player_2_times < $limitMoneyArray[0]) || ($total_player_3_times > 0 && $total_player_3_times < $limitMoneyArray[0]) || ($total_player_1_banker > 0 && $total_player_1_banker < $limitMoneyArray[0]) || ($total_player_2_banker > 0 && $total_player_2_banker < $limitMoneyArray[0]) || ($total_player_3_banker > 0 && $total_player_3_banker < $limitMoneyArray[0]) || ($total_player_1_banker_times > 0 && $total_player_1_banker_times < $limitMoneyArray[0]) || ($total_player_2_banker_times > 0 && $total_player_2_banker_times < $limitMoneyArray[0]) || ($total_player_3_banker_times > 0 && $total_player_3_banker_times < $limitMoneyArray[0]) ){
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'under_limit_table']);
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
return;
|
||||
}
|
||||
/***** Table Limit End *****/
|
||||
|
||||
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
|
||||
if($res){
|
||||
$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']);
|
||||
// 待确定是否推送即时彩池,现不推送
|
||||
}else{
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToBetToningService
|
||||
* Class ToBetToningService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToBetToningService
|
||||
{
|
||||
/**
|
||||
* TODO 处理色碟下注
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toBetToning(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$data = array();
|
||||
$data['toning_zero'] = isset($event['toning_zero']) && intval($event['toning_zero']) > 0 ? intval($event['toning_zero']) : 0;
|
||||
$data['toning_four'] = isset($event['toning_four']) && intval($event['toning_four']) > 0 ? intval($event['toning_four']) : 0;
|
||||
$data['toning_one'] = isset($event['toning_one']) && intval($event['toning_one']) > 0 ? intval($event['toning_one']) : 0;
|
||||
$data['toning_three'] = isset($event['toning_three']) && intval($event['toning_three']) > 0 ? intval($event['toning_three']) : 0;
|
||||
$data['toning_big'] = isset($event['toning_big']) && intval($event['toning_big']) > 0 ? intval($event['toning_big']) : 0;
|
||||
$data['toning_small'] = isset($event['toning_small']) && intval($event['toning_small']) > 0 ? intval($event['toning_small']) : 0;
|
||||
$data['toning_singular'] = isset($event['toning_singular']) && intval($event['toning_singular']) > 0 ? intval($event['toning_singular']) : 0;
|
||||
$data['toning_plural'] = isset($event['toning_plural']) && intval($event['toning_plural']) > 0 ? intval($event['toning_plural']) : 0;
|
||||
$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){
|
||||
$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']);
|
||||
$betTotalAmount = [];
|
||||
if($prevBetInfo){
|
||||
$betArray = string_to_array($prevBetInfo['toning_amount']);
|
||||
$betTotalAmount['toning_zero'] = $betArray['toning_zero'] + $data['toning_zero'];
|
||||
$betTotalAmount['toning_four'] = $betArray['toning_four'] + $data['toning_four'];
|
||||
$betTotalAmount['toning_one'] = $betArray['toning_one'] + $data['toning_one'];
|
||||
$betTotalAmount['toning_three'] = $betArray['toning_three'] + $data['toning_three'];
|
||||
$betTotalAmount['toning_big'] = $betArray['toning_big'] + $data['toning_big'];
|
||||
$betTotalAmount['toning_small'] = $betArray['toning_small'] + $data['toning_small'];
|
||||
$betTotalAmount['toning_singular'] = $betArray['toning_singular'] + $data['toning_singular'];
|
||||
$betTotalAmount['toning_plural'] = $betArray['toning_plural'] + $data['toning_plural'];
|
||||
}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;
|
||||
}
|
||||
$res = Bet::toBet($tableInfo,$userInfo,$numberTabInfo,$prevBetInfo,$data,$seat_num,$betTotalAmount,$time,0);
|
||||
$numberTabAmount = string_to_array($numberTabInfo['toning_amount']);
|
||||
if($res){
|
||||
$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']);
|
||||
$round = array(
|
||||
'toning_zero' => isset($numberTabAmount['toning_zero']) ? intval($numberTabAmount['toning_zero'] + $data['toning_zero']) : $data['toning_zero'],
|
||||
'toning_four' => isset($numberTabAmount['toning_four']) ? intval($numberTabAmount['toning_four'] + $data['toning_four']) : $data['toning_four'],
|
||||
'toning_one' => isset($numberTabAmount['toning_one']) ? intval($numberTabAmount['toning_one'] + $data['toning_one']) : $data['toning_one'],
|
||||
'toning_three' => isset($numberTabAmount['toning_three']) ? intval($numberTabAmount['toning_three'] + $data['toning_three']) : $data['toning_three'],
|
||||
'toning_big' => isset($numberTabAmount['toning_big']) ? intval($numberTabAmount['toning_big'] + $data['toning_big']) : $data['toning_big'],
|
||||
'toning_small' => isset($numberTabAmount['toning_small']) ? intval($numberTabAmount['toning_small'] + $data['toning_small']) : $data['toning_small'],
|
||||
'toning_singular' => isset($numberTabAmount['toning_singular']) ? intval($numberTabAmount['toning_singular'] + $data['toning_singular']) : $data['toning_singular'],
|
||||
'toning_plural' => isset($numberTabAmount['toning_plural']) ? intval($numberTabAmount['toning_plural'] + $data['toning_plural']) : $data['toning_plural'],
|
||||
'amount_item' => array(
|
||||
'toning_zero' => $data['toning_zero'],
|
||||
'toning_four' => $data['toning_four'],
|
||||
'toning_one' => $data['toning_one'],
|
||||
'toning_three' => $data['toning_three'],
|
||||
'toning_big' => $data['toning_big'],
|
||||
'toning_small' => $data['toning_small'],
|
||||
'toning_singular' => $data['toning_singular'],
|
||||
'toning_plural' => $data['toning_plural'],
|
||||
'user_id' => $userInfo['id'],
|
||||
),
|
||||
);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('allBetAmount',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
}else{
|
||||
$ws->emit('toBet',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_bet_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToBet');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToSeatService
|
||||
* Class ToSeatService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToLeaveSeatService
|
||||
{
|
||||
/**
|
||||
* TODO 处理toSeat
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toLeaveSeat(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$numberTabId = isset($event['number_tab_id']) && intval($event['number_tab_id']) > 0 ? intval($event['number_tab_id']) : 0;
|
||||
$userId = isset($event['user_id']) && intval($event['user_id']) > 0 ? intval($event['user_id']) : 0;
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
|
||||
/** 验证是否和当前铺同一铺 */
|
||||
if ($numberTabInfo['id'] != $numberTabId){
|
||||
$ws->emit('toLeaveSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_leave_seat_fail_1']);
|
||||
SocketSession::resetRepeat($fd,'user','isToLeaveSeat');
|
||||
return;
|
||||
}
|
||||
|
||||
$userInfo = User::get(['id' => $userId, 'status' => 1, 'is_delete' => 0]);
|
||||
/** 验证会员有效 */
|
||||
if (!$userInfo || $userInfo['bet_type'] != 2){
|
||||
$ws->emit('toLeaveSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_leave_seat_fail_2']);
|
||||
SocketSession::resetRepeat($fd,'user','isToLeaveSeat');
|
||||
return;
|
||||
}
|
||||
|
||||
/** 验证本局是否下注 */
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
if($prevBetInfo){
|
||||
$ws->emit('toLeaveSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_leave_seat_fail_3']);
|
||||
SocketSession::resetRepeat($fd,'user','isToLeaveSeat');
|
||||
return;
|
||||
}
|
||||
|
||||
$res = Bet::toLeaveSeat($userInfo,$numberTabInfo);
|
||||
if ($res){
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
$table_seat_info = json_decode($numberTabInfo['seat_json'],true);
|
||||
$leaveMsg = ['user_id' => $userInfo['id'], 'manager_id' => $userInfo['manager_id']];
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('toLeaveSeat',['status' => true, 'table_id' => $tableInfo['id'],'leaveMsg' => $leaveMsg, 'table_seat_info' => $table_seat_info[$userInfo['manager_id']], 'msg' => 'to_leave_seat_success']);
|
||||
}else{
|
||||
$ws->emit('toLeaveSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_leave_seat_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToLeaveSeat');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToRobService
|
||||
* Class ToRobService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToRobService
|
||||
{
|
||||
/**
|
||||
* TODO 处理toRob
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toTob(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$numberTabId = isset($event['number_tab_id']) && intval($event['number_tab_id']) > 0 ? intval($event['number_tab_id']) : 0;
|
||||
$userId = isset($event['user_id']) && intval($event['user_id']) > 0 ? intval($event['user_id']) : 0;
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
/** 验证是否和当前铺同一铺 */
|
||||
if ($numberTabInfo['id'] != $numberTabId){
|
||||
$ws->emit('toRob',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_rob_fail_4']);
|
||||
SocketSession::resetRepeat($fd,'user','isToRob');
|
||||
return;
|
||||
}
|
||||
/** 验证是否抢庄时间 */
|
||||
if ($numberTabInfo['rob_status'] != 1 || time() > $numberTabInfo['rob_start_time'] + $tableInfo['rob_time']){
|
||||
$ws->emit('toRob',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_rob_fail_3']);
|
||||
SocketSession::resetRepeat($fd,'user','isToRob');
|
||||
return;
|
||||
}
|
||||
$userInfo = User::get(['id' => $userId, 'status' => 1, 'is_delete' => 0]);
|
||||
/** 验证会员有效 */
|
||||
if (!$userInfo){
|
||||
$ws->emit('toRob',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_rob_fail_2']);
|
||||
SocketSession::resetRepeat($fd,'user','isToRob');
|
||||
return;
|
||||
}
|
||||
/** 十万会员不能抢庄 */
|
||||
if($userInfo['is_sw'] == 1){
|
||||
$ws->emit('toRob',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_rob_fail_5']);
|
||||
SocketSession::resetRepeat($fd,'user','isToRob');
|
||||
return;
|
||||
}
|
||||
/** 会员金额必须大于桌子抢庄金额 */
|
||||
if($userInfo['money'] < $tableInfo['limit_banker_amount']){
|
||||
$ws->emit('toRob',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_rob_fail_1']);
|
||||
SocketSession::resetRepeat($fd,'user','isToRob');
|
||||
return;
|
||||
}
|
||||
/** 验证当前局是否有人已经抢庄 */
|
||||
if($numberTabInfo['rob_banker_id'] > 0){
|
||||
$ws->emit('toRob',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_rob_fail_6']);
|
||||
SocketSession::resetRepeat($fd,'user','isToRob');
|
||||
return;
|
||||
}
|
||||
$res = Bet::toRob($userInfo,$numberTabInfo);
|
||||
if ($res){
|
||||
$RobMsg = ['rob_banker_id' => $userInfo['id'], 'rob_banker_username' => $userInfo['username']];
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('toRob',['status' => true, 'table_id' => $tableInfo['id'], 'RobMsg' => $RobMsg, 'msg' => '抢庄成功']);
|
||||
}else{
|
||||
$ws->emit('toRob',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_rob_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToRob');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
namespace app\services\bet;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use freedom\utils\SocketSession;
|
||||
|
||||
/**
|
||||
* TODO ToSeatService
|
||||
* Class ToSeatService
|
||||
* @package app\services\bet
|
||||
*/
|
||||
class ToSeatService
|
||||
{
|
||||
/**
|
||||
* TODO 处理toSeat
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return void
|
||||
*/
|
||||
public static function toSeat(array $event, array $tableInfo){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$fd = $ws->getSender();
|
||||
$numberTabId = isset($event['number_tab_id']) && intval($event['number_tab_id']) > 0 ? intval($event['number_tab_id']) : 0;
|
||||
$userId = isset($event['user_id']) && intval($event['user_id']) > 0 ? intval($event['user_id']) : 0;
|
||||
$seatNum = isset($event['seat_num']) && intval($event['seat_num']) > 0 ? intval($event['seat_num']) : 0;
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
|
||||
/** 验证是否和当前铺同一 */
|
||||
if ($numberTabInfo['id'] != $numberTabId){
|
||||
$ws->emit('toSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_seat_fail_1']);
|
||||
SocketSession::resetRepeat($fd,'user','isToSeat');
|
||||
return;
|
||||
}
|
||||
|
||||
$userInfo = User::get(['id' => $userId, 'status' => 1, 'is_delete' => 0]);
|
||||
/** 验证会员有效 */
|
||||
if (!$userInfo || $userInfo['bet_type'] != 2){
|
||||
$ws->emit('toSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_seat_fail_2']);
|
||||
SocketSession::resetRepeat($fd,'user','isToSeat');
|
||||
return;
|
||||
}
|
||||
/** 验证座位号参数 */
|
||||
$table_seat_num = $tableInfo['seat_num'] >= 4 ? $tableInfo['seat_num'] + 1 : $tableInfo['seat_num'];
|
||||
if($seatNum < 1 || $seatNum > $table_seat_num){
|
||||
$ws->emit('toSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_seat_fail_3']);
|
||||
SocketSession::resetRepeat($fd,'user','isToSeat');
|
||||
return;
|
||||
}
|
||||
|
||||
$seatJson = $numberTabInfo['seat_json'];
|
||||
$seatArr = json_decode($seatJson,true);
|
||||
/** 验证座位是否有玩家 */
|
||||
if(isset($seatArr[$userInfo['manager_id']])){
|
||||
if($seatArr[$userInfo['manager_id']][$seatNum] && $seatArr[$userInfo['manager_id']][$seatNum] != $userId){
|
||||
$ws->emit('toSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_seat_fail_4']);
|
||||
SocketSession::resetRepeat($fd,'user','isToSeat');
|
||||
return;
|
||||
}
|
||||
}
|
||||
$prevBetInfo = Bet::getPrevBetInfo($userInfo['id'],$numberTabInfo['id']);
|
||||
if($prevBetInfo && $prevBetInfo['seat_num'] != $seatNum){
|
||||
$ws->emit('toSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_seat_fail_5']);
|
||||
SocketSession::resetRepeat($fd,'user','isToSeat');
|
||||
return;
|
||||
}
|
||||
|
||||
$res = Bet::toSeat($userInfo,$numberTabInfo,$tableInfo,$seatNum);
|
||||
if ($res){
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
$table_seat_info = json_decode($numberTabInfo['seat_json'],true);
|
||||
$SeatMsg = ['user_id' => $userInfo['id'], 'username' => $userInfo['username'],'manager_id' => $userInfo['manager_id'],'seat_num' => $seatNum];
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('toSeat',['status' => true, 'table_id' => $tableInfo['id'], 'SeatMsg' => $SeatMsg, 'table_seat_info' => $table_seat_info[$userInfo['manager_id']], 'msg' => 'to_seat_success']);
|
||||
}else{
|
||||
$ws->emit('toSeat',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'to_seat_fail']);
|
||||
}
|
||||
SocketSession::resetRepeat($fd,'user','isToSeat');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
<?php
|
||||
|
||||
namespace app\services\chat;
|
||||
|
||||
use app\models\chat\ChatSession;
|
||||
use app\models\chat\ChatAdminStatus;
|
||||
use think\facade\Db;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 会话分配服务
|
||||
* Class AssignService
|
||||
* @package app\services\chat
|
||||
*/
|
||||
class AssignService
|
||||
{
|
||||
// Redis Key 前缀 (specs.md Section 3)
|
||||
private const LOCK_PREFIX = 'cs:lock:assign:';
|
||||
private const ONLINE_PREFIX = 'cs:online:agent:';
|
||||
private const LOAD_PREFIX = 'cs:agent:load:';
|
||||
private const QUEUE_KEY = 'cs:queue:pending';
|
||||
private const SESSION_OWNER_PREFIX = 'cs:session:owner:';
|
||||
|
||||
// 约束参数 (specs.md CC-01~CC-04)
|
||||
private const LOCK_TTL = 3000; // 分配锁超时 3秒
|
||||
private const MAX_SESSIONS = 10; // 单客服最大会话数
|
||||
|
||||
/**
|
||||
* 分配会话给客服
|
||||
* @param int $userId 用户ID
|
||||
* @param int $sessionId 会话ID
|
||||
* @return int|null 分配的客服ID,null表示无可用客服
|
||||
*/
|
||||
public function assignSession(int $userId, int $sessionId): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$lockKey = self::LOCK_PREFIX . $userId;
|
||||
|
||||
// 1. 获取分配锁 (防止并发双分配)
|
||||
$lockValue = uniqid('', true);
|
||||
$acquired = $redis->set($lockKey, $lockValue, ['NX', 'PX' => self::LOCK_TTL]);
|
||||
|
||||
if (!$acquired) {
|
||||
// 锁被占用,检查是否已有活跃会话
|
||||
return $this->getExistingSessionAgent($userId);
|
||||
}
|
||||
|
||||
try {
|
||||
// 2. 检查用户是否已有活跃会话
|
||||
$existingAgent = $this->getExistingSessionAgent($userId);
|
||||
if ($existingAgent !== null) {
|
||||
return $existingAgent;
|
||||
}
|
||||
|
||||
// 3. 获取所有在线客服
|
||||
$onlineAgents = $this->getOnlineAgents();
|
||||
if (empty($onlineAgents)) {
|
||||
// 无在线客服,进入留言队列
|
||||
$this->addToOfflineQueue($userId, $sessionId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 4. 选择会话数最少的客服
|
||||
$selectedAgent = $this->selectLeastLoadAgent($onlineAgents);
|
||||
if ($selectedAgent === null) {
|
||||
// 所有客服已满载
|
||||
$this->addToOfflineQueue($userId, $sessionId);
|
||||
return null;
|
||||
}
|
||||
|
||||
// 5. 更新会话归属
|
||||
$this->bindSessionToAgent($sessionId, $selectedAgent);
|
||||
|
||||
// 6. 增加客服负载计数
|
||||
$redis->incr(self::LOAD_PREFIX . $selectedAgent);
|
||||
|
||||
return $selectedAgent;
|
||||
|
||||
} finally {
|
||||
// 释放锁 (仅释放自己持有的锁)
|
||||
$this->releaseLock($lockKey, $lockValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取在线客服列表
|
||||
*/
|
||||
public function getOnlineAgents(): array
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$enabledAdmins = ChatAdminStatus::getEnabledAdminIds();
|
||||
$onlineAgents = [];
|
||||
|
||||
foreach ($enabledAdmins as $adminId) {
|
||||
if ($redis->exists(self::ONLINE_PREFIX . $adminId)) {
|
||||
$onlineAgents[] = $adminId;
|
||||
}
|
||||
}
|
||||
|
||||
return $onlineAgents;
|
||||
}
|
||||
|
||||
/**
|
||||
* 选择会话数最少的客服
|
||||
*/
|
||||
public function selectLeastLoadAgent(array $onlineAgents): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$loads = [];
|
||||
|
||||
foreach ($onlineAgents as $agentId) {
|
||||
$load = (int)$redis->get(self::LOAD_PREFIX . $agentId) ?: 0;
|
||||
$maxSessions = $this->getAgentMaxSessions($agentId);
|
||||
|
||||
if ($load < $maxSessions) {
|
||||
$loads[$agentId] = $load;
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($loads)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// 返回负载最小的客服
|
||||
asort($loads);
|
||||
return array_key_first($loads);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加到离线队列 (按余额降序)
|
||||
*/
|
||||
public function addToOfflineQueue(int $userId, int $sessionId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
// 获取用户余额
|
||||
$user = Db::name('user')->where('id', $userId)->find();
|
||||
$balance = $user['money'] ?? 0;
|
||||
|
||||
// ZSET score 使用负余额实现降序 (余额高的先处理)
|
||||
$score = -$balance;
|
||||
$member = json_encode([
|
||||
'userId' => $userId,
|
||||
'sessionId' => $sessionId,
|
||||
'time' => time()
|
||||
]);
|
||||
|
||||
$redis->zAdd(self::QUEUE_KEY, $score, $member);
|
||||
}
|
||||
|
||||
/**
|
||||
* 客服上线时处理队列
|
||||
*/
|
||||
public function processOfflineQueue(int $adminId): array
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$processed = [];
|
||||
|
||||
while (true) {
|
||||
// 获取队列中优先级最高的会话 (score最小 = 余额最高)
|
||||
$items = $redis->zRange(self::QUEUE_KEY, 0, 0);
|
||||
|
||||
if (empty($items)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$item = json_decode($items[0], true);
|
||||
|
||||
// 检查客服是否还能接单
|
||||
$currentLoad = (int)$redis->get(self::LOAD_PREFIX . $adminId) ?: 0;
|
||||
$maxSessions = $this->getAgentMaxSessions($adminId);
|
||||
|
||||
if ($currentLoad >= $maxSessions) {
|
||||
break;
|
||||
}
|
||||
|
||||
// 从队列移除
|
||||
$redis->zRem(self::QUEUE_KEY, $items[0]);
|
||||
|
||||
// 分配会话
|
||||
$this->bindSessionToAgent($item['sessionId'], $adminId);
|
||||
$redis->incr(self::LOAD_PREFIX . $adminId);
|
||||
|
||||
$processed[] = $item;
|
||||
}
|
||||
|
||||
return $processed;
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放会话 (会话结束时调用)
|
||||
*/
|
||||
public function releaseSession(int $sessionId, int $adminId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
// 删除会话归属
|
||||
$redis->del(self::SESSION_OWNER_PREFIX . $sessionId);
|
||||
|
||||
// 减少客服负载
|
||||
$load = (int)$redis->get(self::LOAD_PREFIX . $adminId) ?: 0;
|
||||
if ($load > 0) {
|
||||
$redis->decr(self::LOAD_PREFIX . $adminId);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置客服在线状态
|
||||
*/
|
||||
public function setAgentOnline(int $adminId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->setex(self::ONLINE_PREFIX . $adminId, 60, '1');
|
||||
ChatAdminStatus::updateLastOnlineTime($adminId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新客服在线状态 (心跳续期)
|
||||
*/
|
||||
public function refreshAgentOnline(int $adminId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->expire(self::ONLINE_PREFIX . $adminId, 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置客服离线
|
||||
*/
|
||||
public function setAgentOffline(int $adminId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->del(self::ONLINE_PREFIX . $adminId);
|
||||
$redis->del(self::LOAD_PREFIX . $adminId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服最大会话数
|
||||
*/
|
||||
private function getAgentMaxSessions(int $adminId): int
|
||||
{
|
||||
$status = ChatAdminStatus::getByAdminId($adminId);
|
||||
return $status['max_sessions'] ?? self::MAX_SESSIONS;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户已有会话的客服ID
|
||||
*/
|
||||
private function getExistingSessionAgent(int $userId): ?int
|
||||
{
|
||||
$session = ChatSession::getActiveByUserId($userId);
|
||||
return $session['admin_id'] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定会话到客服
|
||||
*/
|
||||
private function bindSessionToAgent(int $sessionId, int $adminId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
// 更新数据库
|
||||
ChatSession::where('id', $sessionId)->update([
|
||||
'admin_id' => $adminId,
|
||||
'status' => ChatSession::STATUS_ACTIVE,
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
// 设置Redis映射
|
||||
$redis->set(self::SESSION_OWNER_PREFIX . $sessionId, $adminId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 释放分配锁
|
||||
*/
|
||||
private function releaseLock(string $key, string $value): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
// Lua脚本保证原子性:仅当值匹配时才删除
|
||||
$script = <<<LUA
|
||||
if redis.call('get', KEYS[1]) == ARGV[1] then
|
||||
return redis.call('del', KEYS[1])
|
||||
else
|
||||
return 0
|
||||
end
|
||||
LUA;
|
||||
$redis->eval($script, [$key, $value], 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Redis实例
|
||||
*/
|
||||
private function getRedis(): \Redis
|
||||
{
|
||||
return Cache::store('redis')->handler();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,201 @@
|
||||
<?php
|
||||
|
||||
namespace app\services\chat;
|
||||
|
||||
use app\models\chat\ChatMessage;
|
||||
use app\models\chat\ChatSession;
|
||||
use app\utils\Snowflake;
|
||||
use think\facade\Cache;
|
||||
|
||||
/**
|
||||
* 消息服务
|
||||
* Class MessageService
|
||||
* @package app\services\chat
|
||||
*/
|
||||
class MessageService
|
||||
{
|
||||
// 约束参数 (specs.md CC-05~CC-09)
|
||||
private const MAX_RETRY = 3;
|
||||
private const RETRY_DELAYS = [1000, 2000, 4000]; // ms
|
||||
private const MAX_CONTENT_LENGTH = 500;
|
||||
private const RECONNECT_FETCH_LIMIT = 50;
|
||||
|
||||
/**
|
||||
* 创建消息
|
||||
* @param array $data [session_id, sender_type, sender_id, msg_type, content]
|
||||
* @return array 消息数据
|
||||
*/
|
||||
public function createMessage(array $data): array
|
||||
{
|
||||
// 生成雪花ID
|
||||
$msgId = Snowflake::getInstance()->nextId();
|
||||
|
||||
// 内容长度限制
|
||||
$content = $data['content'] ?? '';
|
||||
if (mb_strlen($content) > self::MAX_CONTENT_LENGTH) {
|
||||
$content = mb_substr($content, 0, self::MAX_CONTENT_LENGTH);
|
||||
}
|
||||
|
||||
$message = [
|
||||
'msg_id' => $msgId,
|
||||
'session_id' => $data['session_id'],
|
||||
'sender_type' => $data['sender_type'],
|
||||
'sender_id' => $data['sender_id'],
|
||||
'msg_type' => $data['msg_type'] ?? ChatMessage::MSG_TYPE_TEXT,
|
||||
'content' => $content,
|
||||
'status' => ChatMessage::STATUS_PENDING,
|
||||
'retry_count' => 0,
|
||||
'create_time' => time(),
|
||||
];
|
||||
|
||||
// 幂等性检查
|
||||
if (isset($data['client_msg_id']) && ChatMessage::existsByMsgId($data['client_msg_id'])) {
|
||||
return ChatMessage::where('msg_id', $data['client_msg_id'])->find()->toArray();
|
||||
}
|
||||
|
||||
// 入库
|
||||
$id = ChatMessage::insertGetId($message);
|
||||
$message['id'] = $id;
|
||||
|
||||
// 更新会话最后消息
|
||||
ChatSession::where('id', $data['session_id'])->update([
|
||||
'last_msg_id' => $msgId,
|
||||
'last_msg_time' => time(),
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
return $message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 推送消息到目标连接
|
||||
* @param int $msgId 消息ID
|
||||
* @param int $targetFd 目标连接FD
|
||||
* @param array $payload 消息内容
|
||||
* @return bool
|
||||
*/
|
||||
public function pushMessage(int $msgId, int $targetFd, array $payload): bool
|
||||
{
|
||||
$server = app('swoole.server');
|
||||
|
||||
for ($retry = 0; $retry <= self::MAX_RETRY; $retry++) {
|
||||
// 检查目标连接是否有效
|
||||
if (!$server->isEstablished($targetFd)) {
|
||||
$this->updateMessageStatus($msgId, ChatMessage::STATUS_PENDING);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 尝试推送
|
||||
$result = $server->push($targetFd, json_encode($payload));
|
||||
|
||||
if ($result) {
|
||||
$this->updateMessageStatus($msgId, ChatMessage::STATUS_SENT);
|
||||
return true;
|
||||
}
|
||||
|
||||
// 推送失败,记录重试次数
|
||||
$this->incrementRetryCount($msgId);
|
||||
|
||||
if ($retry < self::MAX_RETRY) {
|
||||
// 指数退避等待
|
||||
usleep(self::RETRY_DELAYS[$retry] * 1000);
|
||||
}
|
||||
}
|
||||
|
||||
// 超过最大重试次数,标记为failed
|
||||
$this->updateMessageStatus($msgId, ChatMessage::STATUS_FAILED);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新消息状态
|
||||
*/
|
||||
public function updateMessageStatus(int $msgId, int $status): void
|
||||
{
|
||||
$update = ['status' => $status];
|
||||
|
||||
if ($status === ChatMessage::STATUS_DELIVERED) {
|
||||
$update['delivered_time'] = time();
|
||||
} elseif ($status === ChatMessage::STATUS_READ) {
|
||||
$update['read_time'] = time();
|
||||
}
|
||||
|
||||
ChatMessage::where('msg_id', $msgId)->update($update);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会话未读消息 (重连后拉取)
|
||||
*/
|
||||
public function getUnreadMessages(int $sessionId, int $receiverType, int $limit = null): array
|
||||
{
|
||||
$limit = $limit ?? self::RECONNECT_FETCH_LIMIT;
|
||||
return ChatMessage::getUnreadBySessionId($sessionId, $receiverType, $limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* 批量标记消息为已读
|
||||
*/
|
||||
public function markMessagesAsRead(array $msgIds): void
|
||||
{
|
||||
if (empty($msgIds)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ChatMessage::whereIn('msg_id', $msgIds)
|
||||
->where('status', '<', ChatMessage::STATUS_READ)
|
||||
->update([
|
||||
'status' => ChatMessage::STATUS_READ,
|
||||
'read_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 标记消息为已送达
|
||||
*/
|
||||
public function markMessageDelivered(int $msgId): void
|
||||
{
|
||||
ChatMessage::where('msg_id', $msgId)
|
||||
->where('status', '<', ChatMessage::STATUS_DELIVERED)
|
||||
->update([
|
||||
'status' => ChatMessage::STATUS_DELIVERED,
|
||||
'delivered_time' => time(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会话消息历史
|
||||
*/
|
||||
public function getMessageHistory(int $sessionId, int $limit = 50, int $lastId = 0): array
|
||||
{
|
||||
return ChatMessage::getBySessionId($sessionId, $limit, $lastId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 增加重试次数
|
||||
*/
|
||||
private function incrementRetryCount(int $msgId): void
|
||||
{
|
||||
ChatMessage::where('msg_id', $msgId)->inc('retry_count')->update();
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证消息内容
|
||||
*/
|
||||
public function validateContent(string $content, int $msgType): array
|
||||
{
|
||||
if ($msgType === ChatMessage::MSG_TYPE_TEXT) {
|
||||
if (empty(trim($content))) {
|
||||
return ['valid' => false, 'error' => '消息内容不能为空'];
|
||||
}
|
||||
if (mb_strlen($content) > self::MAX_CONTENT_LENGTH) {
|
||||
return ['valid' => false, 'error' => '消息内容超过' . self::MAX_CONTENT_LENGTH . '字符限制'];
|
||||
}
|
||||
} elseif ($msgType === ChatMessage::MSG_TYPE_IMAGE) {
|
||||
if (empty($content) || !filter_var($content, FILTER_VALIDATE_URL)) {
|
||||
return ['valid' => false, 'error' => '图片URL无效'];
|
||||
}
|
||||
}
|
||||
|
||||
return ['valid' => true, 'error' => null];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,326 @@
|
||||
<?php
|
||||
|
||||
namespace app\services\chat;
|
||||
|
||||
use app\models\chat\ChatSession;
|
||||
use app\models\chat\ChatMessage;
|
||||
use think\facade\Cache;
|
||||
use think\facade\Db;
|
||||
|
||||
/**
|
||||
* 会话服务
|
||||
* Class SessionService
|
||||
* @package app\services\chat
|
||||
*/
|
||||
class SessionService
|
||||
{
|
||||
// Redis Key 前缀
|
||||
private const USER_ACTIVE_SESSION_PREFIX = 'cs:user:active_session:';
|
||||
private const CONN_USER_PREFIX = 'cs:conn:user:';
|
||||
private const CONN_AGENT_PREFIX = 'cs:conn:agent:';
|
||||
|
||||
private AssignService $assignService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->assignService = new AssignService();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建会话
|
||||
* @param int $userId 用户ID
|
||||
* @param int $source 来源 1=PC 2=Game 3=Portal
|
||||
* @return array 会话数据
|
||||
*/
|
||||
public function createSession(int $userId, int $source): array
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
|
||||
// 检查是否已有活跃会话
|
||||
$existingSession = ChatSession::getActiveByUserId($userId);
|
||||
if ($existingSession) {
|
||||
return $existingSession;
|
||||
}
|
||||
|
||||
// 创建新会话
|
||||
$session = [
|
||||
'user_id' => $userId,
|
||||
'source' => $source,
|
||||
'status' => ChatSession::STATUS_PENDING,
|
||||
'create_time' => time(),
|
||||
'update_time' => time(),
|
||||
];
|
||||
|
||||
$sessionId = ChatSession::insertGetId($session);
|
||||
$session['id'] = $sessionId;
|
||||
|
||||
// 缓存用户活跃会话
|
||||
$redis->set(self::USER_ACTIVE_SESSION_PREFIX . $userId, $sessionId);
|
||||
|
||||
// 尝试分配客服
|
||||
$adminId = $this->assignService->assignSession($userId, $sessionId);
|
||||
if ($adminId !== null) {
|
||||
$session['admin_id'] = $adminId;
|
||||
$session['status'] = ChatSession::STATUS_ACTIVE;
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户活跃会话
|
||||
*/
|
||||
public function getActiveSession(int $userId): ?array
|
||||
{
|
||||
return ChatSession::getActiveByUserId($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取会话详情(含用户信息)
|
||||
*/
|
||||
public function getSessionDetail(int $sessionId): ?array
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$session = $session->toArray();
|
||||
|
||||
// 获取用户信息
|
||||
$user = Db::name('user')->where('id', $session['user_id'])->find();
|
||||
if ($user) {
|
||||
$session['user_info'] = [
|
||||
'id' => $user['id'],
|
||||
'username' => $user['username'],
|
||||
'nickname' => $user['nickname'] ?? $user['username'],
|
||||
'money' => $user['money'],
|
||||
'agent_id' => $user['agent_id'] ?? null,
|
||||
];
|
||||
}
|
||||
|
||||
return $session;
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束会话
|
||||
*/
|
||||
public function endSession(int $sessionId, int $operatorId): bool
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$session = $session->toArray();
|
||||
|
||||
// 只能结束进行中的会话
|
||||
if ($session['status'] === ChatSession::STATUS_ENDED) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// 更新会话状态
|
||||
ChatSession::where('id', $sessionId)->update([
|
||||
'status' => ChatSession::STATUS_ENDED,
|
||||
'end_time' => time(),
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
// 清理Redis缓存
|
||||
$redis = $this->getRedis();
|
||||
$redis->del(self::USER_ACTIVE_SESSION_PREFIX . $session['user_id']);
|
||||
|
||||
// 释放客服会话配额
|
||||
if ($session['admin_id']) {
|
||||
$this->assignService->releaseSession($sessionId, $session['admin_id']);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转接会话
|
||||
*/
|
||||
public function transferSession(int $sessionId, int $newAdminId): bool
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session || $session['status'] !== ChatSession::STATUS_ACTIVE) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$oldAdminId = $session['admin_id'];
|
||||
|
||||
// 更新会话归属
|
||||
ChatSession::where('id', $sessionId)->update([
|
||||
'admin_id' => $newAdminId,
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
// 更新Redis
|
||||
$redis = $this->getRedis();
|
||||
$redis->set('cs:session:owner:' . $sessionId, $newAdminId);
|
||||
|
||||
// 调整负载计数
|
||||
if ($oldAdminId) {
|
||||
$oldLoad = (int)$redis->get('cs:agent:load:' . $oldAdminId) ?: 0;
|
||||
if ($oldLoad > 0) {
|
||||
$redis->decr('cs:agent:load:' . $oldAdminId);
|
||||
}
|
||||
}
|
||||
$redis->incr('cs:agent:load:' . $newAdminId);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 会话评价
|
||||
*/
|
||||
public function rateSession(int $sessionId, int $rating, ?string $content = null): bool
|
||||
{
|
||||
$session = ChatSession::find($sessionId);
|
||||
if (!$session) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 评分范围 1-5
|
||||
$rating = max(1, min(5, $rating));
|
||||
|
||||
ChatSession::where('id', $sessionId)->update([
|
||||
'rating' => $rating,
|
||||
'rating_content' => $content ? mb_substr($content, 0, 500) : null,
|
||||
'update_time' => time(),
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册用户连接
|
||||
*/
|
||||
public function registerUserConnection(int $userId, int $fd): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->setex(self::CONN_USER_PREFIX . $userId, 60, $fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册客服连接
|
||||
*/
|
||||
public function registerAgentConnection(int $adminId, int $fd): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->setex(self::CONN_AGENT_PREFIX . $adminId, 60, $fd);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新用户连接TTL
|
||||
*/
|
||||
public function refreshUserConnection(int $userId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->expire(self::CONN_USER_PREFIX . $userId, 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* 刷新客服连接TTL
|
||||
*/
|
||||
public function refreshAgentConnection(int $adminId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->expire(self::CONN_AGENT_PREFIX . $adminId, 60);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户连接FD
|
||||
*/
|
||||
public function getUserFd(int $userId): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$fd = $redis->get(self::CONN_USER_PREFIX . $userId);
|
||||
return $fd ? (int)$fd : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服连接FD
|
||||
*/
|
||||
public function getAgentFd(int $adminId): ?int
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$fd = $redis->get(self::CONN_AGENT_PREFIX . $adminId);
|
||||
return $fd ? (int)$fd : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理用户连接
|
||||
*/
|
||||
public function clearUserConnection(int $userId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->del(self::CONN_USER_PREFIX . $userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理客服连接
|
||||
*/
|
||||
public function clearAgentConnection(int $adminId): void
|
||||
{
|
||||
$redis = $this->getRedis();
|
||||
$redis->del(self::CONN_AGENT_PREFIX . $adminId);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取客服会话列表
|
||||
*/
|
||||
public function getAgentSessions(int $adminId): array
|
||||
{
|
||||
$sessions = ChatSession::getActiveByAdminId($adminId);
|
||||
|
||||
// 附加用户信息和未读数
|
||||
foreach ($sessions as &$session) {
|
||||
$user = Db::name('user')->where('id', $session['user_id'])->find();
|
||||
$session['user_info'] = [
|
||||
'username' => $user['username'] ?? '',
|
||||
'nickname' => $user['nickname'] ?? $user['username'] ?? '',
|
||||
'money' => $user['money'] ?? 0,
|
||||
];
|
||||
|
||||
// 未读消息数
|
||||
$session['unread_count'] = ChatMessage::where('session_id', $session['id'])
|
||||
->where('sender_type', ChatMessage::SENDER_USER)
|
||||
->where('status', '<', ChatMessage::STATUS_READ)
|
||||
->count();
|
||||
}
|
||||
|
||||
return $sessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取待分配会话列表
|
||||
*/
|
||||
public function getPendingSessions(): array
|
||||
{
|
||||
$sessions = ChatSession::where('status', ChatSession::STATUS_PENDING)
|
||||
->order('create_time', 'asc')
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
foreach ($sessions as &$session) {
|
||||
$user = Db::name('user')->where('id', $session['user_id'])->find();
|
||||
$session['user_info'] = [
|
||||
'username' => $user['username'] ?? '',
|
||||
'nickname' => $user['nickname'] ?? $user['username'] ?? '',
|
||||
'money' => $user['money'] ?? 0,
|
||||
];
|
||||
}
|
||||
|
||||
return $sessions;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取Redis实例
|
||||
*/
|
||||
private function getRedis(): \Redis
|
||||
{
|
||||
return Cache::store('redis')->handler();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\connect;
|
||||
|
||||
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\CardPositionNn;
|
||||
use freedom\utils\CardPositionTc;
|
||||
use freedom\utils\RedisUtil;
|
||||
|
||||
/**
|
||||
* TODO 登录成功卡片获取服务
|
||||
* Class GetCardService
|
||||
* @package app\services\connect
|
||||
*/
|
||||
class GetCardService
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO 控制台登录处理
|
||||
* @param array $tableInfo
|
||||
* @param array $numberTabInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function getCard(array $tableInfo, array $numberTabInfo): array
|
||||
{
|
||||
if ($tableInfo['is_scavenging'] != 1 || $numberTabInfo['bet_status'] != 2) return [];
|
||||
$showCard = array();
|
||||
if ($tableInfo['game_id'] == 4){
|
||||
$cardInfo = RedisUtil::getCard($numberTabInfo['id']);
|
||||
if (!$cardInfo) return [];
|
||||
if($cardInfo['card_first'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['card_first'], 'order_num' => '0');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_1'], 'order_num' => '11');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_2'], 'order_num' => '12');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_3'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_3'], 'order_num' => '13');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_4'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_4'], 'order_num' => '14');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_5'] > 0){
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player1Card[3] = $cardInfo['player_1_card_4'];
|
||||
$player1Card[4] = $cardInfo['player_1_card_5'];
|
||||
$player1Result = CardPositionNn::JudgeCowCow($player1Card);
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_5'], 'order_num' => '15', 'result' => $player1Result['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_1'], 'order_num' => '21');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_2'], 'order_num' => '22');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_3'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_3'], 'order_num' => '23');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_4'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_4'], 'order_num' => '24');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_5'] > 0){
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player2Card[3] = $cardInfo['player_2_card_4'];
|
||||
$player2Card[4] = $cardInfo['player_2_card_5'];
|
||||
$player2Result = CardPositionNn::JudgeCowCow($player2Card);
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_5'], 'order_num' => '25', 'result' => $player2Result['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_1'], 'order_num' => '31');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_2'], 'order_num' => '32');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_3'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_3'], 'order_num' => '33');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_4'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_4'], 'order_num' => '34');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_5'] > 0){
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$player3Card[3] = $cardInfo['player_3_card_4'];
|
||||
$player3Card[4] = $cardInfo['player_3_card_5'];
|
||||
$player3Result = CardPositionNn::JudgeCowCow($player3Card);
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_5'], 'order_num' => '35', 'result' => $player3Result['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['banker_card_1'], 'order_num' => '41');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['banker_card_2'], 'order_num' => '42');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_3'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['banker_card_3'], 'order_num' => '43');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_4'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['banker_card_4'], 'order_num' => '44');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_5'] > 0){
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$bankerCard[3] = $cardInfo['banker_card_4'];
|
||||
$bankerCard[4] = $cardInfo['banker_card_5'];
|
||||
$bankerResult = CardPositionNn::JudgeCowCow($bankerCard);
|
||||
$pushArray = array('card' => $cardInfo['banker_card_5'], 'order_num' => '45', 'result' => $bankerResult['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
}elseif($tableInfo['game_id'] == 5){
|
||||
$cardInfo = RedisUtil::getCard($numberTabInfo['id']);
|
||||
if (!$cardInfo) return [];
|
||||
if($cardInfo['card_first'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['card_first'], 'order_num' => '0');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_1'], 'order_num' => '11');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_2'], 'order_num' => '12');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_1_card_3'] > 0){
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player1Result = CardPositionTc::ThredCardCowCow($player1Card);
|
||||
$pushArray = array('card' => $cardInfo['player_1_card_3'], 'order_num' => '13', 'result' => $player1Result['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_1'], 'order_num' => '21');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_2'], 'order_num' => '22');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_2_card_3'] > 0){
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player2Result = CardPositionTc::ThredCardCowCow($player2Card);
|
||||
$pushArray = array('card' => $cardInfo['player_2_card_3'], 'order_num' => '23', 'result' => $player2Result['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_1'], 'order_num' => '31');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_2'], 'order_num' => '32');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['player_3_card_3'] > 0){
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$player3Result = CardPositionTc::ThredCardCowCow($player3Card);
|
||||
$pushArray = array('card' => $cardInfo['player_3_card_3'], 'order_num' => '33', 'result' => $player3Result['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_1'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['banker_card_1'], 'order_num' => '41');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_2'] > 0){
|
||||
$pushArray = array('card' => $cardInfo['banker_card_2'], 'order_num' => '42');
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
if($cardInfo['banker_card_3'] > 0){
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$bankerResult = CardPositionTc::ThredCardCowCow($bankerCard);
|
||||
$pushArray = array('card' => $cardInfo['banker_card_3'], 'order_num' => '43', 'result' => $bankerResult['word']);
|
||||
array_push($showCard,$pushArray);
|
||||
}
|
||||
}else{
|
||||
$cardInfo = RedisUtil::getCardPosition($numberTabInfo['id']);
|
||||
foreach ($cardInfo AS $k => $v){
|
||||
switch ($k){
|
||||
case 'banker_1':
|
||||
$showCard[] = ['position' => 21, 'card' => intval($v), 'number' => CardPosition::interchangeCard($v)];
|
||||
break;
|
||||
case 'banker_2':
|
||||
$showCard[] = ['position' => 22, 'card' => intval($v), 'number' => CardPosition::interchangeCard($v)];
|
||||
break;
|
||||
case 'banker_3':
|
||||
$showCard[] = ['position' => 23, 'card' => intval($v), 'number' => CardPosition::interchangeCard($v)];
|
||||
break;
|
||||
case 'player_1':
|
||||
$showCard[] = ['position' => 11, 'card' => intval($v), 'number' => CardPosition::interchangeCard($v)];
|
||||
break;
|
||||
case 'player_2':
|
||||
$showCard[] = ['position' => 12, 'card' => intval($v), 'number' => CardPosition::interchangeCard($v)];
|
||||
break;
|
||||
case 'player_3':
|
||||
$showCard[] = ['position' => 13, 'card' => intval($v), 'number' => CardPosition::interchangeCard($v)];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $showCard;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\connect;
|
||||
|
||||
|
||||
use app\models\process\Boot;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\process\Sumday;
|
||||
|
||||
/**
|
||||
* TODO 桌子状态服务
|
||||
* Class InitTableService
|
||||
* @package app\services\connect
|
||||
*/
|
||||
class InitTableService
|
||||
{
|
||||
/**
|
||||
* TODO 控制台登录处理
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function initTable(array $tableInfo): array
|
||||
{
|
||||
//查询日结
|
||||
$lastSumday = Sumday::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$lastSumday) $lastSumday = Sumday::addByTable($tableInfo);
|
||||
//查询靴
|
||||
$lastBoot = Boot::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$lastBoot) $lastBoot = Boot::addBySumday($lastSumday);
|
||||
//查询铺
|
||||
$lastNumberTab = NumberTab::getByBootIdOrderByIdDesc($lastBoot);
|
||||
if (!$lastNumberTab) $lastNumberTab = NumberTab::addByBoot($lastBoot);
|
||||
return $lastNumberTab;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 桌子状态获取
|
||||
* @param array $numberTabInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function numberTabStatus(array $numberTabInfo): array{
|
||||
switch ($numberTabInfo['bet_status']){
|
||||
case 1:
|
||||
$return = ['bet_status' => 1, 'bet_msg' => 'bet_status_1'];
|
||||
break;
|
||||
case 2:
|
||||
$return = ['bet_status' => 2, 'bet_msg' => 'bet_status_2'];
|
||||
break;
|
||||
default:
|
||||
$return = ['bet_status' => 0, 'bet_msg' => 'bet_status_0'];
|
||||
break;
|
||||
}
|
||||
switch ($numberTabInfo['rob_status']){
|
||||
case 1:
|
||||
$return = array_merge(['rob_status' => 1, 'bet_msg' => 'rob_status_1'],$return);
|
||||
break;
|
||||
case 2:
|
||||
$return = array_merge(['rob_status' => 2, 'bet_msg' => 'rob_status_2'],$return);
|
||||
break;
|
||||
default:
|
||||
$return = array_merge(['rob_status' => 0, 'bet_msg' => 'rob_status_0'],$return);
|
||||
break;
|
||||
}
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\connect;
|
||||
|
||||
|
||||
use app\models\manager\Manager;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* TODO 经理登录服务
|
||||
* Class ManagerConnectService
|
||||
* @package app\services\connect
|
||||
*/
|
||||
class ManagerConnectService
|
||||
{
|
||||
/**
|
||||
* TODO 控制台登录处理
|
||||
* @param Request $event
|
||||
* @return void
|
||||
*/
|
||||
public static function doManagerConnect(Request $event){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$userId = intval($event->get('userid'));
|
||||
$loginToken = trim($event->get('login_token'));
|
||||
$username = trim($event->get('account'));
|
||||
if(isset($username) && isset($loginToken) && isset($userId) && $userId > 0){
|
||||
$userInfo = Manager::get(['id' => $userId, 'status' => 1]);
|
||||
if($userInfo && $userInfo['login_token'] == $loginToken && $username == $userInfo['username']){
|
||||
SocketSession::saveSocketSession(['user_id' => $userId, 'username' => $username],'manager');
|
||||
$tableManager = app('swoole.table.manager');
|
||||
$managerSession = $tableManager->get((string) $userId);
|
||||
$ws->setSender(0)->to($managerSession['fd'])->emit('onlineLogin',['status' => true]);
|
||||
}else{
|
||||
$ws->emit('onlineLogin',['status' => false,'msg' => 'link_server_fail']);
|
||||
$ws->close();
|
||||
}
|
||||
}else{
|
||||
$ws->emit('onlineLogin',['status' => false,'msg' => 'link_server_fail']);
|
||||
$ws->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\connect;
|
||||
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\table\Table;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* TODO 扫描登录服务
|
||||
* Class SpaceConnectService
|
||||
* @package app\services\connect
|
||||
*/
|
||||
class ScanConnectService
|
||||
{
|
||||
/**
|
||||
* TODO 控制台登录处理
|
||||
* @param Request $event
|
||||
* @return void
|
||||
*/
|
||||
public static function doScanConnect(Request $event){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$tableId = intval($event->get('table_id'));
|
||||
$tableInfo = Table::get($tableId);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo){
|
||||
$ws->emit('onlineLogin',['status' => false, 'msg' => 'Not NumberTab Data']);
|
||||
$ws->close();
|
||||
return;
|
||||
}
|
||||
$round = array();
|
||||
$round['tid'] = $tableId;
|
||||
$round['boot_id'] = intval($numberTabInfo['boot_id']);
|
||||
$round['boot_num'] = intval($numberTabInfo['boot_num']);
|
||||
$round['number_tab_id'] = intval($numberTabInfo['id']);
|
||||
$round['number_tab_number'] = intval($numberTabInfo['number']);
|
||||
if ($numberTabInfo['bet_status'] == 2){
|
||||
$round['is_scan'] = true;
|
||||
}else{
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
$ws->join(SocketSession::HOUSE_NAME);
|
||||
$ws->emit('onlineLogin',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\connect;
|
||||
|
||||
|
||||
use app\models\table\Table;
|
||||
use app\models\table\UserController;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* TODO 控制台登录服务
|
||||
* Class SpaceConnectService
|
||||
* @package app\services\connect
|
||||
*/
|
||||
class SpaceConnectService
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO 控制台登录处理
|
||||
* @param Request $event
|
||||
* @return void
|
||||
*/
|
||||
public static function doSpaceConnect(Request $event){
|
||||
/*
|
||||
$redis = Cache::store('redis')->handler();
|
||||
//设置哈希
|
||||
$redis->hset('123456','yzm','4566');
|
||||
//设置过期时间
|
||||
$redis->expire('123456',60);
|
||||
*/
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$tableId = intval($event->get('table_id'));
|
||||
$tableInfo = Table::get($tableId);
|
||||
$userId = intval($event->get('userid'));
|
||||
$loginToken = trim($event->get('login_token'));
|
||||
$username = trim($event->get('account'));
|
||||
$userController = UserController::get(['id' => $userId, 'username' => $username, 'login_token' => $loginToken]);
|
||||
if (!$tableInfo || !$userController){
|
||||
$ws->emit('onlineLogin',['status' => false, 'msg' => 'not_table_data']);
|
||||
//$ws->close();
|
||||
return;
|
||||
}
|
||||
$lastNumberTab = InitTableService::initTable($tableInfo);
|
||||
if($lastNumberTab){
|
||||
$round = array();
|
||||
$round['boot_id'] = $lastNumberTab['boot_id'];
|
||||
$round['boot_num'] = $lastNumberTab['boot_num'];
|
||||
$round['number_tab_id'] = $lastNumberTab['id'];
|
||||
$round['number_tab_number'] = $lastNumberTab['number'];
|
||||
$round['in_checkout'] = $tableInfo['in_checkout'];
|
||||
$round['number_tab_status'] = InitTableService::numberTabStatus($lastNumberTab);
|
||||
$round['show_card'] = GetCardService::getCard($tableInfo,$lastNumberTab);
|
||||
$ws->emit('onlineLogin',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
SocketSession::saveSocketSession(['table_id' => $tableInfo['id'], 'table_name' => $tableInfo['table_name']],'space');
|
||||
}else{
|
||||
$ws->emit('onlineLogin',['status' => false, 'table_id' => $tableInfo['id'], 'msg' => 'link_server_fail']);
|
||||
//$ws->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\connect;
|
||||
|
||||
|
||||
use app\models\user\User;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\Request;
|
||||
|
||||
/**
|
||||
* TODO 会员登录服务
|
||||
* Class UserConnectService
|
||||
* @package app\services\connect
|
||||
*/
|
||||
class UserConnectService
|
||||
{
|
||||
/**
|
||||
* TODO 控制台登录处理
|
||||
* @param Request $event
|
||||
* @return void
|
||||
*/
|
||||
public static function doUserConnect(Request $event){
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$userId = intval($event->get('userid'));
|
||||
$loginToken = trim($event->get('login_token'));
|
||||
$username = trim($event->get('account'));
|
||||
if(isset($username) && isset($loginToken) && isset($userId) && $userId > 0){
|
||||
$userInfo = User::get(['id' => $userId, 'status' => 1, 'is_delete' => 0]);
|
||||
if($userInfo && $userInfo['login_token'] == $loginToken && $username == $userInfo['username']){
|
||||
SocketSession::saveSocketSession(['user_id' => $userId, 'username' => $username],'user');
|
||||
$ws->emit('onlineLogin',['status' => true, 'money' => $userInfo['money']]);
|
||||
}else{
|
||||
$ws->emit('onlineLogin',['status' => false, 'money' => 0, 'msg' => 'link_server_fail']);
|
||||
$ws->close();
|
||||
}
|
||||
}else{
|
||||
$ws->emit('onlineLogin',['status' => false, 'money' => 0, 'msg' => 'link_server_fail']);
|
||||
$ws->close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\opening;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\services\connect\InitTableService;
|
||||
use app\services\waybill\WaybillRemindService;
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\RedisUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果服务
|
||||
* Class OpeningBaccaratService
|
||||
* @package app\services\opening
|
||||
*/
|
||||
class OpeningBaccaratService
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function openingBaccarat(array $event, array $tableInfo, Websocket $ws){
|
||||
//判断结果并推送结果
|
||||
$res = self::doOpening($event,$tableInfo);
|
||||
if ($res['status'] == false){
|
||||
$ws->emit('openingBaccarat',['status' => false, 'msg' => $res['msg']]);
|
||||
return;
|
||||
}
|
||||
list($opening,$pair,$luck_six,$big_small,$banker,$player,$lastNumberTabInfo,$newNumberTabInfo) = $res['data'];
|
||||
$round = array(
|
||||
'opening' => $opening,
|
||||
'pair' => $pair,
|
||||
'luck_six' => $luck_six,
|
||||
'big_small' => $big_small,
|
||||
'banker' => $banker,
|
||||
'player' => $player,
|
||||
'boot_id' => $newNumberTabInfo['boot_id'],
|
||||
'boot_num' => $newNumberTabInfo['boot_num'],
|
||||
'number_tab_id' => $newNumberTabInfo['id'],
|
||||
'previous_number_tab_id' => $lastNumberTabInfo['id'],
|
||||
'number_tab_number' => $newNumberTabInfo['number'],
|
||||
'number_tab_status' => InitTableService::numberTabStatus($newNumberTabInfo)
|
||||
);
|
||||
$ws->emit('openingBaccarat',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('openingBaccaratResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
//处理注单
|
||||
self::doBet($ws,$tableInfo,$lastNumberTabInfo);
|
||||
//处理好路
|
||||
WaybillRemindService::parseWaybillRemind($tableInfo['game_id'], $tableInfo['id'], $tableInfo['table_name'], $newNumberTabInfo['boot_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 判断结果
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doOpening(array $event, array $tableInfo): array
|
||||
{
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'opening_fail_4'];
|
||||
$luck_six = 0;
|
||||
$big_small = 0;
|
||||
$banker = null;
|
||||
$player = null;
|
||||
if ($tableInfo['is_scavenging'] == 1){
|
||||
$cardInfo = RedisUtil::getCardPosition($numberTabId);
|
||||
if (!isset($cardInfo['banker_1']) || !isset($cardInfo['banker_2']) || !isset($cardInfo['player_1']) || !isset($cardInfo['player_2'])){
|
||||
return ['status' => false, 'msg' => 'opening_fail_6'];
|
||||
}
|
||||
if (!isset($cardInfo['player_3'])) $cardInfo['player_3'] = 0;
|
||||
if (!isset($cardInfo['banker_3'])) $cardInfo['banker_3'] = 0;
|
||||
$checkOpenScan = CardPosition::checkOpenScan($cardInfo);
|
||||
if (!$checkOpenScan) return ['status' => false, 'msg' => 'opening_fail_6'];
|
||||
$banker_1 = CardPosition::interchangeCard($cardInfo['banker_1']);
|
||||
$banker_2 = CardPosition::interchangeCard($cardInfo['banker_2']);
|
||||
$banker_3 = CardPosition::interchangeCard($cardInfo['banker_3']);
|
||||
$player_1 = CardPosition::interchangeCard($cardInfo['player_1']);
|
||||
$player_2 = CardPosition::interchangeCard($cardInfo['player_2']);
|
||||
$player_3 = CardPosition::interchangeCard($cardInfo['player_3']);
|
||||
$banker = CardPosition::interchangeNumber($banker_1) + CardPosition::interchangeNumber($banker_2) + CardPosition::interchangeNumber($banker_3);
|
||||
$player = CardPosition::interchangeNumber($player_1) + CardPosition::interchangeNumber($player_2) + CardPosition::interchangeNumber($player_3);
|
||||
// 求余
|
||||
if($banker >= 10){
|
||||
$banker = $banker % 10;
|
||||
}
|
||||
if($player >= 10){
|
||||
$player = $player % 10;
|
||||
}
|
||||
// 判断结果
|
||||
if($banker > $player){
|
||||
// 庄赢
|
||||
$opening = 1;
|
||||
}elseif($banker < $player){
|
||||
// 闲赢
|
||||
$opening = 2;
|
||||
}elseif($banker == $player){
|
||||
// 庄赢
|
||||
$opening = 3;
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail_5'];
|
||||
}
|
||||
// 比较对子
|
||||
if(intval($banker_1) == intval($banker_2) && intval($player_1) == intval($player_2)){
|
||||
$pair = 3;
|
||||
}elseif(intval($banker_1) == intval($banker_2)){
|
||||
$pair = 1;
|
||||
}elseif(intval($player_1) == intval($player_2)){
|
||||
$pair = 2;
|
||||
}else{
|
||||
$pair = 0;
|
||||
}
|
||||
// 判断幸运6
|
||||
if ($opening == 1 && $banker == 6){
|
||||
if ($banker_3 > 0){
|
||||
$luck_six = 3;
|
||||
} else {
|
||||
$luck_six = 2;
|
||||
}
|
||||
}
|
||||
// 判断大小
|
||||
if ($banker_3 > 0 || $player_3 > 0){
|
||||
$big_small = 1;
|
||||
} else {
|
||||
$big_small = 2;
|
||||
}
|
||||
}else{
|
||||
$opening = intval($event['opening']);
|
||||
$banker_pair = intval($event['banker_pair']);
|
||||
$player_pair = intval($event['player_pair']);
|
||||
$luck_six = intval($event['luck_six']);
|
||||
//处理开盘
|
||||
if($banker_pair == 1 && $player_pair == 2){
|
||||
//庄闲对
|
||||
$pair = 3;
|
||||
}elseif($banker_pair == 1 && $player_pair != 2){
|
||||
//庄对
|
||||
$pair = 1;
|
||||
}elseif($banker_pair != 1 && $player_pair == 2){
|
||||
//和对
|
||||
$pair = 2;
|
||||
}else{
|
||||
$pair = 0;
|
||||
}
|
||||
}
|
||||
if (!in_array($opening,[1,2,3])) return ['status' => false, 'msg' => 'opening_fail_3'];
|
||||
//开盘
|
||||
$numberTabUpdate = ['result' => $opening, 'pair' => $pair, 'luck_six' => $luck_six, 'big_small' => $big_small, 'end_time' => time(), 'bet_status' => 3];
|
||||
$newNumberTabInfo = NumberTab::next($numberTabInfo,$numberTabUpdate,$tableInfo);
|
||||
if ($newNumberTabInfo){
|
||||
$lastNumberTabInfo = array_merge($numberTabInfo,$numberTabUpdate);
|
||||
return ['status' => true, 'data' => [$opening,$pair,$luck_six,$big_small,$banker,$player,$lastNumberTabInfo,$newNumberTabInfo]];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Bet处理
|
||||
* @param Websocket $ws 桌子信息
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $numberTabInfo 开结果的当前局信息
|
||||
* @return void
|
||||
*/
|
||||
public static function doBet(Websocket $ws, array $tableInfo, array $numberTabInfo){
|
||||
$betArray = Bet::getByNumberTabIdValid($numberTabInfo['id']);
|
||||
foreach ($betArray AS $v){
|
||||
$userInfo = User::get(intval($v['user_id']));
|
||||
if (!$userInfo){
|
||||
continue;
|
||||
}
|
||||
$amount = $v['banker_amount'] + $v['player_amount'] + $v['tie_amount'] + $v['banker_pair_amount'] + $v['player_pair_amount'] + $v['luck_six_amount'] + $v['big_amount'] + $v['small_amount'];
|
||||
$winMoney = 0;
|
||||
// 双边洗码
|
||||
$ximaliang = 0;
|
||||
if($userInfo['type_xima'] == 1){
|
||||
$ximaliang = abs($v['banker_amount'] - $v['player_amount']);
|
||||
}
|
||||
if($numberTabInfo['result'] == 1){
|
||||
// 庄赢
|
||||
if ($v['banker_amount'] > 0){
|
||||
if ($v['baccarat_type'] == 1){
|
||||
if ($numberTabInfo['luck_six'] > 0){
|
||||
$winMoney = round($v['banker_amount'] * (1 + 0.5),2) + $winMoney;
|
||||
} else {
|
||||
$winMoney = round($v['banker_amount'] * (1 + 1),2) + $winMoney;
|
||||
}
|
||||
} else {
|
||||
$winMoney = round($v['banker_amount'] * (1 + $userInfo['price_banker']),2) + $winMoney;
|
||||
}
|
||||
}
|
||||
// 单边洗码
|
||||
if($userInfo['type_xima'] == 2){
|
||||
$ximaliang = $v['player_amount'];
|
||||
}
|
||||
}elseif($numberTabInfo['result'] == 2){
|
||||
// 闲赢
|
||||
if($v['player_amount'] > 0){
|
||||
$winMoney = $v['player_amount'] * (1 + $userInfo['price_player']) + $winMoney;
|
||||
}
|
||||
// 单边洗码
|
||||
if($userInfo['type_xima'] == 2){
|
||||
$ximaliang = $v['banker_amount'];
|
||||
}
|
||||
}elseif($numberTabInfo['result'] == 3) {
|
||||
$ximaliang = 0;
|
||||
// 和赢
|
||||
if($v['tie_amount'] > 0){
|
||||
$winMoney = $v['tie_amount'] * (1 + $userInfo['price_tie_baccarat']) + $winMoney;
|
||||
}
|
||||
// 开 和,下注庄和闲不扣钱
|
||||
if($v['banker_amount'] > 0 && $v['player_amount'] > 0){
|
||||
$winMoney = $v['player_amount'] + $v['banker_amount'] + $winMoney;
|
||||
}elseif($v['banker_amount'] > 0){
|
||||
$winMoney = $v['banker_amount'] + $winMoney;
|
||||
} elseif ($v['player_amount'] > 0){
|
||||
$winMoney = $v['player_amount'] + $winMoney;
|
||||
}
|
||||
}
|
||||
if($numberTabInfo['pair'] == 3){
|
||||
// 计算庄对下注的赢钱金额
|
||||
if ($v['banker_pair_amount'] > 0) {
|
||||
$winMoney = $v['banker_pair_amount'] * (1 + $userInfo['price_pair']) + $winMoney;
|
||||
}
|
||||
//计算闲对下注的赢钱金额
|
||||
if ($v['player_pair_amount'] > 0) {
|
||||
$winMoney = $v['player_pair_amount'] * (1 + $userInfo['price_pair']) + $winMoney;
|
||||
}
|
||||
}elseif($numberTabInfo['pair'] == 1){
|
||||
if ($v['banker_pair_amount'] > 0) {
|
||||
$winMoney = $v['banker_pair_amount'] * (1 + $userInfo['price_pair']) + $winMoney;
|
||||
}
|
||||
}elseif($numberTabInfo['pair'] == 2){
|
||||
if ($v['player_pair_amount'] > 0) {
|
||||
$winMoney = $v['player_pair_amount'] * (1 + $userInfo['price_pair']) + $winMoney;
|
||||
}
|
||||
}
|
||||
if ($numberTabInfo['luck_six'] == 2 && $v['luck_six_amount'] > 0){
|
||||
$winMoney = $v['luck_six_amount'] * (1 + $userInfo['price_luck_six_2']) + $winMoney;
|
||||
}
|
||||
if ($numberTabInfo['luck_six'] == 3 && $v['luck_six_amount'] > 0){
|
||||
$winMoney = $v['luck_six_amount'] * (1 + $userInfo['price_luck_six_3']) + $winMoney;
|
||||
}
|
||||
if ($numberTabInfo['big_small'] == 1){
|
||||
$winMoney = $v['big_amount'] * (1 + $userInfo['price_big']) + $winMoney;
|
||||
}
|
||||
if ($numberTabInfo['big_small'] == 2){
|
||||
$winMoney = $v['small_amount'] * (1 + $userInfo['price_small']) + $winMoney;
|
||||
}
|
||||
// 计算最终赢钱金额
|
||||
$winTotal = $winMoney - $amount;
|
||||
/**
|
||||
* Model处理
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $betInfo bet信息
|
||||
* @param array $userInfo bet用户信息
|
||||
* @param array $numberTabInfo 局信息
|
||||
* @param float $amount 下注总数
|
||||
* @param float $winTotal 赢金额
|
||||
* @param float $ximaliang 洗码量
|
||||
*/
|
||||
$res = Bet::openingBet($tableInfo,$v,$userInfo,$numberTabInfo,$amount,$winTotal,$ximaliang);
|
||||
if ($res['status']){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $v['user_id']);
|
||||
if ($userSession && is_array($userSession)){
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening',['status' => true, 'table_id' => $tableInfo['id'], 'round' => ['money' => $res['money'], 'win_total' => $winTotal, 'previous_number_tab_id' => $v['number_tab_id']]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\opening;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\Boot;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\DiceUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果服务
|
||||
* Class OpeningDiceService
|
||||
* @package app\services\opening
|
||||
*/
|
||||
class OpeningDiceService
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function openingDice(array $event, array $tableInfo, Websocket $ws){
|
||||
//判断结果并推送结果
|
||||
$res = self::doOpening($event,$tableInfo);
|
||||
if ($res['status'] == false){
|
||||
$ws->emit('openingDice',['status' => false, 'msg' => $res['msg']]);
|
||||
return;
|
||||
}
|
||||
list($resultArray,$resultParse,$lastNumberTabInfo,$newNumberTabInfo) = $res['data'];
|
||||
$round = array(
|
||||
'result' => $resultArray,
|
||||
'result_parse' => $resultParse,
|
||||
'boot_id' => $newNumberTabInfo['boot_id'],
|
||||
'boot_num' => $newNumberTabInfo['boot_num'],
|
||||
'number_tab_id' => $newNumberTabInfo['id'],
|
||||
'previous_number_tab_id' => $lastNumberTabInfo['id'],
|
||||
'number_tab_number' => $newNumberTabInfo['number'],
|
||||
'number_tab_status' => InitTableService::numberTabStatus($newNumberTabInfo)
|
||||
);
|
||||
$ws->emit('openingDice',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('openingDiceResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
//处理注单
|
||||
self::doBet($ws,$tableInfo,$lastNumberTabInfo,$resultArray,$resultParse);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 判断结果
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doOpening(array $event, array $tableInfo): array
|
||||
{
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'opening_fail_4'];
|
||||
$resultArray = explode(',', $event['result']);
|
||||
$resultTrue = true;
|
||||
foreach ($resultArray as $v){
|
||||
if (!in_array(intval($v), [1,2,3,4,5,6])){
|
||||
$resultTrue = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($resultTrue == false || count($resultArray) != 3) return ['status' => false, 'msg' => 'opening_fail_3'];
|
||||
$boot = Boot::where(['id' => $numberTabInfo['boot_id']])->find();
|
||||
$afterCountArray = DiceUtil::parseCount($resultArray);
|
||||
$beforeCountString = $boot['dice_count'];
|
||||
$beforeCountArray = string_to_array($beforeCountString);
|
||||
$countArray = DiceUtil::countInc($beforeCountArray, $afterCountArray);
|
||||
$countString = array_to_string($countArray);
|
||||
$numberTabInfo['dice_count'] = $countString;
|
||||
$resultParse = DiceUtil::parseResult($resultArray);
|
||||
$numberTabUpdate = ['dice_result' => $event['result'], 'end_time' => time(), 'bet_status' => 3];
|
||||
$newNumberTabInfo = NumberTab::next($numberTabInfo,$numberTabUpdate,$tableInfo);
|
||||
if ($newNumberTabInfo){
|
||||
$lastNumberTabInfo = array_merge($numberTabInfo,$numberTabUpdate);
|
||||
return ['status' => true, 'data' => [$resultArray,$resultParse,$lastNumberTabInfo,$newNumberTabInfo]];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Bet处理
|
||||
* @param Websocket $ws 桌子信息
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $numberTabInfo 开结果的当前局信息
|
||||
* @return void
|
||||
*/
|
||||
public static function doBet(Websocket $ws, array $tableInfo, array $numberTabInfo, array $resultArray, array $resultParse){
|
||||
$betArray = Bet::getByNumberTabIdValid($numberTabInfo['id']);
|
||||
foreach ($betArray AS $v){
|
||||
$userInfo = User::get(intval($v['user_id']));
|
||||
if (!$userInfo) continue;
|
||||
if (empty($v['dice_amount'])) continue;
|
||||
$priceArray = string_to_array($userInfo['price_dice']);
|
||||
$amountArray = string_to_array($v['dice_amount']);
|
||||
$amount = 0;
|
||||
$winMoney = 0;
|
||||
foreach ($amountArray as $key => $value){
|
||||
$amount += intval($value);
|
||||
if (in_array($key, ['living_1','living_2','living_3','living_4','living_5','living_6'])){
|
||||
$keyArray = explode("_", $key);
|
||||
$count = DiceUtil::getLivingCount($resultArray, intval($keyArray[1]));
|
||||
if ($count == 1){
|
||||
$winMoney = round($value * (1 + $priceArray['once']),2) + $winMoney;
|
||||
} elseif ($count == 2){
|
||||
$winMoney = round($value * (1 + $priceArray['double']),2) + $winMoney;
|
||||
} elseif ($count == 3){
|
||||
$winMoney = round($value * (1 + $priceArray['triple']),2) + $winMoney;
|
||||
}
|
||||
} else {
|
||||
if (in_array($key, $resultParse)){
|
||||
$winMoney = round($value * (1 + $priceArray[$key]),2) + $winMoney;
|
||||
}
|
||||
}
|
||||
}
|
||||
$winTotal = $winMoney - $amount;
|
||||
/**
|
||||
* Model处理
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $betInfo bet信息
|
||||
* @param array $userInfo bet用户信息
|
||||
* @param array $numberTabInfo 局信息
|
||||
* @param float $amount 下注总数
|
||||
* @param float $winTotal 赢金额
|
||||
* @param float $ximaliang 洗码量
|
||||
*/
|
||||
$res = Bet::openingBet($tableInfo,$v,$userInfo,$numberTabInfo,$amount,$winTotal,0);
|
||||
if ($res['status']){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $v['user_id']);
|
||||
if ($userSession && is_array($userSession)){
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening',['status' => true, 'table_id' => $tableInfo['id'], 'round' => ['money' => $res['money'], 'win_total' => $winTotal, 'previous_number_tab_id' => $v['number_tab_id']]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,190 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\opening;
|
||||
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\services\connect\InitTableService;
|
||||
use app\services\waybill\WaybillRemindService;
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\RedisUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\facade\Env;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
/**
|
||||
* TODO Dt开结果服务
|
||||
* Class OpeningDtService
|
||||
* @package app\services\opening
|
||||
*/
|
||||
class OpeningDtService
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO Dt开结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function openingDt(array $event, array $tableInfo, Websocket $ws)
|
||||
{
|
||||
//判断结果并推送结果
|
||||
$res = self::doOpening($event,$tableInfo);
|
||||
if ($res['status'] == false){
|
||||
$ws->emit('openingDt',['status' => false, 'msg' => $res['msg']]);
|
||||
return;
|
||||
}
|
||||
list($opening,$banker,$player,$lastNumberTabInfo,$newNumberTabInfo) = $res['data'];
|
||||
$round = array(
|
||||
'opening' => $opening,
|
||||
'banker' => $banker,
|
||||
'player' => $player,
|
||||
'boot_id' => $newNumberTabInfo['boot_id'],
|
||||
'boot_num' => $newNumberTabInfo['boot_num'],
|
||||
'number_tab_id' => $newNumberTabInfo['id'],
|
||||
'previous_number_tab_id' => $lastNumberTabInfo['id'],
|
||||
'number_tab_number' => $newNumberTabInfo['number'],
|
||||
'number_tab_status' => InitTableService::numberTabStatus($newNumberTabInfo)
|
||||
);
|
||||
$ws->emit('openingDt',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('openingDtResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
//处理注单
|
||||
self::doBet($ws,$tableInfo,$lastNumberTabInfo);
|
||||
//处理好路
|
||||
WaybillRemindService::parseWaybillRemind($tableInfo['game_id'], $tableInfo['id'], $tableInfo['table_name'], $newNumberTabInfo['boot_id']);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 判断结果
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doOpening(array $event, array $tableInfo): array
|
||||
{
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'opening_fail_4'];
|
||||
$banker = null;
|
||||
$player = null;
|
||||
if ($tableInfo['is_scavenging'] == 1){
|
||||
$cardInfo = RedisUtil::getCardPosition($numberTabId);
|
||||
if (!$cardInfo || !isset($cardInfo['banker_1']) || !isset($cardInfo['player_1'])) return ['status' => false, 'msg' => 'opening_fail_6'];
|
||||
// 比较结果
|
||||
$banker = CardPosition::interchangeCard($cardInfo['banker_1']);
|
||||
$player = CardPosition::interchangeCard($cardInfo['player_1']);
|
||||
// 判断结果
|
||||
if($banker > $player){
|
||||
$opening = 1;
|
||||
}elseif($banker < $player){
|
||||
$opening = 2;
|
||||
}else{
|
||||
// 不对比花色
|
||||
$opening = 3;
|
||||
|
||||
// 对比花色
|
||||
// if(CardPosition::interchangeColor($cardInfo['banker_1']) < CardPosition::interchangeColor($cardInfo['player_1'])){
|
||||
// $opening = 1;
|
||||
// }elseif(CardPosition::interchangeColor($cardInfo['banker_1']) > CardPosition::interchangeColor($cardInfo['player_1'])){
|
||||
// $opening = 2;
|
||||
// }else{
|
||||
// $opening = 3;
|
||||
// }
|
||||
}
|
||||
}else{
|
||||
$opening = intval($event['bet']);
|
||||
}
|
||||
if (!in_array($opening,[1,2,3])) return ['status' => false, 'msg' => 'opening_fail_3'];
|
||||
//开盘
|
||||
$numberTabUpdate = ['result' => $opening, 'end_time' => time(), 'bet_status' => 3];
|
||||
$newNumberTabInfo = NumberTab::next($numberTabInfo,$numberTabUpdate,$tableInfo);
|
||||
if ($newNumberTabInfo){
|
||||
$lastNumberTabInfo = array_merge($numberTabInfo,$numberTabUpdate);
|
||||
return ['status' => true, 'data' => [$opening,$banker,$player,$lastNumberTabInfo,$newNumberTabInfo]];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Bet处理
|
||||
* @param Websocket $ws 桌子信息
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $numberTabInfo 开结果的当前局信息
|
||||
* @return void
|
||||
*/
|
||||
public static function doBet(Websocket $ws, array $tableInfo, array $numberTabInfo){
|
||||
$betArray = Bet::getByNumberTabIdValid($numberTabInfo['id']);
|
||||
foreach ($betArray AS $v){
|
||||
$userInfo = User::get(intval($v['user_id']));
|
||||
if (!$userInfo){
|
||||
continue;
|
||||
}
|
||||
$amount = $v['banker_amount'] + $v['player_amount'] + $v['tie_amount'];
|
||||
$winMoney = 0;
|
||||
// 双边洗码
|
||||
$ximaliang = 0;
|
||||
if($userInfo['type_xima'] == 1){
|
||||
$ximaliang = abs($v['banker_amount'] - $v['player_amount']);
|
||||
}
|
||||
// 龙赢
|
||||
if ($numberTabInfo['result'] == 1) {
|
||||
if($v['banker_amount'] > 0){
|
||||
$winMoney = round($v['banker_amount'] * (1 + $userInfo['price_dragon']),2) + $winMoney;
|
||||
}
|
||||
// 单边洗码
|
||||
if($userInfo['type_xima'] == 2){
|
||||
$ximaliang = $v['player_amount'];
|
||||
}
|
||||
}
|
||||
// 虎赢
|
||||
if ($numberTabInfo['result'] == 2) {
|
||||
if($v['player_amount'] > 0){
|
||||
$winMoney = round($v['player_amount'] * (1 + $userInfo['price_tiger']),2) + $winMoney;
|
||||
}
|
||||
// 单边洗码
|
||||
if($userInfo['type_xima'] == 2){
|
||||
$ximaliang = $v['banker_amount'];
|
||||
}
|
||||
}
|
||||
// 和
|
||||
if ($numberTabInfo['result'] == 3) {
|
||||
if (Env::get('system.dt_half') == 1) {
|
||||
$winMoney = round(($v['banker_amount'] + $v['player_amount']) / 2, 2) + $winMoney;
|
||||
} else {
|
||||
$winMoney = $v['banker_amount'] + $v['player_amount'] + $winMoney;
|
||||
}
|
||||
$ximaliang = 0;
|
||||
if ($v['tie_amount'] > 0) {
|
||||
$winMoney = $v['tie_amount'] * (1 + $userInfo['price_tie_dt']) + $winMoney;
|
||||
}
|
||||
}
|
||||
// 计算最终赢钱金额
|
||||
$winTotal = $winMoney - $amount;
|
||||
/**
|
||||
* Model处理
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $betInfo bet信息
|
||||
* @param array $userInfo bet用户信息
|
||||
* @param array $numberTabInfo 局信息
|
||||
* @param float $amount 下注总数
|
||||
* @param float $winTotal 赢金额
|
||||
* @param float $ximaliang 洗码量
|
||||
*/
|
||||
$res = Bet::openingBet($tableInfo,$v,$userInfo,$numberTabInfo,$amount,$winTotal,$ximaliang);
|
||||
if ($res['status']) {
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string)$v['user_id']);
|
||||
if ($userSession && is_array($userSession)) {
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening', ['status' => true, 'table_id' => $tableInfo['id'], 'round' => ['money' => $res['money'], 'win_total' => $winTotal, 'previous_number_tab_id' => $v['number_tab_id']]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,556 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\opening;
|
||||
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\CardPositionNn;
|
||||
use freedom\utils\RedisUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
class OpeningNnService
|
||||
{
|
||||
/**
|
||||
* TODO Dt开结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function openingNn(array $event, array $tableInfo, Websocket $ws){
|
||||
//判断结果并推送结果
|
||||
$res = self::doOpening($event,$tableInfo);
|
||||
if ($res['status'] == false){
|
||||
$ws->emit('openingNn',['status' => false, 'msg' => $res['msg']]);
|
||||
return;
|
||||
}
|
||||
list($data,$lastNumberTabInfo,$newNumberTabInfo) = $res['data'];
|
||||
$round = [
|
||||
'boot_id' => $newNumberTabInfo['boot_id'],
|
||||
'boot_num' => $newNumberTabInfo['boot_num'],
|
||||
'number_tab_id' => $newNumberTabInfo['id'],
|
||||
'previous_number_tab_id' => $lastNumberTabInfo['id'],
|
||||
'number_tab_number' => $newNumberTabInfo['number'] + 1,
|
||||
'number_tab_status' => InitTableService::numberTabStatus($newNumberTabInfo)
|
||||
];
|
||||
$round = array_merge($round,$data);
|
||||
$ws->emit('openingNn',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('openingNnResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
//处理注单
|
||||
self::doBet($ws,$tableInfo,$lastNumberTabInfo,$data);
|
||||
}
|
||||
/**
|
||||
* TODO 判断结果
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doOpening(array $event, array $tableInfo): array
|
||||
{
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'opening_fail_4'];
|
||||
//NN只有扫描台,不是扫描台返回false
|
||||
if ($tableInfo['is_scavenging'] != 1) return ['status' => false, 'msg' => 'opening_fail'];
|
||||
$cardInfo = RedisUtil::getCard($numberTabId);
|
||||
if (!$cardInfo) return ['status' => false, 'msg' => 'opening_fail_6'];
|
||||
// 判断是否所有的牌都已经扫描
|
||||
foreach ($cardInfo AS $v){
|
||||
if ($v == 0){
|
||||
return ['status' => false, 'msg' => 'opening_fail_6'];
|
||||
}
|
||||
}
|
||||
// 比较结果
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player1Card[3] = $cardInfo['player_1_card_4'];
|
||||
$player1Card[4] = $cardInfo['player_1_card_5'];
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player2Card[3] = $cardInfo['player_2_card_4'];
|
||||
$player2Card[4] = $cardInfo['player_2_card_5'];
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$player3Card[3] = $cardInfo['player_3_card_4'];
|
||||
$player3Card[4] = $cardInfo['player_3_card_5'];
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$bankerCard[3] = $cardInfo['banker_card_4'];
|
||||
$bankerCard[4] = $cardInfo['banker_card_5'];
|
||||
$player1Result = CardPositionNn::JudgeCowCow($player1Card);
|
||||
$player2Result = CardPositionNn::JudgeCowCow($player2Card);
|
||||
$player3Result = CardPositionNn::JudgeCowCow($player3Card);
|
||||
$bankerResult = CardPositionNn::JudgeCowCow($bankerCard);
|
||||
|
||||
$data = [];
|
||||
$data['result_player_1'] = $player1Result['cow'];
|
||||
$data['result_player_2'] = $player2Result['cow'];
|
||||
$data['result_player_3'] = $player3Result['cow'];
|
||||
$data['result_banker'] = $bankerResult['cow'];
|
||||
if($data['result_player_1'] > $data['result_banker']){
|
||||
$data['win_player_1'] = 1;
|
||||
}else if($data['result_player_1'] < $data['result_banker']){
|
||||
$data['win_player_1'] = 0;
|
||||
}else if($data['result_player_1'] == $data['result_banker']){
|
||||
$data['win_player_1'] = CardPositionNn::compareCard($player1Result['max'], $bankerResult['max']);
|
||||
}
|
||||
if($data['result_player_2'] > $data['result_banker']){
|
||||
$data['win_player_2'] = 1;
|
||||
}else if($data['result_player_2'] < $data['result_banker']){
|
||||
$data['win_player_2'] = 0;
|
||||
}else if($data['result_player_2'] == $data['result_banker']){
|
||||
$data['win_player_2'] = CardPositionNn::compareCard($player2Result['max'], $bankerResult['max']);
|
||||
}
|
||||
|
||||
if($data['result_player_3'] > $data['result_banker']){
|
||||
$data['win_player_3'] = 1;
|
||||
}else if($data['result_player_3'] < $data['result_banker']){
|
||||
$data['win_player_3'] = 0;
|
||||
}else if($data['result_player_3'] == $data['result_banker']){
|
||||
$data['win_player_3'] = CardPositionNn::compareCard($player3Result['max'], $bankerResult['max']);
|
||||
}
|
||||
//开盘
|
||||
$numberTabUpdate = [
|
||||
'result_player_1' => $data['result_player_1'],
|
||||
'result_player_2' => $data['result_player_2'],
|
||||
'result_player_3' => $data['result_player_3'],
|
||||
'result_banker' => $data['result_banker'],
|
||||
'win_player_1' => $data['win_player_1'],
|
||||
'win_player_2' => $data['win_player_2'],
|
||||
'win_player_3' => $data['win_player_3'],
|
||||
'end_time' => time(),
|
||||
'bet_status' => 3,
|
||||
];
|
||||
$newNumberTabInfo = NumberTab::next($numberTabInfo,$numberTabUpdate,$tableInfo);
|
||||
if ($newNumberTabInfo){
|
||||
$lastNumberTabInfo = array_merge($numberTabInfo,$numberTabUpdate);
|
||||
return ['status' => true, 'data' => [$data,$lastNumberTabInfo,$newNumberTabInfo]];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Bet处理
|
||||
* @param Websocket $ws 桌子信息
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $numberTabInfo 开结果的当前局信息
|
||||
* @param array $data 输赢数据
|
||||
* @return void
|
||||
*/
|
||||
public static function doBet(Websocket $ws, array $tableInfo, array $numberTabInfo, array $data){
|
||||
$bankerWinTotal = 0;
|
||||
if($numberTabInfo['rob_banker_id'] > 0 ){
|
||||
$betInfo = Bet::getByNumberTabIdNotRob($numberTabInfo['id'],$numberTabInfo['rob_banker_id']);
|
||||
$bankerBetInfo = Bet::getByNumberTabIdRob($numberTabInfo['id'],$numberTabInfo['rob_banker_id']);
|
||||
}else{
|
||||
$betInfo = Bet::getByNumberTabIdValid($numberTabInfo['id']);
|
||||
}
|
||||
foreach($betInfo AS $v){
|
||||
$userInfo = User::get(intval($v['user_id']));
|
||||
if (!$userInfo){
|
||||
continue;
|
||||
}
|
||||
$amount = $v['amount_player_1'] +
|
||||
$v['amount_player_1_times'] +
|
||||
$v['amount_player_1_banker'] +
|
||||
$v['amount_player_1_banker_times'] +
|
||||
$v['amount_player_2'] +
|
||||
$v['amount_player_2_times'] +
|
||||
$v['amount_player_2_banker'] +
|
||||
$v['amount_player_2_banker_times'] +
|
||||
$v['amount_player_3'] +
|
||||
$v['amount_player_3_times'] +
|
||||
$v['amount_player_3_banker'] +
|
||||
$v['amount_player_3_banker_times'];
|
||||
$withholdAmount = $v['withhold_player_1_times'] +
|
||||
$v['withhold_player_1_banker_times'] +
|
||||
$v['withhold_player_2_times'] +
|
||||
$v['withhold_player_2_banker_times'] +
|
||||
$v['withhold_player_3_times'] +
|
||||
$v['withhold_player_3_banker_times'];
|
||||
$winTotal = 0;
|
||||
$winTotalActual = 0;
|
||||
$timesPlayer1 = 1;
|
||||
$timesPlayer2 = 1;
|
||||
$timesPlayer3 = 1;
|
||||
$rebate = 0;
|
||||
// 双边洗码 (庄正闲负绝对值)
|
||||
$rebatePlayer1 = 0;
|
||||
$rebatePlayer2 = 0;
|
||||
$rebatePlayer3 = 0;
|
||||
//闲1
|
||||
if($data['win_player_1'] == 1){
|
||||
if($v['amount_player_1'] > 0){
|
||||
$winTotal += round($v['amount_player_1'] * $userInfo['price_n0_n6'],2);
|
||||
$winTotalActual += round($v['amount_player_1'] * 1,2);
|
||||
$rebatePlayer1 -= $v['amount_player_1'];
|
||||
}
|
||||
if($v['amount_player_1_times'] > 0){
|
||||
if(0 <= $data['result_player_1'] && $data['result_player_1'] < 7){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_n0_n6'],2);
|
||||
$winTotalActual += round($v['amount_player_1_times'] * 1,2);
|
||||
}elseif(7 <= $data['result_player_1'] && $data['result_player_1'] <= 9){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_n7_n9'],2) ;
|
||||
$winTotalActual += round($v['amount_player_1_times'] * 2,2);
|
||||
$timesPlayer1 = $userInfo['price_n7_n9'];
|
||||
}elseif($data['result_player_1'] == 10){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_nn'],2);
|
||||
$winTotalActual += round($v['amount_player_1_times'] * 3,2);
|
||||
$timesPlayer1 = $userInfo['price_nn'];
|
||||
}elseif($data['result_player_1'] == 11){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_5n'],2);
|
||||
$winTotalActual += round($v['amount_player_1_times'] * 5,2);
|
||||
$timesPlayer1 = $userInfo['price_5n'];
|
||||
}
|
||||
$rebatePlayer1 -= $v['amount_player_1_times'];
|
||||
}
|
||||
if($v['amount_player_1_banker'] > 0){
|
||||
$winTotal -= $v['amount_player_1_banker'];
|
||||
$winTotalActual -= $v['amount_player_1_banker'];
|
||||
$rebate += $v['amount_player_1_banker'];
|
||||
$rebatePlayer1 += $v['amount_player_1_banker'];
|
||||
}
|
||||
if($v['amount_player_1_banker_times'] > 0){
|
||||
if(0 <= $data['result_player_1'] && $data['result_player_1'] < 7){
|
||||
$winTotal -= $v['amount_player_1_banker_times'];
|
||||
$rebate += $v['amount_player_1_banker_times'];
|
||||
$rebatePlayer1 += $v['amount_player_1_banker_times'];
|
||||
}elseif(7 <= $data['result_player_1'] && $data['result_player_1'] <= 9){
|
||||
$winTotal -= round($v['amount_player_1_banker_times'] * 2,2);
|
||||
$rebate += round($v['amount_player_1_banker_times'] * 2);
|
||||
$rebatePlayer1 += round($v['amount_player_1_banker_times'] * 2);
|
||||
}elseif($data['result_player_1'] == 10){
|
||||
$winTotal -= round($v['amount_player_1_banker_times'] * 3,2);
|
||||
$rebate += round($v['amount_player_1_banker_times'] * 3);
|
||||
$rebatePlayer1 += round($v['amount_player_1_banker_times'] * 3);
|
||||
}elseif($data['result_player_1'] == 11){
|
||||
$winTotal -= round($v['amount_player_1_banker_times'] * 5,2);
|
||||
$rebate += round($v['amount_player_1_banker_times'] * 5);
|
||||
$rebatePlayer1 += round($v['amount_player_1_banker_times'] * 5);
|
||||
}
|
||||
}
|
||||
}elseif($data['win_player_1'] == 0){
|
||||
if($v['amount_player_1_banker'] > 0){
|
||||
$winTotal += round($v['amount_player_1_banker'] * $userInfo['price_n0_n6'],2) ;
|
||||
$rebatePlayer1 += $v['amount_player_1_banker'];
|
||||
}
|
||||
if($v['amount_player_1_banker_times'] > 0){
|
||||
if(0 <= $data['result_banker'] && $data['result_banker'] < 7){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_n0_n6'],2);
|
||||
}elseif(7 <= $data['result_banker'] && $data['result_banker'] <= 9){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_n7_n9'],2);
|
||||
$timesPlayer1 = $userInfo['price_n7_n9'];
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_nn'],2);
|
||||
$timesPlayer1 = $userInfo['price_nn'];
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_5n'],2);
|
||||
$timesPlayer1 = $userInfo['price_5n'];
|
||||
}
|
||||
$rebatePlayer1 += $v['amount_player_1_banker_times'];
|
||||
}
|
||||
if($v['amount_player_1'] > 0){
|
||||
$winTotal -= $v['amount_player_1'];
|
||||
$rebate += $v['amount_player_1'];
|
||||
$rebatePlayer1 -= $v['amount_player_1'];
|
||||
}
|
||||
if($v['amount_player_1_times'] > 0){
|
||||
if(0 <= $data['result_banker'] && $data['result_banker'] < 7){
|
||||
$winTotal -= $v['amount_player_1_times'];
|
||||
$rebate += $v['amount_player_1_times'];
|
||||
$rebatePlayer1 -= $v['amount_player_1_times'];
|
||||
}elseif(7 <= $data['result_banker'] && $data['result_banker'] <= 9){
|
||||
$winTotal -= $v['amount_player_1_times'] * 2;
|
||||
$winTotalActual -= $v['amount_player_1_times'] * 2;
|
||||
$rebate += $v['amount_player_1_times'] * 2;
|
||||
$rebatePlayer1 -= $v['amount_player_1_times'] * 2;
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal -= $v['amount_player_1_times'] * 3;
|
||||
$winTotalActual -= $v['amount_player_1_times'] * 3;
|
||||
$rebate += $v['amount_player_1_times'] * 3;
|
||||
$rebatePlayer1 -= $v['amount_player_1_times'] * 3;
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal -= $v['amount_player_1_times'] * 5;
|
||||
$winTotalActual -= $v['amount_player_1_times'] * 5;
|
||||
$rebate += $v['amount_player_1_times'] * 5;
|
||||
$rebatePlayer1 -= $v['amount_player_1_times'] * 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
//闲2
|
||||
if($data['win_player_2'] == 1){
|
||||
if($v['amount_player_2'] > 0){
|
||||
$winTotal += round($v['amount_player_2'] * $userInfo['price_n0_n6'],2);
|
||||
$winTotalActual += round($v['amount_player_2'] * 1,2);
|
||||
$rebatePlayer2 -= $v['amount_player_2'];
|
||||
}
|
||||
if($v['amount_player_2_times'] > 0){
|
||||
if(0 <= $data['result_player_2'] && $data['result_player_2'] < 7){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_n0_n6'],2);
|
||||
$winTotalActual += round($v['amount_player_2_times'] * 1,2);
|
||||
}elseif(7 <= $data['result_player_2'] && $data['result_player_2'] <= 9){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_n7_n9'],2) ;
|
||||
$winTotalActual += round($v['amount_player_2_times'] * 2,2);
|
||||
$timesPlayer2 = $userInfo['price_n7_n9'];
|
||||
}elseif($data['result_player_2'] == 10){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_nn'],2);
|
||||
$winTotalActual += round($v['amount_player_2_times'] * 3,2);
|
||||
$timesPlayer2 = $userInfo['price_nn'];
|
||||
}elseif($data['result_player_2'] == 11){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_5n'],2);
|
||||
$winTotalActual += round($v['amount_player_2_times'] * 5,2);
|
||||
$timesPlayer2 = $userInfo['price_5n'];
|
||||
}
|
||||
$rebatePlayer2 -= $v['amount_player_2_times'];
|
||||
}
|
||||
if($v['amount_player_2_banker'] > 0){
|
||||
$winTotal -= $v['amount_player_2_banker'];
|
||||
$winTotalActual -= $v['amount_player_2_banker'];
|
||||
$rebate += $v['amount_player_2_banker'];
|
||||
$rebatePlayer2 += $v['amount_player_2_banker'];
|
||||
}
|
||||
if($v['amount_player_2_banker_times'] > 0){
|
||||
if(0 <= $data['result_player_2'] && $data['result_player_2'] < 7){
|
||||
$winTotal -= $v['amount_player_2_banker_times'];
|
||||
$rebate += $v['amount_player_2_banker_times'];
|
||||
$rebatePlayer2 += $v['amount_player_2_banker_times'];
|
||||
}elseif(7 <= $data['result_player_2'] && $data['result_player_2'] <= 9){
|
||||
$winTotal -= round($v['amount_player_2_banker_times'] * 2,2);
|
||||
$rebate += round($v['amount_player_2_banker_times'] * 2);
|
||||
$rebatePlayer2 += round($v['amount_player_2_banker_times'] * 2);
|
||||
}elseif($data['result_player_2'] == 10){
|
||||
$winTotal -= round($v['amount_player_2_banker_times'] * 3,2);
|
||||
$rebate += round($v['amount_player_2_banker_times'] * 3);
|
||||
$rebatePlayer2 += round($v['amount_player_2_banker_times'] * 3);
|
||||
}elseif($data['result_player_2'] == 11){
|
||||
$winTotal -= round($v['amount_player_2_banker_times'] * 5,2);
|
||||
$rebate += round($v['amount_player_2_banker_times'] * 5);
|
||||
$rebatePlayer2 += round($v['amount_player_2_banker_times'] * 5);
|
||||
}
|
||||
}
|
||||
}elseif($data['win_player_2'] == 0){
|
||||
if($v['amount_player_2_banker'] > 0){
|
||||
$winTotal += round($v['amount_player_2_banker'] * $userInfo['price_n0_n6'],2) ;
|
||||
$rebatePlayer2 += $v['amount_player_2_banker'];
|
||||
}
|
||||
if($v['amount_player_2_banker_times'] > 0){
|
||||
if(0 <= $data['result_banker'] && $data['result_banker'] < 7){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_n0_n6'],2);
|
||||
}elseif(7 <= $data['result_banker'] && $data['result_banker'] <= 9){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_n7_n9'],2);
|
||||
$timesPlayer2 = $userInfo['price_n7_n9'];
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_nn'],2);
|
||||
$timesPlayer2 = $userInfo['price_nn'];
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_5n'],2);
|
||||
$timesPlayer2 = $userInfo['price_5n'];
|
||||
}
|
||||
$rebatePlayer2 += $v['amount_player_2_banker_times'];
|
||||
}
|
||||
if($v['amount_player_2'] > 0){
|
||||
$winTotal -= $v['amount_player_2'];
|
||||
$rebate += $v['amount_player_2'];
|
||||
$rebatePlayer2 -= $v['amount_player_2'];
|
||||
}
|
||||
if($v['amount_player_2_times'] > 0){
|
||||
if(0 <= $data['result_banker'] && $data['result_banker'] < 7){
|
||||
$winTotal -= $v['amount_player_2_times'];
|
||||
$rebate += $v['amount_player_2_times'];
|
||||
$rebatePlayer2 -= $v['amount_player_2_times'];
|
||||
}elseif(7 <= $data['result_banker'] && $data['result_banker'] <= 9){
|
||||
$winTotal -= $v['amount_player_2_times'] * 2;
|
||||
$winTotalActual -= $v['amount_player_2_times'] * 2;
|
||||
$rebate += $v['amount_player_2_times'] * 2;
|
||||
$rebatePlayer2 -= $v['amount_player_2_times'] * 2;
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal -= $v['amount_player_2_times'] * 3;
|
||||
$winTotalActual -= $v['amount_player_2_times'] * 3;
|
||||
$rebate += $v['amount_player_2_times'] * 3;
|
||||
$rebatePlayer2 -= $v['amount_player_2_times'] * 3;
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal -= $v['amount_player_2_times'] * 5;
|
||||
$winTotalActual -= $v['amount_player_2_times'] * 5;
|
||||
$rebate += $v['amount_player_2_times'] * 5;
|
||||
$rebatePlayer2 -= $v['amount_player_2_times'] * 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
//闲3
|
||||
if($data['win_player_3'] == 1){
|
||||
if($v['amount_player_3'] > 0){
|
||||
$winTotal += round($v['amount_player_3'] * $userInfo['price_n0_n6'],2);
|
||||
$winTotalActual += round($v['amount_player_3'] * 1,2);
|
||||
$rebatePlayer3 -= $v['amount_player_3'];
|
||||
}
|
||||
if($v['amount_player_3_times'] > 0){
|
||||
if(0 <= $data['result_player_3'] && $data['result_player_3'] < 7){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_n0_n6'],2);
|
||||
$winTotalActual += round($v['amount_player_3_times'] * 1,2);
|
||||
}elseif(7 <= $data['result_player_3'] && $data['result_player_3'] <= 9){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_n7_n9'],2) ;
|
||||
$winTotalActual += round($v['amount_player_3_times'] * 2,2);
|
||||
$timesPlayer3 = $userInfo['price_n7_n9'];
|
||||
}elseif($data['result_player_3'] == 10){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_nn'],2);
|
||||
$winTotalActual += round($v['amount_player_3_times'] * 3,2);
|
||||
$timesPlayer3 = $userInfo['price_nn'];
|
||||
}elseif($data['result_player_3'] == 11){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_5n'],2);
|
||||
$winTotalActual += round($v['amount_player_3_times'] * 5,2);
|
||||
$timesPlayer3 = $userInfo['price_5n'];
|
||||
}
|
||||
$rebatePlayer3 -= $v['amount_player_3_times'];
|
||||
}
|
||||
if($v['amount_player_3_banker'] > 0){
|
||||
$winTotal -= $v['amount_player_3_banker'];
|
||||
$winTotalActual -= $v['amount_player_3_banker'];
|
||||
$rebate += $v['amount_player_3_banker'];
|
||||
$rebatePlayer3 += $v['amount_player_3_banker'];
|
||||
}
|
||||
if($v['amount_player_3_banker_times'] > 0){
|
||||
if(0 <= $data['result_player_3'] && $data['result_player_3'] < 7){
|
||||
$winTotal -= $v['amount_player_3_banker_times'];
|
||||
$rebate += $v['amount_player_3_banker_times'];
|
||||
$rebatePlayer3 += $v['amount_player_3_banker_times'];
|
||||
}elseif(7 <= $data['result_player_3'] && $data['result_player_3'] <= 9){
|
||||
$winTotal -= round($v['amount_player_3_banker_times'] * 2,2);
|
||||
$rebate += round($v['amount_player_3_banker_times'] * 2);
|
||||
$rebatePlayer3 += round($v['amount_player_3_banker_times'] * 2);
|
||||
}elseif($data['result_player_3'] == 10){
|
||||
$winTotal -= round($v['amount_player_3_banker_times'] * 3,2);
|
||||
$rebate += round($v['amount_player_3_banker_times'] * 3);
|
||||
$rebatePlayer3 += round($v['amount_player_3_banker_times'] * 3);
|
||||
}elseif($data['result_player_3'] == 11){
|
||||
$winTotal -= round($v['amount_player_3_banker_times'] * 5,2);
|
||||
$rebate += round($v['amount_player_3_banker_times'] * 5);
|
||||
$rebatePlayer3 += round($v['amount_player_3_banker_times'] * 5);
|
||||
}
|
||||
}
|
||||
|
||||
}elseif($data['win_player_3'] == 0){
|
||||
if($v['amount_player_3_banker'] > 0){
|
||||
$winTotal += round($v['amount_player_3_banker'] * $userInfo['price_n0_n6'],2) ;
|
||||
$rebatePlayer3 += $v['amount_player_3_banker'];
|
||||
}
|
||||
if($v['amount_player_3_banker_times'] > 0){
|
||||
if(0 <= $data['result_banker'] && $data['result_banker'] < 7){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_n0_n6'],2);
|
||||
}elseif(7 <= $data['result_banker'] && $data['result_banker'] <= 9){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_n7_n9'],2);
|
||||
$timesPlayer3 = $userInfo['price_n7_n9'];
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_nn'],2);
|
||||
$timesPlayer3 = $userInfo['price_nn'];
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_5n'],2);
|
||||
$timesPlayer3 = $userInfo['price_5n'];
|
||||
}
|
||||
$rebatePlayer3 += $v['amount_player_3_banker_times'];
|
||||
}
|
||||
if($v['amount_player_3'] > 0){
|
||||
$winTotal -= $v['amount_player_3'];
|
||||
$rebate += $v['amount_player_3'];
|
||||
$rebatePlayer3 -= $v['amount_player_3'];
|
||||
}
|
||||
if($v['amount_player_3_times'] > 0){
|
||||
if(0 <= $data['result_banker'] && $data['result_banker'] < 7){
|
||||
$winTotal -= $v['amount_player_3_times'];
|
||||
$rebate += $v['amount_player_3_times'];
|
||||
$rebatePlayer3 -= $v['amount_player_3_times'];
|
||||
}elseif(7 <= $data['result_banker'] && $data['result_banker'] <= 9){
|
||||
$winTotal -= $v['amount_player_3_times'] * 2;
|
||||
$winTotalActual -= $v['amount_player_3_times'] * 2;
|
||||
$rebate += $v['amount_player_3_times'] * 2;
|
||||
$rebatePlayer3 -= $v['amount_player_3_times'] * 2;
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal -= $v['amount_player_3_times'] * 3;
|
||||
$winTotalActual -= $v['amount_player_3_times'] * 3;
|
||||
$rebate += $v['amount_player_3_times'] * 3;
|
||||
$rebatePlayer3 -= $v['amount_player_3_times'] * 3;
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal -= $v['amount_player_3_times'] * 5;
|
||||
$winTotalActual -= $v['amount_player_3_times'] * 5;
|
||||
$rebate += $v['amount_player_3_times'] * 5;
|
||||
$rebatePlayer3 -= $v['amount_player_3_times'] * 5;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 双边洗码
|
||||
if($userInfo['type_xima'] == 1){
|
||||
$rebate = abs($rebatePlayer1) + abs($rebatePlayer2) + abs($rebatePlayer3);
|
||||
}
|
||||
|
||||
//计算庄家输赢
|
||||
if($numberTabInfo['rob_banker_username']){
|
||||
if($userInfo['is_sw'] == 0){
|
||||
$bankerWinTotal = $winTotalActual + $bankerWinTotal;
|
||||
}
|
||||
}
|
||||
$v['position_first'] = $numberTabInfo['position_first'];
|
||||
$betInfoItem = array_merge($v,$data);
|
||||
$betInfoItem['times_player_1'] = $timesPlayer1;
|
||||
$betInfoItem['times_player_2'] = $timesPlayer2;
|
||||
$betInfoItem['times_player_3'] = $timesPlayer3;
|
||||
$res = Bet::openingBet($tableInfo,$betInfoItem,$userInfo,$numberTabInfo,$amount,$winTotal,$rebate,$withholdAmount);
|
||||
if ($res['status']){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $v['user_id']);
|
||||
if ($userSession && is_array($userSession)){
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening',[
|
||||
'status' => true,
|
||||
'table_id' => $tableInfo['id'],
|
||||
'round' => [
|
||||
'money' => $res['money'],
|
||||
'win_total' => $winTotal,
|
||||
'previous_number_tab_id' => $v['number_tab_id']
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算抢庄
|
||||
*/
|
||||
if($numberTabInfo['rob_banker_id'] > 0){
|
||||
$userInfo = User::get(intval($numberTabInfo['rob_banker_id']));
|
||||
//更新user表余额
|
||||
$winTotal = to_number($bankerWinTotal);
|
||||
if($winTotal > 0){
|
||||
$winTotal = $winTotal * 0.94;
|
||||
}
|
||||
$amount = 0;
|
||||
$rebate = abs($bankerWinTotal);
|
||||
$bankerBetInfo = array_merge($bankerBetInfo,$data);
|
||||
$res = Bet::openingBet($tableInfo,$bankerBetInfo,$userInfo,$numberTabInfo,$amount,$winTotal,$rebate);
|
||||
if ($res['status']){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $userInfo['id']);
|
||||
if ($userSession && is_array($userSession)){
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening',[
|
||||
'status' => true,
|
||||
'table_id' => $tableInfo['id'],
|
||||
'round' => [
|
||||
'money' => $res['money'],
|
||||
'previous_number_tab_id' => $bankerBetInfo['number_tab_id']
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\opening;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\Boot;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\RouletteUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果服务
|
||||
* Class OpeningRouletteService
|
||||
* @package app\services\opening
|
||||
*/
|
||||
class OpeningRouletteService
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function openingRoulette(array $event, array $tableInfo, Websocket $ws){
|
||||
//判断结果并推送结果
|
||||
$res = self::doOpening($event,$tableInfo);
|
||||
if ($res['status'] == false){
|
||||
$ws->emit('openingRoulette',['status' => false,'table_id' => $tableInfo['id'], 'msg' => $res['msg']]);
|
||||
return;
|
||||
}
|
||||
list($result,$resultParse,$lastNumberTabInfo,$newNumberTabInfo) = $res['data'];
|
||||
$round = array(
|
||||
'result' => $result,
|
||||
'result_parse' => $resultParse,
|
||||
'boot_id' => $newNumberTabInfo['boot_id'],
|
||||
'boot_num' => $newNumberTabInfo['boot_num'],
|
||||
'number_tab_id' => $newNumberTabInfo['id'],
|
||||
'previous_number_tab_id' => $lastNumberTabInfo['id'],
|
||||
'number_tab_number' => $newNumberTabInfo['number'],
|
||||
'number_tab_status' => InitTableService::numberTabStatus($newNumberTabInfo)
|
||||
);
|
||||
$ws->emit('openingRoulette',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('openingRouletteResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
//处理注单
|
||||
self::doBet($ws,$tableInfo,$lastNumberTabInfo,$result,$resultParse);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 判断结果
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doOpening(array $event, array $tableInfo): array
|
||||
{
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'opening_fail_4'];
|
||||
$result = intval($event['result']);
|
||||
if ($result < 0 || $result > 36) return ['status' => false, 'msg' => 'opening_fail'];
|
||||
$boot = Boot::where(['id' => $numberTabInfo['boot_id']])->find();
|
||||
$afterCountArray = RouletteUtil::parseCount($result);
|
||||
$beforeCountString = $boot['roulette_count'];
|
||||
$beforeCountArray = string_to_array($beforeCountString);
|
||||
$countArray = RouletteUtil::countInc($beforeCountArray, $afterCountArray);
|
||||
$countString = array_to_string($countArray);
|
||||
$numberTabInfo['roulette_count'] = $countString;
|
||||
$resultParse = RouletteUtil::parseResult($result);
|
||||
$numberTabUpdate = ['roulette_result' => $result, 'end_time' => time(), 'bet_status' => 3];
|
||||
$newNumberTabInfo = NumberTab::next($numberTabInfo,$numberTabUpdate,$tableInfo);
|
||||
if ($newNumberTabInfo){
|
||||
$lastNumberTabInfo = array_merge($numberTabInfo,$numberTabUpdate);
|
||||
return ['status' => true, 'data' => [$result,$resultParse,$lastNumberTabInfo,$newNumberTabInfo]];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Bet处理
|
||||
* @param Websocket $ws 桌子信息
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $numberTabInfo 开结果的当前局信息
|
||||
* @return void
|
||||
*/
|
||||
public static function doBet(Websocket $ws, array $tableInfo, array $numberTabInfo, int $result, array $resultParse){
|
||||
$betArray = Bet::getByNumberTabIdValid($numberTabInfo['id']);
|
||||
foreach ($betArray AS $v){
|
||||
$userInfo = User::get(intval($v['user_id']));
|
||||
if (!$userInfo) continue;
|
||||
if (empty($v['roulette_european_amount']) && empty($v['roulette_french_amount'])) continue;
|
||||
$priceArray = string_to_array($userInfo['price_roulette']);
|
||||
|
||||
$amount = 0;
|
||||
$winMoney = 0;
|
||||
$roulette_amount = $v['roulette_european_amount'] ? $v['roulette_european_amount'] : $v['roulette_french_amount'];
|
||||
$amountArray = string_to_array($roulette_amount);
|
||||
foreach ($amountArray as $key => $value){
|
||||
$amount += intval($value);
|
||||
|
||||
if(in_array($key, ['zeroGame','neighborsOfZero','orphans','theThird'])){
|
||||
if($key == 'zeroGame'){
|
||||
$split_value = $value / 4;
|
||||
if($result == 26){
|
||||
$winMoney = round($split_value * (1 + $priceArray['straight']),2) + $winMoney;
|
||||
}
|
||||
if(in_array($result,[0,3,12,15,32,35])){
|
||||
$winMoney = round($split_value * (1 + $priceArray['split']),2) + $winMoney;
|
||||
}
|
||||
}
|
||||
if($key == 'neighborsOfZero'){
|
||||
$split_value = $value / 9;
|
||||
if(in_array($result,[4,7,12,15,18,21,19,22,32,35])){
|
||||
$winMoney = round($split_value * (1 + $priceArray['split']),2) + $winMoney;
|
||||
}
|
||||
if(in_array($result,[0,2,3])){
|
||||
$winMoney = round($split_value * 2 * (1 + $priceArray['triple']),2) + $winMoney;
|
||||
}
|
||||
if(in_array($result,[25,26,28,29])){
|
||||
$winMoney = round($split_value * 2 * (1 + $priceArray['corner']),2) + $winMoney;
|
||||
}
|
||||
}
|
||||
|
||||
if($key == 'orphans'){
|
||||
$split_value = $value / 5;
|
||||
if($result == 1){
|
||||
$winMoney = round($split_value * (1 + $priceArray['straight']),2) + $winMoney;
|
||||
}
|
||||
if(in_array($result,[6,9,14,17,20,31,34])){
|
||||
if($result == 17){
|
||||
$winMoney = round($split_value * 2 * (1 + $priceArray['split']),2) + $winMoney;
|
||||
}else{
|
||||
$winMoney = round($split_value * (1 + $priceArray['split']),2) + $winMoney;
|
||||
}
|
||||
}
|
||||
}
|
||||
if($key == 'theThird'){
|
||||
$split_value = $value / 6;
|
||||
if(in_array($result,[5,8,10,11,13,16,23,24,27,30,33,36])){
|
||||
$winMoney = round($split_value * (1 + $priceArray['split']),2) + $winMoney;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(in_array($key,['low','high','odd','even','red','black','column_1','column_2','column_3','dozen_1','dozen_2','dozen_3'])){
|
||||
if (in_array($key, $resultParse)){
|
||||
if(in_array($key,['low','high','odd','even','red','black'])){
|
||||
$winMoney = round($value * (1 + $priceArray[$key]),2) + $winMoney;
|
||||
}else{
|
||||
$keyArray = explode("_", $key);
|
||||
$winMoney = round($value * (1 + $priceArray[$keyArray[0]]),2) + $winMoney;
|
||||
}
|
||||
|
||||
}
|
||||
}else{
|
||||
$keyArray = explode("_", $key);
|
||||
if($keyArray[0] == 'straight') {
|
||||
if ($keyArray[1] == $result) {
|
||||
$winMoney = round($value * (1 + $priceArray[$keyArray[0]]),2) + $winMoney;
|
||||
}
|
||||
}else{
|
||||
$betZoneArr = explode("-", $keyArray[1]);
|
||||
if(in_array($result,$betZoneArr)){
|
||||
$winMoney = round($value * (1 + $priceArray[$keyArray[0]]),2) + $winMoney;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
$winTotal = $winMoney - $amount;
|
||||
/**
|
||||
* Model处理
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $betInfo bet信息
|
||||
* @param array $userInfo bet用户信息
|
||||
* @param array $numberTabInfo 局信息
|
||||
* @param float $amount 下注总数
|
||||
* @param float $winTotal 赢金额
|
||||
* @param float $ximaliang 洗码量
|
||||
*/
|
||||
$res = Bet::openingBet($tableInfo,$v,$userInfo,$numberTabInfo,$amount,$winTotal,0);
|
||||
if ($res['status']){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $v['user_id']);
|
||||
if ($userSession && is_array($userSession)){
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening',['status' => true, 'table_id' => $tableInfo['id'], 'round' => ['money' => $res['money'], 'win_total' => $winTotal, 'previous_number_tab_id' => $v['number_tab_id']]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,676 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\opening;
|
||||
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\CardPositionTc;
|
||||
use freedom\utils\RedisUtil;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
class OpeningTcService
|
||||
{
|
||||
/**
|
||||
* TODO Dt开结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function openingTc(array $event, array $tableInfo, Websocket $ws){
|
||||
//判断结果并推送结果
|
||||
$res = self::doOpening($event,$tableInfo);
|
||||
if ($res['status'] == false){
|
||||
$ws->emit('openingTc',['status' => false, 'msg' => $res['msg']]);
|
||||
return;
|
||||
}
|
||||
list($data,$lastNumberTabInfo,$newNumberTabInfo) = $res['data'];
|
||||
$round = [
|
||||
'boot_id' => $newNumberTabInfo['boot_id'],
|
||||
'boot_num' => $newNumberTabInfo['boot_num'],
|
||||
'number_tab_id' => $newNumberTabInfo['id'],
|
||||
'previous_number_tab_id' => $lastNumberTabInfo['id'],
|
||||
'number_tab_number' => $newNumberTabInfo['number'] + 1,
|
||||
'number_tab_status' => InitTableService::numberTabStatus($newNumberTabInfo)
|
||||
];
|
||||
$round = array_merge($round,$data);
|
||||
$ws->emit('openingTc',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('openingTcResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
//处理注单
|
||||
self::doBet($ws,$tableInfo,$lastNumberTabInfo,$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 判断结果
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doOpening(array $event, array $tableInfo): array
|
||||
{
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'opening_fail_4'];
|
||||
//TC只有扫描台,不是扫描台返回false
|
||||
if ($tableInfo['is_scavenging'] != 1) return ['status' => false, 'msg' => 'opening_fail'];
|
||||
$cardInfo = RedisUtil::getCard($numberTabId);
|
||||
if (!$cardInfo) return ['status' => false, 'msg' => 'opening_fail_6'];
|
||||
// 判断是否所有的牌都已经扫描
|
||||
foreach ($cardInfo AS $v){
|
||||
if ($v == 0){
|
||||
return ['status' => false, 'msg' => 'opening_fail_6'];
|
||||
}
|
||||
}
|
||||
// 比较结果
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$player1Result = CardPositionTc::ThredCardCowCow($player1Card);
|
||||
$player2Result = CardPositionTc::ThredCardCowCow($player2Card);
|
||||
$player3Result = CardPositionTc::ThredCardCowCow($player3Card);
|
||||
$bankerResult = CardPositionTc::ThredCardCowCow($bankerCard);
|
||||
|
||||
$data = [];
|
||||
$data['result_player_1'] = $player1Result['cow'];
|
||||
$data['result_player_2'] = $player2Result['cow'];
|
||||
$data['result_player_3'] = $player3Result['cow'];
|
||||
$data['result_banker'] = $bankerResult['cow'];
|
||||
if($data['result_player_1'] > $data['result_banker']){
|
||||
$data['win_player_1'] = 1;
|
||||
}else if($data['result_player_1'] < $data['result_banker']){
|
||||
$data['win_player_1'] = 0;
|
||||
}else if($data['result_player_1'] == $data['result_banker']){
|
||||
$data['win_player_1'] = CardPositionTc::compareCardTc($player1Result['max'], $bankerResult['max'],$data['result_player_1']);
|
||||
}
|
||||
if($data['result_player_2'] > $data['result_banker']){
|
||||
$data['win_player_2'] = 1;
|
||||
}else if($data['result_player_2'] < $data['result_banker']){
|
||||
$data['win_player_2'] = 0;
|
||||
}else if($data['result_player_2'] == $data['result_banker']){
|
||||
$data['win_player_2'] = CardPositionTc::compareCardTc($player2Result['max'], $bankerResult['max'],$data['result_player_2']);
|
||||
}
|
||||
|
||||
if($data['result_player_3'] > $data['result_banker']){
|
||||
$data['win_player_3'] = 1;
|
||||
}else if($data['result_player_3'] < $data['result_banker']){
|
||||
$data['win_player_3'] = 0;
|
||||
}else if($data['result_player_3'] == $data['result_banker']){
|
||||
$data['win_player_3'] = CardPositionTc::compareCardTc($player3Result['max'], $bankerResult['max'],$data['result_player_3']);
|
||||
}
|
||||
//开盘
|
||||
$numberTabUpdate = [
|
||||
'result_player_1' => $data['result_player_1'],
|
||||
'result_player_2' => $data['result_player_2'],
|
||||
'result_player_3' => $data['result_player_3'],
|
||||
'result_banker' => $data['result_banker'],
|
||||
'win_player_1' => $data['win_player_1'],
|
||||
'win_player_2' => $data['win_player_2'],
|
||||
'win_player_3' => $data['win_player_3'],
|
||||
'end_time' => time(),
|
||||
'bet_status' => 3,
|
||||
];
|
||||
$newNumberTabInfo = NumberTab::next($numberTabInfo,$numberTabUpdate,$tableInfo);
|
||||
if ($newNumberTabInfo){
|
||||
$lastNumberTabInfo = array_merge($numberTabInfo,$numberTabUpdate);
|
||||
return ['status' => true, 'data' => [$data,$lastNumberTabInfo,$newNumberTabInfo]];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail'];
|
||||
}
|
||||
}
|
||||
/**
|
||||
* TODO Bet处理
|
||||
* @param Websocket $ws 桌子信息
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $numberTabInfo 开结果的当前局信息
|
||||
* @param array $data 输赢数据
|
||||
* @return void
|
||||
*/
|
||||
public static function doBet(Websocket $ws, array $tableInfo, array $numberTabInfo, array $data){
|
||||
$bankerWinTotal = 0;
|
||||
if($numberTabInfo['rob_banker_id'] > 0 ){
|
||||
$betInfo = Bet::getByNumberTabIdNotRob($numberTabInfo['id'],$numberTabInfo['rob_banker_id']);
|
||||
$bankerBetInfo = Bet::getByNumberTabIdRob($numberTabInfo['id'],$numberTabInfo['rob_banker_id']);
|
||||
}else{
|
||||
$betInfo = Bet::getByNumberTabIdValid($numberTabInfo['id']);
|
||||
}
|
||||
foreach($betInfo AS $v){
|
||||
$userInfo = User::get(intval($v['user_id']));
|
||||
if (!$userInfo){
|
||||
continue;
|
||||
}
|
||||
$amount = $v['amount_player_1'] +
|
||||
$v['amount_player_1_times'] +
|
||||
$v['amount_player_1_banker'] +
|
||||
$v['amount_player_1_banker_times'] +
|
||||
$v['amount_player_2'] +
|
||||
$v['amount_player_2_times'] +
|
||||
$v['amount_player_2_banker'] +
|
||||
$v['amount_player_2_banker_times'] +
|
||||
$v['amount_player_3'] +
|
||||
$v['amount_player_3_times'] +
|
||||
$v['amount_player_3_banker'] +
|
||||
$v['amount_player_3_banker_times'];
|
||||
$withholdAmount = $v['withhold_player_1_times'] +
|
||||
$v['withhold_player_1_banker_times'] +
|
||||
$v['withhold_player_2_times'] +
|
||||
$v['withhold_player_2_banker_times'] +
|
||||
$v['withhold_player_3_times'] +
|
||||
$v['withhold_player_3_banker_times'];
|
||||
$newAmount = 0;
|
||||
$winTotal = 0;
|
||||
$winTotalActual = 0;
|
||||
$timesPlayer1 = 1;
|
||||
$timesPlayer2 = 1;
|
||||
$timesPlayer3 = 1;
|
||||
$rebate = 0;
|
||||
// 双边洗码 (对冲 庄正闲负绝对值)
|
||||
$rebatePlayer1 = 0;
|
||||
$rebatePlayer2 = 0;
|
||||
$rebatePlayer3 = 0;
|
||||
|
||||
//闲1
|
||||
if($data['win_player_1'] == 1){
|
||||
if($v['amount_player_1'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal += round($v['amount_player_1'] * $userInfo['price_tc_n1'],2);
|
||||
$winTotalActual += round($v['amount_player_1'] * $times,2);
|
||||
$newAmount += $v['amount_player_1'];
|
||||
$rebatePlayer1 -= $v['amount_player_1'];
|
||||
}
|
||||
if($v['amount_player_1_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_player_1']);
|
||||
if($data['result_player_1'] == 1){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n1'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n1'];
|
||||
}elseif($data['result_player_1'] == 2){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n2'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n2'];
|
||||
}elseif($data['result_player_1'] == 3){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n3'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n3'];
|
||||
}elseif($data['result_player_1'] == 4){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n4'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n4'];
|
||||
}elseif($data['result_player_1'] == 5){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n5'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n5'];
|
||||
}elseif($data['result_player_1'] == 6){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n6'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n6'];
|
||||
}elseif($data['result_player_1'] == 7){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n7'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n7'];
|
||||
}elseif($data['result_player_1'] == 8){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n8'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n8'];
|
||||
}elseif($data['result_player_1'] == 9){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_n9'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n9'];
|
||||
}elseif($data['result_player_1'] == 10){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_nn'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_nn'];
|
||||
}elseif($data['result_player_1'] == 11){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_bz'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_bz'];
|
||||
}elseif($data['result_player_1'] == 12){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_ths'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_ths'];
|
||||
}elseif($data['result_player_1'] == 13){
|
||||
$winTotal += round($v['amount_player_1_times'] * $userInfo['price_tc_hjths'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_hjths'];
|
||||
}
|
||||
$winTotalActual += round($v['amount_player_1_times'] * $times,2);
|
||||
$newAmount += $v['amount_player_1_times'];
|
||||
$rebatePlayer1 -= $v['amount_player_1_times'];
|
||||
}
|
||||
|
||||
if($v['amount_player_1_banker'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal -= round($v['amount_player_1_banker'] * $times,2);
|
||||
$rebatePlayer1 += round($v['amount_player_1_banker'] * $times,2);
|
||||
$newAmount += $v['amount_player_1_banker'] * $times;
|
||||
$rebate += $v['amount_player_1_banker'] * $times;
|
||||
}
|
||||
if($v['amount_player_1_banker_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_player_1']);
|
||||
$winTotal -= round($v['amount_player_1_banker_times'] * $times,2);
|
||||
$rebatePlayer1 += round($v['amount_player_1_banker_times'] * $times,2);
|
||||
$newAmount += $v['amount_player_1_banker_times'] * $times;
|
||||
$rebate += $v['amount_player_1_banker_times'] * $times;
|
||||
}
|
||||
|
||||
}elseif($data['win_player_1'] == 0){
|
||||
if($v['amount_player_1_banker'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal += round($v['amount_player_1_banker'] * $userInfo['price_tc_n1'],2);
|
||||
$newAmount += $v['amount_player_1_banker'] * $times;
|
||||
$rebatePlayer1 += $v['amount_player_1_banker'] * $times;
|
||||
}
|
||||
if($v['amount_player_1_banker_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_banker']);
|
||||
if($data['result_banker'] == 1){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n1'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n1'];
|
||||
}elseif($data['result_banker'] == 2){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n2'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n2'];
|
||||
}elseif($data['result_banker'] == 3){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n3'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n3'];
|
||||
}elseif($data['result_banker'] == 4){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n4'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n4'];
|
||||
}elseif($data['result_banker'] == 5){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n5'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n5'];
|
||||
}elseif($data['result_banker'] == 6){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n6'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n6'];
|
||||
}elseif($data['result_banker'] == 7){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n7'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n7'];
|
||||
}elseif($data['result_banker'] == 8){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n8'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n8'];
|
||||
}elseif($data['result_banker'] == 9){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_n9'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_n9'];
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_nn'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_nn'];
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_bz'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_bz'];
|
||||
}elseif($data['result_banker'] == 12){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_ths'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_ths'];
|
||||
}elseif($data['result_banker'] == 13){
|
||||
$winTotal += round($v['amount_player_1_banker_times'] * $userInfo['price_tc_hjths'],2);
|
||||
$timesPlayer1 = $userInfo['price_tc_hjths'];
|
||||
}
|
||||
$newAmount += $v['amount_player_1_banker_times'];
|
||||
$rebatePlayer1 += $v['amount_player_1_banker_times'];
|
||||
}
|
||||
|
||||
if($v['amount_player_1'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal -= round($v['amount_player_1'] * $times,2);
|
||||
$winTotalActual -= round($v['amount_player_1'] * $times,2);
|
||||
$rebatePlayer1 -= round($v['amount_player_1'] * $times,2);
|
||||
$rebate += $v['amount_player_1'] * $times;
|
||||
$newAmount += $v['amount_player_1'] * $times;
|
||||
}
|
||||
if($v['amount_player_1_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_banker']);
|
||||
$winTotal -= round($v['amount_player_1_times'] * $times,2);
|
||||
$winTotalActual -= round($v['amount_player_1_times'] * $times,2);
|
||||
$rebatePlayer1 -= round($v['amount_player_1_times'] * $times,2);
|
||||
$rebate += $v['amount_player_1_times'] * $times;
|
||||
$newAmount += $v['amount_player_1_times'] * $times;
|
||||
}
|
||||
}
|
||||
//闲2
|
||||
if($data['win_player_2'] == 1){
|
||||
if($v['amount_player_2'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal += round($v['amount_player_2'] * $userInfo['price_tc_n1'],2);
|
||||
$winTotalActual += round($v['amount_player_2'] * $times,2);
|
||||
$newAmount += $v['amount_player_2'];
|
||||
$rebatePlayer2 -= $v['amount_player_2'];
|
||||
}
|
||||
if($v['amount_player_2_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_player_2']);
|
||||
if($data['result_player_2'] == 1){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n1'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n1'];
|
||||
}elseif($data['result_player_2'] == 2){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n2'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n2'];
|
||||
}elseif($data['result_player_2'] == 3){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n3'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n3'];
|
||||
}elseif($data['result_player_2'] == 4){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n4'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n4'];
|
||||
}elseif($data['result_player_2'] == 5){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n5'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n5'];
|
||||
}elseif($data['result_player_2'] == 6){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n6'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n6'];
|
||||
}elseif($data['result_player_2'] == 7){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n7'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n7'];
|
||||
}elseif($data['result_player_2'] == 8){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n8'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n8'];
|
||||
}elseif($data['result_player_2'] == 9){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_n9'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n9'];
|
||||
}elseif($data['result_player_2'] == 10){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_nn'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_nn'];
|
||||
}elseif($data['result_player_2'] == 11){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_bz'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_bz'];
|
||||
}elseif($data['result_player_2'] == 12){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_ths'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_ths'];
|
||||
}elseif($data['result_player_2'] == 13){
|
||||
$winTotal += round($v['amount_player_2_times'] * $userInfo['price_tc_hjths'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_hjths'];
|
||||
}
|
||||
$winTotalActual += round($v['amount_player_2_times'] * $times,2);
|
||||
$newAmount += $v['amount_player_2_times'];
|
||||
$rebatePlayer2 -= $v['amount_player_2_times'];
|
||||
}
|
||||
|
||||
if($v['amount_player_2_banker'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal -= round($v['amount_player_2_banker'] * $times,2);
|
||||
$rebatePlayer2 += round($v['amount_player_2_banker'] * $times,2);
|
||||
$rebate += $v['amount_player_2_banker'] * $times;
|
||||
$newAmount += $v['amount_player_2_banker'] * $times;
|
||||
}
|
||||
if($v['amount_player_2_banker_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_player_2']);
|
||||
$winTotal -= round($v['amount_player_2_banker_times'] * $times,2);
|
||||
$rebatePlayer2 += round($v['amount_player_2_banker_times'] * $times,2);
|
||||
$rebate += $v['amount_player_2_banker_times'] * $times;
|
||||
$newAmount += $v['amount_player_2_banker_times'] * $times;
|
||||
}
|
||||
|
||||
}elseif($data['win_player_2'] == 0){
|
||||
if($v['amount_player_2_banker'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal += round($v['amount_player_2_banker'] * $userInfo['price_tc_n1'],2);
|
||||
$rebatePlayer2 += $v['amount_player_2_banker'] * $times;
|
||||
$newAmount += $v['amount_player_2_banker'] * $times;
|
||||
}
|
||||
if($v['amount_player_2_banker_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_banker']);
|
||||
if($data['result_banker'] == 1){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n1'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n1'];
|
||||
}elseif($data['result_banker'] == 2){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n2'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n2'];
|
||||
}elseif($data['result_banker'] == 3){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n3'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n3'];
|
||||
}elseif($data['result_banker'] == 4){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n4'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n4'];
|
||||
}elseif($data['result_banker'] == 5){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n5'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n5'];
|
||||
}elseif($data['result_banker'] == 6){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n6'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n6'];
|
||||
}elseif($data['result_banker'] == 7){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n7'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n7'];
|
||||
}elseif($data['result_banker'] == 8){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n8'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n8'];
|
||||
}elseif($data['result_banker'] == 9){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_n9'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_n9'];
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_nn'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_nn'];
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_bz'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_bz'];
|
||||
}elseif($data['result_banker'] == 12){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_ths'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_ths'];
|
||||
}elseif($data['result_banker'] == 13){
|
||||
$winTotal += round($v['amount_player_2_banker_times'] * $userInfo['price_tc_hjths'],2);
|
||||
$timesPlayer2 = $userInfo['price_tc_hjths'];
|
||||
}
|
||||
$rebatePlayer2 += $v['amount_player_2_banker_times'];
|
||||
$newAmount += $v['amount_player_2_banker_times'];
|
||||
}
|
||||
|
||||
if($v['amount_player_2'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal -= round($v['amount_player_2'] * $times,2);
|
||||
$winTotalActual -= round($v['amount_player_2'] * $times,2);
|
||||
$rebatePlayer2 -= round($v['amount_player_2'] * $times,2);
|
||||
$rebate += $v['amount_player_2'] * $times;
|
||||
$newAmount += $v['amount_player_2'] * $times;
|
||||
}
|
||||
if($v['amount_player_2_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_banker']);
|
||||
$winTotal -= round($v['amount_player_2_times'] * $times,2);
|
||||
$winTotalActual -= round($v['amount_player_2_times'] * $times,2);
|
||||
$rebatePlayer2 -= round($v['amount_player_2_times'] * $times,2);
|
||||
$rebate += $v['amount_player_2_times'] * $times;
|
||||
$newAmount += $v['amount_player_2_times'] * $times;
|
||||
}
|
||||
}
|
||||
|
||||
//闲3
|
||||
if($data['win_player_3'] == 1){
|
||||
if($v['amount_player_3'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal += round($v['amount_player_3'] * $userInfo['price_tc_n1'],2);
|
||||
$winTotalActual += round($v['amount_player_3'] * $times,2);
|
||||
$rebatePlayer3 -= $v['amount_player_3'];
|
||||
$newAmount += $v['amount_player_3'];
|
||||
}
|
||||
if($v['amount_player_3_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_player_3']);
|
||||
if($data['result_player_3'] == 1){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n1'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n1'];
|
||||
}elseif($data['result_player_3'] == 2){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n2'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n2'];
|
||||
}elseif($data['result_player_3'] == 3){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n3'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n3'];
|
||||
}elseif($data['result_player_3'] == 4){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n4'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n4'];
|
||||
}elseif($data['result_player_3'] == 5){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n5'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n5'];
|
||||
}elseif($data['result_player_3'] == 6){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n6'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n6'];
|
||||
}elseif($data['result_player_3'] == 7){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n7'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n7'];
|
||||
}elseif($data['result_player_3'] == 8){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n8'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n8'];
|
||||
}elseif($data['result_player_3'] == 9){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_n9'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n9'];
|
||||
}elseif($data['result_player_3'] == 10){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_nn'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_nn'];
|
||||
}elseif($data['result_player_3'] == 11){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_bz'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_bz'];
|
||||
}elseif($data['result_player_3'] == 12){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_ths'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_ths'];
|
||||
}elseif($data['result_player_3'] == 13){
|
||||
$winTotal += round($v['amount_player_3_times'] * $userInfo['price_tc_hjths'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_hjths'];
|
||||
}
|
||||
$winTotalActual += round($v['amount_player_3_times'] * $times,2);
|
||||
$rebatePlayer3 -= $v['amount_player_3_times'];
|
||||
$newAmount += $v['amount_player_3_times'];
|
||||
}
|
||||
|
||||
if($v['amount_player_3_banker'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal -= round($v['amount_player_3_banker'] * $times,2);
|
||||
$rebatePlayer2 += round($v['amount_player_3_banker'] * $times,2);
|
||||
$rebate += $v['amount_player_3_banker'] * $times;
|
||||
$newAmount += $v['amount_player_3_banker'] * $times;
|
||||
}
|
||||
if($v['amount_player_3_banker_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_player_3']);
|
||||
$winTotal -= round($v['amount_player_3_banker_times'] * $times,2);
|
||||
$rebatePlayer1 += round($v['amount_player_3_banker_times'] * $times,2);
|
||||
$rebate += $v['amount_player_3_banker_times'] * $times;
|
||||
$newAmount += $v['amount_player_3_banker_times'] * $times;
|
||||
}
|
||||
|
||||
}elseif($data['win_player_3'] == 0){
|
||||
if($v['amount_player_3_banker'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal += round($v['amount_player_3_banker'] * $userInfo['price_tc_n1'],2);
|
||||
$rebatePlayer3 += $v['amount_player_3_banker'] * $times;
|
||||
$newAmount += $v['amount_player_3_banker'] * $times;
|
||||
}
|
||||
if($v['amount_player_3_banker_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_banker']);
|
||||
if($data['result_banker'] == 1){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n1'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n1'];
|
||||
}elseif($data['result_banker'] == 2){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n2'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n2'];
|
||||
}elseif($data['result_banker'] == 3){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n3'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n3'];
|
||||
}elseif($data['result_banker'] == 4){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n4'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n4'];
|
||||
}elseif($data['result_banker'] == 5){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n5'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n5'];
|
||||
}elseif($data['result_banker'] == 6){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n6'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n6'];
|
||||
}elseif($data['result_banker'] == 7){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n7'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n7'];
|
||||
}elseif($data['result_banker'] == 8){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n8'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n8'];
|
||||
}elseif($data['result_banker'] == 9){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_n9'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_n9'];
|
||||
}elseif($data['result_banker'] == 10){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_nn'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_nn'];
|
||||
}elseif($data['result_banker'] == 11){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_bz'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_bz'];
|
||||
}elseif($data['result_banker'] == 12){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_ths'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_ths'];
|
||||
}elseif($data['result_banker'] == 13){
|
||||
$winTotal += round($v['amount_player_3_banker_times'] * $userInfo['price_tc_hjths'],2);
|
||||
$timesPlayer3 = $userInfo['price_tc_hjths'];
|
||||
}
|
||||
$rebatePlayer3 += $v['amount_player_3_banker_times'];
|
||||
$newAmount += $v['amount_player_3_banker_times'];
|
||||
}
|
||||
|
||||
if($v['amount_player_3'] > 0){
|
||||
$times = CardPositionTc::getTimes(1);
|
||||
$winTotal -= round($v['amount_player_3'] * $times,2);
|
||||
$winTotalActual -= round($v['amount_player_3'] * $times,2);
|
||||
$rebatePlayer3 -= round($v['amount_player_3'] * $times,2);
|
||||
$rebate += $v['amount_player_3'] * $times;
|
||||
$newAmount += $v['amount_player_3'] * $times;
|
||||
}
|
||||
if($v['amount_player_3_times'] > 0){
|
||||
$times = CardPositionTc::getTimes($data['result_banker']);
|
||||
$winTotal -= round($v['amount_player_3_times'] * $times,2);
|
||||
$winTotalActual -= round($v['amount_player_3_times'] * $times,2);
|
||||
$rebatePlayer3 -= round($v['amount_player_3_times'] * $times,2);
|
||||
$rebate += $v['amount_player_3_times'] * $times;
|
||||
$newAmount += $v['amount_player_3_times'] * $times;
|
||||
}
|
||||
}
|
||||
|
||||
// 双边洗码
|
||||
if($userInfo['type_xima'] == 1){
|
||||
$rebate = abs($rebatePlayer1) + abs($rebatePlayer2) + abs($rebatePlayer3);
|
||||
}
|
||||
|
||||
//计算庄家输赢
|
||||
if($numberTabInfo['rob_banker_username']){
|
||||
if($userInfo['is_sw'] == 0){
|
||||
$bankerWinTotal = $winTotalActual + $bankerWinTotal;
|
||||
}
|
||||
}
|
||||
$v['position_first'] = $numberTabInfo['position_first'];
|
||||
$betInfoItem = array_merge($v,$data);
|
||||
$betInfoItem['times_player_1'] = $timesPlayer1;
|
||||
$betInfoItem['times_player_2'] = $timesPlayer2;
|
||||
$betInfoItem['times_player_3'] = $timesPlayer3;
|
||||
$res = Bet::openingBet($tableInfo,$betInfoItem,$userInfo,$numberTabInfo,$amount,$winTotal,$rebate,$withholdAmount);
|
||||
if ($res['status']){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $v['user_id']);
|
||||
if ($userSession && is_array($userSession)){
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening',[
|
||||
'status' => true,
|
||||
'table_id' => $tableInfo['id'],
|
||||
'round' => [
|
||||
'money' => $res['money'],
|
||||
'win_total' => $winTotal,
|
||||
'previous_number_tab_id' => $v['number_tab_id']
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算抢庄
|
||||
*/
|
||||
if($numberTabInfo['rob_banker_id'] > 0){
|
||||
$userInfo = User::get(intval($numberTabInfo['rob_banker_id']));
|
||||
//更新user表余额
|
||||
$winTotal = to_number($bankerWinTotal);
|
||||
if($winTotal > 0){
|
||||
$winTotal = $winTotal * 0.94;
|
||||
}
|
||||
$amount = 0;
|
||||
$rebate = abs($bankerWinTotal);
|
||||
$bankerBetInfo = array_merge($bankerBetInfo,$data);
|
||||
$res = Bet::openingBet($tableInfo,$bankerBetInfo,$userInfo,$numberTabInfo,$amount,$winTotal,$rebate);
|
||||
if ($res['status']){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $userInfo['id']);
|
||||
if ($userSession && is_array($userSession)) {
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening', [
|
||||
'status' => true,
|
||||
'table_id' => $tableInfo['id'],
|
||||
'round' => [
|
||||
'money' => $res['money'],
|
||||
'previous_number_tab_id' => $bankerBetInfo['number_tab_id']
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\opening;
|
||||
|
||||
use app\models\bet\Bet;
|
||||
use app\models\process\Boot;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\user\User;
|
||||
use app\services\connect\InitTableService;
|
||||
use freedom\utils\SocketSession;
|
||||
use freedom\utils\ToningUtil;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果服务
|
||||
* Class OpeningToningService
|
||||
* @package app\services\opening
|
||||
*/
|
||||
class OpeningToningService
|
||||
{
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function openingToning(array $event, array $tableInfo, Websocket $ws){
|
||||
//判断结果并推送结果
|
||||
$res = self::doOpening($event,$tableInfo);
|
||||
if ($res['status'] == false){
|
||||
$ws->emit('openingToning',['status' => false, 'msg' => $res['msg']]);
|
||||
return;
|
||||
}
|
||||
list($result,$lastNumberTabInfo,$newNumberTabInfo) = $res['data'];
|
||||
$round = array(
|
||||
'result' => $result,
|
||||
'boot_id' => $newNumberTabInfo['boot_id'],
|
||||
'boot_num' => $newNumberTabInfo['boot_num'],
|
||||
'number_tab_id' => $newNumberTabInfo['id'],
|
||||
'previous_number_tab_id' => $lastNumberTabInfo['id'],
|
||||
'number_tab_number' => $newNumberTabInfo['number'],
|
||||
'number_tab_status' => InitTableService::numberTabStatus($newNumberTabInfo)
|
||||
);
|
||||
$ws->emit('openingToning',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('openingToningResult',['status' => true, 'table_id' => $tableInfo['id'], 'round' => $round]);
|
||||
//处理注单
|
||||
self::doBet($ws,$tableInfo,$lastNumberTabInfo);
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO 判断结果
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doOpening(array $event, array $tableInfo): array
|
||||
{
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
$numberTabId = intval($event['number_tab_id']);
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo || $numberTabId != $numberTabInfo['id']) return ['status' => false, 'msg' => 'opening_fail_2'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'opening_fail_4'];
|
||||
$result = intval($event['result']);
|
||||
if (!in_array($result,[0,1,2,3,4])) return ['status' => false, 'msg' => 'opening_fail_3'];
|
||||
// 统计结果数目
|
||||
$boot = Boot::where(['id' => $numberTabInfo['boot_id']])->find();
|
||||
$toningCountArray = ToningUtil::countInc($result, $boot['toning_count']);
|
||||
$toningCountString = array_to_string($toningCountArray);
|
||||
$numberTabInfo['toning_count'] = $toningCountString;
|
||||
$numberTabUpdate = ['toning_result' => $result, 'end_time' => time(), 'bet_status' => 3];
|
||||
$newNumberTabInfo = NumberTab::next($numberTabInfo,$numberTabUpdate,$tableInfo);
|
||||
if ($newNumberTabInfo){
|
||||
$lastNumberTabInfo = array_merge($numberTabInfo,$numberTabUpdate);
|
||||
return ['status' => true, 'data' => [$result,$lastNumberTabInfo,$newNumberTabInfo]];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'opening_fail'];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Bet处理
|
||||
* @param Websocket $ws 桌子信息
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $numberTabInfo 开结果的当前局信息
|
||||
* @return void
|
||||
*/
|
||||
public static function doBet(Websocket $ws, array $tableInfo, array $numberTabInfo){
|
||||
$betArray = Bet::getByNumberTabIdValid($numberTabInfo['id']);
|
||||
foreach ($betArray AS $v){
|
||||
$userInfo = User::get(intval($v['user_id']));
|
||||
if (!$userInfo){
|
||||
continue;
|
||||
}
|
||||
if (empty($v['toning_amount'])){
|
||||
continue;
|
||||
}
|
||||
$toningAmountArray = explode(",", $v['toning_amount']);
|
||||
$amount = 0;
|
||||
$winMoney = 0;
|
||||
foreach ($toningAmountArray as $value){
|
||||
$itemArray = explode(":", $value);
|
||||
$area = $itemArray[0];
|
||||
$betAmount = intval($itemArray[1]);
|
||||
$amount += $itemArray[1];
|
||||
if (($area == 'toning_zero' && $numberTabInfo['toning_result'] == 0) || ($area == 'toning_four' && $numberTabInfo['toning_result'] == 4)){
|
||||
$winMoney = round($betAmount * (1 + $userInfo['price_toning_0']),2) + $winMoney;
|
||||
}
|
||||
if (($area == 'toning_one' && $numberTabInfo['toning_result'] == 1) || ($area == 'toning_three' && $numberTabInfo['toning_result'] == 3)){
|
||||
$winMoney = round($betAmount * (1 + $userInfo['price_toning_1']),2) + $winMoney;
|
||||
}
|
||||
if ($area == 'toning_big' && in_array($numberTabInfo['toning_result'], [3,4])){
|
||||
$winMoney = round($betAmount * (1 + $userInfo['price_toning']),2) + $winMoney;
|
||||
}
|
||||
if ($area == 'toning_small' && in_array($numberTabInfo['toning_result'], [0,1])){
|
||||
$winMoney = round($betAmount * (1 + $userInfo['price_toning']),2) + $winMoney;
|
||||
}
|
||||
if ($area == 'toning_singular' && in_array($numberTabInfo['toning_result'], [1,3])){
|
||||
$winMoney = round($betAmount * (1 + $userInfo['price_toning']),2) + $winMoney;
|
||||
}
|
||||
if ($area == 'toning_plural' && in_array($numberTabInfo['toning_result'], [0,2,4])){
|
||||
$winMoney = round($betAmount * (1 + $userInfo['price_toning']),2) + $winMoney;
|
||||
}
|
||||
if (($area == 'toning_small' && $numberTabInfo['toning_result'] == 2) || ($area == 'toning_big' && $numberTabInfo['toning_result'] == 2)){
|
||||
$winMoney = round($betAmount + $winMoney,2);
|
||||
}
|
||||
}
|
||||
$winTotal = $winMoney - $amount;
|
||||
/**
|
||||
* Model处理
|
||||
* @param array $tableInfo 桌子信息
|
||||
* @param array $betInfo bet信息
|
||||
* @param array $userInfo bet用户信息
|
||||
* @param array $numberTabInfo 局信息
|
||||
* @param float $amount 下注总数
|
||||
* @param float $winTotal 赢金额
|
||||
* @param float $ximaliang 洗码量
|
||||
*/
|
||||
$res = Bet::openingBet($tableInfo,$v,$userInfo,$numberTabInfo,$amount,$winTotal,0);
|
||||
if ($res['status'] == true){
|
||||
$tableUser = app('swoole.table.user');
|
||||
$userSession = $tableUser->get((string) $v['user_id']);
|
||||
if ($userSession && is_array($userSession)) {
|
||||
$ws->setSender(0)->to($userSession['fd'])->emit('opening',['status' => true, 'table_id' => $tableInfo['id'], 'round' => ['money' => $res['money'], 'win_total' => $winTotal, 'previous_number_tab_id' => $v['number_tab_id']]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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']]);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\reset;
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果服务
|
||||
* Class ResetBaccaratService
|
||||
* @package app\services\opening
|
||||
*/
|
||||
class ResetBaccaratService
|
||||
{
|
||||
/**
|
||||
* TODO Baccarat修改上一铺结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function resetBaccarat(array $event, array $tableInfo, Websocket $ws){
|
||||
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc_two($tableInfo);
|
||||
if (!$numberTabInfo){
|
||||
$ws->emit('resetBaccarat', ['status' => false, 'msg' => 'not_number_tab_data']);
|
||||
return;
|
||||
}
|
||||
if(count($numberTabInfo) != 2){
|
||||
$ws->emit('resetBaccarat', ['status' => false, 'msg' => '上一铺数据不存在']);
|
||||
return;
|
||||
}
|
||||
if($numberTabInfo[0]['boot_id'] != $numberTabInfo[1]['boot_id']){
|
||||
$ws->emit('resetBaccarat', ['status' => false, 'msg' => '上一铺不在同一靴']);
|
||||
return;
|
||||
}
|
||||
|
||||
$numberTabInfo = $numberTabInfo[1];
|
||||
if($event['opening'] == $numberTabInfo['result'] && $event['pair'] == $numberTabInfo['pair'] && $event['luck_six'] == $numberTabInfo['luck_six']){
|
||||
$ws->emit('resetBaccarat', ['status' => false, 'msg' => '结果一样']);
|
||||
return;
|
||||
}
|
||||
$res = NumberTab::resetBaccarat($event,$numberTabInfo,$tableInfo);
|
||||
if (!$res){
|
||||
$ws->emit('resetBaccarat', ['status' => false, 'msg' => '修改上一局结果失败']);
|
||||
return;
|
||||
}
|
||||
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('resetBaccarat',[
|
||||
'status' => true,
|
||||
'table_id' => $tableInfo['id'],
|
||||
'round' => [
|
||||
'previous_number_tab_id' => $numberTabInfo['id']
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\reset;
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use freedom\utils\SocketSession;
|
||||
use think\swoole\Websocket;
|
||||
|
||||
/**
|
||||
* TODO Baccarat开结果服务
|
||||
* Class ResetDtService
|
||||
* @package app\services\opening
|
||||
*/
|
||||
class ResetDtService
|
||||
{
|
||||
/**
|
||||
* TODO Dt修改上一铺结果处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @param Websocket $ws
|
||||
* @return void
|
||||
*/
|
||||
public static function resetDt(array $event, array $tableInfo, Websocket $ws){
|
||||
|
||||
$ws = app('\think\swoole\WebSocket');
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc_two($tableInfo);
|
||||
if (!$numberTabInfo){
|
||||
$ws->emit('resetDt', ['status' => false, 'msg' => 'not_number_tab_data']);
|
||||
return;
|
||||
}
|
||||
if(count($numberTabInfo) != 2){
|
||||
$ws->emit('resetDt', ['status' => false, 'msg' => '上一铺数据不存在']);
|
||||
return;
|
||||
}
|
||||
if($numberTabInfo[0]['boot_id'] != $numberTabInfo[1]['boot_id']){
|
||||
$ws->emit('resetDt', ['status' => false, 'msg' => '上一铺不在同一靴']);
|
||||
return;
|
||||
}
|
||||
|
||||
$numberTabInfo = $numberTabInfo[1];
|
||||
if($event['opening'] == $numberTabInfo['result']){
|
||||
$ws->emit('resetDt', ['status' => false, 'msg' => '结果一样']);
|
||||
return;
|
||||
}
|
||||
$res = NumberTab::resetDt($event,$numberTabInfo,$tableInfo);
|
||||
if (!$res){
|
||||
$ws->emit('resetDt', ['status' => false, 'msg' => '修改上一局结果失败']);
|
||||
return;
|
||||
}
|
||||
|
||||
$ws->to(SocketSession::HOUSE_NAME)->emit('resetDt',[
|
||||
'status' => true,
|
||||
'table_id' => $tableInfo['id'],
|
||||
'round' => [
|
||||
'previous_number_tab_id' => $numberTabInfo['id']
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,277 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\scan;
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\CardPositionNn;
|
||||
use freedom\utils\RedisUtil;
|
||||
|
||||
/**
|
||||
* TODO NN扫描
|
||||
* Class ScanNnService
|
||||
* @package app\services\scan
|
||||
*/
|
||||
class ChangeNnService
|
||||
{
|
||||
/**
|
||||
* TODO NN扫描处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doScanNnChange(array $event, array $tableInfo): array
|
||||
{
|
||||
$checkScanRes = ScanCommonService::checkScan($event,$tableInfo);
|
||||
if ($checkScanRes['status'] == false){
|
||||
return $checkScanRes;
|
||||
}else{
|
||||
$numberTabInfo = $checkScanRes['numberTabInfo'];
|
||||
$cardInfo = $checkScanRes['cardInfo'];
|
||||
}
|
||||
// 判断牌是否符合规格
|
||||
if (!isset($event['card']) || empty(intval($event['card']))) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$card = intval($event['card']);
|
||||
$round = [
|
||||
'card' => $card,
|
||||
'number' => CardPosition::interchangeCard($card),
|
||||
'boot_id' => intval($numberTabInfo['boot_id']),
|
||||
'boot_num' => intval($numberTabInfo['boot_num']),
|
||||
'number_tab_id' => intval($numberTabInfo['id']),
|
||||
'number_tab_number' => intval($numberTabInfo['number'])
|
||||
];
|
||||
if (!$cardInfo){
|
||||
// 没有牌数据,创建并保存
|
||||
$cardInfo = ['card_first' => $card];
|
||||
$cardInfo['player_1_card_1'] = 0;
|
||||
$cardInfo['player_1_card_2'] = 0;
|
||||
$cardInfo['player_1_card_3'] = 0;
|
||||
$cardInfo['player_1_card_4'] = 0;
|
||||
$cardInfo['player_1_card_5'] = 0;
|
||||
$cardInfo['player_2_card_1'] = 0;
|
||||
$cardInfo['player_2_card_2'] = 0;
|
||||
$cardInfo['player_2_card_3'] = 0;
|
||||
$cardInfo['player_2_card_4'] = 0;
|
||||
$cardInfo['player_2_card_5'] = 0;
|
||||
$cardInfo['player_3_card_1'] = 0;
|
||||
$cardInfo['player_3_card_2'] = 0;
|
||||
$cardInfo['player_3_card_3'] = 0;
|
||||
$cardInfo['player_3_card_4'] = 0;
|
||||
$cardInfo['player_3_card_5'] = 0;
|
||||
$cardInfo['banker_card_1'] = 0;
|
||||
$cardInfo['banker_card_2'] = 0;
|
||||
$cardInfo['banker_card_3'] = 0;
|
||||
$cardInfo['banker_card_4'] = 0;
|
||||
$cardInfo['banker_card_5'] = 0;
|
||||
$positionFirst = CardPositionNn::nnPosition($card);
|
||||
$cardInfo['position_first'] = $positionFirst;
|
||||
NumberTab::where(['id' => $numberTabInfo['id']])->update(['position_first' => $positionFirst]);
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = 0;
|
||||
$round['order_num'] = 0;
|
||||
$round['result'] = '';
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
// 判断是否已经存在过相同牌
|
||||
$beforeCard = $cardInfo;
|
||||
//unset($beforeCard['card_first']);
|
||||
unset($beforeCard['position_first']);
|
||||
if(in_array($card,$beforeCard)) return ['status' => false, 'msg' => 'Card Exists'];
|
||||
$cardCountValues = array_count_values($beforeCard);
|
||||
// 获取当前定位
|
||||
if (isset($cardCountValues[0])){
|
||||
$positionNum = 20 - intval($cardCountValues[0]) + 1;
|
||||
} else {
|
||||
$positionNum = 20;
|
||||
}
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player1Card[3] = $cardInfo['player_1_card_4'];
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player2Card[3] = $cardInfo['player_2_card_4'];
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$player3Card[3] = $cardInfo['player_3_card_4'];
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$bankerCard[3] = $cardInfo['banker_card_4'];
|
||||
$resultWord = '';
|
||||
|
||||
$order = CardPositionNn::nnOrder($cardInfo['position_first']);
|
||||
$orderPosition = $positionNum - 1;
|
||||
$position = $order[$orderPosition];
|
||||
$orderNumArr = CardPositionNn::nnOrderNum($cardInfo['position_first']);
|
||||
$orderNum = $orderNumArr[$orderPosition];
|
||||
$cardInfo[$position] = $card;
|
||||
if($positionNum >= 17 && $positionNum <= 20){
|
||||
if($orderNum > 10 && $orderNum < 20){
|
||||
$player1Card[4] = $card;
|
||||
$player1Result = CardPositionNn::JudgeCowCow($player1Card);
|
||||
$resultWord = $player1Result['word'];
|
||||
}
|
||||
if($orderNum > 20 && $orderNum < 30){
|
||||
$player2Card[4] = $card;
|
||||
$player2Result = CardPositionNn::JudgeCowCow($player2Card);
|
||||
$resultWord = $player2Result['word'];
|
||||
}
|
||||
if($orderNum > 30 && $orderNum < 40){
|
||||
$player3Card[4] = $card;
|
||||
$player3Result = CardPositionNn::JudgeCowCow($player3Card);
|
||||
$resultWord = $player3Result['word'];
|
||||
}
|
||||
if($orderNum > 40){
|
||||
$bankerCard[4] = $card;
|
||||
$bankerResult = CardPositionNn::JudgeCowCow($bankerCard);
|
||||
$resultWord = $bankerResult['word'];
|
||||
}
|
||||
}
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = $positionNum;
|
||||
$round['order_num'] = $orderNum;
|
||||
$round['result'] = $resultWord;
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO NN识别处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doScanNnSbChange(array $event, array $tableInfo): array
|
||||
{
|
||||
$checkScanRes = ScanCommonService::checkScan($event,$tableInfo);
|
||||
if ($checkScanRes['status'] == false){
|
||||
return $checkScanRes;
|
||||
}else{
|
||||
$numberTabInfo = $checkScanRes['numberTabInfo'];
|
||||
$cardInfo = $checkScanRes['cardInfo'];
|
||||
}
|
||||
// 判断牌是否符合规格
|
||||
if (!isset($event['card']) || empty(intval($event['card']))) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$card = intval($event['card']);
|
||||
$round = [
|
||||
'card' => $card,
|
||||
'number' => CardPosition::interchangeCard($card),
|
||||
'boot_id' => intval($numberTabInfo['boot_id']),
|
||||
'boot_num' => intval($numberTabInfo['boot_num']),
|
||||
'number_tab_id' => intval($numberTabInfo['id']),
|
||||
'number_tab_number' => intval($numberTabInfo['number'])
|
||||
];
|
||||
|
||||
// 判断是否已经存在过相同牌
|
||||
$beforeCard = $cardInfo;
|
||||
//unset($beforeCard['card_first']);
|
||||
unset($beforeCard['position_first']);
|
||||
if(in_array($card,$beforeCard)) return ['status' => false, 'msg' => 'Card Exists'];
|
||||
$cardCountValues = array_count_values($beforeCard);
|
||||
// 获取当前定位
|
||||
|
||||
$positionNum = $event['position_num'];
|
||||
$orderNum = 0;
|
||||
$resultWord = '';
|
||||
/*
|
||||
if (isset($cardCountValues[0])){
|
||||
$positionNum = 20 - intval($cardCountValues[0]) + 1;
|
||||
} else {
|
||||
$positionNum = 20;
|
||||
}
|
||||
*/
|
||||
if ($positionNum > 0) {
|
||||
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player1Card[3] = $cardInfo['player_1_card_4'];
|
||||
$player1Card[4] = $cardInfo['player_1_card_5'];
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player2Card[3] = $cardInfo['player_2_card_4'];
|
||||
$player2Card[4] = $cardInfo['player_2_card_5'];
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$player3Card[3] = $cardInfo['player_3_card_4'];
|
||||
$player3Card[4] = $cardInfo['player_3_card_5'];
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$bankerCard[3] = $cardInfo['banker_card_4'];
|
||||
$bankerCard[4] = $cardInfo['banker_card_5'];
|
||||
|
||||
$order = CardPositionNn::nnOrderSb($cardInfo['position_first']);
|
||||
$orderPosition = $positionNum - 1;
|
||||
$position = $order[$orderPosition];
|
||||
$orderNumArr = CardPositionNn::nnOrderNumSb($cardInfo['position_first']);
|
||||
$orderNum = $orderNumArr[$orderPosition];
|
||||
$cardInfo[$position] = $card;
|
||||
|
||||
$indexOfCardToBeChanged = $positionNum % 5 - 1;
|
||||
if ($indexOfCardToBeChanged == -1) $indexOfCardToBeChanged = 4;
|
||||
|
||||
if($orderNum > 10 && $orderNum < 20){
|
||||
$player1Card[$indexOfCardToBeChanged] = $card;
|
||||
$player1Result = CardPositionNn::JudgeCowCow($player1Card);
|
||||
$resultWord = $player1Result['word'];
|
||||
}
|
||||
if($orderNum > 20 && $orderNum < 30){
|
||||
$player2Card[$indexOfCardToBeChanged] = $card;
|
||||
$player2Result = CardPositionNn::JudgeCowCow($player2Card);
|
||||
$resultWord = $player2Result['word'];
|
||||
}
|
||||
if($orderNum > 30 && $orderNum < 40){
|
||||
$player3Card[$indexOfCardToBeChanged] = $card;
|
||||
$player3Result = CardPositionNn::JudgeCowCow($player3Card);
|
||||
$resultWord = $player3Result['word'];
|
||||
}
|
||||
if($orderNum > 40){
|
||||
$bankerCard[$indexOfCardToBeChanged] = $card;
|
||||
$bankerResult = CardPositionNn::JudgeCowCow($bankerCard);
|
||||
$resultWord = $bankerResult['word'];
|
||||
}
|
||||
|
||||
} else {
|
||||
$positionFirst = CardPositionNn::nnPosition($card);
|
||||
$cardInfo['card_first'] = $card;
|
||||
$cardInfo['position_first'] = $positionFirst;
|
||||
}
|
||||
|
||||
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = $positionNum;
|
||||
$round['order_num'] = $orderNum;
|
||||
$round['result'] = $resultWord;
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\scan;
|
||||
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\RedisUtil;
|
||||
|
||||
/**
|
||||
* TODO Baccarat扫描
|
||||
* Class ScanBaccaratService
|
||||
* @package app\services\scan
|
||||
*/
|
||||
class ScanBaccaratService
|
||||
{
|
||||
/**
|
||||
* TODO Baccarat扫描处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doScanBaccarat(array $event, array $tableInfo): array{
|
||||
$checkScanRes = ScanCommonService::checkScan($event,$tableInfo);
|
||||
if ($checkScanRes['status'] == false){
|
||||
return $checkScanRes;
|
||||
}else{
|
||||
$numberTabInfo = $checkScanRes['numberTabInfo'];
|
||||
$cardInfo = $checkScanRes['cardInfo'];
|
||||
}
|
||||
if (!isset($event['card']) || !isset($event['position'])) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$card = CardPosition::interchangeCard($event['card']);
|
||||
if (!$card) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$position = CardPosition::interchangePosition($event['position']);
|
||||
if (!$position) return ['status' => false, 'msg' => 'Position Error'];
|
||||
if (isset($cardInfo[$position]) && $cardInfo[$position] > 0 && $cardInfo[$position] != $event['card']) {
|
||||
if (!(isset($event['change']) && $event['change'] == 1)) {
|
||||
return ['status' => false, 'msg' => 'Already Exists'];
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//判断接受牌的先后顺序
|
||||
if($event['position'] == 11 || $event['position'] == 12 || $event['position'] == 21 || $event['position'] == 22){
|
||||
$returnPosition = intval($event['position']);
|
||||
$cardInfo[$position] = intval($event['card']);
|
||||
$res = RedisUtil::saveCardPosition($numberTabInfo['id'],$returnPosition,intval($event['card']));
|
||||
if (!$res) return ['status' => false, 'msg' => 'Redis Cache Save Error'];
|
||||
}else if($event['position'] == 13){
|
||||
$change = (isset($event['change']) && $event['change'] == 1)? 1 : 0;
|
||||
$returnData = self::baccaratReplenish($cardInfo,$event['position'], $change);
|
||||
if($returnData['status'] == true){
|
||||
if($returnData['position'] == 'banker_3'){
|
||||
$returnPosition = 23;
|
||||
}else{
|
||||
$returnPosition = 13;
|
||||
}
|
||||
$cardInfo[$returnData['position']] = intval($event['card']);
|
||||
$res = RedisUtil::saveCardPosition($numberTabInfo['id'],$returnPosition,intval($event['card']));
|
||||
if (!$res) return ['status' => false, 'msg' => 'Redis Cache Save Error'];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => $returnData['msg']];
|
||||
}
|
||||
}else if($event['position'] == 23){
|
||||
$returnPosition = 23;
|
||||
if(isset($cardInfo['player_3']) && $cardInfo['player_3'] > 0){
|
||||
$change = (isset($event['change']) && $event['change'] == 1)? 1 : 0;
|
||||
$returnData = self::baccaratReplenish($cardInfo,$event['position'], $change);
|
||||
if($returnData['status'] == true){
|
||||
$cardInfo[$returnData['position']] = intval($event['card']);
|
||||
$res = RedisUtil::saveCardPosition($numberTabInfo['id'],$returnPosition,intval($event['card']));
|
||||
if (!$res) return ['status' => false, 'msg' => 'Redis Cache Save Error'];
|
||||
}else{
|
||||
return ['status' => false, 'msg' => $returnData['msg']];
|
||||
}
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'player3_is_not_cannot_scan_banker3'];
|
||||
}
|
||||
}else{
|
||||
return ['status' => false, 'msg' => 'position_error'];
|
||||
}
|
||||
$round = array(
|
||||
'tid' => intval($tableInfo['id']),
|
||||
'number_tab_id' => $numberTabInfo['id'],
|
||||
'card' => intval($event['card']),
|
||||
'number' => intval($card),
|
||||
'position' => $returnPosition,
|
||||
'boot_id' => intval($numberTabInfo['boot_id']),
|
||||
'boot_num' => intval($numberTabInfo['boot_num']),
|
||||
'number_tab_number' => intval($numberTabInfo['number']),
|
||||
'card_info' => $cardInfo
|
||||
);
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'data' => $round];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO Baccarat开牌条件计算方法
|
||||
* @param array $cardInfo
|
||||
* @param int $position
|
||||
* @return array
|
||||
*/
|
||||
public static function baccaratReplenish(array $cardInfo, int $position, int $change = 0): array
|
||||
{
|
||||
if (!isset($cardInfo['banker_1']) || !isset($cardInfo['banker_2']) || !isset($cardInfo['player_1']) || !isset($cardInfo['player_2'])){
|
||||
return array('status' => false, 'msg' => 'player_banker_not_full');
|
||||
}
|
||||
if($cardInfo['banker_1'] > 0 && $cardInfo['banker_2'] > 0 && $cardInfo['player_1'] > 0 && $cardInfo['player_2'] > 0){
|
||||
$player_count = (CardPosition::interchangeNumber(CardPosition::interchangeCard($cardInfo['player_1'])) + CardPosition::interchangeNumber(CardPosition::interchangeCard($cardInfo['player_2']))) % 10;
|
||||
$banker_count = (CardPosition::interchangeNumber(CardPosition::interchangeCard($cardInfo['banker_1'])) + CardPosition::interchangeNumber(CardPosition::interchangeCard($cardInfo['banker_2']))) % 10;
|
||||
if($position == 13){
|
||||
if(isset($cardInfo['player_3']) && $cardInfo['player_3'] > 0 && $change != 1){
|
||||
//第1张增牌已经存在,不允许更改
|
||||
return array('status' => false, 'msg' => 'fail_already_exists');
|
||||
}
|
||||
if($player_count == 8 || $player_count == 9){
|
||||
//闲家8,9点,不允许增牌
|
||||
return array('status' => false, 'msg' => 'fail_player_8_9');
|
||||
}
|
||||
if($banker_count == 8 || $banker_count == 9){
|
||||
//庄家8,9点,不允许增牌
|
||||
return array('status' => false, 'msg' => 'fail_banker_8_9');
|
||||
}
|
||||
if($player_count == 6 || $player_count == 7){
|
||||
return self::baccaratReplenish($cardInfo,23);
|
||||
}
|
||||
return array('status' => true, 'position' => 'player_3', 'msg' => 'Success');
|
||||
}else if($position == 23){
|
||||
if(isset($cardInfo['banker_3']) && $cardInfo['banker_3'] > 0 && $change != 1){
|
||||
//第2张增牌已经存在,不允许更改
|
||||
return array('status' => false, 'msg' => 'fail_already_exists');
|
||||
}
|
||||
if($player_count == 8 || $player_count == 9){
|
||||
//闲家8,9点,不允许增牌
|
||||
return array('status' => false, 'msg' => 'fail_player_8_9');
|
||||
}
|
||||
if($banker_count == 8 || $banker_count == 9){
|
||||
//庄家8,9点,不允许增牌
|
||||
return array('status' => false, 'msg' => 'fail_banker_8_9');
|
||||
}
|
||||
if(isset($cardInfo['player_3']) && $cardInfo['player_3'] > 0){
|
||||
//闲已经补牌
|
||||
$player_3_count = (CardPosition::interchangeNumber(CardPosition::interchangeCard($cardInfo['player_3']))) % 10;
|
||||
if($banker_count < 3 || ($banker_count == 3 && in_array($player_3_count,array(1,2,3,4,5,6,7,9,0))) || ($banker_count == 4 && in_array($player_3_count,array(2,3,4,5,6,7))) || ($banker_count == 5 && in_array($player_3_count,array(4,5,6,7))) || ($banker_count == 6 && in_array($player_3_count,array(6,7)))){
|
||||
return array('status' => true, 'position' => 'banker_3', 'msg' => 'Success');
|
||||
}else{
|
||||
//庄家不符合补牌条件,不接受补牌数据
|
||||
return array('status' => false, 'msg' => 'banker_lby_lfx');
|
||||
}
|
||||
}else{
|
||||
//闲不需要补牌
|
||||
if($banker_count < 6){
|
||||
return array('status' => true, 'position' => 'banker_3', 'msg' => 'Success');
|
||||
}else{
|
||||
//闲家不补牌,庄家点数>=6点,不接受补牌数据
|
||||
return array('status' => false, 'msg' => 'player3_is_not_banker_num_egt_6');
|
||||
}
|
||||
}
|
||||
}else{
|
||||
//定位错误
|
||||
return array('status' => false, 'msg' => 'position_error');
|
||||
}
|
||||
}else{
|
||||
//前面牌数据未全,不接受补牌数据
|
||||
return array('status' => false, 'msg' => 'player_banker_not_full');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\scan;
|
||||
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use freedom\utils\RedisUtil;
|
||||
|
||||
/**
|
||||
* TODO 扫描登录公共处理类
|
||||
* Class ScanDtService
|
||||
* @package app\services\scan
|
||||
*/
|
||||
class ScanCommonService
|
||||
{
|
||||
/**
|
||||
* TODO 扫描公共验证方法
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function checkScan(array $event, array $tableInfo): array
|
||||
{
|
||||
if ($tableInfo['is_scavenging'] != 1) return ['status' => false, 'msg' => 'This Table Is Not Scan'];
|
||||
if (!isset($event['number_tab_id'])) return ['status' => false, 'msg' => 'Not NumberTabId'];
|
||||
$numberTabInfo = NumberTab::getByTableIdOrderByIdDesc($tableInfo);
|
||||
if (!$numberTabInfo) return ['status' => false, 'msg' => 'NumberTabId Error'];
|
||||
if ($numberTabInfo['bet_status'] != 2) return ['status' => false, 'msg' => 'BetStatus No 2'];
|
||||
//判断redis是否存在Card数据,如果不存在则创建
|
||||
if ($tableInfo['game_id'] == 1 || $tableInfo['game_id'] == 2){
|
||||
$cardInfo = RedisUtil::getCardPosition($numberTabInfo['id']);
|
||||
} else {
|
||||
$cardInfo = RedisUtil::getCard($numberTabInfo['id']);
|
||||
}
|
||||
return ['status' => true, 'numberTabInfo' => $numberTabInfo, 'cardInfo' => $cardInfo];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\scan;
|
||||
|
||||
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\RedisUtil;
|
||||
|
||||
/**
|
||||
* TODO Dt扫描
|
||||
* Class ScanDtService
|
||||
* @package app\services\scan
|
||||
*/
|
||||
class ScanDtService
|
||||
{
|
||||
/**
|
||||
* TODO Dt扫描处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doScanDt(array $event, array $tableInfo): array{
|
||||
$checkScanRes = ScanCommonService::checkScan($event,$tableInfo);
|
||||
if ($checkScanRes['status'] == false){
|
||||
return $checkScanRes;
|
||||
}else{
|
||||
$numberTabInfo = $checkScanRes['numberTabInfo'];
|
||||
$cardInfo = $checkScanRes['cardInfo'];
|
||||
}
|
||||
if (!isset($event['card']) || !isset($event['position'])) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$card = CardPosition::interchangeCard($event['card']);
|
||||
if (!$card) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$position = CardPosition::interchangePosition($event['position']);
|
||||
if (!$position) return ['status' => false, 'msg' => 'Position Error'];
|
||||
|
||||
$cardInfo[$position] = intval($event['card']);
|
||||
RedisUtil::saveCardPosition($numberTabInfo['id'],intval($event['position']),intval($event['card']));
|
||||
$round = array(
|
||||
'tid' => intval($tableInfo['id']),
|
||||
'number_tab_id' => $numberTabInfo['id'],
|
||||
'card' => intval($event['card']),
|
||||
'number' => $card,
|
||||
'position' => intval($event['position']),
|
||||
'boot_id' => intval($numberTabInfo['boot_id']),
|
||||
'boot_num' => intval($numberTabInfo['boot_num']),
|
||||
'number_tab_number' => intval($numberTabInfo['number']),
|
||||
'card_info' => $cardInfo
|
||||
);
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'data' => $round];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,329 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\scan;
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\CardPositionNn;
|
||||
use freedom\utils\RedisUtil;
|
||||
|
||||
/**
|
||||
* TODO NN扫描
|
||||
* Class ScanNnService
|
||||
* @package app\services\scan
|
||||
*/
|
||||
class ScanNnService
|
||||
{
|
||||
/**
|
||||
* TODO NN扫描处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doScanNn(array $event, array $tableInfo): array
|
||||
{
|
||||
$checkScanRes = ScanCommonService::checkScan($event,$tableInfo);
|
||||
if ($checkScanRes['status'] == false){
|
||||
return $checkScanRes;
|
||||
}else{
|
||||
$numberTabInfo = $checkScanRes['numberTabInfo'];
|
||||
$cardInfo = $checkScanRes['cardInfo'];
|
||||
}
|
||||
// 判断牌是否符合规格
|
||||
if (!isset($event['card']) || empty(intval($event['card']))) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$card = intval($event['card']);
|
||||
$round = [
|
||||
'card' => $card,
|
||||
'number' => CardPosition::interchangeCard($card),
|
||||
'boot_id' => intval($numberTabInfo['boot_id']),
|
||||
'boot_num' => intval($numberTabInfo['boot_num']),
|
||||
'number_tab_id' => intval($numberTabInfo['id']),
|
||||
'number_tab_number' => intval($numberTabInfo['number'])
|
||||
];
|
||||
if (!$cardInfo){
|
||||
// 没有牌数据,创建并保存
|
||||
$cardInfo = ['card_first' => $card];
|
||||
$cardInfo['player_1_card_1'] = 0;
|
||||
$cardInfo['player_1_card_2'] = 0;
|
||||
$cardInfo['player_1_card_3'] = 0;
|
||||
$cardInfo['player_1_card_4'] = 0;
|
||||
$cardInfo['player_1_card_5'] = 0;
|
||||
$cardInfo['player_2_card_1'] = 0;
|
||||
$cardInfo['player_2_card_2'] = 0;
|
||||
$cardInfo['player_2_card_3'] = 0;
|
||||
$cardInfo['player_2_card_4'] = 0;
|
||||
$cardInfo['player_2_card_5'] = 0;
|
||||
$cardInfo['player_3_card_1'] = 0;
|
||||
$cardInfo['player_3_card_2'] = 0;
|
||||
$cardInfo['player_3_card_3'] = 0;
|
||||
$cardInfo['player_3_card_4'] = 0;
|
||||
$cardInfo['player_3_card_5'] = 0;
|
||||
$cardInfo['banker_card_1'] = 0;
|
||||
$cardInfo['banker_card_2'] = 0;
|
||||
$cardInfo['banker_card_3'] = 0;
|
||||
$cardInfo['banker_card_4'] = 0;
|
||||
$cardInfo['banker_card_5'] = 0;
|
||||
$positionFirst = CardPositionNn::nnPosition($card);
|
||||
$cardInfo['position_first'] = $positionFirst;
|
||||
NumberTab::where(['id' => $numberTabInfo['id']])->update(['position_first' => $positionFirst]);
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = 0;
|
||||
$round['order_num'] = 0;
|
||||
$round['result'] = '';
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
// 判断是否已经存在过相同牌
|
||||
$beforeCard = $cardInfo;
|
||||
//unset($beforeCard['card_first']);
|
||||
unset($beforeCard['position_first']);
|
||||
if(in_array($card,$beforeCard)) return ['status' => false, 'msg' => 'Card Exists'];
|
||||
$cardCountValues = array_count_values($beforeCard);
|
||||
// 获取当前定位
|
||||
if (isset($cardCountValues[0])){
|
||||
$positionNum = 20 - intval($cardCountValues[0]) + 1;
|
||||
} else {
|
||||
$positionNum = 20;
|
||||
}
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player1Card[3] = $cardInfo['player_1_card_4'];
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player2Card[3] = $cardInfo['player_2_card_4'];
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$player3Card[3] = $cardInfo['player_3_card_4'];
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$bankerCard[3] = $cardInfo['banker_card_4'];
|
||||
$resultWord = '';
|
||||
|
||||
$order = CardPositionNn::nnOrder($cardInfo['position_first']);
|
||||
$orderPosition = $positionNum - 1;
|
||||
$position = $order[$orderPosition];
|
||||
$orderNumArr = CardPositionNn::nnOrderNum($cardInfo['position_first']);
|
||||
$orderNum = $orderNumArr[$orderPosition];
|
||||
$cardInfo[$position] = $card;
|
||||
if($positionNum >= 17 && $positionNum <= 20){
|
||||
if($orderNum > 10 && $orderNum < 20){
|
||||
$player1Card[4] = $card;
|
||||
$player1Result = CardPositionNn::JudgeCowCow($player1Card);
|
||||
$resultWord = $player1Result['word'];
|
||||
}
|
||||
if($orderNum > 20 && $orderNum < 30){
|
||||
$player2Card[4] = $card;
|
||||
$player2Result = CardPositionNn::JudgeCowCow($player2Card);
|
||||
$resultWord = $player2Result['word'];
|
||||
}
|
||||
if($orderNum > 30 && $orderNum < 40){
|
||||
$player3Card[4] = $card;
|
||||
$player3Result = CardPositionNn::JudgeCowCow($player3Card);
|
||||
$resultWord = $player3Result['word'];
|
||||
}
|
||||
if($orderNum > 40){
|
||||
$bankerCard[4] = $card;
|
||||
$bankerResult = CardPositionNn::JudgeCowCow($bankerCard);
|
||||
$resultWord = $bankerResult['word'];
|
||||
}
|
||||
}
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = $positionNum;
|
||||
$round['order_num'] = $orderNum;
|
||||
$round['result'] = $resultWord;
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO NN识别处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doScanNnSb(array $event, array $tableInfo): array
|
||||
{
|
||||
$checkScanRes = ScanCommonService::checkScan($event,$tableInfo);
|
||||
if ($checkScanRes['status'] == false){
|
||||
return $checkScanRes;
|
||||
}else{
|
||||
$numberTabInfo = $checkScanRes['numberTabInfo'];
|
||||
$cardInfo = $checkScanRes['cardInfo'];
|
||||
}
|
||||
|
||||
// 所有牌须带上位置 (与扫描不同,识别的牌,位置是固定的)
|
||||
if (!isset($event['position']) || empty(intval($event['card']))) return ['status' => false, 'msg' => 'Card Position Miss. No Good.'];
|
||||
|
||||
$staticPosition = intval($event['position']);
|
||||
|
||||
// 判断牌是否符合规格
|
||||
if (!isset($event['card']) || empty(intval($event['card']))) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
|
||||
|
||||
$card = intval($event['card']);
|
||||
|
||||
$round = [
|
||||
'card' => $card,
|
||||
'number' => CardPosition::interchangeCard($card),
|
||||
'boot_id' => intval($numberTabInfo['boot_id']),
|
||||
'boot_num' => intval($numberTabInfo['boot_num']),
|
||||
'number_tab_id' => intval($numberTabInfo['id']),
|
||||
'number_tab_number' => intval($numberTabInfo['number'])
|
||||
];
|
||||
if (!$cardInfo){
|
||||
if ($staticPosition != 0) {
|
||||
return ['status' => false, 'msg' => 'First Card Position Should be 0. No Good.'];
|
||||
}
|
||||
// 没有牌数据,创建并保存
|
||||
$cardInfo = ['card_first' => $card];
|
||||
$cardInfo['player_1_card_1'] = 0;
|
||||
$cardInfo['player_1_card_2'] = 0;
|
||||
$cardInfo['player_1_card_3'] = 0;
|
||||
$cardInfo['player_1_card_4'] = 0;
|
||||
$cardInfo['player_1_card_5'] = 0;
|
||||
$cardInfo['player_2_card_1'] = 0;
|
||||
$cardInfo['player_2_card_2'] = 0;
|
||||
$cardInfo['player_2_card_3'] = 0;
|
||||
$cardInfo['player_2_card_4'] = 0;
|
||||
$cardInfo['player_2_card_5'] = 0;
|
||||
$cardInfo['player_3_card_1'] = 0;
|
||||
$cardInfo['player_3_card_2'] = 0;
|
||||
$cardInfo['player_3_card_3'] = 0;
|
||||
$cardInfo['player_3_card_4'] = 0;
|
||||
$cardInfo['player_3_card_5'] = 0;
|
||||
$cardInfo['banker_card_1'] = 0;
|
||||
$cardInfo['banker_card_2'] = 0;
|
||||
$cardInfo['banker_card_3'] = 0;
|
||||
$cardInfo['banker_card_4'] = 0;
|
||||
$cardInfo['banker_card_5'] = 0;
|
||||
$positionFirst = CardPositionNn::nnPosition($card);
|
||||
$cardInfo['position_first'] = $positionFirst;
|
||||
NumberTab::where(['id' => $numberTabInfo['id']])->update(['position_first' => $positionFirst]);
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = 0;
|
||||
$round['order_num'] = 0;
|
||||
$round['result'] = '';
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
// 判断是否已经存在过相同牌
|
||||
$beforeCard = $cardInfo;
|
||||
//unset($beforeCard['card_first']);
|
||||
unset($beforeCard['position_first']);
|
||||
|
||||
// 识别的允许先提交重复牌,再修改 2024/4/9
|
||||
// if(in_array($card,$beforeCard)) return ['status' => false, 'msg' => 'Card Exists'];
|
||||
|
||||
|
||||
$cardCountValues = array_count_values($beforeCard);
|
||||
// 获取当前定位
|
||||
if (isset($cardCountValues[0])){
|
||||
$positionNum = 20 - intval($cardCountValues[0]) + 1;
|
||||
} else {
|
||||
$positionNum = 20;
|
||||
}
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player1Card[2] = $cardInfo['player_1_card_3'];
|
||||
$player1Card[3] = $cardInfo['player_1_card_4'];
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player2Card[2] = $cardInfo['player_2_card_3'];
|
||||
$player2Card[3] = $cardInfo['player_2_card_4'];
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$player3Card[2] = $cardInfo['player_3_card_3'];
|
||||
$player3Card[3] = $cardInfo['player_3_card_4'];
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$bankerCard[2] = $cardInfo['banker_card_3'];
|
||||
$bankerCard[3] = $cardInfo['banker_card_4'];
|
||||
$resultWord = '';
|
||||
|
||||
|
||||
$order = CardPositionNn::nnOrderSb($cardInfo['position_first']);
|
||||
$orderPosition = $positionNum - 1;
|
||||
$position = $order[$orderPosition];
|
||||
$orderNumArr = CardPositionNn::nnOrderNumSb($cardInfo['position_first']);
|
||||
$orderNum = $orderNumArr[$orderPosition];
|
||||
|
||||
if (isset($event['position'])) {
|
||||
if ($staticPosition != 0) {
|
||||
$sbStaticPostion = CardPositionNn::sbStaticCardPosition($staticPosition);
|
||||
if ($position != $sbStaticPostion) {
|
||||
return ['status' => false, 'msg' => 'Card Postion Error. No Good.'];
|
||||
}
|
||||
} else {
|
||||
if ($cardInfo['position_first'] != 0) {
|
||||
return ['status' => false, 'msg' => 'First Card Exist. No Good.'];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$cardInfo[$position] = $card;
|
||||
if($positionNum == 5 || $positionNum == 10 || $positionNum == 15 || $positionNum == 20){
|
||||
if($orderNum > 10 && $orderNum < 20){
|
||||
$player1Card[4] = $card;
|
||||
$player1Result = CardPositionNn::JudgeCowCow($player1Card);
|
||||
$resultWord = $player1Result['word'];
|
||||
}
|
||||
if($orderNum > 20 && $orderNum < 30){
|
||||
$player2Card[4] = $card;
|
||||
$player2Result = CardPositionNn::JudgeCowCow($player2Card);
|
||||
$resultWord = $player2Result['word'];
|
||||
}
|
||||
if($orderNum > 30 && $orderNum < 40){
|
||||
$player3Card[4] = $card;
|
||||
$player3Result = CardPositionNn::JudgeCowCow($player3Card);
|
||||
$resultWord = $player3Result['word'];
|
||||
}
|
||||
if($orderNum > 40){
|
||||
$bankerCard[4] = $card;
|
||||
$bankerResult = CardPositionNn::JudgeCowCow($bankerCard);
|
||||
$resultWord = $bankerResult['word'];
|
||||
}
|
||||
}
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = $positionNum;
|
||||
$round['order_num'] = $orderNum;
|
||||
$round['result'] = $resultWord;
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\scan;
|
||||
|
||||
use app\models\process\NumberTab;
|
||||
use freedom\utils\CardPosition;
|
||||
use freedom\utils\CardPositionNn;
|
||||
use freedom\utils\CardPositionTc;
|
||||
use freedom\utils\RedisUtil;
|
||||
|
||||
/**
|
||||
* TODO TC扫描
|
||||
* Class ScanTcService
|
||||
* @package app\services\scan
|
||||
*/
|
||||
class ScanTcService
|
||||
{
|
||||
/**
|
||||
* TODO Tc扫描处理
|
||||
* @param array $event
|
||||
* @param array $tableInfo
|
||||
* @return array
|
||||
*/
|
||||
public static function doScanTc(array $event, array $tableInfo): array
|
||||
{
|
||||
$checkScanRes = ScanCommonService::checkScan($event,$tableInfo);
|
||||
if ($checkScanRes['status'] == false){
|
||||
return $checkScanRes;
|
||||
}else{
|
||||
$numberTabInfo = $checkScanRes['numberTabInfo'];
|
||||
$cardInfo = $checkScanRes['cardInfo'];
|
||||
}
|
||||
// 判断牌是否符合规格
|
||||
if (!isset($event['card']) || empty(intval($event['card']))) return ['status' => false, 'msg' => 'CardPosition Unable Distinguish'];
|
||||
$card = intval($event['card']);
|
||||
$round = [
|
||||
'card' => $card,
|
||||
'number' => CardPosition::interchangeCard($card),
|
||||
'boot_id' => intval($numberTabInfo['boot_id']),
|
||||
'boot_num' => intval($numberTabInfo['boot_num']),
|
||||
'number_tab_id' => intval($numberTabInfo['id']),
|
||||
'number_tab_number' => intval($numberTabInfo['number'])
|
||||
];
|
||||
if (!$cardInfo){
|
||||
// 没有牌数据,创建并保存
|
||||
$cardInfo = ['card_first' => $card];
|
||||
$cardInfo['player_1_card_1'] = 0;
|
||||
$cardInfo['player_1_card_2'] = 0;
|
||||
$cardInfo['player_1_card_3'] = 0;
|
||||
$cardInfo['player_2_card_1'] = 0;
|
||||
$cardInfo['player_2_card_2'] = 0;
|
||||
$cardInfo['player_2_card_3'] = 0;
|
||||
$cardInfo['player_3_card_1'] = 0;
|
||||
$cardInfo['player_3_card_2'] = 0;
|
||||
$cardInfo['player_3_card_3'] = 0;
|
||||
$cardInfo['banker_card_1'] = 0;
|
||||
$cardInfo['banker_card_2'] = 0;
|
||||
$cardInfo['banker_card_3'] = 0;
|
||||
$positionFirst = CardPositionNn::nnPosition($card);
|
||||
$cardInfo['position_first'] = $positionFirst;
|
||||
NumberTab::where(['id' => $numberTabInfo['id']])->update(['position_first' => $positionFirst]);
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = 0;
|
||||
$round['order_num'] = 0;
|
||||
$round['result'] = '';
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
// 判断是否已经存在过相同牌
|
||||
$beforeCard = $cardInfo;
|
||||
//unset($beforeCard['card_first']);
|
||||
unset($beforeCard['position_first']);
|
||||
if(in_array($card,$beforeCard)) return ['status' => false, 'msg' => 'Card Exists'];
|
||||
$cardCountValues = array_count_values($beforeCard);
|
||||
// 获取当前定位
|
||||
if (isset($cardCountValues[0])){
|
||||
$positionNum = 12 - intval($cardCountValues[0]) + 1;
|
||||
} else {
|
||||
$positionNum = 12;
|
||||
}
|
||||
$player1Card[0] = $cardInfo['player_1_card_1'];
|
||||
$player1Card[1] = $cardInfo['player_1_card_2'];
|
||||
$player2Card[0] = $cardInfo['player_2_card_1'];
|
||||
$player2Card[1] = $cardInfo['player_2_card_2'];
|
||||
$player3Card[0] = $cardInfo['player_3_card_1'];
|
||||
$player3Card[1] = $cardInfo['player_3_card_2'];
|
||||
$bankerCard[0] = $cardInfo['banker_card_1'];
|
||||
$bankerCard[1] = $cardInfo['banker_card_2'];
|
||||
$resultWord = '';
|
||||
|
||||
$order = CardPositionTc::tcOrder($cardInfo['position_first']);
|
||||
$orderPosition = $positionNum - 1;
|
||||
$position = $order[$orderPosition];
|
||||
$orderNumArr = CardPositionTc::tcOrderNum($cardInfo['position_first']);
|
||||
$orderNum = $orderNumArr[$orderPosition];
|
||||
$cardInfo[$position] = $card;
|
||||
if($positionNum >= 9){
|
||||
if($orderNum > 10 && $orderNum < 20){
|
||||
$player1Card[2] = $card;
|
||||
$player1Result = CardPositionTc::ThredCardCowCow($player1Card);
|
||||
$resultWord = $player1Result['word'];
|
||||
}
|
||||
if($orderNum > 20 && $orderNum < 30){
|
||||
$player2Card[2] = $card;
|
||||
$player2Result = CardPositionTc::ThredCardCowCow($player2Card);
|
||||
$resultWord = $player2Result['word'];
|
||||
}
|
||||
if($orderNum > 30 && $orderNum < 40){
|
||||
$player3Card[2] = $card;
|
||||
$player3Result = CardPositionTc::ThredCardCowCow($player3Card);
|
||||
$resultWord = $player3Result['word'];
|
||||
}
|
||||
if($orderNum > 40){
|
||||
$bankerCard[2] = $card;
|
||||
$bankerResult = CardPositionTc::ThredCardCowCow($bankerCard);
|
||||
$resultWord = $bankerResult['word'];
|
||||
}
|
||||
}
|
||||
RedisUtil::saveCard($numberTabInfo['id'],$cardInfo);
|
||||
$round['tid'] = $tableInfo['id'];
|
||||
$round['number_tab_id'] = $numberTabInfo['id'];
|
||||
$round['position'] = $positionNum;
|
||||
$round['order_num'] = $orderNum;
|
||||
$round['result'] = $resultWord;
|
||||
$round['card_info'] = $cardInfo;
|
||||
if ($numberTabInfo['bet_status'] == 2) {
|
||||
$round['is_scan'] = true;
|
||||
} else {
|
||||
$round['is_scan'] = false;
|
||||
}
|
||||
return ['status' => true, 'msg' => 'Scan Success', 'data' => $round];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,649 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace app\services\waybill;
|
||||
|
||||
use app\models\process\Boot;
|
||||
use app\models\process\NumberTab;
|
||||
use app\models\table\Table;
|
||||
use app\models\process\WaybillRemind;
|
||||
|
||||
/**
|
||||
* TODO
|
||||
* Class WaybillRemind
|
||||
* @package app\services\waybill
|
||||
*/
|
||||
class WaybillRemindService{
|
||||
public static function parseWaybillRemind($game_id, $table_id, $table_name, $boot_id){
|
||||
$is_good = array();
|
||||
$ns = NumberTab::getByBootIdDone($boot_id,'result, pair');
|
||||
$bigRoad = array();
|
||||
//列
|
||||
$yKey = 0;
|
||||
//行
|
||||
$xKey = 0;
|
||||
$last = array();
|
||||
foreach($ns AS $key => $value){
|
||||
if($value['pair'] == 1){
|
||||
$pair = 1;
|
||||
}elseif($value['pair'] == 2){
|
||||
$pair = 2;
|
||||
}elseif($value['pair'] == 3){
|
||||
$pair = 3;
|
||||
}else{
|
||||
$pair = 0;
|
||||
}
|
||||
if($key == 0 && $value['result'] == 3){
|
||||
$bigRoad[$yKey][$xKey] = array('result' => 3, 'tie_num' => 1, 'pair' => $pair);
|
||||
$last = array('yKey' => $yKey, 'xKey' => $xKey);
|
||||
}elseif($yKey == 0 && $xKey == 0 && !empty($last) && $value['result'] != 3){
|
||||
$bigRoad[$last['yKey']][$last['xKey']]['result'] = $value['result'];
|
||||
$bigRoad[$last['yKey']][$last['xKey']]['pair'] = $value['pair'];
|
||||
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){
|
||||
$yKey++;
|
||||
$xKey = 0;
|
||||
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){
|
||||
$xKey++;
|
||||
}
|
||||
$last = array('yKey' => $yKey, 'xKey' => $xKey);
|
||||
}elseif($key > 0 && $value['result'] == 3){
|
||||
$bigRoad[$last['yKey']][$last['xKey']]['tie_num'] = $bigRoad[$last['yKey']][$last['xKey']]['tie_num'] + 1;
|
||||
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoad[$last['yKey']][$last['xKey']]['result'] != 3){
|
||||
$yKey++;
|
||||
$xKey = 0;
|
||||
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoad[$last['yKey']][$last['xKey']]['result'] != 3){
|
||||
$xKey++;
|
||||
}
|
||||
$last = array('yKey' => $last['yKey'], 'xKey' => $last['xKey']);
|
||||
}else{
|
||||
$bigRoad[$yKey][$xKey] = array('result' => $value['result'], 'tie_num' => 0, 'pair' => $pair);
|
||||
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){
|
||||
$yKey++;
|
||||
$xKey = 0;
|
||||
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){
|
||||
$xKey++;
|
||||
}
|
||||
$last = array('yKey' => $yKey, 'xKey' => $xKey);
|
||||
}
|
||||
}
|
||||
//重新计算坐标
|
||||
$bigRoadLocation = array();
|
||||
$occupy = array();
|
||||
foreach($bigRoad AS $key => $value){
|
||||
$swerve = false;
|
||||
$swerveY = $key;
|
||||
foreach($value AS $k => $v){
|
||||
$show_y = $key;
|
||||
$show_x = $k;
|
||||
if($show_x > 5 && $swerve === false){
|
||||
$swerveY = $swerveY + 1;
|
||||
$show_y = $swerveY;
|
||||
$show_x = 5;
|
||||
array_push($occupy,$show_y.'-'.$show_x);
|
||||
}elseif(in_array($show_y.'-'.$show_x,$occupy)){
|
||||
if($swerve === false){
|
||||
$swerve = $show_x - 1;
|
||||
}
|
||||
$swerveY = $swerveY + 1;
|
||||
$show_y = $swerveY;
|
||||
$show_x = $swerve;
|
||||
array_push($occupy,$show_y.'-'.$show_x);
|
||||
}elseif($swerve !== false){
|
||||
$swerveY = $swerveY + 1;
|
||||
$show_y = $swerveY;
|
||||
$show_x = $swerve;
|
||||
array_push($occupy,$show_y.'-'.$show_x);
|
||||
}
|
||||
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result'], 'pair' => $v['pair'], 'tie_num' => $v['tie_num']);
|
||||
array_push($bigRoadLocation,$pushArray);
|
||||
}
|
||||
}
|
||||
$bigRoad_lenth = count($bigRoadLocation);
|
||||
if($bigRoad_lenth >= 4){
|
||||
//y=1
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 1){
|
||||
//庄
|
||||
if($bigRoad_lenth > 4){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-1]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-2]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-2]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-3]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-5]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '大路单挑');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//闲
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-1]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-2]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-2]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-3]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '大路单挑');
|
||||
}
|
||||
}
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-2]['show_y'] == 2 && $bigRoadLocation[$bigRoad_lenth-2]['result'] == 1){
|
||||
if($bigRoad_lenth > 4){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5]['show_y'] >= 4 && $bigRoadLocation[$bigRoad_lenth-5]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' =>'逢庄黐');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//y=2
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-3]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '拍拍黐');
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-3]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 2 && $bigRoadLocation[$bigRoad_lenth-4]['result'] == 1){
|
||||
if($bigRoad_lenth >= 6){
|
||||
if($bigRoadLocation[$bigRoad_lenth-6]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-6]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '一厅两房(闲)');
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-3]['show_y'] >=4 && $bigRoadLocation[$bigRoad_lenth-3]['result'] == 2){
|
||||
if($bigRoad_lenth >= 9){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-1]['show_x'] - $bigRoadLocation[$bigRoad_lenth-3]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-3-$player_length]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-3-$player_length]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] == 2 && $bigRoadLocation[$bigRoad_lenth-4-$player_length]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '逢闲黐');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['show_y'] < 6){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-3]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-3]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-3-$player_length]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-3-$player_length]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] < 6){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-3-$player_length]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-3-$player_length]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-3-$player_length]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-3-$player_length]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_y'] < 6){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-3-$player_length-$player_length_2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_y'] < 6){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-3-$player_length-$player_length_2-$banker_lenth]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth-$player_length_3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth-$player_length_3]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '隔黐庄');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-3]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '拍拍黐');
|
||||
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-3]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 2 && $bigRoadLocation[$bigRoad_lenth-4]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-6]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-6]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '一厅两房(庄)');
|
||||
}
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-3]['show_y'] < 6){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-3]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-3]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-3]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-3-$banker_length]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-3-$banker_length]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] < 6){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-3-$banker_length]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-3-$banker_length]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-3-$banker_length]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-3-$banker_length]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_y'] < 6){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-3-$banker_length-$banker_length_2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_y'] < 6){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-3-$banker_length-$banker_length_2-$player_lenth]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth-$banker_length_3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth-$banker_length_3]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '隔黐闲');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//y=3
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 3){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-4]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '拍拍黐');
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] < 6){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-1]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4-$player_length]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_y'] < 6){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] < 6){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] < 6){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth-$player_length_3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth-$player_length_3]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '隔黐庄');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-4]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '拍拍黐');
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] < 6){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-1]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_y'] < 6){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] < 6){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] < 6){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth-$banker_length_3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth-$banker_length_3]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '隔黐闲');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//y>=4
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] >= 4){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] < 6){
|
||||
$last_banker_lenth = $bigRoadLocation[$bigRoad_lenth-1]['show_y'];
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 6){
|
||||
for($length=0;$length<99;$length++){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1-$length]['show_y'] == 5){
|
||||
break;
|
||||
}
|
||||
}
|
||||
$last_banker_lenth = 5 + $length;
|
||||
}
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '长庄');
|
||||
if($bigRoadLocation[$bigRoad_lenth-1-$last_banker_lenth]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-1-$last_banker_lenth]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '拍拍黐');
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 4){
|
||||
$bigRoad_lenth = $bigRoad_lenth - 1;
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 5){
|
||||
$bigRoad_lenth = $bigRoad_lenth - 2;
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 6){
|
||||
$bigRoad_lenth = $bigRoad_lenth - 2 - $length;
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] < 6){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-1]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4-$player_length]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_y'] < 6){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$player_length]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$player_length]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] < 6){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_lenth = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] < 6){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$player_length-$player_length_2-$banker_lenth]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth-$player_length_3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-5-$player_length-$player_length_2-$banker_lenth-$player_length_3]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '隔黐庄');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-1]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] < 6){
|
||||
$last_banker_lenth = $bigRoadLocation[$bigRoad_lenth-1]['show_y'];
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 6){
|
||||
for($length=0;$length<99;$length++){
|
||||
if($bigRoadLocation[$bigRoad_lenth-1-$length]['show_y'] == 5){
|
||||
break;
|
||||
}
|
||||
}
|
||||
$last_player_lenth = 5 + $length;
|
||||
}
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '长闲');
|
||||
if($bigRoadLocation[$bigRoad_lenth-1-$last_player_lenth]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-1-$last_player_lenth]['result'] == 1){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '拍拍黐');
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 4){
|
||||
$bigRoad_lenth = $bigRoad_lenth - 1;
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 5){
|
||||
$bigRoad_lenth = $bigRoad_lenth - 2;
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-1]['show_y'] == 6){
|
||||
$bigRoad_lenth = $bigRoad_lenth - 2 - $length;
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-4]['show_y'] < 6){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-4]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-1]['show_x'] - $bigRoadLocation[$bigRoad_lenth-4]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length = $bigRoadLocation[$bigRoad_lenth-4]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_y'] < 6){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$banker_length]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length_2 = $bigRoadLocation[$bigRoad_lenth-4-$banker_length]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] >= 2 && $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['result'] == 2){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] < 6){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_x'];
|
||||
if($is_low == 1){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$player_lenth = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['result'] == 1){
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] < 6){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'];
|
||||
}elseif($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] == 6){
|
||||
$is_low = $bigRoadLocation[$bigRoad_lenth-4-$banker_length-$banker_length_2-$player_lenth]['show_x'] - $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_x'];
|
||||
if($is_low == 1){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'];
|
||||
}elseif($is_low == 0){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] + 1;
|
||||
}elseif($is_low < 0){
|
||||
$banker_length_3 = $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth]['show_y'] - ($is_low * 2);
|
||||
}
|
||||
}
|
||||
if($bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth-$banker_length_3]['show_y'] == 1 && $bigRoadLocation[$bigRoad_lenth-5-$banker_length-$banker_length_2-$player_lenth-$banker_length_3]['result'] == 2){
|
||||
$is_good = array('table_id' => $table_id, 'waybill_type' => '隔黐闲');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$table = WaybillRemind::where('table_id',$table_id)->find();
|
||||
$create_time = time();
|
||||
$bigRoadLocation = json_encode($bigRoadLocation);
|
||||
if($is_good){
|
||||
if($table){
|
||||
$update = [
|
||||
'waybill_type' => $is_good['waybill_type'],
|
||||
'create_time' => $create_time,
|
||||
'boot_id' => $boot_id,
|
||||
'ludan' => $bigRoadLocation,
|
||||
];
|
||||
WaybillRemind::update($update, ['table_id' => $is_good['table_id']]);
|
||||
}else{
|
||||
$insert = [
|
||||
'game_id' => $game_id,
|
||||
'table_id' => $is_good['table_id'],
|
||||
'table_name' => $table_name,
|
||||
'boot_id' => $boot_id,
|
||||
'waybill_type' => $is_good['waybill_type'],
|
||||
'create_time' => $create_time,
|
||||
'ludan' => $bigRoadLocation
|
||||
];
|
||||
WaybillRemind::create($insert);
|
||||
}
|
||||
}else{
|
||||
if($table){
|
||||
WaybillRemind::where('table_id',$table_id)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user