ltv优化

master
yulingwei 5 years ago
parent fc2596a7cc
commit 9f156f7be4

@ -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;

@ -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');
}
}

@ -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"}]}
{"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}]}

@ -6,7 +6,7 @@
<div class="cf main-place top_nav_list navtab_list">
<h3 class="page_title">LTV统计</h3>
<p class="description_text">说明:计算用户生命周期价值的相关数据(充值金额统计用户在平台内/游戏内进行现金充值的数据汇总,游戏内通过平台币/绑币进行消费的计算在内 </p>
<p class="description_text">说明:计算用户生命周期价值的相关数据(充值金额统计用户在平台内/游戏内进行现金充值的数据汇总,游戏内通过平台币/绑币进行消费的计算在内 </p>
</div>
<div class="cf jssearch top_nav_list">
@ -20,7 +20,26 @@
&nbsp;-&nbsp;
<input type="text" id="time-end" name="end" class="" value="{:I('end',date('Y-m-d',strtotime('-1 day')))}" placeholder="选择结束时间" />
</div>
<div class="input-list input-list-game search_label_rehab">
<select id="game_name" name="game_name" class="select_gallery" >
<option value="">游戏名称</option>
<volist name=":getAllGame()" id="vo">
<option value="{$vo.game_name}" <if condition="$vo.game_name eq I('game_name')">selected</if> >{$vo.game_name}</option>
</volist>
</select>
</div>
<div class="input-list input-list-game search_label_rehab">
<select id="game_type" name="game_type" class="select_gallery" >
<option value="">设备类型</option>
<option value="1" <?php echo I('game_type') == 1 ? "selected" : ''?>>安卓</option>
<option value="2" <?php echo I('game_type') == 2 ? "selected" : ''?>>苹果</option>
</select>
</div>
<div class="input-list input-list-server search_label_rehab">
<select id="server_name" name="server_name" class="select_gallery" style="width:120px;">
<option value="">区服名称</option>
</select>
</div>
<div class="input-list">
<a class="sch-btn" href="javascript:;" id="search" url="{:U('Statistics/ltv','model='.$model['name'] .'&row='.I('row'),false)}">搜索</a>
@ -56,18 +75,18 @@
<else/>
<volist name="data" id="vo">
<tr>
<td>{$vo.time}</td>
<td>{$vo.amount}</td>
<td>{$vo.active}</td>
<td>{$vo.ltv1}</td>
<td>{$vo.ltv2}</td>
<td>{$vo.ltv3}</td>
<td>{$vo.ltv4}</td>
<td>{$vo.ltv5}</td>
<td>{$vo.ltv6}</td>
<td>{$vo.ltv7}</td>
<td>{$vo.ltv14}</td>
<td>{$vo.ltv30}</td>
<td>{$vo.date}</td>
<td>{$vo.total_amt}</td>
<td>{$vo.user_count}</td>
<td>{$vo.ltv_1}</td>
<td>{$vo.ltv_2}</td>
<td>{$vo.ltv_3}</td>
<td>{$vo.ltv_4}</td>
<td>{$vo.ltv_5}</td>
<td>{$vo.ltv_6}</td>
<td>{$vo.ltv_7}</td>
<td>{$vo.ltv_14}</td>
<td>{$vo.ltv_30}</td>
</tr>
</volist>
</empty>
@ -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 = "<option value=''>请选择区服</option>";
for (var i in data){
str += "<option value='"+data[i].server_name+"' "+(game_server && data[i].server_name == game_server?'selected':'')+">"+data[i].server_name+"</option>"
}
$("#server_name").empty();
$("#server_name").append(str);
$("#server_name").select2();
}
})
});
$("#game_name").change(function(){
$("#game_type").change();
});
$("#game_name").change();
})
</script>

Loading…
Cancel
Save