FeedsController.php 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Feeds\FeedAction;
  4. use App\Admin\Actions\Feeds\ForwardAction;
  5. use App\Admin\Actions\Feeds\LikeAction;
  6. use App\Admin\Actions\Games\GameMembers;
  7. use App\Admin\Actions\Games\GameUserScores;
  8. use App\Models\Feed;
  9. use App\Models\Team;
  10. use App\Models\User;
  11. use Dcat\Admin\Form;
  12. use Dcat\Admin\Grid;
  13. use Dcat\Admin\Http\Controllers\AdminController;
  14. use Dcat\Admin\Show;
  15. use Dcat\Admin\Widgets\Modal;
  16. class FeedsController extends AdminController
  17. {
  18. /**
  19. * Make a grid builder.
  20. *
  21. * @return Grid
  22. */
  23. protected function grid()
  24. {
  25. $grid = new Grid(new Feed());
  26. $grid->model()->with(['user:id,name,avatar'])->orderByDesc('id');
  27. $grid->column('id')->sortable();
  28. $grid->column('user_id')->display(function (){
  29. if($this->user){
  30. $str = "";
  31. $str.="<div style='margin-right:10px;display: flex;align-items: center'>";
  32. $str.='<img data-action="preview-img" src="'.$this->user->avatar.'" style="max-width:50px;max-height:50px;cursor:pointer;margin-right:5px;" class="img img-thumbnail">';
  33. $str.='<div>';
  34. $str.='<p style="margin-bottom: 2px">ID:'.$this->user->id.'</p>';
  35. $str.='<p>'.trans('feeds.fields.nickname').':'.$this->user->name.'</p>';
  36. $str.="</div>";
  37. $str.="</div>";
  38. return $str;
  39. }else{
  40. return '';
  41. }
  42. });
  43. $grid->column('team_id')->display(function ($res){
  44. if($res>0){
  45. $team = Team::query()->find($res);
  46. if($team){
  47. return '<span class="label" style="background:#586cb1">'.trans('feeds.fields.team').'</span>
  48. <br>
  49. <br>
  50. <span class="label" style="background:#586cb1">'.$team->name.'</span>';
  51. }else{
  52. return "";
  53. }
  54. }else{
  55. return '<span class="label" style="background:#21b978">'.trans('feeds.fields.personal').'</span>';
  56. }
  57. });
  58. $grid->column('forward_id')->display(function ($res){
  59. if($res>0){
  60. return '<span class="label" style="background:#586cb1">'.trans('feeds.fields.forward').' ID:'.$res.'</span>';
  61. }else{
  62. return '<span class="label" style="background:#21b978">'.trans('feeds.fields.original').'</span>';
  63. }
  64. });
  65. $grid->column('content')->limit(30);
  66. $grid->column('file_url')->display(function ($v){
  67. return json_decode($v,true);
  68. })->image('', 60,60);
  69. $grid->column('status')->switch();
  70. $grid->column('like_num');
  71. $grid->column('forward_num');
  72. $grid->column('address_info');
  73. $grid->column('match_title')->display(function ($res){
  74. //dd($this->game_per_id);
  75. $game_per_id = isset($this->game_per_id)&&!empty($this->game_per_id)?$this->game_per_id:'###';
  76. if(!empty($res)) {
  77. return '<a href="/admin/game_user_scores?id='.$game_per_id.'" target="_self"><span class="label" style="background:#21b978;line-height: 40px;">' . $res . '</span>
  78. <br><i class="feather icon-bar-chart-2"></i> '.trans('feeds.fields.scorecard').'</a>';
  79. }else{
  80. return '';
  81. }
  82. });
  83. $grid->column('created_at');
  84. $grid->filter(function (Grid\Filter $filter) {
  85. $filter->equal('id');
  86. $filter->like('user.name');
  87. $team = Team::query()->select(['id','name'])->get()->toArray();
  88. $team_arr[0] = trans('feeds.fields.personal');
  89. foreach ($team as $v){
  90. $team_arr[$v['id']] = $v['name'];
  91. }
  92. $filter->equal('team_id')->select($team_arr);
  93. $filter->like('content');
  94. });
  95. //批量操作
  96. // $grid->batchActions(function (Grid\Tools\BatchActions $batch) {
  97. // $batch->disableDelete();
  98. // });
  99. //操作管理
  100. $grid->actions(function (Grid\Displayers\Actions $actions) {
  101. $actions->disableView();
  102. $actions->disableEdit();
  103. $actions->append(new FeedAction());
  104. $actions->append(new LikeAction());
  105. $actions->append(new ForwardAction());
  106. });
  107. return $grid;
  108. }
  109. /**
  110. * Make a show builder.
  111. *
  112. * @param mixed $id
  113. *
  114. * @return Show
  115. */
  116. protected function detail($id)
  117. {
  118. return Show::make($id, new Feed(), function (Show $show) {
  119. $show->field('id');
  120. $show->field('user_id');
  121. $show->field('content');
  122. $show->field('file_url');
  123. $show->field('status');
  124. $show->field('like_num');
  125. $show->field('address_info');
  126. $show->field('match_title');
  127. $show->field('game_per_id');
  128. $show->field('is_delete');
  129. $show->field('created_at');
  130. $show->field('updated_at');
  131. });
  132. }
  133. /**
  134. * Make a form builder.
  135. *
  136. * @return Form
  137. */
  138. protected function form()
  139. {
  140. return Form::make(new Feed(), function (Form $form) {
  141. $form->display('id');
  142. $user = User::query()->select(['id','name'])->get()->toArray();
  143. $user_arr = array();
  144. foreach ($user as $v){
  145. $user_arr[$v['id']] = $v['name'];
  146. }
  147. $form->select('user_id')->options($user_arr);
  148. $form->textarea('content');
  149. $form->text('file_url');
  150. $form->switch('status')->default(1);
  151. $form->number('like_num')->default(0);
  152. $form->text('address_info');
  153. $form->text('match_title');
  154. $form->text('game_per_id');
  155. $form->text('is_delete');
  156. $form->display('created_at');
  157. $form->display('updated_at');
  158. $form->footer(function ($footer) {
  159. // 去掉`查看`checkbox
  160. $footer->disableViewCheck();
  161. // 去掉`继续编辑`checkbox
  162. $footer->disableEditingCheck();
  163. // 去掉`继续创建`checkbox
  164. $footer->disableCreatingCheck();
  165. });
  166. });
  167. }
  168. }