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.

2914 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
/**
* 获取大号信息
*
* @param int $id 小号编号[帐号]
* @param bool $flag 判断是否编号, true 不是
*
* @return array|mixed|PDOStatement|string|\think\Model|null
*
* @author: 鹿文学[lwx]<fyj301415926@126.com>
* @since: 2019\4\16 0016 13:42
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
function get_user_big_info($id=0, $flag=false) {
if((is_numeric($id) && $id>0) || (is_string($id) && !empty($id)) ) {
if($flag) {
$map['b.account'] = $id;
} else {
$map['b.id'] = $id;
}
return M('User','tab_')
->alias('a')
->field('a.id,a.account,a.balance')
->join('inner join tab_user b on a.id = b.puid')
->where($map)
->find();
} else {
return '';
}
}
/*
* 获取推广员列表(根据父级编号)
* @param integer $id 父级编号(为负数则是全部)
* @author 鹿文学
*/
function get_promote_list_by_id($id=0) {
//为数据权限修改 2019-12-19 lww
$query = M("Promote","tab_")->field('id,account,balance_coin');
$map = array();
setPowerPromoteIds($map, 'id');
if(is_numeric($id) && $id>=0) {
$map['parent_id'] = $id;
} elseif(is_array($id)) {
$map['parent_id'] = array('in',$id);
}
$list = $query->where($map)->select();
return $list;
}
/*
* 秒数转时长(时分秒格式)
* @param int $times 秒数
* @author 鹿文学
*/
function second_to_duration($times){
$result = '00:00:00';
if ($times>0) {
$hour = floor($times/3600);
$minute = floor(($times-3600 * $hour)/60);
$second = floor((($times-3600 * $hour) - 60 * $minute) % 60);
$result = $hour.':'.$minute.':'.$second;
}
return $result;
}
/**
* 后台公共文件扩展
* 主要定义后台公共函数库
*/
function get_vip_level_limit($field='',$level=0) {
if(empty($field)) {return '';}
$tool = M('tool',"tab_")->field('config,status')->where(['name'=>'viplevel'])->find();
if(!empty($tool) && $tool['status']==1){
$viplevel = json_decode($tool['config'],true);
$vl='';
if(empty($viplevel)) {return '';}
foreach($viplevel as $k=>$v) {
$cur = intval(str_replace('vip','',$k));
if($level == 0) {$vl = $field . '<' . $v;break;}
if($level>=count($viplevel) && $cur >= count($viplevel)) {$vl = $field . '>=' . $v;break;}
if($level==$cur) {
$vl = $field . '>=' . $v . ' and ' . $field .'<'.$viplevel['vip'.($cur+1)];
break;
}
}
return $vl;
} else {
return '';
}
}
function addZeroToTime($v) {
return $v.':00';
}
function set_date_day_format($day='') {
return strlen($day)==1?'0'.$day:$day;
}
/*
* 异常类型
*/
function get_bug_name_by_id($id=0) {
if (!is_numeric($id) || $id<0 ) {return '';}
$list = get_bug_list();
return $list[$id];
}
function get_bug_list() {
return array(
100=>'开发者注册未审核',
101=>'游戏充值未到账',
102=>'补单失败',
103=>'平台币充值未到账',
104=>'绑币充值未到账',
200=>'开发者提现未处理',
201=>'推广员提现未处理',
300=>'推广员注册未审核',
301=>'推广员混服申请未审核',
302=>'推广员游戏申请未审核',
303=>'推广员游戏申请未打包',
304=>'推广员游戏盒子APP申请未审核',
305=>'推广员游戏盒子APP申请未打包',
400=>'游戏未设置分成比例',
401=>'开发者游戏未审核',
402=>'游戏原包未上传',
403=>'礼包数量不足',
404=>'评论未审核',
405=>'发放平台币失败',
406=>'发放绑币失败',
);
}
/* 获取色系 鹿文学 2017-11-17 */
function get_color_style_list() {
$result = M('config')->field('extra,value')->find(13);
if ($result) {
$list['list'] = parse_config_attr($result['extra']);
$list['value']=$result['value'];
}
return $list;
}
//根据游戏id获取游戏唯一标示
function get_marking($id)
{
$map['id']=$id;
$game=M("game","tab_")->where($map)->find();
return $game['marking'];
}
function get_auth_group_name($uid){
$model = D("auth_group_access");
$res = $model->join("sys_auth_group on sys_auth_group.id = sys_auth_group_access.group_id")
->field("title")
->where("uid=".$uid)
->find();
return empty($res["title"]) ? "" : $res["title"];
}
//根据发送消息的ID获取通知名字
function get_push_name($id)
{
$map['id']=$id;
$list=M("push","tab_")->where($map)->find();
if(empty($list)){return false;}
return $list['push_name'];
}
//获取推送通知应用
function get_push_list()
{
$list=M("push","tab_")->select();
if(empty($list)){return false;}
return $list;
}
function get_promote_list($select='') {
$list = M("Promote","tab_")->field('id,account,balance_coin')->select();//where("status=1")->
if (empty($list)){return '';}
if($select==111){
$new['id']=-1;
$new['account']="全站用户";
array_unshift($list,$new);
}
return $list;
}
/**
* [获取所有一级推广员]
* @return [type] [description]
*/
function get_all_toppromote(){
$map['status']=1;
$map['level']=['lt', 4];
//为数据权限添加
setPowerPromoteIds($map, 'id');
$list = M("Promote","tab_")->where($map)->select();
if (empty($list)){return '';}
return $list;
}
function time_day($time){
$now = time();
return floor(($now-$time)/(60*60*24));
}
function mdate($time = NULL) {
$text = '';
$time = $time === NULL || $time > time() ? time() : intval($time);
$t = time() - $time; //时间差 (秒)
$y = date('Y', $time)-date('Y', time());//是否跨年
switch($t){
case $t == 0:
$text = '刚刚';
break;
case $t < 60:
$text = $t . '秒前'; // 一分钟内
break;
case $t < 60 * 60:
$text = floor($t / 60) . '分钟前'; //一小时内
break;
case $t < 60 * 60 * 24:
$text = floor($t / (60 * 60)) . '小时前'; // 一天内
break;
case $t < 60 * 60 * 24 * 1:
$text = '昨天 ' . date('H:i', $time);
break;
case $t < 60 * 60 * 24 * 30:
$text = date('m-d H:i', $time); //一个月内
break;
case $t < 60 * 60 * 24 * 365&&$y==0:
$text = date('m-d', $time); //一年内
break;
default:
$text = date('Y-m-d-', $time); //一年以前
break;
}
return $text;
}
//所有支付方式
function all_pay_way($type=false)
{
if($type){
$pay_way[0]=array('key'=>0,'value'=>"平台币");
}
$pay_way[1]=array('key'=>-1,'value'=>"绑币");
$pay_way[2]=array('key'=>1,'value'=>"支付宝");
$pay_way[3]=array('key'=>2,'value'=>"微信");
$pay_way[7]=array('key'=>8,'value'=>'金猪');
$pay_way[9]=array('key'=>9,'value'=>"双乾支付-支付宝");
$pay_way[10]=array('key'=>10,'value'=>"双乾支付-银联");
// $pay_way[3]=array('key'=>3,'value'=>'微信APP');
// $pay_way[4]=array('key'=>4,'value'=>'威富通');
/* $pay_way[4]=array('key'=>5,'value'=>'聚宝云'); */
// $pay_way[5]=array('key'=>6,'value'=>'汇付宝');
/* $pay_way[6]=array('key'=>7,'value'=>"苹果支付");
*/
$pay_way[15]=array('key'=>15,'value'=>'双乾支付-快捷');
$pay_way[17]=array('key'=>17,'value'=>'易宝支付');
return $pay_way;
}
/* //获取支付方式 */
function get_pay_way($id=null)
{
if(!isset($id)){
return false;
}
switch ($id) {
case -1:
return "绑币";
break;
case 0:
return "平台币";
break;
case 1:
return "支付宝";
break;
case 2:
return "微信";
break;
case 3:
return "微信APP";
break;
case 4:
return "汇付宝";
break;
case 5:
return "聚宝云";
break;
case 6:
return "竣付通";
break;
case 7:
return "苹果支付";
break;
case 8:
return "金猪支付";
break;
case 9:
return "双乾支付-支付宝";
break;
case 10:
return "双乾支付-银联";
break;
case 15:
return "双乾支付-快捷";
case 17:
return "易宝支付";
break;
}
}
/**
* 获取订单类型
*
* @param null $id
* @return string
*/
function get_order_type($id=null)
{
switch ($id) {
case 1:
return "sdk充值订单";
break;
case 2:
return "平台币充值订单";
break;
case 3:
return "超级签充值订单";
break;
default:
return '未知';
break;
}
}
function get_pay_way_map($id) {
if(!isset($id)){
return '';
}
switch ($id) {
case -1:
return -1;
break;
case 0:
return 0;
break;
case 1:
return 1;
break;
case 2:
case 3:
case 4:
return array('in',[2,3,4]);
break;
case 5:
return 5;
break;
case 6:
return 6;
break;
case 7:
return 7;
break;
case 8:
return 8;
break;
case 9:
return 9;
case 17:
return 17;
break;
}
}
function get_obtain_pay_way($keys=array()){
$pay_way[0]=array('key'=>0, 'value'=>"平台币");
$pay_way[1]=array('key'=>-1,'value'=>"绑币");
$pay_way[2]=array('key'=>1, 'value'=>"支付宝");
$pay_way[3]=array('key'=>2, 'value'=>"微信");
$pay_way[4]=array('key'=>5, 'value'=>'聚宝云');
$pay_way[6]=array('key'=>7, 'value'=>"苹果支付");
$pay_way[7]=array('key'=>8,'value'=>'竣付通');
if(!empty($keys)){
foreach ($keys as $key) {
unset($pay_way[$key]);
}
}
return $pay_way;
}
//获取支付方式
function get_register_way($id=null)
{
if(!isset($id)){
return false;
}
switch ($id) {
case 1:
return "SDK注册";
break;
case 2:
return "APP注册";
case 3:
return "PC注册";
case 4:
return "WAP注册";
break;
}
}
/**
* 获取所有第三方注册方式
* @param [type] $id [description]
* @return [type] [description]
*/
function get_register_type($id=null){
if(!isset($id)){
return false;
}
switch ($id) {
case 3:
return "微信";
break;
case 4:
return "QQ";
case 5:
return "百度";
case 6:
return "微博";
break;
}
}
/**
* 所有注册方式
* @param boolean $type [description]
* @return [type] [description]
* @author zc <894827077@qq.com>
*/
function all_register_way($type=false)
{
$pay_way[1]=array('key'=>1,'value'=>'SDK注册');
$pay_way[2]=array('key'=>2,'value'=>'APP注册');
$pay_way[3]=array('key'=>3,'value'=>'PC注册');
$pay_way[4]=array('key'=>4,'value'=>'WAP注册');
return $pay_way;
}
/**
* 所有第三方注册方式
* @param boolean $type [description]
* @return [type] [description]
* @author zc <894827077@qq.com>
*/
function all_register_type($type=false)
{
$pay_way[3]=array('key'=>3,'value'=>'微信');
$pay_way[4]=array('key'=>4,'value'=>'QQ');
$pay_way[5]=array('key'=>5,'value'=>'百度');
$pay_way[6]=array('key'=>6,'value'=>'微博');
$pay_way[7]=array('key'=>0,'value'=>'游客');
return $pay_way;
}
/**
* 根据用户账号 获取用户昵称
* @param [type] $account [用户账号]
* @return [type] user_nickname [用户]
* @author [yyh]
*/
function get_user_nickname($account){
$map['account']=$account;
$user=M("user_play","tab_")->field('user_nickname')->where($map)->find();
return $user['user_nickname'];
}
//判断用户是否玩此游戏 authoryyh
function get_play_user($account,$gid){
if(empty($account))return false;
$user = D('User');
$map['account']=$account;
$map['game_id']=$gid;
$data = $user->field('tab_user.id,tab_user.account')
->join('tab_user_play on tab_user.account=tab_user_play.user_account')
->where($map)
->find();
return $data;
}
//生成订单号
function build_order_no(){
return date('Ymd').substr(implode(NULL, array_map('ord', str_split(substr(uniqid(), 7, 13), 1))), 0, 8);
}
/**
* [get_game_id description]根据游戏名称 获取游戏id
* @param [type] $name [游戏名称]
* @return [type] [id]
* @author [yyh] <[email address]>
*/
function get_game_id($name){
$game=M('game','tab_');
$map['game_name']=$name;
$data=$game->where($map)->find();
if($data['id']==null){
return false;
}
return $data['id'];
}
/**
* [ratio_stytl 数值转百分比
* @param integer $num [description]
* @return [yyh] [description]
*/
function ratio_stytl($num = 0){
return $num."%";
}
/**
* [get_user_account 根据用户id 获取用户账号]
* @param [type] $uid [用户id]
* @return [type] account [用户账号]
* @author [yyh] <[email address]>
*/
function get_user_account($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'];
}
/**
* [checked_game description]
* @param [type] $id [description]
* @param [type] $sibling_id [description]
* @return [type] [description]
*/
function checked_game($id,$sibling_id){
if($sibling_id){
$map['id']=array('neq',$id);
$map['sibling_id']=$sibling_id;
$game=M('Game','tab_')->where($map)->find();
if(empty($game)){
return '';
}else{
return $game;
}
}else{
return false;
}
}
/**
* [获取游戏原包文件版本]
* @param [type] $game_id [description]
* @param string $type [description]
* @return [type] [description]
*/
function get_game_version($game_id,$type=''){
$model=M('game_source force index (`game_id`)','tab_');
if($game_id==''){
return '';
}
$map['game_id']=$game_id;
$map['file_type']=$type;
$data=$model
->where($map)
->select();
return $data;
}
/**
* [获取游戏版本]
* @param [type] $id [description]
* @return [type] [description]
*/
function game_version($id){
$game=M('game','tab_');
$map['id']=$id;
$data=$game->field('sdk_version')->where($map)->find();
if($data['id']==null){
return false;
}
return $data['version'];
}
/**
*获取游戏配置的指定字段信息
*/
function get_game_set_field($game_id,$field=""){
$map['id'] = $game_id;
$data = M('GameSet','tab_')->where($map)->getField($field);
if(empty($data)){
return "暂无";
}else{
return $data;
}
}
/**
* 渠道列表
* @param $type
* @return mixed
*/
function promote_lists($type){
if($type){
$map['level'] = $type;
} else{
$map = '';
}
//为数据权限添加
setPowerPromoteIds($map, 'id');
$data = M('promote','tab_')->where($map)->select();
$items = M('PromoteBalanceCoin', 'tab_')->where(['game_id' => 0])->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['num'];
}
foreach ($data as $key => $item) {
$item['common_coin'] = isset($records[$item['id']]) ? $records[$item['id']] : $item['balance_coin'];
$data[$key] = $item;
}
return $data;
}
// 获取IOS游戏名称
function get_ios_game_name($game_id=null,$field='id'){
$map[$field]=$game_id;
$map['game_version']=0;
$data=M('Game','tab_')->where($map)->find();
if(empty($data)){return false;}
$game_name=explode("(", $data['game_name']);
return $game_name[0];
}
/**
* [获取区服名称]
* @param [type] $id [description]
* @return [type] [description]
*/
function get_server_name($id){
if($id==''){
return false;
}
$map['id']=$id;
$area=M("Server","tab_")->field('')->where($map)->find();
return $area['server_name'];
}
/**
* [获取游戏区服名称]
* @param [type] $area_id [description]
* @return [type] [description]
*/
function get_area_name($area_id= null){
if(empty($area_id)){return false;}
$area_model = D('Server');
$map['server_num'] = $area_id;
$name = $area_model->field('server_name')->where($map)->find();
if(empty($name['server_name'])){return false;}
return $name['server_name'];
}
/**
* [根据推广员获取所属专员]
* @param [type] $id [description]
* @return [type] [description]
*/
function get_belong_admin($id)
{
$map['id']=$id;
$pro=M("promote","tab_")->where($map)->find();
if($pro){
return get_admin_nickname($pro['parent_id'],$pro['admin_id']);
}else{
return false;
}
}
/**
* [获取管理员列表]
* @return [type] [description]
*/
function get_admin_list()
{
$list= M("Member")->field('uid,nickname')->where("status=1")->select();
if(empty($list)){return false;}
return $list;
}
/**
* [渠道等级]
* @param [type] $pid [description]
* @return [type] [description]
*/
function get_qu_promote($pid){
if($pid==0){
return "一级推广员";
}else{
return "二级推广员";
}
}
/**
* [上线渠道]
* @param [type] $id [description]
* @param [type] $pid [description]
* @return [type] [description]
*/
function get_top_promote($id,$pid){
if($pid==0){
$pro=M("promote","tab_")->field('account')->where(array('id'=>$id))->find();
}else{
$map['id']=$pid;
$pro=M("promote","tab_")->field('account')->where($map)->find();
}
if($pro==''){
return false;
}
return $pro['account'];
}
function get_parent_promote_name($id) {
if(!is_numeric($id) || $id<1) {return '--';}
$promotemodel= M('promote','tab_');
$pro = $promotemodel->field('account,parent_id')->where(['id'=>$id])->find();
if(is_array($pro)) {
if($pro['parent_id']==0) {return $pro['account'];}
$pre = $promotemodel->field('account')->where(['id'=>$pro['parent_id']])->find();
if(is_array($pre)) {
return $pre['account'];
} else {
return $pro['account'];
}
} else {
return '--';
}
}
/**
* 获取管理员昵称 二级跟随一级
* @param [type] $parent_id [description]
* @param [type] $admin_id [description]
* @return [type] ` [description]
*/
function get_admin_nickname($parent_id = 0,$admin_id=null){
$user = D('member');
$map1['uid'] = $parent_id;
$data = $user->field('nickname')->where($map1)->find();
return $data['nickname'];
}
function get_admin_account($id=0) {
$map['id'] = $id;
$data = M('UcenterMember')->field('username')->where($map)->find();
return $data['username'];
}
/**
* [根据推广员获取所属专员]
* @param [type] $id [description]
* @return [type] [description]
*/
function get_admin_promotes($param,$type='admin_id')
{
$map[$type]=$param;
$pro=M("promote","tab_")->where($map)->select();
return $pro;
}
/**
* [根据推广员id获取上级推广员姓名]
* @param [type] $id [description]
* @return [type] [description]
*/
function get_parent_promoteto($id){
if($id==''){
return '';
}
$list=D("promote");
$map['id']=$id;
$pid=$list->field('parent_id')->where($map)->find();
if($pid['parent_id']!=0){
$mapp['id']=$pid['parent_id'];
$pname=$list->field('account')->where($mapp)->find();
if($pname){
return "[".$pname['account']."]";
}
else{
return "";
}
}else{
return "";
}
}
//获取注册来源
function get_registerway($way){
if(!isset($way)){
return false;
}
$arr=array(
1=>'SDK',
2=>'APP',
3=>'PC',
4=>'WAP',
);
return $arr[$way];
}
//获取注册方式
function get_registertype($type){
if(!isset($type)){
return false;
}
$arr=array(
0=>"游客",
1=>"账号",
2 =>"手机",
3=>"微信",
4=>"QQ",
5=>"百度",
6=>"微博",
7=>"Facebook",
8=>"Google",
9=>"邮箱",
);
return $arr[$type];
}
//获取推广员id
function get_promote_id($name){
$promote=M('Promote','tab_');
$map['account']=$name;
$data=$promote->field('id')->where($map)->find();
if(empty($data)){
return '';
}else{
return $data['id'];
}
}
//获取管理员id
function get_admin_id($name){
$promote=M('Member','sys_');
$map['nickname']=$name;
$data=$promote->field('uid')->where($map)->find();
if(empty($data)){
return '';
}else{
return $data['uid'];
}
}
//获取所有用户列表
function get_user_list(){
$user = M('User','tab_');
$list = $user->field('id,account,balance')->order('id')->select();
return $list;
}
//获取所有用户列表
function get_user_play_group_list(){
$user = M('UserPlay','tab_');
$list = $user->field('user_id,user_account,game_id,game_name,bind_balance')->group("user_id")->select();
return $list;
}
/**
* [array_group_by 二维数组根据里面元素数组的字段 分组]
* @param [type] $arr [description]
* @param [type] $key [description]
* @return [type] [description]
*/
function array_group_by($arr, $key){
$grouped = [];
foreach ($arr as $value) {
$grouped[$value[$key]][] = $value;
}
if (func_num_args() > 2) {
$args = func_get_args();
foreach ($grouped as $key => $value) {
$parms = array_merge([$value], array_slice($args, 2, func_num_args()));
$grouped[$key] = call_user_func_array('array_group_by', $parms);
}
}
return $grouped;
}
/**
* [前几个月]
* @param integer $m [前几个月]
* @return [type] [description]
*/
function before_mounth($m=12){
$time=array();
for ($i=0; $i <$m ; $i++) {
$time[]=date("Y-m", strtotime("-$i month"));
}
return $time;
}
/**
* 获取上周指定日期时间
* @param $str 指定时间
* @return unknown 时间
*/
function get_lastweek_name($str){
switch ($str) {
case '1':
$time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-1,date('Y')));
break;
case '2':
$time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-2,date('Y')));
break;
case '3':
$time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-3,date('Y')));
break;
case '4':
$time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-4,date('Y')));
break;
case '5':
$time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-5,date('Y')));
break;
case '6':
$time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-6,date('Y')));
break;
case '7':
$time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-7,date('Y')));
break;
// case '-1':
// $time = date("Y-m-d",mktime(0,0,0,date('m'),date('d')-7,date('Y')));
// break;
default:
$time =date("Y-m-d",mktime(0,0,0,date('m'),date('d'),date('Y')));
break;
}
return $time;
}
//获取广告图类型
function get_adv_type($type=0){
switch ($type) {
case 1:
return '单图';
break;
case 2:
return '多图';
break;
case 3:
return '文字链接';
break;
case 4:
return '代码';
break;
default:
return '未知类型';
break;
}
}
/**
*获取广告位标题
*@param int $pos_id
*@return string
*@author 小纯洁
*/
function get_adv_pos_title($pos_id=0){
$adv_pos = M('AdvPos',"tab_");
$map['id'] = $pos_id;
$data = $adv_pos->field('title')->where($map)->find();
if(empty($data)){return "没有广告位";}
return $data['title'];
}
function get_relation_game($id,$relation_id){
if($id==$relation_id){
$gdata=M('Game','tab_')->where(array('relation_game_id'=>$relation_id,'id'=>array('neq',$id)))->find();
if(!$gdata){
return false;//未关联游戏 即没有例外一个版本
}else{
return true;
}
}else{
//再次确认关联的游戏
$gdata=M('Game','tab_')->where(array('relation_game_id'=>$relation_id,'id'=>$relation_id))->find();
if($gdata){
return true;
}else{
return -1; //数据出错
}
}
}
function get_kuaijie($type=''){
if($type==''){
return false;
}else{
$data=M('Member')->field('kuaijie_value')->where(array('uid'=>UID))->find();
}
$data=$data['kuaijie_value'];
if(empty($data)){
$data='1,2,3,4,5,6,7,8,9,10';
}
$dataa=explode(',',$data);
if($type==1){
if($data==''){
$dataa='';
}else{
$map['id']=array('in',$data);
$dataa=M('Kuaijieicon')->where($map)->select();
}
}elseif($type==2){
if($data==''){
$dataa=M('Kuaijieicon')->select();
}else{
$map['id']=array('not in',$data);
$dataa=M('Kuaijieicon')->where($map)->select();
}
}
foreach ($dataa as $key => $value) {
foreach ($data as $k => $v) {
if($value==$v['value']){
$dataa[$key]=$v;
}
}
}
return $dataa;
}
/**
* 获取游戏版本
* @param $game_id
* @return string
*/
function get_sdk_version($game_id){
$game = M('Game','tab_')->find($game_id);
$version = empty($game) ? '' : $game['sdk_version'];
return $version;
}
function get_kefu_data(){
$map['status']=1;
$map['istitle']=1;
$list = M('Kefuquestion')
->where($map)
->group('title')
->select();
return $list;
}
//获取短消息未读条数
function get_msg($id = 0){
$id = $id ? $id : session('user_auth.uid');
$map['user_id'] = $id;
$map['status'] = 2;
$count = M('msg', 'tab_')->where($map)->count();
return $count;
}
function array_status2value($status,$param,$array=array()){
foreach ($array as $key => $value) {
if($value[$status]!=1){
unset($array[$key]);
}
}
return $array;
}
/**
* 获取渠道平台币
* @param $promote_id
* @return mixed
*/
function get_promote_coin($promote_id){
$promote = M('promote','tab_')->field('balance_coin')->find($promote_id);
return $promote['balance_coin'];
}
function intFun($v)
{
$v=(int)$v;
return $v;
}
/**
* 获取渠道父类
* @param $promote_id
* @param string $field
* @return mixed
*/
function get_promote_parent($promote_id,$field='account'){
$Promote = M('promote','tab_');
$data = $Promote->field('parent_id')->find($promote_id);
if($data['parent_id'] != 0){
$data = $Promote->find($data['parent_id']);
}
return $data[$field];
}
/**
* 获取渠道父类 父级默认空
*/
function get_promote_parent_acc($promote_id){
$Promote = M('promote','tab_');
$data = $Promote->field('account,parent_id,chain')->find($promote_id);
if(empty($data)){
return $data["account"]=C('OFFICIEL_CHANNEL');exit;
}
$chain = trim($data['chain'], '/');
if ($chain == '') {
return '------';
} else {
$topPromoteId = explode('/', $chain)[0];
$parent_promote = M('promote', 'tab_')->where(['id' => $topPromoteId])->find();
return $parent_promote['account'] ?: '------';
}
}
//获取所有苹果证书id
function get_applecert(){
$data=M('applecert')->select();
return $data;;
}
/**
* 获取ios游戏描述文件路径等
* @param [type] $game_id 游戏id
* @param [type] $type 1 原包路径 2描述文件路径
* @return [type] 路径
*/
function get_game_url($game_id,$type=1){
$map['game_id']=$game_id;
$find=M('game_source','tab_')->field('file_url,description_url')->where($map)->find();
if($type==1){
return $find['file_url'];
}elseif($type==2){
return $find['description_url'];
}
}
/**
* 检查苹果渠道包打包状态
* @param [type] $pid [渠道id]
* @param [type] $gid [游戏id]
* @return boolean [-2 可以申请 -1 正在打包 1打包成功 2 打包失败 ]
*/
function is_check_pack_for_ios($pid,$gid){
$map['channelid']=$pid;
$map['game_id']=$gid;
$find=M('iospacket')->where($map)->find();
if(null==$find){
return -2;
}elseif(null!==$find&&$find['status']==2){
return -1;
}elseif(null!==$find&&$find['status']==0){
return 1;
}elseif(null!==$find&&$find['status']==-1){
return 2;
}
}
/**
* 根据游戏id获取存入iospacket的原包/描述文件路径
* @param [type] $game_id [description]
* @param [type] $t [description]
* @return [type] [description]
*/
function get_ios_purl($game_id,$t){
$a=explode("/",get_game_url($game_id,$t));
return $a[3]."/".$a[4];
}
/**
* 判断原包是否有更新
* @param [type] $game_id [游戏id]
* @param [type] $promote_id [渠道id]
* @return [type] [1 有更新 0 无鞥下]
*/
function check_iosupdate($game_id,$promote_id){
$map['game_id']=$game_id;
$source=M('game_source','tab_')->field('game_id,file_url')->where($map)->find();
$map['channelid']=$promote_id;
$iospack=M('iospacket')->field('originalpath')->where($map)->find();
if($source['file_url']!=="./Uploads/Ios/".$iospack['originalpath']){
return 1;
}else{
return 0;
}
}
/**
* 获取积分类型列表
* @return mixed
* author: xmy 280564871@qq.com
*/
function get_point_type_lists(){
$data =M("point_type","tab_")->where(['status'=>1])->select();
return $data;
}
/**
* 获取积分商品列表
* author: xmy 280564871@qq.com
*/
function get_point_good_lists(){
$data =M("point_shop","tab_")->where(['status'=>1])->select();
return $data;
}
/**
* 验证退款记录
* @param $pay_order_number
* @return int
*/
function ischeck_refund($pay_order_number){
$map['pay_order_number']=$pay_order_number;
$find=M('refund_record','tab_')->where($map)->find();
if(null==$find){
return 1;
}elseif($find['tui_status']=='2'){
return 2;
}elseif($find['tui_status']=='1'){
return 0;
}
}
/**
* 获取支付方式
* @param $order
* @return mixed
*/
function get_spend_pay_way($order){
$map['pay_order_number']=$order;
$find=M('refund_record','tab_')->field('pay_way')->where($map)->find();
return $find['pay_way'];
}
//得到ios游戏的plist_url
function get_plist($game_id){
$map['game_id'] = $game_id;
$data = M('Game_source','tab_')->where($map)->field('plist_url')->find();
if (empty($data['plist_url'])){
return '';
}else{
return "itms-services://?action=download-manifest&url=".$_SERVER['HTTP_HOST'].substr($data['plist_url'],1);
}
}
/**
*删除数组中特定元素
* @param array $data, 要移除的数据
* @param type $element,要移除的指定元素
* @return array 移除后的新数组
* @author 小纯洁
*/
function remove_array_element($data=null,$element=null){
foreach ($data as $key=>$value) {
if ($value === $element)
{
unset($data[$key]);
}
}
return $data;
}
/**
*获取首冲续充对象名称
*@param int $case 类型
*@return string 返回对象名称
*@author 小纯洁
*/
function get_discount_obj_name($case = 0){
$result = "";
switch ($case) {
case -1:
$result = "全站玩家";
break;
case 0:
$result = "官方渠道";
break;
case -2:
$result = "推广渠道";
break;
default:
$result = "全站玩家";
break;
}
return $result;
}
/**
*根据推广员ID获取商务专员账号名称
*@param int $promote_id
*@return string 返回对象名称
*@author 小纯洁
*/
function get_promote_business_account($promote_id=0){
$promote = M('promote','tab_')->find($promote_id);
if(empty($promote)){
return "错误";
}
$business = M('BusinessAffairs','tab_')->find($promote['ba_id']);
return empty($business['account']) ? "暂无" : $business['account'];
}
function get_highlight_subnav($cate_id=0,$url='Article/index',$param='cate_id'){
$map['sys_category.id'] = $cate_id;
$cate_id = D('category')
->field("tab.id,tab.title,tab.pid,tab.sort")
->join("sys_category AS tab ON sys_category.pid = tab.pid")
->where($map)
->order('tab.sort asc')
->getField('tab.id',1);
$url = U($url,array('cate_id'=>$cate_id));
return $url;
}
/**
*根据唯一字段查找特定的字段值
*@param string field 要返回的字段结果
*@param string fieldMap 要查询的字段名称
*@param string value 要查询的唯一字段的值
*/
function get_spend_fields($field='user_account',$fieldMap='id',$value=''){
$map[$fieldMap] = $value;
$data = M('Spend','tab_')->field($field)->where($map)->find();
if(empty($data)){
return false;
}else{
return $field === 'true' ? $data : $data[$field];
}
}
/**
*根据模板id获取获取模板名称
*/
function get_tepname($id){
$model = M("Template");
$map["id"] = $id;
$reg = $model->where($map)->find();
return $reg["temname"];
}
function open_url($url=null){
$str = "<a href='".$url."' target='_blank'>".$url."</a>";
return $str;
}
/**
*获取自建模板
*/
function templatelist(){
$model = M("Template");
$list = $model->select();
return $list;
}
/**
*返回游戏名称
*/
function get_gamename($gid=0){
if($gid == 0){return "未知";}
$model = D("Game");
$list = $model->where("id=".$gid)->find();
// return $list;
return $list["game_name"];
}
/**
*返回游戏官网名称
*/
function get_self_name($gid=0){
if($gid == 0){return "未知";}
$model = D("Game");
$self=M('selfbuilt')->where(['id'=>$gid])->find();
$list = $model->where("id=".$self['gameid'])->find();
return $list["game_name"];
}
function get_list_data($model=null){
$m = M($model)->select();
return $m;
}
function get_list_row($item = "global",$modelName="Model"){
$list = new \Admin\Event\listRowEvent();
$r = $list->getItem($item);
return $list->listRows();
}
function get_pos_game($type=16){
$map['apply_status'] = 1;
$map['game_status'] = 1;
if($type == 16){
$map['sdk_version'] = 1;
}else{
$map['sdk_version'] = 2;
}
$data = M('game','tab_')->field('id,game_name')->where($map)->select();
return $data;
}
function get_promote_levels($id = 0)
{
$data = M('promote', 'tab_')->field('parent_id, level')->where(array('id' => $id))->find();
switch ($data['level']) {
case '1':
return "会长";
break;
case '2':
return "部门长";
break;
case '3':
return "组长";
break;
case '4':
return "组员";
break;
default:
return '';
}
}
/**
* 统计推广员总流水
* @param [type] $id [description]
* @return [type] [description]
*/
function sum_promote_total_money($id){
$map['promote_id']=$id;
$map['pay_status']=1;
$res=M('Spend','tab_')->field("SUM(pay_amount) as pay_amount")->where($map)->select();
return $res[0]['pay_amount']==null ? '0.00':$res[0]['pay_amount'];
}
/**
*后续可用额度
* @param [type] $game_id [description]
* @return [type] $promote_id [description]
*/
function max_quota($game_id,$promote_id){
$map_s['game_id'] =$game_id;
$map_s['promote_id'] =$promote_id;
$map_s['support_type'] =1;
$map_s['notice_status'] =1;
$yishenhe_support_sum=M('support','tab_')->field("SUM(real_support_num) as sum_support_num")->where($map_s)->select();
$map_s['notice_status'] =0;
$map_s['status'] =['neq',0];
$weishenhe_support_sum=M('support','tab_')->field("SUM(support_num) as sum_support_num")->where($map_s)->select();
$support_quota=M('game','tab_')->field('support_quota,support_ratio')->where(['id'=>$game_id])->find();
$max_quota=$support_quota['support_quota']-$support_sum[0]['sum_support_num']; //算法一: 可用额度 = 后台设置额度 - 已申请额度
$map_sp['pay_status']=1;
$map_sp['game_id']=$game_id;
$child_promote = get_zi_promote_id($promote_id);
if($child_promote==0){
$child_promote = $promote_id;
}else{
$child_promote = $child_promote .','.$promote_id;
}
$map_sp['promote_id'] = ['in',$child_promote];
$spend=M('spend','tab_')->field('SUM(pay_amount) as sum_amount')->where($map_sp)->select();
// 该渠道该游戏可用额度 = 该渠道和子渠道的所有玩家的充值量 * 扶持额度 - 待审核额度 - 已申请成功额度
$promote_quota=floor($spend[0]['sum_amount'] * $support_quota['support_ratio']/100 - $weishenhe_support_sum[0]['sum_support_num'] - $yishenhe_support_sum[0]['sum_support_num']);
return $promote_quota < 1 ? 0 : $promote_quota;
}
//现金支付方式
function cash_pay_way()
{
//$pay_way[1]=array('key'=>-1,'value'=>"绑币");
$pay_way[2]=array('key'=>1,'value'=>"支付宝");
$pay_way[3]=array('key'=>2,'value'=>"微信");
// $pay_way[3]=array('key'=>3,'value'=>'微信APP');
// $pay_way[4]=array('key'=>4,'value'=>'威富通');
$pay_way[4]=array('key'=>4,'value'=>'汇付宝');
/* $pay_way[4]=array('key'=>5,'value'=>'聚宝云'); */
// $pay_way[5]=array('key'=>6,'value'=>'汇付宝');
/* $pay_way[6]=array('key'=>7,'value'=>"苹果支付");
*/
$pay_way[7]=array('key'=>8,'value'=>'金猪');
$pay_way[9]=array('key'=>9,'value'=>"双乾支付-支付宝");
$pay_way[10]=array('key'=>10,'value'=>"双乾支付-银联");
$pay_way[15]=array('key'=>15,'value'=>'双乾支付-快捷');
$pay_way[17]=array('key'=>17,'value'=>'易宝支付');
return $pay_way;
}
function getMonth() {
$start = date("Y-m", strtotime("now"));
//开始月份
$range = [];
$i = 1;
do {
$month = date('Y-m', strtotime($start . ' - ' . $i . ' month'));
$range[] = $month;
$i++;
} while ($i<13);
return $range;
}
function getPayType($type) {
$return = '';
switch ($type) {
case -1:
$return = '绑币';
break;
case 0:
$return = '平台币';
break;
case 1:
$return = '支付宝';
break;
case 2:
$return = '微信(扫码)';
break;
case 3:
$return = '微信app';
break;
case 4:
$return = '威富通';
break;
case 5:
$return = '聚宝云';
break;
case 6:
$return = '竣付通';
break;
case 7:
$return = '金猪';
break;
case 9:
$return = '双乾支付-支付宝';
break;
case 10:
$return = '双乾支付-银联';
break;
case 15:
$return = '双乾支付-快捷';
break;
case 17:
$return = '易宝支付';
break;
default:
$return = '未知';
break;
}
return $return;
}
function getPartner() {
$map['status'] = 1;
$data = M('partner','tab_')->field('id,partner')->where($map)->select();
return $data;
}
function getGameList($partner_id) {
if ($partner_id) {
$map['partner_id'] = $partner_id;
}
$data = M('game','tab_')->field("id,game_name")->where($map)->select();
return $data;
}
function getAdminData ($uid) {
$adminData = M('auth_group_access')
->field('data_empower_type,data_president,show_data')
->join('left join sys_auth_group on sys_auth_group_access.group_id=sys_auth_group.id')
->where(array('uid'=>$uid))->find();
// $promoteData = M('promote','tab_')->field('id')->where(array('admin_id'=>$uid))->select();
// $promoteData = implode(',',array_column($promoteData,'id'));
// $adminData['data_president'] = $adminData['data_president'].','.$promoteData;
return $adminData;
}
/**
* 获取当前管理员有权限查看所有推广员id
* @return mixed|string 格式如;all-全部;1,2,3;为空表示都没有权限
*/
function getPowerPromoteIds()
{
//session已存在当前管理员可查看数据的推广员id,则直接返回权限有变化事删除此session
if (!empty(session('user_auth_promote_ids'))) {
return session('user_auth_promote_ids');
}
$userAuth = session('user_auth');
$promoteIds = 'all';
$userAuth['data_president']= trim($userAuth['data_president'], ",");
if (!empty($userAuth['data_empower_type'])) {//数据权限 1 全部 2 部分数据 3 自己底下的会长
//等于1默认全部数据不进行筛选
if (in_array($userAuth['data_empower_type'], [2, 3])) {
$promoteIds = '';
//自己创建的会长
$myPromote_ids = M('promote', 'tab_')
->field('GROUP_CONCAT(id) as promote_ids')
->where(['admin_id' => $userAuth['uid']])
->find();
$myPromote_ids = $myPromote_ids['promote_ids'];
if ($myPromote_ids) {
if ($userAuth['data_empower_type'] == 2) {//部分会长加上自己创建的会长
// $userAuth['data_president'] .= "," . $myPromote_ids;
} elseif ($userAuth['data_empower_type'] == 3) {//自己创建的会长和底下推广员
$userAuth['data_president'] = $myPromote_ids;
}
}
if (!empty($userAuth['data_president'])) {//查询有权限查看的会长以及底下的推广员
$map = array();
//查询会长底下的推广员(首个斜杆之间的数字)
$userAuth['data_president']= trim($userAuth['data_president'], ",");
$where['SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,"/",2),"/",-1)'] = array('exp',"IN({$userAuth['data_president']})");
$where['id'] = array('in', $userAuth['data_president']);//会长本身
$where['_logic'] = 'or';
$map['_complex'] = $where;
$sqlResult = M('promote', 'tab_')
->field('GROUP_CONCAT(id) as promote_ids')
->where($map)
->find();
$promoteIds = $sqlResult['promote_ids'];
}
}
}
// var_dump(in_array('-1',explode(',',$userAuth['data_president'])));die();
if (in_array('-1',explode(',',$userAuth['data_president']))) {
$promoteIds = $promoteIds .',0';
}
// var_dump($promoteIds);die();
session('user_auth_promote_ids', $promoteIds);
return $promoteIds;
}
/**
* 为数据权限添加筛选参数
* @param array $map 查询条件
* @param string $column 字段名默认为promote_id
* @return mixed
*/
function setPowerPromoteIds(&$map, $column = 'promote_id') {
//为数据权限添加
$promoteIds = getPowerPromoteIds();
if (empty($promoteIds)) {
$map[$column] = -1;//没权限时将promote_id置为-1
} elseif ($promoteIds != 'all') {
if (isset($map[$column])) {
if (isset($map['_string'])) {//查询字段中已存在promote_id不覆盖此条件而处理
$map['_string'] .= " and $column in($promoteIds)";
} else {
$map['_string'] = " $column in($promoteIds)";
}
} else {
$map[$column] = array('in', $promoteIds);
}
}
}
function get_promote_listOther($select='') {
// $promoteRoot = getPowerPromoteIds();
// if ($promoteRoot) {
// $map['id'] =array('in',$promoteRoot);
// }
setPowerPromoteIds($map,'id');
$list = M("Promote","tab_")->field('id,account,balance_coin')->where($map)->select();//where("status=1")->
if (empty($list)){return '';}
if($select==111){
$new['id']=-1;
$new['account']="全站用户";
array_unshift($list,$new);
}
return $list;
}
/**
* 渠道列表
* @param $type
* @return mixed
*/
function promote_listsOther($type){
if($type){
$map['level'] = $type;
} else{
$map = '';
}
// $promoteRoot = getPowerPromoteIds();
// if ($promoteRoot) {
// $map['id'] =array('in',$promoteRoot);
// }
setPowerPromoteIds($map,'id');
$data = M('promote','tab_')->where($map)->select();
$items = M('PromoteBalanceCoin', 'tab_')->where(['game_id' => 0])->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['num'];
}
foreach ($data as $key => $item) {
$item['common_coin'] = isset($records[$item['id']]) ? $records[$item['id']] : $item['balance_coin'];
$data[$key] = $item;
}
return $data;
}
function get_admin_listOther()
{
$nickname = session('user_auth')['username'];
$list= M("Member")->field('uid,nickname')->where("status=1 and nickname='{$nickname}'")->select();
if(empty($list)){return false;}
return $list;
}
/**
* 根据会长id底下的推广员id
* @param $promote_id
* @return mixed
*/
function getOffspringByPromoteId($promote_id = null) {
if (isset($promote_id)) {
if ($promote_id ==0) {//官方渠道
$promote_ids = '0';
} else {
$where['chain'] = ['like', "%/{$promote_id}/%"];
$where['id'] = $promote_id;//会长本身
$where['_logic'] = 'or';
$map['_complex'] = $where;
$promote_ids = M('promote', 'tab_')
->where($map)
->field('group_concat(id) as promote_ids')
->find();
$promote_ids = $promote_ids['promote_ids'];
}
} else {
$promote_ids = getPowerPromoteIds();
}
return $promote_ids;
}
/**
* csv 导出函数
* @param [array] $data 一般为数据库查询结果集
* @param [string] $title 表格名称
* @param [array] $fields [字段=>首行名称,...]例如:['name'=>'名称']
* @return void
*/
function data2csv(&$data,$title,$fields){
set_time_limit(0);
ini_set('memory_limit', '-1'); //设置内存不受限制
$csvFileName = $title.'.csv';
//设置好告诉浏览器要下载excel文件的headers
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-Disposition: attachment; filename="'. $csvFileName .'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
$fp = fopen('php://output', 'a');//打开output流
fwrite($fp, chr(0xEF).chr(0xBB).chr(0xBF));//转码,防止乱码
$field = array_keys($fields);
//生成首行
$header = array_values($fields);
fputcsv($fp, $header);
$index = 0;
foreach ($data as $row) {
$a = [];
foreach($field as $k=>$v){
// $a[$v] = $row[$v] . "\t";//防止格式错误
$a[$v] = $row[$v];
}
if ($index == 10000) { //每次写入1000条数据清除内存
$index = 0;
ob_flush();//清除内存
flush();
}
$index++;
fputcsv($fp, $a);
}
ob_flush();
fclose($fp); //每生成一个文件关闭
die();
}
//所有支付方式
function all_pay_way_other($type=false)
{
if($type){
$pay_way[0]=array('key'=>0,'value'=>"平台币");
}
$pay_way[1]=array('key'=>-1,'value'=>"绑币");
$pay_way[2]=array('key'=>1,'value'=>"支付宝");
$pay_way[3]=array('key'=>2,'value'=>"微信");
$pay_way[7]=array('key'=>7,'value'=>'苹果');
$pay_way[9]=array('key'=>9,'value'=>"双乾支付-支付宝");
$pay_way[10]=array('key'=>10,'value'=>"双乾支付-银联");
// $pay_way[3]=array('key'=>3,'value'=>'微信APP');
// $pay_way[4]=array('key'=>4,'value'=>'威富通');
/* $pay_way[4]=array('key'=>5,'value'=>'聚宝云'); */
$pay_way[5]=array('key'=>4,'value'=>'汇付宝');
/* $pay_way[6]=array('key'=>7,'value'=>"苹果支付");
*/
$pay_way[15]=array('key'=>15,'value'=>'双乾支付-快捷');
$pay_way[17]=array('key'=>17,'value'=>'易宝支付');
return $pay_way;
}
function getMonthOther() {
$start = date("Y-m", strtotime("now"));
//开始月份
$range = [];
$i = 0;
do {
$month = date('Y-m', strtotime($start . ' - ' . $i . ' month'));
$range[] = $month;
$i++;
} while ($i<36);
return $range;
}
//获取当前管理员id
function getAdmin($column = 'uid') {
return session("user_auth")[$column];
}
//获取所有有关的公司
function getCompanyList() {
$sql = "select id,company_name,1 as company_type from tab_promote_company UNION ALL select id,partner,0 as company_type from tab_partner";
$data = M()->table("({$sql}) as a")->select();
return $data;
}
//上游cp对账单导出
function excelUpStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money) {
header("Content-type: text/html; charset=utf-8");
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
date_default_timezone_set('Europe/London');
Vendor("PHPExcel.PHPExcel");
$objReader = \PHPExcel_IOFactory::createReader('Excel5');
//设置模板文件
$objPHPExcel = $objReader->load("Public/Admin/excel/up_stream.xls");
//增加甲方信息
$objPHPExcel->getActiveSheet()->setCellValue('D2', $data['first_party_info']['partner']);
$objPHPExcel->getActiveSheet()->setCellValue('D3', $data['first_party_info']['link_man']);
$objPHPExcel->getActiveSheet()->setCellValue('D4', $data['first_party_info']['link_phone']);
$objPHPExcel->getActiveSheet()->setCellValue('D5', $data['first_party_info']['address']);
$objPHPExcel->getActiveSheet()->setCellValue('D6', $data['first_party_info']['company_tax_no']);
//增加乙方信息
$objPHPExcel->getActiveSheet()->setCellValue('J2', $data['second_party_info']['partner']);
$objPHPExcel->getActiveSheet()->setCellValue('J3', $data['second_party_info']['link_man']);
$objPHPExcel->getActiveSheet()->setCellValue('J4', $data['second_party_info']['link_phone']);
$objPHPExcel->getActiveSheet()->setCellValue('J5', $data['second_party_info']['address']);
$objPHPExcel->getActiveSheet()->setCellValue('J6', $data['second_party_info']['company_tax_no']);
$objPHPExcel->getActiveSheet()->setCellValue('C7', "支付给:".$data['receive_company']['partner']); //增加支付给对应公司
$line = 10;
//记录统计项目
$pay_amount_str = "=";
//增加结算记录
foreach ($data['statement_info'] as $key => $value) {
$objPHPExcel->getActiveSheet()->insertNewRowBefore($line,1)->mergeCells("J$line:K$line");
$objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['statement_begin_time'] . '-' . $value['statement_end_time']);
if ($value['statement_type'] > 0) {//罚款
$product_name = $value['game_name'];
$objPHPExcel->getActiveSheet()->setCellValue('F'.$line , '-');
$objPHPExcel->getActiveSheet()->setCellValue('G'.$line, '-');
$objPHPExcel->getActiveSheet()->setCellValue('H'.$line, '-');
$objPHPExcel->getActiveSheet()->setCellValue('I'.$line, '-');
if ($value['statement_type'] == 1) {
$objPHPExcel->getActiveSheet()->setCellValue('E'.$line, "-".$value['pay_amount']);
$objPHPExcel->getActiveSheet()->setCellValue('J'.$line, "-".$value['sum_money']);
}else{
$objPHPExcel->getActiveSheet()->setCellValue('E'.$line, $value['pay_amount']);
$objPHPExcel->getActiveSheet()->setCellValue('J'.$line, $value['sum_money']);
}
} else {//游戏
$product_name = $value['game_name'];
$objPHPExcel->getActiveSheet()->setCellValue('F'.$line , $value['first_ratio'] . '%');
$objPHPExcel->getActiveSheet()->setCellValue('G'.$line, $value['second_ratio'] . '%');
$objPHPExcel->getActiveSheet()->setCellValue('H'.$line, $value['promote_ratio'] . '%');
$objPHPExcel->getActiveSheet()->setCellValue('I'.$line, $value['fax_ratio']. '%');
$objPHPExcel->getActiveSheet()->setCellValue('E'.$line, $value['pay_amount']);
// $objPHPExcel->getActiveSheet()->setCellValue('J'.$line, $value['sum_money']);
if ($data['pay_type'] == 2) {
$objPHPExcel->getActiveSheet()->setCellValue('J'.$line, "=E{$line}*(1-H{$line})*G{$line}*(1-I{$line})");
}else{
$objPHPExcel->getActiveSheet()->setCellValue('J'.$line, "=E{$line}*(1-H{$line})*F{$line}*(1-I{$line})");
}
}
$pay_amount_str .= "J{$line}+";
$objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $product_name);
$line++;
}
//合计
$objPHPExcel->getActiveSheet()->setCellValue("E" . ($line), $data['pay_amount']);
// $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line), $data['statement_money']);
$objPHPExcel->getActiveSheet()->setCellValue("J" . ($line), trim($pay_amount_str,"+"));
// $objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+1), $big_all_sum_money); //本月分成总金额(人民币大写)
$objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+1), "=J{$line}"); //本月分成总金额(人民币大写)
//收款方
$objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+2), $data['receive_company']['payee_name']);
$objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+3), $data['receive_company']['bank_account']);
$objPHPExcel->getActiveSheet()->setCellValue("D" . ($line+4), $data['receive_company']['opening_bank']);
//付款方
$objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+2), $data['pay_company']['payee_name']);
$objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+3), $data['pay_company']['bank_account']);
$objPHPExcel->getActiveSheet()->setCellValue("J" . ($line+4), $data['pay_company']['opening_bank']);
$statement_begin_time = date('Y.m.d', $data['statement_begin_time']);//对账开始时间
$statement_end_time = date('Y.m.d',$data['statement_end_time']);//对账截止时间
$fileName = "{$data['second_party_info']['partner']}&{$data['first_party_info']['partner']}-对账单{$statement_begin_time}-{$statement_end_time}";
ob_end_clean();//清除缓冲区,避免乱码
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xls');
header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
//下游工会对账单导出
function excelDownStreamTemplate($data, $all_sum_money, $all_pay_amount, $big_all_sum_money) {
header("Content-type: text/html; charset=utf-8");
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
define('EOL',(PHP_SAPI == 'cli') ? PHP_EOL : '<br />');
Vendor("PHPExcel.PHPExcel");
$objPHPExcel = new \PHPExcel();
$objReader = \PHPExcel_IOFactory::createReader('Excel5');
//设置模板文件
$objPHPExcel = $objReader->load("Public/Admin/excel/down_stream.xls");
$statement_begin_time = date('Y.m.d', $data['statement_begin_time']);//对账开始时间
$statement_end_time = date('Y.m.d',$data['statement_end_time']);//对账截止时间
$objPHPExcel->getActiveSheet()->setCellValue('A1', "{$data['company_name']} 》结算单\n{$statement_begin_time}-{$statement_end_time}");
if ($data['withdraw_type'] == '2') {
$objPHPExcel->getActiveSheet()->setCellValue('D2','补点比例');
}
$line = 3;
$pay_amount_str = "=";
foreach ($data['statement_info'] as $key => $value) {
$objPHPExcel->getActiveSheet()->insertNewRowBefore($line,1);
$objPHPExcel->getActiveSheet()->removeConditionalStyles();
$objPHPExcel->getActiveSheet()->setCellValue('A'.$line, $value['statement_begin_time'] . '-' . $value['statement_end_time']);
if ($value['statement_type'] > 0) {//罚款
$product_name = $value['game_name'];
$objPHPExcel->getActiveSheet()->setCellValue('D'.$line, '-');
$objPHPExcel->getActiveSheet()->setCellValue('E'.$line, '-');
if ($value['statement_type'] == 1) {
$objPHPExcel->getActiveSheet()->setCellValue('C'.$line, "-".$value['pay_amount']);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$line, "-".$value['sum_money']);
}else{
$objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['pay_amount']);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$line, $value['sum_money']);
}
} else {//游戏
$product_name = $value['game_name'];
if ($data['withdraw_type'] == 2) {
$objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $value['increment_ratio'] . '%');
}else{
$objPHPExcel->getActiveSheet()->setCellValue('D'.$line, $value['ratio'] . '%');
}
$objPHPExcel->getActiveSheet()->setCellValue('E'.$line, $value['fax_ratio'] . '%');
$objPHPExcel->getActiveSheet()->setCellValue('C'.$line, $value['pay_amount']);
// $objPHPExcel->getActiveSheet()->setCellValue('F'.$line, $value['sum_money']);
$objPHPExcel->getActiveSheet()->setCellValue('F'.$line,"=C{$line}*D{$line}*(1-E{$line})");
}
$objPHPExcel->getActiveSheet()->setCellValue('B'.$line, $product_name);
$pay_amount_str .= "F{$line}+";
$line++;
}
$objPHPExcel->getActiveSheet()->setCellValue('C'.($line), $data['pay_amount']);//合计-平台总额
$objPHPExcel->getActiveSheet()->setCellValue('F'.($line), trim($pay_amount_str,"+"));//合计-结算金额
// $objPHPExcel->getActiveSheet()->setCellValue('B'.($line+1), $big_all_sum_money);//大写支付结算金额
$objPHPExcel->getActiveSheet()->setCellValue('B'.($line+1), "=F{$line}");//大写支付结算金额
//甲方信息
$objPHPExcel->getActiveSheet()->setCellValue('B'.($line+3), $data['pay_company']['partner']);//甲方
$objPHPExcel->getActiveSheet()->setCellValue('B'.($line+4), $data['pay_company']['link_man']);//联系人
$objPHPExcel->getActiveSheet()->setCellValue('B'.($line+5), $data['pay_company']['link_phone']);//联系电话
$objPHPExcel->getActiveSheet()->setCellValue('B'.($line+6), $data['receive_company']['invoice_content']);//开票项目
$objPHPExcel->getActiveSheet()->setCellValue('B'.($line+7), $data['receive_company']['invoice_type']);//发票类型
//乙方信息
$objPHPExcel->getActiveSheet()->setCellValue('E'.($line+3), $data['receive_company']['partner']);//乙方
$objPHPExcel->getActiveSheet()->setCellValue('E'.($line+4), $data['receive_company']['link_man']);//联系人
$objPHPExcel->getActiveSheet()->setCellValue('E'.($line+5), $data['receive_company']['link_phone']);//联系电话
$objPHPExcel->getActiveSheet()->setCellValue('E'.($line+6), $data['receive_company']['address']);//邮寄地址
// $objPHPExcel->getActiveSheet()->setCellValue('E'.($line+8), $value['pay_amount']);//请汇入此账号
$objPHPExcel->getActiveSheet()->setCellValue('E'.($line+8), $data['receive_company']['bank_account_name']);//户名
$objPHPExcel->getActiveSheet()->setCellValue('E'.($line+9), $data['receive_company']['bank_account']);//银行账号
$objPHPExcel->getActiveSheet()->setCellValue('E'.($line+10), $data['receive_company']['opening_bank']);//开户行
$fileName = "{$data['second_party_info']['partner']}&{$data['first_party_info']['partner']}-对账单{$statement_begin_time}-{$statement_end_time}";
// dd($fileName);
ob_end_clean();//清除缓冲区,避免乱码
header('pragma:public');
header('Content-type:application/vnd.ms-excel;charset=utf-8;name="' . $fileName .'".xls');
header("Content-Disposition:attachment;filename={$fileName}.xls");//attachment新窗口打印inline本窗口打印
$objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
}
function getWithdrawNumber() {
$map = [];
$map['ext_field'] = ['neq',null];
$data = M('withdraw',"tab_")
->field("widthdraw_number")
->join('left join tab_promote_belong on tab_withdraw.promote_id=tab_promote_belong.promote_id')
->join("left join tab_statement as statement on tab_withdraw.widthdraw_number = statement.ext_field")
->where("ext_field is null and tab_promote_belong.company_type!=2")
->select();
return $data;
}
//上有流水计算
function caculateUpstream($game_id,$pay_amount) {
$ladderData = M('cp_game_ratio','tab_')
->where(['game_id'=>$game_id,'begin_total_amount'=>['elt',$pay_amount],'is_del'=>0])
->limit(0,2)
->order('begin_total_amount desc')
->select();
foreach($ladderData as $key => $value) {
if ($value['instanceof'] == 1 && $value['begin_total_amount'] <= $pay_amount
|| $value['instanceof'] == 2 && $value['begin_total_amount'] != $pay_amount ) {
$data['ratio'] = $value['ratio'];
break;
} else {
$data['ratio'] = $value['ratio'];
}
}
return number_format($pay_amount*($data['ratio']/100),2,'.','');
}
//获取所有有关的公司
function getPromoteCompanyList() {
$sql = "select id,company_name,1 as company_type from tab_promote_company";
$data = M()->table("({$sql}) as a")->select();
return $data;
}
//获取游戏cp分成比例 $type=false时返回最低分成比例
function getGameCpRadio($game_id,$amount,$type) {
if (!$type) {
$data = M('cp_game_ratio','tab_')->where(['game_id'=>$game_id])->order('begin_total_amount asc')->find();
} else {
//取两条
$ladderData = M('cp_game_ratio','tab_')->where(['game_id'=>$game_id,'begin_total_amount'=>['elt',$amount]])->limit(0,2)->order('begin_total_amount desc')->select();
// dump($ladderData);die();
foreach($ladderData as $key => $value) {
if ($value['instanceof'] == 1 && $value['begin_total_amount'] <= $amount
|| $value['instanceof'] == 2 && $value['begin_total_amount'] != $amount ) {
$data['ratio'] = $value['ratio'];
break;
} else {
$data['ratio'] = $value['ratio'];
}
}
}
return $data['ratio']?$data['ratio']:0;
}
/**
* 获取渠道分成比例
* @author chenzhi
* @param [type] $company_id 公司id
* @param [type] $relation_game_id 游戏广联id
* @param [type] $endtime 结算结束的时间戳
* @param [type] $amount 金额
* @param [type] $type $type=false时返回最低分成比例
* @param [type] $company_belong 公司团体类型不传的话用id查询
* @return ratio
*/
function getGamePromoteCompanyRadio($company_id,$relation_game_id,$endtime,$amount,$type,$company_belong=false) {
//判断是否有生效
$rwhere = "(end_time = 0 OR end_time >= '{$endtime}') and company_id='{$company_id}' and relation_game_id='{$relation_game_id}'";
$cgr_res = M("CompanyGameRatio","tab_")->where($rwhere)->find();
// dump( M("CompanyGameRatio","tab_")->where($rwhere)->select(false));
if(empty($cgr_res)){
//模板搜索
//获取公司类型
if($company_belong === false){
$company_belong = M("PromoteCompany","tab_")->field("company_belong")->where("id='{$company_id}'")->find()['company_belong'];
}
$mwhere = "company_belong='{$company_belong}' and relation_game_id='{$relation_game_id}'";
$m_res = M("GameRatioMould","tab_")->where($mwhere)->find();
if(empty($m_res)){
$default_r = 0;
$turnover_ratio = false;
}else{
$default_r = $m_res['ratio'];
$turnover_ratio = json_decode($m_res['turnover_ratio'],true);
}
}else{
$default_r = $cgr_res['ratio'];
$turnover_ratio = json_decode($cgr_res['turnover_ratio'],true);
}
//执行比例
if (!$type || !$turnover_ratio) {
return $default_r;
}
//获取比例
$ratio = $default_r;
foreach($turnover_ratio as $k=>$v){
if($v['instanceof'] == 1){
if($amount >= $v['turnover']){
$ratio = $v['ratio'];
}
}else{
if($amount > $v['turnover']){
$ratio = $v['ratio'];
}
}
}
return $ratio;
}
function check_str($str, $substr)
{
$nums=substr_count($str,$substr);
return $nums;
}
function getPromoteGameRatio($promoteID = 0, $relationGameId = 0, $amount=0, $timeStart=0, $timeEnd=0, $isDefault = false)
{
$map = " promote_id = {$promoteID} and relation_game_id = {$relationGameId} and status = 1 and begin_time <= {$timeStart} ";
if ($timeEnd) {
$map .= " and (end_time = 0 or end_time >= {$timeEnd}) ";
}
$result = M('promote_game_ratio_log', 'tab_')->where($map)->order('id desc')->find();
if (!$result) return 0;
$ratios = array_reverse(json_decode($result['turnover_ratio'], true));
if (!$ratios) return 0;
if ($isDefault) {
return $result['ratio'] ?: 0;
}
$ratio = $result['ratio'];
foreach ($ratios as $item) {
if (($item['instanceof'] == 1 && $amount >= $item['turnover']) || ($item['instanceof'] == 2 && $amount > $item['turnover'])) {
$ratio = $item['ratio'];
break;
}
}
return $ratio;
}
//验证账号
function checkAccount($type,$account) {
// $type = I('type');
// $account = I('account');
$map = [];
$map['account'] = $account;
if ($type == 1) {
$result = M('promote','tab_')->field('account')->where($map)->find();
} else {
$result = M('user','tab_')->field('account')->where($map)->find();
}
if ($result) {
return 1;
} else {
return 0;
}
}
//去重函数
function a_array_unique($array){
$out = array();
foreach ($array as $key=>$value) {
if (!in_array($value, $out)){
$out[$key] = $value;
}
}
$out = array_values($out);
return $out;
}
/**
* 获取团体归属类型
* @author chenzhi 20200219
* $id 不传返回所有类型列表
* 传入ID 返回对应的团体类型
*/
function getCompanyBlong($id = -1)
{
$data = array(
["id"=>0,'name'=>"内团"],
["id"=>1,'name'=>"外团"],
["id"=>2,'name'=>"外团-分发"],
["id"=>3,'name'=>""]
);
if($id > -1){
foreach($data as $k=>$v){
if($v['id'] == $id){
return $v['name'];
break;
}
}
}else{
return $data;
}
}
/**
* 获取团体归属类型其他
* @author chenzhi 20200219
* $id 不传返回所有类型列表
* 传入ID 返回对应的团体类型
*/
function getCompanyBlongOther($id = -1)
{
$data = array(
["id"=>0,'name'=>"内团"],
["id"=>1,'name'=>"外团"],
["id"=>2,'name'=>"外团-分发"],
["id"=>3,'name'=>""],
["id"=>'1,2','name'=>"外团&外团-分发"]
);
if($id > -1){
foreach($data as $k=>$v){
if($v['id'] == $id){
return $v['name'];
break;
}
}
}else{
return $data;
}
}
/**
* 获取公会归属关系
* @author chenzhi 20200219
* $id 不传返回所有关系列表
* 传入ID 返回对应的团体关系
*/
function getCompanyRelation($id = -1)
{
$data = array(
["id"=>0,'name'=>""],
["id"=>1,'name'=>"自主开发"],
["id"=>2,'name'=>"自主开发及维护"],
["id"=>3,'name'=>"只维护"]
);
if($id > -1){
foreach($data as $k=>$v){
if($v['id'] == $id){
return $v['name'];
break;
}
}
}else{
return $data;
}
}
/**
* 获取公会等级对应名称
* @author chenzhi 20200219
* $id 不传返回所有等级名称
* 传入ID 返回对应的等级名称
*/
function getPromoteLeverName($id = -1)
{
$data = array(
["id"=>1,'name'=>"会长"],
["id"=>2,'name'=>"部门长"],
["id"=>3,'name'=>"组长"],
["id"=>4,'name'=>"组员"],
);
if($id > -1){
foreach($data as $k=>$v){
if($v['id'] == $id){
return $v['name'];
break;
}
}
}else{
return $data;
}
}
/**
* 操作日志
* array(
* op_type=>操作类型 0:新增1:编辑 2:删除 3:下载,
* op_name=>操作说明 例如:编辑,删除,锁定等,
* url=>需要跳转的url 添加去列表加唯一id编辑直接去编辑页面下载可以重新下载(新开页面),
* key=>关键词:用户的账号,游戏的名词等,
* menu=>非必须,菜单目录,不存在的话按控制器寻找。
* )
*/
function addOperationLog($options)
{
$checkarr = ['op_type','url','key'];
foreach ($checkarr as $v) {
if(!array_key_exists($v,$options)){
return false;
}
}
if(!array_key_exists("op_name",$options)){
$options['op_name'] = ($options['op_type'] == 1 ? "编辑" : ($options['op_type'] == 2 ? "删除" :($options['op_type'] == 3 ? "导出" :"新增")));
}
//获取ip
$addarray = [
"op_ip"=>$_SERVER['REMOTE_ADDR'],
'admin_id'=>$_SESSION['onethink_admin']['user_auth']['uid'],
'admin_account'=>$_SESSION['onethink_admin']['user_auth']['username'],
'op_type'=>$options['op_type'],
'op_name'=>$options['op_name'],
'url'=>$options['url'],
'key'=>$options['key'],
'create_time'=>time()
];
//获取菜单名称
if(!array_key_exists("menu",$options)){
$act = CONTROLLER_NAME.'/'.ACTION_NAME;
$arr = [];
$menuname = D("menu")->field('title,pid,group')->where("url = '{$act}'")->find();
if($menuname){
$arr[] = $menuname['title'];
if(!empty($menuname['group'])){
$arr[] = $menuname['group'];
}
getLink($menuname['pid'],$arr);
}
$addarray['menu'] = implode ( "-",array_reverse($arr));
}else{
$addarray['menu'] = $options['menu'];
}
M("OperationLog","tab_")->add($addarray);
}
function getLink($pid=0,&$arr){
if($pid == 0){
return;
}
$menuname = D("menu")->field('title,pid,group')->where("id = '{$pid}'")->find();
if($menuname){
$arr[] = $menuname['title'];
if(!empty($menuname['group'])){
$arr[] = $menuname['group'];
}
if($menuname['pid'] != 0){
getLink($menuname['pid'], $arr);
}
}
}
function getNowDate() {
return date('YmdHis',time());
}
//根据推广员id获取推广员姓名
function getPromoteName($id) {
if (!$id) {
return '';
}
$name = M('promote','tab_')
->where(['id'=>$id])
->find()['account'];
return $name;
}
//根据关联id获取游戏名称
function getrelationGameName($id) {
if (!$id) {
return '';
}
$name = M('game','tab_')
->where(['relation_game_id'=>$id])
->find()['relation_game_name'];
return $name;
}
/**
* 获取测试资源可用余额
* promote_id=>推广员id,
* game_id=>游戏id,
*/
function getAvailableBalance($promote_id=0,$game_id=0,$server_id='') {
if (!$promote_id||!$game_id||!$server_id) {
return 0;
}
$availableBalanceData = M('promote_game_available_balance','tab_')
->field('available_balance')
->where(['promote_id'=>$promote_id,'game_id'=>$game_id,'server_name'=>$server_id])
->find();
return $availableBalanceData['available_balance']?$availableBalanceData['available_balance']:0;
}
function getMarketGroupIds()
{
return M('auth_group', 'sys_')->where(['title' => ['like', '%市场专员%']])->getField('id', true);
}
function getAdmins()
{
return M('ucenter_member', 'sys_')->select();
}
function getMarketAdmins()
{
$ids = getMarketGroupIds();
if (count($ids) == 0) {
return [];
}
$adminIds = M('auth_group_access', 'sys_')->where(['group_id' => ['in', $ids]])->getField('uid', true);
return M('ucenter_member', 'sys_')->where(['id' => ['in', $adminIds]])->select();
}
function getMarketAdminsByPromoteIds($promoteIds)
{
if (count($promoteIds) == 0) {
return [];
}
$promotes = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => ['in', $promoteIds]])->select();
$resultMap = [];
foreach ($promotes as $promote) {
if ($promote['chain'] == '/') {
$resultMap[$promote['id']] = ['top_id' => $promote['id']];
} else {
$item = explode('/', trim($promote['chain'], '/'));
$resultMap[$promote['id']] = ['top_id' => $item[0]];
}
}
if (count($promotes) == 0) {
return [];
}
$topPromotes = M('promote', 'tab_')->field(['id', 'admin_id'])->where(['id' => ['in', array_column($resultMap, 'top_id')]])->select();
$topAdminMap = [];
foreach ($topPromotes as $topPromote) {
$topAdminMap[$topPromote['id']] = $topPromote['admin_id'];
}
$admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', array_column($topPromotes, 'admin_id')]])->select();
$admins = index_by_column('id', $admins);
foreach ($resultMap as &$row) {
$adminId = $topAdminMap[$row['top_id']] ?? 0;
$admin = $admins[$adminId] ?? null;
$row['admin'] = $admin;
}
return $resultMap;
}
function getAdminUsernameList(array $ids)
{
if (count($ids) == 0) {
return [];
}
$admins = M('ucenter_member', 'sys_')->field(['id', 'username'])->where(['id' => ['in', $ids]])->select();
$items = [];
foreach ($admins as $admin) {
$items[$admin['id']] = $admin['username'];
}
return $items;
}
function isMarketLeader()
{
$authGroup = M('sys_auth_group')->where(['title'=>'市场总监'])->find();
if (!$authGroup) {
return false;
}
$userAuth = session('user_auth');
$adminIds = M('auth_group_access', 'sys_')->where(['group_id' => $authGroup['id']])->getField('uid', true);
return in_array($userAuth['uid'], $adminIds);
}
function isMarketAdmin()
{
$ids = getMarketGroupIds();
if (count($ids) == 0) {
return false;
}
$userAuth = session('user_auth');
$adminIds = M('auth_group_access', 'sys_')->where(['group_id' => ['in', $ids]])->getField('uid', true);
return in_array($userAuth['uid'], $adminIds);
}
/**
*
* 获取市场专员
*
*/
function getMarketAdmin() {
$map['group_id'] = ['in','11,12,21'];
$admin_id = $_SESSION['onethink_admin']['user_auth']['uid'];
$map['menber.uid'] = $admin_id;
if(is_administrator()||session('user_group_id') == 15||session('user_group_id') == 14) {
unset($map['menber.uid']);
}
$data = M("auth_group_access")
->field("real_name,menber.uid,nickname")
->join("left join sys_member menber on sys_auth_group_access.uid = menber.uid")
->where($map)
->select();
foreach ($data as $key => $value) {
!$value['real_name'] ? ($data[$key]['real_name'] = "未命名"):"";
}
return $data;
}
function is_sendBonus($pay_time = '',$admin_id = '') {
$market_altogether = M("market_altogether","tab_")
->where(['pay_time'=>$pay_time,'admin_id'=>$admin_id])
->find();
if ($market_altogether['status'] > 0) {
return 1;
} else {
return 0;
}
}
function getPromoteIdsByTopIds($ids)
{
if (count($ids) == 0) {
return [];
}
$idsExp = implode(',', $ids);
$map = array();
$where['SUBSTRING_INDEX(SUBSTRING_INDEX(`chain`,"/",2),"/",-1)'] = array('exp',"IN({$idsExp})");
$where['id'] = array('in', $ids);//会长本身
$where['_logic'] = 'or';
$map['_complex'] = $where;
$result = M('promote', 'tab_')->field('id')->where($map)->getField('id', true);
return $result;
}
function getCompanyDevelopTypes()
{
return [
1 => '自主开发',
2 => '自主开发及维护',
3 => '只维护',
];
}
function getCompanyDevelopTypesOther()
{
return [
1 => '自主开发',
2 => '自主开发及维护',
3 => '只维护',
'1,2'=>'自主开发&自主开发及维护'
];
}
function getCompanyDevelopTypeText($type)
{
return getCompanyDevelopTypes()[$type] ?? '无';
}
function withMarketAdminCondition($map, $searchMarketAdminId = 0)
{
$adminId = 0;
$isMarketAdmin = isMarketAdmin();
if ($isMarketAdmin) {
$userAuth = session('user_auth');
$adminId = $userAuth['uid'];
}
if ($adminId == 0) {
$adminId = $searchMarketAdminId > 0 ? $searchMarketAdminId : 0;
}
if ($adminId) {
$topPromoteIds = M('promote', 'tab_')->where(['admin_id' => $adminId, 'level' => 1])->getField('id', true);
$promoteIds = getPromoteIdsByTopIds($topPromoteIds);
if (count($promoteIds) == 0) {
$promoteIds = [-1];
}
$map['promote_id'] = ['in', $promoteIds];
}
return $map;
}
function getMarketMonth() {
$start = date("Y-m", strtotime("+4 month"));
//开始月份
$range = [];
$i = 1;
do {
$month = date('Y-m', strtotime($start . ' - ' . $i . ' month'));
$range[] = $month;
$i++;
} while ($i<13);
return $range;
}
function getDateMarket() {
$admin_id = $_SESSION['onethink_admin']['user_auth']['uid'];
$map['access.uid'] = $admin_id;
if(is_administrator()) {
unset($map['access.uid']);
}
$data = M("member")
->field("access.uid admin_id,real_name,nickname,market_percentage")
->join("left join sys_auth_group_access access on sys_member.uid = access.uid")
->join("left join sys_auth_group auth on access.group_id=auth.id")
->where(['group_id'=>['in','11,12,21']])
->where($map)
->select();
$return = [];
$num = 0;
foreach ($data as $key => $value) {
$group_config = json_decode($value['market_percentage'],true);
$arr_month = getMarketMonth();
foreach ($arr_month as $k => $v) {
// var_dump($v);
$month = date("m",strtotime($v));
if ($group_config['time'] == 1) {
// echo $v.' '."\n";
if ($month == '07'||$month == '10'||$month == '04'||$month == '01') {
$return[$num]['admin_id'] = $value['admin_id'];
$return[$num]['real_name'] = $value['real_name'];
$return[$num]['pay_time'] = $v;
$num++;
}
} elseif($group_config['time'] == 2) {
if ($month == '07'||$month == '01') {
$return[$num]['admin_id'] = $value['admin_id'];
$return[$num]['real_name'] = $value['real_name'];
$return[$num]['pay_time'] = $v;
$num++;
}
} elseif($group_config['time'] == 3) {
if ($month == '01') {
$return[$num]['admin_id'] = $value['admin_id'];
$return[$num]['real_name'] = $value['real_name'];
$return[$num]['pay_time'] = $v;
$num++;
}
} else {
$return[$num]['admin_id'] = $value['admin_id'];
$return[$num]['real_name'] = $value['real_name'];
$return[$num]['pay_time'] = $v;
$num++;
}
}
}
// dump($return);
return $return;
}
/**
* 渠道列表
* @param $type
* @return mixed
*/
function promote_listsMarket($type){
if($type){
$map['level'] = $type;
} else{
$map = '';
}
// $promoteRoot = getPowerPromoteIds();
// if ($promoteRoot) {
// $map['id'] =array('in',$promoteRoot);
// }
setPowerPromoteIds($map,'id');
$admin_id = $_SESSION['onethink_admin']['user_auth']['uid'];
$map['admin_id'] = $admin_id;
if(is_administrator()||session('user_group_id') == 15||session('user_group_id') == 14) {
unset($map['admin_id']);
}
$data = M('promote','tab_')->where($map)->select();
$items = M('PromoteBalanceCoin', 'tab_')->where(['game_id' => 0])->select();
$records = [];
foreach ($items as $item) {
$records[$item['promote_id']] = $item['num'];
}
foreach ($data as $key => $item) {
$item['common_coin'] = isset($records[$item['id']]) ? $records[$item['id']] : $item['balance_coin'];
$data[$key] = $item;
}
return $data;
}
//市场部获取公司或推广员id
function getMarketAuthPromoteId()
{
$map['level'] = 1;
if (isMarketLeader()) {
$map['admin_id'] = ['gt', 0];
}elseif(isMarketAdmin()){
$userAuth = session('user_auth');
$adminId = $userAuth['uid'];
$map['admin_id'] = $adminId;
}else{
return false;
}
$dbres = M("Promote","tab_")->where($map)->getField("id",true);
if(empty($dbres)){
return -1;
}else{
return implode(",",$dbres);
}
}
function throwPromoteIdToCompanyId($p_ids)
{
$map["id"]=["in","{$p_ids}"];
$dbres = M("Promote","tab_")->where($map)->group("company_id")->getField("company_id",true);
if(empty($dbres)){
return -1;
}else{
return implode(",",$dbres);
}
}
/**
* 选择收款商户
* @param $type
* @return mixed
*/
function getMerchant($type = 0){
if ($type) {
$data = M('payment_merchant','tab_')
->field("id,name,identifier,account,main_name")
->where(['status'=>1,'type'=>1])
->group("main_name")
->select();
} else {
$data = M('payment_merchant','tab_')
->field("id,name,identifier,account,main_name")
->where(['status'=>1,'type'=>1])
->select();
}
return $data;
}
/**
* 聚合公司筛选项
* @param $type 1 渠道 2 包名获取
* @return mixed
*/
function getCpCompanySelect($type = 1){
$request['req'] = 1;
if ($type == 1) {
$url = M("kv")->field("value")->where(['key'=>"cp_company_channel_api"])->find();
$data = json_decode(curl_post($url['value'],$request),true);
} elseif($type == 2) {
$url = M("kv")->field("value")->where(['key'=>"cp_company_gamename_api"])->find();
$data = json_decode(curl_post($url['value'],$request),true);
} else {
return [];
}
return $data;
}
/**
* 回去商户列表
* @return mixed
*/
function getMerchantList($type = 1){
$data = M("payment_merchant","tab_")->field("id,name,ways")->select();
return $data;
}
/**
* 回去商户列表
* @param $type 1 渠道 2 包名获取
* @return mixed
*/
function getMerchantName($id = 1){
$data = M("payment_merchant","tab_")->field("name")->where(['id'=>$id])->find();
return $data['name']?$data['name']:'无';
}