Обработка ajax- запроса для данных feed-статистики, обработка post-action

parent b6363793
This diff is collapsed.
<?php
return [
'offer_conf' => [
'lang' => array(
'RU' => 'Русский',
),
'raiting' => ['A', 'B', 'C', 'D'],
'landing_geo' => array(
'UA' => 'Украина',
'RU' => 'Россия',
'BY' => 'Беларусь',
'KZ' => 'Казахстан',
)
],
'cpa_stat_conf' => [
'periods' => array(
'total' => 'всего',
'today' => 'сегодня',
'yesterday' => 'вчера',
'24h' => 'сутки',
'7d' => '7 дней',
'30d' => '30 дней',
),
]
];
<?php
return [
'metrics' => [
// DateStat
'pagestat' => array(
'title' => 'страницам',
'type' => 'pages',
'fields_to_show' => array(
'loadCnt' => 'load',
'startCnt' => 'start',
'runCnt' => 'run',
'runRatio' => 'runRatio', // runCnt/loadCnt * 100, в %
),
'fields' => ['loadCnt', 'startCnt', 'runCnt'],
'filters' => ['SiteID', 'Country'],
),
'minstat' => array(
'title' => 'зонам RTB',
'type' => 'zones',
'fields_to_show' => array(
'sspViewsCnt' => 'Показы',
'sspClicksCnt' => 'Клики',
'ctr' => 'CTR', // sspClicksCnt/sspViewsCnt * 100, в %
'sspMoney' => 'Деньги',
'cpm' => 'CPM', // sspMoney/sspViewsCnt * 1000
'siteCpm' => 'SiteCPM', // sspSiteMoney/sspViewsCnt * 1000
'systemCpm' => 'SystemCPM', // (sspMoney - sspSiteMoney)/sspViewsCnt * 1000
'cpc' => 'CPC', // sspMoney/sspClicksCnt * 100
'siteCpc' => 'SiteCPC', // sspSiteMoney/sspClicksCnt * 100
'systemCpc' => 'SystemCPC', // (sspMoney - sspSiteMoney)/sspClicksCnt * 100
'sumRatio' => 'SumRatio', // sspMoney/sspMoney * 100, в %
'siteRatio' => 'SiteRatio', // sspSiteMoney/sspMoney * 100, в %
'systemRatio' => 'SystemRatio', // sspSiteMoney/(sspMoney - sspSiteMoney) * 100, в %
'sspSiteMoney' => 'Деньги сайта',
'sspSystemMoney' => 'Деньги системы', // sspMoney - sspSiteMoney
),
'fields' => ['sspViewsCnt', 'sspClicksCnt', 'sspMoney', 'sspSiteMoney'],
'filters' => ['SiteID', 'Country', 'ZoneID'],
),
'blockstat' => array(
'title' => 'блокам',
'type' => 'zones',
'fields_to_show' => array(
'blockViewsCnt' => 'Показы блоков',
'blockClicksCnt' => 'Клики по блокам',
'sspViewsCnt' => 'Показы rtb',
'sspClicksCnt' => 'Клики rtb',
//'sum' => 'Сумма', // blockViewsCnt+sspViewsCnt
//'ctr' => 'CTR', // blockClicksCnt/blockViewsCnt * 100, в %
'sumViews' => 'Сумма показов', // blockViewsCnt+sspViewsCnt
'sumClicks' => 'Сумма кликов', // blockClicksCnt+sspClicksCnt
'ctr' => 'CTR', // blockClicksCnt/blockViewsCnt * 100, в %
'ctrRtb' => 'CTR rtb', // sspClicksCnt/sspViewsCnt * 100, в %
),
'fields' => ['blockViewsCnt', 'blockClicksCnt', 'sspViewsCnt', 'sspClicksCnt'],
'filters' => ['SiteID', 'Country', 'ZoneID'],
),
'ndspstat' => array(
'title' => 'провайдерам ndsp',
'type' => 'ndsp',
'fields_to_show' => array(
'adViewsCnt' => 'Показы',
'adClicksCnt' => 'Клики',
'adMoney' => 'Деньги',
'ctr' => 'CTR', // adClicksCnt/adViewsCnt * 100, в %
'cpm' => 'CPM', // adMoney/adViewsCnt * 1000
'cpc' => 'CPC', // adMoney/adClicksCnt * 100
),
'fields' => ['ndspProvider', 'adViewsCnt', 'adClicksCnt', 'adMoney'],
'filters' => ['SiteID', 'Country', 'ZoneID'],
),
// ProviderStat
'bidstat' => array(
'title' => 'ставкам SSP',
'type' => 'bids',
'fields_to_show' => array(
'bidCnt' => 'Кол-во ставок',
'bidMoney' => 'Деньги',
'cpm' => 'CPM', // bidMoney/bidCnt * 1000
),
'fields' => ['sspProvider', 'bidCnt', 'bidMoney'],
'filters' => ['SiteID', 'Country', 'ZoneID'],
),
'winstat' => array(
'title' => 'выиграшам SSP',
'type' => 'zones',
'fields_to_show' => array(
'sspViewsCnt' => 'Показы',
'sspClicksCnt' => 'Клики',
'sspMoney' => 'Деньги',
'ctr' => 'CTR', // sspClicksCnt/sspViewsCnt * 100, в %
'cpm' => 'CPM', // sspMoney/sspViewsCnt * 1000
'cpc' => 'CPC', // sspMoney/sspClicksCnt * 100
),
'fields' => ['sspProvider', 'sspViewsCnt', 'sspClicksCnt', 'sspMoney'],
'filters' => ['SiteID', 'Country', 'ZoneID'],
),
'providersblockstat' => array(
'title' => 'провайдерам блоков',
'type' => 'zones',
'fields_to_show' => array(
'blockViewsCnt' => 'Показы блоков',
'blockClicksCnt' => 'Клики по блокам',
//'sspViewsCnt' => 'Показы rtb',
'sum' => 'Сумма', // blockViewsCnt+sspViewsCnt
'ctr' => 'CTR', // blockClicksCnt/blockViewsCnt * 100, в %
),
'fields' => ['argonProvider', 'blockViewsCnt', 'blockClicksCnt', 'sspViewsCnt', 'sspClicksCnt'],
'filters' => ['SiteID', 'Country', 'ZoneID'],
),
]
];
......@@ -316,12 +316,11 @@ return [
]
],
],
[
'name' => 'user.cabinet',
'path' => '/[:lang/]cabinet/[:report]',
'middleware' => App\Action\User\Cabinet::class,
'allowed_methods' => ['GET'],
'allowed_methods' => ['GET', 'POST'],
'options' => [
'constraints' => [
'lang' => '[a-z]{2,3}',
......@@ -329,6 +328,7 @@ return [
],
'defaults' => [
'lang' => \App\Model\Locales::DEFAULT_LANG,
'action' => App\Action\User\Cabinet::ACTION_STAT,
'report' => 'common',
]
],
......
<?php
return [
'site_categories' => [
'IAB12' => 'Новости',
'IAB2' => 'Авто',
'IAB13' => 'Финансы',
'IAB15-10' => 'Погода',
'IAB-19' => 'HiTech',
'IAB3-1' => 'Объявления',
'IAB17' => 'Спорт',
'IAB29' => 'Торренты',
'IAB1-5' => 'Кино',
'IAB1' => 'Развлекательный',
'IAB1-2' => 'Глянец',
'IAB24' => 'Портал',
'IAB14' => 'Знакомства',
'IAB9-30' => 'Другое',
'IAB5' => 'Образование',
'IAB6' => 'Семья',
'IAB7' => 'Здоровье',
'IAB15' => 'Наука',
'IAB8' => 'Еда и напитки',
'IAB21' => 'Недвижимость',
'IAB1-1' => 'Литература',
'IAB9' => 'Хобби',
'IAB9-23' => 'Фотография',
'IAB16' => 'Животные'
],
'zone_sizes' => [
'300x250',
'300x600',
'728x90',
'300x300',
],
'site_countries' => [
'UA' => 'Украина',
'RU' => 'Россия',
'US' => 'США',
'EU' => 'Европа',
'DE' => 'Германия',
'NL' => 'Нидерланды',
],
];
<?php
return [
'users_segment' => [
'A+' => 'A+',
'A' => 'A',
'B' => 'B',
'C' => 'C',
]
];
......@@ -99,6 +99,17 @@ input[type="checkbox"]
cursor: pointer;
}
.b-feeds-stat_data-loading
{
display: none;
position: absolute;
width: 100%;
height: 100%;
background: #FFF url(../img/gif-load.gif) center 200px no-repeat;
opacity: 0.5;
z-index: 10;
}
.b-feeds-stat_controls
{
margin-bottom: 25px;
......
......@@ -42,12 +42,6 @@ $(document).ready(function(){
return date.getFullYear() +'-'+ pad(date.getMonth()+1) +'-'+ pad(date.getDate());
}
// Форматирование времени
function formatTime(time)
{
return pad(time.getHours()) +':'+ pad(time.getMinutes());
}
function valueFormat(value, ratio, id)
{
var
......
......@@ -8,7 +8,9 @@ $(document).ready(function(){
var
nowDate = new Date(),
isChangePeriod = false,
datepicker1 = $('#date-value-1').datepicker({
$dateFrom = $('#date-value-1'),
$dateTo = $('#date-value-2'),
datepicker1 = $dateFrom.datepicker({
dateFormat: "yyyy-mm-dd",
autoClose: true,
maxDate: nowDate,
......@@ -20,7 +22,7 @@ $(document).ready(function(){
}
},
}).data('datepicker'),
datepicker2 = $('#date-value-2').datepicker({
datepicker2 = $dateTo.datepicker({
dateFormat: "yyyy-mm-dd",
autoClose: true,
maxDate: nowDate,
......@@ -33,9 +35,9 @@ $(document).ready(function(){
}).data('datepicker'),
$chartStat = $('#chart-graph-stat'),
$chartTable = $('#table-stat'),
$loading = $('.b-feeds-stat_data-loading'),
$chartStatInfo = $('.chart-graph-stat-info'),
$chartStatError = $('.chart-graph-stat-error'),
$chartStatLoading = $('.chart-graph-stat-loading'),
$chartStatErrorMessage = $('.chart-graph-stat-error .message'),
periodStatsData,
companyStatsData,
......@@ -167,7 +169,40 @@ $(document).ready(function(){
// Запрос данных за временной период:
function requestDataPeriod()
{
console.log('AAA requestDataPeriod');
var dataRequest = {period: [$dateFrom.val(),$dateTo.val()]};
EnableLoadingState(true);
$.ajax({
url: $periodSelect.attr('data-link'),
method: 'POST',
data: dataRequest,
success: function(res) {
EnableLoadingState(false);
if (res == null) {
console.log("AAA requestDataStat success res: NULL");
$chartStatInfo.show();
$chartStatError.hide();
} else if (res.status == 'Error') {
console.log("AAA requestDataStat error");
$chartStatError.show();
$chartStatInfo.hide();
} else {
//console.log("AAA requestDataStat SUCCESS res: ", res);
$chartStatInfo.hide();
$chartStatError.hide();
periodStatsData = res.period;
companyStatsData = res.company;
dataLineChartStat = periodStatsData;
renderLineChart();
renderHourTable();
}
},
error: function (e) {
console.log('error: ', e);
EnableLoadingState(false);
}
});
}
function setPeriodSelectEmpty()
......@@ -175,4 +210,18 @@ $(document).ready(function(){
$periodSelect.val('');
}
function setPeriodSelectEmpty()
{
$periodSelect.val('');
}
function EnableLoadingState(isLoading)
{
if (isLoading) {
$loading.show();
} else {
$loading.hide();
}
}
});
\ No newline at end of file
......@@ -47,10 +47,7 @@ use Zend\Diactoros\Response\RedirectResponse;
*/
class Cabinet extends Common
{
/**
* @var Mailer
*/
protected $mailer;
const ACTION_STAT = 'stat';
/**
* @param ServerRequestInterface $request
......@@ -60,25 +57,38 @@ class Cabinet extends Common
*/
function __invoke(ServerRequestInterface $request, ResponseInterface $response, callable $next = null)
{
try {
/** @var UserService $auth */
$auth = $this->container->get(UserService::class);
if($request->getMethod() == 'POST') {
try {
switch ($request->getAttribute('action')) {
case self::ACTION_STAT:
$response = $this->getStatData($request);
break;
default:
}
} catch(\Exception $e) {
$data = [
'result' => false,
'msg' => $e->getMessage(),
];
$response = new JsonResponse($data);
}
return $response;
/** @var Statistics $stats */
$stats = $this->container->get(Statistics::class);
} else {
/** @var Users $usersModel */
$usersModel = $this->container->get(Users::class);
try {
/** @var UserService $auth */
$auth = $this->container->get(UserService::class);
$userId = $auth->getIdentity()->getId();
$user = $usersModel->findById($userId);
// Выводим стр. по фидам, если за пользователем закреплен фид:
/** @var \App\Model\Feeds $feedsModel */
$feedsModel = $this->container->get(Feeds::class);
$feeds = $feedsModel->findAll(['clientid' => $userId])->toArray();
// Фиды пользователя:
$feed_id_list = [];
foreach($feeds as $feed_item) {
$feed_id = $feed_item['id'];
......@@ -87,7 +97,6 @@ class Cabinet extends Common
}
}
$report_type = $request->getAttribute('report');
// Текущий месяц:
......@@ -102,7 +111,6 @@ class Cabinet extends Common
$periodStats = $statsDaysModel->getStatsByDate($feed_id_list, $dates);
$companyStats = $statsDaysModel->getStatsByFeeds($feed_id_list, $dates);
$cats = ['shows','clicks','transactions','salemoney','admoney'];
//return new JsonResponse($periodStats);
break;
case 'transaction':
/** @var \App\Model\Feeds $transactionsModel */
......@@ -110,6 +118,7 @@ class Cabinet extends Common
$periodStats = $transactionsModel->getStatsByDate($feed_id_list, $dates);
$companyStats = $transactionsModel->getStatsByFeeds($feed_id_list, $dates);
$cats = ['localmoney','usdollarmoney'];
//return new JsonResponse($periodStats);
break;
default:
$data['error'] = _t('Извините, тип отчета "'. $report_type .'" недоступен');
......@@ -130,8 +139,6 @@ class Cabinet extends Common
$data['companyStats'] = $companyStats;
$data['cats'] = $cats;
/*
$response = new HtmlResponse($this->template->render('app::user/feeds', [
'lang' => $request->getAttribute('layoutInfo')->getLang(),
......@@ -195,5 +202,68 @@ class Cabinet extends Common
]);
return new HtmlResponse($this->template->render('app::user/cabinet-feed', $data));
}
}
private function getStatData(ServerRequestInterface $request)
{
/** @var UserService $auth */
$auth = $this->container->get(UserService::class);
$userId = $auth->getIdentity()->getId();
// Выводим стр. по фидам, если за пользователем закреплен фид:
/** @var \App\Model\Feeds $feedsModel */
$feedsModel = $this->container->get(Feeds::class);
$feeds = $feedsModel->findAll(['clientid' => $userId])->toArray();
// Фиды пользователя:
$feed_id_list = [];
foreach($feeds as $feed_item) {
$feed_id = $feed_item['id'];
if (!in_array($feed_id, $feed_id_list)) {
$feed_id_list[] = $feed_id;
}
}
$report_type = $request->getAttribute('report');
$data_request = $request->getParsedBody();
$dates = $data_request['period'];
switch ($report_type) {
case 'common':
/** @var \App\Model\Feeds $statDaysModel */
$statsDaysModel = $this->container->get(StatsDays::class);
$periodStats = $statsDaysModel->getStatsByDate($feed_id_list, $dates);
$companyStats = $statsDaysModel->getStatsByFeeds($feed_id_list, $dates);
break;
case 'transaction':
/** @var \App\Model\Feeds $transactionsModel */
$transactionsModel = $this->container->get(Transactions::class);
$periodStats = $transactionsModel->getStatsByDate($feed_id_list, $dates);
$companyStats = $transactionsModel->getStatsByFeeds($feed_id_list, $dates);
break;
default:
$periodStats = null;
$companyStats = null;
break;
}
$periodStats['type'] = 'interval';
$periodStats['report'] = $report_type;
$companyStats['type'] = 'interval';
$companyStats['report'] = $report_type;
if ($periodStats || $companyStats) {
$data = array(
'period' => $periodStats,
'company' => $companyStats,
);
} else {
$data = null;
}
return new JsonResponse($data);
}
}
\ No newline at end of file
......@@ -35,7 +35,7 @@ use App\Model\Common;
class Transactions extends Common
{
public function getStatsByFeeds($feeds)
public function getStatsByFeeds($feeds, $dates)
{
$adapter = $this->tableGateway->getAdapter();
......@@ -62,7 +62,7 @@ class Transactions extends Common
return $stats;
}
public function getStatsByDate($feeds)
public function getStatsByDate($feeds, $dates)
{
$adapter = $this->tableGateway->getAdapter();
......
......@@ -80,6 +80,9 @@ $colors_active_lines = array(
'admoney' => '#9467BD',
);
$data_request_link = $this->url('user.cabinet', ['lang' => $this->lang, 'report' => $report]);
?>
......@@ -111,7 +114,9 @@ $colors_active_lines = array(
<textarea id="company-stats"><?= ($companyStats ? json_encode($companyStats) : '')?></textarea>
<section class="b-content__work">
<div class="wrapp">
<div class="wrapp" style="position: relative;">
<div class="b-feeds-stat_data-loading"></div>
<div class="b-feeds-stat_controls form-group">
......@@ -139,7 +144,7 @@ $colors_active_lines = array(
<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">
<select class="form-control stat-period" name="period" data-link="<?=$data_request_link ?>">
<option value="" disabled>--</option>
<?php foreach($periods_conf as $period => $title): ?>
<option value="<?=$period ?>" <?php if ($period == $current_period): ?>selected<?php endif; ?>><?=$title ?></option>
......@@ -159,7 +164,6 @@ $colors_active_lines = array(
<?php /* График */ ?>
<?php if ($report == 'common'): ?>
<div id="chart-graph-stat" style="height: 370px;"></div>
<div class="chart-graph-stat-loading"></div>
<?php endif ?>
<?php /* Таблица */ ?>
......
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