123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- namespace App\Admin\Controllers\ServicePacksManagment;
- use App\Admin\Actions\backstage\Service\ServiceDistributions;
- use App\Models\InsuranceAgreement;
- use App\Models\Nurse;
- use App\Models\ServicePack;
- use App\Models\SystemConfig;
- use App\Models\Team;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Show;
- class ServicePacksController extends AdminController
- {
- /**
- * Title for current resource.
- *
- * @var string
- */
- protected $title = '服务包列表';
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new ServicePack());
- $grid->tools(function (Grid\Tools $tools) {
- $tools->append(new ServiceDistributions());
- });
- $grid->filter(function ($filter){
- $filter->disableIdFilter();
- $filter->like('name','服务包名称');
- });
- $grid->model()->orderBy('id','desc');
- $grid->column('id', __('Id'));
- $grid->column('name', __('服务包名称'));
- $grid->column('intro', __('简介'));
- // $grid->column('desc', __('详细内容'))->limit();
- $grid->column('label','服务类型')->display(function (){
- $tag = [1 => '图文',2 => '电话',3 => '门诊',4 => '计免',5 => '儿保'];
- $datas = $this -> label;
- if($datas){
- for ($i=0;$i<count($datas);$i++){
- $str = $tag[$datas[$i]];
- $label[$i]= $str;
- }
- return $label;
- }
- return '无';
- })->label('info');
- $grid->column('price', __('价格'))->display(function ($money){
- return $money/100;
- });
- $grid->column('team_id', __('团队名称'))->display(function (){
- $modal = $this->team_id;
- if ($modal){
- for ($i=0; $i < count((array)$modal); $i++){
- $id = $modal[$i];
- $name[$i] = Team::where('id',$id)->value('name');
- }
- return $name;
- }
- return '通用';
- })->label('success');
- $grid->column('image','图片')->lightbox(['width' =>'', 'height' => 30]);
- $grid->column('is_need_insure', __('是否包含保险'))->using([0=>'不包含',1=>'包含']);
- $grid->column('insuranceagreement.name', __('保险协议名称'));
- $grid->column('phone_minutes', __('电话次数'));
- $grid->column('chat_num', __('图文次数'));
- $grid->column('appoint_num', __('门诊次数'));
- $grid->column('vaccine_limit_amount', __('计免次数'));
- $grid->column('nurses_limit_amount', __('儿保次数'));
- $grid->column('effective_days', __('服务时长'));
- $grid->column('created_at', __('创建时间'));
- $grid->column('updated_at', __('更新时间'));
- return $grid;
- }
- protected function detail($id)
- {
- $show = new Show(ServicePack::findOrFail($id));
- $show->field('id', 'ID');
- $show->field('name', __('服务包名称'));
- $show->field('intro', __('简介'));
- $show->field('desc', '详细内容')->unescape()->as(function ($avatar) {
- return $avatar;
- });
- $show->field('label', __('服务类型'))->unescape()->as(function ($label) {
- $arr = [];
- foreach ($label as $value){
- switch ($value)
- {
- case 1 :
- array_push($arr,'图文');
- break;
- case 2 :
- array_push($arr,'电话');
- break;
- case 3 :
- array_push($arr,'门诊');
- break;
- case 4 :
- array_push($arr,'门诊');
- break;
- case 5 :
- array_push($arr,'儿保');
- break;
- }
- }
- return $arr;
- })->label('info');
- $show->field('price','价格')->as(function ($price){
- return $price/100;
- });
- $show->field('team_id')->as(function ($team_id){
- $arr = [];
- if ($team_id == 0)
- {
- array_push($arr,'通用');
- return $arr;
- }
- foreach ($team_id as $value){
- $name = Team::where('id',$value)->value('name');
- array_push($arr,$name);
- }
- return $arr;
- })->label();
- $show->field('image','图片')->image();
- $show->field('is_need_insure', __('是否包含保险'))->using([0=>'不包含',1=>'包含']);
- $show->field('insuranceagreement.name', __('保险协议名称'));
- $show->field('phone_minutes', __('电话次数'));
- $show->field('chat_num', __('图文次数'));
- $show->field('appoint_num', __('门诊次数'));
- $show->field('vaccine_limit_amount', __('计免次数'));
- $show->field('nurses_limit_amount', __('儿保次数'));
- $show->field('effective_days', __('服务时长'));
- $show->field('created_at', __('创建时间'));
- $show->field('updated_at', __('更新时间'));
- return $show;
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- $form = new Form(new ServicePack());
- $form->editing(function ($f){
- $f->model()->price /=100;
- });
- $form->text('name', __('服务包名称'))->rules('required' ,['required'=>'请填写名称!']);
- $form->image('image','图片')->rules('required' ,['required'=>'请选择图片!']);
- $form->text('intro', __('简介'))->rules('required' ,['required'=>'请填写简介!']);;
- $form->editor('desc', __('详情内容'))->rules('required' ,['required'=>'请填写内容!']);;
- $form->number('price', __('价钱'))->default(0);
- $form->radio('is_need_insure', __('服务包是否包含保险'))->options([
- 0=>'否',
- 1=>'是'
- ])->when(1,function (Form $form){
- $form->select('agreement_id','协议名称')->options(InsuranceAgreement::pluck('name','id'))->rules('required',['required'=>'请选择协议名称']);
- })->rules('required',['required'=>'请选择是否包含保险']);
- $form->radio('is_need_team', __('是否包含团队'))->options([
- 0=>'否',
- 1=>'是'
- ])->when(1,function (Form $form){
- $form->multipleSelect('team_id', __('团队选择'))->options(Team::all()->pluck('name','id'))->rules('required',['required'=>'请选择团队']);;
- })->rules('required',['required'=>'请选择是否包含团队']);
- $form->checkbox('label','服务类型')
- ->options([
- 1 => '图文',
- 2 => '电话',
- 3 => '门诊',
- 4 => '计免',
- 5 => '儿保'
- ])->when('has',1,function (Form $form){
- $form->number('chat_num', __('图文次数'))->default(0);
- })->when('has',2,function (Form $form){
- $form->number('phone_minutes', __('电话次数'))->default(0);
- })->when('has',3,function (Form $form){
- $form->number('appoint_num', __('门诊次数'))->default(0);
- })->when('has',4,function (Form $form){
- $form->number('vaccine_limit_amount', __('儿保次数'))->default(0);
- })->when('has',5,function (Form $form){
- //暂未完成,这里展示所有的自费的儿保项目
- $form->number('nurses_limit_amount', __('计免次数'))->default(0);
- // $form->select('product', __('儿保项目'))->options(Nurse::where('type',2)->pluck('name','id'));
- })->rules('required',['required'=>'请选择服务类型']);
- $form->text('effective_days', __('服务时长(天)'))->default(0);
- $form->saving(function (Form $form){
- $form->price = $form->price*100;
- // dd($form->price);
- });
- return $form;
- }
- }
|