WxFeedbackController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Grid\ReplyTap;
  4. use App\Admin\Repositories\WxFeedback;
  5. use App\Wen\Utils\Utils;
  6. use App\Models\WxFeedback as Model;
  7. use Dcat\Admin\Form;
  8. use Dcat\Admin\Grid;
  9. use Dcat\Admin\Show;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. class WxFeedbackController extends AdminController
  12. {
  13. /**
  14. * Make a grid builder.
  15. *
  16. * @return Grid
  17. */
  18. protected function grid()
  19. {
  20. return Grid::make(new WxFeedback(['user']), function (Grid $grid) {
  21. $grid->simplePaginate();
  22. $grid->quickSearch(['id', 'feedback_content','user_id','user.user_name', 'circle_name', 'feedback_reply'])->placeholder('搜索ID,内容,用户ID,用户名字,圈子名字...')->width(50);
  23. $grid->model()->orderBy('id', 'desc');
  24. $grid->column('id')->sortable();
  25. $grid->column('user.user_avatar', '用户头像')->image('', 50);
  26. $grid->column('user.user_name', '用户名');
  27. $grid->column('feedback_type');
  28. $grid->column('feedback_content')->limit(30);
  29. $grid->column('feedback_imgs')->display(function ($v) {
  30. if(_empty_($v)){
  31. return '';
  32. }
  33. $imgs = explode(',', $v);
  34. $html = '<div style="max-width: 350px; overflow-x: scroll;">';
  35. foreach ($imgs as $img){
  36. $html .= '<img data-action="preview-img" style="max-width: 50px;margin-right: 10px;" src="'.Utils::imgWithStyle($img).'" / >';
  37. }
  38. return $html.'</div>';
  39. })->width('50px');
  40. $grid->column('feedback_contact');
  41. $grid->column('feedback_reply')->limit(6);
  42. $grid->column('feedback_state')->using([0 => '未受理', 1 => '已受理'])->label([
  43. 0 => 'red',
  44. 1 => 'primary',
  45. ]);
  46. // $grid->column('created_at');
  47. $grid->column('is_solve')->using([0 => '未反馈', 1 => '已解决', 2 => '未解决']);
  48. $grid->column('updated_at')->sortable();
  49. $grid->filter(function (Grid\Filter $filter) {
  50. $filter->equal('id');
  51. });
  52. $grid->actions(function (Grid\Displayers\Actions $actions) {
  53. $actions->append((new ReplyTap())->setKey($this->id));
  54. });
  55. $grid->actions(function (Grid\Displayers\Actions $actions) {
  56. $actions->disableDelete();
  57. $actions->disableEdit();
  58. $actions->disableQuickEdit();
  59. $actions->disableView();
  60. });
  61. $grid->disableCreateButton();
  62. });
  63. }
  64. /**
  65. * Make a show builder.
  66. *
  67. * @param mixed $id
  68. *
  69. * @return Show
  70. */
  71. protected function detail($id)
  72. {
  73. return Show::make($id, new WxFeedback(), function (Show $show) {
  74. $show->field('id');
  75. $show->field('user_id');
  76. $show->field('feedback_type');
  77. $show->field('feedback_content');
  78. $show->field('feedback_reply');
  79. $show->field('feedback_state');
  80. $show->field('created_at');
  81. $show->field('updated_at');
  82. });
  83. }
  84. /**
  85. * Make a form builder.
  86. *
  87. * @return Form
  88. */
  89. protected function form()
  90. {
  91. return Form::make(new WxFeedback(), function (Form $form) {
  92. $form->display('id');
  93. $form->text('user_id');
  94. $form->text('feedback_type');
  95. $form->text('feedback_content');
  96. $form->text('feedback_reply');
  97. $form->text('feedback_state');
  98. $form->deleting(function (Form $form){
  99. global $__MINI_GLOBAL_TENANT_ID__;
  100. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  101. return $form->response()->error('权限不足,不可以删除其他分站对象');
  102. }
  103. });
  104. });
  105. }
  106. /**
  107. * Make a show builder.
  108. *
  109. * @param mixed $id ,$feedback_reply
  110. *
  111. * @return Show
  112. */
  113. protected function reply($id, $feedback_reply)
  114. {
  115. $model = new Model();
  116. $feedback = $model->where('id', $id)->first();
  117. $feedback->feedback_reply = $feedback_reply;
  118. return $feedback->save();
  119. }
  120. }