diff --git a/app/controller/admin/api/v1/PromotionController.php b/app/controller/admin/api/v1/PromotionController.php index 884d885..c07d61b 100644 --- a/app/controller/admin/api/v1/PromotionController.php +++ b/app/controller/admin/api/v1/PromotionController.php @@ -14,6 +14,7 @@ use app\model\UserPhoneLog; use hg\apidoc\annotation as Apidoc; use app\model\Withdraw; use App\Utils\Random; +use support\Db; /** * @Apidoc\Title("admin推广链接控制器") @@ -72,6 +73,7 @@ class PromotionController 'users.remark', 'users.status', 'users.vip_id', + 'users.created_at', 'u.username as parent_username' // 选择所需字段,并为父用户用户名起别名 )->where('users.isrobot', 1) ->orderBy('users.id', 'desc')->get(); // 确保按 users 表的 id 排序 @@ -100,11 +102,14 @@ class PromotionController // 获取用户手机号(按 user_id 分组)并根据时间范围筛选 $UserPhone = UserPhone::whereIn('user_id', $users) ->whereBetween('created_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']) // 时间范围筛选 + ->select('user_id', DB::raw('count(*) as phone_count')) // 聚合查询,按 user_id 分组,计算每个 user_id 的手机数量 ->groupBy('user_id') ->get(); - // 获取注册的用户数量 - $res['register'] = count($users); + // 获取注册的用户数量,按时间筛选 + $res['register'] = User::whereIn('id', $users) + ->whereBetween('created_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']) // 时间范围筛选 + ->count(); // 获取绑定手机号的用户数量 $res['binding'] = count($UserPhone);