SiteAlbumController.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace App\Distributor\Controllers;
  3. use App\Admin\Actions\Grid\RpcAlbumImport;
  4. use App\Admin\Forms\RpcAlbumImportForm;
  5. use App\Distributor\Repositories\RpcAlbum;
  6. use App\Distributor\Repositories\RpcAlbumFolder;
  7. use App\Distributor\Repositories\DistAdminDistributor;
  8. use App\Libraries\CommonHelper;
  9. use Dcat\Admin\Grid;
  10. use Dcat\Admin\Http\Controllers\AdminController;
  11. use Dcat\Admin\Layout\Content;
  12. use Dcat\Admin\Show;
  13. class SiteAlbumController extends AdminController
  14. {
  15. public function title()
  16. {
  17. return admin_trans( 'admin.promotional_materials');
  18. }
  19. /**
  20. * page index
  21. */
  22. public function index(Content $content)
  23. {
  24. return $content
  25. ->header(admin_trans( 'admin.promotional_materials'))
  26. ->breadcrumb(['text'=>'list','url'=>''])
  27. ->body($this->grid());
  28. }
  29. //屏蔽删除
  30. public function destroy($id)
  31. {
  32. abort(404);
  33. }
  34. //屏蔽创建
  35. public function create(Content $content)
  36. {
  37. abort(404);
  38. }
  39. //屏蔽编辑
  40. public function edit($id, Content $content)
  41. {
  42. abort(404);
  43. }
  44. /**
  45. * Make a grid builder.
  46. *
  47. * @return Grid
  48. */
  49. protected function grid()
  50. {
  51. //相册分类
  52. $rpcAlbumFolder = RpcAlbumFolder::selectOptions();
  53. return Grid::make(new RpcAlbum(), function (Grid $grid) use ($rpcAlbumFolder) {
  54. $grid->view('admin.grid.table');
  55. $grid->column('id')->display(function () {
  56. return $this->_index+1;
  57. });
  58. $grid->column('cover')->display(function ($images) {
  59. $images = json_decode($images);
  60. // 限制最多显示2个缩略图
  61. $dataImages = array_slice($images, 0, 1);
  62. return CommonHelper::displayImage($dataImages,100);
  63. });
  64. $grid->column('title');
  65. $grid->column('model');
  66. $grid->column('updated_at')->sortable();
  67. // 筛选
  68. $grid->filter(function (Grid\Filter $filter) use ($rpcAlbumFolder) {
  69. $filter->panel();
  70. $filter->expand();
  71. $filter->equal('model')->width(2);
  72. $filter->equal('folder_id',admin_trans_label('product_category'))->select($rpcAlbumFolder)->width(2);
  73. });
  74. // 删除新增按钮
  75. $grid->disableCreateButton();
  76. $grid->disableEditButton();
  77. $grid->disableDeleteButton();
  78. $grid->disableBatchDelete();
  79. // 添加批量复制操作
  80. $grid->batchActions(function ($batch) {
  81. //$batch->add(new BatchCopy()); 只能2选1
  82. });
  83. $grid->model()->where('enabled',1)->orderBy("order",'desc')->orderBy("created_at",'desc');
  84. });
  85. }
  86. /**
  87. * Make a show builder.
  88. *
  89. * @param mixed $id
  90. *
  91. * @return Show
  92. */
  93. protected function detail($id)
  94. {
  95. return Show::make($id, new RpcAlbum(), function (Show $show) {
  96. $show->field('title');
  97. $show->field('model');
  98. $show->field('parameters',admin_trans_label('attribute'))->as(function ($items) {
  99. $items = json_decode($items);
  100. if (is_array($items)) {
  101. // 创建表格的表头
  102. $table = '<table class="table table-bordered table-condensed">';
  103. // 遍历数组并将数据填充到表格中
  104. foreach ($items as $item) {
  105. $item = (array)$item;
  106. $table .= '<tr>';
  107. $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>'; // 商品名称
  108. $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>'; // 数量
  109. $table .= '</tr>';
  110. }
  111. $table .= '</table>';
  112. return $table;
  113. }
  114. return ''; // 当没有数组数据时
  115. })->unescape();
  116. $show->field('cover')->as(function ($images) {
  117. $images = json_decode($images);
  118. return CommonHelper::displayImage($images,150);
  119. })->unescape();
  120. $show->field('en_detail')->as(function ($images) {
  121. $images = json_decode($images);
  122. $html = '<div style="text-align: center">';
  123. foreach ($images as $key => $image) {
  124. $url = CommonHelper::ossUrl($image);
  125. $html .= '<img src="' . $url . '" style="max-width:90%;margin-bottom:10px">';
  126. }
  127. $html .= '</div>';
  128. return $html;
  129. })->unescape();
  130. $show->field('video')->as(function ($items) {
  131. $items = json_decode($items);
  132. return CommonHelper::displayVideo($items,'cover','video_src','150');
  133. })->unescape();
  134. $show->field('poster')->as(function ($images) {
  135. $images = json_decode($images);
  136. return CommonHelper::displayImage($images,150);
  137. })->unescape();
  138. $show->field('cert')->as(function ($images) {
  139. $images = json_decode($images);
  140. return CommonHelper::displayImage($images,150);
  141. })->unescape();
  142. $show->field('cert')->as(function ($images) {
  143. $images = json_decode($images);
  144. return CommonHelper::displayImage($images,150);
  145. })->unescape();
  146. $show->field('pdf')->as(function ($items) {
  147. $items = json_decode($items);
  148. if (is_array($items)) {
  149. // 创建表格的表头
  150. $table = '<table class="table table-bordered table-condensed">';
  151. // 遍历数组并将数据填充到表格中
  152. foreach ($items as $item) {
  153. $table .= '<tr>';
  154. $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item->pdf_title . '</td>'; // 商品名称
  155. $table .= '<td style="vertical-align: middle !important;"><a target="_blank" href="' . CommonHelper::ossUrl($item->pdf_src). '">查看</a></td>'; // 数量
  156. $table .= '</tr>';
  157. }
  158. $table .= '</table>';
  159. return $table;
  160. }
  161. return ''; // 当没有数组数据时
  162. })->unescape();
  163. // 禁用操作
  164. $show->disableEditButton();
  165. $show->disableDeleteButton();
  166. });
  167. }
  168. }