['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(); } }