' . 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 '黄金会员'; }elseif($money >= 50000){ return '钻石会员'; }elseif($money >= 200000){ return '皇者会员'; }else{ return '会员'; } } /** * 系统非常规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 "
"; //print_r($pathway); //echo ""; //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