ServicePacksController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <?php
  2. namespace App\Admin\Controllers\ServicePacksManagment;
  3. use App\Models\Nurse;
  4. use App\Models\ServicePack;
  5. use App\Models\Team;
  6. use Encore\Admin\Controllers\AdminController;
  7. use Encore\Admin\Form;
  8. use Encore\Admin\Grid;
  9. use Encore\Admin\Show;
  10. class ServicePacksController extends AdminController
  11. {
  12. /**
  13. * Title for current resource.
  14. *
  15. * @var string
  16. */
  17. protected $title = '服务包列表';
  18. /**
  19. * Make a grid builder.
  20. *
  21. * @return Grid
  22. */
  23. protected function grid()
  24. {
  25. $grid = new Grid(new ServicePack());
  26. $grid->actions(function ($actions){
  27. $actions->disableView();
  28. });
  29. $grid->filter(function ($filter){
  30. $filter->disableIdFilter();
  31. $filter->like('name','服务包名称');
  32. });
  33. $grid->model()->orderBy('id','desc');
  34. $grid->column('id', __('Id'));
  35. $grid->column('name', __('服务包名称'));
  36. $grid->column('intro', __('简介'));
  37. $grid->column('desc', __('详细内容'))->limit(100);
  38. $grid->column('label','服务类型')->display(function (){
  39. $tag = [1 => '图文',2 => '电话',3 => '门诊',4 => '计免',5 => '儿保'];
  40. $datas = $this -> label;
  41. if($datas){
  42. for ($i=0;$i<count($datas);$i++){
  43. $str = $tag[$datas[$i]];
  44. $label[$i]= $str;
  45. }
  46. return $label;
  47. }
  48. return '无';
  49. })->label('info');
  50. $grid->column('price', __('价格'))->display(function ($money){
  51. return $money/100;
  52. });
  53. $grid->column('team_id', __('团队名称'))->display(function (){
  54. $modal = $this->team_id;
  55. if ($modal){
  56. for ($i=0; $i < count((array)$modal); $i++){
  57. $id = $modal[$i];
  58. $name[$i] = Team::where('id',$id)->value('name');
  59. }
  60. return $name;
  61. }
  62. return '通用';
  63. })->label('success');
  64. $grid->column('image','图片')->lightbox(['width' =>'', 'height' => 30]);
  65. $grid->column('is_need_insure', __('是否包含保险'))->using([0=>'不包含',1=>'包含']);
  66. $grid->column('insuranceagreement.name', __('保险协议名称'));
  67. $grid->column('phone_minutes', __('电话次数'));
  68. $grid->column('chat_num', __('图文次数'));
  69. $grid->column('appoint_num', __('门诊次数'));
  70. $grid->column('vaccine_limit_amount', __('计免次数'));
  71. $grid->column('nurses_limit_amount', __('儿保次数'));
  72. $grid->column('effective_days', __('服务时长'));
  73. $grid->column('created_at', __('创建时间'));
  74. $grid->column('updated_at', __('更新时间'));
  75. return $grid;
  76. }
  77. /**
  78. * Make a form builder.
  79. *
  80. * @return Form
  81. */
  82. protected function form()
  83. {
  84. $form = new Form(new ServicePack());
  85. $form->editing(function ($f){
  86. $f->model()->price /=100;
  87. });
  88. $form->text('name', __('服务包名称'))->rules('required' ,['required'=>'请填写名称!']);
  89. $form->image('image','图片')->rules('required' ,['required'=>'请选择图片!']);
  90. $form->text('intro', __('简介'))->rules('required' ,['required'=>'请填写简介!']);;
  91. $form->editor('desc', __('详情内容'))->rules('required' ,['required'=>'请填写内容!']);;
  92. $form->number('price', __('价钱'))->default(0);
  93. $form->radio('is_need_insure', __('服务包是否包含保险'))->options([
  94. 0=>'否',
  95. 1=>'是'
  96. ])->rules('required',['required'=>'请选择是否包含保险']);
  97. $form->radio('is_need_team', __('是否包含团队'))->options([
  98. 0=>'否',
  99. 1=>'是'
  100. ])->when(1,function (Form $form){
  101. $form->multipleSelect('team_id', __('团队选择'))->options(Team::all()->pluck('name','id'))->rules('required',['required'=>'请选择团队']);;
  102. })->rules('required',['required'=>'请选择是否包含团队']);
  103. $form->checkbox('label','服务类型')
  104. ->options([
  105. 1 => '图文',
  106. 2 => '电话',
  107. 3 => '门诊',
  108. 4 => '计免',
  109. 5 => '儿保'
  110. ])->when('has',1,function (Form $form){
  111. $form->number('chat_num', __('图文次数'))->default(0);
  112. })->when('has',2,function (Form $form){
  113. $form->number('phone_minutes', __('电话次数'))->default(0);
  114. })->when('has',3,function (Form $form){
  115. $form->number('appoint_num', __('门诊次数'))->default(0);
  116. })->when('has',4,function (Form $form){
  117. $form->number('vaccine_limit_amount', __('儿保金额'))->default(0);
  118. })->when('has',5,function (Form $form){
  119. //暂未完成,这里展示所有的自费的儿保项目
  120. $form->number('nurses_limit_amount', __('计免金额'))->default(0);
  121. // $form->select('product', __('儿保项目'))->options(Nurse::where('type',2)->pluck('name','id'));
  122. })->rules('required',['required'=>'请选择服务类型']);
  123. $form->text('effective_days', __('服务时长(天)'))->default(0);
  124. $form->saving(function (Form $form){
  125. $form->price = $form->price*100;
  126. // dd($form->price);
  127. });
  128. return $form;
  129. }
  130. }