WxAttachmentController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\WxAttachment;
  4. use App\Jobs\Attachment\VideoCosReviewSubmit;
  5. use App\Wen\Utils\Settings;
  6. use App\Wen\Utils\StrUtils;
  7. use App\Wen\Utils\Utils;
  8. use Dcat\Admin\Form;
  9. use Dcat\Admin\Grid;
  10. use Dcat\Admin\Show;
  11. use Dcat\Admin\Http\Controllers\AdminController;
  12. class WxAttachmentController extends AdminController
  13. {
  14. /**
  15. * Make a grid builder.
  16. *
  17. * @return Grid
  18. */
  19. protected function grid()
  20. {
  21. return Grid::make(new WxAttachment(), function (Grid $grid) {
  22. $grid->simplePaginate();
  23. $grid->quickSearch(['id', 'user_id', 'path'])->placeholder('搜索id, 用户id,路径名...')->width(35);
  24. $grid->column('id')->sortable();
  25. $grid->column('users', '头像')->display(function ($v) {
  26. if($this->user['user_avatar'] ?? '') {
  27. return '<img src="' . ($this->user['user_avatar'] ?? Settings::get('img_default', 'https://img.mini.minisns.cn/icons/dafault.png')) . '" style="border-radius:50px;width:30px;" />';
  28. }
  29. return '';
  30. })->width('50px');
  31. $grid->column('user')->display(function ($v) {
  32. if($v && $v['user_name']){
  33. return '<a target="_blank" href="'.admin_url('/users?id='.$v['id']).'">'.$v['user_name'].'</a>' ?? '用户已删除';
  34. }
  35. return '';
  36. })->width('100px');
  37. // $grid->column('path')->image('',80,200);
  38. $grid->column('paths', '路径')->display(function () {
  39. return '<a target="_blank" href="'. $this->domain . '/' . $this->path .'">'. $this->domain . '/' . $this->path . '</a>';
  40. });
  41. $grid->column('show', '路径')->display(function ($v) {
  42. $url = $this->domain . '/' . $this->path;
  43. if(StrUtils::endsWith($url, '.mp4')){
  44. $file_type = 'video';
  45. }else if(StrUtils::endsWith($url, ['.jpg', '.png', 'jpeg', '.webp', '.gif'])){
  46. $file_type = 'image';
  47. }else if(StrUtils::endsWith($url, ['.mp3'])){
  48. $file_type = 'audio';
  49. }else{
  50. $file_type = 'other';
  51. }
  52. if(in_array($file_type, ['video', 'image', 'audio'])){
  53. if($file_type == 'image'){
  54. return '<a target="_blank" href="'. $url .'"><img src="'. Utils::imgWithStyle($url, 2) . '" style="max-height: 100px;"/></a>';
  55. }else if($file_type == 'audio'){
  56. return '<audio controls><source src="'.$url.'" type="audio/mp3"></audio>';
  57. }else if($file_type == 'video'){
  58. return '<video controls width="150">
  59. <source src="'.$url.'" type="video/mp4">
  60. 您的浏览器不支持 video 标签。
  61. </video>';
  62. }
  63. return '';
  64. }
  65. });
  66. $grid->column('store_type','保存位置');
  67. $grid->column('created_at');
  68. $grid->column('cos_review')->using([0 => '正常', 1 => '确认违规', 2=> '疑似违规', 3=>'未审', 4=>'送审中', 5=>'待查询结果'])->label([
  69. 0 => '#5ac725',
  70. 1 => '#f56c6c',
  71. 2 => '#f9ae3d',
  72. 3 => 'gray',
  73. 4 => 'gray',
  74. 5 => 'gray'
  75. ])->display(function ($v){
  76. if($this->cos_review == 4){
  77. VideoCosReviewSubmit::dispatch($this->id);
  78. }
  79. return $v;
  80. })->sortable();
  81. $grid->column('state', '附件状态')->using([0 => '未引用', 1 => '已引用', 2=> '已清理', 3=>'cos冻结中', 4=>'cos已转移'])->label([
  82. 0 => 'red',
  83. 1 => 'primary',
  84. 2 => 'default',
  85. 3 => '#f9ae3d',
  86. 4 => '#f9ae3d'
  87. ])->sortable();
  88. // $grid->column('updated_at');
  89. $grid->model()->orderBy('id', 'desc');
  90. $grid->filter(function (Grid\Filter $filter) {
  91. $filter->equal('id');
  92. $filter->equal('user_id');
  93. });
  94. // $grid->disableActions();
  95. $grid->disableViewButton();
  96. $grid->disableEditButton();
  97. $grid->disableCreateButton();
  98. });
  99. }
  100. /**
  101. * Make a show builder.
  102. *
  103. * @param mixed $id
  104. *
  105. * @return Show
  106. */
  107. protected function detail($id)
  108. {
  109. return Show::make($id, new WxAttachment(), function (Show $show) {
  110. $show->field('id');
  111. $show->field('path');
  112. $show->field('cos_review');
  113. $show->field('created_at');
  114. $show->field('updated_at');
  115. $show->disableEditButton();
  116. });
  117. }
  118. /**
  119. * Make a form builder.
  120. *
  121. * @return Form
  122. */
  123. protected function form()
  124. {
  125. return Form::make(new WxAttachment(), function (Form $form) {
  126. $form->display('id');
  127. $form->text('path');
  128. $form->deleting(function (Form $form){
  129. global $__MINI_GLOBAL_TENANT_ID__;
  130. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  131. return $form->response()->error('权限不足,不可以删除其他分站对象');
  132. }
  133. });
  134. });
  135. }
  136. }