123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- /**
- * [WeEngine System] Copyright (c) 2014 WE7.CC
- * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
- */
- defined('IN_IA') or exit('Access Denied');
- function stat_visit_info($type, $time_type, $module = '', $daterange = array(), $is_system_stat = false) {
- global $_W;
- $result = array();
- if (empty($type) || empty($time_type) || !empty($type) && !in_array($type, array('web', 'app', 'api', 'all'))) {
- return $result;
- }
- $stat_visit_table = table('stat_visit');
- if ($type != 'all') {
- $stat_visit_table->searchWithType($type);
- }
- if (empty($is_system_stat)) {
- $stat_visit_table->searchWithUnacid($_W['uniacid']);
- }
- if (!empty($module)) {
- $stat_visit_table->searchWithModule($module);
- }
- switch ($time_type) {
- case 'today':
- $stat_visit_table->searchWithDate(date('Ymd'));
- break;
- case 'yesterday':
- $stat_visit_table->searchWithDate(date('Ymd', strtotime('-1 days')));
- break;
- case 'week':
- $stat_visit_table->searchWithGreaterThenDate(date('Ymd', strtotime('-6 days')));
- $stat_visit_table->searchWithLessThenDate(date('Ymd'));
- break;
- case 'month':
- $stat_visit_table->searchWithGreaterThenDate(date('Ymd', strtotime('-29 days')));
- $stat_visit_table->searchWithLessThenDate(date('Ymd'));
- break;
- case 'daterange':
- if (empty($daterange)) {
- return stat_visit_info($type, 'month', $module, array(), $is_system_stat);
- }
- $stat_visit_table->searchWithGreaterThenDate(date('Ymd', strtotime($daterange['start'])));
- $stat_visit_table->searchWithLessThenDate(date('Ymd', strtotime($daterange['end'])));
- break;
- }
- $visit_info = $stat_visit_table->getall();
- if (!empty($visit_info)) {
- $result = $visit_info;
- }
- return $result;
- }
- function stat_visit_app_byuniacid($time_type, $module = '', $daterange = array(), $is_system_stat = false) {
- $result = array();
- $visit_info = stat_visit_info('app', $time_type, $module, $daterange, $is_system_stat);
- if (empty($visit_info)) {
- return $result;
- }
- foreach ($visit_info as $info) {
- if ($is_system_stat) {
- if (empty($info['uniacid'])) {
- continue;
- }
- if ($result[$info['uniacid']]['uniacid'] == $info['uniacid']) {
- $result[$info['uniacid']]['count'] += $info['count'];
- $result[$info['uniacid']]['highest'] = $result[$info['uniacid']]['highest'] >= $info['count'] ? $result[$info['uniacid']]['highest'] : $info['count'];
- } else {
- $result[$info['uniacid']] = $info;
- $result[$info['uniacid']]['highest'] = $info['count'];
- }
- } else {
- if (empty($info['module'])) {
- continue;
- }
- if ($result[$info['module']]['module'] == $info['module']) {
- $result[$info['module']]['count'] += $info['count'];
- $result[$info['module']]['highest'] = $result[$info['module']]['highest'] >= $info['count'] ? $result[$info['module']]['highest'] : $info['count'];
- } else {
- $result[$info['module']] = $info;
- $result[$info['module']]['highest'] = $info['count'];
- }
- }
- }
- $modules = stat_modules_except_system();
- $count = count($modules);
- foreach ($result as $key => $val) {
- $result[$key]['avg'] = round($val['count'] / $count);
- }
- return $result;
- }
- function stat_visit_app_bydate($time_type, $module = '', $daterange = array(), $is_system_stat = false) {
- $result = array();
- $visit_info = stat_visit_info('app', $time_type, $module, $daterange, $is_system_stat);
- if (empty($visit_info)) {
- return $result;
- }
- $count = stat_account_count();
- foreach ($visit_info as $info) {
- if (empty($info['uniacid']) || empty($info['date'])) {
- continue;
- }
- if ($result[$info['date']]['date'] == $info['date']) {
- $result[$info['date']]['count'] += $info['count'];
- $result[$info['date']]['highest'] = $result[$info['date']]['highest'] >= $info['count'] ? $result[$info['date']]['highest'] : $info['count'];
- } else {
- unset($info['module'], $info['uniacid']);
- $result[$info['date']] = $info;
- $result[$info['date']]['highest'] = $info['count'];
- }
- }
- if (empty($result)) {
- return $result;
- }
- foreach ($result as $key => $val) {
- $result[$key]['avg'] = round($val['count'] / $count);
- }
- return $result;
- }
- function stat_visit_all_bydate($time_type, $daterange = array(), $is_system_stat = false) {
- $result = array();
- $visit_info = stat_visit_info('all', $time_type, '', $daterange, $is_system_stat);
- if (empty($visit_info)) {
- return $result;
- } else {
- foreach ($visit_info as $visit) {
- $result['count'][$visit['date']] += $visit['count'];
- $result['ip_count'][$visit['date']] += $visit['ip_count'];
- }
- }
- return $result;
- }
- function stat_visit_web_bydate($time_type, $daterange = array(), $is_system_stat = false) {
- $result = array();
- $visit_info = stat_visit_info('web', $time_type, '', $daterange, $is_system_stat);
- if (empty($visit_info)) {
- return $result;
- } else {
- foreach ($visit_info as $visit) {
- $result['count'][$visit['date']] += $visit['count'];
- $result['ip_count'][$visit['date']] += $visit['ip_count'];
- }
- }
- return $result;
- }
- function stat_all_visit_statistics($type, $data) {
- if ($type == 'current_account') {
- $modules = stat_modules_except_system();
- $count = count($modules);
- } elseif ($type == 'all_account') {
- $count = stat_account_count();
- }
- $result = array(
- 'visit_sum' => 0,
- 'visit_highest' => 0,
- 'visit_avg' => 0
- );
- if (empty($data)) {
- return $result;
- }
- foreach ($data as $val) {
- $result['visit_sum'] += $val['count'];
- if ($result['visit_highest'] < $val['count']) {
- $result['visit_highest'] = $val['count'];
- }
- }
- $result['visit_avg'] = round($result['visit_sum'] / $count);
- return $result;
- }
- function stat_modules_except_system() {
- $modules = uni_modules();
- if (!empty($modules)) {
- foreach ($modules as $key => $module) {
- if (!empty($module['issystem'])) {
- unset($modules[$key]);
- }
- }
- }
- return $modules;
- }
- function stat_account_count() {
- $count = 0;
- $account_table = table('account');
- $account_table->searchWithType(array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH));
- $account_table->accountRankOrder();
- $account_list = $account_table->searchAccountList();
- $count = count($account_list);
- return $count;
- }
- function stat_date_range($start, $end) {
- $result = array();
- if (empty($start) || empty($end)) {
- return $result;
- }
- $start = strtotime($start);
- $end = strtotime($end);
- $i = 0;
- while(strtotime(end($result)) < $end) {
- $result[] = date('Ymd', $start + $i * 86400);
- $i++;
- }
- return $result;
- }
|