You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yanzong/app/api/service/statistics/UserData.php

68 lines
2.0 KiB

9 months ago
<?php
namespace app\api\service\statistics;
9 months ago
use app\api\model\GoodsBrowseLog;
9 months ago
use app\api\model\User;
9 months ago
use app\common\service\BaseService;
class UserData extends BaseService
{
9 months ago
protected User $userModel;
public function initialize()
{
parent::initialize(); // TODO: Change the autogenerated stub
$this->userModel = new User();
}
public function getUserData($startDate = null, $endDate = null): array
9 months ago
{
return [
9 months ago
'visitorCount' => $this->getVisitorCount($startDate, $endDate),
9 months ago
'viewCount' => $this->getViewCount($startDate, $endDate),
9 months ago
'newUserCount' => $this->getNewUserCount($startDate, $endDate),
9 months ago
];
}
9 months ago
/**
* 用户访问总数
*/
9 months ago
public function getVisitorCount($startDate = null, $endDate = null) {
$query = new GoodsBrowseLog();
$filter = [];
if (!is_null($startDate) && !is_null($endDate)) {
$filter[] = ['ctime', '>=', $startDate];
$filter[] = ['ctime', '<', $endDate];
}
$value = $query->where($filter)->group('user_id')->count();
return number_format($value);
9 months ago
}
/**
* 用户浏览总数
*/
public function getViewCount($startDate = null, $endDate = null): string
{
$query = new GoodsBrowseLog();
9 months ago
$filter = [];
if (!is_null($startDate) && !is_null($endDate)) {
$filter[] = ['ctime', '>=', $startDate];
$filter[] = ['ctime', '<', $endDate];
9 months ago
}
9 months ago
$value = $query->where($filter)->count();
9 months ago
return number_format($value);
}
/**
* 新用户数量
*/
9 months ago
public function getNewUserCount($startDate = null, $endDate = null) {
$filter = [];
if (!is_null($startDate) && !is_null($endDate)) {
$filter[] = ['create_time', '>=', strtotime($startDate)];
$filter[] = ['create_time', '<', strtotime($endDate) + 86400];
}
$value = $this->userModel->where($filter)->group('user_id')->count();
return number_format($value);
9 months ago
}
9 months ago
}