newUserRetention.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. /*
  3. * To change this license header, choose License Headers in Project Properties.
  4. * To change this template file, choose Tools | Templates
  5. * and open the template in the editor.
  6. */
  7. include_once dirname(__FILE__) . '/../main.php';
  8. $params = query_paras();
  9. $rType = $params['rType'];
  10. if($rType == 1){
  11. $date = $params['date'];
  12. $zoneid = 1;//先默认是1,其他区还没有
  13. $day = intval((strtotime($date)+28800) / 86400);
  14. $memKey = "gamerun-loginUser-byUid-zone".$zoneid."-day_".$day;
  15. if(!gMem()->exists($memKey)){
  16. $result = new stdClass();
  17. $dic = new stdClass();
  18. $dic->data1 = array(0,0,0,0,0,0,0,0);
  19. $dic->data2 = array(0,0,0,0,0,0,0);
  20. $result->data = $dic;
  21. echo json_encode($result);
  22. } else {
  23. $retArr = array();
  24. $perArr = array();
  25. $curLoginUidDic = gMem()->hgetall($memKey);
  26. $total = count((array)$curLoginUidDic);
  27. $retArr[] = $total;
  28. $numbersArr = array(1, 2, 3, 4, 5, 6,7);
  29. foreach ($numbersArr as $type) {
  30. $typeDay = $day + $type;
  31. $memKey = "gamerun-loginUser-byUid-zone".$zoneid."-day_".$typeDay;
  32. if(!gMem()->exists($memKey)){
  33. $retArr[] = 0;
  34. } else {
  35. $typeDic = gMem()->hgetall($memKey);
  36. $n = 0;
  37. foreach ($curLoginUidDic as $uid=>$val) {
  38. if(property_exists($typeDic, $uid)){
  39. $n += 1;
  40. }
  41. }
  42. $retArr[] = $n;
  43. }
  44. }
  45. $index = 0;
  46. foreach ($retArr as $num) {
  47. if($index == 0){
  48. $index += 1;
  49. continue;
  50. }
  51. $per = intval($num/$total*100);
  52. $perArr[] = $per;
  53. }
  54. $result = new stdClass();
  55. $result->data1 = $retArr;
  56. $result->data2 = $perArr;
  57. echo json_encode($result);
  58. }
  59. } else {
  60. $startTime = $paras['date1'];
  61. $endTime = $paras['date2'];
  62. $type = $paras['type'];
  63. $result = new stdClass();
  64. $result->data1 = $retArr;
  65. $result->data2 = $perArr;
  66. echo json_encode($result);
  67. }