783 lines
39 KiB
PHP
783 lines
39 KiB
PHP
<?php
|
|
namespace app\admin\controller;
|
|
use think\Request;
|
|
use think\Db;
|
|
use think\Session;
|
|
use think\Cache;
|
|
|
|
class Waybill extends Common
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
/**
|
|
* 百家乐路单展示页面
|
|
*/
|
|
public function baccarat()
|
|
{
|
|
// 查询百家乐桌子信息
|
|
$table_list = Db::name('table')->where(array('game_id' => 1, 'is_scavenging' => 0))->select();
|
|
$table_id_arr = Db::name('table')->where(array('game_id' => 1, 'is_scavenging' => 0))->column('id');
|
|
// 定义只能查询前7个记账日期
|
|
$date = get_weeks();
|
|
|
|
// 接收分页的数据
|
|
$get = Request::instance()->get();
|
|
$query = http_build_query($get);
|
|
$this->assign('get', $get);
|
|
$this->assign('query', $query);
|
|
|
|
// 接收查询条件
|
|
$table_id = Request::instance()->get('search_table_id');
|
|
$boot_id = Request::instance()->get('search_boot_id');
|
|
$number_id = Request::instance()->get('search_number_id');
|
|
$startTime = strtotime(Request::instance()->get('startDate'));
|
|
$endTime = strtotime(Request::instance()->get('endDate'));
|
|
|
|
// 定义查询条件
|
|
$where = array();
|
|
if ($table_id > 0) {
|
|
$where['table_id'] = $table_id;
|
|
}
|
|
if ($boot_id > 0) {
|
|
$where['boot_id'] = $boot_id;
|
|
}
|
|
if ($number_id > 0) {
|
|
$where['id'] = $number_id;
|
|
}
|
|
if ($startTime > 0 && $endTime > 0){
|
|
$where['start_time'] = array('between',[$startTime,$endTime]);
|
|
}
|
|
$where['bet_status'] = 3; // 已开出结果的铺
|
|
if($table_id > 0){
|
|
$number_tab_list = Db::name('number_tab')->where($where)->order('start_time desc,id desc')->paginate(15, false, array('query' => $get));
|
|
}else{
|
|
$number_tab_list = Db::name('number_tab')->where($where)->whereIn('table_id',$table_id_arr)->order('start_time desc,id desc')->paginate(15, false, array('query' => $get));
|
|
}
|
|
|
|
// 重新组装数据
|
|
foreach ($number_tab_list as $k => $v) {
|
|
$v['start_time'] = date('Y-m-d H:i:s', $v['start_time']);
|
|
if ($v['result'] == 1) $v['result'] = "庄";
|
|
if ($v['result'] == 2) $v['result'] = "闲";
|
|
if ($v['result'] == 3) $v['result'] = "和";
|
|
if ($v['pair'] == 0) $v['pair'] = null;
|
|
if ($v['pair'] == 1) $v['pair'] = "庄对";
|
|
if ($v['pair'] == 2) $v['pair'] = "闲对";
|
|
if ($v['pair'] == 3) $v['pair'] = "庄闲对";
|
|
$number_tab_list[$k] = $v;
|
|
}
|
|
|
|
// 渲染参数和模板
|
|
$this->assign('number_tab_list', $number_tab_list);
|
|
$this->assign('table_list', $table_list);
|
|
$this->assign('date', $date);
|
|
return $this->fetch();
|
|
}
|
|
|
|
/**
|
|
* 龙虎斗路单展示页面
|
|
*/
|
|
public function dt()
|
|
{
|
|
// 查询百家乐桌子信息
|
|
$table_list = Db::name('table')->where(array('game_id' => 2, 'is_scavenging' => 0))->select();
|
|
$table_id_arr = Db::name('table')->where(array('game_id' => 2, 'is_scavenging' => 0))->column('id');
|
|
|
|
// 定义只能查询前7个记账日期
|
|
$date = get_weeks();
|
|
|
|
// 接收分页的数据
|
|
$get = Request::instance()->get();
|
|
$query = http_build_query($get);
|
|
$this->assign('get', $get);
|
|
$this->assign('query', $query);
|
|
|
|
// 接收查询条件
|
|
$table_id = Request::instance()->get('search_table_id');
|
|
$boot_id = Request::instance()->get('search_boot_id');
|
|
$number_id = Request::instance()->get('search_number_id');
|
|
$startTime = strtotime(Request::instance()->get('startDate'));
|
|
$endTime = strtotime(Request::instance()->get('endDate'));
|
|
|
|
// 定义查询条件
|
|
$where = array();
|
|
if ($table_id > 0) {
|
|
$where['table_id'] = $table_id;
|
|
}
|
|
if ($boot_id > 0) {
|
|
$where['boot_id'] = $boot_id;
|
|
}
|
|
if ($number_id > 0) {
|
|
$where['id'] = $number_id;
|
|
}
|
|
if ($startTime > 0 && $endTime > 0){
|
|
$where['start_time'] = array('between',[$startTime,$endTime]);
|
|
}
|
|
$where['bet_status'] = 3;
|
|
if($table_id > 0){
|
|
$number_tab_list = Db::name('number_tab')->where($where)->order('start_time desc,id desc')->paginate(15, false, array('query' => $get));
|
|
}else{
|
|
$number_tab_list = Db::name('number_tab')->where($where)->whereIn('table_id',$table_id_arr)->order('start_time desc,id desc')->paginate(15, false, array('query' => $get));
|
|
}
|
|
|
|
foreach ($number_tab_list as $k => $v) {
|
|
$v['start_time'] = date('Y-m-d H:i:s', $v['start_time']);
|
|
if ($v['result'] == 1) $v['result'] = "龙";
|
|
if ($v['result'] == 2) $v['result'] = "虎";
|
|
if ($v['result'] == 3) $v['result'] = "和";
|
|
$number_tab_list[$k] = $v;
|
|
}
|
|
|
|
// 渲染参和模板
|
|
$this->assign('number_tab_list', $number_tab_list);
|
|
$this->assign('table_list', $table_list);
|
|
$this->assign('date', $date);
|
|
return $this->fetch();
|
|
}
|
|
|
|
public function add_number_tab(){
|
|
if(Request::instance()->post()){
|
|
$post = Request::instance()->post();
|
|
$game_id = intval(Request::instance()->post('game_id'));
|
|
$table_id = intval(Request::instance()->post('table_id'));
|
|
$boot_id = intval(Request::instance()->post('boot_id'));
|
|
$number_tab_id = intval(Request::instance()->post('number_tab_id'));
|
|
$result = trim(Request::instance()->post('result'));
|
|
if($game_id > 0 && $table_id > 0 && $boot_id > 0 && $number_tab_id){
|
|
$table = Db::name('table')->where(array('id' => $table_id))->find();
|
|
$resultArray = explode('-',$result);
|
|
if(intval($resultArray[0]) != 1 && intval($resultArray[0]) != 2 && intval($resultArray[0]) != 3){
|
|
return json(array('code' => 0, 'msg' => '请选择结果,然后再提交'));
|
|
}
|
|
if($table['game_id'] == 1){
|
|
$number_tab_info = Db::name('number_tab')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'id' => $number_tab_id))->find();
|
|
if(empty($number_tab_info)){
|
|
return json(array('code' => 0, 'msg' => '当前铺数据不存在'));
|
|
}
|
|
$insertData = array();
|
|
$insertData['game_id'] = $game_id;
|
|
$insertData['game_name'] = $number_tab_info['game_name'];
|
|
$insertData['table_id'] = $table_id;
|
|
$insertData['table_name'] = $number_tab_info['table_name'];
|
|
$insertData['sumday_id'] = $number_tab_info['sumday_id'];
|
|
$insertData['day'] = $number_tab_info['day'];
|
|
$insertData['boot_id'] = $boot_id;
|
|
$insertData['boot_num'] = $number_tab_info['boot_num'];
|
|
$insertData['number'] = intval($number_tab_info['number']) + 1;
|
|
$insertData['result'] = intval($resultArray[0]);
|
|
$insertData['pair'] = intval($resultArray[1]);
|
|
$insertData['start_time'] = $number_tab_info['start_time'];
|
|
$insertData['end_time'] = $number_tab_info['end_time'];
|
|
$insertData['bet_status'] = 3;
|
|
$insertData['bet_start_time'] = $number_tab_info['bet_start_time'];
|
|
$insertData['bet_end_time'] = $number_tab_info['bet_end_time'];
|
|
if($table['mode'] == 2){
|
|
$insertData['win6'] = intval($resultArray[2]);
|
|
}
|
|
$insertData['is_add'] = 1;
|
|
Db::execute("update `cg_number_tab` set `number` = `number` + 1 where `game_id` = ".$game_id." and `table_id` = ".$table_id." and `boot_id` = ".$boot_id." and `number` > ".intval($number_tab_info['number']));
|
|
Db::name('number_tab')->insert($insertData);
|
|
return json(array('code' => 1, 'msg' => '修改成功'));
|
|
}elseif($table['game_id'] == 2){
|
|
$number_tab_info = Db::name('number_tab')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'id' => $number_tab_id))->find();
|
|
if(empty($number_tab_info)){
|
|
return json(array('code' => 0, 'msg' => '当前铺数据不存在'));
|
|
}
|
|
$insertData = array();
|
|
$insertData['game_id'] = $game_id;
|
|
$insertData['game_name'] = $number_tab_info['game_name'];
|
|
$insertData['table_id'] = $table_id;
|
|
$insertData['table_name'] = $number_tab_info['table_name'];
|
|
$insertData['sumday_id'] = $number_tab_info['sumday_id'];
|
|
$insertData['day'] = $number_tab_info['day'];
|
|
$insertData['boot_id'] = $boot_id;
|
|
$insertData['boot_num'] = $number_tab_info['boot_num'];
|
|
$insertData['number'] = intval($number_tab_info['number']) + 1;
|
|
$insertData['result'] = intval($resultArray[0]);
|
|
$insertData['start_time'] = $number_tab_info['start_time'];
|
|
$insertData['end_time'] = $number_tab_info['end_time'];
|
|
$insertData['bet_status'] = 3;
|
|
$insertData['bet_start_time'] = $number_tab_info['bet_start_time'];
|
|
$insertData['bet_end_time'] = $number_tab_info['bet_end_time'];
|
|
$insertData['is_add'] = 1;
|
|
Db::execute("update `cg_number_tab` set `number` = `number` + 1 where `game_id` = ".$game_id." and `table_id` = ".$table_id." and `boot_id` = ".$boot_id." and `number` > ".intval($number_tab_info['number']));
|
|
Db::name('number_tab')->insert($insertData);
|
|
return json(array('code' => 1, 'msg' => '修改成功'));
|
|
}
|
|
}else{
|
|
return json(array('code' => 0, 'msg' => '数据出错,不能修改,请稍后再试'));
|
|
}
|
|
}else{
|
|
die('ERROR');
|
|
}
|
|
}
|
|
|
|
public function edit_number_tab(){
|
|
if(Request::instance()->post()){
|
|
$post = Request::instance()->post();
|
|
$game_id = intval(Request::instance()->post('game_id'));
|
|
$table_id = intval(Request::instance()->post('table_id'));
|
|
$boot_id = intval(Request::instance()->post('boot_id'));
|
|
$number_tab_id = intval(Request::instance()->post('number_tab_id'));
|
|
$result = trim(Request::instance()->post('result'));
|
|
if($game_id > 0 && $table_id > 0 && $boot_id > 0 && $number_tab_id){
|
|
$table = Db::name('table')->where(array('id' => $table_id))->find();
|
|
$resultArray = explode('-',$result);
|
|
if($table['game_id'] == 1){
|
|
$number_tab_info = Db::name('number_tab')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'id' => $number_tab_id))->find();
|
|
if(empty($number_tab_info)){
|
|
return json(array('code' => 0, 'msg' => '数据出错,不能修改,请稍后再试'));
|
|
}
|
|
if($table['mode'] == 2){
|
|
$resultData = array();
|
|
$resultData['opening'] = intval($resultArray[0]);
|
|
$resultData['pair'] = intval($resultArray[1]);
|
|
$resultData['win6'] = intval($resultArray[2]);
|
|
if($resultData['opening'] > 0 && $resultData['opening'] < 4){
|
|
$returnInfo = $this->retreated_baccarat_win6($game_id,$table_id,$boot_id,$number_tab_id,$resultData,$number_tab_info);
|
|
return json($returnInfo);
|
|
}else{
|
|
return json(array('code' => 0, 'msg' => '请选择结果,然后再提交'));
|
|
}
|
|
}else{
|
|
$resultData = array();
|
|
$resultData['opening'] = intval($resultArray[0]);
|
|
$resultData['pair'] = intval($resultArray[1]);
|
|
if($resultData['opening'] > 0 && $resultData['opening'] < 4){
|
|
$returnInfo = $this->retreated_baccarat($game_id,$table_id,$boot_id,$number_tab_id,$resultData,$number_tab_info);
|
|
return json($returnInfo);
|
|
}else{
|
|
return json(array('code' => 0, 'msg' => '请选择结果,然后再提交'));
|
|
}
|
|
}
|
|
}elseif($table['game_id'] == 2){
|
|
$number_tab_info = Db::name('number_tab')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'id' => $number_tab_id))->find();
|
|
if(empty($number_tab_info)){
|
|
return json(array('code' => 0, 'msg' => '数据出错,不能修改,请稍后再试'));
|
|
}
|
|
$resultData = array();
|
|
$resultData['opening'] = intval($resultArray[0]);
|
|
if($resultData['opening'] > 0 && $resultData['opening'] < 4){
|
|
$returnInfo = $this->retreated_dt($game_id,$table_id,$boot_id,$number_tab_id,$resultData,$number_tab_info);
|
|
return json($returnInfo);
|
|
}else{
|
|
return json(array('code' => 0, 'msg' => '请选择结果,然后再提交'));
|
|
}
|
|
}
|
|
}else{
|
|
return json(array('code' => 0, 'msg' => '数据出错,不能修改,请稍后再试'));
|
|
}
|
|
}else{
|
|
die('ERROR');
|
|
}
|
|
}
|
|
/**
|
|
* 处理龙虎回档
|
|
* $table_info 桌子的数据
|
|
* $data 当前回合数据
|
|
* $serv swoole对象
|
|
* $connections 链接ID
|
|
*/
|
|
function retreated_dt($game_id,$table_id,$boot_id,$number_tab_id,$resultData,$number_tab_info){
|
|
$lastNumberTabInfo = $number_tab_info;
|
|
$table_info = Db::name('table')->where('id',$table_id)->find();
|
|
//首先更新会员账户余额,减去相应的投注额
|
|
$bets = Db::name('bet')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id'], 'status' => 1))->select();
|
|
$oBets = $bets;
|
|
foreach($bets AS $key => $value){
|
|
$bet_win_total = $value['win_total'];
|
|
Db::execute("update `cg_user` set `money` = `money` - ".$bet_win_total." where `id`=".$value['user_id']);
|
|
}
|
|
//删除上一铺下注、洗码、分成
|
|
Db::name('bet')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('xima')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('cs')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('agent_commission')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
$opening = $resultData['opening'];
|
|
Db::name('number_tab')->where(array('id' => $lastNumberTabInfo['id']))->update(array('result' => $opening));
|
|
//记录修改日志
|
|
$retreated_log_data = array();
|
|
$retreated_log_data['mode'] = 1;
|
|
$retreated_log_data['type'] = 1;
|
|
$retreated_log_data['create_time'] = time();
|
|
$retreated_log_data['gamei_id'] = $game_id;
|
|
$retreated_log_data['table_id'] = $table_id;
|
|
$retreated_log_data['table_name'] = $lastNumberTabInfo['table_name'];
|
|
$retreated_log_data['boot_id'] = $boot_id;
|
|
$retreated_log_data['boot_num'] = $lastNumberTabInfo['boot_num'];
|
|
$retreated_log_data['number_tab_id'] = $number_tab_id;
|
|
$retreated_log_data['number'] = $lastNumberTabInfo['number'];
|
|
$str = '';
|
|
if($lastNumberTabInfo['result'] == 1) $str = '龙';
|
|
if($lastNumberTabInfo['result'] == 2) $str = '虎';
|
|
if($lastNumberTabInfo['result'] == 3) $str = '和';
|
|
$nstr = '';
|
|
if($opening == 1) $nstr = '龙';
|
|
if($opening == 2) $nstr = '虎';
|
|
if($opening == 3) $nstr = '和';
|
|
$retreated_log_data['remark'] = '该口原本结果为:'.$str.',更改为:'.$nstr;
|
|
Db::name('retreated_log')->insert($retreated_log_data);
|
|
if(!empty($oBets)){
|
|
foreach($oBets AS $k => $v){
|
|
$user_info = Db::name('user')->where(array('id' => intval($v['user_id'])))->find();
|
|
$agent_commission = $user_info['agent_commission_dt'] / 100;
|
|
if($user_info){
|
|
$amount = 0;
|
|
$amount = $v['banker_amount'] + $v['player_amount'] + $v['tie_amount'];
|
|
$win_money = 0;
|
|
// 双边洗码
|
|
$ximaliang = 0;
|
|
if($user_info['type_xima'] == 1){
|
|
$ximaliang = $v['banker_amount'] - $v['player_amount'];
|
|
$ximaliang = abs($ximaliang);
|
|
}
|
|
// 龙赢
|
|
if ($opening == 1) {
|
|
if($v['banker_amount'] > 0){
|
|
$win_money = round($v['banker_amount'] * (1 + $user_info['price_dragon']),2) + $win_money;
|
|
}
|
|
// 单边洗码
|
|
if($user_info['type_xima'] == 2){
|
|
$ximaliang = $v['player_amount'];
|
|
}
|
|
}
|
|
// 虎赢
|
|
if ($opening == 2) {
|
|
if($v['player_amount'] > 0){
|
|
$win_money = round($v['player_amount'] * (1 + $user_info['price_tiger']),2) + $win_money;
|
|
}
|
|
// 单边洗码
|
|
if($user_info['type_xima'] == 2){
|
|
$ximaliang = $v['banker_amount'];
|
|
}
|
|
}
|
|
// 和
|
|
if ($opening == 3) {
|
|
if(DT_HALF == 1){
|
|
$win_money = round(($v['banker_amount'] + $v['player_amount']) / 2,2) + $win_money;
|
|
}else{
|
|
$win_money = $v['banker_amount'] + $v['player_amount'] + $win_money;
|
|
}
|
|
$ximaliang = 0;
|
|
if($v['tie_amount'] > 0){
|
|
$win_money = $v['tie_amount'] * (1 + $user_info['price_tie_dt']) + $win_money;
|
|
}
|
|
}
|
|
// 计算最终赢钱还是输钱
|
|
$win_total = $win_money - $amount;
|
|
//更新user表余额
|
|
$money = $user_info['money'] + $win_total;
|
|
Db::name('user')->where(array('id' => $user_info['id']))->update(array('money' => $money));
|
|
//更新bet表
|
|
$insertBetData = $v;
|
|
$insertBetData['result'] = $opening;
|
|
$insertBetData['win_total'] = $win_total;
|
|
$insertBetData['is_edit'] = 1;
|
|
Db::name('bet')->insert($insertBetData);
|
|
//写入cs表
|
|
$agent = explode(',', $user_info['agent_parent_id_path']); //切割多个代理ID为数组
|
|
krsort($agent);
|
|
$nextCs = 0;
|
|
$nextMaliang = 0;
|
|
foreach($agent as $key => $value){
|
|
$user_path_info = Db::name('user')->where(array('id' => $value))->find();
|
|
if($user_path_info){
|
|
$maliang = 0;
|
|
$ximalv = $user_path_info['agent_ximalv_dt'];
|
|
$maliang_true = 0;
|
|
if($ximalv > 0 && $ximaliang > 0){
|
|
$type = $key == 0 ? 1 : 0;
|
|
$maliang = round(($ximaliang * $ximalv) / 100,2);
|
|
$maliang_true = $maliang;
|
|
if($user_path_info['agent_cs'] > 0 && $user_path_info['share_xima'] == 2){
|
|
$maliang_true = $maliang - round($maliang * ($user_path_info['agent_cs'] / 100),2);
|
|
}
|
|
$net_maliang = $maliang - $nextMaliang;
|
|
$nextMaliang = $net_maliang + $nextMaliang;
|
|
$insert_xima_sql = "INSERT INTO `cg_xima` (`user_id`,`bet_user_id`,`bet_id`,`game_id`,`table_id`,`sumday_id`,`day`,`number_tab_id`,`boot_id`,`ximaliang`,`ximalv`,`maliang`,`maliang_true`,`total`,`win_total`,`create_time`,`type`,`net_maliang`) VALUES (".$value.",".$user_info['id'].",".$v['id'].",".$v['game_id'].",".$v['table_id'].",".$v['sumday_id'].",'".$v['day']."',".$v['number_tab_id'].",".$v['boot_id'].",".$ximaliang.",".$ximalv.",".$maliang.",".$maliang_true.",".$amount.",".$win_total.",".time().",".$type.",".$net_maliang.")";
|
|
Db::execute($insert_xima_sql);
|
|
}
|
|
//if($user_path_info['agent_cs'] > 0){
|
|
$type = $key == 0 ? 1 : 0;
|
|
$share_amount = to_number(round(($user_path_info['agent_cs'] * $win_total) / 100,2));
|
|
if($user_path_info['agent_cs'] > 0){
|
|
$share_amount_true = round(to_number($maliang + $win_total) * ($user_path_info['agent_cs'] / 100),2);
|
|
}else{
|
|
$share_amount_true = $maliang;
|
|
}
|
|
$net_cs = $share_amount - $nextCs;
|
|
$nextCs = $net_cs + $nextCs;
|
|
$insert_cs_sql = "INSERT INTO `cg_cs` (`user_id`,`bet_user_id`,`bet_id`,`game_id`,`table_id`,`number_tab_id`,`boot_id`,`sumday_id`,`day`,`share_amount`,`share_amount_true`,`share_percent`,`total`,`win_total`,`create_time`,`type`,`net_cs`,`maliang`) VALUES (".$value.",".$user_info['id'].",".$v['id'].",".$v['game_id'].",".$v['table_id'].",".$v['number_tab_id'].",".$v['boot_id'].",".$v['sumday_id'].",'".$v['day']."',".$share_amount.",".$share_amount_true.",".$user_path_info['agent_cs'].",".$amount.",".$win_total.",".time().",".$type.",".$net_cs.",".$maliang.")";
|
|
Db::execute($insert_cs_sql);
|
|
//}
|
|
}
|
|
}
|
|
// 代理抽水
|
|
if($opening == 1 && $v['banker_amount'] > 0 && $user_info['agent_commission'] > 0){
|
|
$parentIdPath = explode(',',$user_info['agent_parent_id_path']);
|
|
foreach($parentIdPath as $value){
|
|
$user = Db::name('user')->where('id',$value)->find();
|
|
$insert_commission_sql = "INSERT INTO `cg_agent_commission` (`user_id`,`username`,`agent_id`,`agent_username`,`game_id`,`game_name`,`table_id`,`table_name`,`boot_id`,`boot_num`,`number_tab_id`,`number`,`bet_id`,`amount`,`agent_commission`,`money_commission`,`result`,`create_time`) VALUES (".$user['id'].",'".$user['username']."',".$user['agent_parent_id'].",'".$user['agent_parent_username']."',2,'龙虎',".$table_info['id'].",'".$table_info['table_name']."',".$v['boot_id'].",".$v['boot_num'].",".$v['number_tab_id'].",".$v['number'].",".$v['id'].",".$v['banker_amount'].",".$agent_commission.",".$v['banker_amount'] * $agent_commission.",".$opening.",".time().")";
|
|
Db::execute($insert_commission_sql);
|
|
}
|
|
}
|
|
if($opening == 2 && $v['player_amount'] > 0 && $user_info['agent_commission'] > 0){
|
|
$parentIdPath = explode(',',$user_info['agent_parent_id_path']);
|
|
foreach($parentIdPath as $value){
|
|
$user = Db::name('user')->where('id',$value)->find();
|
|
$insert_commission_sql = "INSERT INTO `cg_agent_commission` (`user_id`,`username`,`agent_id`,`agent_username`,`game_id`,`game_name`,`table_id`,`table_name`,`boot_id`,`boot_num`,`number_tab_id`,`number`,`bet_id`,`amount`,`agent_commission`,`money_commission`,`result`,`create_time`) VALUES (".$user['id'].",'".$user['username']."',".$user['agent_parent_id'].",'".$user['agent_parent_username']."',2,'龙虎',".$table_info['id'].",'".$table_info['table_name']."',".$v['boot_id'].",".$v['boot_num'].",".$v['number_tab_id'].",".$v['number'].",".$v['id'].",".$v['player_amount'].",".$user_info['agent_commission'].",".$v['player_amount'] * $agent_commission.",".$opening.",".time().")";
|
|
Db::execute($insert_commission_sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return array('code' => 1, 'msg' => '修改成功');
|
|
}
|
|
|
|
/**
|
|
* 处理百家乐回档
|
|
* $table_info 桌子的数据
|
|
* $data 当前回合数据
|
|
* $serv swoole对象
|
|
* $connections 链接ID
|
|
*/
|
|
private function retreated_baccarat($game_id,$table_id,$boot_id,$number_tab_id,$resultData,$number_tab_info){
|
|
$lastNumberTabInfo = $number_tab_info;
|
|
$table_info = Db::name('table')->where('id',$table_id)->find();
|
|
//首先更新会员账户余额,减去相应的投注额
|
|
$bets = Db::name('bet')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id'], 'status' => 1))->select();
|
|
$oBets = $bets;
|
|
foreach($bets AS $key => $value){
|
|
$bet_win_total = $value['win_total'];
|
|
Db::execute("update `cg_user` set `money` = `money` - ".$bet_win_total." where `id`=".$value['user_id']);
|
|
}
|
|
//删除上一铺下注、洗码、分成
|
|
Db::name('bet')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('xima')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('cs')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('agent_commission')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
$opening = $resultData['opening'];
|
|
$pair = $resultData['pair'];
|
|
Db::name('number_tab')->where(array('id' => $lastNumberTabInfo['id']))->update(array('result' => $opening, 'pair' => $pair));
|
|
//记录修改日志
|
|
$retreated_log_data = array();
|
|
$retreated_log_data['mode'] = 1;
|
|
$retreated_log_data['type'] = 1;
|
|
$retreated_log_data['create_time'] = time();
|
|
$retreated_log_data['gamei_id'] = $game_id;
|
|
$retreated_log_data['table_id'] = $table_id;
|
|
$retreated_log_data['table_name'] = $lastNumberTabInfo['table_name'];
|
|
$retreated_log_data['boot_id'] = $boot_id;
|
|
$retreated_log_data['boot_num'] = $lastNumberTabInfo['boot_num'];
|
|
$retreated_log_data['number_tab_id'] = $number_tab_id;
|
|
$retreated_log_data['number'] = $lastNumberTabInfo['number'];
|
|
$str = '';
|
|
if($lastNumberTabInfo['result'] == 1) $str = '庄';
|
|
if($lastNumberTabInfo['result'] == 2) $str = '闲';
|
|
if($lastNumberTabInfo['result'] == 3) $str = '和';
|
|
if($lastNumberTabInfo['pair'] == 1) $str = $str.'-庄对';
|
|
if($lastNumberTabInfo['pair'] == 2) $str = $str.'-闲对';
|
|
if($lastNumberTabInfo['pair'] == 3) $str = $str.'-庄闲对';
|
|
$nstr = '';
|
|
if($opening == 1) $nstr = '庄';
|
|
if($opening == 2) $nstr = '闲';
|
|
if($opening == 3) $nstr = '和';
|
|
if($pair == 1) $nstr = $nstr.'-庄对';
|
|
if($pair == 2) $nstr = $nstr.'-闲对';
|
|
if($pair == 3) $nstr = $nstr.'-庄闲对';
|
|
$retreated_log_data['remark'] = '该口原本结果为:'.$str.',更改为:'.$nstr;
|
|
Db::name('retreated_log')->insert($retreated_log_data);
|
|
if(!empty($oBets)){
|
|
foreach($oBets AS $k => $v){
|
|
$user_info = Db::name('user')->where(array('id' => intval($v['user_id'])))->find();
|
|
$agent_commission = $user_info['agent_commission'] / 100;
|
|
if($user_info){
|
|
$amount = 0;
|
|
$amount = $v['banker_amount'] + $v['player_amount'] + $v['tie_amount'] + $v['banker_pair_amount'] + $v['player_pair_amount'];
|
|
$win_money = 0;
|
|
// 双边洗码
|
|
$ximaliang = 0;
|
|
if($user_info['type_xima'] == 1){
|
|
$ximaliang = $v['banker_amount'] - $v['player_amount'];
|
|
$ximaliang = abs($ximaliang);
|
|
}
|
|
if($opening == 1){
|
|
// 庄赢
|
|
if($v['banker_amount'] > 0){
|
|
if($table_info['mode'] == 1){
|
|
$win_money = round($v['banker_amount'] * (1 + $user_info['price_banker'] - $agent_commission),2) + $win_money;
|
|
}else{
|
|
$win_money = round($v['banker_amount'] * (1 + $user_info['price_banker']),2) + $win_money;
|
|
}
|
|
}
|
|
// 单边洗码
|
|
if($user_info['type_xima'] == 2){
|
|
$ximaliang = $v['player_amount'];
|
|
}
|
|
}elseif($opening == 2){
|
|
// 闲赢
|
|
if($v['player_amount'] > 0){
|
|
$win_money = $v['player_amount'] * (1 + $user_info['price_player']) + $win_money;
|
|
}
|
|
// 单边洗码
|
|
if($user_info['type_xima'] == 2){
|
|
$ximaliang = $v['banker_amount'];
|
|
}
|
|
}elseif($opening == 3) {
|
|
$ximaliang = 0;
|
|
// 和赢
|
|
if($v['tie_amount'] > 0){
|
|
$win_money = $v['tie_amount'] * (1 + $user_info['price_tie_baccarat']) + $win_money;
|
|
}
|
|
// 开 和,下注庄和闲不扣钱
|
|
if($v['banker_amount'] > 0 && $v['player_amount'] > 0){
|
|
$win_money = $v['player_amount'] + $v['banker_amount'] + $win_money;
|
|
}elseif($v['banker_amount'] > 0){
|
|
$win_money = $v['banker_amount'] + $win_money;
|
|
} elseif ($v['player_amount'] > 0){
|
|
$win_money = $v['player_amount'] + $win_money;
|
|
}
|
|
}
|
|
if($pair == 3){
|
|
// 计算庄对下注的赢钱金额
|
|
if ($v['banker_pair_amount'] > 0) {
|
|
$win_money = $v['banker_pair_amount'] * (1 + $user_info['price_pair']) + $win_money;
|
|
}
|
|
//计算闲对下注的赢钱金额
|
|
if ($v['player_pair_amount'] > 0) {
|
|
$win_money = $v['player_pair_amount'] * (1 + $user_info['price_pair']) + $win_money;
|
|
}
|
|
}elseif($pair == 1){
|
|
if ($v['banker_pair_amount'] > 0) {
|
|
$win_money = $v['banker_pair_amount'] * (1 + $user_info['price_pair']) + $win_money;
|
|
}
|
|
}elseif($pair == 2){
|
|
if ($v['player_pair_amount'] > 0) {
|
|
$win_money = $v['player_pair_amount'] * (1 + $user_info['price_pair']) + $win_money;
|
|
}
|
|
}
|
|
// 计算最终赢钱还是输钱
|
|
$win_total = $win_money - $amount;
|
|
//更新user表余额
|
|
$money = $user_info['money'] + $win_total;
|
|
Db::name('user')->where(array('id' => $user_info['id']))->update(array('money' => $money));
|
|
//更新bet表
|
|
$insertBetData = $v;
|
|
$insertBetData['result'] = $opening;
|
|
$insertBetData['pair'] = $pair;
|
|
$insertBetData['win_total'] = $win_total;
|
|
$insertBetData['is_edit'] = 1;
|
|
Db::name('bet')->insert($insertBetData);
|
|
//写入码率表及cs表
|
|
$agent = explode(',', $user_info['agent_parent_id_path']);
|
|
krsort($agent);
|
|
$nextCs = 0;
|
|
$nextMaliang = 0;
|
|
foreach($agent as $key => $value){
|
|
$user_path_info = Db::name('user')->where(array('id' => $value))->find();
|
|
if($user_path_info){
|
|
$maliang = 0;
|
|
$ximalv = $user_path_info['agent_ximalv'];
|
|
$maliang_true = 0;
|
|
if($ximalv > 0 && $ximaliang > 0){
|
|
$type = $key == 0 ? 1 : 0;
|
|
$maliang = round(($ximaliang * $ximalv) / 100,2);
|
|
$maliang_true = $maliang;
|
|
if($user_path_info['agent_cs'] > 0 && $user_path_info['share_xima'] == 2){
|
|
$maliang_true = $maliang - round($maliang * ($user_path_info['agent_cs'] / 100),2);
|
|
}
|
|
$net_maliang = $maliang - $nextMaliang;
|
|
$nextMaliang = $net_maliang + $nextMaliang;
|
|
$insert_xima_sql = "INSERT INTO `cg_xima` (`user_id`,`bet_user_id`,`bet_id`,`game_id`,`table_id`,`sumday_id`,`day`,`number_tab_id`,`boot_id`,`ximaliang`,`ximalv`,`maliang`,`maliang_true`,`total`,`win_total`,`create_time`,`type`,`net_maliang`) VALUES (".$value.",".$user_info['id'].",".$v['id'].",".$v['game_id'].",".$v['table_id'].",".$v['sumday_id'].",'".$v['day']."',".$v['number_tab_id'].",".$v['boot_id'].",".$ximaliang.",".$ximalv.",".$maliang.",".$maliang_true.",".$amount.",".$win_total.",".$lastNumberTabInfo['bet_start_time'].",".$type.",".$net_maliang.")";
|
|
Db::execute($insert_xima_sql);
|
|
}
|
|
//if($user_path_info['agent_cs'] > 0){
|
|
$type = $key == 0 ? 1 : 0;
|
|
$share_amount = to_number(($user_path_info['agent_cs'] * $win_total) / 100);
|
|
if($user_path_info['agent_cs'] > 0){
|
|
$share_amount_true = round(to_number($maliang + $win_total) * ($user_path_info['agent_cs'] / 100),2);
|
|
}else{
|
|
$share_amount_true = $maliang;
|
|
}
|
|
$net_cs = $share_amount - $nextCs;
|
|
$nextCs = $net_cs + $nextCs;
|
|
$insert_cs_sql = "INSERT INTO `cg_cs` (`user_id`,`bet_user_id`,`bet_id`,`game_id`,`table_id`,`number_tab_id`,`boot_id`,`sumday_id`,`day`,`share_amount`,`share_amount_true`,`share_percent`,`total`,`win_total`,`create_time`,`type`,`net_cs`,`maliang`) VALUES (".$value.",".$user_info['id'].",".$v['id'].",".$v['game_id'].",".$v['table_id'].",".$v['number_tab_id'].",".$v['boot_id'].",".$v['sumday_id'].",'".$v['day']."',".$share_amount.",".$share_amount_true.",".$user_path_info['agent_cs'].",".$amount.",".$win_total.",".$lastNumberTabInfo['bet_start_time'].",".$type.",".$net_cs.",".$maliang.")";
|
|
Db::execute($insert_cs_sql);
|
|
//}
|
|
}
|
|
}
|
|
// 代理抽水
|
|
if($opening == 1 && $v['banker_amount'] > 0 && $user_info['agent_commission'] > 0 ){
|
|
$parentIdPath = explode(',',$user_info['agent_parent_id_path']);
|
|
foreach($parentIdPath as $value){
|
|
$user = Db::name('user')->where('id',$value)->find();
|
|
$insert_commission_sql = "INSERT INTO `cg_agent_commission` (`user_id`,`username`,`agent_id`,`agent_username`,`game_id`,`game_name`,`table_id`,`table_name`,`boot_id`,`boot_num`,`number_tab_id`,`number`,`bet_id`,`amount`,`agent_commission`,`money_commission`,`result`,`pair`,`create_time`) VALUES (".$user['id'].",'".$user['username']."',".$user['agent_parent_id'].",'".$user['agent_parent_username']."',1,'百家乐',".$table_info['id'].",'".$table_info['table_name']."',".$v['boot_id'].",".$v['boot_num'].",".$v['number_tab_id'].",".$v['number'].",".$v['id'].",".$v['banker_amount'].",".$user_info['agent_commission'].",".$v['banker_amount'] * $agent_commission.",".$opening.",".$pair.",".time().")";
|
|
Db::execute($insert_commission_sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return array('code' => 1, 'msg' => '修改成功');
|
|
}
|
|
/**
|
|
* 处理百家乐Win6回档
|
|
* $table_info 桌子的数据
|
|
* $data 当前回合数据
|
|
* $serv swoole对象
|
|
* $connections 链接ID
|
|
*/
|
|
function retreated_baccarat_win6($game_id,$table_id,$boot_id,$number_tab_id,$resultData,$number_tab_info){
|
|
$lastNumberTabInfo = $number_tab_info;
|
|
//首先更新会员账户余额,减去相应的投注额
|
|
$bets = Db::name('bet')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id'], 'status' => 1))->select();
|
|
$oBets = $bets;
|
|
foreach($bets AS $key => $value){
|
|
$bet_win_total = $value['win_total'];
|
|
Db::execute("update `cg_user` set `money` = `money` - ".$bet_win_total." where `id`=".$value['user_id']);
|
|
}
|
|
//删除上一铺下注、洗码、分成
|
|
Db::name('bet')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('xima')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
Db::name('cs')->where(array('game_id' => $game_id, 'table_id' => $table_id, 'boot_id' => $boot_id, 'number_tab_id' => $lastNumberTabInfo['id']))->delete();
|
|
$opening = $resultData['opening'];
|
|
$pair = $resultData['pair'];
|
|
$isWin6 = $resultData['win6'] == 1 ? 1 : 0;
|
|
Db::name('number_tab')->where(array('id' => $lastNumberTabInfo['id']))->update(array('result' => $opening, 'pair' => $pair, 'win6' => $isWin6));
|
|
//记录修改日志
|
|
$retreated_log_data = array();
|
|
$retreated_log_data['mode'] = 1;
|
|
$retreated_log_data['type'] = 1;
|
|
$retreated_log_data['create_time'] = time();
|
|
$retreated_log_data['gamei_id'] = $game_id;
|
|
$retreated_log_data['table_id'] = $table_id;
|
|
$retreated_log_data['table_name'] = $lastNumberTabInfo['table_name'];
|
|
$retreated_log_data['boot_id'] = $boot_id;
|
|
$retreated_log_data['boot_num'] = $lastNumberTabInfo['boot_num'];
|
|
$retreated_log_data['number_tab_id'] = $number_tab_id;
|
|
$retreated_log_data['number'] = $lastNumberTabInfo['number'];
|
|
$str = '';
|
|
if($lastNumberTabInfo['result'] == 1) $str = '庄';
|
|
if($lastNumberTabInfo['result'] == 2) $str = '闲';
|
|
if($lastNumberTabInfo['result'] == 3) $str = '和';
|
|
if($lastNumberTabInfo['pair'] == 1) $str = $str.'-庄对';
|
|
if($lastNumberTabInfo['pair'] == 2) $str = $str.'-闲对';
|
|
if($lastNumberTabInfo['pair'] == 3) $str = $str.'-庄闲对';
|
|
if($lastNumberTabInfo['win6'] == 1) $str = $str.'-赢6';
|
|
$nstr = '';
|
|
if($opening == 1) $nstr = '庄';
|
|
if($opening == 2) $nstr = '闲';
|
|
if($opening == 3) $nstr = '和';
|
|
if($pair == 1) $nstr = $nstr.'-庄对';
|
|
if($pair == 2) $nstr = $nstr.'-闲对';
|
|
if($pair == 3) $nstr = $nstr.'-庄闲对';
|
|
if($isWin6 == 1) $nstr = $nstr.'-赢6';
|
|
$retreated_log_data['remark'] = '该口原本结果为:'.$str.',更改为:'.$nstr;
|
|
Db::name('retreated_log')->insert($retreated_log_data);
|
|
if(!empty($oBets)){
|
|
foreach($oBets AS $k => $v){
|
|
$user_info = Db::name('user')->field(array('id','money','agent_parent_id_path'))->where(array('id' => intval($v['user_id'])))->find();
|
|
if($user_info){
|
|
$amount = 0;
|
|
$amount = $v['banker_amount'] + $v['player_amount'] + $v['tie_amount'] + $v['banker_pair_amount'] + $v['player_pair_amount'];
|
|
$win_money = 0;
|
|
$BPT_ximaliang = 0;
|
|
if($opening == 1){
|
|
// 庄赢
|
|
if($v['banker_amount'] > 0){
|
|
if($isWin6 === 1){
|
|
$win_money = $v['banker_amount'] * (1 + 0.5) + $win_money;
|
|
}else{
|
|
$win_money = $v['banker_amount'] * (1 + 1) + $win_money;
|
|
}
|
|
}
|
|
$BPT_ximaliang = $v['player_amount'] + $v['tie_amount'];
|
|
}elseif($opening == 2){
|
|
// 闲赢
|
|
if($v['player_amount'] > 0){
|
|
if($isWin6 === 1){
|
|
$win_money = $v['player_amount'] * (1 + 0.5) + $win_money;
|
|
}else{
|
|
$win_money = $v['player_amount'] * (1 + 1) + $win_money;
|
|
}
|
|
}
|
|
$BPT_ximaliang = $v['banker_amount'] + $v['tie_amount'];
|
|
}elseif($opening == 3) {
|
|
// 和赢
|
|
if($v['tie_amount'] > 0){
|
|
$win_money = $v['tie_amount'] * (1 + 8) + $win_money;
|
|
}
|
|
// 开 和,下注庄和闲不扣钱
|
|
if($v['banker_amount'] > 0 && $v['player_amount'] > 0){
|
|
$win_money = $v['player_amount'] + $v['banker_amount'] + $win_money;
|
|
}elseif($v['banker_amount'] > 0){
|
|
$win_money = $v['banker_amount'] + $win_money;
|
|
} elseif ($v['player_amount'] > 0){
|
|
$win_money = $v['player_amount'] + $win_money;
|
|
}
|
|
//$BPT_ximaliang = $v['banker_amount'] + $v['player_amount'];
|
|
}
|
|
$PAIR_ximaliang = 0;
|
|
if($pair == 3){
|
|
// 计算庄对下注的赢钱金额
|
|
if ($v['banker_pair_amount'] > 0) {
|
|
$win_money = $v['banker_pair_amount'] * (1 + 11) + $win_money;
|
|
}
|
|
//计算闲对下注的赢钱金额
|
|
if ($v['player_pair_amount'] > 0) {
|
|
$win_money = $v['player_pair_amount'] * (1 + 11) + $win_money;
|
|
}
|
|
}elseif($pair == 1){
|
|
if ($v['banker_pair_amount'] > 0) {
|
|
$win_money = $v['banker_pair_amount'] * (1 + 11) + $win_money;
|
|
}
|
|
$PAIR_ximaliang = $PAIR_ximaliang + $v['player_pair_amount'];
|
|
}elseif($pair == 2){
|
|
if ($v['player_pair_amount'] > 0) {
|
|
$win_money = $v['player_pair_amount'] * (1 + 11) + $win_money;
|
|
}
|
|
$PAIR_ximaliang = $PAIR_ximaliang + $v['banker_pair_amount'];
|
|
}else{
|
|
$PAIR_ximaliang = $v['player_pair_amount'] + $v['banker_pair_amount'];
|
|
}
|
|
$ximaliang = $BPT_ximaliang + $PAIR_ximaliang;
|
|
// 计算最终赢钱还是输钱
|
|
$win_total = $win_money - $amount;
|
|
//更新user表余额
|
|
$money = $user_info['money'] + $win_total;
|
|
Db::name('user')->where(array('id' => $user_info['id']))->update(array('money' => $money));
|
|
//更新bet表
|
|
$insertBetData = $v;
|
|
$insertBetData['result'] = $opening;
|
|
$insertBetData['pair'] = $pair;
|
|
$insertBetData['win_total'] = $win_total;
|
|
$insertBetData['is_edit'] = 1;
|
|
Db::name('bet')->insert($insertBetData);
|
|
//写入cs表
|
|
$agent = explode(',', $user_info['agent_parent_id_path']); //切割多个代理ID为数组
|
|
krsort($agent);
|
|
$nextCs = 0;
|
|
foreach($agent as $key => $value){
|
|
$user_path_info = Db::name('user')->where(array('id' => $value))->find();
|
|
if($user_path_info){
|
|
if($user_path_info['agent_cs'] > 0){
|
|
$type = $key == 0 ? 1 : 0;
|
|
$share_amount = to_number(($user_path_info['agent_cs'] * $win_total) / 100);
|
|
$share_amount_true = 0;
|
|
$net_cs = $share_amount - $share_amount;
|
|
$nextCs = $net_cs + $nextCs;
|
|
$insert_cs_sql = "INSERT INTO `cg_cs` (`user_id`,`bet_user_id`,`bet_id`,`game_id`,`table_id`,`number_tab_id`,`boot_id`,`sumday_id`,`day`,`share_amount`,`share_amount_true`,`share_percent`,`total`,`win_total`,`create_time`,`type`,`net_cs`) VALUES (".$value.",".$user_info['id'].",".$v['id'].",".$v['game_id'].",".$v['table_id'].",".$v['number_tab_id'].",".$v['boot_id'].",".$v['sumday_id'].",'".$v['day']."',".$share_amount.",".$share_amount_true.",".$user_path_info['agent_cs'].",".$amount.",".$win_total.",".time().",".$type.",".$net_cs.")";
|
|
Db::execute($insert_cs_sql);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return array('code' => 1, 'msg' => '修改成功');
|
|
}
|
|
} |