Pro/extend/Waybill/WaybillRoulette.php
2026-02-25 01:50:31 +08:00

227 lines
8.0 KiB
PHP

<?php
namespace Waybill;
class WaybillRoulette{
/**
* 色碟露珠生成
* @param $ns
* @return array
*/
public static function createWaybill($ns){
/**************************** 计算 showRoad start ***************************/
$showRoad = array_chunk($ns,6);
$showRoadLocation = array();
foreach($showRoad as $k => $v){
foreach($v as $key => $val){
$pushData = array('show_x' => $k + 1, 'show_y' =>$key + 1, 'result' => $val['roulette_result']);
$showRoadLocation[] = $pushData;
}
}
/**************************** 计算 showRoad end ***************************/
/**************************** 计算 bigRoadBS start ***************************/
//列
$yKey = 0;
//行
$xKey = 0;
$bigRoadBS = array();
foreach($ns AS $key => $value) {
$value['result'] = self::resultParseBS($value['roulette_result']);
$ns[$key] = $value;
}
foreach($ns AS $key => $value){
$bigRoadBS[$yKey][$xKey] = array('result' => $value['result']);
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoadBS[$yKey][$xKey]['result']){
$yKey++;
$xKey = 0;
}else{
$xKey++;
}
}
//重新计算坐标
$bigRoadBSLocation = array();
$occupy = array();
foreach($bigRoadBS AS $key => $value){
$swerve = false;
$swerveY = $key;
foreach($value AS $k => $v){
$show_y = $key;
$show_x = $k;
if($show_x > 5 && $swerve === false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = 5;
$occupy[] = $show_y . '-' . $show_x;
}elseif(in_array($show_y.'-'.$show_x,$occupy)){
if($swerve === false){
$swerve = $show_x - 1;
}
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
$occupy[] = $show_y . '-' . $show_x;
}elseif($swerve !== false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
$occupy[] = $show_y . '-' . $show_x;
}
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
$bigRoadBSLocation[] = $pushArray;
}
}
/**************************** 计算 bigRoadBS end ***************************/
/**************************** 计算 bigRoadSP start ***************************/
//列
$yKey = 0;
//行
$xKey = 0;
$bigRoadSP = array();
foreach($ns AS $key => $value) {
$value['result'] = self::resultParseSP($value['roulette_result']);
$ns[$key] = $value;
}
foreach($ns AS $key => $value){
$bigRoadSP[$yKey][$xKey] = array('result' => $value['result']);
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoadSP[$yKey][$xKey]['result']){
$yKey++;
$xKey = 0;
}else{
$xKey++;
}
}
//重新计算坐标
$bigRoadSPLocation = array();
$occupy = array();
foreach($bigRoadSP AS $key => $value){
$swerve = false;
$swerveY = $key;
foreach($value AS $k => $v){
$show_y = $key;
$show_x = $k;
if($show_x > 5 && $swerve === false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = 5;
$occupy[] = $show_y . '-' . $show_x;
}elseif(in_array($show_y.'-'.$show_x,$occupy)){
if($swerve === false){
$swerve = $show_x - 1;
}
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
$occupy[] = $show_y . '-' . $show_x;
}elseif($swerve !== false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
$occupy[] = $show_y . '-' . $show_x;
}
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
$bigRoadSPLocation[] = $pushArray;
}
}
/**************************** 计算 bigRoadSP end ***************************/
/**************************** 计算 bigRoadRB start ***************************/
//列
$yKey = 0;
//行
$xKey = 0;
$bigRoadRB = array();
foreach($ns AS $key => $value) {
$value['result'] = self::resultParseRB($value['roulette_result']);
$ns[$key] = $value;
}
foreach($ns AS $key => $value){
$bigRoadRB[$yKey][$xKey] = array('result' => $value['result']);
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoadRB[$yKey][$xKey]['result']){
$yKey++;
$xKey = 0;
}else{
$xKey++;
}
}
//重新计算坐标
$bigRoadRBLocation = array();
$occupy = array();
foreach($bigRoadRB AS $key => $value){
$swerve = false;
$swerveY = $key;
foreach($value AS $k => $v){
$show_y = $key;
$show_x = $k;
if($show_x > 5 && $swerve === false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = 5;
$occupy[] = $show_y . '-' . $show_x;
}elseif(in_array($show_y.'-'.$show_x,$occupy)){
if($swerve === false){
$swerve = $show_x - 1;
}
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
$occupy[] = $show_y . '-' . $show_x;
}elseif($swerve !== false){
$swerveY = $swerveY + 1;
$show_y = $swerveY;
$show_x = $swerve;
$occupy[] = $show_y . '-' . $show_x;
}
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
$bigRoadRBLocation[] = $pushArray;
}
}
/**************************** 计算 bigRoadRB end ***************************/
$data = array();
$data['showRoad'] = $showRoadLocation;
$data['bigRoadBS'] = $bigRoadBSLocation;
$data['bigRoadSP'] = $bigRoadSPLocation;
$data['bigRoadRB'] = $bigRoadRBLocation;
return (['status'=>true, 'msg'=>'数据存在', 'waybill'=>$data]);
}
// 结果分析(大小)
public static function resultParseBS($result){
if($result == 0) {
return 3;
} else {
if($result >= 1 && $result <= 18) {
return 2;
} else {
return 1;
}
}
}
// 结果分析(单双)
public static function resultParseSP($result){
if($result == 0) {
return 3;
} else {
if ($result % 2 == 0) {
return 1;
} else {
return 2;
}
}
}
// 结果分析(红黑)
public static function resultParseRB($result){
if($result == 0) {
return 3;
} else {
if(in_array($result,[1,3,5,7,9,12,14,16,18,19,21,23,25,27,30,32,34,36])){
return 1;
} else {
return 2;
}
}
}
}