WxCommentController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. namespace App\Admin\Controllers\Posts;
  3. use App\Admin\Actions\Grid\BatchCommentAction;
  4. use App\Admin\Actions\Grid\CommentAction;
  5. use App\Admin\Actions\Grid\Posts\CommentApplyAction;
  6. use App\Admin\Repositories\Posts\WxComment;
  7. use App\Jobs\Posts\UpdateCommentOnlyTextJob;
  8. use App\Wen\Utils\Settings;
  9. use Dcat\Admin\Actions\Action;
  10. use Dcat\Admin\Form;
  11. use Dcat\Admin\Grid;
  12. use Dcat\Admin\Show;
  13. use Dcat\Admin\Http\Controllers\AdminController;
  14. class WxCommentController extends AdminController
  15. {
  16. /**
  17. * Make a grid builder.
  18. *
  19. * @return Grid
  20. */
  21. protected function grid()
  22. {
  23. return Grid::make(new WxComment(), function (Grid $grid) {
  24. global $__MINI_GLOBAL_TENANT_ID__;
  25. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  26. $grid->model()->whereHas('post', function ($query) use ($__MINI_GLOBAL_TENANT_ID__){
  27. $query->where('tenant_id', $__MINI_GLOBAL_TENANT_ID__);
  28. });
  29. }
  30. $grid->simplePaginate();
  31. $grid->quickSearch(['comment_content','id','user_name', 'comment_agent_name'])->placeholder('搜索评论内容,ID,评论人的名字,被评论的人名字');
  32. $grid->model()->orderBy('id','desc');
  33. $grid->column('id')->sortable();
  34. $grid->column('posts_id');
  35. // $grid->column('posts_user_id');
  36. $grid->column('users', '头像')->display(function ($v) {
  37. return '<img src="' . ($this->user['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />';
  38. })->width('50px');
  39. $grid->column('user')->display(function ($v) {
  40. if($v && $v['user_name']){
  41. return '<a target="_blank" href="'.admin_url('users?id='.$v['id']).'">'.$v['user_name'].'</a>' ?? '用户已删除';
  42. }
  43. return '用户已删除';
  44. })->width('100px');
  45. $grid->column('comment_agent_avatar')->image('',50);
  46. $grid->column('comment_agent_name');
  47. $grid->column('comment_content')->display(function ($v){
  48. return _mini_phone(_mini_emoji(_mini_aite_replace($v, true), true), true);
  49. })->limit(20);
  50. $grid->column('comment_img_url')->image(100);
  51. $grid->column('is_anonymous')->display(function ($v){
  52. if($v == 1){
  53. return '是';
  54. }else{
  55. return '';
  56. }
  57. });
  58. $grid->column('comment_state')->using([0=>'待审核',1=>'审核通过',2=>'驳回'])->label([
  59. 0=>'red',
  60. 1=>'green',
  61. 2=>'default'
  62. ])->sortable();
  63. $grid->column('created_at');
  64. // $grid->column('updated_at')->sortable();
  65. $grid->filter(function (Grid\Filter $filter) {
  66. $filter->equal('id');
  67. });
  68. $grid->batchActions(function ($batch) {
  69. $batch->add((new BatchCommentAction()));
  70. });
  71. global $__MINI_GLOBAL_TENANT_ID__;
  72. if($__MINI_GLOBAL_TENANT_ID__ === 0){
  73. $grid->actions(function (Grid\Displayers\Actions $actions) {
  74. $actions->append((new CommentAction())->setKey($this->id));
  75. $actions->append((new CommentApplyAction())->setKey($this->id));
  76. });
  77. }else{
  78. $grid->actions(function (Grid\Displayers\Actions $actions) {
  79. $actions->append((new CommentAction())->setKey($this->id));
  80. });
  81. }
  82. $grid->disableCreateButton();
  83. // 禁用编辑按钮
  84. // $grid->disableEditButton();
  85. // 禁用详情按钮
  86. $grid->disableViewButton();
  87. });
  88. }
  89. /**
  90. * Make a show builder.
  91. *
  92. * @param mixed $id
  93. *
  94. * @return Show
  95. */
  96. protected function detail($id)
  97. {
  98. return Show::make($id, new WxComment(), function (Show $show) {
  99. $show->field('id');
  100. $show->field('posts_id');
  101. $show->field('posts_user_id');
  102. $show->field('user_id');
  103. $show->field('user_name');
  104. $show->field('user_avatar');
  105. $show->field('comment_agent_id');
  106. $show->field('comment_agent_name');
  107. $show->field('comment_agent_avatar');
  108. $show->field('comment_content');
  109. $show->field('comment_id');
  110. $show->field('is_anonymous');
  111. $show->field('comment_state');
  112. $show->field('created_at');
  113. $show->field('updated_at');
  114. });
  115. }
  116. /**
  117. * Make a form builder.
  118. *
  119. * @return Form
  120. */
  121. protected function form()
  122. {
  123. return Form::make(new WxComment(), function (Form $form) {
  124. $form->display('id');
  125. // $form->text('posts_id');
  126. // $form->text('posts_user_id');
  127. // $form->text('user_id');
  128. // $form->text('user_name');
  129. // $form->image('user_avatar')->url('files/uploads')->autoUpload();
  130. // $form->text('comment_agent_id');
  131. // $form->text('comment_agent_name');
  132. // $form->text('comment_agent_avatar');
  133. $form->textarea('comment_content');
  134. $form->image('comment_img_url')->url('files/uploads')->autoUpload();
  135. // $form->text('comment_id');
  136. $form->radio('comment_state', '状态')->options([0=>'待审核',1=>'审核通过',2=>'驳回']);
  137. $form->saved(function (Form $form){
  138. \App\Models\Posts\WxComment::where('id', $form->model()->id )->update(['is_only_text'=>null]);
  139. UpdateCommentOnlyTextJob::dispatch($form->model()->id);
  140. });
  141. $form->deleting(function (Form $form){
  142. global $__MINI_GLOBAL_TENANT_ID__;
  143. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  144. if(\App\Models\Posts\WxComment::where('id', $form->getKey())->value('tenant_id') != $__MINI_GLOBAL_TENANT_ID__){
  145. return $form->response()->error('权限不足,不可以删除其他分站对象');
  146. }
  147. }
  148. });
  149. });
  150. }
  151. }