|
@@ -0,0 +1,91 @@
|
|
|
|
+<?php
|
|
|
|
+
|
|
|
|
+namespace App\Community\Controllers\Vaccine;
|
|
|
|
+
|
|
|
|
+use App\Models\Organization;
|
|
|
|
+use App\Models\OrganizationVaccine;
|
|
|
|
+use App\Models\Vaccine;
|
|
|
|
+use Encore\Admin\Controllers\AdminController;
|
|
|
|
+use Encore\Admin\Facades\Admin;
|
|
|
|
+use Encore\Admin\Form;
|
|
|
|
+use Encore\Admin\Grid;
|
|
|
|
+use Encore\Admin\Show;
|
|
|
|
+
|
|
|
|
+class OrganizationVaccineController extends AdminController
|
|
|
|
+{
|
|
|
|
+ /**
|
|
|
|
+ * Title for current resource.
|
|
|
|
+ *
|
|
|
|
+ * @var string
|
|
|
|
+ */
|
|
|
|
+ protected $title = '机构疫苗';
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a grid builder.
|
|
|
|
+ *
|
|
|
|
+ * @return Grid
|
|
|
|
+ */
|
|
|
|
+ protected function grid()
|
|
|
|
+ {
|
|
|
|
+ $grid = new Grid(new OrganizationVaccine());
|
|
|
|
+
|
|
|
|
+ $org_id = Admin::user()->org_id;
|
|
|
|
+ if($org_id){
|
|
|
|
+ $grid->model()->where(['org_id'=>$org_id]);
|
|
|
|
+ }
|
|
|
|
+ $grid->disableCreateButton(false);
|
|
|
|
+
|
|
|
|
+ $grid->column('id', __('Id'));
|
|
|
|
+ $grid->column('organization.name', __('机构'));
|
|
|
|
+ $grid->column('vaccine.name', __('疫苗'));
|
|
|
|
+ $grid->column('stock', __('库存'));
|
|
|
|
+ $grid->column('created_at', __('创建时间'));
|
|
|
|
+ $grid->column('updated_at', __('更新时间'));
|
|
|
|
+
|
|
|
|
+ return $grid;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a show builder.
|
|
|
|
+ *
|
|
|
|
+ * @param mixed $id
|
|
|
|
+ * @return Show
|
|
|
|
+ */
|
|
|
|
+ protected function detail($id)
|
|
|
|
+ {
|
|
|
|
+ $show = new Show(OrganizationVaccine::findOrFail($id));
|
|
|
|
+
|
|
|
|
+ $show->field('id', __('Id'));
|
|
|
|
+ $show->field('org_id', __('Org id'));
|
|
|
|
+ $show->field('vaccine_id', __('Vaccine id'));
|
|
|
|
+ $show->field('stock', __('Stock'));
|
|
|
|
+ $show->field('created_at', __('Created at'));
|
|
|
|
+ $show->field('updated_at', __('Updated at'));
|
|
|
|
+
|
|
|
|
+ return $show;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Make a form builder.
|
|
|
|
+ *
|
|
|
|
+ * @return Form
|
|
|
|
+ */
|
|
|
|
+ protected function form()
|
|
|
|
+ {
|
|
|
|
+ $form = new Form(new OrganizationVaccine());
|
|
|
|
+ $is_admin = Admin::user()->isAdministrator();
|
|
|
|
+ if($is_admin){
|
|
|
|
+ if($form->isEditing()){
|
|
|
|
+ $form->select('org_id','机构')->options(Organization::pluck('name','id'))->disable();
|
|
|
|
+ } else {
|
|
|
|
+ $form->select('org_id','机构')->options(Organization::pluck('name','id'));
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ $form->hidden('org_id')->value(Admin::user()->org_id);
|
|
|
|
+ }
|
|
|
|
+ $form->select('vaccine_id', __('疫苗'))->options(Vaccine::pluck('name','id'));
|
|
|
|
+ $form->text('stock', __('库存'))->rules('required',['required'=>'请输入库存']);
|
|
|
|
+
|
|
|
|
+ return $form;
|
|
|
|
+ }
|
|
|
|
+}
|