Pro/application/console/controller/Tc.php
2026-02-25 01:50:31 +08:00

298 lines
8.4 KiB
PHP

<?php
namespace app\console\controller;
use think\Controller;
use think\Session;
use think\Request;
use think\Db;
use waybill\WayBill;
use think\Lang;
class Tc Extends Common{
public function create_online_token($user){
$ip = getIP();
$time = time();
return md5($ip.$time.$user['encrypt'].$user['password']);
}
public function index(){
$user_info = Session::get('user_info');
$user = Db::name('user_controller')->where(array('id' => $user_info['id']))->find();
if(!$user) exit(Lang::get('userNotExit'));
$online_token = $this->create_online_token($user);
$r = Db::name('user_controller')->where(array('id' => $user_info['id']))->update(array('login_token' => $online_token));
$table = Db::name('table')->where(array('id' => $user_info['table_id']))->find();
$memo = Db::name('memo')->where('table_id',$table['id'])->where('position',['=',2],['=',3],'or')->where('status',1)->order('id desc')->limit(1)->find();
if($table['scene_limit_money']){
$scene_limit_money = explode('-', $table['scene_limit_money']);
}else{
$scene_limit_money = array(0,0);
}
// 获取语言包信息
$langType = cookie('think_var');
$lang = Lang::get();
$lang = json_encode($lang);
// 渲染参数和模板
$this->assign('scene_limit_money',$scene_limit_money);
$this->assign('memo',$memo);
$this->assign('connections_url','connections_'.$table['port']);
$this->assign('online_token',$online_token);
$this->assign('table',$table);
$this->assign('user',$user);
$this->assign('websocketUrl',$table['ws_local_url']);
$this->assign('langType',$langType);
$this->assign('lang',$lang);
if($table['is_scavenging'] == 1){
return $this->fetch('/tc/index');
}else{
return $this->fetch('/tc/index');
}
}
//获取当前靴的结果汇总
public function get_result_total(){
if(Request::instance()->isPost()){
//获取路单对象
$table_id = Request::instance()->post('table_id');
$boot_id = Request::instance()->post('boot_id');
// $game_id = Db::name('table')->where(array('id' => $table_id))->value('game_id');
$banker_total = 0;
$player_total = 0;
$result = array();
$all_result = Db::name('number_tab_nn')->where(array('boot_id' => $boot_id,'bet_status'=>3))->select();
foreach($all_result as $k => $v){
if($v['win_player_1'] == 1){
$player_total++;
}elseif($v['win_player_1'] == 0){
$banker_total++;
}
if($v['win_player_2'] == 1){
$player_total++;
}elseif($v['win_player_2'] == 0){
$banker_total++;
}
if($v['win_player_3'] == 1){
$player_total++;
}elseif($v['win_player_3'] == 0){
$banker_total++;
}
}
$result['banker'] = $banker_total;
$result['player'] = $player_total;
return json(['code'=>1,'data'=>$result]);
}
}
// 路单接口调用
public function waybill(){
if(Request::instance()->post()){
// 接收游戏ID和靴ID
$game_id = Request::instance()->post('game_id');
$boot_id = Request::instance()->post('boot_id');
//验证游戏ID
if($game_id == 4 || $game_id == 5){
$numberTabTable = 'number_tab_tc';
}else{
die(json_encode(['status'=>false,'msg'=>'游戏ID错误']));
}
// 验证靴ID
if($boot_id > 0){
$ns = Db::name($numberTabTable)->where(array('boot_id' => $boot_id, 'bet_status' => 3))->field('result_banker,result_player_1,result_player_2,result_player_3,win_player_1,win_player_2,win_player_3')->order('start_time ASC,id ASC')->select();
// 数据存在,输出路单
if($ns){
// die(json_encode($ns));
$result = nn_waybill($ns);
die(json_encode($result));
}else{
$waybill = array();
die(json_encode(['status'=>false,'msg'=>'数据不存在','waybill'=>$waybill]));
}
}else{
die(json_encode(['status'=>false,'msg'=>'靴ID错误']));
}
}else{
die(json_encode(['status'=>false,'msg'=>'操作错误']));
}
}
//获取点数
public function get_nn_num(){
if(Request::instance()->post()){
$result_arr = Request::instance()->post('result_json');
$result = JudgeCowCow(json_decode($result_arr,true));
die(json_encode(['status'=>true,'msg'=>$result['word']]));
}else{
die(json_encode(['status'=>false,'msg'=>'操作错误']));
}
}
public function ThredCardCowCow(){
$card = array('112','201','301');
$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];
}
}
}
}
array_push($result,$word,$cow,$max);
return json($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];
}
return $max;
array_push($result,$word,$cow,$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];
}
array_push($result,$word,$cow,$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;
}
}