account.ctrl.php 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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', 'get_account_visit');
  9. $do = in_array($do, $dos) ? $do : 'display';
  10. $support_type = array(
  11. 'time' => array('today', '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 = $today['count'];
  17. $today = !empty($today) ? current($today) : 0;
  18. $yesterday = stat_visit_all_bydate('yesterday', array(), true);
  19. $yesterday = $yesterday['count'];
  20. $yesterday = !empty($yesterday) ? current($yesterday) : 0;
  21. template('statistics/account');
  22. }
  23. if ($do == 'app_display') {
  24. $today = stat_visit_app_byuniacid('today', '', array(), true);
  25. $yesterday = stat_visit_app_byuniacid('yesterday', '', array(), true);
  26. $today_module_api = stat_all_visit_statistics('all_account', $today);
  27. $yesterday_module_api = stat_all_visit_statistics('all_account', $yesterday);
  28. template('statistics/app-account');
  29. }
  30. if ($do == 'get_account_api') {
  31. $data = array();
  32. $time_type = trim($_GPC['time_type']);
  33. $type = trim($_GPC['type']);
  34. if (!in_array($time_type, $support_type['time'])) {
  35. iajax(-1, '参数错误!');
  36. }
  37. $daterange = array();
  38. if (!empty($_GPC['daterange'])) {
  39. $daterange = array(
  40. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  41. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  42. );
  43. }
  44. if ($type == 'web') {
  45. $all_result = stat_visit_web_bydate($time_type, $daterange, true);
  46. } elseif ($type == 'app') {
  47. $all_result = array();
  48. $visit_info = stat_visit_info('app', $time_type, '', $daterange, true);
  49. if (!empty($visit_info)) {
  50. foreach ($visit_info as $visit) {
  51. $all_result['count'][$visit['date']] += $visit['count'];
  52. $all_result['ip_count'][$visit['date']] += $visit['ip_count'];
  53. }
  54. }
  55. } else {
  56. $all_result = stat_visit_all_bydate($time_type, $daterange, true);
  57. }
  58. $result = $all_result['count'];
  59. $ip_visit_result = $all_result['ip_count'];
  60. if ($time_type == 'today') {
  61. $data_x = array(date('Ymd'));
  62. }
  63. if ($time_type == 'week') {
  64. $data_x = stat_date_range(date('Ymd', strtotime('-6 days')), date('Ymd'));
  65. }
  66. if ($time_type == 'month') {
  67. $data_x = stat_date_range(date('Ymd', strtotime('-29 days')), date('Ymd'));
  68. }
  69. if ($time_type == 'daterange') {
  70. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  71. }
  72. if (empty($result)) {
  73. foreach ($data_x as $val) {
  74. $data_y[] = 0;
  75. }
  76. } else {
  77. foreach ($data_x as $key => $data) {
  78. foreach ($result as $date_key => $val) {
  79. if (strtotime($date_key) != strtotime($data)) {
  80. continue;
  81. }
  82. $data_y[$key] = $val;
  83. }
  84. if (empty($data_y[$key])) {
  85. $data_y[$key] = 0;
  86. }
  87. }
  88. }
  89. if (empty($ip_visit_result)) {
  90. foreach ($data_x as $val) {
  91. $data_y_ip[] = 0;
  92. }
  93. } else {
  94. foreach ($data_x as $key => $data) {
  95. foreach ($ip_visit_result as $ip_date_key => $ip_val) {
  96. if (strtotime($ip_date_key) != strtotime($data)) {
  97. continue;
  98. }
  99. $data_y_ip[$key] = $ip_val;
  100. }
  101. if (empty($data_y_ip[$key])) {
  102. $data_y_ip[$key] = 0;
  103. }
  104. }
  105. }
  106. if (empty($result) && empty($ip_visit_result)) {
  107. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y, 'data_y_ip' => $data_y_ip));
  108. }
  109. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y, 'data_y_ip' => $data_y_ip));
  110. }
  111. if ($do == 'get_account_app_api') {
  112. $accounts = array();
  113. $data = array();
  114. $account_table = table('account');
  115. $account_table->searchWithType(array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH));
  116. $account_table->accountRankOrder();
  117. $account_list = $account_table->searchAccountList();
  118. foreach ($account_list as $key => $account) {
  119. $account_list[$key] = uni_fetch($account['uniacid']);
  120. $accounts[] = mb_substr($account_list[$key]['name'], 0, 5, 'utf-8');
  121. }
  122. $type = trim($_GPC['time_type']);
  123. $divide_type = trim($_GPC['divide_type']);
  124. if (!in_array($type, $support_type['time']) || !in_array($divide_type, $support_type['divide'])) {
  125. iajax(-1, '参数错误!');
  126. }
  127. $daterange = array();
  128. if (!empty($_GPC['daterange'])) {
  129. $daterange = array(
  130. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  131. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  132. );
  133. }
  134. $result = stat_visit_app_bydate($type, '', $daterange, true);
  135. if (empty($result)) {
  136. if ($type == 'today') {
  137. $data_x = date('Ymd');
  138. }
  139. if ($type == 'week') {
  140. $data_x = stat_date_range(date('Ymd', strtotime('-7 days')), date('Ymd'));
  141. }
  142. if ($type == 'month') {
  143. $data_x = stat_date_range(date('Ymd', strtotime('-30 days')), date('Ymd'));
  144. }
  145. if ($type == 'daterange') {
  146. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  147. }
  148. foreach ($data_x as $val) {
  149. $data_y[] = 0;
  150. }
  151. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  152. }
  153. foreach ($result as $val) {
  154. $data_x[] = $val['date'];
  155. if ($divide_type == 'bysum') {
  156. $data_y[] = $val['count'];
  157. } elseif ($divide_type == 'byavg') {
  158. $data_y[] = $val['avg'];
  159. } elseif ($divide_type == 'byhighest') {
  160. $data_y[] = $val['highest'];
  161. }
  162. }
  163. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  164. }
  165. if ($do == 'get_account_visit') {
  166. $page = max(1, intval($_GPC['page']));
  167. $size = max(10, intval($_GPC['size']));
  168. $start_time = date('Ymd', strtotime($_GPC['start_time']));
  169. $end_time = date('Ymd', strtotime($_GPC['end_time']) + 86400);
  170. if (empty($start_time) || empty($end_time)) {
  171. iajax(1, '参数有误');
  172. }
  173. $account_table = table('account');
  174. $accounts = $account_table->searchWithPage($page, $size)->orderby(array('rank' => 'DESC', 'uniacid' => 'DESC'))->getall('uniacid');
  175. if (empty($accounts)) {
  176. iajax(0, array());
  177. }
  178. $total_account = $account_table->getLastQueryTotal();
  179. $tota_visit = 0;
  180. $account_stat = array();
  181. $visit_data = pdo_getall('stat_visit', array('date >=' => $start_time, 'date <=' => $end_time), array('uniacid', 'count'));
  182. foreach ($visit_data as $item) {
  183. $tota_visit += $item['count'];
  184. if (!empty($accounts[$item['uniacid']])) {
  185. $account_stat[$item['uniacid']]['total'] += $item['count'];
  186. $account_stat[$item['uniacid']]['name'] = $accounts[$item['uniacid']]['name'];
  187. }
  188. }
  189. foreach ($accounts as $uniacid => $account) {
  190. if (!empty($account_stat[$uniacid])) {
  191. $accounts[$uniacid] = $account_stat[$uniacid];
  192. } else {
  193. $accounts[$uniacid] = array('total' => 0, 'name' => $account['name']);
  194. }
  195. }
  196. iajax(0, array(
  197. 'total_account' => $total_account,
  198. 'total_visit' => $tota_visit,
  199. 'list' => array_values($accounts),
  200. ));
  201. }