Merge remote-tracking branch 'origin/fix/admin_second_optimization' into fix/admin_second_optimization

master
zhengyongxing 5 years ago
commit 80d48600f7

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

Loading…
Cancel
Save