fix: refactor visitor statistics calculation and layout
parent
35a9c7f61d
commit
59f9c24ce3
|
|
@ -1 +1,3 @@
|
|||
- Reduced font size of the statistics table in the footer for better alignment.
|
||||
- Refactored visitor statistics calculation logic for better accuracy and performance.
|
||||
- Fixed incorrect aggregation in monthly and yearly statistics.
|
||||
|
|
|
|||
|
|
@ -129,37 +129,54 @@ class AbtComponent
|
|||
|
||||
public function getCounterToday()
|
||||
{
|
||||
$counter = Counter::find()->where(['date_visit' => date('Y-m-d')])->one();
|
||||
return isset($counter) ? $counter->visit : 0;
|
||||
$counter = Counter::find()->where(['date_visit' => date('Y-m-d')])->one();
|
||||
return isset($counter) ? (int)$counter->visit : 0;
|
||||
}
|
||||
|
||||
public function getCounterYesterday()
|
||||
{
|
||||
$counter = Counter::find()->where(['date_visit' => date('Y-m-d', strtotime('Yesterday'))])->one();
|
||||
return isset($counter) ? $counter->visit : 0;
|
||||
$counter = Counter::find()->where(['date_visit' => date('Y-m-d', strtotime('Yesterday'))])->one();
|
||||
return isset($counter) ? (int)$counter->visit : 0;
|
||||
}
|
||||
|
||||
public function getCounterThisMonth()
|
||||
{
|
||||
$counter = Counter::find()->where(['MONTH(date_visit)' => date('m')])->sum('visit');
|
||||
return isset($counter) ? $counter : 0;
|
||||
$firstDay = date('Y-m-01');
|
||||
$lastDay = date('Y-m-t');
|
||||
return (int)Counter::find()
|
||||
->where(['between', 'date_visit', $firstDay, $lastDay])
|
||||
->sum('visit');
|
||||
}
|
||||
|
||||
public function getCounterLastMonth()
|
||||
{
|
||||
$counter = Counter::find()->where(['MONTH(date_visit)' => date('m', strtotime('-1 month'))])->one();
|
||||
return isset($counter) ? $counter->visit : 0;
|
||||
$firstDay = date('Y-m-01', strtotime('-1 month'));
|
||||
$lastDay = date('Y-m-t', strtotime('-1 month'));
|
||||
return (int)Counter::find()
|
||||
->where(['between', 'date_visit', $firstDay, $lastDay])
|
||||
->sum('visit');
|
||||
}
|
||||
|
||||
public function getCounterThisYear()
|
||||
{
|
||||
$counter = Counter::find()->where(['YEAR(date_visit)' => date('Y')])->sum('visit');
|
||||
return isset($counter) ? $counter : 0;
|
||||
$firstDay = date('Y-01-01');
|
||||
$lastDay = date('Y-12-31');
|
||||
return (int)Counter::find()
|
||||
->where(['between', 'date_visit', $firstDay, $lastDay])
|
||||
->sum('visit');
|
||||
}
|
||||
|
||||
public function getCounterLastYear()
|
||||
{
|
||||
$counter = Counter::find()->where(['YEAR(date_visit)' => date('Y', strtotime('-1 year'))])->one();
|
||||
return isset($counter) ? $counter->visit : 0;
|
||||
$firstDay = date('Y-01-01', strtotime('-1 year'));
|
||||
$lastDay = date('Y-12-31', strtotime('-1 year'));
|
||||
return (int)Counter::find()
|
||||
->where(['between', 'date_visit', $firstDay, $lastDay])
|
||||
->sum('visit');
|
||||
}
|
||||
|
||||
public function getCounterTotal()
|
||||
{
|
||||
return (int)Counter::find()->sum('visit');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1132,7 +1132,7 @@ $assets = Yii::$app->assetManager->getPublishedUrl('@frontend/themes/mali/assets
|
|||
</tr>
|
||||
<tr>
|
||||
<td>รวมทั้งหมด</td>
|
||||
<td class="text-right"><?= number_format(Yii::$app->abt->getCounterLastYear(), 0) ?></td>
|
||||
<td class="text-right"><?= number_format(Yii::$app->abt->getCounterTotal(), 0) ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in New Issue