add
This commit is contained in:
@@ -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']]]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user