GameContinuedTs.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. include_once dirname(__FILE__) . '/../main.php';
  3. $params = query_paras();
  4. //$params = $_POST['date'];
  5. $date = $params['date']['ts'];
  6. $uid = $params['date']['uid'];
  7. $zoneid = $params['date']['zoneid'];
  8. $tableName = "tab_op_log" . $date;
  9. $dic = new stdClass();
  10. if (daoInst()->tableExist($tableName)) {
  11. $arr = daoInst()->select("*")->from($tableName)
  12. ->where('cmd')->eq(6903)
  13. ->andWhere('zoneid')->eq($zoneid)
  14. ->andWhere('uid')->eq($uid)
  15. ->fetchAll();
  16. $lastItem = null;
  17. $list = array();
  18. $index = 1;
  19. $num = 0;
  20. foreach ($arr as $item) {
  21. if ($lastItem != null) {
  22. $list[] = $lastItem;
  23. if (strtotime($item->ts) - strtotime($lastItem->ts) > 20 * 60) {
  24. $timeDic = new stdClass();
  25. $timeDic->startTs = strtotime($list[0]->ts);
  26. $timeDic->endTs = strtotime($list[count($list) - 1]->ts);
  27. $timeDic->durationTs = strtotime($list[count($list) - 1]->ts) - strtotime($list[0]->ts);
  28. $dic->$index = $timeDic;
  29. $index += 1;
  30. $list = array();
  31. }
  32. }
  33. $num += 1;
  34. $lastItem = $item;
  35. if (count($arr) == $num) {
  36. $list[] = $item;
  37. $timeDic = new stdClass();
  38. $timeDic->startTs = strtotime($list[0]->ts);
  39. $timeDic->endTs = strtotime($list[count($list) - 1]->ts);
  40. $timeDic->durationTs = strtotime($list[count($list) - 1]->ts) - strtotime($list[0]->ts);
  41. $dic->$index = $timeDic;
  42. break;
  43. }
  44. }
  45. }
  46. echo Resp::ret($dic);
  47. //echo json_encode($result);