doulaozhi6835 2016-08-13 17:26
浏览 31

Laravel 5.1访客计数器不计入正确的访问次数

I have a self-made visitor counter (sort of) I'm using the pragmarx plugin, but getting the data by myself.

So I have a chart, wich looks like this: chart

When I count everything from the day, there is no problem, it returns the correct values. But when I try to get the count of visits of each week, month or year, it returns the totally wrong numbers.

This is how I get my chart:

public function getVisitors()
    {
        $begin = Carbon::now()->startOfMonth();
        $end = Carbon::now()->endOfMonth();

        $stats = DB::table('tracker_sessions')
            ->whereRaw("created_at between '$begin' and '$end'")
            ->where('is_robot', '=', 0)
            ->groupBy(DB::raw('DATE_FORMAT(created_at,"%d-%m-%Y")'))
            ->orderBy(DB::raw('DATE_FORMAT(created_at,"%d-%m-%Y")'))
            ->get([
            DB::raw('DATE_FORMAT(created_at,"%d-%m-%Y") as y'),
            DB::raw('COUNT(DISTINCT client_ip) as b')
          ]
        );

          return $stats;
    }

And this is how I get everything by week:

public static function getVisitorsThisWeek()
    {
        $begin = Carbon::now()->startOfWeek();
        $end = Carbon::now()->endOfWeek();

        $stats = DB::table('tracker_sessions')
            ->whereRaw("created_at between '$begin' and '$end'")
            ->where('is_robot', '=', 0)
            ->count(DB::raw('DISTINCT client_ip'));

        return $stats;
    }

I'm doing the same for the month and the year, except then I change the Carbon::now()->startOfWeek(); to the Year or Month type of Carbon.

I really don't know what I'm doing wrong right now? I already tried to add the groupBy and orderBy, or switch them and so on, but noting seems to work. Hopefully someone can help me out with this.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题