123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Actions\Problem\Reply;
- use App\Models\UserProblemModel;
- use App\Models\UsersProblem;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Http\Controllers\AdminController;
- use Dcat\Admin\Show;
- class UsersProblemController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- $grid = new Grid(new UserProblemModel());
- $grid->model()->orderBy('id','desc');
- $grid->column('id')->sortable();
- $grid->column('user_id');
- $grid->column('content')->limit(50);
- $grid->column('img_url')->display(function ($v){
- if(isset($v)){
- $v = json_decode($v,true);
- $str = '';
- if(count($v)>0){
- foreach ($v as $item){
- $str.='<img data-action="preview-img" src="'.$item.'" style="max-width:50px;max-height:200px;cursor:pointer" class="img img-thumbnail">';
- }
- }
- return $str;
- }else{
- return "";
- }
- });
- $grid->column('status')->using(['待处理','已处理'])->label(['warning','success']);
- $grid->column('reply','回复内容');
- $grid->column('created_at');
- $grid->column('updated_at')->sortable();
- $grid->filter(function (Grid\Filter $filter) {
- $filter->equal('id');
- });
- //操作管理
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableEdit();
- $actions->disableDelete();
- if ($actions->row->status == 0) {
- $actions->append(new Reply(UserProblemModel::class));
- }
- });
- $grid->disableCreateButton();
- return $grid;
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new UserProblemModel(), function (Show $show) {
- $show->field('id');
- $show->field('user_id');
- $show->field('content')->unescape();
- $show->html(function ($res){
- $str = "";
- if($res['img_url']){
- $res = json_decode($res['img_url'],true);
- if(count($res)>0){
- foreach ($res as $k=>$v){
- $str.='<img data-action="preview-img" src="'.$v.'" style="max-width:100px;max-height:100px;cursor:pointer" class="img img-thumbnail">';
- }
- }else{
- $str = "无";
- }
- }else{
- $str = "无";
- }
- $html = '<div class="show-field form-group row">
- <div class="col-sm-2 control-label">
- <span>图片</span>
- </div>
- <div class="col-sm-8">
- <div class="box box-solid box-default no-margin box-show">
- <div class="box-body">
- '.$str.'
- </div>
- </div>
- </div>
- </div>';
- return $html;
- });
- $show->field('status')->using(['待处理','已处理']);
- $show->field('reply','回复内容');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new UserProblemModel(), function (Form $form) {
- $form->display('id');
- $form->text('user_id');
- $form->text('content');
- $form->text('img_url');
- $form->text('status');
- $form->display('created_at');
- $form->display('updated_at');
- });
- }
- }
|