| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- <?php
- /**
- * Created by PhpStorm.
- * User: ring
- * Date: 2019/7/23
- * Time: 上午11:49
- */
- namespace App\Admin\Controllers;
- use App\Models\DynamicTopic;
- use App\Models\Users;
- use Encore\Admin\Controllers\AdminController;
- use Encore\Admin\Form;
- use Encore\Admin\Grid;
- use Encore\Admin\Layout\Content;
- use Encore\Admin\Show;
- use Illuminate\Support\Facades\Cache;
- use App\Api\Util\IM;
- class TopicController extends AdminController
- {
- use IM;
- protected $title = '话题管理';
- protected function grid()
- {
- $grid = new Grid(new DynamicTopic());
- $grid->id('ID')->sortable();
- $grid->column('name', '话题/圈子名');
- $grid->column('file', '图片')->image(config('love.QINIU_MY_DOMAINS'),100,100);
- $grid->column('user.lid', '所属用户');
- $grid->column('like_size', '粉丝数');
- $grid->column('view_size', '浏览数');
- $grid->column('comment_size', '评论数');
- $grid->column('description', '描述')->limit(30);
- $grid->created_at('创建时间');
- $grid->updated_at('修改时间');
-
- $grid->disableExport();
- $grid->disableRowSelector();
- $grid->disableColumnSelector();
- // $grid->disableCreateButton();
- $grid->disablePagination();
- $grid->actions(function ($actions) {
- $actions->disableEdit();
- //$actions->disableEdit();
- });
- $grid->filter(function ($filter) {
- $filter->disableIdFilter();
- $filter->equal('user.lid','客户ID')->placeholder('请输入客户ID');
- $filter->equal('name','话题/圈子名')->placeholder('请输入话题/圈子名');
- });
- return $grid;
- }
- protected function form()
- {
- $form = new Form(new DynamicTopic);
- $form->text('name', '话题/圈子名')->rules('required|min:1');
- $form->image('file','图片')->uniqueName()->help('若上传不成功检查图片大小');
- $paht=config('admin.route.prefix');
- $form->select('uid','所属用户')->options(function ($id) {
- $user = Users::where('lid',$id)->first();
- if ($user) {
- return [$user->id => $user->name];
- }else{
- return [0=> '无'];
- }
- })->ajax('/'.$paht.'/groups/users')->help('用用户ID搜索');
- $form->textarea('description', '描述');
- $form->footer(function ($footer) {
- $footer->disableReset();
- $footer->disableViewCheck();
- $footer->disableEditingCheck();
- $footer->disableCreatingCheck();
- });
- $form->tools(function (Form\Tools $tools) {
- $tools->disableView();
- $tools->disableDelete();
- });
- return $form;
- }
- public function detail($id){
- $dy=DynamicTopic::findOrFail($id);
- $show = new Show($dy);
- $show->field('name', '话题/圈子名');
- if($dy->uid){
- $show->user()->as(function ($u) {
- return $u->name.'--ID['.$u->lid;
- })->lable('用户');
- }
- $show->field('file', '图片')->image(config('love.QINIU_MY_DOMAINS'),300,300);;
- $show->field('like_size', trans('粉丝数'));
- $show->field('view_size', trans('浏览数'));
- $show->field('comment_size', trans('评论数'));
- $show->field('description', trans('描述'));
- $show->field('created_at', trans('admin.created_at'));
- $show->field('updated_at', trans('admin.updated_at'));
- $show->panel()->tools(function ($tools) {
- $tools->disableEdit();
- $tools->disableDelete();
- });
- $show->comments('话题下的朋友圈', function ($comments) {
- $comments->resource('dynamic');
- $comments->id('ID')->sortable();
- $comments->column('description', '内容')->limit(10);
- $comments->column('user.lid', '发贴用户ID');
- $comments->column('user.avatar', '用户头像')->image(config('love.QINIU_MY_DOMAINS'), 50, 50);
- $comments->column('type', '类型')->display(function ($x) {
- return $x == 1 ? '图片类型' : $x == 2 ? '视频类型' : '语音';
- })->sortable();
- $comments->column('like_size', '点赞数');
- $comments->column('rose', '看需玫瑰');
- $comments->column('view_size', '浏览数');
- $comments->column('comment_size', '评论数');
- $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');
- $filter->like('description')->placeholder('内容');
- });
- });
- return $show;
- }
- public function store()
- {
- Cache::forget('Topic');
- return $this->form()->store();
- }
- public function update($id)
- {
- Cache::forget('Topic');
- return $this->form()->update($id);
- }
- public function destroy($id)
- {
- Cache::forget('Topic');
- $student=DynamicTopic::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);
- }
- }
|