104 lines
3.5 KiB
PHP
104 lines
3.5 KiB
PHP
<?php
|
||
|
||
namespace app\controller\admin\api\v1;
|
||
|
||
use app\dao\UserDao;
|
||
use support\Request;
|
||
use App\Utils\ApiResponse;
|
||
use App\model\Admin;
|
||
use app\model\User;
|
||
use app\model\UserPhone;
|
||
use hg\apidoc\annotation as Apidoc;
|
||
use app\model\Withdraw;
|
||
use App\Utils\API\PaymentNew;
|
||
|
||
/**
|
||
* @Apidoc\Title("首页展示数据")
|
||
* @Apidoc\Group("admin")
|
||
*/
|
||
class DashboardController
|
||
{
|
||
/**
|
||
* @Apidoc\Title("1.0 首页展示数据")
|
||
* @Apidoc\Url("admin/api/v1/Dashboard/index")
|
||
* @Apidoc\Method("POST")
|
||
*/
|
||
public function index(Request $request)
|
||
{
|
||
$res = [];
|
||
$res['user_total'] = User::count();
|
||
$res['user_phone'] = UserPhone::count();
|
||
$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);
|
||
}
|
||
/**
|
||
* @Apidoc\Title("1.0 首页用户注册分析")
|
||
* @Apidoc\Url("admin/api/v1/Dashboard/useranalysis")
|
||
* @Apidoc\Method("POST")
|
||
*/
|
||
public function useranalysis(Request $request)
|
||
{
|
||
$res = [];
|
||
$res['user_total'] = User::count();
|
||
$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")
|
||
*/
|
||
public function useranalysis_time(Request $request)
|
||
{
|
||
/**
|
||
* 登录人数 注册人数 提款人数 绑定手机号用户 默认今天
|
||
*/
|
||
$res = [];
|
||
|
||
// 获取传递的时间参数
|
||
$data = $request->post();
|
||
$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);
|
||
}
|
||
/**
|
||
* @Apidoc\Title("1.0 查询第三方支付余额")
|
||
* @Apidoc\Url("admin/api/v1/Dashboard/shopGetBalance")
|
||
* @Apidoc\Method("POST")
|
||
*/
|
||
public function shopGetBalance(Request $request)
|
||
{
|
||
$res = [];
|
||
$res['AmountAvailable'] = PaymentNew::shopGetBalance();
|
||
return ApiResponse::success(200, $res);
|
||
}
|
||
}
|