where('status', 1) ->count(); // 获取今日新增用户数 $today = strtotime(date('Y-m-d')); $todayNew = Users::where('delete_time', 0) ->where('status', 1) ->where('create_time', '>=', $today) ->count(); // 获取最近7天的用户数据 $dates = []; $counts = []; $totalCounts = []; // 存储每天的总用户数 for ($i = 6; $i >= 0; $i--) { $date = date('Y-m-d', strtotime("-$i days")); $start = strtotime($date); $end = $start + 86400; // 获取当天新增用户数 $count = Users::where('delete_time', 0) ->where('status', 1) ->where('create_time', '>=', $start) ->where('create_time', '<', $end) ->count(); // 获取截至当天的总用户数 $totalCount = Users::where('delete_time', 0) ->where('status', 1) ->where('create_time', '<', $end) ->count(); $dates[] = $date; $counts[] = $count; $totalCounts[] = $totalCount; } return json([ 'code' => 0, 'msg' => '获取成功', 'data' => [ 'total' => $total, 'todayNew' => $todayNew, 'dates' => $dates, 'counts' => $counts, 'totalCounts' => $totalCounts ] ]); } catch (\Exception $e) { return json([ 'code' => 1, 'msg' => '获取失败:' . $e->getMessage() ]); } } }