1643 lines
45 KiB
PHP
1643 lines
45 KiB
PHP
<?php
|
||
|
||
use think\Cache;
|
||
use \think\Db;
|
||
use \think\Session;
|
||
|
||
// 版本号
|
||
define('VERSION_V','?ver=v1.5.0');
|
||
//加密常量16位
|
||
define('ENCODE_CONSTANT','ZZWBKJ_ZHIHUAWEI');
|
||
//加密秘钥16位
|
||
define('ENCODE_TOKEN','1519699179001WZH');
|
||
|
||
//******************************集成函数********************************
|
||
/**
|
||
* 打印调试函数
|
||
* @param $content
|
||
* @param $is_die
|
||
*/
|
||
function pre($content, $is_die = true){
|
||
header('Content-type: text/html; charset=utf-8');
|
||
echo '<pre>' . print_r($content, true);
|
||
$is_die && die();
|
||
}
|
||
function decrypt_data($post){
|
||
$decrypted = openssl_decrypt(base64_decode($post['encryptData']), 'aes-128-cbc', ENCODE_TOKEN, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING, ENCODE_CONSTANT);
|
||
$json_str = rtrim($decrypted, "\0");
|
||
$json_arr = json_decode($json_str,true);
|
||
return $json_arr;
|
||
}
|
||
function encrypt_data($array){
|
||
$str_padded = json_encode($array);
|
||
if (strlen($str_padded) % 16) {
|
||
$str_padded = str_pad($str_padded,strlen($str_padded) + 16 - strlen($str_padded) % 16, "\0");
|
||
}
|
||
$encrypted = openssl_encrypt($str_padded, 'aes-128-cbc', ENCODE_TOKEN, OPENSSL_RAW_DATA|OPENSSL_NO_PADDING, ENCODE_CONSTANT);
|
||
return base64_encode($encrypted);
|
||
}
|
||
//生成一个apiToken
|
||
function create_api_token($username,$nickname){
|
||
$curTime = time();
|
||
return md5($curTime.$username.$nickname);
|
||
}
|
||
//充值称号生成
|
||
function recharge_title($money){
|
||
if($money >= 10000){
|
||
return '<font style="color:#02B3DD;">黄金会员</font>';
|
||
}elseif($money >= 50000){
|
||
return '<font style="color:#FBA85C;">钻石会员</font>';
|
||
}elseif($money >= 200000){
|
||
return '<font style="color:#C53187;">皇者会员</font>';
|
||
}else{
|
||
return '<font>会员</font>';
|
||
}
|
||
}
|
||
/**
|
||
* 系统非常规MD5加密方法
|
||
* @param string $str 要加密的字符串
|
||
* @return string
|
||
*/
|
||
function think_ucenter_md5($str, $key = 'ThinkUCenter'){
|
||
return '' === $str ? '' : md5(sha1($str) . $key);
|
||
}
|
||
// 百家乐结果转换
|
||
function resultBaccarat($result){
|
||
if($result == 1){
|
||
$result = '庄';
|
||
}elseif($result == 2){
|
||
$result = '闲';
|
||
}elseif($result == 3){
|
||
$result = '和';
|
||
}else{
|
||
$result = '';
|
||
}
|
||
return $result;
|
||
}
|
||
// 百家乐对子转换
|
||
function pairBaccarat($pair,$mode){
|
||
if($mode == true){
|
||
$str = '-';
|
||
}else{
|
||
$str = '';
|
||
}
|
||
if($pair == 1){
|
||
$pair = $str.'庄对';
|
||
}elseif($pair == 2){
|
||
$pair = $str.'闲对';
|
||
}elseif($pair == 3){
|
||
$pair = $str.'庄闲对';
|
||
}else{
|
||
$pair = '';
|
||
}
|
||
return $pair;
|
||
}
|
||
// 龙虎结果转换
|
||
function resultDt($result){
|
||
if($result == 1){
|
||
$result = '龙';
|
||
}elseif($result == 2){
|
||
$result = '虎';
|
||
}elseif($result == 3){
|
||
$result = '和';
|
||
}else{
|
||
$result = '';
|
||
}
|
||
return $result;
|
||
}
|
||
// 牛牛结果转换
|
||
function resultNn($result){
|
||
if($result == 0){
|
||
$result = '无牛';
|
||
}elseif($result >= 1 && $result <= 9){
|
||
$result = '牛'.$result;
|
||
}elseif($result == 10){
|
||
$result = '牛牛';
|
||
}elseif($result == 11){
|
||
$result = '五公';
|
||
}
|
||
return $result;
|
||
}
|
||
// 客户端转换
|
||
function exchangeClient($client){
|
||
if($client == 1){
|
||
$client = '电脑版';
|
||
}elseif($client == 2){
|
||
$client = '苹果版';
|
||
}elseif($client == 3){
|
||
$client = '安卓版';
|
||
}elseif($client == 4){
|
||
$client = '网页版';
|
||
}elseif($client == 5){
|
||
$client = '微投';
|
||
}else{
|
||
$client = '未知';
|
||
}
|
||
return $client;
|
||
}
|
||
// 定义一个函数获取客户端IP地址
|
||
function getIP(){
|
||
global $ip;
|
||
if(getenv("HTTP_X_FORWARDED_FOR"))
|
||
$ip = getenv("HTTP_X_FORWARDED_FOR");
|
||
else if (getenv("HTTP_CLIENT_IP"))
|
||
$ip = getenv("HTTP_CLIENT_IP");
|
||
else if(getenv("REMOTE_ADDR"))
|
||
$ip = getenv("REMOTE_ADDR");
|
||
else $ip = "";
|
||
return $ip;
|
||
}
|
||
//记录操作函数
|
||
function insertAgentLog($control = '', $remake = ''){
|
||
$ui = Session::get('user_info');
|
||
$insertData = array();
|
||
$insertData['user_id'] = $ui['id'];
|
||
$insertData['username'] = $ui['username'];
|
||
$insertData['nickname'] = $ui['nickname'];
|
||
$insertData['ip'] = getIP();
|
||
$insertData['control'] = $control;
|
||
$insertData['control_time'] = time();
|
||
$insertData['remake'] = $remake;
|
||
Db::name('agent_log')->insert($insertData);
|
||
}
|
||
|
||
/**
|
||
* 记录管理员日志
|
||
* @param string $control
|
||
* @param string $remake
|
||
*/
|
||
function insertAdminLog($control = '', $remake = ''){
|
||
$ui = Session::get('user_info');
|
||
$insertData = array();
|
||
$insertData['space_admin_id'] = $ui['id'];
|
||
$insertData['space_admin'] = $ui['admin'];
|
||
$insertData['ip'] = getIP();
|
||
$insertData['control'] = $control;
|
||
$insertData['control_time'] = time();
|
||
$insertData['remake'] = $remake;
|
||
Db::name('space_system_log')->insert($insertData);
|
||
}
|
||
//正负数转换
|
||
function to_number($number){
|
||
return $number > 0 ? -1 * $number : abs($number);
|
||
}
|
||
/**
|
||
* 随机生成字符串
|
||
* @param int $length
|
||
* @return null|string
|
||
*/
|
||
function getRandChar($length = 6){
|
||
$str = null;
|
||
$strPol = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
|
||
$max = strlen($strPol)-1;
|
||
for($i=0;$i<$length;$i++){
|
||
$str.=$strPol[rand(0,$max)]; //rand($min,$max)生成介于min和max两个数之间的一个随机整数
|
||
}
|
||
return $str;
|
||
}
|
||
|
||
/**
|
||
* 获取最近七天所有日期
|
||
*/
|
||
function get_weeks($time = '', $format='Y-m-d'){
|
||
$time = $time != '' ? $time : time();
|
||
//组合数据
|
||
$date = [];
|
||
for ($i=0; $i<7; $i++){
|
||
$date[$i] = date($format ,strtotime( '-' . $i .' days', $time));
|
||
}
|
||
return $date;
|
||
}
|
||
/**
|
||
* 生成牛牛路单
|
||
*/
|
||
function nn_waybill($ns){
|
||
$showRoadLocation = array();
|
||
foreach($ns as $k => $v){
|
||
|
||
$pushData2 = array('show_x' => $k + 1, 'show_y' =>2,'type' => 2, 'result' => $v['result_player_1'], 'is_win' => $v['win_player_1']);
|
||
$pushData3 = array('show_x' => $k + 1, 'show_y' =>3,'type' => 2, 'result' => $v['result_player_2'], 'is_win' => $v['win_player_2']);
|
||
$pushData4 = array('show_x' => $k + 1, 'show_y' =>4,'type' => 2, 'result' => $v['result_player_3'], 'is_win' => $v['win_player_3']);
|
||
if($v['win_player_1'] == 0 && $v['win_player_2'] == 0 && $v['win_player_3'] == 0){
|
||
$banker_win = 1;
|
||
}else{
|
||
$banker_win = 0;
|
||
}
|
||
$pushData1 = array('show_x' => $k + 1, 'show_y' =>1,'type' => 1, 'result' => $v['result_banker'], 'is_win' => $banker_win);
|
||
array_push($showRoadLocation,$pushData1);
|
||
array_push($showRoadLocation,$pushData2);
|
||
array_push($showRoadLocation,$pushData3);
|
||
array_push($showRoadLocation,$pushData4);
|
||
}
|
||
return (['status'=>true,'msg'=>'数据存在','waybill'=>$showRoadLocation]);
|
||
|
||
}
|
||
/**
|
||
* 生成路单
|
||
*/
|
||
function waybill($ns){
|
||
/**************************** 计算 sanxingRoad start ***************************/
|
||
$sanxingRoad = array();
|
||
$firstTieNum = 0;
|
||
$isFirst = true;
|
||
$num = 0;
|
||
foreach($ns AS $k => $v){
|
||
if($isFirst == true){
|
||
if($v['result'] == 3){
|
||
$firstTieNum++;
|
||
}elseif($v['result'] == 1 || $v['result'] == 2){
|
||
$v['tie_num'] = $firstTieNum;
|
||
$sanxingRoad[$num] = $v;
|
||
$isFirst = false;
|
||
$num++;
|
||
}
|
||
}else{
|
||
if($v['result'] == 3){
|
||
$sanxingRoad[$num-1]['tie_num'] = $sanxingRoad[$num-1]['tie_num'] + 1;
|
||
}elseif($v['result'] == 1 || $v['result'] == 2){
|
||
$v['tie_num'] = 0;
|
||
$sanxingRoad[] = $v;
|
||
$num++;
|
||
}
|
||
}
|
||
}
|
||
$sanxingRoad = array_chunk($sanxingRoad,3);
|
||
$sanxingRoadLocation = array();
|
||
foreach($sanxingRoad AS $k => $v){
|
||
foreach($v as $key => $val){
|
||
$pushData = array('show_x' => $k + 1, 'show_y' =>$key + 1, 'result' => $val['result'], 'pair' => $val['pair'], 'tie_num' => $val['tie_num']);
|
||
array_push($sanxingRoadLocation,$pushData);
|
||
}
|
||
}
|
||
/**************************** 计算 sanxingRoad end ***************************/
|
||
/**************************** 计算 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['result'], 'pair' => $val['pair']);
|
||
array_push($showRoadLocation,$pushData);
|
||
}
|
||
}
|
||
/**************************** 计算 showRoad end ***************************/
|
||
$bigRoad = array();
|
||
$bigEyeRoad = array();
|
||
$pathway = array();
|
||
$roach = array();
|
||
/**************************** 计算 bigRoad start ***************************/
|
||
//列
|
||
$yKey = 0;
|
||
//行
|
||
$xKey = 0;
|
||
$last = array();
|
||
foreach($ns AS $key => $value){
|
||
if($value['pair'] == 1){
|
||
$pair = 1;
|
||
}elseif($value['pair'] == 2){
|
||
$pair = 2;
|
||
}elseif($value['pair'] == 3){
|
||
$pair = 3;
|
||
}else{
|
||
$pair = 0;
|
||
}
|
||
if($key == 0 && $value['result'] == 3){
|
||
$bigRoad[$yKey][$xKey] = array('result' => 3, 'tie_num' => 1, 'pair' => $pair);
|
||
$last = array('yKey' => $yKey, 'xKey' => $xKey);
|
||
}elseif($yKey == 0 && $xKey == 0 && !empty($last) && $value['result'] != 3){
|
||
$bigRoad[$last['yKey']][$last['xKey']]['result'] = $value['result'];
|
||
$bigRoad[$last['yKey']][$last['xKey']]['pair'] = $value['pair'];
|
||
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){
|
||
$yKey++;
|
||
$xKey = 0;
|
||
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3){
|
||
$xKey++;
|
||
}
|
||
$last = array('yKey' => $yKey, 'xKey' => $xKey);
|
||
}elseif($key > 0 && $value['result'] == 3){
|
||
$bigRoad[$last['yKey']][$last['xKey']]['tie_num'] = $bigRoad[$last['yKey']][$last['xKey']]['tie_num'] + 1;
|
||
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoad[$last['yKey']][$last['xKey']]['result'] != 3){
|
||
$yKey++;
|
||
$xKey = 0;
|
||
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$last['yKey']][$last['xKey']]['result'] && $ns[$key+1]['result'] != 3 && $bigRoad[$last['yKey']][$last['xKey']]['result'] != 3){
|
||
$xKey++;
|
||
}
|
||
$last = array('yKey' => $last['yKey'], 'xKey' => $last['xKey']);
|
||
}else{
|
||
$bigRoad[$yKey][$xKey] = array('result' => $value['result'], 'tie_num' => 0, 'pair' => $pair);
|
||
if(isset($ns[$key+1]) && $ns[$key+1]['result'] != $bigRoad[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){
|
||
$yKey++;
|
||
$xKey = 0;
|
||
}elseif(isset($ns[$key+1]) && $ns[$key+1]['result'] == $bigRoad[$yKey][$xKey]['result'] && $ns[$key+1]['result'] != 3){
|
||
$xKey++;
|
||
}
|
||
$last = array('yKey' => $yKey, 'xKey' => $xKey);
|
||
}
|
||
}
|
||
//重新计算坐标
|
||
$bigRoadLocation = array();
|
||
$occupy = array();
|
||
foreach($bigRoad AS $key => $value){
|
||
$swerve = false;
|
||
$swerveY = $key;
|
||
foreach($value AS $k => $v){
|
||
$show_y = $key;
|
||
$show_x = $k;
|
||
if($show_x > 5 && $swerve === false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = 5;
|
||
array_push($occupy,$show_y.'-'.$show_x);
|
||
}elseif(in_array($show_y.'-'.$show_x,$occupy)){
|
||
if($swerve === false){
|
||
$swerve = $show_x - 1;
|
||
}
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupy,$show_y.'-'.$show_x);
|
||
}elseif($swerve !== false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupy,$show_y.'-'.$show_x);
|
||
}
|
||
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result'], 'pair' => $v['pair'], 'tie_num' => $v['tie_num']);
|
||
array_push($bigRoadLocation,$pushArray);
|
||
}
|
||
}
|
||
/**************************** 计算 bigRoad end ***************************/
|
||
/**************************** 计算 bigEyeRoad start ***************************/
|
||
$bigEyeRoadStart = false;
|
||
$bigEyeRoadYKey = 0;
|
||
$bigEyeRoadXKey = 0;
|
||
$bigEyeRoadLast = array();
|
||
foreach($bigRoad AS $key => $value){
|
||
foreach($value AS $k => $v){
|
||
if($key == 1 && $k == 1 && isset($bigRoad[1][1])){
|
||
if(isset($bigRoad[0][1])){
|
||
$bigEyeRoad[0][0] = array('result' => 1);
|
||
}else{
|
||
$bigEyeRoad[0][0] = array('result' => 2);
|
||
}
|
||
$bigEyeRoadStart = true;
|
||
$bigEyeRoadLast = $bigEyeRoad[0][0];
|
||
continue;
|
||
}
|
||
if($key == 2 && $k == 0 && !isset($bigEyeRoad[0][0])){
|
||
if(isset($bigRoad[0]) && isset($bigRoad[1]) && count($bigRoad[0]) == count($bigRoad[1])){
|
||
$bigEyeRoad[0][0] = array('result' => 1);
|
||
}else{
|
||
$bigEyeRoad[0][0] = array('result' => 2);
|
||
}
|
||
$bigEyeRoadStart = true;
|
||
$bigEyeRoadLast = $bigEyeRoad[0][0];
|
||
continue;
|
||
}
|
||
if($bigEyeRoadStart == true){
|
||
$bigEyeRoadPushData = array();
|
||
if($k == 0){ //第一个
|
||
$p1 = $key - 1;
|
||
$p2 = $key - 2;
|
||
if(count($bigRoad[$p1]) == count($bigRoad[$p2])){
|
||
$bigEyeRoadPushData = array('result' => 1);
|
||
}else{
|
||
$bigEyeRoadPushData = array('result' => 2);
|
||
}
|
||
}elseif($k == 1){ //第二个
|
||
if(isset($bigRoad[$key-1][$k])){
|
||
$bigEyeRoadPushData = array('result' => 1);
|
||
}else{
|
||
$bigEyeRoadPushData = array('result' => 2);
|
||
}
|
||
}else{ //第三个或者之后那些
|
||
if(isset($bigRoad[$key-1][$k-1]) && !isset($bigRoad[$key-1][$k])){
|
||
$bigEyeRoadPushData = array('result' => 2);
|
||
}else{
|
||
$bigEyeRoadPushData = array('result' => 1);
|
||
}
|
||
}
|
||
if($bigEyeRoadLast['result'] == $bigEyeRoadPushData['result']){
|
||
$bigEyeRoadXKey++;
|
||
}else{
|
||
$bigEyeRoadYKey++;
|
||
$bigEyeRoadXKey = 0;
|
||
}
|
||
$bigEyeRoad[$bigEyeRoadYKey][$bigEyeRoadXKey] = $bigEyeRoadPushData;
|
||
$bigEyeRoadLast = $bigEyeRoadPushData;
|
||
}
|
||
}
|
||
}
|
||
//重新计算坐标
|
||
$bigEyeRoadLocation = array();
|
||
$occupyEye = array();
|
||
foreach($bigEyeRoad AS $key => $value){
|
||
$swerve = false;
|
||
$swerveY = $key;
|
||
foreach($value AS $k => $v){
|
||
$show_y = $key;
|
||
$show_x = $k;
|
||
if($show_x > 5 && $swerve === false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = 5;
|
||
array_push($occupyEye,$show_y.'-'.$show_x);
|
||
}elseif(in_array($show_y.'-'.$show_x,$occupyEye)){
|
||
if($swerve === false){
|
||
$swerve = $show_x - 1;
|
||
}
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupyEye,$show_y.'-'.$show_x);
|
||
}elseif($swerve !== false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupyEye,$show_y.'-'.$show_x);
|
||
}
|
||
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
|
||
array_push($bigEyeRoadLocation,$pushArray);
|
||
}
|
||
}
|
||
/**************************** 计算 bigEyeRoad end ***************************/
|
||
/**************************** 计算 pathway start ***************************/
|
||
$pathwayStart = false;
|
||
$pathwayYKey = 0;
|
||
$pathwayXKey = 0;
|
||
$pathwayLast = array();
|
||
foreach($bigRoad AS $key => $value){
|
||
foreach($value AS $k => $v){
|
||
if($key == 2 && $k == 1 && isset($bigRoad[2][1])){
|
||
if(isset($bigRoad[0][1])){
|
||
$pathway[0][0] = array('result' => 1);
|
||
}else{
|
||
$pathway[0][0] = array('result' => 2);
|
||
}
|
||
$pathwayStart = true;
|
||
$pathwayLast = $pathway[0][0];
|
||
continue;
|
||
}
|
||
if($key == 3 && $k == 0 && !isset($pathway[0][0])){
|
||
if(isset($bigRoad[0]) && isset($bigRoad[2]) && count($bigRoad[0]) == count($bigRoad[2])){
|
||
$pathway[0][0] = array('result' => 1);
|
||
}else{
|
||
$pathway[0][0] = array('result' => 2);
|
||
}
|
||
$pathwayStart = true;
|
||
$pathwayLast = $pathway[0][0];
|
||
continue;
|
||
}
|
||
if($pathwayStart == true){
|
||
$pushData = array();
|
||
if($k == 0){ //第一个
|
||
$p1 = $key - 1;
|
||
$p2 = $key - 3;
|
||
if(count($bigRoad[$p1]) == count($bigRoad[$p2])){
|
||
$pushData = array('result' => 1);
|
||
}else{
|
||
$pushData = array('result' => 2);
|
||
}
|
||
}elseif($k == 1){ //第二个
|
||
if(isset($bigRoad[$key-2][$k])){
|
||
$pushData = array('result' => 1);
|
||
}else{
|
||
$pushData = array('result' => 2);
|
||
}
|
||
}else{ //第三个或者之后那些
|
||
if(isset($bigRoad[$key-2][$k-1]) && !isset($bigRoad[$key-2][$k])){
|
||
$pushData = array('result' => 2);
|
||
}else{
|
||
$pushData = array('result' => 1);
|
||
}
|
||
}
|
||
if($pathwayLast['result'] == $pushData['result']){
|
||
$pathwayXKey++;
|
||
}else{
|
||
$pathwayYKey++;
|
||
$pathwayXKey = 0;
|
||
}
|
||
$pathway[$pathwayYKey][$pathwayXKey] = $pushData;
|
||
$pathwayLast = $pushData;
|
||
}
|
||
}
|
||
}
|
||
//echo "<pre>";
|
||
//print_r($pathway);
|
||
//echo "</pre>";
|
||
//exit();
|
||
//重新计算坐标
|
||
$pathwayLocation = array();
|
||
$occupyPathway = array();
|
||
foreach($pathway AS $key => $value){
|
||
$swerve = false;
|
||
$swerveY = $key;
|
||
foreach($value AS $k => $v){
|
||
$show_y = $key;
|
||
$show_x = $k;
|
||
if($show_x > 5 && $swerve === false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = 5;
|
||
array_push($occupyPathway,$show_y.'-'.$show_x);
|
||
}elseif(in_array($show_y.'-'.$show_x,$occupyPathway)){
|
||
if($swerve === false){
|
||
$swerve = $show_x - 1;
|
||
}
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupyPathway,$show_y.'-'.$show_x);
|
||
}elseif($swerve !== false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupyPathway,$show_y.'-'.$show_x);
|
||
}
|
||
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
|
||
array_push($pathwayLocation,$pushArray);
|
||
}
|
||
}
|
||
/**************************** 计算 pathway end ***************************/
|
||
/**************************** 计算 roach start ***************************/
|
||
$roachStart = false;
|
||
$roachYKey = 0;
|
||
$roachXKey = 0;
|
||
$roachLast = array();
|
||
foreach($bigRoad AS $key => $value){
|
||
foreach($value AS $k => $v){
|
||
if($key == 3 && $k == 1 && isset($bigRoad[3][1])){
|
||
if(isset($bigRoad[0][1])){
|
||
$roach[0][0] = array('result' => 1);
|
||
}else{
|
||
$roach[0][0] = array('result' => 2);
|
||
}
|
||
$roachStart = true;
|
||
$roachLast = $roach[0][0];
|
||
continue;
|
||
}
|
||
if($key == 4 && $k == 0 && !isset($roach[0][0])){
|
||
if(isset($bigRoad[0]) && isset($bigRoad[3]) && count($bigRoad[0]) == count($bigRoad[3])){
|
||
$roach[0][0] = array('result' => 1);
|
||
}else{
|
||
$roach[0][0] = array('result' => 2);
|
||
}
|
||
$roachStart = true;
|
||
$roachLast = $roach[0][0];
|
||
continue;
|
||
}
|
||
if($roachStart == true){
|
||
$pushData = array();
|
||
if($k == 0){ //第一个
|
||
$p1 = $key - 1;
|
||
$p2 = $key - 4;
|
||
if(count($bigRoad[$p1]) == count($bigRoad[$p2])){
|
||
$pushData = array('result' => 1);
|
||
}else{
|
||
$pushData = array('result' => 2);
|
||
}
|
||
}elseif($k == 1){ //第二个
|
||
if(isset($bigRoad[$key-3][$k])){
|
||
$pushData = array('result' => 1);
|
||
}else{
|
||
$pushData = array('result' => 2);
|
||
}
|
||
}else{ //第三个或者之后那些
|
||
if(isset($bigRoad[$key-3][$k-1]) && !isset($bigRoad[$key-3][$k])){
|
||
$pushData = array('result' => 2);
|
||
}else{
|
||
$pushData = array('result' => 1);
|
||
}
|
||
}
|
||
if($roachLast['result'] == $pushData['result']){
|
||
$roachXKey++;
|
||
}else{
|
||
$roachYKey++;
|
||
$roachXKey = 0;
|
||
}
|
||
$roach[$roachYKey][$roachXKey] = $pushData;
|
||
$roachLast = $pushData;
|
||
}
|
||
}
|
||
}
|
||
//重新计算坐标
|
||
$roachLocation = array();
|
||
$occupyRoach = array();
|
||
foreach($roach AS $key => $value){
|
||
$swerve = false;
|
||
$swerveY = $key;
|
||
foreach($value AS $k => $v){
|
||
$show_y = $key;
|
||
$show_x = $k;
|
||
if($show_x > 5 && $swerve === false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = 5;
|
||
array_push($occupyRoach,$show_y.'-'.$show_x);
|
||
}elseif(in_array($show_y.'-'.$show_x,$occupyRoach)){
|
||
if($swerve === false){
|
||
$swerve = $show_x - 1;
|
||
}
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupyRoach,$show_y.'-'.$show_x);
|
||
}elseif($swerve !== false){
|
||
$swerveY = $swerveY + 1;
|
||
$show_y = $swerveY;
|
||
$show_x = $swerve;
|
||
array_push($occupyRoach,$show_y.'-'.$show_x);
|
||
}
|
||
$pushArray = array('show_x' => $show_y+1, 'show_y' => $show_x+1, 'result' => $v['result']);
|
||
array_push($roachLocation,$pushArray);
|
||
}
|
||
}
|
||
$data = array();
|
||
$data['showRoad'] = $showRoadLocation;
|
||
$data['bigRoad'] = $bigRoadLocation;
|
||
$data['bigEyeRoad'] = $bigEyeRoadLocation;
|
||
$data['pathway'] = $pathwayLocation;
|
||
$data['roach'] = $roachLocation;
|
||
$data['sanxingRoad'] = $sanxingRoadLocation;
|
||
return (['status'=>true,'msg'=>'数据存在','waybill'=>$data]);
|
||
}
|
||
|
||
|
||
/**
|
||
* 解决前端路单显示爆格问题
|
||
*/
|
||
function reform($waybill,$forecast=0){
|
||
// 结果
|
||
$showRoad = $waybill['waybill']['showRoad'];
|
||
$count = count($showRoad)-1;
|
||
if($count >= 0){
|
||
$end_x = $showRoad[$count]['show_x'];
|
||
$end_y = $showRoad[$count]['show_y'];
|
||
$length = 5;
|
||
if(($forecast == 1 || $forecast == 2) && $end_y == 1){
|
||
$length = 6;
|
||
}
|
||
if($end_x > 6){
|
||
$start_x = $end_x - $length;
|
||
}else{
|
||
$start_x = 1;
|
||
}
|
||
foreach($showRoad as $k => $v){
|
||
if($v['show_x'] >= $start_x && $v['show_x'] <= $end_x){
|
||
$v['show_x'] = $v['show_x'] - $start_x + 1;
|
||
$showRoad[$k] = $v;
|
||
}else{
|
||
unset($showRoad[$k]);
|
||
}
|
||
}
|
||
$waybill['waybill']['showRoad'] = $showRoad;
|
||
}
|
||
|
||
|
||
// 大路
|
||
$bigRoad = $waybill['waybill']['bigRoad'];
|
||
$count = count($bigRoad)-1;
|
||
if($count >= 0){
|
||
$end_x = $bigRoad[$count]['show_x'];
|
||
$end_y = $bigRoad[$count]['show_y'];
|
||
$length = 16;
|
||
if(($forecast == 1 || $forecast == 2) && $end_y == 1){
|
||
$length = 17;
|
||
}
|
||
if($end_x > 17){
|
||
$start_x = $end_x - $length;
|
||
}else{
|
||
$start_x = 1;
|
||
}
|
||
foreach($bigRoad as $k => $v){
|
||
if($v['show_x'] >= $start_x && $v['show_x'] <= $end_x){
|
||
$v['show_x'] = $v['show_x'] - $start_x + 1;
|
||
$bigRoad[$k] = $v;
|
||
}else{
|
||
unset($bigRoad[$k]);
|
||
}
|
||
}
|
||
$waybill['waybill']['bigRoad'] = $bigRoad;
|
||
}
|
||
|
||
// 大眼路
|
||
$bigEyeRoad = $waybill['waybill']['bigEyeRoad'];
|
||
$count = count($bigEyeRoad)-1;
|
||
if($count >= 0){
|
||
$end_x = $bigEyeRoad[$count]['show_x'];
|
||
$end_y = $bigEyeRoad[$count]['show_y'];
|
||
$length = 34;
|
||
if(($forecast == 1 || $forecast == 2) && $end_y == 1){
|
||
$length = 35;
|
||
}
|
||
if($end_x > 35){
|
||
$start_x = $end_x - $length;
|
||
}else{
|
||
$start_x = 1;
|
||
}
|
||
foreach($bigEyeRoad as $k => $v){
|
||
if($v['show_x'] >= $start_x && $v['show_x'] <= $end_x){
|
||
$v['show_x'] = $v['show_x'] - $start_x + 1;
|
||
$bigEyeRoad[$k] = $v;
|
||
}else{
|
||
unset($bigEyeRoad[$k]);
|
||
}
|
||
}
|
||
$waybill['waybill']['bigEyeRoad'] = $bigEyeRoad;
|
||
}
|
||
|
||
|
||
// 小路
|
||
$pathway = $waybill['waybill']['pathway'];
|
||
$count = count($pathway)-1;
|
||
if($count >= 0){
|
||
$end_x = $pathway[$count]['show_x'];
|
||
$end_y = $pathway[$count]['show_y'];
|
||
$length = 16;
|
||
if(($forecast == 1 || $forecast == 2) && $end_y == 1){
|
||
$length = 17;
|
||
}
|
||
if($end_x > 17){
|
||
$start_x = $end_x - $length;
|
||
}else{
|
||
$start_x = 1;
|
||
}
|
||
foreach($pathway as $k => $v){
|
||
if($v['show_x'] >= $start_x && $v['show_x'] <= $end_x){
|
||
$v['show_x'] = $v['show_x'] - $start_x + 1;
|
||
$pathway[$k] = $v;
|
||
}else{
|
||
unset($pathway[$k]);
|
||
}
|
||
}
|
||
$waybill['waybill']['pathway'] = $pathway;
|
||
}
|
||
|
||
|
||
// 曱甴路
|
||
$roach = $waybill['waybill']['roach'];
|
||
$count = count($roach)-1;
|
||
if($count >= 0){
|
||
$end_x = $roach[$count]['show_x'];
|
||
$end_y = $roach[$count]['show_y'];
|
||
$length = 16;
|
||
if(($forecast == 1 || $forecast == 2) && $end_y == 1){
|
||
$length = 17;
|
||
}
|
||
if($end_x > 17){
|
||
$start_x = $end_x - $length;
|
||
}else{
|
||
$start_x = 1;
|
||
}
|
||
foreach($roach as $k => $v){
|
||
if($v['show_x'] >= $start_x && $v['show_x'] <= $end_x){
|
||
$v['show_x'] = $v['show_x'] - $start_x + 1;
|
||
$roach[$k] = $v;
|
||
}else{
|
||
unset($roach[$k]);
|
||
}
|
||
}
|
||
$waybill['waybill']['roach'] = $roach;
|
||
}
|
||
|
||
|
||
return $waybill;
|
||
}
|
||
|
||
/**
|
||
* 根据IP获取国家名称(淘宝接口)
|
||
* 并存档
|
||
*/
|
||
function getCountryByIp($ip = '') {
|
||
if ($ip == '') {
|
||
$ip = getIP();
|
||
}
|
||
$ipInfo = Db::name('ip_country')->where('ip', $ip)->find();
|
||
if ($ipInfo) {
|
||
return $ipInfo['country'];
|
||
} else {
|
||
return '未知';
|
||
/*
|
||
$api = "http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
|
||
$ret = https_request($api);
|
||
$arr = json_decode($ret,true);
|
||
if (!empty($arr)) {
|
||
$country = $arr['data']['country'];
|
||
$ipInfo['country'] = $country;
|
||
$ipInfo['ip'] = $ip;
|
||
Db::name('ip_country')->insert($ipInfo);
|
||
|
||
$city = $arr['data']['city'];
|
||
if (!is_null($city) && $city != '') {
|
||
$country = $country . "|" . $city;
|
||
}
|
||
return $country;
|
||
}
|
||
*/
|
||
}
|
||
return '无法识别';
|
||
}
|
||
function https_request($url,$data = null){
|
||
$curl = curl_init();
|
||
curl_setopt($curl,CURLOPT_URL,$url);
|
||
curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
|
||
curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
|
||
if(!empty($data)){
|
||
curl_setopt($curl,CURLOPT_POST,1);
|
||
curl_setopt($curl,CURLOPT_POSTFIELDS,$data);
|
||
}
|
||
|
||
curl_setopt($curl,CURLOPT_RETURNTRANSFER,1);
|
||
$output = curl_exec($curl);
|
||
curl_close($curl);
|
||
return $output;
|
||
}
|
||
|
||
/**
|
||
* 用户登录/退出登录记录表
|
||
* 并存档
|
||
* @param $user 用户信息
|
||
* @param $client 登录客户端信息
|
||
* @param $remark 备注
|
||
*/
|
||
function userLoginLog($user,$client,$remark){
|
||
$data = array();
|
||
$data['user_id'] = $user['id'];
|
||
$data['username'] = $user['username'];
|
||
$data['nickname'] = $user['nickname'];
|
||
$data['ip'] = getIp();
|
||
$data['ip_location'] = getCountryByIp();
|
||
$data['client'] = $client;
|
||
$data['create_time'] = time();
|
||
$data['remark'] = $remark;
|
||
Db::name('user_log')->insert($data);
|
||
}
|
||
|
||
/**
|
||
* 检测是否是手机访问
|
||
*/
|
||
function isMobile()
|
||
{
|
||
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
|
||
if (isset ($_SERVER['HTTP_X_WAP_PROFILE']))
|
||
{
|
||
return true;
|
||
}
|
||
// 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
|
||
if (isset ($_SERVER['HTTP_VIA']))
|
||
{
|
||
// 找不到为flase,否则为true
|
||
return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
|
||
}
|
||
// 脑残法,判断手机发送的客户端标志,兼容性有待提高
|
||
if (isset ($_SERVER['HTTP_USER_AGENT']))
|
||
{
|
||
$clientkeywords = array ('nokia',
|
||
'sony',
|
||
'ericsson',
|
||
'mot',
|
||
'samsung',
|
||
'htc',
|
||
'sgh',
|
||
'lg',
|
||
'sharp',
|
||
'sie-',
|
||
'philips',
|
||
'panasonic',
|
||
'alcatel',
|
||
'lenovo',
|
||
'iphone',
|
||
'ipod',
|
||
'blackberry',
|
||
'meizu',
|
||
'android',
|
||
'netfront',
|
||
'symbian',
|
||
'ucweb',
|
||
'windowsce',
|
||
'palm',
|
||
'operamini',
|
||
'operamobi',
|
||
'openwave',
|
||
'nexusone',
|
||
'cldc',
|
||
'midp',
|
||
'wap',
|
||
'mobile'
|
||
);
|
||
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
|
||
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT'])))
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
// 协议法,因为有可能不准确,放到最后判断
|
||
if (isset ($_SERVER['HTTP_ACCEPT']))
|
||
{
|
||
// 如果只支持wml并且不支持html那一定是移动设备
|
||
// 如果支持wml和html但是wml在html之前则是移动设备
|
||
if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html'))))
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
//截取字符串中的数字
|
||
|
||
function findNum($str=''){
|
||
$str=trim($str);
|
||
if(empty($str)){return '';}
|
||
$temp=array('1','2','3','4','5','6','7','8','9','0');
|
||
$result='';
|
||
for($i=0;$i<strlen($str);$i++){
|
||
if(in_array($str[$i],$temp)){
|
||
$result.=$str[$i];
|
||
}
|
||
}
|
||
return $result;
|
||
}
|
||
|
||
|
||
function JudgeCowCow($card){
|
||
if(!is_array($card) || count($card) !== 5){
|
||
return '牌数不足五张牌';
|
||
}
|
||
//获取五张牌中最大的牌
|
||
$compare = $card;
|
||
for($i=0;$i<4;$i++){
|
||
for($j=$i+1;$j<5;$j++){
|
||
if(substr($compare[$i],1,2) < substr($compare[$j],1,2)){
|
||
$a = $compare[$i];
|
||
$compare[$i] = $compare[$j];
|
||
$compare[$j]=$a;
|
||
}
|
||
}
|
||
}
|
||
$max_card = substr($compare['0'],1,2);
|
||
if(substr($max_card,0,1) == 0){
|
||
$max_card = substr($max_card,1,1);
|
||
}
|
||
$same_num = 0;
|
||
// return $max_card;
|
||
for($i=0;$i<5; $i++){
|
||
$card[$i] = substr($card[$i],1,2);
|
||
if(substr($card[$i],0,1) == 0){
|
||
$card[$i] = substr($card[$i],1,1);
|
||
}
|
||
if($card[$i] == $max_card){
|
||
$same_num++;
|
||
}
|
||
}
|
||
if($same_num == 1){
|
||
$max = $compare['0'];
|
||
}
|
||
if($same_num > 1){
|
||
$compare = array_slice($compare,0,$same_num);
|
||
for($i=0;$i<$same_num-1;$i++){//对5张牌从大到小排序。
|
||
for($j=$i+1;$j<$same_num;$j++){
|
||
if($compare[$i] > $compare[$j]){
|
||
$a = $compare[$i];
|
||
$compare[$i] = $compare[$j];
|
||
$compare[$j]=$a;
|
||
}
|
||
}
|
||
}
|
||
$max = $compare['0'];
|
||
}
|
||
$cow = -1;
|
||
//计算5张牌总值,cow计算牛几。
|
||
$cardall = 0;
|
||
$n= 0 ;//存储10、J、Q、K张数。
|
||
$king = 0;//存储J、Q、K张数。
|
||
$result = array();
|
||
//计算J、Q、K张数。
|
||
for($i=0;$i<5;$i++){
|
||
if($card[$i] >= 11){
|
||
$king++;
|
||
}
|
||
}
|
||
if($king == 5){
|
||
$cow = 11;
|
||
$word = '五公';
|
||
$result['word'] = $word;
|
||
$result['cow'] = $cow;
|
||
$result['max'] = $max;
|
||
return $result;
|
||
}
|
||
for($i=0;$i<4;$i++){//对5张牌从大到小排序。
|
||
for($j=$i+1;$j<5;$j++){
|
||
if($card[$i] < $card[$j]){
|
||
$a = $card[$i];
|
||
$card[$i] = $card[$j];
|
||
$card[$j]=$a;
|
||
}
|
||
}
|
||
}
|
||
for($i=0;$i<5;$i++){
|
||
if($card[$i] >= 10){
|
||
$n++;
|
||
$card[$i] = 10;
|
||
}
|
||
$cardall += $card[$i];
|
||
}
|
||
switch ($n){
|
||
case 0: //5张牌中没有一张10、J、Q、K。
|
||
for($i=0;$i<4;$i++){
|
||
for($j=$i + 1;$j<5;$j++){
|
||
if(($cardall - $card[$i]- $card[$j])%10==0){
|
||
$cow=($card[$i] + $card[$j])%10;
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 1: //5张牌中有一张10、J、Q、K。
|
||
//先判断是否有牛牛,不能判断剩余四张相加为10倍数为牛牛,如 Q 8 5 4 3
|
||
//只能先判断两张是否是10的倍数,如果是再判断剩余是否是10的倍数;有限判断出牛牛;再来判断三张是否有10的倍数,有的话有牛,否则无牛
|
||
for($i =1; $i < 4; $i ++){
|
||
for($j = $i +1; $j < 5; $j++){
|
||
if(($card[$i] + $card[$j]) % 10 == 0){
|
||
$cow=($cardall - $card[0])%10;
|
||
}
|
||
}
|
||
}
|
||
//判断是否有牛
|
||
for($i=1; $i<5; $i++){ //剩下四张牌有三张加起来等于10
|
||
if(($cardall - $card[0] - $card[$i])%10==0){
|
||
$cow=($cardall-$card[0])%10;
|
||
break;
|
||
}
|
||
}
|
||
break;
|
||
case 2: //5张牌中有两张10、J、Q、K。 三张是个牛就有问题,应该优先输出
|
||
if(($cardall - $card[0] - $card[1])%10 == 0){//优先牛牛输出 如 J Q 2 3 5;这里先检查剩余是否为牛牛,否则算法有漏洞
|
||
$cow = 0;
|
||
}else{
|
||
//10 10 6 5 3 n=2 i=3 j=4 cardall = 34
|
||
for($i=$n;$i<4;$i++){//剩下三(四)张牌有两张加起来等于10。
|
||
for($j=$i+1;$j<5;$j++){
|
||
if(($card[$i]+$card[$j])==10){
|
||
$temp = $cardall;
|
||
for($k=0;$k<$n;$k++){
|
||
$temp -= $card[$k]; // 18
|
||
$cow = $temp%10; //8
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|
||
break;
|
||
case 3: //5张牌中有三张10、J、Q、K。
|
||
case 4: //5张牌中有四张10、J、Q、K。
|
||
case 5: //5张牌中五张都是10、J、Q、K。
|
||
for($i=0;$i<$n;$i++){//总值减去10、J、Q、K的牌。
|
||
$cardall -= $card[$i];
|
||
}
|
||
$cow = $cardall%10;
|
||
break;
|
||
}
|
||
switch ($cow){
|
||
case 0:
|
||
$word = '牛牛';
|
||
break;
|
||
case 1:
|
||
$word = '牛一';
|
||
break;
|
||
case 2:
|
||
$word = '牛二';
|
||
break;
|
||
case 3:
|
||
$word = '牛三';
|
||
break;
|
||
case 4:
|
||
$word = '牛四';
|
||
break;
|
||
case 5:
|
||
$word = '牛五';
|
||
break;
|
||
case 6:
|
||
$word = '牛六';
|
||
break;
|
||
case 7:
|
||
$word = '牛七';
|
||
break;
|
||
case 8:
|
||
$word = '牛八';
|
||
break;
|
||
case 9:
|
||
$word = '牛九';
|
||
break;
|
||
case -1:
|
||
$word = '无牛';
|
||
break;
|
||
}
|
||
if($cow == -1){
|
||
$cow = 0;
|
||
}else if($cow == 0){
|
||
$cow = 10;
|
||
}
|
||
$result['word'] = $word;
|
||
$result['cow'] = $cow;
|
||
$result['max'] = $max;
|
||
return $result;
|
||
}
|
||
/**
|
||
* 三卡牛牛结果
|
||
* $id 位置牌
|
||
* return array
|
||
*/
|
||
function ThredCardCowCow($card){
|
||
$card_type = array();
|
||
if(!is_array($card) || count($card) !== 3){
|
||
return false;
|
||
}
|
||
//获取三张牌中最大的牌
|
||
$compare = $card;
|
||
for($i=0;$i<2;$i++){
|
||
for($j=$i+1;$j<3;$j++){
|
||
if(substr($compare[$i],1,2) < substr($compare[$j],1,2)){
|
||
$a = $compare[$i];
|
||
$compare[$i] = $compare[$j];
|
||
$compare[$j]=$a;
|
||
}
|
||
}
|
||
}
|
||
$max_card = substr($compare['0'],1,2);
|
||
|
||
if(substr($max_card,0,1) == 0){
|
||
$max_card = substr($max_card,1,1);
|
||
}
|
||
$same_num = 0;
|
||
for($i=0;$i<3; $i++){
|
||
$card_type[$i] = substr($card[$i],0,1);
|
||
$card[$i] = substr($card[$i],1,2);
|
||
if(substr($card[$i],0,1) == 0){
|
||
$card[$i] = substr($card[$i],1,1);
|
||
}
|
||
if($card[$i] == $max_card){
|
||
$same_num++;
|
||
}
|
||
}
|
||
//特殊牌型最大牌判断
|
||
$space_num = array_count_values($card);
|
||
if($same_num == 1){
|
||
$max = $compare['0'];
|
||
}
|
||
if($same_num > 1){
|
||
$compare = array_slice($compare,0,$same_num);
|
||
for($i=0;$i<$same_num-1;$i++){//对5张牌从大到小排序。
|
||
for($j=$i+1;$j<$same_num;$j++){
|
||
if($compare[$i] > $compare[$j]){
|
||
$a = $compare[$i];
|
||
$compare[$i] = $compare[$j];
|
||
$compare[$j]=$a;
|
||
}
|
||
}
|
||
}
|
||
$max = $compare['0'];
|
||
if($same_num == 2){
|
||
if($compare['0']>300 && $compare['0']<400){
|
||
$max = $compare['1'];
|
||
}
|
||
}
|
||
|
||
}
|
||
$result = array();
|
||
//豹子判断
|
||
if(count($card) != count(array_unique($card))) {
|
||
$unique_arr = array_unique($card);
|
||
if(count($unique_arr) == 1){
|
||
$cow = 11;
|
||
$word = '豹子';
|
||
if(array_key_exists(1,$space_num)){
|
||
if($space_num['1'] > 0){
|
||
if($space_num['1'] == 1){
|
||
$max = $compare[2];
|
||
}
|
||
if($space_num['1'] == 2){
|
||
if($compare[1]>300 && $compare[1]<400){
|
||
$max = $compare[2];
|
||
}else{
|
||
$max = $compare[1];
|
||
}
|
||
|
||
}
|
||
}
|
||
}
|
||
$result['word'] = $word;
|
||
$result['cow'] = $cow;
|
||
$result['max'] = $max;
|
||
return $result;
|
||
}
|
||
}
|
||
if(count(array_unique($card_type)) == 1){
|
||
//皇家同花顺
|
||
$example = array(1,12,13);
|
||
$diff_result=array_diff($card,$example);
|
||
if(count($diff_result) == 0){
|
||
$cow = 13;
|
||
$word = '皇家同花顺';
|
||
if($space_num[1] == 1){
|
||
$max = $compare[2];
|
||
}
|
||
$result['word'] = $word;
|
||
$result['cow'] = $cow;
|
||
$result['max'] = $max;
|
||
return $result;
|
||
}
|
||
//同花顺
|
||
if(count($card) == count(array_unique($card))) {
|
||
$max=$min=-1;
|
||
for ($i=0; $i < 3; $i++) {
|
||
if($card[$i] > $max || $max == -1){
|
||
$max = $card[$i];
|
||
}
|
||
if($card[$i] < $min || $min == -1){
|
||
$min = $card[$i];
|
||
}
|
||
if($max - $min == 2){
|
||
$cow = 12;
|
||
$word = '同花顺';
|
||
if($space_num[1] == 1){
|
||
$max = $compare[2];
|
||
}
|
||
$result['word'] = $word;
|
||
$result['cow'] = $cow;
|
||
$result['max'] = $max;
|
||
return $result;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
if($card[0]>10)$card[0]=10;
|
||
if($card[1]>10)$card[1]=10;
|
||
if($card[2]>10)$card[2]=10;
|
||
$sum_num = $card[0] + $card[1] + $card[2];
|
||
if($sum_num < 10){
|
||
$cow = $sum_num;
|
||
}else{
|
||
$cow = $sum_num%10;
|
||
}
|
||
switch ($cow){
|
||
case 0:
|
||
$word = '牛牛';
|
||
break;
|
||
case 1:
|
||
$word = '牛一';
|
||
break;
|
||
case 2:
|
||
$word = '牛二';
|
||
break;
|
||
case 3:
|
||
$word = '牛三';
|
||
break;
|
||
case 4:
|
||
$word = '牛四';
|
||
break;
|
||
case 5:
|
||
$word = '牛五';
|
||
break;
|
||
case 6:
|
||
$word = '牛六';
|
||
break;
|
||
case 7:
|
||
$word = '牛七';
|
||
break;
|
||
case 8:
|
||
$word = '牛八';
|
||
break;
|
||
case 9:
|
||
$word = '牛九';
|
||
break;
|
||
}
|
||
if($cow == 0){
|
||
$cow = 10;
|
||
}
|
||
$result['word'] = $word;
|
||
$result['cow'] = $cow;
|
||
$result['max'] = $max;
|
||
return $result;
|
||
}
|
||
|
||
|
||
/**
|
||
* 卡牌编号转换数字
|
||
* $id 卡牌编号
|
||
* return 一个数字
|
||
*/
|
||
function interchange_card($id){
|
||
if($id == 101 || $id == 201 || $id == 301 || $id == 401){
|
||
return 1;
|
||
}
|
||
if($id == 102 || $id == 202 || $id == 302 || $id == 402){
|
||
return 2;
|
||
}
|
||
if($id == 103 || $id == 203 || $id == 303 || $id == 403){
|
||
return 3;
|
||
}
|
||
if($id == 104 || $id == 204 || $id == 304 || $id == 404){
|
||
return 4;
|
||
}
|
||
if($id == 105 || $id == 205 || $id == 305 || $id == 405){
|
||
return 5;
|
||
}
|
||
if($id == 106 || $id == 206 || $id == 306 || $id == 406){
|
||
return 6;
|
||
}
|
||
if($id == 107 || $id == 207 || $id == 307 || $id == 407){
|
||
return 7;
|
||
}
|
||
if($id == 108 || $id == 208 || $id == 308 || $id == 408){
|
||
return 8;
|
||
}
|
||
if($id == 109 || $id == 209 || $id == 309 || $id == 409){
|
||
return 9;
|
||
}
|
||
if($id == 110 || $id == 210 || $id == 310 || $id == 410){
|
||
return 10;
|
||
}
|
||
if($id == 111 || $id == 211 || $id == 311 || $id == 411){
|
||
return 11;
|
||
}
|
||
if($id == 112 || $id == 212 || $id == 312 || $id == 412){
|
||
return 12;
|
||
}
|
||
if($id == 113 || $id == 213 || $id == 313 || $id == 413){
|
||
return 13;
|
||
}
|
||
|
||
return false;
|
||
}
|
||
//获取牛牛结果
|
||
function interchange_nn($id,$lang=[]){
|
||
if($id == 0){
|
||
return empty($lang) ? '无牛' : $lang['bull_0'];
|
||
}
|
||
if($id == 1){
|
||
return empty($lang) ? '牛一' : $lang['bull_1'];
|
||
}
|
||
if($id == 2){
|
||
return empty($lang) ? '牛二' : $lang['bull_2'];
|
||
}
|
||
if($id == 3){
|
||
return empty($lang) ? '牛三' : $lang['bull_3'];
|
||
}
|
||
if($id == 4){
|
||
return empty($lang) ? '牛四' : $lang['bull_4'];
|
||
}
|
||
if($id == 5){
|
||
return empty($lang) ? '牛五' : $lang['bull_5'];
|
||
}
|
||
if($id == 6){
|
||
return empty($lang) ? '牛六' : $lang['bull_6'];
|
||
}
|
||
if($id == 7){
|
||
return empty($lang) ? '牛七' : $lang['bull_7'];
|
||
}
|
||
if($id == 8){
|
||
return empty($lang) ? '牛八' : $lang['bull_8'];
|
||
}
|
||
if($id == 9){
|
||
return empty($lang) ? '牛九' : $lang['bull_9'];
|
||
}
|
||
if($id == 10){
|
||
return empty($lang) ? '牛牛' : $lang['bull_bull'];
|
||
}
|
||
if($id == 11){
|
||
return empty($lang) ? '五公' : $lang['5_bulls'];
|
||
}
|
||
|
||
return false;
|
||
}
|
||
|
||
/**
|
||
* 随机生成推荐码
|
||
* @return string
|
||
* DateTime: 2019/12/24 14:59
|
||
*/
|
||
function getRandCode(){
|
||
do{
|
||
$str = str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWSYZ');
|
||
$begin=substr($str, 0,2);
|
||
$referral_code = $begin.rand(100000,999999);
|
||
}while(Db::name('user')->where(['referral_code'=>$referral_code])->find());
|
||
return $referral_code;
|
||
}
|
||
|
||
function object_to_array($obj) {
|
||
$obj = (array)$obj;
|
||
foreach ($obj as $k => $v) {
|
||
if (gettype($v) == 'resource') {
|
||
return;
|
||
}
|
||
if (gettype($v) == 'object' || gettype($v) == 'array') {
|
||
$obj[$k] = (array)object_to_array($v);
|
||
}
|
||
}
|
||
return $obj;
|
||
}
|
||
|
||
|
||
/**
|
||
* GET 请求
|
||
* @param $url
|
||
* @param array $headers
|
||
* @return mixed
|
||
*/
|
||
function httpGet($url, $headers=[])
|
||
{
|
||
$oCurl = curl_init();
|
||
if (stripos($url, "https://") !== FALSE) {
|
||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYPEER, FALSE);
|
||
curl_setopt($oCurl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
||
curl_setopt($oCurl, CURLOPT_SSLVERSION, 1); //CURL_SSLVERSION_TLSv1
|
||
}
|
||
if(!empty($headers)){
|
||
curl_setopt($oCurl, CURLOPT_HTTPHEADER, $headers);
|
||
}
|
||
curl_setopt($oCurl, CURLOPT_ENCODING, '');
|
||
curl_setopt($oCurl, CURLOPT_URL, $url);
|
||
curl_setopt($oCurl, CURLOPT_RETURNTRANSFER, 1);
|
||
$sContent = curl_exec($oCurl);
|
||
$aStatus = curl_getinfo($oCurl);
|
||
curl_close($oCurl);
|
||
return json_decode($sContent, true);
|
||
|
||
}
|
||
|
||
/**
|
||
* POST 请求
|
||
* @param $url
|
||
* @param $data
|
||
* @param array $headers
|
||
* @return mixed
|
||
*/
|
||
function httpPost($url, $data, $headers=[])
|
||
{
|
||
$ch = curl_init();
|
||
curl_setopt($ch, CURLOPT_URL, $url);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
|
||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||
curl_setopt($ch, CURLOPT_POST, 1);
|
||
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
||
if(!empty($headers)){
|
||
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
||
}
|
||
$result = curl_exec($ch);
|
||
$aStatus = curl_getinfo($ch);
|
||
curl_close($ch);
|
||
return json_decode($result, true);
|
||
}
|
||
|
||
/**
|
||
* 生成订单号
|
||
* @param string $prefix
|
||
* @return string
|
||
*/
|
||
function createOrderNo($prefix="TNT")
|
||
{
|
||
$orderNo = $prefix.date('YmdHis').mt_rand(100000,999999).substr(microtime(true),-1,4);
|
||
return $orderNo;
|
||
}
|
||
|
||
// 获取redis下百家乐与龙虎的卡牌数据
|
||
function getRedisCardByPosition($numberTabId){
|
||
$card11 = Cache::store('redis')->get('card_'.$numberTabId.'_11');
|
||
$card12 = Cache::store('redis')->get('card_'.$numberTabId.'_12');
|
||
$card13 = Cache::store('redis')->get('card_'.$numberTabId.'_13');
|
||
$card21 = Cache::store('redis')->get('card_'.$numberTabId.'_21');
|
||
$card22 = Cache::store('redis')->get('card_'.$numberTabId.'_22');
|
||
$card23 = Cache::store('redis')->get('card_'.$numberTabId.'_23');
|
||
$cardInfoRedis = [];
|
||
$cardInfoRedis['player_1'] = $card11 ? $card11 : 0;
|
||
$cardInfoRedis['player_2'] = $card12 ? $card12 : 0;
|
||
$cardInfoRedis['player_3'] = $card13 ? $card13 : 0;
|
||
$cardInfoRedis['banker_1'] = $card21 ? $card21 : 0;
|
||
$cardInfoRedis['banker_2'] = $card22 ? $card22 : 0;
|
||
$cardInfoRedis['banker_3'] = $card23 ? $card23 : 0;
|
||
return $cardInfoRedis;
|
||
}
|
||
|
||
// 获取redis下百家乐与龙虎的卡牌数据
|
||
function getRedisCard($numberTabId){
|
||
$cardInfo = Cache::store('redis')->get('card_'.$numberTabId);
|
||
$cardInfo = unserialize($cardInfo);
|
||
return json_decode($cardInfo, true);
|
||
}
|
||
|
||
// 字符串结果转数组
|
||
function result_to_array($resultString){
|
||
if (empty($resultString)){
|
||
return [];
|
||
}
|
||
$array = explode(",", $resultString);
|
||
$returnArray = [];
|
||
foreach ($array as $v){
|
||
$item = explode(":", $v);
|
||
$returnArray[$item[0]] = $item[1];
|
||
}
|
||
return $returnArray;
|
||
}
|
||
// 字符串结果转数组(色碟结果统计)
|
||
function toning_count_to_array($countString){
|
||
if (empty($countString)){
|
||
return [
|
||
'zero_count' => 0,
|
||
'one_count' => 0,
|
||
'two_count' => 0,
|
||
'three_count' => 0,
|
||
'four_count' => 0,
|
||
'big_count' => 0,
|
||
'small_count' => 0,
|
||
'singular_count' => 0,
|
||
'plural_count' => 0
|
||
];
|
||
}
|
||
$array = explode(",", $countString);
|
||
$returnArray = [];
|
||
foreach ($array as $v){
|
||
$item = explode(":", $v);
|
||
$returnArray[$item[0]] = $item[1];
|
||
}
|
||
return $returnArray;
|
||
}
|
||
// 色碟统计转数组
|
||
function tonging_count_to_array($toningCountString)
|
||
{
|
||
if (empty($toningCountString)){
|
||
return [
|
||
'zero_count' => 0,
|
||
'one_count' => 0,
|
||
'two_count' => 0,
|
||
'three_count' => 0,
|
||
'four_count' => 0,
|
||
'big_count' => 0,
|
||
'small_count' => 0,
|
||
'singular_count' => 0,
|
||
'plural_count' => 0
|
||
];
|
||
} else {
|
||
return result_to_array($toningCountString);
|
||
}
|
||
}
|
||
// 骰宝统计转数组
|
||
function dice_count_to_array($diceCountString)
|
||
{
|
||
if (empty($diceCountString)){
|
||
return [
|
||
'leopard_count' => 0,
|
||
'small_count' => 0,
|
||
'big_count' => 0,
|
||
'singular_count' => 0,
|
||
'plural_count' => 0
|
||
];
|
||
} else {
|
||
$returnData = [];
|
||
$arr = result_to_array($diceCountString);
|
||
foreach ($arr as $key => $value){
|
||
$returnData[$key.'_count'] = $value;
|
||
}
|
||
unset($arr);
|
||
return $returnData;
|
||
}
|
||
}
|
||
// 添加日志到文件
|
||
function addLogToFile($content,$fileName="log",$dir='log')
|
||
{
|
||
// 目录
|
||
$dirPath = LOG_PATH . $dir;
|
||
if(!is_dir($dirPath)){
|
||
mkdir($dirPath,0755);
|
||
}
|
||
|
||
// 文件
|
||
$filePath = $dirPath . '/' . $fileName.'_'.date('Ymd').'.log';
|
||
$content = '['.date('Y-m-d H:i:s').'] '.$content. " \n";
|
||
file_put_contents($filePath,$content,FILE_APPEND);
|
||
|
||
return true;
|
||
}
|
||
|
||
function roulette_count_to_array($rouletteCountString)
|
||
{
|
||
if (empty($rouletteCountString)) {
|
||
return [
|
||
'low_count' => 0,
|
||
'high_count' => 0,
|
||
'even_count' => 0,
|
||
'odd_count' => 0,
|
||
'red_count' => 0,
|
||
'black_count' => 0,
|
||
'zero_count' => 0,
|
||
];
|
||
} else {
|
||
$returnData = [];
|
||
$arr = result_to_array($rouletteCountString);
|
||
foreach ($arr as $key => $value) {
|
||
$returnData[$key . '_count'] = $value;
|
||
}
|
||
unset($arr);
|
||
return $returnData;
|
||
}
|
||
} |