UserNoticeController.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <?php
  2. namespace App\Community\Controllers;
  3. use App\Admin\Actions\Community\Notice\sendNotice;
  4. use App\Models\Order;
  5. use App\Models\Patient;
  6. use Encore\Admin\Controllers\AdminController;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Show;
  11. class UserNoticeController extends AdminController
  12. {
  13. /**
  14. * Title for current resource.
  15. *
  16. * @var string
  17. */
  18. protected $title = '群发通知';
  19. /**
  20. * Make a grid builder.
  21. *
  22. * @return Grid
  23. */
  24. protected function grid()
  25. {
  26. $grid = new Grid(new Patient());
  27. $grid->model()->orderByDesc('id');
  28. $user = Admin::user();
  29. echo request('product_type');
  30. if(!empty(request('product_type'))){
  31. $user_ids = Order::whereIn('product_type',[4,5])->distinct('user_id')->pluck('user_id');
  32. $grid->model()->whereIn('user_id',$user_ids);
  33. }
  34. $grid->column('user.nickname', __('用户'));
  35. $grid->column('guardian_name', __('监护人'));
  36. $grid->column('name', __('患者'));
  37. $grid->column('relationship_type', __('关系'))->using([1=>'父亲',2=>'母亲',3=>'祖父',4=>'祖母',5=>'外祖父',6=>'外祖母',7=>'叔侄',8=>'其他']);
  38. $grid->column('phone', __('用户手机号'));
  39. $grid->column('birthday', __('出生日期'));
  40. $grid->filter(function ($flter){
  41. $flter->like('name','请输入患者姓名');
  42. $flter->like('user.nickname','用户');
  43. $flter->like('guardian_name','请输入监护人姓名');
  44. $flter->like('phone','电话');
  45. $flter->between('birthday','生日')->datetime();
  46. // $flter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
  47. $flter->equal('order.product_type','用户类型')->select([4=>'计免',5=>'儿保']);
  48. });
  49. $grid->actions(function ($actions){
  50. $actions->disableView();
  51. $actions->disableDelete();
  52. $actions->disableEdit();
  53. });
  54. $grid->batchActions(function ($batch) {
  55. $batch->disableDelete();
  56. $batch->add(new sendNotice());
  57. });
  58. return $grid;
  59. }
  60. /**
  61. * Make a show builder.
  62. *
  63. * @param mixed $id
  64. * @return Show
  65. */
  66. protected function detail($id)
  67. {
  68. $show = new Show(Order::findOrFail($id));
  69. $show->field('id', __('Id'));
  70. $show->field('user_id', __('User id'));
  71. $show->field('docter_id', __('Docter id'));
  72. $show->field('patient_id', __('Patient id'));
  73. $show->field('organization_id', __('Organization id'));
  74. $show->field('order_sn', __('Order sn'));
  75. $show->field('payment_type', __('Payment type'));
  76. $show->field('product_type', __('Product type'));
  77. $show->field('order_status', __('Order status'));
  78. $show->field('payment_status', __('Payment status'));
  79. $show->field('total_amount', __('Total amount'));
  80. $show->field('payment_amount', __('Payment amount'));
  81. $show->field('discount_amount', __('Discount amount'));
  82. $show->field('payment_time', __('Payment time'));
  83. $show->field('created_at', __('Created at'));
  84. $show->field('updated_at', __('Updated at'));
  85. return $show;
  86. }
  87. /**
  88. * Make a form builder.
  89. *
  90. * @return Form
  91. */
  92. protected function form()
  93. {
  94. $form = new Form(new Order());
  95. $form->number('user_id', __('User id'));
  96. $form->number('docter_id', __('Docter id'));
  97. $form->number('patient_id', __('Patient id'));
  98. $form->number('organization_id', __('Organization id'));
  99. $form->text('order_sn', __('Order sn'));
  100. $form->switch('payment_type', __('Payment type'))->default(1);
  101. $form->switch('product_type', __('Product type'))->default(1);
  102. $form->switch('order_status', __('Order status'))->default(1);
  103. $form->switch('payment_status', __('Payment status'))->default(1);
  104. $form->number('total_amount', __('Total amount'));
  105. $form->number('payment_amount', __('Payment amount'));
  106. $form->number('discount_amount', __('Discount amount'));
  107. $form->number('payment_time', __('Payment time'));
  108. return $form;
  109. }
  110. }