no message
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller\popup;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\popup\PopupLogLists;
|
||||
use app\common\model\popup\PagePopup;
|
||||
use app\common\model\popup\PagePopupLog;
|
||||
|
||||
/**
|
||||
* 弹窗操作日志
|
||||
*/
|
||||
class PopupLogController extends BaseAdminController
|
||||
{
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new PopupLogLists());
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹窗统计概览
|
||||
* GET /popup.popup_log/stats?popup_id=xxx
|
||||
* 返回:[show, click, close, ctr, days[]]
|
||||
*/
|
||||
public function stats()
|
||||
{
|
||||
$popupId = (int)$this->request->get('popup_id', 0);
|
||||
$where = [];
|
||||
if ($popupId > 0) $where[] = ['popup_id', '=', $popupId];
|
||||
|
||||
$show = PagePopupLog::where($where)->where('action', 1)->count();
|
||||
$click = PagePopupLog::where($where)->where('action', 2)->count();
|
||||
$close = PagePopupLog::where($where)->where('action', 3)->count();
|
||||
$ctr = $show > 0 ? round($click / $show * 100, 2) : 0;
|
||||
|
||||
// 最近 7 天每日统计
|
||||
$days = [];
|
||||
for ($i = 6; $i >= 0; $i--) {
|
||||
$start = strtotime(date('Y-m-d', strtotime("-{$i} day")));
|
||||
$end = $start + 86400;
|
||||
$dShow = PagePopupLog::where($where)->where('action', 1)
|
||||
->where('create_time', '>=', $start)
|
||||
->where('create_time', '<', $end)->count();
|
||||
$dClick = PagePopupLog::where($where)->where('action', 2)
|
||||
->where('create_time', '>=', $start)
|
||||
->where('create_time', '<', $end)->count();
|
||||
$days[] = [
|
||||
'date' => date('m-d', $start),
|
||||
'show' => $dShow,
|
||||
'click' => $dClick,
|
||||
];
|
||||
}
|
||||
|
||||
$popupName = '';
|
||||
if ($popupId > 0) {
|
||||
$popup = PagePopup::find($popupId);
|
||||
$popupName = $popup ? (string)$popup['name'] : '';
|
||||
}
|
||||
|
||||
return $this->data([
|
||||
'popup_id' => $popupId,
|
||||
'popup_name' => $popupName,
|
||||
'show' => $show,
|
||||
'click' => $click,
|
||||
'close' => $close,
|
||||
'ctr' => $ctr,
|
||||
'days' => $days,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user