field("count_date,cash_count,balance_coin_count,inside_cash_count,all_cash_count") // ->where($map) // ->page($page,$row) // ->group("count_date") // ->select(); if (empty(I('game_id'))) { $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count, sum(inside_cash_count) as inside_cash_count,sum(cash_count+balance_coin_count) as all_cash_count"; $InsideField = "inside_cash_count"; $map['inside_cash_count'] = ['neq',0]; $insideData = D("spend_count")->getSpendCountData($map,"count_date,inside_cash_count as count","promote_id,count_date"); unset($map['inside_cash_count']); } else { $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count, sum(bind_coin_count) as inside_cash_count,sum(cash_count+balance_coin_count) as all_cash_count"; $InsideField = "bind_coin_count"; $map['bind_coin_count'] = ['neq',0]; $insideData = D("spend_count")->getSpendCountData($map,"count_date,bind_coin_count as count","promote_id,count_date,game_id"); unset($map['bind_coin_count']); } //内充流水与绑定流水数据 $insideDataSum = []; foreach ($insideData as $key => $value) { if (isset($insideDataSum[$value['count_date']])) { $insideDataSum[$value['count_date']] = $insideDataSum[$value['count_date']] + $value['count']; } else { $insideDataSum[$value['count_date']] = $value['count']; } } // var_dump($insideDataSum); // var_dump(array_sum($insideDataSum)); // echo D("spend_count")->_sql(); // var_dump($insideData);die(); $group = "count_date"; $order = "id DESC"; $data = D("spend_count")->getSpendCountData($map,$field,$group,$order,$page,$row); foreach ($data as $key => $value) { $data[$key]['all_cash_count'] = $value['all_cash_count'] + $insideDataSum[$value['count_date']]; $data[$key]['inside_cash_count'] = $insideDataSum[$value['count_date']]; } $sumCash = D("spend_count")->sumSpendCountField($map,"cash_count"); $sumBalance = D("spend_count")->sumSpendCountField($map,"balance_coin_count"); $sumInside = array_sum($insideDataSum); $allField = "cash_count+balance_coin_count"; $sumAll = D("spend_count")->sumSpendCountField($map,$allField)+array_sum($insideDataSum); $count = D("spend_count")->getSpendCountData($map,$field,$group,$order); $count = count($count); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $this->assign('sumCash',$sumCash); $this->assign('sumBalance',$sumBalance); $this->assign('sumInside',$sumInside); $this->assign('sumAll',$sumAll); $this->assign('data',$data); $this->display(); } function gameFinance($p = 1) { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $row=10; if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} $map = []; if(!empty(I('count_date'))){ $map['count_date']=I('count_date'); } if(!empty(I('root_id'))||!I('sign')) { $root_id = I('root_id'); if ($root_id == 0) { // $map['_string'] = "promote_id = {$root_id}"; } else { $map['_string'] = "promote_id = {$root_id} or parent_id = {$root_id} or root_id = {$root_id}"; } } if(!empty(I('parent_id'))) { $parent_id = I('parent_id'); $map['_string'] = "promote_id = {$parent_id} or parent_id = {$parent_id}"; } if (!empty(I('promote_id'))) { $promote_id = I('promote_id'); $map['_string'] = "promote_id = {$promote_id}"; } // var_dump($map);die(); $map['bind_coin_count'] = ['neq',0]; $insideData = D("spend_count")->getSpendCountData($map,"game_id,bind_coin_count as count","promote_id,count_date,game_id"); unset($map['bind_coin_count']); //内充流水与绑定流水数据 $insideDataSum = []; foreach ($insideData as $key => $value) { if (isset($insideDataSum[$value['game_id']])) { $insideDataSum[$value['game_id']] = $insideDataSum[$value['game_id']] + $value['count']; } else { $insideDataSum[$value['game_id']] = $value['count']; } } $field = "count_date,sum(cash_count) as cash_count,sum(balance_coin_count) as balance_coin_count, sum(bind_coin_count) as inside_cash_count,sum(cash_count+balance_coin_count+bind_coin_count) as all_cash_count,game_name,game_id,partner_name"; $group = "game_id"; $order = "id DESC"; $data = D("spend_count")->getSpendCountData($map,$field,$group,$order,$page,$row); // echo D("spend_count")->_sql();die(); foreach ($data as $key => $value) { $data[$key]['inside_cash_count'] = $insideDataSum[$value['game_id']]; } $sumCash = D("spend_count")->sumSpendCountField($map,"cash_count"); $sumBalance = D("spend_count")->sumSpendCountField($map,"balance_coin_count"); $sumInside = D("spend_count")->sumSpendCountField($map,"bind_coin_count"); $sumAll = D("spend_count")->sumSpendCountField($map,"cash_count+balance_coin_count+bind_coin_count"); $count = D("spend_count")->getSpendCountData($map,$field,$group,$order); $count = count($count); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $this->assign('sumCash',$sumCash); $this->assign('sumBalance',$sumBalance); $this->assign('sumInside',$sumInside); $this->assign('sumAll',$sumAll); $this->assign('data',$data); $this->display(); } function gameFinanceDetail($p = 1) { if (!empty(I("promote_id"))) { $promote_id = I("promote_id"); } if (!empty(I("root_id"))) { $root_id = I("root_id"); $promote_id = $this->getPromoteList($root_id); array_push($promote_id,$root_id); } else if (I("root_id")==0) { $promote_id = 0; } if (!empty(I("parent_id"))) { $parent_id = I("parent_id"); $promote_id = $this->getPromoteList($parent_id); array_push($promote_id,$parent_id); } dump($promote_id);die(); $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $row=10; if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} if (!empty(I("count_date"))) { $month = I("count_date"); } else { $this->error('月份不能为空'); } $tarry = explode('-',$month); $startTime=mktime(0,0,0,$tarry[1],1,$tarry[0]); $endTime =mktime(0,0,0,$tarry[1]-0+1,1,$tarry[0])-1; $map['pay_time'] = array('between',array($startTime,$endTime)); $map['pay_status'] = 1; if (!empty(I("game_id"))) { $map['game_id'] = I("game_id"); } if (!empty(I('user_account'))) { $map['user_account'] = array('like','%'.I("user_account").'%'); } if (!empty(I('user_nickname'))) { $map['user_nickname'] = array('like',I("user_nickname").'%'); } $field = "pay_order_number,FROM_UNIXTIME(pay_time) as pay_time,user_account,game_name,promote_account,spend_ip,server_name,game_player_name,pay_amount,cost,pay_way"; $group = ""; $order = "pay_time DESC"; $data = D('spend')->getSpendData($map,$field,$group,$order,$page,$row); foreach($data as $key => $value) { $data[$key]['pay_way'] = getPayType($value['pay_way']); } $sum = D('spend')->sumSpend($map,'pay_amount'); $count = D("spend")->getSpendData($map,$field,$group,$order); $count = count($count); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $this->assign('data',$data); $this->assign('sum_amount',$sum); $this->display(); } //按月份获取会长统计 public function getRootUser($p = 1) { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $row=10; if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} //获取所有数据 if (!empty(I("count_date"))) { $map['count_date'] = I("count_date"); } else { $this->error('月份不能为空'); } if (!empty(I("root_name"))) { $map['promote_account']=['like','%'.I("root_name").'%']; } $map['parent_id'] = 0; $map['root_id'] = 0; $subQueryAll = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->group('promote_id') ->page($page,$row) ->select(); $sumData = M('spend_user_count','tab_') ->field('sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->find(); $count = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->group('promote_id') ->select(); $count = count($count); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $this->assign('sumData',$sumData); $this->assign('data',$subQueryAll); $this->display(); } public function getParentUser($p = 1) { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $row=10; if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} if (!empty(I("count_date")) ) { $month = I("count_date"); $map['count_date'] =$month; } else { $this->error('参数错误'); } if (!empty(I("root_id"))) { $root_id = I("root_id"); $map['parent_id'] =$root_id; } else if(!empty(I("sign"))){ $map['parent_id'] = ['neq',0]; $map['root_id'] = ['eq',0]; } else { if (I("root_id") == 0) { $this->display(); } } if (!empty(I("root_name"))) { $rootname = I("root_name"); $map['promote_account'] =['like','%'.$rootname.'%']; } $subQueryAll = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->group('promote_id') ->page($page,$row) ->select(); $sumData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->find(); $count = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->group('promote_id') ->select(); $count = count($count); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $this->assign('sumData',$sumData); $this->assign('data',$subQueryAll); $this->display(); } public function getPromoteUser($p = 1) { $page = intval($p); $page = $page ? $page : 1; //默认显示第一页数据 $row=10; if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} if (!empty(I("count_date"))) { $month = I("count_date"); $map['count_date'] =$month; } else { $this->error('参数错误'); } if (!empty(I("parent_id"))) { $parent_id = I("parent_id"); $map['parent_id'] =$parent_id; } if (!empty(I('sign'))) { $map['parent_id'] = ['neq',0]; $map['root_id'] = I("root_id"); } $subQueryAll = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->group('promote_id') ->page($page,$row) ->select(); $sumData = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->find(); $count = M('spend_user_count','tab_') ->field('promote_id,promote_account,sum(cash_count) cash_count,sum(balance_coin_count) balance_coin_count,sum(inside_cash_count) inside_cash_count, sum(all_count) as all_count') ->where($map) ->group('promote_id') ->select(); $count = count($count); $page = set_pagination($count,$row); if($page) {$this->assign('_page', $page);} $sum = array_sum($sumData); $this->assign('sumData',$sumData); $this->assign('data',$subQueryAll); $this->display(); # code... } function getPromoteList($root_id = 0) { $data = M('promote','tab_') ->field("id") ->where("parent_id={$root_id} or grand_id={$root_id}") ->select(); $handleData = []; foreach ($data as $key => $value) { array_push($handleData,$data[$key]['id']); } return $handleData; } }