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

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