This commit is contained in:
parent
50c903f3ca
commit
eaf89ed282
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -14,6 +14,7 @@ use app\model\UserPhoneLog;
|
|||
use hg\apidoc\annotation as Apidoc;
|
||||
use app\model\Withdraw;
|
||||
use App\Utils\Random;
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("admin推广链接控制器")
|
||||
* @Apidoc\Group("admin")
|
||||
|
@ -21,24 +22,104 @@ use App\Utils\Random;
|
|||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
}
|
|
@ -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([], '注册成功');
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue