$searchFields, ]; } private function baseQuery() { $query = AccountCost::where($this->searchWhere); if (!empty($this->params['start_date']) && !empty($this->params['end_date'])) { $query->whereBetween('cost_date', [$this->params['start_date'], $this->params['end_date']]); } elseif (!empty($this->params['start_date'])) { $query->where('cost_date', '>=', $this->params['start_date']); } elseif (!empty($this->params['end_date'])) { $query->where('cost_date', '<=', $this->params['end_date']); } if (!empty($this->params['media_channel_code'])) { $query->where('media_channel_code', trim((string) $this->params['media_channel_code'])); } if (AccountCost::supportsDeptBinding() && !empty($this->params['dept_id'])) { $query->where('dept_id', (int) $this->params['dept_id']); } return $query; } public function lists(): array { return $this->baseQuery() ->order(['cost_date' => 'desc', 'id' => 'desc']) ->limit($this->limitOffset, $this->limitLength) ->select() ->toArray(); } public function count(): int { return (int) $this->baseQuery()->count(); } public function extend(): array { return [ 'total_amount' => round((float) $this->baseQuery()->sum('amount'), 2), 'days_count' => (int) $this->baseQuery()->distinct(true)->count('cost_date'), 'media_channel_options' => MediaChannelService::getOptions(), 'media_channel_groups' => MediaChannelService::getOptionGroups(), 'dept_options' => DeptLogic::getAllData(), 'supports_dept_binding' => AccountCost::supportsDeptBinding(), 'default_media_channel_code' => MediaChannelService::getDefaultCode(), ]; } }