TopicController.php 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ring
  5. * Date: 2019/7/23
  6. * Time: 上午11:49
  7. */
  8. namespace App\Admin\Controllers;
  9. use App\Models\DynamicTopic;
  10. use App\Models\Users;
  11. use Encore\Admin\Controllers\AdminController;
  12. use Encore\Admin\Form;
  13. use Encore\Admin\Grid;
  14. use Encore\Admin\Layout\Content;
  15. use Encore\Admin\Show;
  16. use Illuminate\Support\Facades\Cache;
  17. use App\Api\Util\IM;
  18. class TopicController extends AdminController
  19. {
  20. use IM;
  21. protected $title = '话题管理';
  22. protected function grid()
  23. {
  24. $grid = new Grid(new DynamicTopic());
  25. $grid->id('ID')->sortable();
  26. $grid->column('name', '话题/圈子名');
  27. $grid->column('file', '图片')->image(config('love.QINIU_MY_DOMAINS'),100,100);
  28. $grid->column('user.lid', '所属用户');
  29. $grid->column('like_size', '粉丝数');
  30. $grid->column('view_size', '浏览数');
  31. $grid->column('comment_size', '评论数');
  32. $grid->column('description', '描述')->limit(30);
  33. $grid->created_at('创建时间');
  34. $grid->updated_at('修改时间');
  35. $grid->disableExport();
  36. $grid->disableRowSelector();
  37. $grid->disableColumnSelector();
  38. // $grid->disableCreateButton();
  39. $grid->disablePagination();
  40. $grid->actions(function ($actions) {
  41. $actions->disableEdit();
  42. //$actions->disableEdit();
  43. });
  44. $grid->filter(function ($filter) {
  45. $filter->disableIdFilter();
  46. $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
  47. $filter->equal('name','话题/圈子名')->placeholder('请输入话题/圈子名');
  48. });
  49. return $grid;
  50. }
  51. protected function form()
  52. {
  53. $form = new Form(new DynamicTopic);
  54. $form->text('name', '话题/圈子名')->rules('required|min:1');
  55. $form->image('file','图片')->uniqueName()->help('若上传不成功检查图片大小');
  56. $paht=config('admin.route.prefix');
  57. $form->select('uid','所属用户')->options(function ($id) {
  58. $user = Users::where('lid',$id)->first();
  59. if ($user) {
  60. return [$user->id => $user->name];
  61. }else{
  62. return [0=> '无'];
  63. }
  64. })->ajax('/'.$paht.'/groups/users')->help('用用户ID搜索');
  65. $form->textarea('description', '描述');
  66. $form->footer(function ($footer) {
  67. $footer->disableReset();
  68. $footer->disableViewCheck();
  69. $footer->disableEditingCheck();
  70. $footer->disableCreatingCheck();
  71. });
  72. $form->tools(function (Form\Tools $tools) {
  73. $tools->disableView();
  74. $tools->disableDelete();
  75. });
  76. return $form;
  77. }
  78. public function detail($id){
  79. $dy=DynamicTopic::findOrFail($id);
  80. $show = new Show($dy);
  81. $show->field('name', '话题/圈子名');
  82. if($dy->uid){
  83. $show->user()->as(function ($u) {
  84. return $u->name.'--ID['.$u->lid;
  85. })->lable('用户');
  86. }
  87. $show->field('file', '图片')->image(config('love.QINIU_MY_DOMAINS'),300,300);;
  88. $show->field('like_size', trans('粉丝数'));
  89. $show->field('view_size', trans('浏览数'));
  90. $show->field('comment_size', trans('评论数'));
  91. $show->field('description', trans('描述'));
  92. $show->field('created_at', trans('admin.created_at'));
  93. $show->field('updated_at', trans('admin.updated_at'));
  94. $show->panel()->tools(function ($tools) {
  95. $tools->disableEdit();
  96. $tools->disableDelete();
  97. });
  98. $show->comments('话题下的朋友圈', function ($comments) {
  99. $comments->resource('dynamic');
  100. $comments->id('ID')->sortable();
  101. $comments->column('description', '内容')->limit(10);
  102. $comments->column('user.lid', '发贴用户ID');
  103. $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  104. $comments->column('type', '类型')->display(function ($x) {
  105. return $x == 1 ? '图片类型' : $x == 2 ? '视频类型' : '语音';
  106. })->sortable();
  107. $comments->column('like_size', '点赞数');
  108. $comments->column('rose', '看需玫瑰');
  109. $comments->column('view_size', '浏览数');
  110. $comments->column('comment_size', '评论数');
  111. $comments->created_at('创建时间');
  112. $comments->updated_at('修改时间');
  113. $comments->disableExport();
  114. $comments->disableRowSelector();
  115. $comments->disableColumnSelector();
  116. $comments->disableCreateButton();
  117. $comments->disableActions();
  118. $comments->filter(function ($filter) {
  119. $filter->disableIdFilter();
  120. $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
  121. $filter->like('description')->placeholder('内容');
  122. });
  123. });
  124. return $show;
  125. }
  126. public function store()
  127. {
  128. Cache::forget('Topic');
  129. return $this->form()->store();
  130. }
  131. public function update($id)
  132. {
  133. Cache::forget('Topic');
  134. return $this->form()->update($id);
  135. }
  136. public function destroy($id)
  137. {
  138. Cache::forget('Topic');
  139. $student=DynamicTopic::where('id',$id)->first();
  140. $this->imsendmassage('admin',$student->uid,'话题被管理删除!请谨慎操作');
  141. $student->delete();
  142. if($student->trashed()){
  143. $response = [
  144. 'status' => true,
  145. 'message' => trans('admin.delete_succeeded'),
  146. ];
  147. }else{
  148. $response = [
  149. 'status' => false,
  150. 'message' => '删除失败',
  151. ];
  152. }
  153. return response()->json($response);
  154. }
  155. }