Статистика по клику

parent 046cd179
......@@ -34,7 +34,7 @@ return [
->allow(Roles::ROLE_GUEST, 'user.mail.sent.password')
->allow(Roles::ROLE_USER, 'user.cabinet', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'user.cabinet.profile', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'user.viewid', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'user.cabinet.viewid', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'install.counter', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_USER, 'download.counter', null, new \App\Acl\Assertion\UserActive())
->allow(Roles::ROLE_GUEST, 'email.counter')
......
......@@ -53,6 +53,7 @@ return [
'cats' => [
'Timestamp' => 'Время<br />Дата',
'Basket' => 'Состав корзины',
'ViewID' => 'ViewID',
'OrderSum' => 'Сумма',
]
/*
......
......@@ -314,13 +314,14 @@ return [
],
],
[
'name' => 'user.viewid',
'path' => '/[:lang/]cabinet/viewid/:id',
'name' => 'user.cabinet.viewid',
'path' => '/[:lang/]cabinet/viewid/:feedid/:id',
'middleware' => App\Action\User\ViewId::class,
'allowed_methods' => ['GET', 'POST'],
'options' => [
'constraints' => [
'lang' => '[a-z]{2,3}',
'feedid' => '\w+',
'id' => '\w+',
],
'defaults' => [
......
......@@ -25,7 +25,8 @@
#period-stats,
#campaign-stats,
#report-cats
#report-cats,
#viewid-stats
{
display: none;
}
......@@ -158,7 +159,7 @@ input[type="checkbox"]
text-align: center;
}
.b-table_wrapp
.b-table_wrapp.report
{
display: none;
margin-top: 30px;
......@@ -225,6 +226,17 @@ input[type="checkbox"]
line-height: 14px;
}
.table.table-striped.admin thead tr th.StartTime,
.table.table-striped.admin thead tr th.EndTime
{
width: auto;
}
.table.table-striped.admin thead tr th.URL
{
width: 500px;
}
.table.table-striped.admin tbody td.Timestamp
{
line-height: 13px;
......@@ -248,7 +260,15 @@ input[type="checkbox"]
width: 530px;
}
.table.table-striped.admin thead tr th.Basket .quantity
.table.table-striped.admin.viewid thead tr th.Basket .basket-link
{
width: 500px;
}
.table.table-striped.admin thead tr th.Basket .quantity,
.table.table-striped.admin thead tr th.Basket .viewid
{
text-align: center;
width: 55px;
......@@ -306,7 +326,23 @@ input[type="checkbox"]
display: inline-block;
width: 540px;
}
table.viewid .b-basket-content .basket-link
{
display: inline-block;
width: 510px;
font-size: 11px;
font-weight: bold;
}
.b-basket-content .view-id-url
{
display: inline-block;
width: 595px;
margin-bottom: 4px;
}
.b-basket-content .quantity
{
display: inline-block;
......@@ -321,6 +357,11 @@ input[type="checkbox"]
text-align: left;
}
table.viewid .b-basket-content .price
{
width: 40px;
}
......
......@@ -7,7 +7,7 @@ $(document).ready(function(){
activeLines = [],
currentActiveLine,
currencyFields = ['admoney', 'salemoney', 'usdollarmoney', 'localmoney', 'AdMoney', 'OrderSum', 'Price'],
notFormatFields = ['Timestamp', 'Basket'],
notFormatFields = ['Timestamp', 'Basket', 'ViewID'],
dateTimeFields = ['Timestamp', 'period'];
// Шаблон содержимого ячейки Basket
......@@ -33,6 +33,12 @@ $(document).ready(function(){
' <span><%=data.date %></span><br /> \n' +
'');
// Шаблон ячейки ViewID
var templateViewIDContent = _.template('\n'+
' <a class="viewid-link" href="viewid/<%=data.feedId %>/<%=data.viewId %>" target="_blank"><%=data.viewId %></a> \n' +
'');
function valueFormat(value)
{
......@@ -126,7 +132,7 @@ $(document).ready(function(){
return (isDesc) ? b[sortField]-a[sortField] : a[sortField]-b[sortField];
}
});
//console.log('AAA dataTableForSort = ', dataTableForSort);
console.log('AAA dataTableForSort = ', dataTableForSort);
// Отрисовка таблицы:
dataTableForSort.forEach(function(item){
......@@ -141,7 +147,10 @@ $(document).ready(function(){
$row.append($('<td class="'+ line +'">').append(templateTimestampContent({
data: {date: getDateValue(item[line]), time: getHourMinValue(item[line])}
})));
} else if (line == 'ViewID') {
$row.append($('<td class="'+ line +'">').append(templateViewIDContent({
data: {feedId: item[line][0], viewId: item[line][1]}
})));
} else {
currentActiveLine = line;
$row.append($('<td class="'+ line +'">').html(valueFormat(item[line])));
......
......@@ -73,14 +73,14 @@ $(document).ready(function(){
//console.log('AAA dataLineChartStat = ', dataLineChartStat);
if (!dataLineChartStat) {
ShowInfo();
}
// Отрисовка графика и таблицы по стартовым данным:
if (dataLineChartStat.status == 'Error') {
ShowError();
} else {
renderLineChart();
renderHourTable();
// Отрисовка графика и таблицы по стартовым данным:
if (dataLineChartStat.status == 'Error') {
ShowError();
} else {
renderLineChart();
renderHourTable();
}
}
......
......@@ -88,6 +88,7 @@ class Cabinet extends Common
/** @var \App\Model\Feeds $feedsModel */
$feedsModel = $this->container->get(Feeds::class);
$feeds = $feedsModel->findAll(['clientid' => $userId])->toArray();
//$feed_id_list = $feedsModel->getIdListByUser($userId);
if ($feeds) {
......
......@@ -79,23 +79,41 @@ class ViewId extends Common
} else {
/*
$feed_id = $request->getAttribute('feedid');
$view_id = $request->getAttribute('id');
$viewIdStats = $stats->getViewIdStatData($feed_id, $view_id);
return new JsonResponse($viewIdStats);
*/
try {
$feed_id = $request->getAttribute('feedid');
$view_id = $request->getAttribute('id');
/** @var UserService $auth */
$auth = $this->container->get(UserService::class);
$userId = $auth->getIdentity()->getId();
/** @var \App\Model\Feeds $feedsModel */
$feedsModel = $this->container->get(Feeds::class);
$feed_id_list = $feedsModel->getIdListByUser($userId);
$feed_item = $feedsModel->findById($feed_id);
$view_id = $request->getAttribute('id');
// Статистика по клику:
$viewIdStats = $stats->getViewIdStatData($feed_id_list, $view_id);
$data['viewIdStats'] = $viewIdStats;
if ($feed_item) {
if ($feed_item->getClientid() == $userId){
// Статистика по клику:
$viewIdStats = $stats->getViewIdStatData($feed_id, $view_id);
$data['viewIdStats'] = $viewIdStats;
} else {
$data['error'] = _t('Извините, данный фид закреплен за другим пользователем');
}
} else {
$data['error'] = _t('Извините, фид не найден');
}
} catch(\Exception $e) {
$data['error'] = _t('Извините, история визитов по клику временно не работает');
......@@ -106,7 +124,7 @@ class ViewId extends Common
'layoutInfo' => $request->getAttribute('layoutInfo'),
]);
return new HtmlResponse($this->template->render('app::user/view-id', $data));
return new HtmlResponse($this->template->render('app::user/cabinet-feed-click-history', $data));
}
}
......
......@@ -58,7 +58,7 @@ class Feed extends Common
/**
* @return mixed
*/
public function getClientid()
public function getClientid(): int
{
return $this->clientid;
}
......
......@@ -67,6 +67,7 @@ class Statistics
//return $dataRequest;
//$stats = $this->apiRequest($dataRequest);
//return $stats;
try {
$stats = $this->apiRequest($dataRequest);
} catch (\Exception $e) {
......@@ -240,6 +241,7 @@ class Statistics
if ($report_type == 'transaction') {
foreach ($stats['data'] as $item) {
$dataStats['period'][] = $item['ForeignID'];
$dataStats['ViewID'][] = [$item['FeedID'], $item['ViewID']];
$dataStats['Timestamp'][] = $item['Timestamp'];
$dataStats['OrderSum'][] = $item['OrderSum'];
$dataStats['Basket'][] = $item['Basket'];
......@@ -251,27 +253,39 @@ class Statistics
}
// Данные по статистике по клику
public function getViewIdStatData($feed_id_list, $view_id)
public function getViewIdStatData($feed_id, $view_id)
{
$dataRequest = array(
'method' => "viewid",
'method' => 'feed_click_history',
'data' => array(
'filters' => array(
'FeedID' => array('values' => $feed_id_list),
'ViewID' => $view_id,
),
'feed_id' => (int) $feed_id,
'view_id' => $view_id
//'feed_id' => 10004,
//'view_id' => '94ed3f578fa785d3'
)
);
return $dataRequest;
//$stats = $this->apiRequest($dataRequest);
//return $dataRequest;
$stats = $this->apiRequest($dataRequest);
//return $stats;
try {
$stats = $this->apiRequest($dataRequest);
} catch (\Exception $e) {
$stats['status'] = 'Error';
}
//return $stats;
$stats = [$feed_id_list, $view_id];
// В запросе ошибка или отсутствуют данные для статистики:
if ($stats['status'] == 'Error') {
return $stats;
}
if ($stats['data'] == []) {
return null;
}
$stats = $stats['data'];
return $stats;
}
......
......@@ -58,12 +58,18 @@ $error = $this->error;
if (!$error) {
$periodStats = $this->periodStats;
$current_period = $this->current_period;
$dates = $this->dates;
$periods_list = $this->periods_list;
$viewIdStats = $this->viewIdStats;
$cats = array(
'StartTime' => 'StartTime',
'EndTime' => 'EndTime',
'IP' => 'IP',
'Basket' => 'Basket',
'Pages' => 'Pages',
//'TransactionID' => 'TransactionID',
'ForeignID' => 'ForeignID',
'OrderSum' => 'OrderSum',
);
//$data_request_link = $this->url('user.cabinet', ['lang' => $this->lang, 'report' => $current_report]);
}
......@@ -80,35 +86,16 @@ if (!$error) {
<?php else: ?>
<textarea id="period-stats"><?= ($viewIdStats ? json_encode($viewIdStats, JSON_UNESCAPED_UNICODE) : '')?></textarea>
<?php /* ?>
<textarea id="viewid-stats"><?= ($viewIdStats ? json_encode($viewIdStats, JSON_UNESCAPED_UNICODE) : '')?></textarea>
<?php */ ?>
<section class="b-content__work">
<div class="wrapp" style="position: relative;">
<div class="b-feeds-stat_data-loading"></div>
<div class="b-feeds-stat_controls form-group">
<?php /* Выбор дат */ ?>
<span class="b-feeds-stat_controls-period">
<div style="display:inline-block;">Дата: </div>
<input type='text' id="date-value-1" class="btn btn-default date-value" value="<?=$dates[0] ?>"/> &ndash;
<input type='text' id="date-value-2" class="btn btn-default date-value" value="<?=$dates[1] ?>"/>
<span>период: </span>
<select class="form-control stat-period" name="period" data-link="<?=$data_request_link ?>">
<option value="" disabled>--</option>
<?php foreach($periods_list as $period => $title): ?>
<option value="<?=$period ?>" <?php if ($period == $current_period): ?>selected<?php endif; ?>><?=$title ?></option>
<?php endforeach; ?>
</select>
</span>
</div>
<?php print_r($viewIdStats) ?>
<?php //print_r($viewIdStats) ?>
<div class="chart-graph-stat-info">
<h2>По заданным параметрам статистика отсутствует</h2>
......@@ -118,6 +105,68 @@ if (!$error) {
<div class="message"></div>
</div>
<?php /* Таблица */ ?>
<div id="table-stat" class="b-table_wrapp">
<div class="b-content__loading"></div>
<table id="table-line" class="table table-striped admin transaction viewid">
<thead class="metric sortable">
<tr>
<?php foreach($cats as $name => $title): ?>
<th class="<?= $name ?>" data-id="<?= $name ?>">
<?php if ($name == 'Basket'): ?>
<b class="cat not-sorted" id="<?= $name ?>"><?= _t($title)?></b><br />
<b class="basket-link not-sorted">Товар</b> <b class="quantity not-sorted">Кол-во</b> <b class="price not-sorted">Цена</b>
<?php else: ?>
<b class="cat" id="<?= $name ?>"><?= _t($title)?></b>
<?php endif; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach($viewIdStats as $view_id): ?>
<tr>
<?php foreach($cats as $name => $title): ?>
<td class="<?= $name ?>" data-id="<?= $name ?>">
<?php if($name == 'StartTime' || $name == 'EndTime'): ?>
<?php
$date_time = explode(" ", $view_id[$name]);
?>
<span style="white-space: nowrap;">
<b><?= $date_time[1] ?></b>
<span><?= $date_time[0] ?></span>
</span>
<?php elseif($name == 'Basket'): ?>
<div class="b-basket-content">
<a class="view-id-url" href="<?=$view_id['URL'] ?>" target="_blank"><?= $view_id['URL'] ?></a>
<?php if(count($view_id[$name])>0): ?>
<table>
<tbody>
<?php foreach($view_id[$name] as $item): ?>
<tr>
<td><a class="basket-link" href="<?=$item['URL'] ?>" target="_blank"><?=$item['Title'] ?></a></td>
<td><span class="quantity"><?=$item['Quantity'] ?></span></td>
<td><span class="price"><?=$item['Price'] ?></span></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
<?php else: ?>
<span class="cat"><?= $view_id[$name] ?></span>
<?php endif; ?>
</td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
</div>
</section>
......
......@@ -166,7 +166,7 @@ if (!$error) {
<?php endif ?>
<?php /* Таблица */ ?>
<div id="table-stat" class="b-table_wrapp">
<div id="table-stat" class="b-table_wrapp report">
<div class="b-content__loading"></div>
<table id="table-line" class="table table-striped admin <?= $current_report ?>">
<thead class="metric sortable">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment