ServicePacksController.php 8.2 KB

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