retention.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * 留存1
  4. */
  5. include_once dirname(__FILE__) . '/../main.php';
  6. $params = query_paras();
  7. $date = $params['date'];
  8. /*---old
  9. $numbers = array(1, 3, 5, 7, 15, 30); # 留存天数
  10. $array = array();
  11. $array2 = array();
  12. // 计算新增人数
  13. $tabName = "tab_rolename";
  14. $new = daoInst()->select('*')->from($tabName)
  15. ->where('ts')->ge($date . " 00:00:00")
  16. ->andWhere('ts')->le($date . " 23:59:59")
  17. ->count();
  18. $array[] = intval($new);
  19. // 遍历 留存天数数组, 计算相应留存/率
  20. array_map(function ($n)use($date, $tabName, $new, &$array, &$array2) {
  21. $iday = strtotime("$date +$n day");
  22. $day = date("Y-m-d", $iday);
  23. $total = daoInst()->select('*')->from($tabName)
  24. ->where('ts')->ge($date . " 00:00:00")
  25. ->andWhere('ts')->le($date . " 23:59:59")
  26. ->andWhere('lastlogin')->ge($day . " 00:00:00")
  27. ->count();
  28. $array[] = $total; # 输出
  29. $array2[] = (int) ($total / $new * 100); # 输出
  30. }, $numbers);
  31. //
  32. */
  33. //------new----
  34. $zoneid = 1;//先默认是1,其他区还没有
  35. $curLoginUidArr = gMem()->hgetall($key);
  36. $numbersArr = array(1, 2, 3, 4, 5, 6,7);
  37. $day = intval(strtotime($date)/24/60/60);
  38. foreach ($numbersArr as $type) {
  39. $typeDay = intval(strtotime("$day +$type day")/24/60/60);
  40. $memKey = "gamerun-loginUser-byUid-zone".$zoneid."-day_".$typeDay;
  41. $typeArr = gMem()->hgetall($memKey);
  42. $retainArr = array();
  43. foreach ($curLoginUidArr as $uid=>$val) {
  44. if(in_array($uid, $typeArr)){
  45. $retainArr[]=$uid;
  46. }
  47. }
  48. }
  49. $result = new stdClass();
  50. $result->data1 = $array;
  51. $result->data2 = $array2;
  52. echo json_encode($result);