retention.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. /*
  3. * 留存1
  4. */
  5. include_once dirname(__FILE__) . '/../main.php';
  6. $params = query_paras();
  7. $date = $params['date'];
  8. $numbers = array(1, 3, 5, 7, 15, 30); # 留存天数
  9. $array = array();
  10. $array2 = array();
  11. // 计算新增人数
  12. $tabName = "tab_rolename";
  13. $new = daoInst()->select('*')->from($tabName)
  14. ->where('ts')->ge($date . " 00:00:00")
  15. ->andWhere('ts')->le($date . " 23:59:59")
  16. ->count();
  17. $array[] = intval($new);
  18. // 遍历 留存天数数组, 计算相应留存/率
  19. array_map(function ($n)use($date, $tabName, $new, &$array, &$array2) {
  20. $iday = strtotime("$date +$n day");
  21. $day = date("Y-m-d", $iday);
  22. $total = daoInst()->select('*')->from($tabName)
  23. ->where('ts')->ge($date . " 00:00:00")
  24. ->andWhere('ts')->le($date . " 23:59:59")
  25. ->andWhere('lastlogin')->ge($day . " 00:00:00")
  26. ->count();
  27. $array[] = $total; # 输出
  28. $array2[] = (int) ($total / $new * 100); # 输出
  29. }, $numbers);
  30. //
  31. $result = new stdClass();
  32. $result->data1 = $array;
  33. $result->data2 = $array2;
  34. echo json_encode($result);