statistics.ctrl.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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('statistics');
  8. $dos = array('display', 'get_visit_api');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. permission_check_account_user('statistics_visit_wxapp');
  11. if ($do == 'display') {
  12. miniapp_update_daily_visittrend();
  13. $yesterday = date('Ymd', strtotime('-1 days'));
  14. $yesterday_stat = pdo_get('wxapp_general_analysis', array('uniacid' => $_W['uniacid'], 'type' => '2', 'ref_date' => $yesterday));
  15. if (empty($yesterday_stat)) {
  16. $yesterday_stat = array('session_cnt' => 0, 'visit_pv' => 0, 'visit_uv' => 0, 'visit_uv_new' => 0, 'stay_time_uv' => 0, 'stay_time_session' => 0);
  17. } else {
  18. $yesterday_stat['stay_time_uv'] = intval($yesterday_stat['stay_time_uv']);
  19. $yesterday_stat['stay_time_session'] = intval($yesterday_stat['stay_time_session']);
  20. }
  21. }
  22. if ($do == 'get_visit_api') {
  23. $support_type = array(
  24. 'time' => array('today', 'week', 'month', 'daterange'),
  25. 'divide' => array('session_cnt', 'visit_pv', 'visit_uv', 'visit_uv_new', 'stay_time_uv', 'stay_time_session'),
  26. );
  27. $data = array();
  28. $type = trim($_GPC['time_type']);
  29. $divide_type = trim($_GPC['divide_type']);
  30. if (!in_array($type, $support_type['time']) || !in_array($divide_type, $support_type['divide'])) {
  31. iajax(-1, '参数错误!');
  32. }
  33. $daterange = array();
  34. if (!empty($_GPC['daterange'])) {
  35. $daterange = array(
  36. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  37. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  38. );
  39. }
  40. $params = array('uniacid' => $_W['uniacid']);
  41. switch ($type) {
  42. case 'week':
  43. $params['ref_date >'] = date('Ymd', strtotime('-7 days'));
  44. $params['ref_date <='] = date('Ymd');
  45. break;
  46. case 'month':
  47. $params['ref_date >'] = date('Ymd', strtotime('-30 days'));
  48. $params['ref_date <='] = date('Ymd');
  49. break;
  50. case 'daterange':
  51. if (empty($daterange)) {
  52. $daterange = array('start' => date('Ymd', strtotime('-30 days')), 'end' => date('Ymd'));
  53. }
  54. $params['ref_date >='] = date('Ymd', strtotime($daterange['start']));
  55. $params['ref_date <='] = date('Ymd', strtotime($daterange['end']));
  56. break;
  57. }
  58. $result = pdo_getall('wxapp_general_analysis', $params, array(), 'ref_date');
  59. if ($type == 'week') {
  60. $data_x = stat_date_range(date('Ymd', strtotime('-7 days')), date('Ymd'));
  61. }
  62. if ($type == 'month') {
  63. $data_x = stat_date_range(date('Ymd', strtotime('-30 days')), date('Ymd'));
  64. }
  65. if ($type == 'daterange') {
  66. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  67. }
  68. if (empty($result)) {
  69. foreach ($data_x as $val) {
  70. $data_y[] = 0;
  71. }
  72. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  73. }
  74. $today = date('Ymd');
  75. foreach ($data_x as $key => $date) {
  76. if ($date == $today) {
  77. continue;
  78. }
  79. if (empty($result[$date])) {
  80. $date_visit = miniapp_insert_date_visit_trend($date);
  81. $data_y[$key] = empty($date_visit[$divide_type]) ? 0 : $date_visit[$divide_type];
  82. } else {
  83. $data_y[$key] = $result[$date][$divide_type];
  84. }
  85. }
  86. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  87. }
  88. template('wxapp/statistics');