77 lines
2.5 KiB
PHP
Executable File
77 lines
2.5 KiB
PHP
Executable File
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace app\adminapi\lists\finance;
|
|
|
|
use app\adminapi\logic\dept\DeptLogic;
|
|
use app\adminapi\lists\BaseAdminDataLists;
|
|
use app\common\lists\ListsExtendInterface;
|
|
use app\common\lists\ListsSearchInterface;
|
|
use app\common\model\finance\AccountCost;
|
|
use app\common\service\qywx\MediaChannelService;
|
|
|
|
class AccountCostLists extends BaseAdminDataLists implements ListsSearchInterface, ListsExtendInterface
|
|
{
|
|
public function setSearch(): array
|
|
{
|
|
$searchFields = ['remark', 'creator_name', 'updater_name'];
|
|
if (AccountCost::supportsDeptBinding()) {
|
|
$searchFields[] = 'dept_name';
|
|
}
|
|
|
|
return [
|
|
'%like%' => $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(),
|
|
'dept_options' => DeptLogic::getAllData(),
|
|
'supports_dept_binding' => AccountCost::supportsDeptBinding(),
|
|
'default_media_channel_code' => MediaChannelService::getDefaultCode(),
|
|
];
|
|
}
|
|
}
|