ServicePacksController.php 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <?php
  2. namespace App\Admin\Controllers\ServicePacksManagment;
  3. use App\Models\InsuranceAgreement;
  4. use App\Models\Nurse;
  5. use App\Models\ServicePack;
  6. use App\Models\SystemConfig;
  7. use App\Models\Team;
  8. use Encore\Admin\Controllers\AdminController;
  9. use Encore\Admin\Form;
  10. use Encore\Admin\Grid;
  11. use Encore\Admin\Show;
  12. class ServicePacksController extends AdminController
  13. {
  14. /**
  15. * Title for current resource.
  16. *
  17. * @var string
  18. */
  19. protected $title = '服务包列表';
  20. /**
  21. * Make a grid builder.
  22. *
  23. * @return Grid
  24. */
  25. protected function grid()
  26. {
  27. $grid = new Grid(new ServicePack());
  28. $grid->filter(function ($filter){
  29. $filter->disableIdFilter();
  30. $filter->like('name','服务包名称');
  31. });
  32. $grid->model()->orderBy('id','desc');
  33. $grid->column('id', __('Id'));
  34. $grid->column('name', __('服务包名称'));
  35. $grid->column('intro', __('简介'));
  36. // $grid->column('desc', __('详细内容'))->limit();
  37. $grid->column('label','服务类型')->display(function (){
  38. $tag = [1 => '图文',2 => '电话',3 => '门诊',4 => '计免',5 => '儿保'];
  39. $datas = $this -> label;
  40. if($datas){
  41. for ($i=0;$i<count($datas);$i++){
  42. $str = $tag[$datas[$i]];
  43. $label[$i]= $str;
  44. }
  45. return $label;
  46. }
  47. return '无';
  48. })->label('info');
  49. $grid->column('price', __('价格'))->display(function ($money){
  50. return $money/100;
  51. });
  52. $grid->column('team_id', __('团队名称'))->display(function (){
  53. $modal = $this->team_id;
  54. if ($modal){
  55. for ($i=0; $i < count((array)$modal); $i++){
  56. $id = $modal[$i];
  57. $name[$i] = Team::where('id',$id)->value('name');
  58. }
  59. return $name;
  60. }
  61. return '通用';
  62. })->label('success');
  63. $grid->column('image','图片')->lightbox(['width' =>'', 'height' => 30]);
  64. $grid->column('is_need_insure', __('是否包含保险'))->using([0=>'不包含',1=>'包含']);
  65. $grid->column('insuranceagreement.name', __('保险协议名称'));
  66. $grid->column('phone_minutes', __('电话次数'));
  67. $grid->column('chat_num', __('图文次数'));
  68. $grid->column('appoint_num', __('门诊次数'));
  69. $grid->column('vaccine_limit_amount', __('计免次数'));
  70. $grid->column('nurses_limit_amount', __('儿保次数'));
  71. $grid->column('effective_days', __('服务时长'));
  72. $grid->column('created_at', __('创建时间'));
  73. $grid->column('updated_at', __('更新时间'));
  74. return $grid;
  75. }
  76. protected function detail($id)
  77. {
  78. $show = new Show(ServicePack::findOrFail($id));
  79. $show->field('id', 'ID');
  80. $show->field('name', __('服务包名称'));
  81. $show->field('intro', __('简介'));
  82. $show->field('desc', '详细内容')->unescape()->as(function ($avatar) {
  83. return $avatar;
  84. });
  85. $show->field('label', __('服务类型'))->unescape()->as(function ($label) {
  86. $arr = [];
  87. foreach ($label as $value){
  88. switch ($value)
  89. {
  90. case 1 :
  91. array_push($arr,'图文');
  92. break;
  93. case 2 :
  94. array_push($arr,'电话');
  95. break;
  96. case 3 :
  97. array_push($arr,'门诊');
  98. break;
  99. case 4 :
  100. array_push($arr,'门诊');
  101. break;
  102. case 5 :
  103. array_push($arr,'儿保');
  104. break;
  105. }
  106. }
  107. return $arr;
  108. })->label('info');
  109. $show->field('price','价格')->as(function ($price){
  110. return $price/100;
  111. });
  112. $show->field('team_id')->as(function ($team_id){
  113. $arr = [];
  114. if ($team_id == 0)
  115. {
  116. array_push($arr,'通用');
  117. return $arr;
  118. }
  119. foreach ($team_id as $value){
  120. $name = Team::where('id',$value)->value('name');
  121. array_push($arr,$name);
  122. }
  123. return $arr;
  124. })->label();
  125. $show->field('image','图片')->image();
  126. $show->field('is_need_insure', __('是否包含保险'))->using([0=>'不包含',1=>'包含']);
  127. $show->field('insuranceagreement.name', __('保险协议名称'));
  128. $show->field('phone_minutes', __('电话次数'));
  129. $show->field('chat_num', __('图文次数'));
  130. $show->field('appoint_num', __('门诊次数'));
  131. $show->field('vaccine_limit_amount', __('计免次数'));
  132. $show->field('nurses_limit_amount', __('儿保次数'));
  133. $show->field('effective_days', __('服务时长'));
  134. $show->field('created_at', __('创建时间'));
  135. $show->field('updated_at', __('更新时间'));
  136. return $show;
  137. }
  138. /**
  139. * Make a form builder.
  140. *
  141. * @return Form
  142. */
  143. protected function form()
  144. {
  145. $form = new Form(new ServicePack());
  146. $form->editing(function ($f){
  147. $f->model()->price /=100;
  148. });
  149. $form->text('name', __('服务包名称'))->rules('required' ,['required'=>'请填写名称!']);
  150. $form->image('image','图片')->rules('required' ,['required'=>'请选择图片!']);
  151. $form->text('intro', __('简介'))->rules('required' ,['required'=>'请填写简介!']);;
  152. $form->editor('desc', __('详情内容'))->rules('required' ,['required'=>'请填写内容!']);;
  153. $form->number('price', __('价钱'))->default(0);
  154. $form->radio('is_need_insure', __('服务包是否包含保险'))->options([
  155. 0=>'否',
  156. 1=>'是'
  157. ])->when(1,function (Form $form){
  158. $form->select('agreement_id','协议名称')->options(InsuranceAgreement::pluck('name','id'))->rules('required',['required'=>'请选择协议名称']);
  159. })->rules('required',['required'=>'请选择是否包含保险']);
  160. $form->radio('is_need_team', __('是否包含团队'))->options([
  161. 0=>'否',
  162. 1=>'是'
  163. ])->when(1,function (Form $form){
  164. $form->multipleSelect('team_id', __('团队选择'))->options(Team::all()->pluck('name','id'))->rules('required',['required'=>'请选择团队']);;
  165. })->rules('required',['required'=>'请选择是否包含团队']);
  166. $form->checkbox('label','服务类型')
  167. ->options([
  168. 1 => '图文',
  169. 2 => '电话',
  170. 3 => '门诊',
  171. 4 => '计免',
  172. 5 => '儿保'
  173. ])->when('has',1,function (Form $form){
  174. $form->number('chat_num', __('图文次数'))->default(0);
  175. })->when('has',2,function (Form $form){
  176. $form->number('phone_minutes', __('电话次数'))->default(0);
  177. })->when('has',3,function (Form $form){
  178. $form->number('appoint_num', __('门诊次数'))->default(0);
  179. })->when('has',4,function (Form $form){
  180. $form->number('vaccine_limit_amount', __('儿保次数'))->default(0);
  181. })->when('has',5,function (Form $form){
  182. //暂未完成,这里展示所有的自费的儿保项目
  183. $form->number('nurses_limit_amount', __('计免次数'))->default(0);
  184. // $form->select('product', __('儿保项目'))->options(Nurse::where('type',2)->pluck('name','id'));
  185. })->rules('required',['required'=>'请选择服务类型']);
  186. $form->text('effective_days', __('服务时长(天)'))->default(0);
  187. $form->saving(function (Form $form){
  188. $form->price = $form->price*100;
  189. // dd($form->price);
  190. });
  191. return $form;
  192. }
  193. }