StatisticsController.php 2.6 KB
<?php

namespace App\Http\Controllers\Bside;


use App\Http\Logic\Bside\Statistics\StatisticsLogic;
use App\Models\Bside\Statistics\TrafficStatistics;
use Illuminate\Http\JsonResponse;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use Throwable;

/**
 * 流量统计
 * Class StatisticsController
 * @package App\Http\Controllers\Bside
 */
class StatisticsController extends BaseController
{
    public $statisticsLogic;

    public $trafficStatistics;

    public function __construct()
    {
        $this->statisticsLogic   = new StatisticsLogic();
        $this->trafficStatistics = new TrafficStatistics();
    }

    /**
     * 访问来源
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|Throwable
     */
    public function source()
    {
        $type     = $this->trafficStatistics::TYPE_SOURCE;
        $response = $this->statisticsLogic->getStatisticsData($type);
        return $this->success($response);
    }

    /**
     * 地域分布
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|Throwable
     */
    public function distribution()
    {
        $type     = $this->trafficStatistics::TYPE_DISTRIBUTION;
        $response = $this->statisticsLogic->getStatisticsData($type);
        return $this->success($response);
    }

    /**
     * 受访页面
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|Throwable
     */
    public function page()
    {
        $type     = $this->trafficStatistics::TYPE_PAGE;
        $response = $this->statisticsLogic->getStatisticsData($type);
        return $this->success($response);
    }

    /**
     * 访问终端
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|Throwable
     */
    public function terminal()
    {
        $type     = $this->trafficStatistics::TYPE_TERMINAL;
        $response = $this->statisticsLogic->getStatisticsData($type);
        return $this->success($response);
    }

    /**
     * 流量趋势
     * @return JsonResponse
     * @throws ContainerExceptionInterface
     * @throws NotFoundExceptionInterface|Throwable
     */
    public function trend()
    {
        $type             = $this->trafficStatistics::TYPE_TREND;
        $response         = $this->statisticsLogic->getStatisticsData($type);
        $response['days'] = $this->statisticsLogic->getDaysTrend();
        return $this->success($response);
    }


}