public function actionAccess($date = '') { $date = $date ? $date : date("Y-m-d"); $date_now = date("Y-m-d H:i:s"); if (!preg_match("/^\\d{4}-\\d{2}-\\d{2}\$/", $date)) { return $this->echoLog("date{$date} is illegal!!"); } $this->echoLog("stat_access date is {$date}"); $info = StatAccess::findOne(['date' => $date]); if ($info) { $model_stat_access = $info; } else { $model_stat_access = new StatAccess(); $model_stat_access->date = $date; $model_stat_access->created_time = $date_now; } $stat_count = AccessLogs::find()->where(['>=', 'created_time', date("Y-m-d 00:00:00", strtotime($date))])->andWhere(['<=', 'created_time', date("Y-m-d 23:59:59", strtotime($date))])->count(); $model_stat_access->total_number = $stat_count ? $stat_count : 0; $stat_ip_count = AccessLogs::find()->where(['>=', 'created_time', date("Y-m-d 00:00:00", strtotime($date))])->andWhere(['<=', 'created_time', date("Y-m-d 23:59:59", strtotime($date))])->groupBy("ip")->count(); $model_stat_access->total_ip_number = $stat_ip_count ? $stat_ip_count : 0; $stat_uuid = AccessLogs::find()->select(['uuid'])->where(['>=', 'created_time', date("Y-m-d 00:00:00", strtotime($date))])->andWhere(['<=', 'created_time', date("Y-m-d 23:59:59", strtotime($date))])->groupBy("uuid")->asArray()->all(); $model_stat_access->total_uv_number = $stat_uuid ? count($stat_uuid) : 0; if ($stat_uuid) { $stat_returned_user = StatDailyUuid::find()->select(['uuid'])->where(['uuid' => array_column($stat_uuid, 'uuid')])->andWhere(['<', 'date', date("Ymd", strtotime($date))])->groupBy(['uuid'])->all(); $model_stat_access->total_returned_user_number = $stat_returned_user ? count($stat_returned_user) : 0; $model_stat_access->total_new_user_number = $model_stat_access->total_uv_number - $model_stat_access->total_returned_user_number; } if ($model_stat_access->total_number && $model_stat_access->total_uv_number) { $model_stat_access->avg_pv_per_uv = sprintf("%.2f", $model_stat_access->total_number / $model_stat_access->total_uv_number); } $model_stat_access->updated_time = $date_now; return $model_stat_access->save(0); }
public function actionAccess() { $date_from = $this->get("date_from", date("Y-m-01")); $date_to = $this->get("date_to", date("Y-m-d")); $source = trim($this->get("source", "")); $uuid = trim($this->get("uuid", "")); $client_os = trim($this->get("client_os", "")); $client_browser = trim($this->get("client_browser", "")); $p = intval($this->get("p", 1)); if (!$p) { $p = 1; } $data = []; $query = AccessLogs::find(); if ($date_from) { $query->andWhere(['>=', 'created_time', $date_from . ' 00:00:00']); } if ($date_from) { $query->andWhere(['<=', 'created_time', $date_to . " 23:59:59"]); } if ($source) { $query->andWhere(['source' => $source]); } if ($uuid) { $query->andWhere(['uuid' => $uuid]); } if ($client_os) { $query->andWhere(['client_os' => $client_os]); } if ($client_browser) { $query->andWhere(['client_browser' => $client_browser]); } $total_count = $query->count(); $offset = ($p - 1) * $this->page_size; $access_list = $query->orderBy("id desc")->offset($offset)->limit($this->page_size)->all(); $page_info = DataHelper::ipagination(["total_count" => $total_count, "page_size" => $this->page_size, "page" => $p, "display" => 10]); if ($access_list) { $idx = 1; foreach ($access_list as $_item_access) { $tmp_referer = urldecode($_item_access['referer']); if (stripos($tmp_referer, "baidu.com") !== false) { $tmp_referer = @iconv("GBK", "UTF-8", $tmp_referer); } $data[] = ['idx' => $idx, 'target_url' => urldecode($_item_access['target_url']), 'referer' => $tmp_referer, 'user_agent' => $_item_access['user_agent'], 'source' => $_item_access['source'], 'uuid' => $_item_access['uuid'], 'ip' => $_item_access['ip'], 'ip_desc' => implode(" ", IPService::find($_item_access['ip'])), 'browser' => $_item_access['client_browser'] . "/" . $_item_access['client_browser_version'], 'os' => $_item_access['client_os'] . "/" . $_item_access['client_os_version'], 'client_device' => $_item_access['client_device'], 'created_time' => $_item_access['created_time']]; $idx++; } } $search_conditions = ['date_from' => $date_from, 'date_to' => $date_to, 'source' => $source, 'uuid' => $uuid, 'client_os' => $client_os, 'client_browser' => $client_browser]; return $this->render("access", ["data" => $data, "page_info" => $page_info, 'search_conditions' => $search_conditions]); }
public function actionTest() { $flag = false; if ($flag) { $list = AccessLogs::find()->orderBy(['id' => SORT_ASC])->all(); foreach ($list as $_item) { $tmp_browser = new Browser($_item['user_agent']); $tmp_os = new Os($_item['user_agent']); $tmp_device = new Device($_item['user_agent']); $_item->client_browser = $tmp_browser->getName(); $_item->client_browser_version = $tmp_browser->getVersion(); $_item->client_os = $tmp_os->getName(); $_item->client_os_version = $tmp_os->getVersion(); $_item->client_device = $tmp_device->getName(); $_item->update(0); } } $start = '2015-12-18'; $end = date("Y-m-d", strtotime("+1 days")); for ($tmp_date = $start; $tmp_date < $end; $tmp_date = date("Y-m-d", strtotime($tmp_date) + 86400)) { $this->actionDevice($tmp_date); } }
public function actionAdd() { $referer = trim($this->get("referer", "")); $screen = trim($this->get("screen", "")); $target_url = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : ""; if ($target_url) { $blog_id = 0; preg_match("/\\/default\\/(\\d+)(.html)?/", $target_url, $matches); if ($matches && count($matches) >= 2) { $blog_id = $matches[1]; } $tmp_source = 'direct'; if ($referer) { $tmp_source = parse_url($referer, PHP_URL_HOST); if (stripos($tmp_source, "www.google.") !== false) { $tmp_source = "www.google.com"; } } $uuid = $this->getUUID(); $uuid = ltrim($uuid, "{"); $uuid = rtrim($uuid, "}"); $model_ac_log = new AccessLogs(); $model_ac_log->referer = $referer; $model_ac_log->target_url = $target_url; $model_ac_log->blog_id = $blog_id; $model_ac_log->source = $tmp_source ? $tmp_source : ''; $model_ac_log->user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : ""; if ($model_ac_log->user_agent) { $tmp_browser = new Browser($model_ac_log->user_agent); $tmp_os = new Os($model_ac_log->user_agent); $tmp_device = new Device($model_ac_log->user_agent); $model_ac_log->client_browser = $tmp_browser->getName() ? $tmp_browser->getName() : ''; $model_ac_log->client_browser_version = $tmp_browser->getVersion() ? $tmp_browser->getVersion() : ''; $model_ac_log->client_os = $tmp_os->getName() ? $tmp_os->getName() : ''; $model_ac_log->client_os_version = $tmp_os->getVersion() ? $tmp_os->getVersion() : ''; $model_ac_log->client_device = $tmp_device->getName() ? $tmp_device->getName() : ''; if ($model_ac_log->client_device == "unknown" && UtilHelper::isPC()) { $model_ac_log->client_device = "pc"; } } $model_ac_log->ip = UtilHelper::getClientIP(); $model_ac_log->uuid = $uuid; if ($screen) { list($client_width, $client_height) = explode("/", $screen); if ($client_width) { $model_ac_log->client_width = $client_width; } if ($client_height) { $model_ac_log->client_height = $client_height; } } $model_ac_log->created_time_min = date("Y-m-d H:i"); $model_ac_log->created_time = date("Y-m-d H:i:s"); $model_ac_log->save(); /*更新文章阅读量*/ if ($blog_id) { $blog_info = Posts::findOne(['id' => $blog_id]); if ($blog_info) { $blog_info->view_count += 1; $blog_info->update(0); } } } }