代码优化
This commit is contained in:
@@ -195,6 +195,46 @@ class TrafficPoolBehavior extends Model
|
||||
->limit($limit)
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页获取用户行为轨迹
|
||||
* @param int $poolCompanyId
|
||||
* @param int $page 页码
|
||||
* @param int $pageSize 每页数量
|
||||
* @param string $keyword 搜索关键词(搜索行为名称)
|
||||
* @param int $behaviorType 行为类型筛选
|
||||
* @return array ['list' => [], 'total' => 0, 'page' => 1, 'pageSize' => 10]
|
||||
*/
|
||||
public static function getUserJourneyPaginated(int $poolCompanyId, int $page = 1, int $pageSize = 20, string $keyword = '', int $behaviorType = 0): array
|
||||
{
|
||||
$query = self::where('poolCompanyId', $poolCompanyId);
|
||||
|
||||
// 关键词搜索
|
||||
if (!empty($keyword)) {
|
||||
$query->where('behaviorName', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
|
||||
// 行为类型筛选
|
||||
if ($behaviorType > 0) {
|
||||
$query->where('behaviorType', $behaviorType);
|
||||
}
|
||||
|
||||
// 统计总数
|
||||
$total = $query->count();
|
||||
|
||||
// 分页查询
|
||||
$behaviors = $query->order('behaviorTime DESC')
|
||||
->page($page, $pageSize)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
return [
|
||||
'list' => $behaviors,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
'pageSize' => $pageSize
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user