- 模型去掉 defaultSoftDelete=0,避免 ThinkPHP 软删过滤导致新增记录"隐形" - 菜单 paths 改相对路径并新增「自录数据统计」目录,迁移已有菜单 - Lists/Overview 补部门关联、支持按部门筛选 - 数据权限改由 self_input_stats_view_all_roles 白名单 + DataScope 控制, 编辑/删除完全交给按钮权限校验(移除"仅本人可改"硬限制) - 新增 /stats.self_input/mediaSourceOptions 接口,统计页/账户消耗页/录入弹窗 共用 useMediaSourceOptions + MediaSourceSelect,去重动态加载 Co-authored-by: Cursor <cursoragent@cursor.com>
78 lines
2.4 KiB
PHP
78 lines
2.4 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'),
|
|
];
|
|
}
|
|
}
|