1
0
Fork 0

admin total-record

master
panliang 2023-09-01 10:08:32 +08:00
parent 53f60bbf94
commit 73664e4e37
7 changed files with 176 additions and 4 deletions

View File

@ -0,0 +1,85 @@
<?php
namespace App\Admin\Controllers;
use Slowlyo\OwlAdmin\Controllers\AdminController;
use App\Models\{Patient, PatientRecord};
use Illuminate\Support\Facades\DB;
use App\Admin\Services\TotalRecordService;
/**
* 财务统计
*/
class TotalRecordController extends AdminController
{
protected string $serviceName = TotalRecordService::class;
protected $patientOptions;
// public function index()
// {
// $list = PatientRecord::with(['patient'])->filter(request()->all())->groupBy('patient_id')->select([
// 'patient_id',
// DB::raw('count(1) as count'),
// DB::raw('sum(`origin_price`) as `origin_price`'),
// DB::raw('sum(`sell_price`) as `sell_price`'),
// ])->get();
// if ($this->actionOfGetData()) {
// return $this->response()->success(['items' => $list]);
// }
// return $this->response()->success($this->basePage()->data(['items' => $list])->className('cxd-Crud')->body([
// $this->baseFilter()->actions()->mode('inline')->body([
// amisMake()->SelectControl()->options($this->getPatientOptions())->searchable()->name('patient_id')->label(__('patient_record.patient_id'))->size('md')->clearable(),
// amisMake()->DateRangeControl()->name('treat_range')->label(__('total-record.treat_at'))->clearable()->size('md'),
// amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
// ]),
// amisMake()->Table()->affixHeader(false)->source('${items}')->columns([
// amisMake()->Column()->name('patient.name')->label(__('total-record.name')),
// amisMake()->Column()->name('count')->label(__('total-record.count')),
// amisMake()->Column()->name('origin_price')->label(__('total-record.origin_price')),
// amisMake()->Column()->name('sell_price')->label(__('total-record.sell_price')),
// ]),
// ]));
// }
public function list()
{
$crud = $this->baseCRUD()
->filterTogglable(false)
->columnsTogglable(false)
->headerToolbar([
// amis('reload')->align('right'),
])
->filter($this->baseFilter()->actions()->body([
amisMake()->SelectControl()->options($this->getPatientOptions())->searchable()->name('patient_id')->label(__('patient_record.patient_id'))->size('md')->clearable(),
amisMake()->DateRangeControl()->name('treat_range')->label(__('total-record.treat_at'))->clearable()->size('md'),
// amisMake()->Button()->label(__('admin.reset'))->actionType('clear-and-submit'),
amisMake()->Component()->setType('submit')->label(__('admin.search'))->level('primary'),
]))
->columns([
amisMake()->Column()->name('patient.name')->label(__('total-record.name')),
amisMake()->Date()->name('min_treat_at')->label(__('total-record.min_treat_at'))->sortable(true),
amisMake()->Date()->name('max_treat_at')->label(__('total-record.max_treat_at'))->sortable(true),
amisMake()->Column()->name('count')->label(__('total-record.count'))->sortable(true),
amisMake()->Column()->name('origin_price')->label(__('total-record.origin_price'))->sortable(true),
amisMake()->Column()->name('sell_price')->label(__('total-record.sell_price'))->sortable(true),
])->affixRowClassName('text-info-dk')->affixRow([
['type' => 'text', 'text' => '总计', 'colSpan' => 3],
['type' => 'text', 'text' => '记录数: ${total}'],
['type' => 'text', 'text' => __('total-record.origin_price') . ': ${origin_price}'],
['type' => 'text', 'text' => __('total-record.sell_price') . ': ${sell_price}'],
]);
return $this->baseList($crud);
}
public function getPatientOptions()
{
if (!$this->patientOptions) {
$this->patientOptions = Patient::select(['id as value', 'name as label'])->sort()->get();
}
return $this->patientOptions;
}
}

View File

@ -2,7 +2,7 @@
namespace App\Admin\Services;
use App\ModelFilters\PatienRecordFilter;
use App\ModelFilters\PatientRecordFilter;
use App\Models\PatientRecord;
use Illuminate\Support\Facades\Validator;
use Slowlyo\OwlAdmin\Admin;
@ -13,7 +13,7 @@ class PatientRecordService extends BaseService
protected array $withRelationships = ['doctor', 'patient'];
protected string $modelFilterName = PatienRecordFilter::class;
protected string $modelFilterName = PatientRecordFilter::class;
public function listQuery()
{

View File

@ -0,0 +1,72 @@
<?php
namespace App\Admin\Services;
use App\Models\PatientRecord;
use App\ModelFilters\PatientRecordFilter;
use Illuminate\Support\Facades\DB;
class TotalRecordService extends BaseService
{
protected string $modelName = PatientRecord::class;
protected array $withRelationships = ['patient'];
protected string $modelFilterName = PatientRecordFilter::class;
public function getModelFilter()
{
return $this->modelFilterName;
}
public function primaryKey()
{
return 'patient_id';
}
public function sortColumn()
{
return 'patient_id';
}
public function listQuery()
{
$model = $this->getModel();
$filter = $this->getModelFilter();
$query = $this->query();
if ($this->withRelationships) {
$query->with($this->withRelationships);
}
if ($filter) {
$query->filter(request()->input(), $filter);
}
$query->select([
'patient_id',
DB::raw('count(1) as count'),
DB::raw('sum(`origin_price`) as `origin_price`'),
DB::raw('sum(`sell_price`) as `sell_price`'),
DB::raw('min(`treat_at`) as `min_treat_at`'),
DB::raw('max(`treat_at`) as `max_treat_at`'),
])->groupBy('patient_id');
$this->sortable($query);
return $query;
}
public function list()
{
$query = $this->listQuery();
$list = (clone $query)->paginate(request()->input('perPage', 20));
$items = $list->items();
$total = $list->total();
$origin_price = (new PatientRecordService())->listQuery()->sum('origin_price');
$sell_price = (new PatientRecordService())->listQuery()->sum('sell_price');
return compact('items', 'total', 'sell_price', 'origin_price');
}
}

View File

@ -36,4 +36,7 @@ Route::group([
$router->resource('patient', \App\Admin\Controllers\PatientController::class)->names('admin.patient');
// 病历管理
$router->resource('record', \App\Admin\Controllers\PatientRecordController::class)->names('admin.patient_record');
// 财务统计
$router->get('total/record', [\App\Admin\Controllers\TotalRecordController::class, 'index']);
});

View File

@ -5,7 +5,7 @@ namespace App\ModelFilters;
use EloquentFilter\ModelFilter;
use Carbon\Carbon;
class PatienRecordFilter extends ModelFilter
class PatientRecordFilter extends ModelFilter
{
/**
* Related Models that have ModelFilters as well as the method on the ModelFilter

View File

@ -22,7 +22,8 @@ class AdminMenuSeeder extends Seeder
['title' => '分类管理', 'icon' => 'icon-park:all-application', 'url' => '/category', 'order' => 2],
['title' => '病人管理', 'icon' => 'icon-park:peoples-two', 'url' => '/patient', 'order' => 3],
['title' => '病历管理', 'icon' => 'icon-park:newspaper-folding', 'url' => '/record', 'order' => 4],
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'order' => 5, 'children' => [
['title' => '财务统计', 'icon' => 'icon-park:data-file', 'url' => '/total/record', 'order' => 5],
['title' => '系统管理', 'icon' => 'icon-park:setting', 'url' => '/system', 'order' => 6, 'children' => [
['title' => '用户管理', 'icon' => 'icon-park:people-plus', 'url' => '/system/admin_users', 'order' => 1],
['title' => '角色管理', 'icon' => 'icon-park:people-plus-one', 'url' => '/system/admin_roles', 'order' => 2],
['title' => '权限管理', 'icon' => 'icon-park:key-one', 'url' => '/system/admin_permissions', 'order' => 3],

View File

@ -0,0 +1,11 @@
<?php
return [
'name' => '姓名',
'treat_at' => '时间段',
'min_treat_at' => '开始时间',
'max_treat_at' => '结束时间',
'count' => '看病次数',
'origin_price' => '划价总金额',
'sell_price' => '实收总金额',
];