UsersProblemController.php 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Problem\Reply;
  4. use App\Models\UserProblemModel;
  5. use App\Models\UsersProblem;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. use Dcat\Admin\Show;
  10. class UsersProblemController extends AdminController
  11. {
  12. /**
  13. * Make a grid builder.
  14. *
  15. * @return Grid
  16. */
  17. protected function grid()
  18. {
  19. $grid = new Grid(new UserProblemModel());
  20. $grid->model()->orderBy('id','desc');
  21. $grid->column('id')->sortable();
  22. $grid->column('user_id');
  23. $grid->column('content')->limit(50);
  24. $grid->column('img_url')->display(function ($v){
  25. if(isset($v)){
  26. $v = json_decode($v,true);
  27. $str = '';
  28. if(count($v)>0){
  29. foreach ($v as $item){
  30. $str.='<img data-action="preview-img" src="'.$item.'" style="max-width:50px;max-height:200px;cursor:pointer" class="img img-thumbnail">';
  31. }
  32. }
  33. return $str;
  34. }else{
  35. return "";
  36. }
  37. });
  38. $grid->column('status')->using(['待处理','已处理'])->label(['warning','success']);
  39. $grid->column('reply','回复内容');
  40. $grid->column('created_at');
  41. $grid->column('updated_at')->sortable();
  42. $grid->filter(function (Grid\Filter $filter) {
  43. $filter->equal('id');
  44. });
  45. //操作管理
  46. $grid->actions(function (Grid\Displayers\Actions $actions) {
  47. $actions->disableEdit();
  48. $actions->disableDelete();
  49. if ($actions->row->status == 0) {
  50. $actions->append(new Reply(UserProblemModel::class));
  51. }
  52. });
  53. $grid->disableCreateButton();
  54. return $grid;
  55. }
  56. /**
  57. * Make a show builder.
  58. *
  59. * @param mixed $id
  60. *
  61. * @return Show
  62. */
  63. protected function detail($id)
  64. {
  65. return Show::make($id, new UserProblemModel(), function (Show $show) {
  66. $show->field('id');
  67. $show->field('user_id');
  68. $show->field('content')->unescape();
  69. $show->html(function ($res){
  70. $str = "";
  71. if($res['img_url']){
  72. $res = json_decode($res['img_url'],true);
  73. if(count($res)>0){
  74. foreach ($res as $k=>$v){
  75. $str.='<img data-action="preview-img" src="'.$v.'" style="max-width:100px;max-height:100px;cursor:pointer" class="img img-thumbnail">';
  76. }
  77. }else{
  78. $str = "无";
  79. }
  80. }else{
  81. $str = "无";
  82. }
  83. $html = '<div class="show-field form-group row">
  84. <div class="col-sm-2 control-label">
  85. <span>图片</span>
  86. </div>
  87. <div class="col-sm-8">
  88. <div class="box box-solid box-default no-margin box-show">
  89. <div class="box-body">
  90. '.$str.'
  91. </div>
  92. </div>
  93. </div>
  94. </div>';
  95. return $html;
  96. });
  97. $show->field('status')->using(['待处理','已处理']);
  98. $show->field('reply','回复内容');
  99. $show->field('created_at');
  100. $show->field('updated_at');
  101. });
  102. }
  103. /**
  104. * Make a form builder.
  105. *
  106. * @return Form
  107. */
  108. protected function form()
  109. {
  110. return Form::make(new UserProblemModel(), function (Form $form) {
  111. $form->display('id');
  112. $form->text('user_id');
  113. $form->text('content');
  114. $form->text('img_url');
  115. $form->text('status');
  116. $form->display('created_at');
  117. $form->display('updated_at');
  118. });
  119. }
  120. }