人人商城

app.ctrl.php 4.9KB

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