Files
huangjingfen/pro_v3.5.1/app/dao/user/UserVisitDao.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

84 lines
2.3 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | Author: ScottPan Team
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\dao\user;
use app\dao\BaseDao;
use app\model\user\UserVisit;
/**
*
* Class UserVisitDao
* @package app\dao\user
*/
class UserVisitDao extends BaseDao
{
/**
* 设置模型
* @return string
*/
protected function setModel(): string
{
return UserVisit::class;
}
/**
* 用户趋势数据
* @param $time
* @param $type
* @param $timeType
* @param $str
* @return mixed
*/
public function getTrendData($time, $type, $timeType, $str)
{
return $this->getModel()->when($type != '', function ($query) use ($type) {
$query->where('channel_type', $type);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field("FROM_UNIXTIME(add_time,'$timeType') as days,$str as num")->group('days')->select()->toArray();
}
/**
* 用户地域数据
* @param $time
* @param $userType
* @return mixed
*/
public function getRegion($time, $userType)
{
return $this->getModel()->when($userType != '', function ($query) use ($userType) {
$query->where('channel_type', $userType);
})->where(function ($query) use ($time) {
if ($time[0] == $time[1]) {
$query->whereDay('add_time', $time[0]);
} else {
$time[1] = date('Y-m-d', strtotime($time[1]) + 86400);
$query->whereTime('add_time', 'between', $time);
}
})->field('COUNT(distinct(uid)) as visitNum,province')
->group('province')->select()->toArray();
}
/**
* 根据分组获取记录条数
* @param array $where
* @param string $group
* @return mixed
*/
public function groupCount(array $where, string $group = 'uid')
{
return $this->search($where)->group($group)->count();
}
}