Example #1
0
 public static function stat($back = 2, $diff = 1)
 {
     if ((int) $back < 1) {
         $back = 1;
     }
     if ((int) $diff < 1) {
         $diff = 1;
     }
     $stat = new self();
     return $stat::select($stat->raw(implode(', ', ['FROM_UNIXTIME(UNIX_TIMESTAMP(min(`time_s`))-`time`) `start`', 'SUM(`time`) `curltime`', '`time` `timef`', 'max(`time_s`)-min(`time_s`)+`time` `usertime`', 'SUM(`size`) `size`', '`searchId` `search`', 'count(`id`) `cnt`'])))->whereRaw('`time_s` between FROM_UNIXTIME(UNIX_TIMESTAMP(NOW())-' . ($back + $diff) * 3600 . ') and FROM_UNIXTIME(UNIX_TIMESTAMP(NOW())-' . ($back * 3600 - 1800) . ')')->groupBy('search')->having($stat->raw('min(`time_s`)'), 'between', $stat->raw('FROM_UNIXTIME(UNIX_TIMESTAMP(NOW())-' . ($back + $diff) * 3600 . ') AND FROM_UNIXTIME(UNIX_TIMESTAMP(NOW())-' . $back * 3600 . ')'))->orderBy('start', 'asc')->get();
 }