diff --git a/Application/Admin/Controller/ExportController.class.php b/Application/Admin/Controller/ExportController.class.php index 332414b6b..68b327454 100644 --- a/Application/Admin/Controller/ExportController.class.php +++ b/Application/Admin/Controller/ExportController.class.php @@ -2971,46 +2971,113 @@ class ExportController extends Controller * ltv统计 * @author 鹿文学 */ - public function ltv($p=1) { + public function ltv($p=1, $start, $end) { $xlsName = $_REQUEST['xlsname']; $xlsCell = array( - array('time','日期'), - array('amount','充值金额'), - array('active','活跃用户'), - array('ltv1','LTV1'), - array('ltv2','LTV2'), - array('ltv3','LTV3'), - array('ltv4','LTV4'), - array('ltv5','LTV5'), - array('ltv6','LTV6'), - array('ltv7','LTV7'), - array('ltv14','LTV14'), - array('ltv30','LTV30'), + array('date','日期'), + array('total_amt','充值金额'), + array('user_count','活跃用户'), + array('ltv_1','LTV1'), + array('ltv_2','LTV2'), + array('ltv_3','LTV3'), + array('ltv_4','LTV4'), + array('ltv_5','LTV5'), + array('ltv_6','LTV6'), + array('ltv_7','LTV7'), + array('ltv_14','LTV14'), + array('ltv_30','LTV30'), ); - if (is_file(dirname(__FILE__).'/access_data_ltv.txt')) { - - $filetxt = file_get_contents(dirname(__FILE__).'/access_data_ltv.txt'); - - $data = json_decode($filetxt,true); - - } else { - $page = intval($p); - $page = $page ? $page : 1; //默认显示第一页数据 - if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;}//10; - - $start = I('start',date('Y-m-d',strtotime('-30 day'))); - - $end = I('end',date('Y-m-d',strtotime('-1 day'))); - - $end = strtotime($end)>=strtotime(date('Y-m-d'))?date('Y-m-d',strtotime('-1 day')):$end; - - $data = D('user')->ltv(strtotime($start),strtotime($end)); + $start_time = $start = strtotime($start); + $end_time = $end = strtotime($end) + 86400; + $map = " 1=1 "; + if (isset($_REQUEST['game_name'])) { + $map .= " AND game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")"; + } + if (isset($_REQUEST['server_name'])) { + $map .= " AND server_name = '{$_REQUEST['server_name']}' "; + } - } + // 获取包含的用户id + $users = M()->query(" + SELECT + count(*) as total_count, + GROUP_CONCAT(u.id) as ids, + FROM_UNIXTIME(u.register_time, '%Y-%m-%d') as reg_date + FROM + tab_user u + WHERE + u.register_time BETWEEN {$start_time} + AND {$end_time} + GROUP BY reg_date + ORDER BY reg_date asc + "); + $result = []; + foreach ($users as $index => $item) { + $ltv_start = strtotime($item['reg_date']); + $ltv_end = strtotime($item['reg_date']) + 30 * 86400; + $ltv = M()->query(" + SELECT + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 1).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_1, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 2).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_2, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 3).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_3, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 4).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_4, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 5).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_5, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 6).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_6, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 7).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_7, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 14).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_14, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 30).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_30, + SUM(pay_amount) as total_amt + FROM + tab_spend + WHERE + {$map} + AND pay_time BETWEEN {$ltv_start} + AND {$ltv_end} + AND user_id IN ({$item['ids']}) AND pay_status = 1 + "); + $result[] = [ + 'date'=>$item['reg_date'], + 'total_amt'=>$ltv[0]['total_amt'] ?: 0, + 'user_count'=>$item['total_count'] ?: 0, + 'ltv_1'=>$ltv[0]['ltv_1'] ?: 0, + 'ltv_2'=>$ltv[0]['ltv_2'] ?: 0, + 'ltv_3'=>$ltv[0]['ltv_3'] ?: 0, + 'ltv_4'=>$ltv[0]['ltv_4'] ?: 0, + 'ltv_5'=>$ltv[0]['ltv_5'] ?: 0, + 'ltv_6'=>$ltv[0]['ltv_6'] ?: 0, + 'ltv_7'=>$ltv[0]['ltv_7'] ?: 0, + 'ltv_14'=>$ltv[0]['ltv_14'] ?: 0, + 'ltv_30'=>$ltv[0]['ltv_30'] ?: 0 + ]; + unset($user[$index]); + } + $data = []; + $k = 0; + for($i=$start_time; $i<$end_time; $i+=86400) { + if (($result[$k]['date'] == date("Y-m-d", $i))) { + $data[] = $result[$k]; + $k += 1; + } else { + $data[] = [ + 'date'=>date("Y-m-d", $i), + 'total_amt'=> 0, + 'user_count'=> 0, + 'ltv_1'=> 0, + 'ltv_2'=> 0, + 'ltv_3'=> 0, + 'ltv_4'=> 0, + 'ltv_5'=> 0, + 'ltv_6'=> 0, + 'ltv_7'=> 0, + 'ltv_14'=> 0, + 'ltv_30'=> 0 + ]; + } + } foreach ($data as $v) { $xlsData[] = $v; diff --git a/Application/Admin/Controller/StatisticsController.class.php b/Application/Admin/Controller/StatisticsController.class.php index 4dd30404b..31040e7d4 100644 --- a/Application/Admin/Controller/StatisticsController.class.php +++ b/Application/Admin/Controller/StatisticsController.class.php @@ -954,43 +954,146 @@ if ($payids) { * @param integer $p 当前页 * @author 鹿文学 */ - public function ltv($p=1) { + // public function ltv($p=1) { - $page = intval($p); + // $page = intval($p); - $page = $page ? $page : 1; //默认显示第一页数据 + // $page = $page ? $page : 1; //默认显示第一页数据 - if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} + // if(isset($_REQUEST['row'])) {$row = $_REQUEST['row'];}else{$row = 10;} - $start = $_GET['start']= I('start',date('Y-m-d',strtotime('-30 day'))); + // $start = $_GET['start']= I('start',date('Y-m-d',strtotime('-30 day'))); - $end = I('end',date('Y-m-d',strtotime('-1 day'))); + // $end = I('end',date('Y-m-d',strtotime('-1 day'))); - $end = strtotime($end)>=strtotime(date('Y-m-d'))?date('Y-m-d',strtotime('-1 day')):$end; + // $end = strtotime($end)>=strtotime(date('Y-m-d'))?date('Y-m-d',strtotime('-1 day')):$end; - $_GET['end'] = $end; + // $_GET['end'] = $end; - $list = D('user')->ltv(strtotime($start),strtotime($end)); + // $list = D('user')->ltv(strtotime($start),strtotime($end)); - $count = count($list); + // $count = count($list); - $data = array_slice($list,($page-1)*$row,$row,true); + // $data = array_slice($list,($page-1)*$row,$row,true); - file_put_contents(dirname(__FILE__).'/access_data_ltv.txt',json_encode($list)); + // file_put_contents(dirname(__FILE__).'/access_data_ltv.txt',json_encode($list)); - $page = set_pagination($count,$row); - if($page) {$this->assign('_page', $page);} + // $page = set_pagination($count,$row); + // if($page) {$this->assign('_page', $page);} + + + // $this->meta_title = 'LTV统计'; + + // $this->assign('data',$data); + // $this->display(); + // } + + public function ltv($p=1, $row=10) + { + $start = I('start',date('Y-m-d',strtotime('-30 day'))); + $end = I('end',date('Y-m-d',strtotime('-1 day'))); + $start = strtotime($start); + $end = strtotime($end) + 86400; + $start_time = strtotime("+".(($p-1)*$row)." day", $start); + $end_time = strtotime("+".($p*$row+1)." day", $start); + $end_time = $end_time > $end ? $end : $end_time; + + $map = " 1=1 "; + if (isset($_REQUEST['game_name'])) { + $map .= " AND game_id in (" . implode(',', array_column(getGameByName($_REQUEST['game_name'], $_REQUEST['game_type']), 'id')) . ")"; + } + if (isset($_REQUEST['server_name'])) { + $map .= " AND server_name = '{$_REQUEST['server_name']}' "; + } + // 获取包含的用户id + $users = M()->query(" + SELECT + count(*) as total_count, + GROUP_CONCAT(u.id) as ids, + FROM_UNIXTIME(u.register_time, '%Y-%m-%d') as reg_date + FROM + tab_user u + WHERE + u.register_time BETWEEN {$start_time} + AND {$end_time} + GROUP BY reg_date + ORDER BY reg_date asc + "); + $result = []; + foreach ($users as $index => $item) { + $ltv_start = strtotime($item['reg_date']); + $ltv_end = strtotime($item['reg_date']) + 30 * 86400; + $ltv = M()->query(" + SELECT + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 1).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_1, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 2).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_2, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 3).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_3, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 4).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_4, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 5).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_5, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 6).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_6, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 7).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_7, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 14).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_14, + ROUND(SUM(if (pay_time BETWEEN {$ltv_start} and ".($ltv_start+86400 * 30).", pay_amount, 0))/{$item['total_count']}, 2) as ltv_30, + SUM(pay_amount) as total_amt + FROM + tab_spend + WHERE + {$map} + AND pay_time BETWEEN {$ltv_start} + AND {$ltv_end} + AND user_id IN ({$item['ids']}) AND pay_status = 1 + "); + $result[] = [ + 'date'=>$item['reg_date'], + 'total_amt'=>$ltv[0]['total_amt'] ?: 0, + 'user_count'=>$item['total_count'] ?: 0, + 'ltv_1'=>$ltv[0]['ltv_1'] ?: 0, + 'ltv_2'=>$ltv[0]['ltv_2'] ?: 0, + 'ltv_3'=>$ltv[0]['ltv_3'] ?: 0, + 'ltv_4'=>$ltv[0]['ltv_4'] ?: 0, + 'ltv_5'=>$ltv[0]['ltv_5'] ?: 0, + 'ltv_6'=>$ltv[0]['ltv_6'] ?: 0, + 'ltv_7'=>$ltv[0]['ltv_7'] ?: 0, + 'ltv_14'=>$ltv[0]['ltv_14'] ?: 0, + 'ltv_30'=>$ltv[0]['ltv_30'] ?: 0 + ]; + unset($user[$index]); + } + $data = []; + $k = 0; + for($i=$start_time; $i<$end_time; $i+=86400) { + if (($result[$k]['date'] == date("Y-m-d", $i))) { + $data[] = $result[$k]; + $k += 1; + } else { + $data[] = [ + 'date'=>date("Y-m-d", $i), + 'total_amt'=> 0, + 'user_count'=> 0, + 'ltv_1'=> 0, + 'ltv_2'=> 0, + 'ltv_3'=> 0, + 'ltv_4'=> 0, + 'ltv_5'=> 0, + 'ltv_6'=> 0, + 'ltv_7'=> 0, + 'ltv_14'=> 0, + 'ltv_30'=> 0 + ]; + } + } + $count = ($end-$start)/86400; + $page = set_pagination($count,$row); + if($page) {$this->assign('_page', $page);} + $this->meta_title = 'LTV统计'; $this->assign('data',$data); - $this->display(); - + $this->display('ltv'); } - - } diff --git a/Application/Admin/Controller/access_data_foldline.txt b/Application/Admin/Controller/access_data_foldline.txt index 18f7fceb5..89c4789df 100644 --- a/Application/Admin/Controller/access_data_foldline.txt +++ b/Application/Admin/Controller/access_data_foldline.txt @@ -1 +1 @@ -{"news":[{"time":"0:00","count":6},{"time":"1:00","count":9},{"time":"2:00","count":7},{"time":"3:00","count":11},{"time":"4:00","count":16},{"time":"5:00","count":7},{"time":"6:00","count":9},{"time":"7:00","count":11},{"time":"8:00","count":14},{"time":"9:00","count":40},{"time":"10:00","count":58},{"time":"11:00","count":86},{"time":"12:00","count":41},{"time":"13:00","count":55},{"time":"14:00","count":194},{"time":"15:00","count":180},{"time":"16:00","count":121},{"time":"17:00","count":98},{"time":"18:00","count":120},{"time":"19:00","count":147},{"time":"20:00","count":146},{"time":"21:00","count":124},{"time":"22:00","count":93},{"time":"23:00","count":56}],"sum":{"news":1649,"active":8210,"player":1715,"money":226618},"active":[{"time":"0:00","count":967},{"time":"1:00","count":343},{"time":"2:00","count":176},{"time":"3:00","count":135},{"time":"4:00","count":118},{"time":"5:00","count":177},{"time":"6:00","count":465},{"time":"7:00","count":661},{"time":"8:00","count":622},{"time":"9:00","count":547},{"time":"10:00","count":480},{"time":"11:00","count":414},{"time":"12:00","count":326},{"time":"13:00","count":237},{"time":"14:00","count":354},{"time":"15:00","count":328},{"time":"16:00","count":215},{"time":"17:00","count":219},{"time":"18:00","count":256},{"time":"19:00","count":335},{"time":"20:00","count":274},{"time":"21:00","count":244},{"time":"22:00","count":197},{"time":"23:00","count":120}],"player":[{"time":"0:00","count":211},{"time":"1:00","count":84},{"time":"2:00","count":29},{"time":"3:00","count":25},{"time":"4:00","count":16},{"time":"5:00","count":24},{"time":"6:00","count":32},{"time":"7:00","count":56},{"time":"8:00","count":71},{"time":"9:00","count":66},{"time":"10:00","count":63},{"time":"11:00","count":69},{"time":"12:00","count":58},{"time":"13:00","count":62},{"time":"14:00","count":50},{"time":"15:00","count":99},{"time":"16:00","count":68},{"time":"17:00","count":61},{"time":"18:00","count":77},{"time":"19:00","count":157},{"time":"20:00","count":107},{"time":"21:00","count":101},{"time":"22:00","count":74},{"time":"23:00","count":55}],"money":[{"time":"0:00","count":"31554.00"},{"time":"1:00","count":"4117.00"},{"time":"2:00","count":"1839.00"},{"time":"3:00","count":"4513.00"},{"time":"4:00","count":"1008.00"},{"time":"5:00","count":"1981.00"},{"time":"6:00","count":"1270.00"},{"time":"7:00","count":"1906.00"},{"time":"8:00","count":"6683.00"},{"time":"9:00","count":"6119.00"},{"time":"10:00","count":"8974.00"},{"time":"11:00","count":"14147.00"},{"time":"12:00","count":"9775.00"},{"time":"13:00","count":"11908.00"},{"time":"14:00","count":"6781.00"},{"time":"15:00","count":"12626.00"},{"time":"16:00","count":"6742.00"},{"time":"17:00","count":"8303.00"},{"time":"18:00","count":"8804.00"},{"time":"19:00","count":"23476.00"},{"time":"20:00","count":"17464.00"},{"time":"21:00","count":"16899.00"},{"time":"22:00","count":"13143.00"},{"time":"23:00","count":"6586.00"}]} \ No newline at end of file +{"news":[{"time":"0:00","count":0},{"time":"1:00","count":0},{"time":"2:00","count":0},{"time":"3:00","count":0},{"time":"4:00","count":0},{"time":"5:00","count":0},{"time":"6:00","count":0},{"time":"7:00","count":0},{"time":"8:00","count":0},{"time":"9:00","count":1},{"time":"10:00","count":0},{"time":"11:00","count":0},{"time":"12:00","count":0},{"time":"13:00","count":0},{"time":"14:00","count":0},{"time":"15:00","count":0},{"time":"16:00","count":0},{"time":"17:00","count":0},{"time":"18:00","count":0},{"time":"19:00","count":1},{"time":"20:00","count":0},{"time":"21:00","count":0},{"time":"22:00","count":0},{"time":"23:00","count":0}],"sum":{"news":2,"active":13,"player":5,"money":1330.05},"active":[{"time":"0:00","count":0},{"time":"1:00","count":0},{"time":"2:00","count":0},{"time":"3:00","count":0},{"time":"4:00","count":0},{"time":"5:00","count":0},{"time":"6:00","count":0},{"time":"7:00","count":0},{"time":"8:00","count":0},{"time":"9:00","count":3},{"time":"10:00","count":2},{"time":"11:00","count":2},{"time":"12:00","count":0},{"time":"13:00","count":0},{"time":"14:00","count":1},{"time":"15:00","count":1},{"time":"16:00","count":0},{"time":"17:00","count":1},{"time":"18:00","count":0},{"time":"19:00","count":2},{"time":"20:00","count":0},{"time":"21:00","count":1},{"time":"22:00","count":0},{"time":"23:00","count":0}],"player":[{"time":"0:00","count":0},{"time":"1:00","count":0},{"time":"2:00","count":0},{"time":"3:00","count":0},{"time":"4:00","count":0},{"time":"5:00","count":0},{"time":"6:00","count":0},{"time":"7:00","count":0},{"time":"8:00","count":0},{"time":"9:00","count":0},{"time":"10:00","count":0},{"time":"11:00","count":1},{"time":"12:00","count":0},{"time":"13:00","count":0},{"time":"14:00","count":1},{"time":"15:00","count":1},{"time":"16:00","count":2},{"time":"17:00","count":0},{"time":"18:00","count":0},{"time":"19:00","count":0},{"time":"20:00","count":0},{"time":"21:00","count":0},{"time":"22:00","count":0},{"time":"23:00","count":0}],"money":[{"time":"0:00","count":0},{"time":"1:00","count":0},{"time":"2:00","count":0},{"time":"3:00","count":0},{"time":"4:00","count":0},{"time":"5:00","count":0},{"time":"6:00","count":0},{"time":"7:00","count":0},{"time":"8:00","count":0},{"time":"9:00","count":0},{"time":"10:00","count":0},{"time":"11:00","count":"962.00"},{"time":"12:00","count":0},{"time":"13:00","count":0},{"time":"14:00","count":"356.00"},{"time":"15:00","count":"0.03"},{"time":"16:00","count":"12.02"},{"time":"17:00","count":0},{"time":"18:00","count":0},{"time":"19:00","count":0},{"time":"20:00","count":0},{"time":"21:00","count":0},{"time":"22:00","count":0},{"time":"23:00","count":0}]} \ No newline at end of file diff --git a/Application/Admin/View/Statistics/ltv.html b/Application/Admin/View/Statistics/ltv.html index 0022914fa..518d3000b 100644 --- a/Application/Admin/View/Statistics/ltv.html +++ b/Application/Admin/View/Statistics/ltv.html @@ -6,7 +6,7 @@
@@ -20,7 +20,26 @@  - 
- +
+ +
+
+ +
+
+ +
搜索 @@ -56,18 +75,18 @@ - {$vo.time} - {$vo.amount} - {$vo.active} - {$vo.ltv1} - {$vo.ltv2} - {$vo.ltv3} - {$vo.ltv4} - {$vo.ltv5} - {$vo.ltv6} - {$vo.ltv7} - {$vo.ltv14} - {$vo.ltv30} + {$vo.date} + {$vo.total_amt} + {$vo.user_count} + {$vo.ltv_1} + {$vo.ltv_2} + {$vo.ltv_3} + {$vo.ltv_4} + {$vo.ltv_5} + {$vo.ltv_6} + {$vo.ltv_7} + {$vo.ltv_14} + {$vo.ltv_30} @@ -172,10 +191,33 @@ $(function(){ autoclose:1,endDate:new Date(new Date().getTime()-24*60*60*1000), pickerPosition:'bottom-right' }); - - - + var game_server = "{:I('server_name')}"; + $("#game_type").change(function(){ + console.log({sdk_version:$("#game_type option:selected").val(), game_name:$("#game_name option:selected").val()}) + $.ajax({ + url:"{:U('Ajax/getGmeServer')}", + type:"post", + data:{sdk_version:$("#game_type option:selected").val(), game_name:$("#game_name option:selected").val()}, + dataType:'json', + success:function(data){ + console.log(data) + str = ""; + for (var i in data){ + str += "" + } + $("#server_name").empty(); + $("#server_name").append(str); + $("#server_name").select2(); + } + }) + }); + + $("#game_name").change(function(){ + $("#game_type").change(); + }); + + $("#game_name").change(); })