From eaf89ed282f85b7a604c5d79bd6b7cf957eb3ba8 Mon Sep 17 00:00:00 2001 From: lingling <1077478963@qq.com> Date: Wed, 26 Feb 2025 10:50:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../admin/api/v1/JobuserController.php | 29 +++-- .../admin/api/v1/PromotionController.php | 117 +++++++++++++++--- app/controller/api/UserController.php | 5 +- app/dao/UserDao.php | 2 +- app/model/User.php | 1 + 5 files changed, 124 insertions(+), 30 deletions(-) diff --git a/app/controller/admin/api/v1/JobuserController.php b/app/controller/admin/api/v1/JobuserController.php index da9784e..14f65c8 100644 --- a/app/controller/admin/api/v1/JobuserController.php +++ b/app/controller/admin/api/v1/JobuserController.php @@ -38,9 +38,9 @@ class JobuserController if (!empty($data['key'])) { $key = $data['key']; $query->where(function ($query) use ($key) { - $query->where('username', 'like', '%' . $key . '%') - ->orWhere('invite_code', 'like', '%' . $key . '%') - ->orWhere('remark', 'like', '%' . $key . '%'); + $query->where('users.username', 'like', '%' . $key . '%') + ->orWhere('users.invite_code', 'like', '%' . $key . '%') + ->orWhere('users.remark', 'like', '%' . $key . '%'); }); } @@ -52,13 +52,24 @@ class JobuserController } // 使用 join 进行关联查询 f_id 对应的用户名称 - $users = $query->leftJoin('users as u', 'users.f_id', '=', 'u.id') // 假设 users 表有 id 字段,f_id 关联到父用户 - ->select('users.*', 'u.username as parent_username') // 选择用户表的字段和关联表的 username 字段 - ->orderBy('id', 'desc') - ->get(); // 或者使用 paginate() 来进行分页 + $users = $query->leftJoin('users as u', 'users.f_id', '=', 'u.id') // 假设 users 表有 id 字段,f_id 关联到父用户 + ->select( + 'users.id', + 'users.username', + 'users.updated_at', + 'users.invite_code', + 'users.login_time', + 'users.money', + 'users.remark', + 'users.status', + 'users.vip_id', + 'u.username as parent_username' // 选择所需字段,并为父用户用户名起别名 + )->where('users.isrobot',0) + ->orderBy('users.id', 'desc')->get(); // 确保按 users 表的 id 排序 - // 格式化结果为数组 - return ApiResponse::success(200, $users->toArray()); + + // 返回分页结果 + return ApiResponse::success(200, $users); } /** diff --git a/app/controller/admin/api/v1/PromotionController.php b/app/controller/admin/api/v1/PromotionController.php index 18d2449..884d885 100644 --- a/app/controller/admin/api/v1/PromotionController.php +++ b/app/controller/admin/api/v1/PromotionController.php @@ -14,31 +14,112 @@ use app\model\UserPhoneLog; use hg\apidoc\annotation as Apidoc; use app\model\Withdraw; use App\Utils\Random; + /** * @Apidoc\Title("admin推广链接控制器") * @Apidoc\Group("admin") */ class PromotionController -{ +{ /** - * @Apidoc\Title("管理员生成推广链接") - * @Apidoc\Url("admin/api/v1/Promotion/Generatelink") - * @Apidoc\Method("POST") - */ - public function Generatelink(Request $request){ - $invite_code=Random::str_random(7); - $Recommend =new Recommend(); - $Recommend->invite_code=$invite_code; - $Recommend->save(); + * @Apidoc\Title("管理员生成推广链接") + * @Apidoc\Url("admin/api/v1/Promotion/Generatelink") + * @Apidoc\Method("POST") + */ + public function Generatelink(Request $request) + { + $invite_code = UserDao::Createuser(); return ApiResponse::success(200, $invite_code); } /** - * @Apidoc\Title("获取推广列表所有") - * @Apidoc\Url("admin/api/v1/Promotion/list") - * @Apidoc\Method("POST") - */ - public function list(Request $request){ - $Recommend =Recommend::all(); - return ApiResponse::success(200, $Recommend); + * @Apidoc\Title("获取推广列表所有") + * @Apidoc\Url("admin/api/v1/Promotion/list") + * @Apidoc\Method("POST") + */ + public function list(Request $request) + { + // 获取请求的参数 + $data = $request->post(); + + // 构建查询构造器 + $query = User::query(); + + // 根据 key 进行模糊查询 + if (!empty($data['key'])) { + $key = $data['key']; + $query->where(function ($query) use ($key) { + $query->where('users.invite_code', 'like', '%' . $key . '%') + ->orWhere('users.remark', 'like', '%' . $key . '%'); + }); + } + + // 根据 status 过滤,假设 status 字段存在并且不是 -1 + if (isset($data['status']) && $data['status'] != -1) { + $status = (int)$data['status']; // 强制转换为整数 + // 使用 users 表的别名明确指定 status 字段 + $query->where('users.status', $status); + } + + // 使用 join 进行关联查询 f_id 对应的用户名称 + $users = $query->leftJoin('users as u', 'users.f_id', '=', 'u.id') // 假设 users 表有 id 字段,f_id 关联到父用户 + ->select( + 'users.id', + 'users.username', + 'users.updated_at', + 'users.invite_code', + 'users.login_time', + 'users.money', + 'users.remark', + 'users.status', + 'users.vip_id', + 'u.username as parent_username' // 选择所需字段,并为父用户用户名起别名 + )->where('users.isrobot', 1) + ->orderBy('users.id', 'desc')->get(); // 确保按 users 表的 id 排序 + return ApiResponse::success(200, $users); } -} \ No newline at end of file + + /** + * @Apidoc\Title(" 获取推广链接详细注册名单") + * @Apidoc\Url("admin/api/v1/Promotion/detailed") + * @Apidoc\Param("invite_code", type="string", require=true, desc="机器人的邀请码") + * @Apidoc\Param("start_date", type="string", require=false, desc="开始时间,格式:YYYY-MM-DD") + * @Apidoc\Param("end_date", type="string", require=false, desc="结束时间,格式:YYYY-MM-DD") + * @Apidoc\Method("POST") + */ + public function detailed(Request $request) + { + $data = $request->post(); + + // 获取机器人邀请码对应的用户 ID + $users = User::where('robot_invite_code', $data['invite_code'])->pluck('id')->toArray(); + + // 获取时间段参数,默认使用今天 + $startDate = isset($data['start_date']) ? $data['start_date'] : date('Y-m-d'); + $endDate = isset($data['end_date']) ? $data['end_date'] : date('Y-m-d'); + + // 获取用户手机号(按 user_id 分组)并根据时间范围筛选 + $UserPhone = UserPhone::whereIn('user_id', $users) + ->whereBetween('created_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']) // 时间范围筛选 + ->groupBy('user_id') + ->get(); + + // 获取注册的用户数量 + $res['register'] = count($users); + + // 获取绑定手机号的用户数量 + $res['binding'] = count($UserPhone); + + // 获取注册的用户详细信息(筛选注册时间段) + $res['register_user'] = User::whereIn('id', $users) + ->whereBetween('created_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']) // 时间范围筛选 + ->get(); + + // 获取绑定手机号的用户详细信息 + $userIdsWithPhones = $UserPhone->pluck('user_id')->toArray(); // 获取绑定手机号的用户 ID 列表 + $res['binding_user'] = User::whereIn('id', $userIdsWithPhones) + ->whereBetween('created_at', [$startDate . ' 00:00:00', $endDate . ' 23:59:59']) // 时间范围筛选 + ->get(); + + return ApiResponse::success(200, $res); + } +} diff --git a/app/controller/api/UserController.php b/app/controller/api/UserController.php index dfd027b..d71681d 100644 --- a/app/controller/api/UserController.php +++ b/app/controller/api/UserController.php @@ -91,10 +91,12 @@ class UserController $f_id = 0; $ff_id = 0; $length = strlen($invitation); + $user = new User(); if (!empty($invitation)) { if ($length == 7) { $Recommend = Recommend::where('invite_code', $invitation)->first(); if (!empty($Recommend)) { + $user->robot_invite_code = $invitation; $Recommend->register += 1; $Recommend->save(); } @@ -110,7 +112,7 @@ class UserController $f->vip_id += 1; } } - $user = new User(); + $col = ['username']; foreach ($col as $v) { $user->$v = $request->post($v); @@ -122,7 +124,6 @@ class UserController $user->password = password_hash($password, PASSWORD_DEFAULT); $user->save(); $user_new = User::where('username', $username)->first(); - var_dump($user_new); UserRewardDao::Register_for_free($user_new->id); return ApiResponseApp::success([], '注册成功'); } diff --git a/app/dao/UserDao.php b/app/dao/UserDao.php index 3a502af..97c4d81 100644 --- a/app/dao/UserDao.php +++ b/app/dao/UserDao.php @@ -159,7 +159,7 @@ class UserDao * 返回邀请码 */ public static function Createuser(){ - $invite_code=Random::str_random(5); + $invite_code=Random::str_random(7); $user=new User(); $user->join_ip = '127.0.0.1'; $user->f_id = 0; diff --git a/app/model/User.php b/app/model/User.php index dba316b..aeae304 100644 --- a/app/model/User.php +++ b/app/model/User.php @@ -33,6 +33,7 @@ use support\Model; * @property integer $created_at 创建时间 * @property integer $updatetime 更新时间 * @property integer $isrobot 是否是 管理员为了生成推广链接创建的机器人好做统计 0不是 1是机器人 + * @property string $robot_invite_code 机器人邀请码 为了统计推广邀请人数 */ class User extends Model {