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

130 lines
4.1 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 Nn 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('/nn/index');
}else{
return $this->fetch('/nn/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){
$numberTabTable = 'number_tab_nn';
}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'=>'操作错误']));
}
}
}