app.ctrl.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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('display', 'get_account_api', 'get_module_api');
  10. $do = in_array($do, $dos) ? $do : 'display';
  11. permission_check_account_user('statistics_visit_app');
  12. $support_type = array(
  13. 'time' => array('today', 'week', 'month', 'daterange'),
  14. 'divide' => array('bysum', 'byavg', 'byhighest'),
  15. );
  16. if ($do == 'display') {
  17. $today = stat_visit_app_byuniacid('today');
  18. $yesterday = stat_visit_app_byuniacid('yesterday');
  19. $today_module_api = stat_all_visit_statistics('current_account', $today);
  20. $yesterday_module_api = stat_all_visit_statistics('current_account', $yesterday);
  21. $statistics_setting = (array)uni_setting_load(array('statistics'), $_W['uniacid']);
  22. $highest_visit = empty($statistics_setting['statistics']['founder']) ? 0 : $statistics_setting['statistics']['founder'];
  23. $month_use = 0;
  24. $stat_visit_teble = table('stat_visit');
  25. $stat_visit_teble->searchWithGreaterThenDate(date('Ym01'));
  26. $stat_visit_teble->searchWithLessThenDate(date('Ymt'));
  27. $stat_visit_teble->searchWithType('app');
  28. $stat_visit_teble->searchWithUnacid($_W['uniacid']);
  29. $visit_list = $stat_visit_teble->getall();
  30. if (!empty($visit_list)) {
  31. foreach ($visit_list as $key => $val) {
  32. $month_use += $val['count'];
  33. }
  34. }
  35. $order_num = 0;
  36. $orders = table('store')->apiOrderWithUniacid($_W['uniacid']);
  37. if (!empty($orders)) {
  38. foreach ($orders as $order) {
  39. $order_num += $order['duration'] * $order['api_num'] * 10000;
  40. }
  41. }
  42. $api_remain_num = empty($statistics_setting['statistics']['use']) ? $order_num : ($order_num - $statistics_setting['statistics']['use']);
  43. if ($api_remain_num < 0) {
  44. $api_remain_num = 0;
  45. }
  46. template('statistics/app-display');
  47. }
  48. if ($do == 'get_account_api') {
  49. $data = array();
  50. $type = trim($_GPC['time_type']);
  51. $divide_type = trim($_GPC['divide_type']);
  52. if (!in_array($type, $support_type['time']) || !in_array($divide_type, $support_type['divide'])) {
  53. iajax(-1, '参数错误!');
  54. }
  55. $daterange = array();
  56. if (!empty($_GPC['daterange'])) {
  57. $daterange = array(
  58. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  59. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  60. );
  61. }
  62. $result = stat_visit_app_bydate($type, '', $daterange);
  63. if ($type == 'today') {
  64. $data_x = array(date('Ymd'));
  65. }
  66. if ($type == 'week') {
  67. $data_x = stat_date_range(date('Ymd', strtotime('-7 days')), date('Ymd'));
  68. }
  69. if ($type == 'month') {
  70. $data_x = stat_date_range(date('Ymd', strtotime('-30 days')), date('Ymd'));
  71. }
  72. if ($type == 'daterange') {
  73. $data_x = stat_date_range($daterange['start'], $daterange['end']);
  74. }
  75. if (empty($result)) {
  76. foreach ($data_x as $val) {
  77. $data_y[] = 0;
  78. }
  79. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  80. }
  81. foreach ($data_x as $key => $data) {
  82. foreach ($result as $val) {
  83. if (strtotime($val['date']) != strtotime($data)) {
  84. continue;
  85. }
  86. if ($divide_type == 'bysum') {
  87. $data_y[$key] = $val['count'];
  88. } elseif ($divide_type == 'byavg') {
  89. $data_y[$key] = $val['avg'];
  90. } elseif ($divide_type == 'byhighest') {
  91. $data_y[$key] = $val['highest'];
  92. }
  93. }
  94. if (empty($data_y[$key])) {
  95. $data_y[$key] = 0;
  96. }
  97. }
  98. iajax(0, array('data_x' => $data_x, 'data_y' => $data_y));
  99. }
  100. if ($do == 'get_module_api') {
  101. $modules = array();
  102. $data = array();
  103. $modules_info = stat_modules_except_system();
  104. if (in_array(FRAME, array(ACCOUNT_TYPE_OFFCIAL_NORMAL, ACCOUNT_TYPE_OFFCIAL_AUTH))) {
  105. array_unshift($modules_info, array('name' => 'wesite', 'title' => '微站'));
  106. } else {
  107. array_unshift($modules_info, array('name' => 'wesite', 'title' => '其他'));
  108. }
  109. foreach ($modules_info as $info) {
  110. $modules[] = mb_substr($info['title'], 0, 5, 'utf-8');
  111. }
  112. $type = trim($_GPC['time_type']);
  113. $divide_type = trim($_GPC['divide_type']);
  114. if (!in_array($type, $support_type['time']) || !in_array($divide_type, $support_type['divide'])) {
  115. iajax(-1, '参数错误!');
  116. }
  117. $daterange = array();
  118. if (!empty($_GPC['daterange'])) {
  119. $daterange = array(
  120. 'start' => date('Ymd', strtotime($_GPC['daterange']['startDate'])),
  121. 'end' => date('Ymd', strtotime($_GPC['daterange']['endDate'])),
  122. );
  123. }
  124. $result = stat_visit_app_byuniacid($type, '', $daterange);
  125. if (empty($result)) {
  126. foreach ($modules_info as $module) {
  127. $data[] = 0;
  128. }
  129. iajax(0, array('data_x' => $data, 'data_y' => $modules));
  130. }
  131. foreach ($modules_info as $module) {
  132. $have_count = false;
  133. foreach ($result as $val) {
  134. if ($module['name'] == $val['module']) {
  135. if ($divide_type == 'bysum') {
  136. $data[] = $val['count'];
  137. } elseif ($divide_type == 'byavg') {
  138. $data[] = $val['avg'];
  139. } elseif ($divide_type == 'byhighest') {
  140. $data[] = $val['highest'];
  141. }
  142. $have_count = true;
  143. }
  144. }
  145. if (empty($have_count)) {
  146. $data[] = 0;
  147. }
  148. }
  149. iajax(0, array('data_x' => $data, 'data_y' => $modules));
  150. }