支持后台用户手动录入个人业绩与账户消耗,独立计算转化指标,接入 DataScope 数据权限。 Co-authored-by: Cursor <cursoragent@cursor.com>
66 lines
2.0 KiB
PHP
66 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\lists\stats;
|
|
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
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;
|
|
|
|
public function setSearch(): array
|
|
{
|
|
return [
|
|
'%like%' => ['media_source', 'creator_name', 'remark'],
|
|
];
|
|
}
|
|
|
|
private function baseQuery()
|
|
{
|
|
$query = PersonalAccountCost::where($this->searchWhere);
|
|
$this->applyDataScopeByOwner($query, 'creator_id');
|
|
|
|
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->whereLike('media_source', '%' . trim((string) $this->params['media_source']) . '%');
|
|
}
|
|
|
|
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'),
|
|
];
|
|
}
|
|
}
|