Files
huangjingfen/pro_v3.5.1/app/controller/admin/v1/statistic/UserStatistic.php
panchengyong c1e74d8e68 chore(php): 统一 ScottPan 文件头与注释域名替换
- 按 docs/renew-code-comment.md 将 PHP 文件头改为带边框的 Author 注释\n- 注释中的 crmeb.com 替换为 uj345.cn(代码字符串中的外链未改)\n- 新增 docs/renew-code-comment.md 说明

Made-with: Cursor
2026-03-29 11:22:58 +08:00

147 lines
3.7 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
namespace app\controller\admin\v1\statistic;
use app\controller\admin\AuthController;
use app\services\statistic\UserStatisticServices;
use think\annotation\Inject;
/**
* Class UserStatistic
* @package app\controller\admin\v1\statistic
*/
class UserStatistic extends AuthController
{
/**
* @var UserStatisticServices
*/
#[Inject]
protected UserStatisticServices $services;
/**
* 用户基础信息
* @return mixed
*/
public function getBasic()
{
$where = $this->request->getMore([
['channel_type', ''],
['data', '', '', 'time']
]);
$where['time'] = $this->getDay($where['time']);
return $this->success($this->services->getBasic($where));
}
/**
* 用户趋势
* @return mixed
*/
public function getTrend()
{
$where = $this->request->getMore([
['channel_type', ''],
['data', '', '', 'time']
]);
$where['time'] = $this->getDay($where['time']);
return $this->success($this->services->getTrend($where));
}
/**
* 微信用户信息
* @return mixed
*/
public function getWechat()
{
$where = $this->request->getMore([
['channel_type', ''],
['data', '', '', 'time']
]);
$where['time'] = $this->getDay($where['time']);
return $this->success($this->services->getWechat($where));
}
/**
* 微信用户趋势
* @return mixed
*/
public function getWechatTrend()
{
$where = $this->request->getMore([
['channel_type', ''],
['data', '', '', 'time']
]);
$where['time'] = $this->getDay($where['time']);
return $this->success($this->services->getWechatTrend($where));
}
/**
* 用户地域
* @return mixed
*/
public function getRegion()
{
$where = $this->request->getMore([
['channel_type', ''],
['data', '', '', 'time'],
['sort', 'allNum']
]);
$where['time'] = $this->getDay($where['time']);
return $this->success($this->services->getRegionV1($where));
}
/**
* 用户性别
* @return mixed
*/
public function getSex()
{
$where = $this->request->getMore([
['channel_type', ''],
['data', '', '', 'time']
]);
$where['time'] = $this->getDay($where['time']);
return $this->success($this->services->getSex($where));
}
/**
* 用户统计导出
* @return mixed
*/
public function getExcel()
{
$where = $this->request->getMore([
['channel_type', ''],
['data', '', '', 'time']
]);
$where['time'] = $this->getDay($where['time']);
return $this->success($this->services->getTrend($where, true));
}
/**
* 格式化时间
* @param $time
* @return string
*/
public function getDay($time)
{
if (strstr($time, '-') !== false) {
[$startTime, $endTime] = explode('-', $time);
if (!$startTime && !$endTime) {
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d 23:59:59", time());
} else {
if (strtotime($endTime) == strtotime(date('Y-m-d', strtotime($endTime)))) {
$endTime = $endTime . ' 23:59:59';
}
return $startTime . '-' . $endTime;
}
} else {
return date("Y/m/d", strtotime("-30 days", time())) . '-' . date("Y/m/d 23:59:59", time());
}
}
}