public function actionOs($date = '') { $date = $date ? $date : date("Y-m-d"); if (!preg_match("/^\\d{4}-\\d{2}-\\d{2}\$/", $date)) { return $this->echoLog("param date format error,2016-04-28"); } $time_from = date("Y-m-d 00:00:00", strtotime($date)); $time_to = date("Y-m-d 23:59:59", strtotime($date)); $list = AccessLogs::find()->select(['client_os', 'COUNT(*) as total_number'])->where(['>=', 'created_time', $time_from])->andWhere(['<=', 'created_time', $time_to])->groupBy("client_os")->asArray()->all(); if (!$list) { return $this->echoLog('no data to handle~~'); } $date_int = date("Ymd", strtotime($date)); $date_now = date("Y-m-d H:i:s"); foreach ($list as $_item) { $tmp_client_os = $_item['client_os']; if (!$tmp_client_os) { continue; } $tmp_total_number = $_item['total_number']; $tmp_info = StatDailyOs::find()->where(['date' => $date_int, 'client_os' => $tmp_client_os])->one(); if ($tmp_info) { $tmp_model_info = $tmp_info; } else { $tmp_model_info = new StatDailyOs(); $tmp_model_info->date = $date_int; $tmp_model_info->client_os = $tmp_client_os; $tmp_model_info->created_time = $date_now; } $tmp_model_info->total_number = $tmp_total_number; $tmp_model_info->updated_time = $date_now; $tmp_model_info->save(0); } return $this->echoLog("it's over~~"); }
public function actionOs() { $date_from = $this->get("date_from", date("Y-m-d")); $date_to = $this->get("date_to", date("Y-m-d")); $p = intval($this->get("p", 1)); if (!$p) { $p = 1; } $query = StatDailyOs::find(); if ($date_from) { $query->andWhere(['>=', 'date', date("Ymd", strtotime($date_from))]); } if ($date_from) { $query->andWhere(['<=', 'date', date("Ymd", strtotime($date_to))]); } $total_count = $query->count(); $offset = ($p - 1) * $this->page_size; $list = $query->orderBy(['id' => SORT_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]); $data = []; if ($list) { $idx = 1; foreach ($list as $_item) { $data[] = ['idx' => $idx, 'date' => $_item['date'], 'client_os' => $_item['client_os'], 'total_number' => $_item['total_number']]; $idx++; } } $search_conditions = ['date_from' => $date_from, 'date_to' => $date_to]; return $this->render("os", ["data" => $data, "page_info" => $page_info, 'search_conditions' => $search_conditions]); }
public function actionIndex() { $data = ["posts" => [], "library" => [], 'summary' => []]; $total_posts = Posts::find()->count(); $total_valid_posts = Posts::find()->where(['status' => 1])->count(); $data['posts'] = ["total" => $total_posts, "total_valid" => $total_valid_posts]; $total_book = Book::find()->count(); $total_valid_book = Book::find()->where(['status' => 1])->count(); $data['library'] = ["total" => $total_book, "total_valid" => $total_valid_book]; /*画图*/ $date_from = date("Y-m-d", strtotime("-30 day")); $date_to = date("Y-m-d"); $stat_access_list = StatAccess::find()->where(['>=', "date", $date_from])->andWhere(['<=', "date", $date_to])->orderBy("date asc")->asArray()->all(); $data_access = ["categories" => [], "series" => [['name' => 'PV', 'data' => []], ['name' => 'UV', 'data' => []], ['name' => 'IP', 'data' => []]]]; if ($stat_access_list) { foreach ($stat_access_list as $_item) { $data_access['categories'][] = $_item['date']; $data_access['series'][0]['data'][] = intval($_item['total_number']); $data_access['series'][1]['data'][] = intval($_item['total_uv_number']); $data_access['series'][2]['data'][] = intval($_item['total_ip_number']); if ($_item['date'] >= date("Y-m-d", strtotime("-7 days"))) { $data['summary'][] = ['date' => $_item['date'], 'total_number' => $_item['total_number'], 'total_ip_number' => $_item['total_ip_number'], 'total_uv_number' => $_item['total_uv_number'], 'total_new_user_number' => $_item['total_new_user_number'], 'total_returned_user_number' => $_item['total_returned_user_number'], 'avg_pv_per_uv' => $_item['avg_pv_per_uv']]; } } $data['summary'] = array_reverse($data['summary']); } $stat_blog_list = StatBlog::find()->where(['>=', "date", $date_from])->andWhere(['<=', "date", $date_to])->orderBy("date asc")->asArray()->all(); $data_blog = ["categories" => [], "series" => [['name' => '已发布', 'data' => []], ['name' => '待发布', 'data' => []]]]; if ($stat_blog_list) { foreach ($stat_blog_list as $_item) { $data_blog['categories'][] = $_item['date']; $data_blog['series'][0]['data'][] = intval($_item['total_post_number']); $data_blog['series'][1]['data'][] = intval($_item['total_unpost_number']); } } $date_int = date("Ymd"); /*今日来源域名*/ $ignore_source = ["direct", "www.vincentguo.cn", "m.vincentguo.cn"]; $data_source = ['series' => [['data' => []]]]; $source_list = StatDailyAccessSource::find()->where(['date' => $date_int])->andWhere(['not in', 'source', $ignore_source])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($source_list) { $total_number = array_sum(array_column($source_list, "total_number")); foreach ($source_list as $_item) { $data_source['series'][0]['data'][] = ['name' => $_item['source'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } /*操作系统*/ $data_client_os = ['series' => [['data' => []]]]; $os_list = StatDailyOs::find()->where(['date' => $date_int])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($os_list) { $total_number = array_sum(array_column($os_list, "total_number")); foreach ($os_list as $_item) { $data_client_os['series'][0]['data'][] = ['name' => $_item['client_os'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } /*浏览器统计*/ $data_client_browser = ['series' => [['data' => []]]]; $client_browser_list = StatDailyBrowser::find()->where(['date' => $date_int])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($client_browser_list) { $total_number = array_sum(array_column($client_browser_list, "total_number")); foreach ($client_browser_list as $_item) { $data_client_browser['series'][0]['data'][] = ['name' => $_item['client_browser'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } /*设备统计*/ $data_client_device = ['series' => [['data' => []]]]; $client_device_list = StatDailyDevice::find()->where(['date' => $date_int])->orderBy(['total_number' => SORT_DESC])->asArray()->all(); if ($client_device_list) { $total_number = array_sum(array_column($client_device_list, "total_number")); foreach ($client_device_list as $_item) { $data_client_device['series'][0]['data'][] = ['name' => $_item['client_device'], 'y' => floatval(sprintf("%.2f", $_item['total_number'] / $total_number * 100)), 'total_number' => $_item['total_number']]; } } //环境变量 // $db_target = Yii::$app->get("blog"); // $db_target->createCommand("SELECT version() as version,user() as user")->queryOne(); $env = ['sys' => ['服务器' => $_SERVER["SERVER_SOFTWARE"], 'PHP版本' => PHP_VERSION, '操作系统' => php_uname(), '端口' => $_SERVER['SERVER_PORT'], '上传限制' => ini_get("file_uploads") ? ini_get("upload_max_filesize") : "Disabled"]]; return $this->render("index", ["stat" => $data, "data_access" => $data_access, "data_blog" => $data_blog, "data_client_os" => $data_client_os, 'data_source' => $data_source, 'data_client_browser' => $data_client_browser, 'data_client_device' => $data_client_device, 'env' => $env]); }