78 lines
2.5 KiB
PHP
78 lines
2.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\lists\stats;
|
|
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
use app\adminapi\logic\stats\PersonalStatsScopeTrait;
|
|
use app\common\lists\ListsExtendInterface;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\lists\Traits\HasDataScopeFilter;
|
|
use app\common\model\stats\PersonalAccountCost;
|
|
|
|
class PersonalAccountCostLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
|
{
|
|
use HasDataScopeFilter;
|
|
use PersonalStatsScopeTrait;
|
|
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'%like%' => ['media_source', 'creator_name', 'remark'],
|
|
];
|
|
}
|
|
|
|
private function baseQuery()
|
|
{
|
|
$query = PersonalAccountCost::where($this->searchWhere);
|
|
$visibleIds = $this->getDataScopeVisibleAdminIds();
|
|
$deptId = (int) ($this->params['dept_id'] ?? 0);
|
|
|
|
$finalIds = self::intersectVisibleByDept($visibleIds, $deptId);
|
|
if ($finalIds === []) {
|
|
$query->whereRaw('0 = 1');
|
|
} elseif ($finalIds !== null) {
|
|
$query->whereIn('creator_id', $finalIds);
|
|
}
|
|
|
|
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_source'])) {
|
|
$query->where('media_source', trim((string) $this->params['media_source']));
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function lists(): array
|
|
{
|
|
$rows = $this->baseQuery()
|
|
->order(['cost_date' => 'desc', 'id' => 'desc'])
|
|
->limit($this->limitOffset, $this->limitLength)
|
|
->select()
|
|
->toArray();
|
|
|
|
return self::attachDeptInfoToRows($rows);
|
|
}
|
|
|
|
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'),
|
|
];
|
|
}
|
|
}
|