/public/module/basedata/task_lose_rate.php

https://github.com/karlom/gameadmin · PHP · 141 lines · 79 code · 26 blank · 36 comment · 6 complexity · 711a618294e71505277a142bcbb014d9 MD5 · raw file

  1. <?php
  2. include_once '../../../protected/config/config.php';
  3. include_once SYSDIR_ADMIN_INCLUDE . '/global.php';
  4. include_once SYSDIR_ADMIN_DICT . '/task.php';
  5. global $lang;
  6. $auth->assertModuleAccess(__FILE__);
  7. $nowTime = time();
  8. //获取时间段
  9. if (!isset ($_POST['starttime'])) {
  10. $startDate = Datatime :: getTodayString();
  11. // $startDate = ONLINEDATE;
  12. } else {
  13. $startDate = SS($_POST['starttime']);
  14. }
  15. if (!isset ($_POST['endtime'])) {
  16. $endDate = Datatime :: getTodayString();
  17. } else {
  18. $endDate = SS($_POST['endtime']);
  19. }
  20. $openTimestamp = strtotime( ONLINEDATE );
  21. if(strtotime($startDate) < $openTimestamp)
  22. {
  23. $startDate = ONLINEDATE;
  24. }
  25. $minLevel = isset($_POST["min_level"]) ? SS($_POST["min_level"]) : 1;
  26. $maxLevel = isset($_POST["max_level"]) ? SS($_POST["max_level"]) : GAME_MAXLEVEL ;
  27. //任务类型
  28. $type = SS($_POST['type']);
  29. $viewData = getTaskLoseRate($startDate, $endDate) ;
  30. //第一个任务无日志,创建完角色即接受
  31. $sql = "select count(distinct account_name) num from ".T_LOG_CREATE_LOSS." where mtime>=".strtotime($startDate)." and mtime<=".strtotime($endDate." 23:59:59")." and step=1";
  32. $firstTaskAccept = GFetchRowOne($sql);
  33. //完成数
  34. $sql = "select count(*) as num from t_log_task where mtime>=".strtotime($startDate)." and mtime<=".strtotime($endDate." 23:59:59")." and task_id=1 and task_action=1";
  35. $firstTaskFinish = GFetchRowOne($sql);
  36. $firstTask = array (
  37. 'task_id' => 1,
  38. 'accept' => $firstTaskAccept['num'],
  39. 'finish' => $firstTaskFinish['num'],
  40. );
  41. array_unshift($viewData,$firstTask);
  42. foreach($viewData as $key => &$value){
  43. // if($value['task_id'] == 1) {
  44. // $value['accept'] = $firstTaskAccept['num'];
  45. // }
  46. $value['accept'] = intval($value['accept']);
  47. $value['finish'] = intval($value['finish']);
  48. if(intval($value['accept'])){
  49. $value['finishRate'] = number_format(intval($value['finish']) / intval($value['accept']) * 100, 2)."%";
  50. }else{
  51. $value['finishRate'] = "N/A";
  52. }
  53. }
  54. $minDate = ONLINEDATE;
  55. $maxDate = Datatime :: getTodayString();
  56. $smarty->assign("minDate", $minDate);
  57. $smarty->assign("maxDate", $maxDate);
  58. $smarty->assign("startDate", $startDate);
  59. $smarty->assign("endDate", $endDate);
  60. $smarty->assign("minLevel", $minLevel);
  61. $smarty->assign("maxLevel", $maxLevel);
  62. $smarty->assign('dictTask', $dictTask);
  63. $smarty->assign('lang', $lang);
  64. $smarty->assign('viewData', $viewData);
  65. $smarty->assign('type', $type);
  66. $smarty->assign('missionType', $missionType);
  67. $smarty->display('module/basedata/task_lose_rate.tpl');
  68. function getTaskLoseRate($startDate, $endDate ) {
  69. $startTime = strtotime($startDate);
  70. $endTime = strtotime($endDate." 23:59:59");
  71. $where = 1;
  72. $where .= " and task_id < 10000 ";
  73. $where .= " and mtime>=".$startTime;
  74. $where .= " and mtime<=".$endTime;
  75. /*
  76. //这个SQL统计时间段内每个任务接受,完成,放弃的人数
  77. $sql = "select U30.mission_id missionId,U30.mission_name missionName,U30.accept,U30.finish,U30.groupId,U30.minLevel,U30.maxLevel,U40.cancle from (
  78. select U10.*, U20.accept from (SELECT mission_id, mission_name, count(mission_id) finish, group_id groupId, min_level minLevel, max_level maxLevel FROM t_log_mission where {$where} and `status`=2 group by mission_id) U10
  79. left join (SELECT mission_id, mission_name, count(mission_id) accept FROM t_log_mission where {$where} and `status`=1 group by mission_id) U20 on U10.mission_id=U20.mission_id) U30
  80. left join (SELECT mission_id, mission_name, count(mission_id) cancle FROM t_log_mission where {$where} and `status`=3 group by mission_id) U40 on U30.mission_id=U40.mission_id";
  81. $sql = "select
  82. U30.task_id, U30.accept, U30.finish, U40.cancle
  83. from (
  84. select U10.*, U20.accept
  85. from
  86. (
  87. SELECT task_id, count(task_id) as finish FROM t_log_task where {$where} and `task_action`=1 group by task_id
  88. ) U10
  89. left join
  90. (
  91. SELECT task_id, count(task_id) accept FROM t_log_task where {$where} and `task_action`=0 group by task_id
  92. ) U20 on U10.task_id=U20.task_id
  93. ) U30
  94. left join
  95. (
  96. SELECT task_id, count(task_id) cancle FROM t_log_task where {$where} and `task_action`=2 group by task_id
  97. ) U40
  98. on U30.task_id=U40.task_id"; //此sql只统计指定时间段内的任务情况,包括时间段前接受的任务,完成率可能会超100%
  99. */
  100. //时间段内接受的任务数
  101. $sql1 = " select task_id, count(task_id) as accept from t_log_task where {$where} and `task_action`=0 group by task_id ";
  102. //完成任务数
  103. $sql2 = " select T1.task_id, count(T1.uuid) as finish
  104. from
  105. ( select uuid,task_id,count(task_action) as ff
  106. from t_log_task
  107. where {$where} and `task_action`<>2
  108. group by task_id,uuid having ff=2
  109. ) T1
  110. group by T1.task_id ";
  111. $sql = "select U10.task_id, U10.accept, U20.finish from ({$sql1}) U10 left join ({$sql2}) U20 on U10.task_id=U20.task_id";
  112. $task_lose_rate = GFetchRowSet($sql, "task_id");
  113. return $task_lose_rate;
  114. }