/public/module/player/escort_statistics.php

https://github.com/karlom/gameadmin · PHP · 148 lines · 112 code · 21 blank · 15 comment · 7 complexity · 1c3c408ecc01b2e245941a93b754565e MD5 · raw file

  1. <?php
  2. /**
  3. * 护送灵兽统计
  4. */
  5. include_once '../../../protected/config/config.php';
  6. include_once SYSDIR_ADMIN_INCLUDE . '/global.php';
  7. include_once SYSDIR_ADMIN_DICT . '/dict.php';
  8. global $dictColor;
  9. unset($dictColor[count($dictColor) - 1]);//去掉金色
  10. unset($dictColor[0]);//去掉灰色
  11. $errorMsg = $successMsg = array();// 消息数组
  12. $onlineDate = $serverList[$_SESSION ['gameAdminServer']]['onlinedate'];//开服日期
  13. //请求参数获取
  14. $startDay = (isset( $_GET['start_day'] ) && Validator::isDate($_GET['start_day']) )? SS($_GET['start_day']) : date('Y-m-d', strtotime('-6 days'));
  15. $endDay = (isset( $_GET['end_day'] ) && Validator::isDate($_GET['end_day']) )? SS($_GET['end_day']) : date('Y-m-d');
  16. //
  17. $startTimestamp = Datatime::getDayBeginTimestamp($startDay);//
  18. $endTimestamp = Datatime::getDayEndTimestamp($endDay);//
  19. $openTimestamp = strtotime( ONLINEDATE );
  20. if($startTimestamp < $openTimestamp)
  21. {
  22. $startTimestamp = $openTimestamp;
  23. $startDay = ONLINEDATE;
  24. }
  25. if($startTimestamp > $endTimestamp)
  26. {
  27. $errorMsg[] = $lang->page->startTimeGtEndTime;
  28. }
  29. if( empty($errorMsg) )//
  30. {
  31. $viewData = getEscortStatistics($startTimestamp, $endTimestamp, $dictColor);
  32. $smarty->assign( 'viewData', $viewData );
  33. }
  34. $smarty->assign( 'lang', $lang );
  35. $smarty->assign( 'dictColor', $dictColor);
  36. $smarty->assign( 'errorMsg', implode('<br/>', $errorMsg ) );
  37. $smarty->assign( 'successMsg', implode('<br/>', $successMsg ) );
  38. $smarty->assign( 'minDate', $onlineDate);
  39. $smarty->assign( 'maxDate', Datatime :: getTodayString());
  40. $smarty->assign( 'startDay', $startDay );
  41. $smarty->assign( 'endDay', $endDay );
  42. $smarty->assign( 'roleName', $roleName );
  43. $smarty->assign( 'accountName', $accountName );
  44. $smarty->display( 'module/player/escort_statistics.tpl' );
  45. function getEscortStatistics( $startTimestamp, $endTimestamp, $dictColor)
  46. {
  47. $andCond = array();
  48. $andCond[] = " mtime > $startTimestamp";
  49. $andCond[] = " mtime < $endTimestamp";
  50. $generalWhereCond = implode(' AND ', $andCond);
  51. // 初始化结果数组
  52. $viewData = array();
  53. $viewData['accept_color'] = $viewData['refresh_color'] = $viewData['refresh_color_times'] = array();
  54. $tmpColorList = array();
  55. foreach( array_keys($dictColor) as $key )
  56. {
  57. $viewData['accept_color'][$key] = $viewData['refresh_color'][$key] = 0;
  58. $tmpColorList[$key] = 0;
  59. }
  60. //$sqlMaxRefreshTimes = "SELECT MAX(refresh_times) max_refresh_times FROM " . T_LOG_ESCORT . " WHERE $generalWhereCond";
  61. $sqlMaxRefreshTimes = 'SELECT MAX(refresh_times) max_refresh_times FROM (SELECT SUM(refresh_times) refresh_times FROM ' . T_LOG_ESCORT_REFRESH . " WHERE $generalWhereCond GROUP BY role_name, escort_times, year, month, day) t1";
  62. $resultMaxRefreshTimes = GFetchRowOne($sqlMaxRefreshTimes);
  63. $maxRefreshTimesLayer = floor($resultMaxRefreshTimes['max_refresh_times'] / 10);
  64. for ( $i = 0; $i <= $maxRefreshTimesLayer; $i++ )
  65. {
  66. $start = $i == 0? 1: $i * 10;
  67. $end = ($i + 1) * 10 - 1;
  68. $viewData['refresh_color_times'][$i] = array('label' => $start . ' - ' . $end, 'data' => $tmpColorList);
  69. }
  70. // 汇总统计
  71. $sqlGeneral = "SELECT
  72. (SELECT COUNT(*) FROM " . T_LOG_ESCORT . " WHERE result = 1 AND $generalWhereCond) accept_times,
  73. (SELECT COUNT(*) FROM " . T_LOG_ESCORT . " WHERE result = 2 AND escort_status = 1 AND $generalWhereCond) finish_times,
  74. (SELECT COUNT(*) FROM " . T_LOG_ESCORT . " WHERE result = 2 AND escort_status = 3 AND $generalWhereCond) hijack_times,
  75. (SELECT COUNT(*) FROM " . T_LOG_ESCORT . " WHERE result = 3 AND $generalWhereCond) abandon_times,
  76. (SELECT COUNT(distinct(account_name)) FROM " . T_LOG_ESCORT . " WHERE result = 1 AND $generalWhereCond) accept_role_counts,
  77. (SELECT COUNT(distinct(account_name)) FROM " . T_LOG_ESCORT . " WHERE result = 2 AND $generalWhereCond) finish_role_counts";
  78. $viewData['general'] = GFetchRowOne($sqlGeneral);
  79. // 护送灵兽颜色分布统计
  80. $sqlInitColor = "SELECT COUNT(*) times, escort_type FROM " . T_LOG_ESCORT . " WHERE result = 1 AND $generalWhereCond GROUP BY escort_type";
  81. $initColor = GFetchRowSet($sqlInitColor);
  82. foreach( $initColor as $item )
  83. {
  84. $viewData['accept_color'][$item['escort_type']] = $item['times'];
  85. }
  86. // 刷新后护送灵兽颜色分布统计
  87. // $sqlRefreshColor = "SELECT COUNT(*) times, escort_type FROM " . T_LOG_ESCORT . " WHERE result = 1 AND refresh_times > 0 GROUP BY escort_type";
  88. $sqlRefreshColor = 'SELECT COUNT(t.refresh_times) times, t.escort_type
  89. FROM (
  90. SELECT
  91. t1.mtime, t1.role_name, t1.account_name, t1.time_used, t2.refresh_times, t1.escort_type, t1.escort_status, t1.result
  92. FROM ' . T_LOG_ESCORT . ' t1
  93. LEFT JOIN (
  94. SELECT SUM(refresh_times) refresh_times, role_name, escort_times, year, day, month FROM ' . T_LOG_ESCORT_REFRESH ." WHERE $generalWhereCond GROUP BY role_name, escort_times, year, month, day
  95. ) t2
  96. ON
  97. t1.role_name = t2.role_name AND t1.escort_times = t2.escort_times AND t1.`year` = t2.`year` AND t1.`month` = t2.`month` AND t1.`day` = t2.`day`
  98. WHERE $generalWhereCond AND t1.result = 1 AND t2.refresh_times > 0
  99. ) t GROUP BY t.escort_type";
  100. $refreshColor = GFetchRowSet($sqlRefreshColor);
  101. foreach( $refreshColor as $item )
  102. {
  103. $viewData['refresh_color'][$item['escort_type']] = $item['times'];
  104. }
  105. // 刷新护送灵兽颜色次数分布统计
  106. // $sqlRefreshColorTimes = "SELECT COUNT(*) times, escort_type, FLOOR(refresh_times/10) layer FROM " . T_LOG_ESCORT . " WHERE result = 1 AND refresh_times > 0 GROUP BY FLOOR(refresh_times/10)";
  107. $sqlRefreshColorTimes = 'SELECT count(t.refresh_times) times, t.escort_type, FLOOR(t.refresh_times/10) layer
  108. FROM (
  109. SELECT
  110. t1.mtime, t1.role_name, t1.account_name, t1.time_used, t2.refresh_times, t1.escort_type, t1.escort_status, t1.result
  111. FROM ' . T_LOG_ESCORT . ' t1
  112. LEFT JOIN (
  113. SELECT SUM(refresh_times) refresh_times, role_name, escort_times, year, day, month FROM ' . T_LOG_ESCORT_REFRESH ." WHERE $generalWhereCond GROUP BY role_name, escort_times, year, month, day
  114. ) t2
  115. ON
  116. t1.role_name = t2.role_name AND t1.escort_times = t2.escort_times AND t1.`year` = t2.`year` AND t1.`month` = t2.`month` AND t1.`day` = t2.`day`
  117. WHERE $generalWhereCond AND t1.result = 1 AND t2.refresh_times > 0
  118. ) t GROUP BY FLOOR(t.refresh_times/10), t.escort_type";
  119. $refreshColorTimes= GFetchRowSet($sqlRefreshColorTimes);
  120. //dump($sqlRefreshColorTimes);
  121. foreach($refreshColorTimes as $item)
  122. {
  123. $viewData['refresh_color_times'][$item['layer']]['data'][$item['escort_type']] = $item['times'];
  124. }
  125. //dump($viewData);
  126. return $viewData;
  127. }