You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2992 lines
84 KiB
PHP

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
require 'encryption.php';
//php防注入和XSS攻击过滤.
function SafeFilter(&$arr) {
$ra = Array('/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/', '/script/', '/javascript/', '/vbscript/', '/expression/', '/applet/', '/meta/', '/xml/', '/blink/', '/link/', '/style/', '/embed/', '/object/',
'/frame/', '/layer/', '/title/', '/bgsound/', '/base/', '/onload/', '/onunload/', '/onchange/', '/onsubmit/', '/onreset/', '/onselect/', '/onblur/', '/onfocus/', '/onabort/',
'/onkeydown/', '/onkeypress/', '/onkeyup/', '/onclick/', '/ondblclick/', '/onmousedown/', '/onmousemove/', '/onmouseout/', '/onmouseover/', '/onmouseup/', '/onunload/');
if (is_array($arr)) {
foreach ($arr as $key => $value) {
if (!is_array($value)) {
if (!get_magic_quotes_gpc()) { //不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
$value = addslashes($value); //给单引号(')、双引号(")、反斜线(\)与 NULNULL 字符)加上反斜线转义
}
$value = preg_replace($ra, '', $value); //删除非打印字符粗暴式过滤xss可疑字符串
$arr[$key] = htmlentities(strip_tags($value)); //去除 HTML 和 PHP 标记并转换为 HTML 实体
} else {
SafeFilter($arr[$key]);
}
}
}
return $arr;
}
/*
* 验证身份证号
* @param sting $idcard 身份证号码
* @author 鹿文学
*/
function is_idcard( $idcard ) {
$id = strtoupper($idcard);
$regx = "/(^\d{15}$)|(^\d{17}([0-9]|X)$)/";
$arr_split = array();
if(!preg_match($regx, $id)) {
return FALSE;
}
if(15==strlen($id)) { /* 检查15位 */
$regx = "/^(\d{6})+(\d{2})+(\d{2})+(\d{2})+(\d{3})$/";
@preg_match($regx, $id, $arr_split);
//检查生日日期是否正确
$dtm_birth = "19".$arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
if(!strtotime($dtm_birth)) {
return FALSE;
} else {
return TRUE;
}
}
else { /* 检查18位 */
$regx = "/^(\d{6})+(\d{4})+(\d{2})+(\d{2})+(\d{3})([0-9]|X)$/";
@preg_match($regx, $id, $arr_split);
$dtm_birth = $arr_split[2] . '/' . $arr_split[3]. '/' .$arr_split[4];
if(!strtotime($dtm_birth)) { /* 检查生日日期是否正确 */
return FALSE;
} else {
//检验18位身份证的校验码是否正确。
//校验位按照ISO 7064:1983.MOD 11-2的规定生成X可以认为是数字10。
$arr_int = array(7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2);
$arr_ch = array('1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2');
$sign = 0;
for ( $i = 0; $i < 17; $i++ ) {
$b = (int) $id{$i};
$w = $arr_int[$i];
$sign += $b * $w;
}
$n = $sign % 11;
$val_num = $arr_ch[$n];
if ($val_num != substr($id,17, 1)) {
return FALSE;
} else {
return TRUE;
}
}
}
}
/**
* 计算两点地理坐标之间的距离
* @param string $start_longitude 起点经度
* @param string $start_latitude 起点纬度
* @param string $end_longitude 终点经度
* @param string $end_latitude 终点纬度
* @param integer $unit 单位 1:公里 2:米
* @param integer $decimal 精度 保留小数位数
* @return Decimal
* @author 鹿文学
*/
function get_distance_by_twopoint($start_longitude, $start_latitude, $end_longitude, $end_latitude, $unit=1, $decimal=2){
$earch_radius = 6370.996;
$radian = pi()/180.0;
$rad_start_lat = $start_latitude * $radian;
$rad_end_lat = $end_latitude * $radian;
$rad_start_lng = $start_longitude * $radian;
$rad_end_lng = $end_longitude * $radian;
$lat = $rad_start_lat - $rad_end_lat;
$lng = $rad_start_lng - $rad_end_lng;
$distance = 2 * asin(sqrt(pow(sin($lat/2),2) + cos($rad_start_lat) * cos($rad_end_lat) * pow(sin($lng/2),2)));
$distance = $distance * $earch_radius * 1000;
if($unit==1){
$distance = $distance / 1000;
}
return round($distance, $decimal);
}
/**
* 计算某个经纬度周围某段距离的四个点
* @param string $longitude 经度(单位:度)
* @param string $latitude 纬度(单位:度)
* @param integer $distance 距离(单位:千米)
* @author 鹿文学
*/
function get_square_point($longitude,$latitude,$distance=3) {
$earch_radius = 6370.996;
$dit_lng = 2 * asin(sin($distance/(2*$earch_radius))/cos(deg2rad($latitude)));
$dit_lng = rad2deg($dit_lng);
$dit_lat = $distance/$earch_radius;
$dit_lat = rad2deg($dit_lat);
return [
'left_top'=>array('longitude'=>$longitude-$dit_lng,'latitude'=>$latitude+$dit_lat),
'right_top'=>array('longitude'=>$longitude+$dit_lng,'latitude'=>$latitude+$dit_lat),
'left_bottom'=>array('longitude'=>$longitude-$dit_lng,'latitude'=>$latitude-$dit_lat),
'right_bottom'=>array('longitude'=>$longitude+$dit_lng,'latitude'=>$latitude-$dit_lat),
];
}
/**
* 检测账户是否存在
* @param string
* @author 鹿文学
*/
function check_account_is_existence($account){
$map['account']=$account;
$find=M('user','tab_')->field('id')->where($map)->find();
if(!empty($find)){
return $find['id'];
}else{
return 0;
}
}
/**
* 获取小号累充
* @author 鹿文学
*/
function get_small_spend_sum($small_id) {
$res = M('Spend','tab_')->where(['pay_status'=>1,'small_id'=>$small_id])->sum('pay_amount');
if(!empty($res)) {return $res;} else {return '0.00';}
}
/**
* 获取VIP等级
* @author 鹿文学
*/
function get_vip_level($money=0) {
if(!is_numeric($money) || $money<0) {return 0;}
$tool = M('tool',"tab_")->field('config,status')->where(['name'=>'viplevel'])->find();
if(!empty($tool) && $tool['status']==1){
$viplevel = json_decode($tool['config'],true);
$vl=0;
$len = count($viplevel);
if(empty($viplevel)) {return 0;}
$money = intval($money*10000);
foreach($viplevel as $k=>$v) {
$i = intval(str_replace('vip','',$k));
if($money<intval($v*10000)) {$vl = $i-1;break;}
if($i == $len) {$vl = $i;}
}
return $vl;
} else {
return 0;
}
}
function add_str_to_array($arr,$str,$separator='',$prefix=1) {
if($prefix) {
foreach($arr as $k => $v) {
$arr[$k] = $str . $separator . $v;
}
}else {
foreach($arr as $k => $v) {
$arr[$k] = $v . $separator . $str;
}
}
return $arr;
}
function get_kefu_list() {
$list = M('kefuquestion')->field('id,title,titleurl')->where(['status'=>1,'istitle'=>1])->select();
return $list;
}
/**
* 获取游戏名称
* @author 鹿文学
*/
function get_game_name_by_id($id=0,$replace='') {
if(is_numeric($id) && $id>0) {
$game = M('Game','tab_');
$result = $game->where(['id'=>$id])->find();
return is_array($result)?$result['game_name']:$replace;
} else {
return $replace;
}
}
/**
* 判断文件是否存在
* @author 鹿文学
*/
function check_promote_game_file_url($id) {
$url = get_promote_game_file_url($id);
if(empty($url)) {return false;}else {
return is_file($url);
}
}
/**
* 整理下载链接
* @author 鹿文学
*/
function get_promote_game_file_url($id) {
if(is_numeric($id) && $id>0) {
$result = M('apply','tab_')->field('pack_url,plist_url,sdk_version')->where(['id'=>$id])->find();
if($result['sdk_version']==1) {
return ROOTTT.ltrim($result['pack_url'],'./');
} elseif($result['sdk_version']==2) {
return ROOTTT.ltrim($result['plist_url'],'./');
} else {
return '';
}
} else {
return '';
}
}
/**
* 投放平台名称通过编号
* @author 鹿文学
*/
function get_launch_platform_name($id=0,$replace='') {
if(is_numeric($id) && $id>0) {
$platform = M('LaunchPlatform','tab_');
$result = $platform->where(['id'=>$id])->find();
return is_array($result)?$result['name']:$replace;
} else {
return $replace;
}
}
/**
* 投放平台列表
* @author 鹿文学
*/
function get_launch_platform_list($flag='') {
$platform = M('LaunchPlatform','tab_');
if(is_numeric($flag)&&($flag==0||$flag==1)) {
$list = $platform->where(['status'=>1,'mark'=>$flag])->select();
} else {
$list = $platform->where(['status'=>1])->select();
}
return $list;
}
/**
* 文章
* @author 鹿文学
*/
function get_model_attribute2($model_id,$group) {
/* 非法ID */
if(empty($model_id) || !is_numeric($model_id)){
return '';
}
if($group[0]) {
$group = array_merge([0=>1],$group);
unset($group[0]);
}
if(!isset($list[$model_id])){
static $list;
$map = array('model_id'=>$model_id);
$extend = M('Model')->getFieldById($model_id,'extend');
if($extend){
$map = array('model_id'=> array("in", array($model_id, $extend)));
}
$info = M('Attribute')->where($map)->field($fields)->select();
$list[$model_id] = $info;
}
$attr = array();
foreach ($list[$model_id] as $value) {
$attr[$value['id']] = $value;
}
foreach ($group as &$value) {
foreach ($value as $key => $val) {
$value[$key] = $attr[$val];
unset($attr[$val]);
}
}
return $group;
}
/**
* 客服问题分类列表
* @author 鹿文学
*/
function get_custom_category_list() {
return array(
1=>['title'=>'商城问题','url'=>'shop'],
2=>['title'=>'账户问题','url'=>'account'],
3=>['title'=>'常见问题','url'=>'often'],
4=>['title'=>'充值问题','url'=>'pay'],
5=>['title'=>'密码问题','url'=>'mima'],
6=>['title'=>'礼包问题','url'=>'gift'],
);
}
/**
* 获取客服问题分类名称
* @param
* @author 鹿文学
*/
function get_custom_category_title($id=0,$title=0) {
if(!is_numeric($id) || $id<1 || $id>6) {return $title==1?'未知分类':['title'=>'未知分类','url'=>'weizhi'];}
$array = get_custom_category_list();
return $title==1?$array[$id]['title']:$array[$id];
}
/**
* 分页
* @author 鹿文学
*/
function set_pagination($count, $row,$request='') {
$aside = '<script>function pagechange(that){url = location.href.replace(".html","").replace(/(&|\/)row(=|\/)\d*/gi,"").replace(/\/p\/\d*/gi,"");if(url.indexOf("?")>0){url += "&row="+that.value;}else{url += "?row="+that.value;} window.location.href = url;}</script><select id="pagechange" name="row" onchange="pagechange(this)">';
if($row == 10){
$aside .= '<option value="10" selected>每页10条</option>';
}else{
$aside .= '<option value="10">每页10条</option>';
}
if($row == 25){
$aside .= '<option value="25" selected>每页25条</option>';
}else{
$aside .= '<option value="25">每页25条</option>';
}
if($row == 50){
$aside .= '<option value="50" selected>每页50条</option>';
}else{
$aside .= '<option value="50">每页50条</option>';
}
if($row == 100){
$aside .= '<option value="100" selected>每页100条</option></select>';
}else{
$aside .= '<option value="100">每页100条</option></select>';
}
$count=$count?$count:0;
$row=$row?$row:10;
if ($count > $row) {
$page = new \Think\Page($count, $row,$request);
$page->setConfig('theme', '%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$html = $page->show();
return str_replace('<div>','<div>' .$aside,$html);
} else {
return '<div>' .$aside. '<span class="rows">共 '.$count.' 条记录</span></div>';
}
}
function get_source_from_game($id=0) {
if (!is_numeric($id) || $id<1) {return '全部';}
$game = M('game','tab_')->field('game_name')->where(['id'=>$id])->find();
return $game['game_name']?$game['game_name']:'全部';
}
function get_source_of_game() {
$developers = M('game','tab_')->field('developers')->where()->find();
if ($developers['developers']>0) {
return '开发者';
} else {
return '平台官网';
}
}
function get_game_type_by_id($id=0) {
if (!is_numeric($id) || $id <1 ){return '';}
$data = M('game_type','tab_')->field('type_name')->where(array('status_show'=>1,'id'=>$id))->find();
return $data['type_name']?$data['type_name']:'';
}
function set_number_short($number) {
if (!is_numeric($number) || $number<=0) {return 0;}
$len = strlen((integer)$number);
$str = '';
if ($len<5){$str = $number;}
elseif($len<9) {$str=round($number/10000,2).'万';}
elseif ($len<12) {$str=round($number/100000000,2).'亿';}
elseif ($len<16) {$str=round($number/100000000000,2).'兆';}
return $str;
}
function emoji_encode($nickname){
$strEncode = '';
$length = mb_strlen($nickname,'utf-8');
for ($i=0; $i < $length; $i++) {
$_tmpStr = mb_substr($nickname,$i,1,'utf-8');
if(strlen($_tmpStr) >= 4){
$strEncode .= '[[EMOJI:'.rawurlencode($_tmpStr).']]';
}else{
$strEncode .= $_tmpStr;
}
}
return $strEncode;
}
function get_promote_entity($id=0,$isAccount = false){
if($id =='' ){
return false;
}
$user = M('Promote',"tab_");
if($isAccount){
$map['account'] = $id;
$data = $user->where($map)->find();
}
else{
$data = $user->find($id);
}
if(empty($data)){
return false;
}
return $data;
}
function get_target_name($str) {
$temp = '';
switch($str) {
case '_blank':$temp='新页面';break;
default:$temp='本页面';
}
return $temp;
}
function get_recommend_status_info($str) {
$str2 ='';
$arr = explode(',',$str);
foreach($arr as $v) {
$str2 .= ','.get_info_status($v,1);
}
return substr($str2,1);
}
// lwx 判断手机类型
function get_devices_type() {
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$type = '';
if (strpos($agent,'iphone') || strpos($agent,'ipad')) {
$type = 2;
} elseif (strpos($agent,'android')) {
$type = 1;
}
return $type;
}
function is_https() {
if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') {
return true;
} elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) {
return true;
} elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') {
return true;
}
return false;
}
//判断是否是手机端请求
function is_mobile_request() {
$_SERVER['ALL_HTTP'] = isset($_SERVER['ALL_HTTP']) ? $_SERVER['ALL_HTTP'] : '';
$mobile_browser = '0';
if(preg_match('/(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|iphone|ipad|ipod|android|xoom)/i', strtolower($_SERVER['HTTP_USER_AGENT']))) $mobile_browser++;
if((isset($_SERVER['HTTP_ACCEPT'])) and (strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') !== false))
$mobile_browser++;
if(isset($_SERVER['HTTP_X_WAP_PROFILE']))
$mobile_browser++;
if(isset($_SERVER['HTTP_PROFILE']))
$mobile_browser++;
$mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'],0,4));
$mobile_agents =
array(
'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',
'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',
'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',
'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',
'newt','noki','oper','palm','pana','pant','phil','play','port','prox',
'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',
'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',
'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',
'wapr','webc','winw','winw','xda','xda-'
);
if(in_array($mobile_ua, $mobile_agents))
$mobile_browser++;
if(strpos(strtolower($_SERVER['ALL_HTTP']), 'operamini') !== false)
$mobile_browser++;
// Pre-final check to reset everything if the user is on Windows
if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows') !== false)
$mobile_browser=0;
// But WP7 is also Windows, with a slightly different characteristic
if(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'windows phone') !== false)
$mobile_browser++; if($mobile_browser>0)
return true;
else
return false;
}
/* 获取日期间隔数组 @author 鹿文学 */
function get_date_list($d1='',$d2='',$flag=1) {
if ($flag == 1){/* 天 形如array('2017-03-10','2017-03-11','2017-03-12','2017-03-13')*/
$d1 = $d1?$d1:mktime(0,0,0,date('m'),date('d')-6,date('Y'));
$d2 = $d2?$d2:mktime(0,0,0,date('m'),date('d'),date('Y'));
$date = range($d1,$d2,86400);
if(!is_array($date))
$date = [date('Y-m-d',$d1)];
else
$date = array_map(create_function('$v','return date("Y-m-d",$v);'),$date);
} elseif ($flag == 2) {/* 月 形如array('2017-01','2017-02','2017-03','2017-04')*/
$d1 = $d1?$d1:mktime(0,0,0,date('m')-5,1,date('Y'));
$d2 = $d2?$d2:mktime(0,0,0,date('m'),date('d'),date('Y'));
$i = false;
while($d1<$d2) {
$d1 = !$i?$d1:strtotime('+1 month',$d1);
$date[]=date('Y-m',$d1);$i=true;
}
array_pop($date);
} elseif ($flag == 3) {/* 周 形如array('2017-01','2017-02','2017-03','2017-04')*/
$d1 = $d1?$d1:mktime(0,0,0,date('m')-2,1,date('Y'));
$d2 = $d2?$d2:mktime(0,0,0,date('m'),date('d'),date('Y'));
$i = false;
while($d1<$d2) {
$d1 = !$i?$d1:strtotime('+1 week',$d1);
$date[]=date('Y-W',$d1);$i=true;
}
} elseif ($flag == 4) {
$d1 = $d1?date('Y-m',$d1):date('Y-m',strtotime('-5 month'));
$d2 = $d2?date('Y-m',$d2):date('Y-m');
$temp = explode('-',$d1);
$year = $temp[0];
$month = $temp[1];
while(strtotime($d1)<=strtotime($d2)) {
$date[]=$d1;$month++;if($month>12) {$month=1;$year+=1;}
$t = strlen($month.'')==1?'0'.$month:$month;
$d1=$year.'-'.$t;
}
}
return $date;
}
/**
* [获取游戏的app状态]
* @param $game_id
* @return bool
*/
function get_game_appstatus2($game_id){
$map['id']=$game_id;
$game=M('game','tab_')->field('appstatus')->where($map)->find();
if($game['appstatus']==1){
return true;
}else{
return false;
}
}
/**
* 获取对应游戏类型的状态信息
* @param int $group 状态分组
* @param int $type 状态文字
* @return string 状态文字 false 未获取到
* @author
*/
function get_info_status($type=null,$group=0){
if(!isset($type)){
return false;
}
$arr=array(
0 =>array(0=>"关闭" ,1=>"开启"),//关闭 开启
1 =>array(0=>"不推荐" ,1=>"推荐",2=>"热门",3=>"最新"),//游戏设置状态 不推荐 推荐 热门最新
2 =>array(0=>"" ,1=>""),//否 是
3 =>array(0=>"待审核" ,1=>"正常",2=>L('Lock')),//推广员状态 待审核 正常 锁定
4 =>array(0=>L('Lock') ,1=>"正常"),//用户状态 锁定 正常
5 =>array(0=>"未审核" ,1=>"已审核" ,2=>"驳回"),//游戏审核状态
6 =>array(0=>"未修复" ,1=>"已修复"),//纠错状态
7 =>array(0=>"失败" ,1=>"成功"),//纠错状态 未修复 已修复
8 =>array(0=>"禁用" ,1=>"启用"),//显示状态 禁用 启用
9 =>array(0=>"下单未支付" ,1=>"充值成功"),//订单状态 下单未支付 充值成功
10 =>array(0=>"正常" ,1=>"拥挤",2=>"爆满"),//区服状态 正常 拥挤 饱满
12 =>array(0=>L('Unpaid'),1=>"成功"), // 未支付 成功
30=>array(0=>"待审核",1=>"已审核",2=>"驳回"), //待审核
13 =>array(1=>'已读',2=>"未读"),
14 =>array(0=>"通知失败",1=>"通知成功"),
15 =>array(0=>"未充值",1=>"已充值"),
16 =>array(0=>"未回复",1=>"已回复"),
17 =>array(0=>"平台币",1=>"绑定平台币"),
29=>array(0=>"待审核",1=>"已通过",2=>"未通过"),
30=>array(0=>"禁用",1=>"正常"),
18 => ["平台币","支付宝","微信","聚宝云"],
19 => ["待审核","已通过","未通过"],
20 => ['',"会长",'部门长','组长', '组员'],
21 => ['',"支付宝","微信","聚宝云","平台币",L('Jtpay')],
22 => ["双平台","安卓","苹果"],
23 => ['',"安卓","苹果"],
24 => ['',"系统分配","自主添加"],
25 => ['',"已通过","待审核"],
26 => ['',"开启","关闭"],
27 => ['',"实物","虚拟物品"],
28 => ['',"已签署","待签署","待签署","已确认"],
31 => array(0=>"未审核",1=>"已审核"),
32 => array(1=>'公司',2=>'个人'),
33 =>array(0=>"待审核",1=>"已通过"),
34 => ["已关闭","已开启"],
35 => array(-1=>"审核中",1=>"正常",2=>"锁定",3=>"驳回"),
38 => array(0=>'待付款',1=>'交易成功',2=>'交易取消'),
39 => array(0=>'未打款',1=>'已打款',2=>'已驳回'),
36 => array(0=>"未打款",1=>"手动打款",2=>"自动打款"),
37 => array(0=>"不参与",1=>"已参与"),
40 => array(0=>'未处理',1=>'已处理',2=>'忽略'),
41 => array(-1=>'已下架',0=>'待审核',1=>'已售出',2=>'已驳回',3=>'出售中',4=>'待发货',5=>'审核中'),
42 => array(0=>'未认证',1=>'成功',2=>'拒绝',3=>'正在审核',4=>'修改审核中'),
);
return $arr[$group][$type];
}
/**
* [用于导出时 develop表有部分数据为null]
* @author 幽灵[syt]
*/
function get_developer_type($type){
if ($type == 1){
return "公司";
}else{
return "个人";
}
}
/**
* 获取平台币类型
* @return [type] [description]
*/
function get_banlan_type($id){
$name=$id==1?"平台币":"绑币";
return $name;
}
/**
* 返回状态恢复成功/失败的语言包
* @param [type] $msg [description]
* @author zc 894827077@qqcom
*/
function Status_recovery($msg){
if($msg=="success"){
return "状态恢复成功!";
}else{
return "状态恢复失败!";
}
}
// lwx 2017-01-07
function get_systems_name($id,$lan='cn') {
$list = get_systems_list($lan);
return $list[$id];
}
// lwx 2017-01-07
function get_systems_list($lan='cn') {
switch($lan) {
case 'en' :{$list = array(0=>'double',1=>'Android',2=>'IOS');}break;
case 'cnen':{$list = array(1=>"安卓",2=>"IOS");}break;
default:$list = array(1=>"安卓",2=>"苹果");
}
return $list;
}
// lwx
function seo_replace($str='',$array=array(),$site='media',$meat='title') {
switch ($site) {
case 'channel':
switch ($meat) {
case 'title':
$title = C('CH_SET_TITLE');
break;
case 'keywords':
$title = C('CH_SET_META_KEY');
break;
case 'description':
$title = C('CH_SET_META_DESC');
break;
default:
$title = C('CH_SET_TITLE');
break;
}
break;
case 'media':
switch ($meat) {
case 'title':
$title = C('PC_SET_TITLE');
break;
case 'description':
$title = C('PC_SET_META_DESC');
break;
default:
$title = C('PC_SET_TITLE');
break;
}
break;
case 'wap':
switch ($meat) {
case 'title':
$title = C('WAP_SET_TITLE');
break;
case 'keywords':
$title = C('WAP_SET_META_KEY');
break;
case 'description':
$title = C('WAP_SET_META_DESC');
break;
default:
$title = C('WAP_SET_TITLE');
break;
}
break;
default:
$title = C('PC_SET_TITLE');
break;
}
if (empty($str)) {return $title;}
$find = array('%webname%','%gamename%','%newsname%','%giftname%','%gametype%', '%catetitle%', '%gamedevice%');
$replace = array($title,$array['game_name'],$array['news_title'],$array['giftbag_name'],$array['game_type_name'],$array['cate_title'],$array['game_device']);
$str = str_replace($find,$replace,$str);
return preg_replace('/((-|_)+)?((%[0-9A-Za-z_]*%)|%+)((-|_)+)?/','',$str);
}
function auto_get_access_token($dirname){
$appid = C('weixin_login.appid');
$appsecret = C('weixin_login.appsecret');
$access_token_validity=file_get_contents($dirname);
if($access_token_validity){
$access_token_validity=json_decode($access_token_validity,true);
$is_validity=$access_token_validity['expires_in_validity']-1000>time()?true:false;
}else{
$is_validity=false;
}
$result['is_validity']=$is_validity;
$result['access_token']=$access_token_validity['access_token'];
return $result;
}
//判断客户端是否是在微信客户端打开
function is_weixin(){
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
return true;
}
return false;
}
/**
* [获取开放类型名称]
* @param string $id [description]
* @return [type] [description]
*/
function get_one_opentype_name($id=''){
if($id==''){
return '';
}
if($id==0){
return "公测";
}
$data=M('Opentype','tab_')->where(array('id'=>$id))->find();
if($data==''){
return false;
}else{
return $data['open_name'];
}
}
/**
* 验证用户是否存在
* @author zc 894827077@qq.com
*/
function is_check_account($account){
$map['account']=$account;
$find=M('user','tab_')->field('id')->where($map)->find();
if(null==$find){
return false;
}else{
return true;
}
}
/**
* 获取游戏列表
* @return arrayfalse
* @author yyh
*/
function get_game_list($type = null,$sdk_type=1)
{
$game = M("game","tab_");
if(MODULE_NAME == 'Admin') {
$map['game_status'] = array('in','0,1');
} else {
$map['game_status'] = 1;
}
if(!empty($type)){
/*$map['developers'] = $type == 1? array('EQ',0):array('GT',0);*/
/* $map['game_status'] = $type == 1? 1:array('in','0,1'); */
switch($type) {
case 1:
$map['developers'] = array('EQ',0);
break;
case 2:
$map['developers'] = array('EGT',0);
break;
default:
$map['developers'] = array('GT',0);
}
}else{
$map['apply_status'] = 1;
$map['online_status'] = 1;
}
if($sdk_type==2){
$map['sdk_version']=1;
} else if ($sdk_type == 3) {
$map['sdk_version']=2;
}
$lists = $game->field('id,game_name,sdk_version,relation_game_name,icon,relation_game_id,game_status,display_site,dow_num')->where($map)->select();
if(empty($lists)){return false;}
return $lists;
}
/**
*根据条件 显示游戏数组
*/
function get_game_list_map($type){
$game = M("game","tab_");
$map['sdk_version'] = $type;
$map['game_status'] = 1;
$lists = $game->field('id,game_name,sdk_version,relation_game_name,icon,relation_game_id,dow_num')->where($map)->select();
if(empty($lists)){return false;}
return $lists;
}
/**
*推广员搜索游戏下拉列表
*/
function get_promote_serach_game_list(){
$game = M("game","tab_");
if(!empty($type)){
$map['developers'] = $type == 1? array('EQ',0):array('GT',0);
$map['game_status'] = $type == 1? 1:array('in','0,1');
}else{
$map['apply_status'] = 1;
$map['online_status'] = 1;
}
$map['down_port'] = 1;
$lists = $game->field('id,game_name,sdk_version,relation_game_name,icon,relation_game_id')->where($map)->select();
if(empty($lists)){return false;}
return $lists;
}
/**
*获取推广员申请的游戏信息和折扣比例
* @param int promote_id 推广员id
* @param string fields 要显示字段
* @return array|bool
*/
function get_apply_game_welfare_list($promote_id,$fields=""){
if(empty($fields)){
$fields = "tab_apply.game_id,
tab_apply.game_name,
tab_apply.promote_id,
tab_apply.promote_account,
tab_apply.`status`,
IF (tab_promote_welfare.promote_discount IS NULL,tab_game.discount,tab_promote_welfare.promote_discount) AS discount";
}
$data = M('Apply','tab_')
->field($fields)
->join('tab_game ON tab_apply.game_id = tab_game.id AND tab_apply.`status` = 1 AND tab_apply.promote_id = '.$promote_id)
->join('tab_promote_welfare ON tab_apply.game_id = tab_promote_welfare.game_id AND tab_apply.promote_id = tab_promote_welfare.promote_id','LEFT')
->select();
if(empty($data)){
return false;
}else{
return $data;
}
}
/**
* 获取申请游戏列表
* @return arrayfalse
* @author yyh
*/
function get_apply_game_list2($promote_id=0)
{
$apply = M('Apply',"tab_");
$map['promote_id'] = $promote_id;
$map['tab_game.online_status']=1;
$lists = $apply
->field("tab_apply.*,tab_game.icon,tab_game.short,tab_game.game_appid,tab_game.discount")
->join("left join tab_game on tab_apply.game_id = tab_game.id")
->where($map)
->order("id DESC")
->select();
if(empty($lists)){return false;}
return $lists;
}
/**
* 获取申请游戏列表
* @return arrayfalse
*/
function get_apply_game_list($promote_id=0)
{
$apply = M('Apply',"tab_");
$map['promote_id'] = $promote_id;
$map['tab_game.online_status']=1;
$map['status'] = 1;
$lists = $apply
->field("tab_apply.*,tab_game.icon,tab_game.short,tab_game.game_appid,tab_game.discount")
->join("left join tab_game on tab_apply.game_id = tab_game.id")
->where($map)
->order("id DESC")
->select();
if(empty($lists)){return false;}
return $lists;
}
/**
* [获取该渠道以及子渠道下的游戏]
* @param int $promote_id
* @return bool
* @author 幽灵[syt]
*/
function get_apply_game_list3($promote_id=0)
{
$apply = M('Apply',"tab_");
$son_promote_id = M('Promote','tab_')->field('id')->where(array('parent_id'=>$promote_id,'status'=>1))->select();
foreach ($son_promote_id as $key => $value){
$arr[] = $son_promote_id[$key]['id'];
}
if (empty($arr)){}
array_push($arr,$promote_id);
$map['promote_id'] = array('in',$arr);
$map['tab_game.online_status']=1;
$map['status'] = 1;
$lists = $apply
->field("tab_apply.*,tab_game.icon,tab_game.short,tab_game.game_appid,tab_game.discount")
->join("left join tab_game on tab_apply.game_id = tab_game.id")
->where($map)
->order("id DESC")
->select();
if(empty($lists)){return false;}
return $lists;
}
/**
* 获取游戏类型列表
* @return arrayfalse
* @author yyh
*/
function get_game_type_all() {
$list = M("Game_type","tab_")->where("status_show=1")->select();
if (empty($list)) {return '';}
return $list;
}
function get_opentype_all() {
$list = M("Opentype","tab_")->where("status=1")->select();
if (empty($list)) {return '';}
return $list;
}
/**
* 生成唯一的APPID
* @param $str_key 加密key
* @return string
* @author 小纯洁
*/
function generate_game_appid($str_key=""){
$guid = '';
$data = $str_key;
$data .= $_SERVER ['REQUEST_TIME'];
$data .= $_SERVER ['HTTP_USER_AGENT'];
$data .= $_SERVER ['SERVER_ADDR'];
$data .= $_SERVER ['SERVER_PORT'];
$data .= $_SERVER ['REMOTE_ADDR'];
$data .= $_SERVER ['REMOTE_PORT'];
$hash = strtoupper ( hash ( 'MD4', $guid . md5 ( $data ) ) ); //ABCDEFZHIJKLMNOPQISTWARY
$guid .= substr ( $hash, 0, 9 ) . substr ( $hash, 17, 8 ) ;
return $guid;
}
// 获取游戏名称
function get_game_name($game_id=null,$field='id'){
$map[$field]=$game_id;
$data=M('Game','tab_')->field('game_name')->where($map)->find();
if(empty($data)){return ' ';}
return $data['game_name'];
}
//获取游戏cp比例
function get_game_selle_ratio($game_id = null, $field = 'id')
{
$map[$field] = $game_id;
$data = M('game', 'tab_')->where($map)->find();
if (empty($data)) {
return '';
}
return $data['ratio'];
}
//获取游戏cp比例
function getGameSelleRatio($promoteId = null, $gameId = null, $field = 'id')
{
$promoteGameRatio = getGameSelleRatioByPromote($promoteId, $gameId);
if ($promoteGameRatio === false) {
$map[$field] = $gameId;
$data = M('game', 'tab_')->where($map)->find();
if (empty($data)) {
return 0;
}
return $data['ratio'];
} else {
return $promoteGameRatio;
}
}
//获取推广员设置的游戏cp比例
function getGameSelleRatioByPromote($promoteId = null, $gameId = null)
{
if (empty($promoteId) || empty($gameId)) {
return false;
}
$promoteId = intval($promoteId);
$gameId = intval($gameId);
$promote = M('promote', 'tab_')->find($promoteId);
if (empty($promote)) {
return false;
}
if ($promote['level'] != 1) {
$chain = explode('/', trim($promote['chain'], '/'));
$promoteId = empty($chain[0]) ? 0 : intval($chain[0]);
}
$map['promote_id'] = $promoteId;
$map['game_id'] = $gameId;
$promoteGameRatio = M('promote_game_ratio', 'tab_')->where($map)->find();
if (empty($promoteGameRatio) || $promoteGameRatio['status'] != 1) {
return false;
}
if ($promoteGameRatio['begin_time'] > time()) {
return false;
}
if (!empty($promoteGameRatio['end_time']) && $promoteGameRatio['end_time'] < time()) {
return false;
}
return $promoteGameRatio['ratio'];
}
/**
* [获取管理员昵称]
* @param integer $id [description]
* @return [yyh] [description]
*/
function get_admin_name($id=0){
if($id==null){
return '';
}
$data = M("Member")->find($id);
if(empty($data)){return "";}
return $data['nickname'];
}
/**
* [获取原包类型]
* @param integer $type [description]
* @return [type] [description]
*/
function file_type($file_type='',$type=0){
if($file_type==''){
return false;
}
if($type){
$file_type==1?$file_type_name='Android':$file_type_name='IOS';
}else{
$file_type==1?$file_type_name="安卓":$file_type_name="苹果";
}
return $file_type_name;
}
/**
* [获取游戏appid]
* @param [type] $game_name [description]
* @param string $field [description]
* @param string $md5 [16位加密]
* @return [type] [description]
* @author yyh <[email address]>
*/
function get_game_appid($game_name=null,$field='game_name',$md5=false){
if($game_name==null){
return false;
}
$map[$field]=$game_name;
$data=M('Game','tab_')->where($map)->find();
if(empty($data)){return false;}
if($md5){
return md5($data['game_appid']);
}else{
return $data['game_appid'];
}
}
/**
* [字符串转数组 计算个数]
* @param [type] $string [description]
* @return [type] [description]
*/
function arr_count($string){
if($string){
$arr=explode(',',$string);
$cou=count($arr);
}else{
$cou=0;
}
return $cou;
}
function get_operation_platform($id,$table,$field='id'){
if(!$table||!$id){
return false;
}
$model=M($table,'tab_');
$map[$field]=$id;
$data = $model->where($map)->find();
if(empty($data)){
return false;
}else{
if($data['giftbag_version']==0){
return '双平台';
}elseif($data['giftbag_version']==1){
return "安卓";
}elseif($data['giftbag_version']==2){
return "苹果";
}
}
}
/**
* [获取渠道名称]
* @param integer $prmote_id [description]
* @return [type] [description]
*/
function get_promote_name($prmote_id=0){
if($prmote_id==0){
return "官方渠道";
}
$promote = M("promote","tab_");
$map['id'] = $prmote_id;
$data = $promote->where($map)->find();
if(empty($data)){return "官方渠道";}
if(empty($data['account'])){return "未知推广";}
$result = $data['account'];
return $result;
}
/**
* [获取开发商名称]
* @param integer $prmote_id [description]
* @return [type] [description]
*/
function get_developer_name($develop_id=0){
if($develop_id==0){
return '无';
}
$promote = M("developers","tab_");
$map['id'] = $develop_id;
$data = $promote->where($map)->find();
if(empty($data)){return '无';}
if(empty($data['nickname'])){return "";}
$result = $data['nickname'];
return $result;
}
/**
* [获取开发商账户]
* @param integer $prmote_id [description]
* @return [type] [description]
*/
function get_developer_account($develop_id=0){
if($develop_id==0){
return '无';
}
$promote = M("developers","tab_");
$map['id'] = $develop_id;
$data = $promote->where($map)->find();
if(empty($data)){return '无';}
if(empty($data['account'])){return "";}
$result = $data['account'];
return $result;
}
/**
* [根据渠道id 获取上线渠道id]
* @param [type] $id [description]
* @return [type] [description]
*/
function get_parent_id($param,$type='id'){
$map[$type]=$param;
$pdata=M('Promote','tab_')->where($map)->find();
if(empty($pdata)){
return false;
}else{
$p_id=$pdata['parent_id'];
return $p_id;
}
}
/**
* [pay_way description]
* @param [type] $pay_way [description]
* @return [type] [description]
*/
function pay_way($pay_way){
if($pay_way==-1){
return '绑定平台币';
}
if($pay_way==0){
return "平台币";
}
if($pay_way==1){
return "支付宝";
}
if($pay_way==2){
return "微信";
}
if($pay_way==3){
return "苹果支付";
}
}
function get_subordinate_promote($param,$type="parent_id"){
if($param==''){
return false;
}
$map[$type]=$param;
$data=M('Promote','tab_')
->field('account')
->where($map)
->select();
return array_column($data,'account');
}
function get_subordinate_promote_($param){
if($param==''){
return false;
}
$map['parent_name'] = $param;
$map['grand_account'] = $param;
$map['_logic'] = 'or';
$data=M('Promote','tab_')
->field('account')
->where($map)
->select();
return array_column($data,'account');
}
/**
* [二维数组 按照某字段排序]
* @param [type] $arrays [description]
* @param [type] $sort_key [description]
* @param [type] $sort_order [description]
* @param [type] $sort_type [description]
* @return [type] [description]
*/
function my_sort($arrays,$sort_key,$sort_order=SORT_ASC,$sort_type=SORT_NUMERIC ){
if(is_array($arrays)){
foreach ($arrays as $array){
if(is_array($array)){
$key_arrays[] = $array[$sort_key];
}else{
return false;
}
}
}else{
return false;
}
array_multisort($key_arrays,$sort_order,$sort_type,$arrays);
return $arrays;
}
/**
* [判断结算时间是否合法]
* @param [type] $start [description]
* @param [type] $promote_id [description]
* @param [type] $game_id [description]
* @return [type] [description]
*/
function get_settlement($start,$end,$promote_id,$game_id){
$start=strtotime($start);
$end=strtotime($end)+24*60*60-1;
$map['promote_id']=$promote_id;
$map['game_id']=$game_id;
$data=M('settlement','tab_')
->where($map)
->select();
foreach ($data as $key => $value) {
if($start<$value['endtime']){
if($end>$value['starttime']){
return true;//开始时间<结算 不可结算
}
}
}
return false;
}
/**
*随机生成字符串
*@param $len int 字符串长度
*@return string
*@author 小纯洁
*/
function sp_random_string($len = 6) {
$chars = array(
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
"l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
"w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
"H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
"S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
"3", "4", "5", "6", "7", "8", "9"
);
$charsLen = count($chars) - 1;
shuffle($chars); // 将数组打乱
$output = "";
for ($i = 0; $i < $len; $i++) {
$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
/**
*随机生成字符串
*@param $len int 字符串长度
*@return string
*@author 小纯洁
*/
function sp_random_num($len = 5) {
$chars = array(
"0", "1", "2","3", "4", "5", "6", "7", "8", "9"
);
$charsLen = count($chars) - 1;
shuffle($chars); // 将数组打乱
$output = "";
for ($i = 0; $i < $len; $i++) {
$output .= $chars[mt_rand(0, $charsLen)];
}
return $output;
}
/**
* [获取合作模式]
* @param [type] $type [description]
* @return [type] [description]
*/
function get_pattern($type){
if($type==0){
return "CPS";
}else{
return "CPA";
}
}
/**
*获取绑币范畴
*/
function get_bind_coin_status($type=0){
switch ($type) {
case 0:
$result = "排除绑币";
break;
case 1:
$result = "包含绑币";
break;
}
return $result;
}
/**
* [获取日期时间戳]
* @param [type] $type [description]
* @return [type] [description]
*/
function total($type,$str=true) {
switch ($type) {
case 1: { // 今天
$start=mktime(0,0,0,date('m'),date('d'),date('Y'));
$end=mktime(0,0,0,date('m'),date('d')+1,date('Y'))-1;
};break;
case 2: { // 本周
// $start=mktime(0, 0 , 0,date("m"),date("d")-date("w")+1,date("Y"));
// $end=mktime(23,59,59,date("m"),date("d")-date("w")+7,date("Y"));
//当前日期
$sdefaultDate = date("Y-m-d");
//$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
$first=1;
//获取当前周的第几天 周日是 0 周一到周六是 1 - 6
$w=date('w',strtotime($sdefaultDate));
//获取本周开始日期,如果$w是0则表示周日减去 6 天
$week_start=date('Y-m-d',strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days'));
//本周结束日期
$week_end=date('Y-m-d',strtotime("$week_start +6 days"));
//当前日期
$sdefaultDate = date("Y-m-d");
//$first =1 表示每周星期一为开始日期 0表示每周日为开始日期
$first=1;
//获取当前周的第几天 周日是 0 周一到周六是 1 - 6
$w=date('w',strtotime($sdefaultDate));
//获取本周开始日期,如果$w是0则表示周日减去 6 天
$start=strtotime("$sdefaultDate -".($w ? $w - $first : 6).' days');
//本周结束日期
$end=$start+7*24*60*60-1;
};break;
case 3: { // 本月
$start=mktime(0,0,0,date('m'),1,date('Y'));
$end=mktime(0,0,0,date('m')+1,1,date('Y'))-1;
};break;
case 4: { // 本年
$start=mktime(0,0,0,1,1,date('Y'));
$end=mktime(0,0,0,1,1,date('Y')+1)-1;
};break;
case 5: { // 昨天
$start=mktime(0,0,0,date('m'),date('d')-1,date('Y'));
$end=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
};break;
case 6: { // 上周
$start=mktime(0, 0 , 0,date("m"),date("d")-date("w")+1-7,date("Y"));
$end=mktime(23,59,59,date("m"),date("d")-date("w")+7-7,date("Y"));
};break;
case 7: { // 上月
$start=mktime(0, 0 , 0,date("m")-1,1,date("Y"));
$end=mktime(23,59,59,date("m") ,0,date("Y"));
};break;
case 8: { // 上一年
$start=mktime(0,0,0,date('m')-11,1,date('Y'));
$end=mktime(0,0,0,date('m')+1,1,date('Y'))-1;
};break;
case 9: { // 前七天
$start = mktime(0,0,0,date('m'),date('d')-6,date('Y'));
$end=mktime(23,59,59,date('m'),date('d'),date('Y'));
};break;
case 10: { // 前30天
$start = mktime(0,0,0,date('m'),date('d')-29,date('Y'));
$end=mktime(23,59,59,date('m'),date('d'),date('Y'));
};break;
default:
$start='';$end='';
}
if($str){
return " between $start and $end ";
}else{
return ['between',[$start,$end]];
}
}
/**
* [null_to_0 description]
* @param [type] $num [description]
* @return [type] [description]
*/
function null_to_0($num){
if($num){
return sprintf("%.2f",$num);
}else{
return sprintf("%.2f",0);
}
}
function get_game_limit_name($game_id){
if (empty($game_id)) {
return '全部游戏';
} else {
$game = M("game", "tab_");
$map['game_status'] = 1;
$lists = $game->where($map)->find();
if (empty($lists)) {
return '';
}
return $lists['game_name'];
}
}
/**
* [获取用户实体]
* @param integer $id [description]
* @param boolean $isAccount [description]
* @return [yyh] [description]
*/
function get_user_entity($id=0,$isAccount = false){
if($id =='' ){
return false;
}
$user = M('user',"tab_");
if($isAccount){
$map['account'] = $id;
$data = $user->where($map)->find();
}
else{
$data = $user->find($id);
}
if(empty($data)){
return false;
}
return $data;
}
function get_user_account_by_id($id=0) {
if(!is_numeric($id) || $id < 1 ){
return '';
}
$data = M('user',"tab_")->field('account')->find($id);
if(empty($data)){
return '';
}
return $data['account'];
}
/**
* [两个运营平台的游戏合并]
* @param [type] $data [最新添加的游戏]
* @param [type] $map [description]
* @return [type] [游戏信息]
*/
function game_merge($data,$map){
$model=M('Game','tab_');
for ($i=0; $i <count($data); $i++) {
if($data[$i]['sdk_version']==2){
$data[$i]['and_id']='';
$data[$i]['and_dow_address']='';
$data[$i]['add_game_address']='';
$data[$i]['ios_id']=$data[$i]['id'];
$data[$i]['iosdow']=$data[$i]['dow_num'];
$data[$i]['iosdowstatus']=$data[$i]['dow_status'];
}else if($data[$i]['sdk_version']==1){
$data[$i]['ios_id']='';
$data[$i]['ios_dow_address']='';
$data[$i]['ios_game_address']='';
$data[$i]['and_id']=$data[$i]['id'];
$data[$i]['anddow']=$data[$i]['dow_num'];
$data[$i]['anddowstatus']=$data[$i]['dow_status'];
}
if($data[$i]['relation_game_id']!=$data[$i]['id']){
//最新添加的游戏id和关联游戏id不一致 即不止一个游戏
$sibling_id=$data[$i]['relation_game_id'];
$map['id']=array('eq',$sibling_id);//id不等于关联id(第一个)
$map['relation_game_id']=$sibling_id;
}else{
//最新添加的游戏和关联游戏一致 即只有一个游戏 下面代码可以屏蔽
$sibling_id=$data[$i]['id'];
$map['id']=array('neq',$sibling_id);
$map['relation_game_id']=$data[$i]['relation_game_id'];
}
$game_data=$model->where($map)->find();
if($game_data['sdk_version']==2){
$data[$i]['ios_id']=$game_data['id'];
$data[$i]['ios_dow_address']=$game_data['ios_dow_address'];
$data[$i]['ios_game_address']=$game_data['ios_game_address'];
$data[$i]['iosdow']=$data[$i]['dow_num'];
$data[$i]['iosdowstatus']=$game_data['dow_status'];
}else if ($game_data['sdk_version']==1){
$data[$i]['and_id']=$game_data['id'];
$data[$i]['and_dow_address']=$game_data['and_dow_address'];
$data[$i]['add_game_address']=$game_data['add_game_address'];
$data[$i]['anddow']=$data[$i]['dow_num'];
$data[$i]['anddowstatus']=$game_data['dow_status'];
}
}
return $data;
}
/**
* [获取文本 超过字数显示..]
* @param [type] $title [description]
* @return [type] [description]
*/
function get_title($title,$len=30){
if(mb_strlen($title,'utf8') > $len){
$title = mb_substr($title,0,$len,'utf-8').'...';
}else{
$title = $title;
}
if(empty($title)){return false;}
return $title;
}
/**
* [游戏某一礼包所有激活码个数(未领取和已领取)]
* @param [type] $gid [游戏id]
* @param [type] $gift_id [礼包 id]
* @return [type] [description]
*/
function gift_recorded($gid,$gift_id){
$wnovice=M('giftbag','tab_')->where(array('game_id'=>$gid,'id'=>$gift_id))->find();
if($wnovice['novice']!=''){
$wnovice=count(explode(',',$wnovice['novice']));
}else{
$wnovice=0;
}
$ynpvice=M('gift_record','tab_')->where(array('game_id'=>$gid,'gift_id'=>$gift_id))->select();
if($ynpvice!=''){
$ynpvice=count($ynpvice);
}else{
$ynpvice=0;
}
$return['all']=$wnovice+$ynpvice;
$return['wei']=$wnovice;
return $return;
}
/**
* [获取26个字母]
* @return array
*/
function zimu26(){
for($i=0;$i<26;$i++){
$zimu[]['value']=chr($i+65);
}
return $zimu;
}
/**
* [获取礼包列表]
* @param string $game_id
* @param string $limit
* @return mixed
*/
function get_gift_list($game_id='all',$limit="",$display_site=''){
$map['status'] = 1;
$map['game_status']=1;
empty($display_site) || $map['display_site'] = ['like','%' . $display_site . '%'];
$map['end_time']=array(array('gt',time()),array('eq',0),'or');
if($game_id!='all'){
$map['game_id']=$game_id;
}
$model = array(
'm_name'=>'Giftbag',
'prefix'=>'tab_',
'field' =>'tab_giftbag.id as gift_id,relation_game_name,game_id,tab_giftbag.game_name,giftbag_name,giftbag_type,tab_game.icon,tab_giftbag.create_time',
'join' =>'tab_game on tab_giftbag.game_id = tab_game.id',
'order' =>'create_time desc',
);
if(!empty($limit)){
$map_list=$limit;
}
$game = M($model['m_name'],$model['prefix']);
$data = $game
->field($model['field'])
->join($model['join'])
->where($map)
->limit($map_list)
->order($model['order'])
->select();
return $data;
}
function shuffle_assoc($list) {
if (!is_array($list)) return $list;
$keys = array_keys($list);
shuffle($keys);
$random = array();
foreach ($keys as $key)
$random[$key] = $list[$key];
return $random;
}
//获取推广员父类id
function get_fu_id($id){
$map['id']=$id;
$pro=M("promote","tab_")->where($map)->find();
if(null==$pro||$pro['parent_id']==0){
return 0;
}else{
return $pro['parent_id'];
}
}
function get_parent_name($id){
$map['id']=$id;
$pro=M("promote","tab_")->where($map)->find();
if(null!=$pro&&$pro['parent_id']>0){
$pro_map['id']=$pro['parent_id'];
$pro_p=M("promote","tab_")->where($pro_map)->find();
return $pro_p['account'];
}else if($pro['parent_id']==0){
return $pro['account'];
}else{
return false;
}
}
/**
* [用于统计排行 给根据某一字段倒序 获得的结果集插入排序字段 ]
* @param [type] $arr [description]
* @return [type] [description]
*/
function array_order($arr){
foreach ($arr as $key => $value) {
$arr[$key]['rand']=++$i;
}
return $arr;
}
/**
*将时间戳装成年月日(不同格式)
*@param int $time 要转换的时间戳
*@param string $date 类型
*@return string
*/
function set_show_time($time = null,$type='time',$tab_type=''){
$date = "";
// switch ($type) {
// case 'date':
// $date = date('Y-m-d ',$time);
// break;
// case 'time':
// $date = date('Y-m-d H:i',$time);
// break;
// default:
// $date = date('Y-m-d H:i:s',$time);
// break;
// }
$date = date('Y-m-d H:i:s',$time);
if(empty($time)){//若为空 根据不同情况返回
if($tab_type==''){
return "暂无登录";
}
if($tab_type=='forever'){
return "永久";
}
if($tab_type=='other'){
return "";
}
}
return $date;
}
//判断支付设置
//yyh
function pay_set_status($type){
$sta=M('tool','tab_')->field('status')->where(array('name'=>$type))->find();
return $sta['status'];
}
//获取微信支付类型 0官方 1 威富通 2俊付通wap 3金猪wap
function get_wx_type(){
if(MODULE_NAME=='Media'||MODULE_NAME=='Media2'||MODULE_NAME=='Home'){
$map['name']=array('in',array('wei_xin','weixin','weixin_gf'));
}elseif(MODULE_NAME=='Sdk'){
$map['name']=array('in',array('wei_xin_app','weixin','weixin_gf','jft_wap','goldpig'));
}elseif(MODULE_NAME=='App'){
$map['name']=array('in',array('wei_xin_apps','weixin_app'));
}
$type=M('Tool','tab_')->where($map)->select();
foreach ($type as $k => $v) {
if($v['status']==1){
$name=$v['name'];
}
}
if($name=="weixin"){
return 1;
}elseif($name=="weixin_gf"){
return 1;
}elseif($name=="jft_wap"){
return 2;
}elseif($name=="goldpig" && C('goldpig.wx')){
return 3;
}else{
return 0;
}
}
function get_wx_pay_type($flag=0) {
if(MODULE_NAME=='Media'||MODULE_NAME=='Media2'||MODULE_NAME=='Home'){
$map['name']=array('in',array('wei_xin','weixin','weixin_gf'));
}elseif(MODULE_NAME=='Sdk'){
if($flag==1) {
$map['name']=array('in',array('wei_xin_app','weixin','jft_wap','weixin_gf','goldpig'));
} else {
$map['name']=array('in',array('wei_xin_app','wei_xin','weixin','jft_wap','weixin_gf','goldpig','heepay'));
}
}elseif(MODULE_NAME=='App'){
$map['name']=array('in',array('wei_xin_apps','weixin_app'));
}
$map['status'] =1;
$type=M('Tool','tab_')->field('*')->where($map)->select();
$name = array_column($type,'name');
//0 官方 1威富通 2俊付通 4 双乾小程序
if(in_array('wei_xin_app',$name) || in_array('wei_xin',$name)) {
return 0;
} else if(in_array('heepay',$name)) {
return 1;
} else if(in_array('jft_wap',$name)) {
return 2;
} else if(in_array('weixin_gf',$name)) {
return 1;
} else if(in_array('goldpig',$name) && C('goldpig.wx')) {
return 3;
} else if(in_array('sqpay',$name) && C('sqpay.wx_small')) {
return 4;
}else {
return 0;
}
}
//获取银联支付类型 0官方 1双乾wap 暂时只有双乾
function get_union_pay_type(){
$map['name']='sqpay';
$type=M('Tool','tab_')->field('status')->where($map)->find();
if($type['status']==1 && C('sqpay.union')){
return 1;
}else{
return 0;
}
}
//获取快捷支付类型 0官方 1双乾wap 暂时只有双乾
function get_shortcut_pay_type(){
$map['name']='sqpay';
$type=M('Tool','tab_')->field('status')->where($map)->find();
if($type['status']==1 && C('sqpay.shortcut')){
return 1;
}else{
return 0;
}
}
//获取微信支付类型 0官方 1金猪wap 2双乾
function get_zfb_type(){
if(C('alipay.status') == 1) {return 0;}
$map['name']='goldpig';
$type=M('Tool','tab_')->field('status')->where($map)->find();
if($type['status']==1 && C('goldpig.zfb')){
return 1;
}else{
$map['name']='sqpay';
$type=M('Tool','tab_')->field('status')->where($map)->find();
if($type['status']==1 && C('sqpay.zfb')) return 2;
return 0;
}
}
/**
* 威富通选择
* @return [type] [中信 1 官方 2]
*/
function wft_status(){
$map['name']=array('like','%weixin%');
$map['status']=1;
$type=M('Tool','tab_')->where($map)->find();
if($type['name']=="weixin"){
return 1;
}else{
return 2;
}
}
//app微信支付类型
function get_weixin_type(){
$map['name']=array('like','%wei%');
$type=M('Tool','tab_')->where($map)->select();
foreach ($type as $k => $v) {
if($v['status']==1){
$name=$v['name'];
}
}
return $name=="wei_xin_apps"?0:1;
}
//查询uc用户是否存在该平台
function find_uc_account($name){
$map['account']=trim($name);
$user=M('user','tab_')->where($map)->find();
if(null==$user){
return false;
}else{
return $user;
}
}
/**
*检查链接地址是否有效
*/
function varify_url($url){
$check = @fopen($url,"r");
if($check){
$status = true;
}else{
$status = false;
}
return $status;
}
//获取当前推广员id
function get_pid()
{
return $_SESSION['onethink_home']['promote_auth']['pid'];
}
// //计算数组个数用于模板
function arr_count1($string){
if($string){
$arr=explode(',',$string);
$cou=count($arr);
}else{
$cou=0;
}
return $cou;
}
/**
* 获取新推广权限后 底下推广员子账号
* @param int $id 推广员id
* @param array,string 查询字段
* @return array
*/
function getPrmoteChlidAccount($id=0,$field="*")
{
$promote = M("promote","tab_");
//获取自己的等级
$self = $promote->field("chain,level")->where("id = '{$id}'")->find();
if($self['chain'] == "/"){
$self['chain'] = "/".$id."/";
}
$map['status'] = 1;
$map["chain"] = array("LIKE","%{$self['chain']}%");
$map["level"] = array("GT",$self['level']);
$data = $promote->field($field)->where($map)->select();
if(empty($data)){return array();}
return $data;
}
/**
*获取推广员子账号
*/
function get_prmoote_chlid_account($id=0){
$promote = M("promote","tab_");
$map['status'] = 1;
$map["parent_id"] = $id;
$data = $promote->where("(parent_id = $id or grand_id = $id) and status = 1")->select();
if(empty($data)){return "";}
return $data;
}
function get_prmoote_chlid_account2($id=0){
$promote = M("promote","tab_");
$map['status'] = 1;
if(is_numeric($id)) {
$map["_complex"] = [
'parent_id'=>$id,
'grand_id'=>$id,
'_logic'=>'or',
];
} else {
$map["_complex"] = [
'parent_id'=>array('in',$id),
'grand_id'=>array('in',$id),
'_logic'=>'or',
];
}
$data = $promote->where($map)->select();
if(empty($data)){return "";}
return $data;
}
function get_promote_chlid_account($id=0){
$promote = M("promote","tab_");
$map['status'] = 1;
$map["parent_id"] = $id;
$data = $promote->where($map)->select();
if(empty($data)){return "";}
return $data;
}
/**
*获取推广员父类账号 改写
*@param $promote_id 推广id
*@param $isShow bool
*@return string
*@author yyh
*/
function get_parent_promote_($prmote_id=0,$isShwo=true)
{
$promote = M("promote","tab_");
$map['id'] = $prmote_id;//本推广员的id
$data1 = $promote->where($map)->find();//本推广员的记录
if(empty($data1)){return false;}
if($data1['parent_id']==0){return false;}
if($data1['parent_id']){
$map1['id']=$data1['parent_id'];
}
$data = $promote->where($map1)->find();//父类的记录
$result = "";
if($isShwo){
$result = "[{$data['account']}]";
}
else{
$result = $data['account'];
}
return $result;
}
//获取当前子渠道,推广员列表不用过滤锁定的推广员
function get_zi_promote_id($id, $status = 1){
// $map['parent_id']=$id;
// $map['grand_id'] = $id;
// $map['_logic'] = 'or';
// $pro=M("promote","tab_")->field('id')->where($map)->select();
// if(null==$pro){
// return 0;
// }else{
// for ($i=0; $i <count($pro); $i++) {
// $sd[]=implode(",", $pro[$i]);
// }
// return implode(",", $sd);
// }
$promote = M("promote","tab_");
//获取自己的等级
$self = $promote->field("chain,level")->where("id = '{$id}'")->find();
if ($self['level'] == 1) {
$self['chain'] = "/{$id}/";
}
if ($status)
$map['status'] = $status;
$map["chain"] = array("LIKE","%{$self['chain']}%");
$map["level"] = array("GT",$self['level']);
$data = $promote->field("id")->where($map)->select();
if(empty($data)){return array();}
$data = implode(",",array_column($data,"id"));
return $data;
}
/**
* 获取子渠道
* @param $id 渠道编号
* @param $grade 渠道等级1:一级2:二级3:三级)
* @param $flag 是否此渠道加入进去1:不需要0:需要)
* @return array / string
* @author 鹿文学
*/
function get_sub_channel_id($id,$grade=1,$flag=0) {
if(is_numeric($id) && $id>=0) {
switch($grade) {
case 0:
case 1:{
$map['parent_id']=$id;
$map['grand_id'] = $id;
$map['_logic'] = 'or';
$pro=M("promote","tab_")->field('id')->where($map)->select();
if(is_array($pro)) {
return $flag?array_column($pro,'id'):array_merge([$id],array_column($pro,'id'));
} else {
return $flag?'':[$id];
}
};break;
case 2:{
$map['parent_id']=$id;
$pro=M("promote","tab_")->field('id')->where($map)->select();
if(is_array($pro)) {
return $flag?array_column($pro,'id'):array_merge([$id],array_column($pro,'id'));
} else {
return $flag?'':[$id];
}
};break;
default:
if(!$flag) {return [$id];} else {return '';}
}
} else {
return '';
}
}
/**
* 折扣信息
* @param $data
* @return mixed
*/
function discount_data($data){
if($data['recharge_status'] != 1){
$pw = M('promote_welfare','tab_')->find($data['id']);
$game_discount = $pw['game_discount'];
$data['promote_discount'] = $game_discount;
}
if($data['promote_status'] != 1 || empty($data['first_discount'])){
$data['first_discount'] = 10;
}
if($data['cont_status'] != 1 || empty($data['continue_discount'])){
$data['continue_discount'] = 10;
}
$user = M('User','tab_')->field('promote_id')->find($data['user_id']);
switch ($data['promote_id']) {
case 0://官方玩家
if(!empty($user['promote_id'])){
$data['first_discount'] = 10;
$data['continue_discount'] = 10;
}
break;
case 1://推广渠道
if(empty($user['promote_id'])){
$data['first_discount'] = 10;
$data['continue_discount'] = 10;
}
break;
}
return $data;
}
/**
*设置状态文本
*/
function get_status_text($index=1,$mark=1){
$data_text = array(
0 => array( 0 => '失败' ,1 => '成功'),
1 => array( 0 => L('Lock') ,1 => "正常"),
2 => array( 0 => '未申' ,1 => '已审' , 2 => '拉黑'),
3 =>array(0=>'不参与',1=>'已参与'),
4 => ['系统','上级渠道'],
);
return $data_text[$index][$mark];
}
//获取推广员帐号
function get_promote_account($promote_id){
if($promote_id == 0){
return "官方渠道";
}elseif ($promote_id==-1){
return '全平台用户';
}elseif($promote_id == -2){
return '推广渠道';
}
$data = M('promote','tab_')->find($promote_id);
$account = empty($data['account']) ? '系统' : $data['account'];
return $account;
}
function get_promote_id_by_account($promote_account,$flag=0) {
if(!empty($promote_account)) {
if($flag==1) {
$map['account'] = ['like','%'.$promote_account.'%'];
$result = M('promote','tab_')->field('id')->where($map)->select();
return array_column($result,'id');
} else {
$map['account'] = $promote_account;
$result = M('promote','tab_')->field('id')->where($map)->find();
return $result['id'];
}
} else {
return 0;
}
}
/**
* 获取推广员支付宝账号
*/
function get_promote_alipay_account($promote_id){
$data = M('promote','tab_')->find($promote_id);
$account = empty($data['alipay_account']) ? '未知' : $data['alipay_account'];
return $account;
}
/**
* 获取推广员微信账号
*/
function get_promote_weixin_account($promote_id){
$data = M('promote','tab_')->find($promote_id);
$account = empty($data['weixin_account']) ? '未知' : $data['weixin_account'];
return $account;
}
/**
* 获取渠道等级
* @param $promote_id
* @return mixed
*/
function get_promote_level($promote_id){
$model = M('promote','tab_');
$map['id'] = $promote_id;
$data = $model->where($map)->find();
if(empty($data)){
return '';
}
if($data['parent_id'] == 0) {
return '1';
} elseif($data['parent_id']>0 && $data['grand_id'] == 0) {
return 2;
} else {
return 3;
}
}
//获得当前的脚本网址
function GetCurUrl()
{
if(!empty($_SERVER["REQUEST_URI"]))
{
$scriptName = $_SERVER["REQUEST_URI"];
$nowurl = $scriptName;
} else
{
$scriptName = $_SERVER["PHP_SELF"];
if(empty($_SERVER["QUERY_STRING"]))
{
$nowurl = $scriptName;
} else
{
$nowurl = $scriptName."?".$_SERVER["QUERY_STRING"];
}
}
return $nowurl;
}
/**
* [获取游戏原包数据]
* @param [type] $and_id [安卓版本id]
* @param [type] $ios_id [苹果版本id]
* @return [type] [description]
* @author [yyh] <[email address]>
*/
function get_game_source($and_id,$ios_id){
$model = M('Game_source','tab_');
if($and_id&&$ios_id){
$map['game_id']=array('in',$and_id.','.$ios_id);
}else if($and_id||$ios_id){
if($and_id){
$map['game_id']=$and_id;
}else{
$map['game_id']=$ios_id;
}
}else{
return false;
}
$data=$model->where($map)->select();
foreach ($data as $key => $value) {
if($value['game_id']==$and_id){
$dataa['and_id']=$data[$key];
}
if($value['game_id']==$ios_id){
$dataa['ios_id']=$data[$key];
}
}
return $dataa;
}
/**
* [获取扩展状态]
* @param [type] $name [description]
* @return [type] [description]
*/
function get_tool_status($name){
$map['name']=$name;
$tool=M("tool","tab_")->where($map)->find();
return $tool['status'];
}
//二级推广员id
function get_child_ids($id){
$map1['parent_id']=$id;
$map1['id']=$id;
$map1['_logic']='OR';
$arr1=M('promote','tab_')->where($map1)->field('id')->select();
if($arr1){
return $arr1;
}else{
return false;
}
}
//获取图片连接
function icon_url($value){
if (C('OSS_STATUS')){
$url = get_cover($value, 'path');
} else {
$url = 'http://' . $_SERVER['HTTP_HOST'] . get_cover($value, 'path');
}
return $url;
}
//获取图片连接 发布出现纯域名情况
function new_icon_url($value){
$cover = get_cover($value, 'path');
if(strpos($cover, 'http')!==false){
$url = $cover;
}elseif(!$cover){
$url = '';
}else{
$url = 'http://'.$_SERVER['HTTP_HOST'].$cover;
}
return $url;
}
//获取广告数据
function get_adv_data($pos_name){
$adv = M("Adv","tab_");
$map['tab_adv.status'] = 1;
$map['p.name'] = $pos_name;
$map['tab_adv.start_time']=array(array('lt',time()),array('eq',0), 'or') ;
$map['tab_adv.end_time']=array(array('gt',time()),array('eq',0), 'or') ;
$data = $adv
->field('tab_adv.*,p.width,p.height,p.name')
->where($map)
->join("right join tab_adv_pos as p on p.id = tab_adv.pos_id")
->order('sort desc')
->select();
return $data;
}
//获取指定文件夹内文件数量
function getfilecounts($ff){
$dir = './'.$ff;
$handle = opendir($dir);
$i = 0;
while(false !== $file=(readdir($handle))){
if($file !== '.' && $file != '..')
{
$i++;
}
}
closedir($handle);
return $i;
}
/**
* [获取ios包的状态]
* @param $game_id
* @param $promote_id
* @return int
*/
function get_iospack_status($game_id,$promote_id){
$map['channelid']=$promote_id;
$map['game_id']=$game_id;
$find=M('iospacket')->where($map)->find();
if(null==$find){
return 0;
}elseif ($find['status']!=="0"&&$find['status']!=="2") {
return 0;
}elseif ($find['status']!=="0"&&$find['status']=="2") {
return 2;
}
elseif ($find['status']=="0") {
return 1;
}
}
/**
* 获取所有开发者信息
* @return [type] [description]
*/
function get_developers_list(){
$list = M("developers","tab_")->select();
if (empty($list)){return '';}
return $list;
}
//获取指定开发者账户
function get_developers_account($id=0,$fields=true){
$data = M('developers','tab_')->field($fields)->find($id);
if(empty($data)){
return false;
}else{
return $fields === true ? $data : $data[$fields];
}
}
function get_developers_account_log($id=0){
$data = M('developers','tab_')->field('account')->find($id);
if(empty($data)){
return false;
}else{
return $data['account'];
}
}
//sdk加密方法
function get_ss($key){
$verfy_key="gnauhcgnem";
$len=strlen($key);
$res="";
for ($i=0; $i <$len; $i++) {
if($i<11){
$a=0;
}else{
$a=-1;
}
$res.=chr(ord($key[$i])^ord($verfy_key[$i%10+$a]));
}
return base64_encode($res);
}
// lwx 获取游戏类型名称
function get_game_type_name($type = null){
if(!isset($type) || empty($type)){
return '全部';
}
$cl = M("game_type","tab_")->where("id={$type}")->limit(1)->select();
return $cl[0]['type_name'];
}
/**
* 获取退款商户订单
* @param [type] $order [description]
* @return [type] [description]
*/
function get_refund_pay_order_number($order)
{
$map['order_number']=$order;
$find=M('refund_record','tab_')->where($map)->find();
return $find['pay_order_number'];
}
/* 获取时间闭合区间 @author 鹿文学 */
function period($flag=0,$opposite=true) {/* 0:今日1昨天 4:本周 5:上周 8:本月 9:上月*/
switch($flag) {
case 0:
case 1:{
$start = mktime(0,0,0,date('m'),date('d')-$flag,date('Y'));
$end = mktime(0,0,0,date('m'),date('d')-$flag+1,date('Y'))-1;
};break;
case 3:
case 7:{
$start = mktime(0,0,0,date('m'),date('d')-$flag,date('Y'));
$end = mktime(0,0,0,date('m'),date('d'),date('Y'))-1;
};break;
case 4:{
$start = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('Y'));
$end = mktime(0,0,0,date('m'),date('d')-date('w')+8,date('Y'))-1;
};break;
case 5:{
$start = mktime(0,0,0,date('m'),date('d')-date('w')-6,date('Y'));
$end = mktime(0,0,0,date('m'),date('d')-date('w')+1,date('Y'))-1;
};break;
case 8: {
$start = mktime(0,0,0,date('m'),1,date('Y'));
$end = mktime(0,0,0,date('m')+1,1,date('Y'))-1;
};break;
case 9: {
$start = mktime(0,0,0,date('m')-1,1,date('Y'));
$end = mktime(0,0,0,date('m'),1,date('Y'))-1;
};break;
}
if ($opposite)
return array(array('egt',$start),array('elt',$end));
else
return array(array('elt',$start),array('egt',$end));
}
/**
*商务专员列表
* @author 小纯洁
*/
function get_business_affairs_list(){
$BusinessAffairs = M("BusinessAffairs","tab_");
$lists = $BusinessAffairs->field('id,account')->select();
if(empty($lists)){return false;}
return $lists;
}
/**
*商务专员列表
* @author 小纯洁
*/
function get_business_affairs_account($id){
$BusinessAffairs = M("BusinessAffairs","tab_");
$map['id']=$id;
$lists = $BusinessAffairs->field('account')->where($map)->find();
if(empty($lists)){return '暂无';}
return $lists['account'];
}
/**
* 获取商务专员下渠道id
* @author zc <894827077@qq.com>
*/
function get_business_affairs_pid(){
$BusinessAffairs = M("BusinessAffairs","tab_");
$lists = $BusinessAffairs->field('promote_id')->where($map)->find();
if(empty($lists)){return false;}
return $lists['prmote_id'];
}
/**
* 检测该渠道是否申请某个游戏
* @param [type] $pid [description]
* @return boolean [description]
*/
function is_check_apply_promote($gid,$pid){
$map['promote_id']=$pid;
$map['game_id']=$gid;
$map['status']=1;
$find=M('apply','tab_')->field('id')->where($map)->find();
if(null==$find){
return false;
}else{
return true;
}
}
/**
* 获取游戏原包路径
* @return [type] [description]
* @author zc 894827077@qq.com
*/
function get_game_source_file_url($game_id){
$map['game_id']=$game_id;
$find=M('game_source','tab_')->field('file_name,file_url,file_type')->where($map)->find();
if($find['file_type']=='1'){
$path = './Uploads/SourcePack/';
}else{
$path = './Uploads/Ios/original/';
}
$file_url = $path.$find['file_name'];
return ROOTTT.ltrim($file_url,'./');
}
/**
* 获取游戏区服列表
* @return arrayfalse
* @author yyh
*/
function get_server_list($game_id = 0)
{
$server = M("server","tab_");
$map['game_id'] = $game_id;
$lists = $server->field('id,server_name,game_name')->where($map)->select();
if(empty($lists)){return false;}
return $lists;
}
//根据name获得相关seo设置内容
function get_seo_set($name){
$map['name'] = $name;
$data = M('Seo','tab_')
->where($map)
->find();
return $data;
}
function get_game_icon_id($id)
{
$map['id']=$id;
$data=M("game","tab_")->field('icon')->where($map)->find();
return $data['icon'];
}
/**
* 获取苹果包名
* @param [type] $game_id [description]
* @return [type] [description]
*/
function get_payload_name($game_id){
$map['game_id']=$game_id;
$find=M('game_source','tab_')->field('bao_name')->where($map)->find();
return $find['bao_name'];
}
/**
* 获取用户头像
* @return [type] [description]
*/
function get_user_head_img($id){
$map['id']=$id;
$find=M('user','tab_')->field('head_img')->where($map)->find();
if(preg_match('/logoo.png/',$find['head_img'])){
return "";
}else{
return $find['head_img'];
}
}
/**
* 获取qq登录唯一值
* @param [type] $access_token [description]
* @return [type] [description]
*/
function get_union_id($access_token){
$url = "https://graph.qq.com/oauth2.0/me?access_token=".$access_token."&unionid=1";
$content = file_get_contents($url);
$packname1 = '/\"unionid\"\:\"(.*?)\"/';
preg_match($packname1,$content,$packname2);
$packname = $packname2[1];
return $packname;
}
/**
*默认图片
*/
function check_logo_is_exist($code=0,$logoName=""){
$codeUrl = get_cover($code,'path');
$codeUrl_ = '.'.get_cover($code,'path');
if(file_get_contents($codeUrl)){
clearstatcache();
return $codeUrl;
}elseif(file_get_contents($codeUrl_)){
clearstatcache();
return $codeUrl_;
}else{
clearstatcache();
return '/Public/' . MODULE_NAME . '/images/'.$logoName;
}
}
//签名方法
function signsortData($data, $secret)
{
ksort($data);
foreach ($data as $k => $v) {
$tmp[] = $k . '=' . urlencode($v);
}
$str = implode('&', $tmp) . $secret;
return md5($str);
}
//签名字符串方法
function sortData($data)
{
ksort($data);
foreach ($data as $k => $v) {
$tmp[] = $k . '=' . urlencode($v);
}
$str = implode('&', $tmp) . $secret;
return $str;
}
/**获取自建官网id
* @param $game_id
*/
function get_self_id($game_id)
{
$map['gameid'] = $game_id;
$find = M('selfbuilt')->where($map)->find();
return $find == null ? 0 : $find['id'];
}
/**
* 是否开启缓存
* @return boolean [description]
* @author chenbin <[email address]>
*/
function is_cache(){
if(C('CACHE_TYPE')==1||C('CACHE_TYPE')==2){
return true;
}else{
return false;
}
}
//
function get_user_account_log($uid=null){
if(empty($uid)){return false;}
$user = D('User');
$map['id'] = $uid;
$data = $user->field('account')->where($map)->find();
if(empty($data['account'])){return false;}
return $data['account'];
}
/**
* 获取管理员昵称 二级跟随一级
* @param [type] $parent_id [description]
* @param [type] $admin_id [description]
* @return [type] ` [description]
*/
function get_admin_nickname_log($admin_id=0){
$user = D('member');
$map1['uid'] = $admin_id;
$data = $user->field('nickname')->where($map1)->find();
return $data['nickname'];
}
function get_authgroup_title($id=0){
$data = M('AuthGroup')->field('title')->find($id);
return $data['title'];
}
/**
* 获取设置工具的title
*/
function get_tool_title($name=''){
$map['name'] = $name;
$data = M('Tool','tab_')->field('title')->where($map)->find();
return $data['title'];
}
/**
* 获取图片路径
* @param [type] $path [description]
* @return [type] [description]
*/
function array_map_self($path){
if( strpos(get_cover($path,'path'),"http") !==false ){
return get_cover($path,'path');
}else{
return 'http://'.$_SERVER['HTTP_HOST'].get_cover($path,'path');
}
}
/**
* 为空判断
* [IsNull description]
* @param [type] $num [description]
*/
function IsNull($num){
if($num === null){
$num = 0;
}
return $num;
}
//判断网址是否正确
function url_exit($url){
$ch = curl_init();
$timeout = 3;
curl_setopt($ch,CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch,CURLOPT_URL,$url);
curl_exec($ch);
$httpcode = curl_getinfo($ch,CURLINFO_HTTP_CODE);
curl_close($ch);
if($httpcode != 200) {
return 0;
}
else {
return 1;
}
}
/**
* 模拟post进行url请求
* @param string $url
* @param string $param
*/
function request_post($url = '', $param = '') {
if (empty($url) || empty($param)) {
return false;
}
$postUrl = $url;
$curlPost = $param;
$ch = curl_init();//初始化curl
curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
$data = curl_exec($ch);//运行curl
curl_close($ch);
return $data;
}
function get_user_name($id){
if($id =='' ){
return false;
}
$user = M('user',"tab_");
$data = $user->field('account')->find($id);
if(empty($data)){
return false;
}
return $data['account'];
}
/**
*根据用户名获取用户id
*/
function get_user_id($account){
$model = M("user",'tab_');
$map["account"] = $account;
$reg = $model->where($map)->find();
if(null!==$reg){
return $reg["id"];
}else{
return 0;
}
}
/**
* [写入redis数据]
* @author 郭家屯[gjt]
*/
function get_redis_data(){
$redis = Org\RedisSDK\Redis::getInstance(['host'=>'127.0.0.1','port'=>6379],[]);
$data = M('analysis','tab_')->field('time,new_count,new_id,active_count,active_id,game_id,promote_id')->select();
$redis->multi();
foreach ($data as $key=>$v) {
if($v['promote_id']>0 && $v['game_id']>0){
$redis->set('analysis_'.$v['time']."_promote_".$v['promote_id']."_game_".$v['game_id'], json_encode($v));
}elseif($v['promote_id']>0 ){
$redis->set('analysis_'.$v['time']."_promote_".$v['promote_id'], json_encode($v));
}elseif($v['game_id']>0){
$redis->set('analysis_'.$v['time']."_game_".$v['game_id'], json_encode($v));
}else{
$redis->set('analysis_'.$v['time'], json_encode($v));
}
}
$redis->exec();
}
/**
* @函数或方法说明
* @发送预警信息
* @param $to
* @param $rand
*
* @return bool
*
* @author: 郭家屯
* @since: 2019/4/30 10:38
*/
function sendBrushMail($to,$content) {
Vendor('phpmailer.PHPMailerAutoload');
$mail = new \PHPMailer(); //实例化
$mail->IsSMTP(); // 启用SMTP
$mail->Host=C('email_set.smtp'); //smtp服务器的名称这里以126邮箱为例smtp.126.com
$mail->SMTPAuth = TRUE;//C('MAIL_SMTPAUTH'); //启用smtp认证
$mail->SMTPSecure = 'ssl'; //设置使用ssl加密方式登录鉴权
$mail->Port = C('email_set.smtp_port'); //设置ssl连接smtp服务器的远程服务器端口号
$mail->CharSet = 'UTF-8';
$mail->Username = C('email_set.smtp_account'); //你的邮箱名
$mail->Password = C('email_set.smtp_password') ; //邮箱密码
$mail->From = C('email_set.smtp_account'); //发件人地址(也就是你的邮箱地址)
$mail->FromName = C('email_set.smtp_name'); //发件人姓名
$mail->AddAddress($to,"尊敬的客户");
$mail->WordWrap = 50; //设置每行字符长度
$mail->IsHTML(TRUE); // 是否HTML格式邮件
$mail->CharSet='utf-8'; //设置邮件编码
$mail->Subject ="防刷预警通知邮件"; //邮件主题
$mail->Body = $content; //邮件内容
$c = strip_tags($content);
$mail->AltBody = $c; //邮件正文不支持HTML的备用显示
return($mail->Send());
}
function index_by_column($column, $items)
{
$records = [];
foreach ($items as $item) {
$records[$item[$column]] = $item;
}
return $records;
}
/**
* [获取用户是否补链中]
* @param integer $user_id [description]
* @return bool
*/
function getIsTask($user_id){
$shift = M("shift_task");
$map=array(
"status"=>0,
"shift_ids"=>array("LIKE","%\"{$user_id}\"%")
);
$shiftres = $shift->field("id")->where($map)->find();
if(empty($shiftres)){
return 0;
}else{
return $shiftres['id'];
}
}
function encryption($string) {
//订单隐藏算法
$orderLen = strlen($string);
$strLen = 3;
$hideChar = '';
if($orderLen <=8) {
$strLen = 2;
}
for($i = 0;$i<$orderLen-$strLen*2;$i++) {
$hideChar .='*';
}
return substr($string, 0, $strLen) . $hideChar . substr($string, $orderLen-$strLen);
}
//导出csv
function db2csv(&$data,$title,$header=false){
set_time_limit(0);
$filename = $title .'.csv';
$fp = fopen($filename, 'w'); //生成临时文件
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码
if($header) fputcsv($fp, $header);
foreach ($data as $a) {
fputcsv($fp, $a);
}
fclose($fp); //每生成一个文件关闭
//下载
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-Disposition: attachment;filename="' . $title . '.csv"');
header('Cache-Control: max-age=0');
header('Content-Length: ' . filesize($filename));
readfile($filename);
unlink($filename);
die();
}
function hideRealName($realName)
{
return mb_strlen($realName,'utf-8') == 2 ? mb_substr($realName,0,1,'utf-8').'*':mb_substr($realName,0,1,'utf-8').'**';
}