From 53f60bbf9419fa5c16957ba1cf365d606fd946d3 Mon Sep 17 00:00:00 2001 From: panliang <1163816051@qq.com> Date: Thu, 31 Aug 2023 18:00:27 +0800 Subject: [PATCH] admin --- app/Admin/Components.php | 3 ++- app/Admin/Controllers/PatientController.php | 12 +++++++++++- .../Controllers/PatientRecordController.php | 9 +++++---- app/Admin/Services/BaseService.php | 2 +- app/Admin/Services/PatientService.php | 17 +++++++++++++++++ app/Admin/routes.php | 1 + app/Models/Patient.php | 5 +++++ 7 files changed, 42 insertions(+), 7 deletions(-) diff --git a/app/Admin/Components.php b/app/Admin/Components.php index 2a29582..a9587b9 100644 --- a/app/Admin/Components.php +++ b/app/Admin/Components.php @@ -5,6 +5,7 @@ namespace App\Admin; use Slowlyo\OwlAdmin\Renderers\BaseRenderer; use Slowlyo\OwlAdmin\Renderers\WangEditor; use Slowlyo\OwlAdmin\Models\AdminUser; +use Slowlyo\OwlAdmin\Services\AdminUserService; class Components extends BaseRenderer { @@ -122,7 +123,7 @@ class Components extends BaseRenderer public function adminUserSelectControl() { - $options = AdminUser::get(); + $options = AdminUserService::make()->query()->get(); return amisMake()->SelectControl() ->options($options) ->searchable() diff --git a/app/Admin/Controllers/PatientController.php b/app/Admin/Controllers/PatientController.php index 344ae9c..08264db 100644 --- a/app/Admin/Controllers/PatientController.php +++ b/app/Admin/Controllers/PatientController.php @@ -8,7 +8,8 @@ use App\Admin\Services\PatientService; use Slowlyo\OwlAdmin\Controllers\AdminController; use Slowlyo\OwlAdmin\Renderers\Form; use Slowlyo\OwlAdmin\Renderers\Page; -use App\Models\Keyword; +use App\Models\{Keyword, Patient}; +use Illuminate\Http\Request; /** * 病人管理 @@ -145,4 +146,13 @@ class PatientController extends AdminController return $this->typeOptions; } + + public function getSelectOptions(Request $request) + { + $list = Patient::filter($request->all())->select(['id as value', 'name as label'])->sort()->get(); + + return $this->response()->success([ + 'items' => $list->items() + ]); + } } diff --git a/app/Admin/Controllers/PatientRecordController.php b/app/Admin/Controllers/PatientRecordController.php index 09b2825..e40eafd 100644 --- a/app/Admin/Controllers/PatientRecordController.php +++ b/app/Admin/Controllers/PatientRecordController.php @@ -10,6 +10,7 @@ use App\Admin\Services\PatientRecordService; use Slowlyo\OwlAdmin\Controllers\AdminController; use Slowlyo\OwlAdmin\Renderers\Form; use Slowlyo\OwlAdmin\Renderers\Page; +use Slowlyo\OwlAdmin\Services\AdminUserService; /** * 病历管理 @@ -69,7 +70,7 @@ class PatientRecordController extends AdminController ] ]), amisMake()->DateTimeControl()->name('treat_at')->label(__('patient_record.treat_at'))->value(now())->required(), - amisMake()->SelectControl()->options($this->getAdminUserOptions())->name('doctor_id')->label(__('patient_record.doctor_id'))->required(), + amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('doctor_id')->label(__('patient_record.doctor_id'))->required(), amisMake()->NumberControl()->name('origin_price')->label(__('patient_record.origin_price'))->required(), amisMake()->NumberControl()->name('sell_price')->label(__('patient_record.sell_price'))->required(), amisMake()->SelectControl()->options(OrderStatus::options())->name('order_status')->label(__('patient_record.order_status'))->default(OrderStatus::Success->value)->required(), @@ -80,7 +81,7 @@ class PatientRecordController extends AdminController ->initFetch(false) ->body(amisMake()->TextareaControl()->name('content')->label(__('patient_record.content'))), amisMake()->DateTimeControl()->name('next_treat_at')->label(__('patient_record.next_treat_at')), - amisMake()->SelectControl()->options($this->getAdminUserOptions())->name('notify_user_id')->label(__('patient_record.notify_user_id')), + amisMake()->SelectControl()->options($this->getAdminUserOptions())->searchable()->name('notify_user_id')->label(__('patient_record.notify_user_id')), amisMake()->DateTimeControl()->name('notify_at')->label(__('patient_record.notify_at')), amisMake()->TextControl()->name('notify_remarks')->label(__('patient_record.notify_remarks')), amisMake()->TextControl()->label(__('patient_record.creator_id'))->value($this->user()->name)->staitc(), @@ -119,7 +120,7 @@ class PatientRecordController extends AdminController public function getPatientOptions() { if (!$this->patientOptions) { - $this->patientOptions = Patient::select(['id as value', 'name as label'])->get(); + $this->patientOptions = Patient::select(['id as value', 'name as label'])->sort()->get(); } return $this->patientOptions; @@ -128,7 +129,7 @@ class PatientRecordController extends AdminController public function getAdminUserOptions() { if (!$this->adminUserOptions) { - $this->adminUserOptions = AdminUser::select(['id as value', 'name as label'])->get(); + $this->adminUserOptions = AdminUserService::make()->query()->select(['id as value', 'name as label'])->get(); } return $this->adminUserOptions; diff --git a/app/Admin/Services/BaseService.php b/app/Admin/Services/BaseService.php index 5c741df..06d3dee 100644 --- a/app/Admin/Services/BaseService.php +++ b/app/Admin/Services/BaseService.php @@ -79,7 +79,7 @@ class BaseService extends AdminService public function update($primaryKey, $data): bool { $data = $this->resloveData($data); - $model = $this->query()->whereKey($primaryKey)->first(); + $model = $this->query()->whereKey($primaryKey)->firstOrFail(); $validate = $this->validate($data, $model->id); if ($validate !== true) { $this->setError($validate); diff --git a/app/Admin/Services/PatientService.php b/app/Admin/Services/PatientService.php index 7eaf43b..806959a 100644 --- a/app/Admin/Services/PatientService.php +++ b/app/Admin/Services/PatientService.php @@ -14,6 +14,23 @@ class PatientService extends BaseService protected string $modelFilterName = PatientFilter::class; + 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); + } + + return $query->sort(); + } + /** * 处理表单数据 * diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 09c5ccb..17a029f 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -25,6 +25,7 @@ Route::group([ $router->get('keywords/tree-list', '\App\Admin\Controllers\KeywordsController@getTreeList')->name('api.keywords.tree-list'); $router->get('keywords/list', '\App\Admin\Controllers\KeywordsController@getList')->name('api.keywords.get_list'); $router->get('category/content', '\App\Admin\Controllers\CategoryController@getContent')->name('api.category.content'); + $router->get('patient/options', '\App\Admin\Controllers\PatientController@getSelectOptions')->name('api.patient.options'); }); // 字典表 diff --git a/app/Models/Patient.php b/app/Models/Patient.php index 825ca51..e7d2034 100644 --- a/app/Models/Patient.php +++ b/app/Models/Patient.php @@ -58,4 +58,9 @@ class Patient extends Model { return $this->belongsTo(AdminUser::class, 'doctor_id'); } + + public function scopeSort($q) + { + return $q->orderBy('id', 'desc'); + } }