PageRenderTime 27ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/public/module/activity/yjxb_statistics.php

https://github.com/karlom/gameadmin
PHP | 268 lines | 175 code | 48 blank | 45 comment | 13 complexity | afa4af27d06896e3702776f3f8784a10 MD5 | raw file
  1. <?php
  2. /**
  3. * yjxb_statistics.php
  4. * 遗迹寻宝 数据统计
  5. */
  6. include_once '../../../protected/config/config.php';
  7. include_once SYSDIR_ADMIN_INCLUDE.'/global.php';
  8. include_once SYSDIR_ADMIN_DICT.'/dict.php';
  9. /*
  10. $dictYjxbSkill = array(
  11. '5006' => '鞭炮',
  12. '5008' => '缩小术',
  13. '5009' => '跳跃',
  14. '5010' => '笨重术',
  15. '5011' => '痊愈',
  16. );
  17. */
  18. $dictMonsterType = array(
  19. 'xunluo' => '巡逻' ,
  20. 'dingdian' => '定点蹲守' ,
  21. 'jiguan' => '机关类型' ,
  22. 'boss' => 'BOSS' ,
  23. );
  24. $copyId = 300;
  25. $mapId = 3003;
  26. $limitLevel = 40;
  27. //副本开启时间:每天14:00 - 14:30
  28. $today = date('Y-m-d');
  29. $todayTime = strtotime($today." 00:00:00 ");
  30. $todayEndTime = strtotime($today." 23:59:59 ");
  31. $startDay = $_REQUEST['startDay'] ? $_REQUEST['startDay'] : date("Y-m-d", ($todayTime - 7*86400) );
  32. $endDay = $_REQUEST['endDay'] ? $_REQUEST['endDay'] : $today;
  33. if( strtotime($startDay) < strtotime(ONLINEDATE) ) {
  34. $startDay = ONLINEDATE;
  35. }
  36. $days = array();
  37. for($i = strtotime($startDay); $i<= strtotime($endDay) ; $i+= 86400){
  38. $days[] = date("Y-m-d", $i);
  39. }
  40. foreach( $days as $d ){
  41. $joinData[$d] = getJoinData($d);
  42. if(empty($joinData[$d])){
  43. $joinData[$d] = array(
  44. 'mdate' => $d,
  45. 'act_count' => '<font color="blue">(-1)</font>',
  46. 'join_count' => 0,
  47. 'joinRate' => 0,
  48. 'room_count' => 0,
  49. );
  50. }
  51. }
  52. //if(isPost()){
  53. //历史数据
  54. $selectDay = $_REQUEST['selectDay'] ? SS($_REQUEST['selectDay']) : $today;
  55. $weekDays = getWeekDays($selectDay);
  56. //本周各天数据
  57. foreach($weekDays as $k => $day){
  58. $viewData[$day] = getYjxbData($day);
  59. }
  60. //本周数据
  61. //开始、结束日期
  62. $weekStartDay = $weekDays[0];
  63. $weekEndDay = $weekDays[(count($weekDays)-1)];
  64. $thisWeek = $weekStartDay."~".$weekEndDay;
  65. $thisWeekData = getYjxbData($weekStartDay, $weekEndDay);
  66. $viewData['thisWeek'] = $thisWeekData;
  67. //上周数据
  68. $lastWeekDays = getWeekDays( date('Y-m-d', strtotime($selectDay)-7*86400) );
  69. //开始、结束日期
  70. $lastWeekStartDay = $lastWeekDays[0];
  71. $lastWeekEndDay = $lastWeekDays[(count($lastWeekDays)-1)];
  72. $lastWeek = $lastWeekStartDay."~".$lastWeekEndDay;
  73. $lastWeekData = getYjxbData($lastWeekStartDay, $lastWeekEndDay);
  74. $viewData['lastWeek'] = $lastWeekData;
  75. //}
  76. //data
  77. $smarty->assign('joinData', $joinData );
  78. $smarty->assign('viewData', $viewData );
  79. $smarty->assign('thisWeek', $thisWeek );
  80. $smarty->assign('lastWeek', $lastWeek );
  81. //other
  82. $smarty->assign('lang', $lang );
  83. $smarty->assign('minDate', ONLINEDATE );
  84. $smarty->assign('maxDate', $today );
  85. $smarty->assign('startDay', $startDay );
  86. $smarty->assign('endDay', $endDay );
  87. $smarty->assign('selectDay', $selectDay );
  88. $smarty->display( 'module/activity/yjxb_statistics.tpl' );
  89. function getJoinData($date){
  90. // $table = c_activity_join;
  91. $act_no = 2;
  92. $sql = "select * from ". C_ACTIVITY_JOIN . " where act_no={$act_no} AND mdate='{$date}' ";
  93. $result = GFetchRowOne($sql);
  94. if(!empty($result)) {
  95. $result['joinRate'] = $result['act_count'] ? round($result['join_count']/$result['act_count'],4)*100 :0;
  96. }
  97. return $result;
  98. }
  99. /**
  100. * 遗迹寻宝副本统计数据
  101. * @param string1,string2 开始日期【,结束日期】 日期格式:"YYYY-MM-DD"
  102. * @author Libiao
  103. */
  104. function getYjxbData($startDay, $endDay=""){
  105. global $mapId, $copyId;
  106. $startTime = strtotime($startDay." 00:00:00 ");
  107. if("" == $endDay){
  108. $endTime = strtotime($startDay." 23:59:59 ");
  109. } else {
  110. $endTime = strtotime($endDay." 23:59:59 ");
  111. }
  112. //普通宝箱ID:3003801,3003803,3003805
  113. //高级宝箱ID:3003802,3003804,3003806
  114. //华丽宝箱ID:3003807
  115. $sqlCommonBox = "select count(*) as `count` from t_log_yjxb_collect where collect_id in (3003801, 3003803, 3003805) AND mtime>={$startTime} and mtime<={$endTime} ";
  116. $sqlAdvancedBox = "select count(*) as `count` from t_log_yjxb_collect where collect_id in (3003802, 3003804, 3003806) AND mtime>={$startTime} and mtime<={$endTime} ";
  117. $sqlGorgeousBox = "select count(*) as `count` from t_log_yjxb_collect where collect_id=3003807 AND mtime>={$startTime} and mtime<={$endTime} ";
  118. $sqlCommonBoxResult = GFetchRowOne($sqlCommonBox);
  119. $sqlAdvancedBoxResult = GFetchRowOne($sqlAdvancedBox);
  120. $sqlGorgeousBoxResult = GFetchRowOne($sqlGorgeousBox);
  121. //参与人数
  122. $sqlJoinCount = "select count(distinct uuid) as `count` from t_log_copy where mtime >=$startTime and mtime< $endTime and copy_id='{$copyId}' and action=1 ";
  123. $sqlJoinCountResult = GFetchRowOne($sqlJoinCount);
  124. //死亡转移寻宝金币数量
  125. $sqlDieDivertJb = "select sum(jb) as `jb` from t_log_yjxb_jb where mtime >=$startTime and mtime< $endTime AND jb>0 AND is_from_human=1 ";
  126. $sqlDieDivertJbResult = GFetchRowOne($sqlDieDivertJb);
  127. //怪物击杀
  128. $sqlMonsterKill = "select killer_uuid, count(id) as `die_cnt` from t_log_die where mtime>={$startTime} and mtime<={$endTime} AND map_id={$mapId} AND killer_type=3 group by killer_uuid";
  129. $sqlMonsterKillResult = GFetchRowSet($sqlMonsterKill);
  130. //死亡总次数
  131. $allKillCount = 0;
  132. if(!empty($sqlMonsterKillResult)) {
  133. foreach($sqlMonsterKillResult as $key => $value) {
  134. $allKillCount += $value['die_cnt'];
  135. }
  136. }
  137. //平均死亡次数
  138. $avgDie = ($sqlJoinCountResult['count']!=0) ? round($allKillCount/$sqlJoinCountResult['count'],1):0;
  139. //怪物击杀比率
  140. //巡逻 怪物ID:3003003,3003004,3003005,3003006,3003007,3003008,3003009,3003010,3003011,3003014,3003015
  141. //定点蹲守 怪物ID:3003012,3003013
  142. //机关类型 怪物ID:3003002
  143. //BOSS怪物ID:3003001
  144. $monsterKill = array(
  145. 'xunluo' => array('count' => 0, 'percent' => 0, ) ,
  146. 'dingdian' => array('count' => 0, 'percent' => 0, ) ,
  147. 'jiguan' => array('count' => 0, 'percent' => 0, ) ,
  148. 'boss' => array('count' => 0, 'percent' => 0, ) ,
  149. );
  150. foreach($sqlMonsterKillResult as $key => $value) {
  151. //分类统计
  152. switch($value['killer_uuid']) {
  153. case 3003001 :
  154. $monsterKill['boss']['count'] += $value['die_cnt'];
  155. break;
  156. case 3003002 :
  157. $monsterKill['jiguan']['count'] += $value['die_cnt'];
  158. break;
  159. case 3003012 :
  160. case 3003013 :
  161. $monsterKill['dingdian']['count'] += $value['die_cnt'];
  162. break;
  163. default:
  164. $monsterKill['xunluo']['count'] += $value['die_cnt'];
  165. break;
  166. }
  167. }
  168. if( !empty($allKillCount) ) {
  169. foreach( $monsterKill as $key => $value ) {
  170. $monsterKill[$key]['percent'] = round( ($value['count']/$allKillCount)*100 );
  171. }
  172. }
  173. //技能使用情况
  174. $sqlSkillUse = "select skill_id, count(*) as `count` from t_log_yjxb_skill where mtime>={$startTime} and mtime<={$endTime} group by skill_id ";
  175. $sqlSkillUseResult = GFetchRowSet($sqlSkillUse);
  176. $skillUse = array(
  177. '5006' => array('skill_id' => 5006, 'count'=>0, 'percent' => 0,),
  178. '5008' => array('skill_id' => 5008, 'count'=>0, 'percent' => 0,),
  179. '5009' => array('skill_id' => 5009, 'count'=>0, 'percent' => 0,),
  180. '5010' => array('skill_id' => 5010, 'count'=>0, 'percent' => 0,),
  181. '5011' => array('skill_id' => 5011, 'count'=>0, 'percent' => 0,),
  182. );
  183. if(!empty($sqlSkillUseResult)){
  184. $allUse = 0;
  185. foreach($sqlSkillUseResult as $key => $value) {
  186. $allUse += $value['count'];
  187. $skillID = $value['skill_id'];
  188. $skillUse[$skillID]['count'] = $value['count'];
  189. }
  190. if( $allUse != 0 ) {
  191. foreach($skillUse as $key => &$value) {
  192. $value['percent'] = round( ($value['count']/$allUse)*100, 2 );
  193. }
  194. }
  195. }
  196. if( ($endTime - $startTime) > 86400 ) {
  197. $tmpRank = sortArrayByKey($monsterKill, 'count', 'desc');
  198. $i = 1;
  199. global $dictMonsterType;
  200. foreach($tmpRank as $key => $value) {
  201. $monsterKillRank[$i]['rank'] = $i;
  202. $monsterKillRank[$i]['name'] = $dictMonsterType[$key];
  203. $monsterKillRank[$i]['count'] = $value['count'];
  204. $monsterKillRank[$i]['percent'] = $value['percent'];
  205. $i++;
  206. }
  207. }
  208. $data = array(
  209. 'joinCount' => $sqlJoinCountResult['count'],
  210. 'dieDivertJb' => $sqlDieDivertJbResult['jb'] ? $sqlDieDivertJbResult['jb'] : 0 ,
  211. 'commonBox' => $sqlCommonBoxResult['count'] ,
  212. 'advancedBox' => $sqlAdvancedBoxResult['count'] ,
  213. 'gorgeousBox' => $sqlGorgeousBoxResult['count'] ,
  214. 'avgDie' => $avgDie ,
  215. 'skillUse' => $skillUse ,
  216. 'monsterKill' => $monsterKill ,
  217. 'monsterKillRank' => $monsterKillRank ,
  218. );
  219. return $data;
  220. }