site.ctrl.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. $support_type = array(
  12. 'time' => array('today', 'week', 'month', 'daterange'),
  13. );
  14. if ($do == 'current_account') {
  15. $today = stat_visit_all_bydate('today');
  16. $today = !empty($today) ? current($today) : 0;
  17. $yesterday = stat_visit_all_bydate('yesterday');
  18. $yesterday = !empty($yesterday) ? current($yesterday) : 0;
  19. template('statistics/site-current-account');
  20. }
  21. if ($do == 'get_account_api') {
  22. $data = array();
  23. $time_type = trim($_GPC['time_type']);
  24. if (!in_array($time_type, $support_type['time'])) {
  25. iajax(-1, '参数错误!');
  26. }
  27. $daterange = array();
  28. if (!empty($_GPC['daterange'])) {
  29. $daterange = array(
  30. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  31. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  32. );
  33. }
  34. $result = stat_visit_all_bydate($time_type, $daterange);
  35. if ($time_type == 'today') {
  36. $data_x = array(date('Ymd'));
  37. }
  38. if ($time_type == 'week') {
  39. $data_x = stat_date_range(date('Ymd', strtotime('-7 days')), date('Ymd'));
  40. }
  41. if ($time_type == 'month') {
  42. $data_x = stat_date_range(date('Ymd', strtotime('-30 days')), date('Ymd'));
  43. }
  44. if ($time_type == 'daterange') {
  45. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  46. }
  47. if (empty($result)) {
  48. foreach ($data_x as $val) {
  49. $data_y[] = 0;
  50. }
  51. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  52. }
  53. foreach ($data_x as $key => $data) {
  54. foreach ($result as $date => $val) {
  55. if (strtotime($date) != strtotime($data)) {
  56. continue;
  57. }
  58. $data_y[$key] = $val;
  59. }
  60. if (empty($data_y[$key])) {
  61. $data_y[$key] = 0;
  62. }
  63. }
  64. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  65. }