0, 'sum' => 0]; $promoteRoot = getPowerPromoteIds(); if ($promoteRoot) { $rmap['tab_user.promote_id'] = $map['promote_id'] = array('in',$promoteRoot); } if (isset($_REQUEST['promote_id'])) { if ($_REQUEST['promote_id'] > 0) { $promoter_ids = D("Promote")->where("chain like '%/{$_REQUEST['promote_id']}/%' or id={$_REQUEST['promote_id']}")->field('id')->select(); $promoter_ids ? $rmap['tab_user.promote_id'] = $map['promote_id'] = ['in', implode(',', array_column($promoter_ids, 'id'))] : null; } else { $rmap['tab_user.promote_id'] = $map['promote_id'] = 0; } } $data = []; if (intval(($endTime + (24 * 3600)) - $startTime) / (24 * 3600) <= 31) { for ($start = $endTime; $start >= $startTime; $start -= 86400) { $startDate = $start; $endDate = $startDate + 24 * 60 * 60 - 1; $rmap['register_time'] = $map['register_time'] = array('BETWEEN', array($startDate, $endDate)); $map['play_time'] = array('BETWEEN', array($startDate, $endDate)); $map['pay_time'] = array('BETWEEN', array($startDate, $endDate)); if (!empty($_REQUEST['game_type'])) { $map['sdk_version'] = $_REQUEST['game_type']; $rmap['sdk_version'] = $_REQUEST['game_type']; } if (!empty($_REQUEST['game_name'])) { $rmap['game_id'] = $map['game_id'] = ['in', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')]; } if (!empty($_REQUEST['server_id'])) { $rmap['tab_user_play.server_id'] = $map['server_id'] = $_REQUEST['server_id']; } if ($_REQUEST['bindcoin'] == 1) { $map['pay_way'] = array('egt', 0); } //当天注册人数 $registerNum = D('User')->where(array_merge($rmap, array('puid' => 0)))->join("tab_user_play on tab_user.id = tab_user_play.user_id and tab_user.fgame_id = tab_user_play.game_id", 'left')->field("tab_user.id")->select(); $registerNum = $registerNum ? array_column($registerNum, 'id') : []; //当天活跃人数 $livenNum = D('UserPlay')->where($map)->count("id"); //当天新增付费 if (empty($registerNum)) { $map['user_id'] = array('IN', '0'); } else { $map['user_id'] = array('IN', $registerNum); } $map['pay_status'] = 1; $newAddPay = D('Spend')->where(array_merge($map, array('_string' => '( small_id = 0 or small_id = user_id)')))->sum('pay_amount'); //当天累计付费 unset($map['user_id']); $accumulated = D('Spend')->where($map)->sum('pay_amount'); $data[$key]['date'] = date('Y-m-d', $start); $data[$key]['game_id'] = empty($_REQUEST['game_id']) ? "全部" : get_game_name($_REQUEST['game_id']); switch ($_REQUEST['promote_id']) { case 'GUANFANG': $data[$key]['promote_id'] = "官方渠道"; break; case '0': $data[$key]['promote_id'] = "官方渠道"; break; case 'PROMOTE': $data[$key]['promote_id'] = "推广渠道"; break; case 'ALL': $data[$key]['promote_id'] = "全部"; break; default: $data[$key]['promote_id'] = empty($_REQUEST['promote_id']) ? "全部" : get_promote_account($_REQUEST['promote_id']); break; } $data[$key]['registerNum'] = count($registerNum); $data[$key]['livenNum'] = $livenNum; $data[$key]['newAddPay'] = empty($newAddPay) ? 0 : $newAddPay; $data[$key]['accumulated'] = empty($accumulated) ? 0 : $accumulated; $total['sum'] += $data[$key]['accumulated']; $key++; } } if (isset($_REQUEST['row'])) { $row = $_REQUEST['row']; } else { $row = 10; } $count = count($data); $export_data = $data; $page = set_pagination($count, $row); if ($page) { $this->assign('_page', $page); } $pnum = ceil(count($data) / $row); //总页数,ceil()函数用于求大于数字的最小整数 //用array_slice(array,offset,length) 函数在数组中根据条件取出一段值;array(数组),offset(元素的开始位置),length(组的长度) $data = array_slice($data, ($p - 1) * $row, $row); foreach ($data as $k => $v) { $total['current'] += $v['accumulated']; } //判断是否执行导出 if (I('export') == 1) { $this->exportSum($export_data); } $this->assign('meta_title', "充值汇总"); $this->assign('list_data', $data); $this->assign('total', $total); $this->assign('startDate', $startDateTime); $this->assign('endDate', $endDateTime); $this->m_title = '充值汇总'; $this->assign('commonset', M('Kuaijieicon')->where(['url' => 'RechargeSum/summation', 'status' => 1])->find()); $this->display(); } public function exportSum($data) { $export = A('Export'); $exptitle = $_REQUEST['xlsname']; $expCellName = array( array('date', '日期'), array('promote_id', '渠道来源'), array('game_id', '游戏名称'), array('registerNum', '新增人数'), array('livenNum', '活跃人数'), array('newAddPay', "新增玩家付费"), array('accumulated', '本日累计'), ); $expTableData = $data; $export->exportExcel($exptitle, $expCellName, $expTableData); } }