fix: 优化时间范围内用户统计逻辑,确保日期格式合法性

This commit is contained in:
lingling 2025-02-28 18:45:49 +08:00
parent b21a112022
commit a461baf360
1 changed files with 35 additions and 18 deletions

View File

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