@ -439,28 +439,24 @@ class PlatformController extends ThinkController
$today = total(1);
$week = total(2);
$mounth = total(3);
if (isset($_REQUEST['promote_id'])) {
$map['tp1.id'] = $_REQUEST['promote_id'];
} else {
$map['tp1.chain'] = '/';
$promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select();
if ($promoter_ids) {
$map['u.promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))];
}
}
//为数据权限添加
setPowerPromoteIds($map, 'u.promote_id');
$data = M('promote', 'tab_')->alias('tp1')
->field('tp1.account as promote_account,tp1.id,
date_format(FROM_UNIXTIME(register_time),"% ") AS time,
count(u.id) as count')
->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left')
->join("tab_user as u on tp2.id = u.promote_id", 'left')
->join($play_map ? "tab_user_play as up on up.user_id = u.id " . $play_map : false)
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->where($map)
->group('tp1.id')
->order('count desc, register_time')
->select();
$data = M("User u","tab_")
->field("count(u.id) as count,IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',u.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) id")
->join("tab_promote promote ON u.promote_id = promote.id","left")
->join($play_map ? "tab_user_play as up on up.user_id = u.id " . $play_map : false)
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->where($map)
->group('id')
->order('count desc, register_time')
->select();
//今日/本周/本月不变
$tmap = $map;
if(isset($tmap['register_time'])){
@ -476,21 +472,19 @@ class PlatformController extends ThinkController
}
$tmap['register_time'] = ['between', array($tmin,$tmonth[1][1])];
}
$tdata = M('promote', 'tab_')->alias('tp1')
->field('tp1.account as promote_account,tp1.id,
date_format(FROM_UNIXTIME(register_time),"% ") AS time,
count(IF(register_time ' . $today . ',1,null)) as today,
count(IF(register_time ' . $week . ',1,null)) as week,
count(IF(register_time ' . $mounth . ',1,null)) as mounth')
->join("tab_promote AS tp2 ON tp2.`chain` LIKE CONCAT('%/', tp1.id, '/%') OR tp2.id = tp1.id", 'left')
->join("tab_user as u on tp2.id = u.promote_id", 'left')
->join($play_map ? "tab_user_play as up on up.user_id = u.id " . $play_map : false)
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->where($tmap)
->group('tp1.id')
->order('register_time')
->select();
$tdata = M("User u","tab_")
->field("count(IF(register_time {$today},1,null)) as today,
count(IF(register_time {$week},1,null)) as week,
count(IF(register_time {$mounth},1,null)) as mounth,
IFNULL(if(substring_index(substring_index(promote.`chain`,'/',2),'/',-1)='',u.promote_id,substring_index(substring_index(promote.`chain`,'/',2),'/',-1)),0) id")
->join("tab_promote promote ON u.promote_id = promote.id","left")
->join($play_map ? "tab_user_play as up on up.user_id = u.id " . $play_map : false)
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->where($tmap)
->group('id')
->order('register_time')
->select();
$tmdata = [];
foreach($data as $k=>$v){
$v['today'] = 0;
@ -503,18 +497,24 @@ class PlatformController extends ThinkController
$tmdata[$v['id']]['today'] = $v['today'];
$tmdata[$v['id']]['week'] = $v['week'];
$tmdata[$v['id']]['mounth'] = $v['mounth'];
if (!$tmdata[$v['id']]['promote_account']) {
$tmdata[$v['id']]['promote_account'] = $v['promote_account'];
$tmdata[$v['id']]['count'] = 0;
}
$tmdata[$v['id']]['id'] = $v['id'];
}
}
if(count($tmdata) >0){
//获取推广员
$idstr = implode(",",array_keys($tmdata));
$promoteRes = M("Promote","tab_")->field("id,account promote_account")->where("id in ({$idstr})")->select();
foreach($promoteRes as $k=>$v){
$tmdata[$v['id']]['promote_account'] = $v['promote_account'];
}
}
$data = [];
foreach($tmdata as $k => $v){
if($v['id'] == 0){
$v['promote_account'] = "官方渠道";
}
$data[] = $v;
}
unset($map['tp1.id']);
unset($map['tp1.chain']);
unset($tmap['tp1.id']);
@ -522,38 +522,6 @@ class PlatformController extends ThinkController
$map['u.promote_id'] = 0;
$tmap['u.promote_id'] = 0;
$authorityData['count'] = 0;
//如果有官方渠道权限
$user_auth_promote_ids = session('user_auth_promote_ids');
if ($user_auth_promote_ids == 'all' || in_array('0', explode(",", $user_auth_promote_ids))) {
//官方渠道数据添加
$authorityData = M('user', 'tab_')->alias('u')
->field('date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time,count(u.id) as count')
->join($play_map ? "tab_user_play as up on up.user_id = u.id " . $play_map : false)
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->where($map)
->find();
$tauthorityData = M('user', 'tab_')->alias('u')
->field('date_format(FROM_UNIXTIME(register_time),"%Y-%m-%d") AS time,
count(IF(register_time ' . $today . ',1,null)) as today,
count(IF(register_time ' . $week . ',1,null)) as week,
count(IF(register_time ' . $mounth . ',1,null)) as mounth')
->where($tmap)
->join($play_map ? "tab_user_play as up on up.user_id = u.id " . $play_map : false)
->join($play_info_map ? "tab_user_play_info as upi on upi.user_id = u.id " . $play_info_map : false)
->find();
$authorityData['today'] = $tauthorityData['today'];
$authorityData['week'] = $tauthorityData['week'];
$authorityData['mounth'] = $tauthorityData['mounth'];
}
$authorityData['promote_account'] = "官方渠道";
$authorityData['id'] = "1";
if (isset($_REQUEST['promote_id'])||$authorityData['count']==0) {
$authorityData = [];
} else {
array_push($data, $authorityData);
}
//数据排序
$last_names = array_column($data,'count');
array_multisort($last_names,SORT_DESC,$data);