fix: 优化时间范围内用户统计逻辑,确保日期格式合法性
This commit is contained in:
parent
b21a112022
commit
a461baf360
|
@ -28,7 +28,7 @@ class DashboardController
|
|||
$res = [];
|
||||
$res['user_total'] = User::count();
|
||||
$res['user_phone'] = UserPhone::count();
|
||||
$res['withdraw'] =withdraw::query()->distinct('user_id')->count('user_id'); // 统计不同的 user_id 个数;
|
||||
$res['withdraw'] = withdraw::query()->distinct('user_id')->count('user_id'); // 统计不同的 user_id 个数;
|
||||
$res['user_phone_onlin'] = UserPhone::where('status', 1)->count();
|
||||
return ApiResponse::success(200, $res);
|
||||
}
|
||||
|
@ -41,11 +41,11 @@ class DashboardController
|
|||
{
|
||||
$res = [];
|
||||
$res['user_total'] = User::count();
|
||||
$res['register'] = User::where('f_id',0)->count();
|
||||
$res['inviteregistration'] =User::where('f_id','>',0)->count(); // 统计不同的 user_id 个数;
|
||||
$res['register'] = User::where('f_id', 0)->count();
|
||||
$res['inviteregistration'] = User::where('f_id', '>', 0)->count(); // 统计不同的 user_id 个数;
|
||||
return ApiResponse::success(200, $res);
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* @Apidoc\Title("1.0 首页用户按照时间展示数据")
|
||||
* @Apidoc\Url("admin/api/v1/Dashboard/useranalysis_time")
|
||||
* @Apidoc\Method("POST")
|
||||
|
@ -56,20 +56,37 @@ class DashboardController
|
|||
* 登录人数 注册人数 提款人数 绑定手机号用户 默认今天
|
||||
*/
|
||||
$res = [];
|
||||
|
||||
// 获取今天的开始和结束时间
|
||||
|
||||
// 获取传递的时间参数
|
||||
$data = $request->post();
|
||||
$startOfDay = $data['start_time']; // 今天的开始时间(00:00:00)
|
||||
$endOfDay = $data['end_time']; // 今天的结束时间(23:59:59)
|
||||
|
||||
$login = User::whereBetween('login_time', [ $startOfDay, $endOfDay])->count();
|
||||
$registration = User::whereBetween('created_at', [ \Carbon\Carbon::createFromTimestamp($startOfDay)->toDateTimeString(), \Carbon\Carbon::createFromTimestamp($endOfDay)->toDateTimeString()])->count();
|
||||
$withdraw=Withdraw::whereBetween('createtime2', [ \Carbon\Carbon::createFromTimestamp($startOfDay)->toDateTimeString(), \Carbon\Carbon::createFromTimestamp($endOfDay)->toDateTimeString()])->count();;
|
||||
$binding=UserPhone::whereBetween('created_at', [ \Carbon\Carbon::createFromTimestamp($startOfDay)->toDateTimeString(), \Carbon\Carbon::createFromTimestamp($endOfDay)->toDateTimeString()])->distinct('user_id')->count('user_id');
|
||||
$res['login']=$login;
|
||||
$res['registration']=$registration;
|
||||
$res['withdraw']=$withdraw;
|
||||
$res['binding']=$binding;
|
||||
$startOfDay = $data['start_time']; // 开始时间
|
||||
$endOfDay = $data['end_time']; // 结束时间
|
||||
|
||||
// 确保 start_time 和 end_time 是合法的日期时间格式
|
||||
$startOfDay = \Carbon\Carbon::createFromTimestamp($startOfDay)->toDateTimeString();
|
||||
$endOfDay = \Carbon\Carbon::createFromTimestamp($endOfDay)->toDateTimeString();
|
||||
|
||||
// 获取在给定时间范围内登录的用户数量
|
||||
$login = User::whereBetween('login_time', [$startOfDay, $endOfDay])->count();
|
||||
|
||||
// 获取在给定时间范围内注册的用户数量
|
||||
$registration = User::whereBetween('created_at', [$startOfDay, $endOfDay])->count();
|
||||
|
||||
// 获取在给定时间范围内提款的用户数量
|
||||
$withdraw = Withdraw::whereBetween('createtime2', [$startOfDay, $endOfDay])->count();
|
||||
|
||||
// 获取在给定时间范围内绑定手机号的用户数量(distinct user_id)
|
||||
$binding = UserPhone::whereBetween('created_at', [$startOfDay, $endOfDay])
|
||||
->distinct('user_id') // 使用 distinct 去重 user_id
|
||||
->count('user_id');
|
||||
|
||||
// 将结果保存到返回数组中
|
||||
$res['login'] = $login;
|
||||
$res['registration'] = $registration;
|
||||
$res['withdraw'] = $withdraw;
|
||||
$res['binding'] = $binding;
|
||||
|
||||
// 返回结果
|
||||
return ApiResponse::success(200, $res);
|
||||
}
|
||||
/**
|
||||
|
@ -80,7 +97,7 @@ class DashboardController
|
|||
public function shopGetBalance(Request $request)
|
||||
{
|
||||
$res = [];
|
||||
$res['AmountAvailable']=PaymentNew::shopGetBalance();
|
||||
$res['AmountAvailable'] = PaymentNew::shopGetBalance();
|
||||
return ApiResponse::success(200, $res);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue