site.ctrl.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * [WeEngine System] Copyright (c) 2014 WE7.CC
  4. * WeEngine is NOT a free software, it under the license terms, visited http://www.we7.cc/ for more details.
  5. */
  6. defined('IN_IA') or exit('Access Denied');
  7. load()->model('module');
  8. load()->model('statistics');
  9. $dos = array('current_account', 'all_account', 'get_account_api');
  10. $do = in_array($do, $dos) ? $do : 'current_account';
  11. permission_check_account_user('statistics_visit_site');
  12. $support_type = array(
  13. 'time' => array('today', 'week', 'month', 'daterange'),
  14. );
  15. if ($do == 'current_account') {
  16. $today = stat_visit_all_bydate('today');
  17. $today = !empty($today) ? current($today['count']) : 0;
  18. $yesterday = stat_visit_all_bydate('yesterday');
  19. $yesterday = !empty($yesterday) ? current($yesterday['count']) : 0;
  20. template('statistics/site-current-account');
  21. }
  22. if ($do == 'get_account_api') {
  23. $data = array();
  24. $time_type = trim($_GPC['time_type']);
  25. if (!in_array($time_type, $support_type['time'])) {
  26. iajax(-1, '参数错误!');
  27. }
  28. $daterange = array();
  29. if (!empty($_GPC['daterange'])) {
  30. $daterange = array(
  31. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  32. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  33. );
  34. }
  35. $result = stat_visit_all_bydate($time_type, $daterange);
  36. if ($time_type == 'today') {
  37. $data_x = array(date('Ymd'));
  38. }
  39. if ($time_type == 'week') {
  40. $data_x = stat_date_range(date('Ymd', strtotime('-7 days')), date('Ymd'));
  41. }
  42. if ($time_type == 'month') {
  43. $data_x = stat_date_range(date('Ymd', strtotime('-30 days')), date('Ymd'));
  44. }
  45. if ($time_type == 'daterange') {
  46. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  47. }
  48. if (empty($result)) {
  49. foreach ($data_x as $val) {
  50. $data_y[] = 0;
  51. }
  52. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  53. }
  54. foreach ($data_x as $key => $data) {
  55. foreach ($result['count'] as $date => $val) {
  56. if (strtotime($date) != strtotime($data)) {
  57. continue;
  58. }
  59. $data_y[$key] = $val;
  60. }
  61. if (empty($data_y[$key])) {
  62. $data_y[$key] = 0;
  63. }
  64. }
  65. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  66. }