DocterChatController.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace App\Community\Controllers;
  3. use App\Admin\Actions\Community\Docter\Chat;
  4. use App\Admin\Actions\Community\Notice\sendNotice;
  5. use App\Admin\Actions\Community\Order\Detail;
  6. use App\Models\Docter;
  7. use App\Models\DocterOrganization;
  8. use App\Models\Order;
  9. use Encore\Admin\Controllers\AdminController;
  10. use Encore\Admin\Facades\Admin;
  11. use Encore\Admin\Form;
  12. use Encore\Admin\Grid;
  13. use Encore\Admin\Layout\Content;
  14. use Encore\Admin\Show;
  15. use App\Models\User;
  16. class DocterChatController extends AdminController
  17. {
  18. /**
  19. * Title for current resource.
  20. *
  21. * @var string
  22. */
  23. protected $title = '咨询订单';
  24. /**
  25. * Make a grid builder.
  26. *
  27. * @return Grid
  28. */
  29. protected function grid()
  30. {
  31. $grid = new Grid(new Order());
  32. $user = Admin::user();
  33. $org_id = $user->org_id;
  34. $docter_id = $user->docter_id;
  35. $grid->model()->orderByDesc('id');
  36. $is_admin = Admin::user()->inRoles(['administrator','devloper']);
  37. $grid->batchActions(function ($batch) {
  38. $batch->add(new sendNotice());
  39. });
  40. $where['product_type'] = 2;
  41. if(!$is_admin){
  42. if($docter_id){
  43. $where['docter_id'] = $docter_id;
  44. }
  45. }
  46. if (empty($docter_id)) {
  47. $docter_ids = DocterOrganization::where('organization_id', $org_id)->pluck('docter_id')->toArray();
  48. $grid->model()->where($where)->whereIn('id', $docter_ids);
  49. }
  50. else {
  51. $grid->model()->where($where);
  52. }
  53. $grid->column('order_sn', __('订单号'));
  54. $grid->column('docter.name', __('医生'));
  55. $grid->column('orderUser.nickname', __('咨询用户'));
  56. $grid->column('orderPatient.name', __('咨询患者'));
  57. $grid->column('patient.phone', __('电话'));
  58. $grid->column('orderPatient.birthday', __('患者年龄'))->display(function ($w){
  59. return birthday_to_age($w);
  60. });
  61. $grid->actions(function ($actions) use($docter_id) {
  62. if($docter_id){
  63. $actions->add( new Chat());
  64. }
  65. $actions->add(new Detail());
  66. $actions->disableDelete();
  67. $actions->disableView();
  68. $actions->disableEdit();
  69. });
  70. $grid->filter(function (Grid\Filter $filter){
  71. $filter->disableIdFilter();
  72. $filter->column(1/2, function ($filter) {
  73. $filter->like('order_sn','订单号');
  74. $filter->like('patient.phone','电话');
  75. $filter->like('patient.name','患者名称');
  76. $filter->equal('order_status','订单状态')->select(Order::$_order_status);
  77. $filter->timestampBetween('orderPatient.appoint_start_time','预约时间')->datetime();
  78. });
  79. });
  80. $status_arr = Order::getStatus();
  81. $grid->column('order_status', __('订单状态'))->display(function ($w) use ($status_arr) {
  82. $info = $status_arr[intval($w)];
  83. if($w == 1 || $w == 2){
  84. return '<span class="label label-warning">'.$info.'</span>';
  85. } else if( $w == 4 ){
  86. return '<span class="label label-success">'.$info.'</span>';
  87. } else if($w == 7 || $w == 3 ){
  88. return '<span class="label label-info">'.$info.'</span>';
  89. } else if($w == 6){
  90. return '<span class="label label-danger">'.$info.'</span>';
  91. } else {
  92. return '<span class="label label-default">'.$info.'</span>';
  93. }
  94. });
  95. $grid->column('created_at', __('下单时间'));
  96. return $grid;
  97. }
  98. /**
  99. * Make a show builder.
  100. *
  101. * @param mixed $id
  102. * @return Show
  103. */
  104. protected function detail($id)
  105. {
  106. return '';
  107. }
  108. /**
  109. * Make a form builder.
  110. *
  111. * @return Form
  112. */
  113. protected function form()
  114. {
  115. return '';
  116. }
  117. function chats(Content $content){
  118. $content->title('咨询订单 ');
  119. $content->description('医生用户可以接受预约');
  120. $user = Admin::user();
  121. $org_id = $user->org_id;
  122. $docter_id = $user->docter_id;
  123. Admin::js('jquery-3.5.1.min.js');
  124. $url = '/cdms/chat_view?docter_id='.$docter_id;
  125. // $content->body('<iframe src="/cdms/chat_view?docter_id='.$docter_id.'" style="width: 100%;height:800px;border: none"></iframe>');
  126. $content->body('<iframe src="/cdms/chat_view?docter_id='.$docter_id.'" style="width: 100%;height:800px;border: none"></iframe>');
  127. return $content;
  128. }
  129. public function chat_view()
  130. {
  131. return view('cdms.chat');
  132. }
  133. }