人人商城

account.ctrl.php 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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', 'app_display', 'get_account_api', 'get_account_app_api');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. $support_type = array(
  11. 'time' => array('week', 'month', 'daterange'),
  12. 'divide' => array('bysum', 'byavg', 'byhighest'),
  13. );
  14. if ($do == 'display') {
  15. $today = stat_visit_all_bydate('today', array(), true);
  16. $today = !empty($today) ? current($today) : 0;
  17. $yesterday = stat_visit_all_bydate('yesterday', array(), true);
  18. $yesterday = !empty($yesterday) ? current($yesterday) : 0;
  19. template('statistics/account');
  20. }
  21. if ($do == 'app_display') {
  22. $today = stat_visit_app_byuniacid('today', '', array(), true);
  23. $yesterday = stat_visit_app_byuniacid('yesterday', '', array(), true);
  24. $today_module_api = stat_all_visit_statistics('all_account', $today);
  25. $yesterday_module_api = stat_all_visit_statistics('all_account', $yesterday);
  26. template('statistics/app-account');
  27. }
  28. if ($do == 'get_account_api') {
  29. $data = array();
  30. $type = trim($_GPC['time_type']);
  31. if (!in_array($type, $support_type['time'])) {
  32. iajax(-1, '参数错误!');
  33. }
  34. $daterange = array();
  35. if (!empty($_GPC['daterange'])) {
  36. $daterange = array(
  37. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  38. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  39. );
  40. }
  41. $result = stat_visit_all_bydate($type, $daterange, true);
  42. if ($type == 'today') {
  43. $data_x = array(date('Ymd'));
  44. }
  45. if ($type == 'week') {
  46. $data_x = stat_date_range(date('Ymd', strtotime('-6 days')), date('Ymd'));
  47. }
  48. if ($type == 'month') {
  49. $data_x = stat_date_range(date('Ymd', strtotime('-29 days')), date('Ymd'));
  50. }
  51. if ($type == 'daterange') {
  52. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  53. }
  54. if (empty($result)) {
  55. foreach ($data_x as $val) {
  56. $data_y[] = 0;
  57. }
  58. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  59. }
  60. foreach ($data_x as $key => $data) {
  61. foreach ($result as $date_key => $val) {
  62. if (strtotime($date_key) != strtotime($data)) {
  63. continue;
  64. }
  65. $data_y[$key] = $val;
  66. }
  67. if (empty($data_y[$key])) {
  68. $data_y[$key] = 0;
  69. }
  70. }
  71. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  72. }
  73. if ($do == 'get_account_app_api') {
  74. $accounts = array();
  75. $data = array();
  76. $account_table = table('account');
  77. $account_table->searchWithType(array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH));
  78. $account_table->accountRankOrder();
  79. $account_list = $account_table->searchAccountList();
  80. foreach ($account_list as $key => $account) {
  81. $account_list[$key] = uni_fetch($account['uniacid']);
  82. $accounts[] = mb_substr($account_list[$key]['name'], 0, 5, 'utf-8');
  83. }
  84. $type = trim($_GPC['time_type']);
  85. $divide_type = trim($_GPC['divide_type']);
  86. if (!in_array($type, $support_type['time']) || !in_array($divide_type, $support_type['divide'])) {
  87. iajax(-1, '参数错误!');
  88. }
  89. $daterange = array();
  90. if (!empty($_GPC['daterange'])) {
  91. $daterange = array(
  92. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  93. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  94. );
  95. }
  96. $result = stat_visit_app_bydate($type, '', $daterange, true);
  97. if (empty($result)) {
  98. if ($type == 'today') {
  99. $data_x = date('Ymd');
  100. }
  101. if ($type == 'week') {
  102. $data_x = stat_date_range(date('Ymd', strtotime('-7 days')), date('Ymd'));
  103. }
  104. if ($type == 'month') {
  105. $data_x = stat_date_range(date('Ymd', strtotime('-30 days')), date('Ymd'));
  106. }
  107. if ($type == 'daterange') {
  108. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  109. }
  110. foreach ($data_x as $val) {
  111. $data_y[] = 0;
  112. }
  113. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  114. }
  115. foreach ($result as $val) {
  116. $data_x[] = $val['date'];
  117. if ($divide_type == 'bysum') {
  118. $data_y[] = $val['count'];
  119. } elseif ($divide_type == 'byavg') {
  120. $data_y[] = $val['avg'];
  121. } elseif ($divide_type == 'byhighest') {
  122. $data_y[] = $val['highest'];
  123. }
  124. }
  125. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  126. }