Files
zyt/server/app/adminapi/lists/FanLists.php
2026-05-11 17:49:38 +08:00

50 lines
1.4 KiB
PHP
Executable File

<?php
namespace app\adminapi\lists;
use app\adminapi\lists\BaseAdminDataLists;
use app\common\model\Fan;
use app\common\model\FanVisitRecord;
use app\common\lists\ListsSearchInterface;
class FanLists extends BaseAdminDataLists implements ListsSearchInterface
{
public function setSearch(): array
{
return [
'%like%' => ['name', 'phone'],
'=' => ['gender', 'status'],
];
}
public function lists(): array
{
$lists = Fan::where($this->searchWhere)
->field(['id', 'name', 'phone', 'id_card', 'age', 'gender', 'remark', 'creator_id', 'creator_name', 'status', 'create_time', 'update_time'])
->append(['gender_desc', 'status_desc'])
->order(['id' => 'desc'])
->limit($this->limitOffset, $this->limitLength)
->select()
->toArray();
$fanIds = array_column($lists, 'id');
if (!empty($fanIds)) {
$visitCounts = FanVisitRecord::where('fan_id', 'in', $fanIds)
->where('delete_time', null)
->group('fan_id')
->column('count(*) as cnt', 'fan_id');
foreach ($lists as &$item) {
$item['visit_count'] = $visitCounts[$item['id']] ?? 0;
}
}
return $lists;
}
public function count(): int
{
return Fan::where($this->searchWhere)->count();
}
}