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.

562 lines
28 KiB
PHP

<?php
namespace Commerce\Controller;
use Think\Controller;
class BuydetailController extends MainController{
public function index(){
$this->display();
}
public function summary($p=1){
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据arraypage
$arraypage = $page ? $page : 1; //默认显示第一页数据
$size = 10;
$uid = $_SESSION['user_auth_commerce']['uid'];
//查询条件
if(isset($_REQUEST['game_id'])){
$game_id = M('game','tab_')->field('id')->where(array('relation_game_id'=>$_REQUEST['game_id']))->select();
$game_id = array_map('array_shift',$game_id);
$gmap['game_id'] =$smap['game_id']= $g_map['id'] =$umap['fgame_id']= array('in',$game_id);
//unset($_REQUEST['game_id']);
}
if(isset($_REQUEST['promote_id']) && isset($_REQUEST['promote_account'])){
if($_REQUEST['promote_id'] != $_REQUEST['promote_account']){
$this->error('渠道ID与渠道账号不匹配');
}else{
$map['id'] = $_REQUEST['promote_id'];
}
unset($_REQUEST['promote_id']);
unset($_REQUEST['promote_account']);
}elseif(isset($_REQUEST['promote_id'])){
$map['id'] = $_REQUEST['promote_id'];
unset($_REQUEST['promote_id']);
}elseif(isset($_REQUEST['promote_account'])){
$map['id'] = $_REQUEST['promote_account'];
unset($_REQUEST['promote_account']);
}
if(isset($_REQUEST['server_name'])){
$smap['server_name'] = $dmap['server_name'] = $_REQUEST['server_name'];
unset($_REQUEST['server_name']);
}
if(isset($_REQUEST['game_level'])&&!empty($_REQUEST['game_level'])){
$gamedata = M('game','tab_')->field('first_level,first_level_name,second_level_name,second_level,third_level,third_level_name')->where(array('relation_game_id'=>$_REQUEST['game_id']))->find();
if($gamedata['first_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['first_level']);
}elseif($gamedata['second_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['second_level']);
}elseif($gamedata['third_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['third_level']);
}
unset($_REQUEST['game_level']);
}
if(isset($_REQUEST['begtime']) && isset($_REQUEST['endtime'])&&!empty($_REQUEST['begtime'])&&!empty($_REQUEST['endtime'])) {
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time'] = array('BETWEEN',[strtotime($_REQUEST['begtime']),strtotime($_REQUEST['endtime'])+86400]);
unset($_REQUEST['begtime']);
unset($_REQUEST['endtime']);
}elseif(isset($_REQUEST['begtime'])&&!empty($_REQUEST['begtime'])){
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time']= array('BETWEEN',[strtotime($_REQUEST['begtime']),time()]);
unset($_REQUEST['begtime']);
}elseif(isset($_REQUEST['endtime'])&&!empty($_REQUEST['endtime'])){
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time'] = array('ELT',strtotime($_REQUEST['endtime'])+86400);
unset($_REQUEST['endtime']);
}
$data = M('promote','tab_')
->field('id,account')
->where($map)
->where(array('ba_id'=>$uid,'parent_id'=>0,'status'=>1))
->order('id')
->page($page,$size)
->select();
$count = M('promote','tab_')
->field('id')
->where($map)
->where(array('ba_id'=>$uid,'parent_id'=>0,'status'=>1))
->count();
//分页
$this->assign("count",$count);
if($count > $size){
$page = new \Think\Page($count, $size);
$page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');
$this->assign('_page', $page->show());
}
//渠道循环查询
foreach ($data as $key => $value) {
//子渠道
$condition['parent_id'] = $data[$key]['id'];
$condition['grand_id'] = $data[$key]['id'];
$condition['_logic'] = 'OR';
$data[$key]['pid'] = M('promote','tab_')
->field('id')
->where($condition)
->select();
$data[$key]['pid'] = array_map('array_shift',$data[$key]['pid']);
array_push($data[$key]['pid'], $data[$key]['id']);
//注册用户
$data[$key]['register_user'] = M('user','tab_')
->field('id')
->where($umap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'puid'=>0))
->count();
//新增用户
$data[$key]['new_user'] = M('user','tab_')
->field('id')
->where($umap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'puid'=>0))
->group('register_ip')
->select();
$data[$key]['new_user'] = count($data[$key]['new_user']);
//注册ip数
$data[$key]['register_ip'] = M('user','tab_')
->field('register_ip')
->where($umap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'puid'=>0))
->group('register_ip')
->select();
$data[$key]['register_ip'] = count($data[$key]['register_ip']);
//达标用户
$game = M('apply','tab_')
->field('game_id')
->where($gmap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'status'=>1))
->group('game_id')
->select();
$game_count = count($game);
$dabiao_user = 0;
$dabiao_game = 0;
for($x=0;$x<$game_count;$x++){
$game_level = M('game','tab_')->field('first_level,id')->where(array('id'=>$game[$x]['game_id']))->find();
if($dmap['role_level']){
$game_level['first_level'] = $dmap['role_level'][1];
}
$dabiao = M('user_play_info','tab_')
->field('user_id')
->where($dmap)
->where(array('game_id'=>$game[$x]['game_id'],'role_level'=>array('egt',$game_level['first_level']),'promote_id'=>array('in',$data[$key]['pid']),'pipuid'=>0))
->group('user_id')
->select();
$dabiao=count($dabiao);
if($dabiao>0) {
$dabiao_game++;
}
$dabiao_user += $dabiao;
}
$data[$key]['dabiao_user'] = $dabiao_user;
$data[$key]['dabiao_game'] = $dabiao_game;
//达标游戏
/* $dabiao_game = 0;
for($y=0;$y<=$game_count;$y++){
$game_level = M('game','tab_')->field('first_level,id')->where(array('id'=>$game[$y]['game_id']))->find();
if($dmap['role_level']){
$game_level['first_level'] = $dmap['role_level'][1];
}
$gdabiao = M('user_play_info','tab_')
->field('user_id')
->where($dmap)
->where(array('game_id'=>$game[$y]['game_id'],'role_level'=>array('egt',$game_level['first_level']),'promote_id'=>array('in',$data[$key]['pid'])))
->group('user_id')
->select();
$gdabiao = count($gdabiao);
$dabiao_game += $gdabiao;
}
$data[$key]['dabiao_game'] = $dabiao_game; */
//移动端充值
$data[$key]['spend'] = M('spend','tab_')
->field('user_id')
->where($smap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'pay_status'=>1))
->group('user_id')
->select();
$data[$key]['spend'] = count($data[$key]['spend']);
//安卓端充值
$data[$key]['and_spend'] = M('spend','tab_')
->field('sum(pay_amount) as amount ')
->where($smap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'pay_status'=>1,'sdk_version'=>1))
->select();
$data[$key]['and_spend'] = array_map('array_shift',$data[$key]['and_spend'])[0];
//苹果端充值
$data[$key]['ios_spend'] = M('spend','tab_')
->field('sum(pay_amount) as amount ')
->where($smap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'pay_status'=>1,'sdk_version'=>2))
->select();
$data[$key]['ios_spend'] = array_map('array_shift',$data[$key]['ios_spend'])[0];
}
//汇总
foreach ($data as $key1 => $value2) {
$all_data['new_user']+=$data[$key1]['new_user'];
$all_data['all_new_user']+=$data[$key1]['new_user'];
$all_data['register_user']+=$data[$key1]['register_user'];
$all_data['register_ip']+=$data[$key1]['register_ip'];
$all_data['dabiao_user']+=$data[$key1]['dabiao_user'];
$all_data['dabiao_game']+=$data[$key1]['dabiao_game'];
$all_data['spend']+=$data[$key1]['spend'];
$all_data['and_spend']+=$data[$key1]['and_spend'];
$all_data['ios_spend']+=$data[$key1]['ios_spend'];
}
$this->assign('all_data',$all_data);
$this->assign("list_data",$data);
$this->map_game_list();
$this->assign("uid",$uid);
$this->assign('setdate',date("Y-m-d",strtotime("-1 day")));
$this->display();
}
public function exportSummary($p=1){
$xlsName = "数据汇总";
$xlsCell = array(
array('id', '推广员ID'),
array('account', '一级推广员帐号'),
array('register_user', '注册用户'),
array('register_ip', '注册IP数'),
array('dabiao_user', '达标用户'),
array('dabiao_game', '达标游戏'),
array('spend', '移动端充值人数'),
array('and_spend', '安卓充值'),
array('ios_spend', '苹果充值'),
);
$page = intval($p);
$page = $page ? $page : 1; //默认显示第一页数据arraypage
$arraypage = $page ? $page : 1; //默认显示第一页数据
$size = 20;
$uid = $_SESSION['user_auth_commerce']['uid'];
//查询条件
if(isset($_REQUEST['game_id'])){
$game_id = M('game','tab_')->field('id')->where(array('relation_game_id'=>$_REQUEST['game_id']))->select();
$game_id = array_map('array_shift',$game_id);
$smap['game_id'] = $gmap['game_id'] = $g_map['id'] = $umap['fgame_id'] = array('in',$game_id);
// unset($_REQUEST['game_id']);
}
if(isset($_REQUEST['promote_id']) && isset($_REQUEST['promote_account'])){
if($_REQUEST['promote_id'] != $_REQUEST['promote_account']){
$this->error('渠道ID与渠道账号不匹配');
}else{
$map['id'] = $_REQUEST['promote_id'];
}
unset($_REQUEST['promote_id']);
unset($_REQUEST['promote_account']);
}elseif(isset($_REQUEST['promote_id'])){
$map['id'] = $_REQUEST['promote_id'];
unset($_REQUEST['promote_id']);
}elseif(isset($_REQUEST['promote_account'])){
$map['id'] = $_REQUEST['promote_account'];
unset($_REQUEST['promote_account']);
}
if(isset($_REQUEST['server_name'])){
$smap['server_name'] = $dmap['server_name'] = $_REQUEST['server_name'];
unset($_REQUEST['server_name']);
}
if(isset($_REQUEST['game_level'])&&!empty($_REQUEST['game_level'])){
$gamedata = M('game','tab_')->field('first_level,first_level_name,second_level_name,second_level,third_level,third_level_name')->where(array('relation_game_id'=>$_REQUEST['game_id']))->find();
if($gamedata['first_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['first_level']);
}elseif($gamedata['second_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['second_level']);
}elseif($gamedata['third_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['third_level']);
}
unset($_REQUEST['game_level']);
}
if(isset($_REQUEST['begtime']) && isset($_REQUEST['endtime'])&&!empty($_REQUEST['begtime'])&&!empty($_REQUEST['endtime'])) {
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time'] = array('BETWEEN',[strtotime($_REQUEST['begtime']),strtotime($_REQUEST['endtime'])+86400]);
unset($_REQUEST['begtime']);
unset($_REQUEST['endtime']);
}elseif(isset($_REQUEST['begtime'])&&!empty($_REQUEST['begtime'])){
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time']= array('BETWEEN',[strtotime($_REQUEST['begtime']),time()]);
unset($_REQUEST['begtime']);
}elseif(isset($_REQUEST['endtime'])&&!empty($_REQUEST['endtime'])){
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time'] = array('ELT',strtotime($_REQUEST['endtime'])+86400);
unset($_REQUEST['endtime']);
}
$data = M('promote','tab_')
->field('id,account')
->where($map)
->where(array('ba_id'=>$uid,'parent_id'=>0,'status'=>1))
->order('id')
->page($page,$size)
->select();
//渠道循环查询
foreach ($data as $key => $value) {
//子渠道
$condition['parent_id'] = $data[$key]['id'];
$condition['grand_id'] = $data[$key]['id'];
$condition['_logic'] = 'OR';
$data[$key]['pid'] = M('promote','tab_')
->field('id')
->where($condition)
->select();
$data[$key]['pid'] = array_map('array_shift',$data[$key]['pid']);
array_push($data[$key]['pid'], $data[$key]['id']);
//注册用户
$data[$key]['register_user'] = M('user','tab_')
->field('id')
->where($umap)
->where(array('promote_id'=>array('in',$data[$key]['pid'])))
->count();
//新增用户
$data[$key]['new_user'] = M('user','tab_')
->field('id')
->where($umap)
->where(array('promote_id'=>array('in',$data[$key]['pid'])))
->group('register_ip')
->select();
$data[$key]['new_user'] = count($data[$key]['new_user']);
//注册ip数
$data[$key]['register_ip'] = M('user','tab_')
->field('register_ip')
->where($umap)
->where(array('promote_id'=>array('in',$data[$key]['pid'])))
->group('register_ip')
->select();
$data[$key]['register_ip'] = count($data[$key]['register_ip']);
//达标用户
$game = M('apply','tab_')
->field('game_id')
->where($gmap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'status'=>1))
->group('game_id')
->select();
$game_count = count($game);
$dabiao_user = 0;
for($x=0;$x<=$game_count;$x++){
$game_level = M('game','tab_')->field('first_level')->where(array('id'=>$game[$x]['game_id']))->find();
if($dmap['role_level']){
$game_level['first_level'] = $dmap['role_level'][1];
}
$dabiao = M('user_play_info','tab_')
->field('user_id')
->where($dmap)
->where(array('game_id'=>$game[$x]['game_id'],'role_level'=>array('egt',$game_level['first_level']),'promote_id'=>array('in',$data[$key]['pid'])))
->group('user_id')
->select();
$dabiao=count($dabiao);
$dabiao_user += $dabiao;
}
$data[$key]['dabiao_user'] = $dabiao_user;
//达标游戏
$dabiao_game = 0;
for($y=0;$y<=$game_count;$y++){
$game_level = M('game','tab_')->field('first_level')->where(array('id'=>$game[$y]['game_id']))->find();
if($dmap['role_level']){
$game_level['first_level'] = $dmap['role_level'][1];
}
$gdabiao = M('user_play_info','tab_')
->field('game_id')
->where($dmap)
->where(array('game_id'=>$game[$y]['game_id'],'role_level'=>array('egt',$game_level['first_level']),'promote_id'=>array('in',$data[$key]['pid'])))
->group('game_id')
->select();
$gdabiao = count($gdabiao);
$dabiao_game += $gdabiao;
}
$data[$key]['dabiao_game'] = $dabiao_game;
//移动端充值
$data[$key]['spend'] = M('spend','tab_')
->field('user_id')
->where($smap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'pay_status'=>1))
->group('user_id')
->select();
$data[$key]['spend'] = count($data[$key]['spend']);
//安卓端充值
$data[$key]['and_spend'] = M('spend','tab_')
->field('sum(pay_amount) as amount ')
->where($smap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'pay_status'=>1,'sdk_version'=>1))
->select();
$data[$key]['and_spend'] = array_map('array_shift',$data[$key]['and_spend'])[0];
//苹果端充值
$data[$key]['ios_spend'] = M('spend','tab_')
->field('sum(pay_amount) as amount ')
->where($smap)
->where(array('promote_id'=>array('in',$data[$key]['pid']),'pay_status'=>1,'sdk_version'=>2))
->select();
$data[$key]['ios_spend'] = array_map('array_shift',$data[$key]['ios_spend'])[0];
}
$xlsData = $data;
foreach ($xlsData as $key1 => $value1) {
$xlsData[$key]['register_user'] = IsNull($value1['register_user']);
$xlsData[$key1]['register_ip'] = IsNull($value1['register_ip']);
$xlsData[$key1]['dabiao_user'] = IsNull($value1['dabiao_user']);
$xlsData[$key1]['dabiao_game'] = IsNull($value1['dabiao_game']);
$xlsData[$key1]['spend'] = IsNull($value1['spend']);
$xlsData[$key1]['and_spend'] = null_to_0($value1['and_spend']);
$xlsData[$key1]['ios_spend'] = null_to_0($value1['ios_spend']);
}
$this->exportExcel($xlsName,$xlsCell,$xlsData);
}
//判断是否登录
public function check_login(){
if(empty($_SESSION['user_auth_commerce']['uid'])){
$this->redirect('Index/index');
}
$uid = M('Commissioner','tab_')->where(array('id'=>$_SESSION['user_auth_commerce']['uid']))->find();
if(empty($uid)){
$this->redirect('Index/index');
}
}
private function map_game_list(){
$uid = $_SESSION['user_auth_commerce']['uid'];
$map['tab_game.game_status'] = 1;
$map['tab_apply.status'] = 1;
$data = M('game','tab_')
->field('relation_game_name,relation_game_id')
->join('tab_apply on tab_apply.game_id = tab_game.id')
->join('tab_promote ON tab_apply.promote_id = tab_promote.id AND tab_promote.ba_id = '.$uid)
->where($map)
->group('relation_game_id')
->select();
$this->assign("game_list",$data);
}
public function getServer(){
$uid = session('promote_auth.pid');
$promote = $this->get_child_promote();
array_push($promote, $uid);
if(IS_POST){
if(isset($_POST['game_id'])&&!empty($_POST['game_id'])){
$game = M('game','tab_')->field('id')->where(array('relation_game_id'=>$_POST['game_id']))->select();
$map['game_id'] = array('in',array_map('array_shift', $game));
$map['promote_id'] = array('in',$promote);
$map['server_name'] = array('neq','');
$data1 = M('spend','tab_')
->field('server_name')
->where(array('pay_status'=>1))
->where($map)
->group('server_name')
->select();
$data2 = M('user_play_info','tab_')
->field('server_name')
->where($map)
->group('server_name')
->select();
$data3 = M('game','tab_')
->field('first_level_name,second_level_name,third_level_name')
->where(array('relation_game_id'=>$_POST['game_id']))
->find();
$data['server_name'] = array_unique(array_merge(array_map('array_shift', $data1),array_map('array_shift', $data2)));
$data['game_level'] =$data3;
echo json_encode(array('data'=>$data));
}else{
echo json_encode(array('data'=>''));
}
}
}
public function get_promote_account($id=0){
$data = M('promote','tab_')->field('account')->find($id);
return $data['account'];
}
public function get_game_name($id){
$data = M('game','tab_')->field('game_name')->find($id);
return $data['game_name'];
}
public function get_child_promote(){
$map['ba_id'] = $_SESSION['user_auth_commerce']['uid'];
$map['status'] = 1;
$data = M('promote','tab_')
->field('id')
->where($map)
->select();
return array_map('array_shift', $data);
}
public function dabiao_game(){
if(isset($_REQUEST['game_id'])){
$game_id = M('game','tab_')->field('id')->where(array('relation_game_id'=>$_REQUEST['game_id']))->select();
$game_id = array_map('array_shift',$game_id);
$gmap['game_id'] = array('in',$game_id);
// unset($_REQUEST['game_id']);
}
if(isset($_REQUEST['server_name'])){
$dmap['server_name'] = $_REQUEST['server_name'];
unset($_REQUEST['server_name']);
}
if(isset($_REQUEST['game_level'])&&!empty($_REQUEST['game_level'])){
$gamedata = M('game','tab_')->field('first_level,first_level_name,second_level_name,second_level,third_level,third_level_name')->where(array('relation_game_id'=>$_REQUEST['game_id']))->find();
if($gamedata['first_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['first_level']);
}elseif($gamedata['second_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['second_level']);
}elseif($gamedata['third_level_name']==$_REQUEST['game_level']){
$dmap['role_level'] = array('egt',$gamedata['third_level']);
}
unset($_REQUEST['game_level']);
}
if(isset($_REQUEST['begtime']) && isset($_REQUEST['endtime'])&&!empty($_REQUEST['begtime'])&&!empty($_REQUEST['endtime'])) {
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time'] = array('BETWEEN',[strtotime($_REQUEST['begtime']),strtotime($_REQUEST['endtime'])+86400]);
unset($_REQUEST['begtime']);
unset($_REQUEST['endtime']);
}elseif(isset($_REQUEST['begtime'])&&!empty($_REQUEST['begtime'])){
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time']= array('BETWEEN',[strtotime($_REQUEST['begtime']),time()]);
unset($_REQUEST['begtime']);
}elseif(isset($_REQUEST['endtime'])&&!empty($_REQUEST['endtime'])){
$smap['pay_time'] = $umap['register_time'] = $dmap['play_time'] = array('ELT',strtotime($_REQUEST['endtime'])+86400);
unset($_REQUEST['endtime']);
}
$maps['id'] = $_REQUEST['promote_id'];
$maps['parent_id'] = $_REQUEST['promote_id'];
$maps['grand_id'] = $_REQUEST['promote_id'];
$maps['_logic'] = "or";
$promote = M('promote','tab_')
->field('id')
->where($maps)
->select();
$promote = array_map('array_shift',$promote);
array_push($promote,$_REQUEST['promote_id']);
$game = M('apply','tab_')
->field('game_id,game_name')
->where($gmap)
->where(array('promote_id'=>array('in',$promote),'status'=>1))
->group('game_id')
->select();
$game_count = count($game);
for($y=0;$y<=$game_count;$y++){
$game_level = M('game','tab_')->field('first_level')->where(array('id'=>$game[$y]['game_id']))->find();
if($dmap['role_level']){
$game_level['first_level'] = $dmap['role_level'][1];
}
$gdabiao = M('user_play_info','tab_')
->field('user_id')
->where($dmap)
->where(array('game_id'=>$game[$y]['game_id'],'role_level'=>array('egt',$game_level['first_level']),'promote_id'=>array('in',$promote),'pipuid'=>0))
->group('user_id')
->select();
$gdabiao = count($gdabiao);
$game[$y]['num'] = $gdabiao;
if($game[$y]['num']==0){
unset($game[$y]);
}
}
$this->assign('list_data',$game);
$this->display();
}
}