Commit d4957fad by 冷斌

fix bug

parent ee50aefd
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<li><a href="{:U('Gather/add')}">添加</a></li> <li><a href="{:U('Gather/add')}">添加</a></li>
</if> </if>
</ul> </ul>
<form class="well form-search" method="post" action="{:U('Gather/index')}"> <form class="well form-search" name="form1" method="post" action="{:U('Gather/index')}">
类型: 类型:
<select class="select_2" name="type" id="four"> <select class="select_2" name="type" id="four">
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
时间段: 时间段:
<input type="text" name="start_time" class="js-date date" id="start_time" value="{$formget.start_time}" style="width: 80px;" autocomplete="off">- <input type="text" name="start_time" class="js-date date" id="start_time" value="{$formget.start_time}" style="width: 80px;" autocomplete="off">-
<input type="text" class="js-date date" name="end_time" id="end_time" value="{$formget.end_time}" style="width: 80px;" autocomplete="off"> &nbsp; &nbsp; <input type="text" class="js-date date" name="end_time" id="end_time" value="{$formget.end_time}" style="width: 80px;" autocomplete="off"> &nbsp; &nbsp;
<input type="submit" class="btn btn-primary" value="搜索"> <input type="submit" class="btn btn-primary" value="搜索" onclick="form1.action='{:U('Gather/index')}';form1.submit();">
<input type="button" class="btn btn-primary" style="background-color: #1dccaa;" value="导出" onclick="form1.action='{:U('Gather/export')}';form1.submit();"/>
<div style="margin-top:10px"> <div style="margin-top:10px">
{$date}月数据统计 (根据筛选条件统计) {$date}月数据统计 (根据筛选条件统计)
<span style="color:red;font-size: 17px;"> <span style="color:red;font-size: 17px;">
...@@ -40,11 +41,11 @@ ...@@ -40,11 +41,11 @@
<th>注册人数</th> <th>注册人数</th>
<th>充值金额</th> <th>充值金额</th>
<th>充值人数</th> <th>充值人数</th>
<th>守护金额(萌币</th> <th>守护金额(钻石</th>
<th>商城消费(萌币</th> <th>商城消费(钻石</th>
<th>自客自销(萌币</th> <th>自客自销(钻石</th>
<th>他客自销(萌币</th> <th>他客自销(钻石</th>
<th>自客他销(萌币</th> <th>自客他销(钻石</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
......
...@@ -479,4 +479,441 @@ class GatherController extends AdminbaseController{ ...@@ -479,4 +479,441 @@ class GatherController extends AdminbaseController{
$this->assign("users",$users); $this->assign("users",$users);
$this->display(); $this->display();
} }
function export(){
$Charge=M('users_charge');//充值表
$coin=M("users_coinrecord");//礼物支出
$Proxy=M('users_proxy');
$User=M('users');
$adminid = $_SESSION['ADMIN_ID'];
$date = date("Y-m");//默认当月
$stime = $date.'-01 00:00:00';//默认当月一号开始
$etime = $date.date("-d H:i:s");//当前时间
//默认时间搜索条件
$amap['addtime'] = array("between",array(strtotime($stime),strtotime($etime)));
$bmap['create_time'] = array("between",array($stime,$etime));
$where=[];
$where1=[];
if($_REQUEST['start_time']!=''){
$amap['addtime']=array("gt",strtotime($_REQUEST['start_time'].' 00:00:00'));
$bmap['create_time']=array("gt",$_REQUEST['start_time'].' 00:00:00');
$_GET['start_time']=$_REQUEST['start_time'];
}
if($_REQUEST['end_time']!=''){
$amap['addtime']=array("lt",strtotime($_REQUEST['end_time'].' 23:59:59'));
$bmap['create_time']=array("lt",$_REQUEST['end_time'].' 23:59:59');
$_GET['end_time']=$_REQUEST['end_time'];
}
if($_REQUEST['start_time']!='' && $_REQUEST['end_time']!='' ){
$amap['addtime']=array("between",array(strtotime($_REQUEST['start_time'].' 00:00:00'),strtotime($_REQUEST['end_time'].' 23:59:59')));
$bmap['create_time']=array("between",array($_REQUEST['start_time'].' 00:00:00',$_REQUEST['end_time'].' 23:59:59'));
$_GET['start_time']=$_REQUEST['start_time'];
$_GET['end_time']=$_REQUEST['end_time'];
}
//扶持账户
$fuchi = $User->where("rg_multiple>1")->getField('id',true);//充值倍数大于1的
//当前管理员
$user = $User->where("id={$_SESSION['ADMIN_ID']}")->find();
$_GET['type'] = 0;
//管理员类型
if($user['tg_type'] == 0){//平台
$where['tg_type'] = array('in',array('2','3','4','5'));
if($_REQUEST['type'] == 1){
$where['tg_type'] = 2;
$_GET['type'] = 1;
}
if($_REQUEST['type'] == 2){
$where['tg_type'] = 3;
$_GET['type'] = 2;
}
if($_REQUEST['type'] == 3){
$where['tg_type'] = 4;
$_GET['type'] = 3;
}
if($_REQUEST['type'] == 4){
$where['tg_type'] = 5;
$_GET['type'] = 4;
}
$this->assign('types',array(
array(
'type' => 0,
'name' => "总数据"
),
array(
'type' => 1,
'name' => "一级推广"
),
array(
'type' => 2,
'name' => "二级推广"
),
array(
'type' => 3,
'name' => "主播"
),
array(
'type' => 4,
'name' => "业务员"
)
));
}else{//代理主播业务员
//和自己有关的用户
$pa=setpath($adminid);
$uids0=$Proxy->where("path like '%{$pa}%' and (type = 3 or type = 0)")->getField('uid',true);
if(!$uids0){
$uids0=[];
array_push($uids0,'0');
}
$where1['uid'] = array('in',$uids0);
if($user['tg_type'] == 2){//一级代理
if($_REQUEST['type'] == 0){
$where['id'] = $adminid;//默认自己
}else{
$where['tg_type'] = array('in',array('3','4','5'));//查看自己下面的和二级代理,主播,业务员
}
if($_REQUEST['type'] == 2){
$where['tg_type'] = 3;
$_GET['type'] = 2;
//和自己有关的二级代理
$path1=setpath($adminid);
$uids1=$Proxy->where("path like '%{$path1}%' and type = 2")->getField('uid',true);
if(!$uids1){
$uids1=[];
array_push($uids1,'0');
}
$where['id'] = array('in',$uids1);
//和二级代理有关的
}
if($_REQUEST['type'] == 3){
$where['tg_type'] = 4;
$_GET['type'] = 3;
//和自己有关的主播
$path1=setpath($adminid);
$uids1=$Proxy->where("path like '%{$path1}%' and type = 3")->getField('uid',true);
if(!$uids1){
$uids1=[];
array_push($uids1,'0');
}
$where['id'] = array('in',$uids1);
}
if($_REQUEST['type'] == 4){
$where['tg_type'] = 5;
$_GET['type'] = 4;
//和自己有关的业务员
$path1=setpath($adminid);
$uids1=$Proxy->where("path like '%{$path1}%' and type = -1")->getField('uid',true);
if(!$uids1){
$uids1=[];
array_push($uids1,'0');
}
$where['id'] = array('in',$uids1);
}
$this->assign('type',$_REQUEST['type']);
$this->assign('types',array(
array(
'type' => 0,
'name' => "我的数据"
),
array(
'type' => 2,
'name' => "二级推广"
),
array(
'type' => 3,
'name' => "主播"
),
array(
'type' => 4,
'name' => "业务员"
)
));
}elseif($user['tg_type'] == 3){//二级代理
//$where['tg_type'] = array('in',array('4','5'));//查看主播,业务员
if($_REQUEST['type'] == 0){
$where['id'] = $adminid;//默认自己
}else{
$where['tg_type'] = array('in',array('4','5'));//查看自己下面的,主播,业务员
}
if($_REQUEST['type'] == 3){
$where['tg_type'] = 4;
$_GET['type'] = 3;
//和自己有关的主播
$path1=setpath($adminid);
$uids1=$Proxy->where("path like '%{$path1}%' and type = 3")->getField('uid',true);
if(!$uids1){
$uids1=[];
array_push($uids1,'0');
}
$where['id'] = array('in',$uids1);
}
if($_REQUEST['type'] == 4){
$where['tg_type'] = 5;
$_GET['type'] = 4;
//和自己有关的业务员
$path1=setpath($adminid);
$uids1=$Proxy->where("path like '%{$path1}%' and type = -1")->getField('uid',true);
if(!$uids1){
$uids1=[];
array_push($uids1,'0');
}
$where['id'] = array('in',$uids1);
}
$this->assign('type',$_REQUEST['type']);
$this->assign('types',array(
array(
'type' => 0,
'name' => "我的数据"
),
array(
'type' => 3,
'name' => "主播"
),
array(
'type' => 4,
'name' => "业务员"
)
));
}elseif($user['tg_type'] == 4){//主播
//$where['tg_type'] = array('in',array('5'));//查看业务员的
if($_REQUEST['type'] == 0){
$where['id'] = $adminid;//默认自己
}else{
$where['tg_type'] = array('in',array('5'));//查看自己下面的,业务员
}
if($_REQUEST['type'] == 4){
$where['tg_type'] = 5;
$_GET['type'] = 4;
//和自己有关的业务员
$path1=setpath($adminid);
$uids1=$Proxy->where("path like '%{$path1}%' and type = -1")->getField('uid',true);
if(!$uids1){
$uids1=[];
array_push($uids1,'0');
}
$where['id'] = array('in',$uids1);
}
$this->assign('type',$_REQUEST['type']);
$this->assign('types',array(
array(
'type' => 0,
'name' => "我的数据"
),
array(
'type' => 4,
'name' => "业务员"
)
));
$this->assign('showlevel',3);
}elseif($user['tg_type'] == 5){//业务员查看用户消费情况
//$where['tg_type'] = 1;
$where['id'] = $adminid;//默认自己
$this->assign('types',array(
array(
'type' => 0,
'name' => "我的数据"
),
));
}
}
/* 展示列表 */
$users = $User
->field('*')
->where($where)
->order("create_time DESC")
->select();//列表用户信息
if(!empty($users)){
foreach ($users as $k1 => $v1) {
if($v1['tg_type'] == 2){
$v1['rbac'] = '一级代理';
}elseif($v1['tg_type'] == 3){
$v1['rbac'] = '二级代理';
}elseif($v1['tg_type'] == 4){
$v1['rbac'] = '主播';
}elseif($v1['tg_type'] == 5){
$v1['rbac'] = '业务员';
}
$path1=setpath($v1['id']);
$uids1=$Proxy->where("path like '%{$path1}%' and (type = 0 or type = 3)")->getField('uid',true);//和当前列管理员有关的所有普通用户或者主播
if(!$uids1){
$uids1=[];
array_push($uids1,'0');
}
//充值金额
$map=$amap;
$map['uid'] = array('in',$uids1);
$total_charge=$Charge->where("status=1 and uid not in (".implode(",", $fuchi).")")->where($map)->sum('money');
if(!$total_charge){
$total_charge='0';
}
//充值人数
$total_charge_num=count($Charge->where("status=1 and uid not in (".implode(",", $fuchi).")")->where($map)->group('uid')->select());
//$v1['sql'] = $Charge->getLastSql();
if(!$total_charge_num){
$total_charge_num='0';
}
$v1['total_charge_num']=$total_charge_num;
$v1['total_charge']=$total_charge;
//注册人数
$map2=$bmap;
$map2['id'] = array('in',$uids1);
$total_reg=$User->where("user_type=2 and id not in (".implode(",", $fuchi).")")->where($map2)->count();
if(!$total_reg){
$total_reg='0';
}
$v1['total_reg']=$total_reg;
$map1=$amap;
$map1['uid'] = array('in',$uids1);
//守护金额
$guardcoin = $coin->where("type='expend' and action='buyguard' and uid not in (".implode(",", $fuchi).")")->where($map1)->sum('totalcoin');
if(!$guardcoin){
$guardcoin = '0';
}
$v1['guardcoin'] = $guardcoin;
//商城消费buyvip buyliang buycar
$mallcoin = $coin->where("type='expend' and (action='buyvip' or action='buyliang' or action='buycar') and uid not in (".implode(",", $fuchi).")")->where($map1)->sum('totalcoin');
if(!$mallcoin){
$mallcoin = '0';
}
$v1['mallcoin'] = $mallcoin;
//自客自销,他客自销,自客他销
$solt1 = 0;
$solt2 = 0;
$expends = $coin->where("type='expend' and action='sendgift' and uid not in (".implode(",", $fuchi).")")->where($map1)->select();//当前列管理相关的所有用户送的礼物
//$v1['test'] = $coin->getLastSql();
if($v1['tg_type'] == 2 || $v1['tg_type'] == 3){//对于代理来说
foreach ($expends as $k2 => $v2) {
if(!empty($fuchi) && in_array($v2['uid'], $fuchi)){//排除扶持账户
continue;
}
// $uid = str_pad($v2['uid'],8,"0",STR_PAD_LEFT);//送礼的人
// $iszi = $Proxy->where("uid = {$v2['uid']} and (type = 0 or type = 3) and path like '%{$path1}%'")->count();
$touid = str_pad($v2['touid'],8,"0",STR_PAD_LEFT);//收礼的人
$iszi = $Proxy->where("uid = {$v2['touid']} and (type = 0 or type = 3) and path like '%{$path1}%'")->count();
//var_dump($Proxy->getLastSql());
if($iszi){//自客自销
$solt1 += $v2['totalcoin'];
}else{//自客他销
$solt2 += $v2['totalcoin'];
}
}
$v1['solt1'] = $solt1;
$v1['solt2'] = $solt2;
}elseif($v1['tg_type'] == 4 || $v1['tg_type'] == 5){//主播,业务员
foreach ($expends as $k2 => $v2) {
if(!empty($fuchi) && in_array($v2['uid'], $fuchi)){//排除扶持账户
continue;
}
$uid = str_pad($v2['uid'],8,"0",STR_PAD_LEFT);//送礼的人
$touid = str_pad($v2['touid'],8,"0",STR_PAD_LEFT);//收礼的人
$iszi = $Proxy->where("uid = {$v2['uid']} and (type = 0 or type = 3) and path like '%{$touid}%'")->count();
//var_dump($Proxy->getLastSql());
if($iszi){//自客自销
$solt1 += $v2['totalcoin'];
}else{//自客他销
$solt2 += $v2['totalcoin'];
}
}
$v1['solt1'] = $solt1;
$v1['solt2'] = $solt2;
}
//他客自销
$solt3 = 0;
$map3 = $amap;
if($v1['tg_type'] == 2 || $v1['tg_type'] == 3){//如果是代理
$uids2 = $Proxy->where("type = 3 and path like '%{$path1}%'")->getField('uid',true);//相关的主播
if(!$uids2){
$uids2=[];
array_push($uids2,'0');
}
$map3['touid'] = array('in',$uids2);
$expends1 = $coin->where("type='expend' and action='sendgift' and uid not in (".implode(",", $fuchi).")")->where($map3)->select();//当前列管理相关的所有主播收的礼物
//$v1['test2'] = $coin->getLastSql();
foreach ($expends1 as $k3 => $v3) {
//$uid = str_pad($v3['uid'],8,"0",STR_PAD_LEFT);//送礼的人
//$touid = str_pad($v3['touid'],8,"0",STR_PAD_LEFT);//收礼的人
$iszi = $Proxy->where("uid = {$v3['uid']} and path like '%{$path1}%'")->count();//如果送礼的人和当前代理有关系
if(!$iszi){
$solt3 += $v3['totalcoin'];
}
}
}elseif($v1['tg_type'] == 4){//主播
$map3['touid'] = $v1['id'];
$expends1 = $coin->where("type='expend' and action='sendgift' and uid not in (".implode(",", $fuchi).")")->where($map3)->select();//主播收的礼物
//$v1['test2'] = $coin->getLastSql();
$touid = str_pad($v1['id'],8,"0",STR_PAD_LEFT);//收礼的人
foreach ($expends1 as $k3 => $v3) {
//$uid = str_pad($v3['uid'],8,"0",STR_PAD_LEFT);//送礼的人
$iszi = $Proxy->where("uid = {$v3['uid']} and path like '%{$touid}%'")->count();
if(!$iszi){
$solt3 += $v3['totalcoin'];
}
}
}
$v1['solt3'] = $solt3;
//业务员没有
$users[$k1]=$v1;
}
}
$xlsName = "Excel";
$action="导出数据查询记录:".$User->getLastSql();
setAdminLog($action);
$cellName = array('A','B','C','D','E','F','G','H','I','J', 'K', 'L', 'M');
$xlsCell = array(
array('id','序号'),
array('rbac','角色'),
array('user_login','账号'),
array('user_nicename','昵称'),
array('mobile','手机'),
array('total_reg','注册人数'),
array('total_charge','充值金额'),
array('total_charge_num','充值人数'),
array('guardcoin','守护金额(钻石)'),
array('mallcoin','商城消费(钻石)'),
array('solt1','自客自销(钻石)'),
array('solt3','他客自销(钻石)'),
array('solt2','自客他销(钻石)'),
);
exportExcel($xlsName,$xlsCell,$users,$cellName);
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment