| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906 |
- <?php
- /**
- * 充值记录管理控制器
- *
- */
- namespace app\admin\controller;
- use app\common\library\MakeReportGo;
- use think\Db;
- use app\common\library\MakeReport;
- use GuzzleHttp\Client;
- use GuzzleHttp\Exception\GuzzleException;
- use think\Model;
- class Retaine extends Admin
- {
- public function retaineGame()
- {
- $tmpGameList = model('Common/Game')->getAllByCondition('name,id', ['cooperation_status' => 1], "id desc", "all");
- $gameList = array();
- foreach ($tmpGameList as $game) {
- $gameList[$game['id']] = $game;
- }
- $this->assign('gameArr', $tmpGameList);
- $this->assign('game_list', $gameList);
- list($list, $total) = $this->retaineGameList(request()->param(), 1);
-
- $this->assign('total', $total);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- public function retaineGameChannel()
- {
- $tmpGameList = model('Common/Game')->getAllByCondition('name,id', ['cooperation_status' => 1]);
- $gameList = array();
- foreach ($tmpGameList as $game) {
- $gameList[$game['id']] = $game;
- }
- $level = input('level', 0);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'), $level);
- $channelWhere = [];
- if ($business != -1) {
- if ($business) {
- $channelWhere['id'] = ['in', $business];
- } else {
- $channelWhere['id'] = -1;
- }
- }
- $channel = model('common/Channel')->where(['level' => $level])->where($channelWhere)->field('id,name')->order('id desc')->select();
- $channelC = model('common/Channel')->field('id,name')->order('id desc')->select();
- foreach ($channelC as $v) {
- $channelList[$v['id']] = $v;
- }
- $this->assign('level', $level);
- $this->assign('channel', $channel);
- $this->assign('channelList', $channelList);
- $this->assign('gameArr', $tmpGameList);
- $this->assign('game_list', $gameList);
- list($list, $total) = $this->retaineGameList(request()->param(), 2);
- $this->assign('total', $total);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- public function retaineGameChannelSummary()
- {
- $tmpGameList = model('Common/Game')->getAllByCondition('name,id', ['cooperation_status' => 1]);
- $gameList = array();
- foreach ($tmpGameList as $game) {
- $gameList[$game['id']] = $game;
- }
- $level = input('level', 0);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'), $level);
- $channelWhere = [];
- if ($business != -1) {
- if ($business) {
- $channelWhere['id'] = ['in', $business];
- } else {
- $channelWhere['id'] = -1;
- }
- }
- $channel = model('common/Channel')->where(['level' => $level])->where($channelWhere)->field('id,name')->order('id desc')->select();
- $channelC = model('common/Channel')->field('id,name')->order('id desc')->select();
- foreach ($channelC as $v) {
- $channelList[$v['id']] = $v;
- }
- $this->assign('level', $level);
- $this->assign('channel', $channel);
- $this->assign('channelList', $channelList);
- $this->assign('gameArr', $tmpGameList);
- $this->assign('game_list', $gameList);
- list($list, $total) = $this->retaineGameList(request()->param(), 2, 'summary');
- $this->assign('total', $total);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- private function retaineGameList($data, $type_id, $mode = 'normal')
- {
- $tmpGameList = model('Common/Game')->getAllByCondition('name,id', ['cooperation_status' => 1], "id desc", "all");
- $gameIds = '';
- if($tmpGameList){
- $gameIds = implode(array_column($tmpGameList, 'id'), ',');
- $where['game_id'] = ['in', $gameIds];
- }
- $where['type_id'] = ['=', $type_id];
- if (isset($data['game_id']) && $data['game_id']) {
- $where['game_id'] = ['in', $data['game_id']];
- }
- $dataTime = "";
- // 开始时间和结束时间不为空时
- if (isset($data['start']) && isset($data['end']) && $data['start'] != '' && $data['end'] != '') {
- $where['day'] = [
- ['>=', $data['start']],
- ['<=', $data['end']],
- ];
- } //开始时间不为空时
- elseif (isset($data['start']) && $data['start'] != '') {
- $where['day'] = ['>=', $data['start']];
- } //结束时间不为空时
- elseif (isset($data['end']) && $data['end'] != '') {
- $where['day'] = ['<=', $data['end']];
- }
- // 默认昨天
- if(empty($where['day'])){
- $dataTime = date('Y-m-d', strtotime('-1 day'));
- $where['day'] = [
- ['>=', $dataTime],
- ['<=', $dataTime],
- ];
- }
- $this->assign('start', $dataTime);
- $this->assign('end', $dataTime);
- // 判断是否多日期
- $rangeTimeStatus = "";
- if(!empty($where['day']) && $mode == 'summary'){
- // 从原始数据中获取开始和结束日期
- $startDate = isset($data['start']) && $data['start'] != '' ? $data['start'] : '';
- $endDate = isset($data['end']) && $data['end'] != '' ? $data['end'] : '';
- // 如果前端没有传入日期(采用默认日期范围),则从$where条件中解析
- if(($startDate == '' || $endDate == '') && isset($where['day'])){
- $dayCondition = $where['day'];
- // between 条件:[['>=', start], ['<=', end]]
- if(isset($dayCondition[0]) && is_array($dayCondition[0])){
- if($startDate == '' && isset($dayCondition[0][1])){
- $startDate = $dayCondition[0][1];
- }
- if($endDate == '' && isset($dayCondition[1][1])){
- $endDate = $dayCondition[1][1];
- }
- } else {
- // 单条件:['>=', start] 或 ['<=', end]
- if($startDate == '' && isset($dayCondition[0]) && $dayCondition[0] == '>=' && isset($dayCondition[1])){
- $startDate = $dayCondition[1];
- }
- if($endDate == '' && isset($dayCondition[0]) && $dayCondition[0] == '<=' && isset($dayCondition[1])){
- $endDate = $dayCondition[1];
- }
- }
- }
-
- if($startDate && $endDate){
- // 有开始和结束日期
- $dayDiff = (strtotime($endDate) - strtotime($startDate))/(24*3600);
- if($dayDiff >= 1){
- // 多天:显示日期范围
- $rangeTimeStatus = $startDate.' 至 '.$endDate;
- } else {
- // 单天:显示该日期(开始日期和结束日期相同,或日期差小于1天)
- $rangeTimeStatus = $startDate;
- }
- } elseif($startDate){
- // 只有开始日期,使用开始日期
- $rangeTimeStatus = $startDate;
- } elseif($endDate){
- // 只有结束日期,使用结束日期
- $rangeTimeStatus = $endDate;
- }
- }
- $level = input('level', 0);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'), $level);
- // $type_id = 2, $business = -1, $level = 0
- if ($type_id == 2 && $level != 3) {
- if ($level == 0) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['s_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['s_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['s_channel_id'] = ['in', $business];
- }
- } else {
- $where['s_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['s_channel_id'] = ['in', $data['channel_id']];
- }
- }
- $field = 's_channel_id as channel_id';
- $group = 's_channel_id';
- } else if ($level == 1) {
- // if (isset($data['channel_id']) && $data['channel_id']) {
- // $where['b_channel_id'] = ['in', $data['channel_id']];
- // }
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['b_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['b_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['b_channel_id'] = ['in', $business];
- }
- } else {
- $where['b_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['b_channel_id'] = ['in', $data['channel_id']];
- }
- }
- $field = 'b_channel_id as channel_id';
- $group = 'b_channel_id';
- } else if ($level == 2) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['bz_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['bz_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['bz_channel_id'] = ['in', $business];
- }
- } else {
- $where['bz_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['bz_channel_id'] = ['in', $data['channel_id']];
- }
- }
- if (!(isset($data['channel_id']) && $data['channel_id'])) {
- $where['bz_channel_id'] = ['>', 0];
- }
- $field = 'bz_channel_id as channel_id';
- $group = 'bz_channel_id';
- }
- if (request()->isAjax()) {
- // 根据mode决定group和order
- $groupForExport = $group . ',game_id,day';
- $orderForExport = 'day desc, reg_num desc, game_id desc';
- $dayField = ',day';
- if($mode == 'summary' && $rangeTimeStatus){
- $groupForExport = $group . ',game_id';
- $orderForExport = 'reg_num desc, game_id desc';
- // summary模式下,day字段使用空字符串,实际显示由Go代码根据RangeTimeStatus处理
- $dayField = ",'".$rangeTimeStatus."' as day";
- }
- $field = "channel_id"; // TODO:没找到具体问题,因为上边的 $field 看不懂用来干啥的,导致渠道数据下载时候下载为空;这里先用固定方式使用;
- $field = 'type_id' . $dayField . ',game_id,bz_channel_id,b_channel_id,s_channel_id,sum(reg_num) as reg_num,sum(role_num) as role_num,sum(act_num) as act_num,sum(recharge_num) as recharge_num,sum(pay_num) as pay_num,sum(one_stay) as one_stay,sum(three_stay) as three_stay,sum(four_stay) as four_stay,sum(five_stay) as five_stay,sum(six_stay) as six_stay,sum(seven_stay) as seven_stay,sum(fifteen_stay) as fifteen_stay,sum(thirty_stay) as thirty_stay, ' . $field;
- if($mode == 'summary'){
- $field .= " ,reg_total,new_act_num,new_pay_num,new_recharge_num";
- }else{
- $field .= " ,three_stay_rate,four_stay_rate,five_stay_rate,six_stay_rate,seven_stay_rate,fifteen_stay_rate,thirty_stay_rate,reg_total";
- }
- $sql = model('common/RetaineGame')->field($field)->where($where)->group($groupForExport)->order($orderForExport)->fetchSql(true)->select();
- // $sql = model('common/RetaineGame')->field('type_id' . $dayField . ',game_id,bz_channel_id,b_channel_id,s_channel_id,sum(reg_num) as reg_num,sum(role_num) as role_num,sum(act_num) as act_num,sum(recharge_num) as recharge_num,sum(pay_num) as pay_num,sum(one_stay) as one_stay,sum(three_stay) as three_stay,sum(four_stay) as four_stay,sum(five_stay) as five_stay,sum(six_stay) as six_stay,sum(seven_stay) as seven_stay,sum(fifteen_stay) as fifteen_stay,sum(thirty_stay) as thirty_stay' . $field)->where($where)->group($groupForExport)->order($orderForExport)->fetchSql(true)->select();
- $extendParams = ['Level' => $level, 'TypeId' => $type_id, 'Mode' => $mode];
- if($mode == 'summary' && $rangeTimeStatus){
- $extendParams['RangeTimeStatus'] = $rangeTimeStatus;
- }
- if ((new MakeReportGo())->addTask('retaineGame', $sql, session_id(), $extendParams)) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $total = model('common/RetaineGame')->where($where)->field('sum(reg_num) as reg_num,sum(role_num) as role_num,sum(recharge_num) as recharge_num,sum(act_num) as act_num,sum(reg_total) as reg_total')->find();
- $groupNew = $group . ',game_id,day';
- if($mode == 'summary'){
- $groupNew = $group . ',game_id';
- }
- // dump($groupNew);
- // ->field($filed)
- $sql = model('common/RetaineGame')->where($where)->group($groupNew)->where($where)->buildSql();
- // summary模式下,排序去掉day desc
- $orderBy = 'day desc, reg_num desc, game_id desc';
- if($mode == 'summary'){
- $orderBy = 'reg_num desc, game_id desc';
- }
- $list = Db::table($sql . ' a')->order($orderBy)->paginate(30, false, ['query' => input('get.')])->each(function ($item, $key) use ($mode, $rangeTimeStatus) {
- if($rangeTimeStatus && $mode == 'summary'){
- $item['day'] = $rangeTimeStatus;
- }
- $item['rate'] = $item['act_num'] > 0 ? priceFormat(100 * $item['pay_num'] / $item['act_num']) : '0.00'; // 付费率 = 付费人数/活跃人数
- $item['arpu'] = $item['act_num'] > 0 ? priceFormat($item['recharge_num'] / $item['act_num']) : '0.00'; // arpu = 充值金额/活跃玩家
- $item['arppu'] = $item['pay_num'] > 0 ? priceFormat($item['recharge_num'] / $item['pay_num']) : '0.00'; // arppu = 充值金额/付费人数
- if($mode == 'normal'){
- $item['one_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['one_stay'] / $item['reg_num']) : '0.00'; //次留
- $item['three_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['three_stay'] / $item['reg_num']) : '0.00'; //三留
- $item['four_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['four_stay'] / $item['reg_num']) : '0.00'; //四留
- $item['five_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['five_stay'] / $item['reg_num']) : '0.00'; //五留
- $item['six_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['six_stay'] / $item['reg_num']) : '0.00'; //六留
- $item['seven_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['seven_stay'] / $item['reg_num']) : '0.00'; //七留
- $item['fifteen_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['fifteen_stay'] / $item['reg_num']) : '0.00'; //十五留
- $item['thirty_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['thirty_stay'] / $item['reg_num']) : '0.00'; //三十留
- }else{
- $item['old_act_num'] = $item['old_pay_num'] = $item['old_recharge_num'] = 0;
- if($item['act_num'] > 0 & ($item['act_num'] - $item['new_act_num']) > 0){
- $item['old_act_num'] = $item['act_num'] - $item['new_act_num']; // 老活跃玩家
- }
- if($item['pay_num'] > 0 & ($item['pay_num'] - $item['new_pay_num']) > 0){
- $item['old_pay_num'] = $item['pay_num'] - $item['new_pay_num']; // 老付费玩家
- }
- if($item['recharge_num'] > 0 & ($item['recharge_num'] - $item['new_recharge_num']) > 0){
- $item['old_recharge_num'] = sprintf("%.2f", ($item['recharge_num'] - $item['new_recharge_num'])); // 老玩家付费金额
- }
- }
- return $item;
- });
- } else {
- if ($type_id == 2 && $level = 3) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['channel_id'] = ['in',[-1]];
- }
- } else {
- $where['channel_id'] = ['in', $business];
- }
- } else {
- $where['channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['channel_id'] = ['in', $data['channel_id']];
- }
- }
- }
- if (request()->isAjax()) {
- // 根据mode决定group和order
- $field = '*';
- if($mode == 'summary' && $rangeTimeStatus){
- // summary模式下,day字段使用空字符串,实际显示由Go代码根据RangeTimeStatus处理
- $field = "*,'{$rangeTimeStatus}' as day";
- }
- $sql = model('common/RetaineGame')->where($where)->field($field)->order('day desc, reg_num desc, game_id desc')->fetchSql(true)->select();
- // dump($sql);
- if ((new MakeReportGo())->addTask('retaineGame', $sql, session_id(), ['Level' => $level, 'TypeId' => $type_id, 'Mode' => $mode])) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $total = model('common/RetaineGame')->where($where)->field('sum(reg_num) as reg_num,sum(role_num) as role_num,sum(recharge_num) as recharge_num,sum(act_num) as act_num,sum(reg_total) as reg_total')->find();
- $list = model('common/RetaineGame')->where($where)
- ->order('day desc, reg_num desc, game_id desc')
- // ->order('reg_num desc')
- ->paginate(20, false, ['query' => input('get.')])
- ->each(function ($item, $key) use ($mode, $rangeTimeStatus) {
- if($rangeTimeStatus && $mode == 'summary'){
- $item['day'] = $rangeTimeStatus;
- }
- $item['arpu'] = $item['act_num'] > 0 ? priceFormat($item['recharge_num'] / $item['act_num']) : '0.00'; // 充值金额/活跃玩家
- $item['arppu'] = $item['pay_num'] > 0 ? priceFormat($item['recharge_num'] / $item['pay_num']) : '0.00'; // 充值金额/付费人数
- if($mode == 'normal'){
- $item['rate'] = $item['act_num'] > 0 ? priceFormat(100 * $item['pay_num'] / $item['act_num']) : '0.00'; // 付费率 = 付费人数/活跃人数
- $item['one_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['one_stay'] / $item['reg_num']) : '0.00'; //次留
- $item['three_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['three_stay'] / $item['reg_num']) : '0.00'; //三留
- $item['four_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['four_stay'] / $item['reg_num']) : '0.00'; //四留
- $item['five_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['five_stay'] / $item['reg_num']) : '0.00'; //五留
- $item['six_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['six_stay'] / $item['reg_num']) : '0.00'; //六留
- $item['seven_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['seven_stay'] / $item['reg_num']) : '0.00'; //七留
- $item['fifteen_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['fifteen_stay'] / $item['reg_num']) : '0.00'; //十五留
- $item['thirty_stay_rate'] = $item['reg_num'] > 0 ? priceFormat(100 * $item['thirty_stay'] / $item['reg_num']) : '0.00'; //三十留
- }else{
- $item['old_act_num'] = $item['old_pay_num'] = $item['old_recharge_num'] = 0;
- if($item['act_num'] > 0 && ($item['act_num'] - $item['new_act_num']) > 0){
- $item['old_act_num'] = $item['act_num'] - $item['new_act_num']; // 老活跃玩家
- }
- if($item['pay_num'] > 0 && ($item['pay_num'] - $item['new_pay_num']) > 0){
- $item['old_pay_num'] = $item['pay_num'] - $item['new_pay_num']; // 老付费玩家
- }
- if($item['recharge_num'] > 0 && ($item['recharge_num'] - $item['new_recharge_num']) > 0){
- $item['old_recharge_num'] = sprintf("%.2f", ($item['recharge_num'] - $item['new_recharge_num'])); // 老玩家付费金额
- }
- }
- return $item;
- });
- }
- return [$list, $total];
- }
- public function retaineServer()
- {
- $tmpGameList = model('Common/Game')->getAllByCondition('name,id', ['cooperation_status' => 1]);
- $gameList = array();
- foreach ($tmpGameList as $game) {
- $gameList[$game['id']] = $game;
- }
- $servers = model('common/GameServer')->cache('retaineServer:server', 60)->field('serverid,game_id,servername')->select();
- $serversList = [];
- foreach ($servers as $k => $v) {
- $serversList[$v['game_id'] . '_' . $v['serverid']] = $v['servername'];
- }
- $this->assign('serversList', $serversList);
- $this->assign('gameArr', $tmpGameList);
- $this->assign('game_list', $gameList);
- list($list, $total) = $this->retaineGameServerList(request()->param(), 1);
- $this->assign('total', $total);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- public function retaineServerChannel()
- {
- $tmpGameList = model('Common/Game')->getAllByCondition('name,id', ['cooperation_status' => 1]);
- $gameList = array();
- foreach ($tmpGameList as $game) {
- $gameList[$game['id']] = $game;
- }
- $level = input('level', 0);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'), $level);
- $channelWhere = [];
- if ($business != -1) {
- if ($business) {
- $channelWhere['id'] = ['in', $business];
- } else {
- $channelWhere['id'] = ['in',[-1]];
- }
- }
- $channel = model('common/Channel')->where(['level' => $level])->where($channelWhere)->field('id,name')->order('id desc')->select();
- $channelC = model('common/Channel')->field('id,name')->order('id desc')->select();
- foreach ($channelC as $v) {
- $channelList[$v['id']] = $v;
- }
- $servers = model('common/GameServer')->cache('retaineServer:server', 60)->field('serverid,game_id,servername')->select();
- $serversList = [];
- foreach ($servers as $k => $v) {
- $serversList[$v['game_id'] . '_' . $v['serverid']] = $v['servername'];
- }
- $this->assign('serversList', $serversList);
- $this->assign('level', $level);
- $this->assign('channel', $channel);
- $this->assign('channelList', $channelList);
- $this->assign('gameArr', $tmpGameList);
- $this->assign('game_list', $gameList);
- list($list, $total) = $this->retaineGameServerList(request()->param(), 2);
- $this->assign('total', $total);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- private function retaineGameServerList($data, $type_id)
- {
- $where['type_id'] = ['=', $type_id];
- if (isset($data['server_id']) && $data['server_id']) {
- $where['server_id'] = ['in', $data['server_id']];
- }
- if (isset($data['game_id']) && $data['game_id']) {
- $where['game_id'] = ['in', $data['game_id']];
- }
- //开始时间和结束时间不为空时
- if (isset($data['start']) && isset($data['end']) && $data['start'] != '' && $data['end'] != '') {
- $where['day'] = [
- ['>=', $data['start']],
- ['<=', $data['end']],
- ];
- } //开始时间不为空时
- elseif (isset($data['start']) && $data['start'] != '') {
- $where['day'] = ['>=', $data['start']];
- } //结束时间不为空时
- elseif (isset($data['end']) && $data['end'] != '') {
- $where['day'] = ['<=', $data['end']];
- }
- // 默认昨天
- if(empty($where['day'])){
- $dataTime = date('Y-m-d', strtotime('-1 day'));
- $where['day'] = [
- ['>=', $dataTime],
- ['<=', $dataTime],
- ];
- $this->assign('start', $dataTime);
- $this->assign('end', $dataTime);
- }
- $level = input('level', 0);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'), $level);
- if ($type_id == 2 && $level != 3) {
- if ($level == 0) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['s_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['s_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['s_channel_id'] = ['in', $business];
- }
- } else {
- $where['s_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['s_channel_id'] = ['in', $data['channel_id']];
- }
- }
- $field = ',s_channel_id as channel_id';
- $group = 's_channel_id';
- } else if ($level == 1) {
- // if (isset($data['channel_id']) && $data['channel_id']) {
- // $where['b_channel_id'] = ['in', $data['channel_id']];
- // }
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['b_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['b_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['b_channel_id'] = ['in', $business];
- }
- } else {
- $where['b_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['b_channel_id'] = ['in', $data['channel_id']];
- }
- }
- $field = ',b_channel_id as channel_id';
- $group = 'b_channel_id';
- } else if ($level == 2) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['bz_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['bz_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['bz_channel_id'] = ['in', $business];
- }
- } else {
- $where['bz_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['bz_channel_id'] = ['in', $data['channel_id']];
- }
- }
- if (!(isset($data['channel_id']) && $data['channel_id'])) {
- $where['bz_channel_id'] = ['>', 0];
- }
- $field = ',bz_channel_id as channel_id';
- $group = 'bz_channel_id';
- }
- if (request()->isAjax()) {
- $sql = model('common/RetaineServer')->field('type_id,day,game_id,server_id,bz_channel_id,b_channel_id,s_channel_id,sum(reg_num) as reg_num,sum(role_num) as role_num,sum(act_num) as act_num,sum(recharge_num) as recharge_num,sum(pay_num) as pay_num,sum(one_stay) as one_stay,sum(three_stay) as three_stay,sum(four_stay) as four_stay,sum(five_stay) as five_stay,sum(six_stay) as six_stay,sum(seven_stay) as seven_stay,sum(fifteen_stay) as fifteen_stay,sum(thirty_stay) as thirty_stay' . $field)->where($where)->group($group . ',game_id,server_id,day')->orderRaw('day desc,reg_num desc')->fetchSql(true)->select();
- if ((new MakeReportGo())->addTask('retaineGameServer', $sql, session_id(), ['Level' => $level, 'TypeId' => $type_id])) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $total = model('common/RetaineServer')->where($where)->field('sum(reg_num) as reg_num,sum(role_num) as role_num,sum(recharge_num) as recharge_num,sum(act_num) as act_num')->find();
- $sql = model('common/RetaineServer')->field('type_id,day,game_id,server_id,bz_channel_id,b_channel_id,s_channel_id,sum(reg_num) as reg_num,sum(role_num) as role_num,sum(act_num) as act_num,sum(recharge_num) as recharge_num,sum(pay_num) as pay_num,sum(one_stay) as one_stay,sum(three_stay) as three_stay,sum(four_stay) as four_stay,sum(five_stay) as five_stay,sum(six_stay) as six_stay,sum(seven_stay) as seven_stay,sum(fifteen_stay) as fifteen_stay,sum(thirty_stay) as thirty_stay' . $field)->where($where)->group($group . ',game_id,server_id,day')->buildSql();
- $list = Db::table($sql . ' a')->orderRaw('day desc,reg_num desc')->paginate(20, false, ['query' => input('get.')])->each(function ($item, $key) {
- $item['rate'] = $item['act_num'] > 0 ? priceFormat(100 * $item['pay_num'] / $item['act_num']) : '0.00';//付费人数/活跃人数
- $item['arpu'] = $item['act_num'] > 0 ? priceFormat($item['recharge_num'] / $item['act_num']) : '0.00';//充值金额/活跃玩家
- $item['arppu'] = $item['pay_num'] > 0 ? priceFormat($item['recharge_num'] / $item['pay_num']) : '0.00';// 充值金额/付费人数
- $item['one_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['one_stay'] / $item['role_num']) : '0.00'; //次留
- $item['three_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['three_stay'] / $item['role_num']) : '0.00'; //三留
- $item['four_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['four_stay'] / $item['role_num']) : '0.00'; //四留
- $item['five_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['five_stay'] / $item['role_num']) : '0.00'; //五留
- $item['six_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['six_stay'] / $item['role_num']) : '0.00'; //六留
- $item['seven_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['seven_stay'] / $item['role_num']) : '0.00'; //七留
- $item['fifteen_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['fifteen_stay'] / $item['role_num']) : '0.00'; //十五留
- $item['thirty_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['thirty_stay'] / $item['role_num']) : '0.00'; //三十留
- return $item;
- });
- } else {
- if ($level = 3 && $type_id == 2) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['channel_id'] = ['in',[-1]];
- }
- } else {
- $where['channel_id'] = ['in', $business];
- }
- } else {
- $where['channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['channel_id'] = ['in', $data['channel_id']];
- }
- }
- }
- if (request()->isAjax()) {
- $sql = model('common/RetaineServer')->where($where)->orderRaw('day desc,reg_num desc')->fetchSql(true)->select();
- if ((new MakeReportGo())->addTask('retaineGameServer', $sql, session_id(), ['Level' => $level, 'TypeId' => $type_id])) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $total = model('common/RetaineServer')->where($where)->field('sum(reg_num) as reg_num,sum(role_num) as role_num,sum(recharge_num) as recharge_num,sum(act_num) as act_num')->find();
- $list = model('common/RetaineServer')->where($where)->orderRaw('day desc,reg_num desc')->paginate(20, false, ['query' => input('get.')])->each(function ($item, $key) {
- $item['rate'] = $item['act_num'] > 0 ? priceFormat(100 * $item['pay_num'] / $item['act_num']) : '0.00';//付费人数/活跃人数
- $item['arpu'] = $item['act_num'] > 0 ? priceFormat($item['recharge_num'] / $item['act_num']) : '0.00';//充值金额/活跃玩家
- $item['arppu'] = $item['pay_num'] > 0 ? priceFormat($item['recharge_num'] / $item['pay_num']) : '0.00';// 充值金额/付费人数
- $item['one_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['one_stay'] / $item['role_num']) : '0.00'; //次留
- $item['three_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['three_stay'] / $item['role_num']) : '0.00'; //三留
- $item['four_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['four_stay'] / $item['role_num']) : '0.00'; //四留
- $item['five_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['five_stay'] / $item['role_num']) : '0.00'; //五留
- $item['six_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['six_stay'] / $item['role_num']) : '0.00'; //六留
- $item['seven_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['seven_stay'] / $item['role_num']) : '0.00'; //七留
- $item['fifteen_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['fifteen_stay'] / $item['role_num']) : '0.00'; //十五留
- $item['thirty_stay_rate'] = $item['role_num'] > 0 ? priceFormat($item['thirty_stay'] / $item['role_num']) : '0.00'; //三十留
- return $item;
- });
- }
- return [$list, $total];
- }
- public function getServer()
- {
- $games = explode(',', input('game'));
- if(in_array(223,$games) || in_array(224,$games)){
- $list = model('common/GameServer')
- ->where('game_id', 'in', explode(',', input('game')))
- ->whereRaw('serverid!=-1')
- ->field('servername as name,serverid as id')->group('serverid')->orderRaw('convert(serverid,signed) desc')->select();
- }else{
- $list = model('common/GameServer')
- ->where('game_id', 'in', explode(',', input('game')))
- ->whereRaw('serverid!=servername')
- ->field('servername as name,serverid as id')->group('serverid')->orderRaw('convert(serverid,signed) desc')->select();
- }
- $this->jsonResult($list, 1, '成功');
- }
- public function getChannel()
- {
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'), input('level', 0));
- $channelWhere = [];
- if ($business != -1) {
- if ($business) {
- $channelWhere['id'] = ['in', $business];
- } else {
- $channelWhere['id'] = -1;
- }
- }
- $channel = model('common/Channel')->where(['level' => input('level', 0)])->where($channelWhere)->field('id,name')->order('id desc')->select();
- $this->jsonResult($channel, 1, '成功');
- }
- public function retaine()
- {
- list($list, $total) = $this->retainePlatformList(request()->param(), 1);
- $this->assign('total', $total);
- $this->assign('list', $list);
- $this->assign('page', $list->render());
- return $this->fetch();
- }
- private function retainePlatformList($data, $type_id)
- {
- $where['type_id'] = ['=', $type_id];
- //开始时间和结束时间不为空时
- if (isset($data['start']) && isset($data['end']) && $data['start'] != '' && $data['end'] != '') {
- $where['day'] = [
- ['>=', $data['start']],
- ['<=', $data['end']],
- ];
- } //开始时间不为空时
- elseif (isset($data['start']) && $data['start'] != '') {
- $where['day'] = ['>=', $data['start']];
- } //结束时间不为空时
- elseif (isset($data['end']) && $data['end'] != '') {
- $where['day'] = ['<=', $data['end']];
- }
- $level = input('level', 0);
- $business = model('common/Business')->getChannelIds(session('ADMIN_ID'), $level);
- if ($type_id == 2 && $level != 3) {
- if ($level == 0) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['s_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['s_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['s_channel_id'] = ['in', $business];
- }
- } else {
- $where['s_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['s_channel_id'] = ['in', $data['channel_id']];
- }
- }
- $field = ',s_channel_id as channel_id';
- $group = 's_channel_id';
- } else if ($level == 1) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['b_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['b_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['b_channel_id'] = ['in', $business];
- }
- } else {
- $where['b_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['b_channel_id'] = ['in', $data['channel_id']];
- }
- }
- $field = ',b_channel_id as channel_id';
- $group = 'b_channel_id';
- } else if ($level == 2) {
- if ($business != -1) {
- if ($business && $business != -2) {
- if (isset($data['channel_id']) && $data['channel_id']) {
- if (in_array($data['channel_id'], $business)) {
- $where['bz_channel_id'] = ['in', $data['channel_id']];
- } else {
- $where['bz_channel_id'] = ['in',[-1]];
- }
- } else {
- $where['bz_channel_id'] = ['in', $business];
- }
- } else {
- $where['bz_channel_id'] = ['in',[-1]];
- }
- } else {
- if (isset($data['channel_id']) && $data['channel_id']) {
- $where['bz_channel_id'] = ['in', $data['channel_id']];
- }
- }
- $field = ',bz_channel_id as channel_id';
- $group = 'bz_channel_id';
- }
- if (request()->isAjax()) {
- $sql = model('common/Retaine')->field('type_id,day,bz_channel_id,b_channel_id,s_channel_id,sum(reg_num) as reg_num,sum(role_num) as role_num,sum(act_num) as act_num,sum(recharge_num) as recharge_num,sum(pay_num) as pay_num' . $field)->where($where)->group($group)->order('day desc')->fetchSql(true)->select();
- if ((new MakeReportGo())->addTask('retaine', $sql, session_id(), ['Level' => $level, 'TypeId' => $type_id])) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $total = model('common/Retaine')->where($where)->field('sum(reg_num) as reg_num,sum(role_num) as role_num,sum(recharge_num) as recharge_num,sum(act_num) as act_num')->find();
- $sql = model('common/Retaine')->field('type_id,day,bz_channel_id,b_channel_id,s_channel_id,sum(reg_num) as reg_num,sum(role_num) as role_num,sum(act_num) as act_num,sum(recharge_num) as recharge_num,sum(pay_num) as pay_num' . $field)->where($where)->group($group . ',day')->where($where)->buildSql();
- $list = Db::table($sql . ' a')->order('day desc')->paginate(20, false, ['query' => input('get.')])->each(function ($item, $key) {
- $item['rate'] = $item['act_num'] > 0 ? priceFormat(100 * $item['pay_num'] / $item['act_num']) : '0.00';//付费人数/活跃人数
- $item['arpu'] = $item['act_num'] > 0 ? priceFormat($item['recharge_num'] / $item['act_num']) : '0.00';//充值金额/活跃玩家
- $item['arppu'] = $item['pay_num'] > 0 ? priceFormat($item['recharge_num'] / $item['pay_num']) : '0.00';// 充值金额/付费人数
- return $item;
- });
- } else {
- if (request()->isAjax()) {
- $sql = model('common/Retaine')->where($where)->order('day desc')->fetchSql(true)->select();
- if ((new MakeReportGo())->addTask('retaine', $sql, session_id(), ['Level' => $level, 'TypeId' => $type_id])) {
- $this->success('报表生成的任务已经提交, 报表生成完成后,会及时通知您,请耐心稍等');
- } else {
- $this->error('报表生成任务不可重复提交,如遇到无法导出情况,建议修改查询条件解除当前状态,提交重新生成报表任务!');
- }
- }
- $total = model('common/Retaine')->where($where)->field('sum(reg_num) as reg_num,sum(role_num) as role_num,sum(recharge_num) as recharge_num,sum(act_num) as act_num')->find();
- $list = model('common/Retaine')->where($where)->order('day desc')->paginate(20, false, ['query' => input('get.')])->each(function ($item, $key) {
- $item['rate'] = $item['act_num'] > 0 ? priceFormat(100 * $item['pay_num'] / $item['act_num']) : '0.00';// 付费人数/活跃人数
- $item['arpu'] = $item['act_num'] > 0 ? priceFormat($item['recharge_num'] / $item['act_num']) : '0.00';// 充值金额/活跃玩家
- $item['arppu'] = $item['pay_num'] > 0 ? priceFormat($item['recharge_num'] / $item['pay_num']) : '0.00';// 充值金额/付费人数
- return $item;
- });
- }
- return [$list, $total];
- }
- }
|