Добавил поле CTR в сводный отчет для магазина

parent ec1e813d
......@@ -28,6 +28,7 @@ return [
'cats' => [
'Views' => 'Показы',
'Clicks' => 'Клики',
'ctr' => 'CTR',
'Orders' => 'Заказы',
'OrderSum' => 'Заказы на сумму',
'AdMoney' => 'Комиссия AddCPM'
......
......@@ -68,20 +68,15 @@ $(document).ready(function(){
isNonFormatValue = notFormatFields.indexOf(currentActiveLine) > -1,
format = d3.format(',.0f');
if (currentActiveLine == 'AdMoney') {
format = d3.format(',.2f');
}
if (currentActiveLine == 'AdMoney') format = d3.format(',.2f');
if (currentActiveLine == 'ctr') format = d3.format(',.2f');
if (isNonFormatValue) {
return value;
}
if (isCurrencyValue) return format(value) + ' грн.';
if (currentActiveLine == 'ctr') return format(value) + ' %';
if (isNonFormatValue) return value;
if (isCurrencyValue) {
return format(value) + ' грн.';
} else {
return format(value);
}
}
function getDateValue(dataDate)
{
......@@ -242,9 +237,21 @@ $(document).ready(function(){
if (!isNotSumValue) {
var totalValue = 0;
if (currentActiveLine == 'ctr') {
var totalViews = 0;
var totalClicks = 0;
for(var i = dataPeriod.length-1; i >= 0; i--) {
totalViews += dataTable['Views'][i];
totalClicks += dataTable['Clicks'][i];
}
totalValue = (totalViews != 0) ? (totalClicks/totalViews*100).toFixed(2) : 0;
} else {
for(var i = dataPeriod.length-1; i >= 0; i--) {
totalValue += dataTable[item][i];
}
}
} else {
totalValue = '';
}
......
......@@ -146,6 +146,11 @@ class Cabinet extends Common
break;
}
// Добавляем спец. категории для сводного отчета по магазину:
if ($report_type == 'common') {
$periodStats = $this->addStatsSpecialCats($periodStats);
}
// Добавляем данные о статусах заказов:
if ($report_type == 'transactions') {
/** @var \App\Model\Feeds $ordersStatusModel */
......@@ -504,6 +509,11 @@ class Cabinet extends Common
return new JsonResponse(null);
}
// Добавляем спец. категории для сводного отчета по магазину:
if ($report_type == 'common') {
$periodStats = $this->addStatsSpecialCats($periodStats);
}
// Добавляем данные о статусах заказов:
if ($report_type == 'transactions') {
/** @var \App\Model\Feeds $ordersStatusModel */
......@@ -588,4 +598,18 @@ class Cabinet extends Common
]);
return $response;
}
// Добавляем категории для сводного отчета по магазину:
private function addStatsSpecialCats($periodStats)
{
$periodStats['ctr'] = [];
foreach($periodStats['period'] as $ind => $period) {
$views_value = $periodStats['Views'][$ind];
$clicks_value = $periodStats['Clicks'][$ind];
$periodStats['ctr'][] = ($views_value != 0) ? round(($clicks_value/$views_value)*100, 2) : 0;
}
return $periodStats;
}
}
\ No newline at end of file
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