12345678910111213141516171819202122232425262728293031323334353637383940 |
- <?php
- /*
- * 留存1
- */
- include_once dirname(__FILE__) . '/../main.php';
- $params = query_paras();
- $date = $params['date'];
- $numbers = array(1, 3, 5, 7, 15, 30); # 留存天数
- $array = array();
- $array2 = array();
- // 计算新增人数
- $tabName = "tab_rolename";
- $new = daoInst()->select('*')->from($tabName)
- ->where('ts')->ge($date . " 00:00:00")
- ->andWhere('ts')->le($date . " 23:59:59")
- ->count();
- $array[] = intval($new);
- // 遍历 留存天数数组, 计算相应留存/率
- array_map(function ($n)use($date, $tabName, $new, &$array, &$array2) {
- $iday = strtotime("$date +$n day");
- $day = date("Y-m-d", $iday);
- $total = daoInst()->select('*')->from($tabName)
- ->where('ts')->ge($date . " 00:00:00")
- ->andWhere('ts')->le($date . " 23:59:59")
- ->andWhere('lastlogin')->ge($day . " 00:00:00")
- ->count();
- $array[] = $total; # 输出
- $array2[] = (int) ($total / $new * 100); # 输出
- }, $numbers);
- //
- $result = new stdClass();
- $result->data1 = $array;
- $result->data2 = $array2;
- echo json_encode($result);
|