| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215 |
- <?php
- /**
- * Created by PhpStorm.
- * User: ring
- * Date: 2019/7/23
- * Time: 上午11:54
- */
- namespace App\Admin\Controllers;
- use App\Api\Util\IM;
- use App\Models\Dynamic;
- use Encore\Admin\Form;
- use App\Models\DynamicComment;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Column;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Layout\Row;
- use Encore\Admin\Show;
- use Illuminate\Support\Arr;
- use Illuminate\Support\Facades\Cache;
- class DynamicController extends AdminController
- {
- use IM;
- protected $title = '朋友圈管理';
- protected $description = [
- 'index' => '列表',
- 'show' => '详情',
- 'edit' => '编辑',
- 'create' => '创建',
- ];
-
- protected function grid()
- {
- $grid = new Grid(new Dynamic());
- $grid->id('ID')->sortable();
- $grid->column('description', '内容')->limit(10);
- $grid->column('topic.name', '所属话题');
- $grid->column('user.lid', '发贴用户ID');
- $grid->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
- $grid->column('type', '类型')->display(function ($x) {
- return $x == 1 ? '图片类型' : $x == 2 ? '视频类型' : '语音';
- })->sortable();
- $grid->column('like_size', '点赞数');
- $grid->column('rose', '看需玫瑰');
- $grid->column('view_size', '浏览数');
- $grid->column('comment_size', '评论数');
- $grid->column('status', '审核')->editable('select', [1 => '通过',0=>'申请']);
- $grid->created_at('创建时间');
- $grid->updated_at('修改时间');
- $grid->disableExport();
- $grid->disableRowSelector();
- $grid->disableColumnSelector();
- $grid->disableCreateButton();
- $grid->expandFilter();
- $grid->model()->orderBy('id', 'desc');
- $grid->actions(function ($actions) {
- $actions->disableEdit();
- //$actions->disableEdit();
- });
- $grid->filter(function ($filter) {
- $filter->disableIdFilter();
- $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
- });
- return $grid;
- }
- protected function form()
- {
- $form = new Form(new Dynamic);
- $form->number('status', '审核')->rules('required|min:1');
- return $form;
- }
- public function show($id,Content $content){
- $d=Dynamic::findOrFail($id);
- $show = new Show($d);
- $show->user()->as(function ($u) {
- return $u->name.'--ID'.$u->lid;
- })->lable('发布用户');
- $show->topic()->as(function ($u) {
- return $u->name;
- })->lable('所属话题');
- $show->field('rose', '看次动态需玫瑰');
- $show->addField('数量','数量')->as(function ($q)use($d){return '点赞数:'.$d->like_size.'浏览数:'.$d->view_size.'评论数:'.$d->comment_size;});
- $show->field('description', trans('描述'));
- $show->panel()->tools(function ($tools) {
- $tools->disableEdit();
- $tools->disableDelete();
- });
- if($d->type==3){
- $show->files('语音')->unescape()->as(function ($u) use ($d) {
- $a=Arr::pluck($u->toArray(),'file') ;
- $url='';
- foreach ($a as $k=>$v){
- $k++;
- $url.="<a href='{$v}' target='_blank'>语音文件{$k}</a>--|";
- }
- return $url;
- });
- }
- if($d->type==1){
- $show->files('图片')->as(function ($u) {
- return Arr::pluck($u->toArray(),'file') ;
- })->carousel();
- }
- if($d->type==2){
- $show->files('视频')->unescape()->as(function ($u) {
- $a=Arr::pluck($u->toArray(),'file') ;
- $url='';
- foreach ($a as $k=>$v){
- $k++;
- $url.="<a href='{$v}' target='_blank'>视频文件{$k}</a>--|";
- }
- return $url;
- });
- }
- $show->comments('评论', function ($comments) {
- $comments->id('ID')->sortable();
- $comments->column('description', '内容')->limit(50);
- $comments->column('user.lid', '发贴用户ID');
- $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
- $comments->created_at('创建时间');
- $comments->updated_at('修改时间');
- $comments->disableExport();
- $comments->disableRowSelector();
- $comments->disableColumnSelector();
- $comments->disableCreateButton();
- $comments->actions(function ($actions) {
- $actions->disableEdit();
- $actions->disableView();
- });
- $comments->filter(function ($filter) {
- $filter->disableIdFilter();
- $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
- $filter->like('description')->placeholder('内容');
- });
- });
- $show->like('点赞', function ($comments) {
- $comments->id('ID')->sortable();
- $comments->column('user.lid', '点赞用户ID');
- $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
- $comments->created_at('创建时间');
- $comments->updated_at('修改时间');
- $comments->disableExport();
- $comments->disableRowSelector();
- $comments->disableColumnSelector();
- $comments->disableCreateButton();
- $comments->disableActions();
- $comments->filter(function ($filter) {
- $filter->disableIdFilter();
- $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
- });
- });
- $show->pays('支付', function ($comments) {
- $comments->id('ID')->sortable();
- $comments->column('user.lid', '支付用户ID');
- $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
- $comments->created_at('创建时间');
- $comments->updated_at('修改时间');
- $comments->disableExport();
- $comments->disableRowSelector();
- $comments->disableColumnSelector();
- $comments->disableCreateButton();
- $comments->disableActions();
- $comments->filter(function ($filter) {
- $filter->disableIdFilter();
- $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
- });
- });
- return $content
- ->title($this->title)
- ->description($this->description['show'])
- ->row($show);
- }
- public function destroy($id)
- {
- Cache::forget('Topic');
- $student=Dynamic::where('id',$id)->first();
- $this->imsendmassage('admin',$student->uid,'动态被管理删除!请谨慎操作');
- $student->delete();
- if($student->trashed()){
- $response = [
- 'status' => true,
- 'message' => trans('admin.delete_succeeded'),
- ];
- }else{
- $response = [
- 'status' => false,
- 'message' => '删除失败',
- ];
- }
- return response()->json($response);
- }
- public function delete($did,$id){
- if(DynamicComment::where('id',$id)->delete()){
- $response = [
- 'status' => true,
- 'message' => trans('admin.delete_succeeded'),
- ];
- }else{
- $response = [
- 'status' => false,
- 'message' => '删除失败',
- ];
- }
- return response()->json($response);
- }
- }
|