fans.ctrl.php 2.8 KB

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