DynamicController.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: ring
  5. * Date: 2019/7/23
  6. * Time: 上午11:54
  7. */
  8. namespace App\Admin\Controllers;
  9. use App\Api\Util\IM;
  10. use App\Models\Dynamic;
  11. use Encore\Admin\Form;
  12. use App\Models\DynamicComment;
  13. use Encore\Admin\Controllers\AdminController;
  14. use Encore\Admin\Grid;
  15. use Encore\Admin\Layout\Column;
  16. use Encore\Admin\Layout\Content;
  17. use Encore\Admin\Layout\Row;
  18. use Encore\Admin\Show;
  19. use Illuminate\Support\Arr;
  20. use Illuminate\Support\Facades\Cache;
  21. class DynamicController extends AdminController
  22. {
  23. use IM;
  24. protected $title = '朋友圈管理';
  25. protected $description = [
  26. 'index' => '列表',
  27. 'show' => '详情',
  28. 'edit' => '编辑',
  29. 'create' => '创建',
  30. ];
  31. protected function grid()
  32. {
  33. $grid = new Grid(new Dynamic());
  34. $grid->id('ID')->sortable();
  35. $grid->column('description', '内容')->limit(10);
  36. $grid->column('topic.name', '所属话题');
  37. $grid->column('user.lid', '发贴用户ID');
  38. $grid->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  39. $grid->column('type', '类型')->display(function ($x) {
  40. return $x == 1 ? '图片类型' : $x == 2 ? '视频类型' : '语音';
  41. })->sortable();
  42. $grid->column('like_size', '点赞数');
  43. $grid->column('rose', '看需玫瑰');
  44. $grid->column('view_size', '浏览数');
  45. $grid->column('comment_size', '评论数');
  46. $grid->column('status', '审核')->editable('select', [1 => '通过',0=>'申请']);
  47. $grid->created_at('创建时间');
  48. $grid->updated_at('修改时间');
  49. $grid->disableExport();
  50. $grid->disableRowSelector();
  51. $grid->disableColumnSelector();
  52. $grid->disableCreateButton();
  53. $grid->expandFilter();
  54. $grid->model()->orderBy('id', 'desc');
  55. $grid->actions(function ($actions) {
  56. $actions->disableEdit();
  57. //$actions->disableEdit();
  58. });
  59. $grid->filter(function ($filter) {
  60. $filter->disableIdFilter();
  61. $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
  62. });
  63. return $grid;
  64. }
  65. protected function form()
  66. {
  67. $form = new Form(new Dynamic);
  68. $form->number('status', '审核')->rules('required|min:1');
  69. return $form;
  70. }
  71. public function show($id,Content $content){
  72. $d=Dynamic::findOrFail($id);
  73. $show = new Show($d);
  74. $show->user()->as(function ($u) {
  75. return $u->name.'--ID'.$u->lid;
  76. })->lable('发布用户');
  77. $show->topic()->as(function ($u) {
  78. return $u->name;
  79. })->lable('所属话题');
  80. $show->field('rose', '看次动态需玫瑰');
  81. $show->addField('数量','数量')->as(function ($q)use($d){return '点赞数:'.$d->like_size.'浏览数:'.$d->view_size.'评论数:'.$d->comment_size;});
  82. $show->field('description', trans('描述'));
  83. $show->panel()->tools(function ($tools) {
  84. $tools->disableEdit();
  85. $tools->disableDelete();
  86. });
  87. if($d->type==3){
  88. $show->files('语音')->unescape()->as(function ($u) use ($d) {
  89. $a=Arr::pluck($u->toArray(),'file') ;
  90. $url='';
  91. foreach ($a as $k=>$v){
  92. $k++;
  93. $url.="<a href='{$v}' target='_blank'>语音文件{$k}</a>--|";
  94. }
  95. return $url;
  96. });
  97. }
  98. if($d->type==1){
  99. $show->files('图片')->as(function ($u) {
  100. return Arr::pluck($u->toArray(),'file') ;
  101. })->carousel();
  102. }
  103. if($d->type==2){
  104. $show->files('视频')->unescape()->as(function ($u) {
  105. $a=Arr::pluck($u->toArray(),'file') ;
  106. $url='';
  107. foreach ($a as $k=>$v){
  108. $k++;
  109. $url.="<a href='{$v}' target='_blank'>视频文件{$k}</a>--|";
  110. }
  111. return $url;
  112. });
  113. }
  114. $show->comments('评论', function ($comments) {
  115. $comments->id('ID')->sortable();
  116. $comments->column('description', '内容')->limit(50);
  117. $comments->column('user.lid', '发贴用户ID');
  118. $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  119. $comments->created_at('创建时间');
  120. $comments->updated_at('修改时间');
  121. $comments->disableExport();
  122. $comments->disableRowSelector();
  123. $comments->disableColumnSelector();
  124. $comments->disableCreateButton();
  125. $comments->actions(function ($actions) {
  126. $actions->disableEdit();
  127. $actions->disableView();
  128. });
  129. $comments->filter(function ($filter) {
  130. $filter->disableIdFilter();
  131. $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
  132. $filter->like('description')->placeholder('内容');
  133. });
  134. });
  135. $show->like('点赞', function ($comments) {
  136. $comments->id('ID')->sortable();
  137. $comments->column('user.lid', '点赞用户ID');
  138. $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  139. $comments->created_at('创建时间');
  140. $comments->updated_at('修改时间');
  141. $comments->disableExport();
  142. $comments->disableRowSelector();
  143. $comments->disableColumnSelector();
  144. $comments->disableCreateButton();
  145. $comments->disableActions();
  146. $comments->filter(function ($filter) {
  147. $filter->disableIdFilter();
  148. $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
  149. });
  150. });
  151. $show->pays('支付', function ($comments) {
  152. $comments->id('ID')->sortable();
  153. $comments->column('user.lid', '支付用户ID');
  154. $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
  155. $comments->created_at('创建时间');
  156. $comments->updated_at('修改时间');
  157. $comments->disableExport();
  158. $comments->disableRowSelector();
  159. $comments->disableColumnSelector();
  160. $comments->disableCreateButton();
  161. $comments->disableActions();
  162. $comments->filter(function ($filter) {
  163. $filter->disableIdFilter();
  164. $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
  165. });
  166. });
  167. return $content
  168. ->title($this->title)
  169. ->description($this->description['show'])
  170. ->row($show);
  171. }
  172. public function destroy($id)
  173. {
  174. Cache::forget('Topic');
  175. $student=Dynamic::where('id',$id)->first();
  176. $this->imsendmassage('admin',$student->uid,'动态被管理删除!请谨慎操作');
  177. $student->delete();
  178. if($student->trashed()){
  179. $response = [
  180. 'status' => true,
  181. 'message' => trans('admin.delete_succeeded'),
  182. ];
  183. }else{
  184. $response = [
  185. 'status' => false,
  186. 'message' => '删除失败',
  187. ];
  188. }
  189. return response()->json($response);
  190. }
  191. public function delete($did,$id){
  192. if(DynamicComment::where('id',$id)->delete()){
  193. $response = [
  194. 'status' => true,
  195. 'message' => trans('admin.delete_succeeded'),
  196. ];
  197. }else{
  198. $response = [
  199. 'status' => false,
  200. 'message' => '删除失败',
  201. ];
  202. }
  203. return response()->json($response);
  204. }
  205. }