ImportProductController.php 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Actions\Grid\RpcAlbumImport;
  4. use App\Admin\Forms\RpcAlbumImportForm;
  5. use App\Admin\Repositories\BaseProductCategory;
  6. use App\Admin\Repositories\RpcAlbum;
  7. use App\Admin\Repositories\RpcAlbumFolder;
  8. use App\Distributor\Actions\Extensions\DistProductImportForm;
  9. use App\Distributor\Repositories\BaseProduct;
  10. use App\Libraries\CommonHelper;
  11. use Dcat\Admin\Admin;
  12. use Dcat\Admin\Grid;
  13. use Dcat\Admin\Http\Controllers\AdminController;
  14. use Dcat\Admin\Layout\Content;
  15. use Dcat\Admin\Show;
  16. class ImportProductController extends AdminController
  17. {
  18. /**
  19. * page index
  20. */
  21. public function index(Content $content)
  22. {
  23. return $content
  24. ->header(admin_trans( 'admin.product_import'))
  25. ->description('<span style="color: red; font-weight: bold;">'.admin_trans_label('select_products_to_import').'</span>')
  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. return Grid::make(new RpcAlbum(), function (Grid $grid) {
  52. $grid->view('admin.grid.table');
  53. $grid->column('id')->display(function () {
  54. return $this->_index+1;
  55. })->width('8%');
  56. $grid->column('cover')->display(function ($images) {
  57. $images = json_decode($images);
  58. // 限制最多显示2个缩略图
  59. $dataImages = array_slice($images, 0, 1);
  60. return CommonHelper::displayImage($dataImages,100);
  61. });
  62. $grid->column('title');
  63. $grid->column('model');
  64. $grid->column('missing_content')->display(function ($missing_content) {
  65. $missing_content = [];
  66. if ($this->cover == '[]') {$missing_content[] = '主图';}
  67. if ($this->en_detail == '[]') {$missing_content[] = '英文详情';}
  68. if ($this->cn_detail == '[]') {$missing_content[] = '中文详情';}
  69. if ($this->video == '[]') {$missing_content[] = '视频';}
  70. if ($this->poster == '[]') {$missing_content[] = '海报';}
  71. if ($this->cert == '[]') {$missing_content[] = '证书';}
  72. if ($this->pdf == '[]') {$missing_content[] = 'PDF';}
  73. return implode(' / ', $missing_content);
  74. });
  75. $grid->column('created_at')->sortable();
  76. $grid->column('updated_at')->sortable();
  77. // 筛选
  78. $grid->filter(function (Grid\Filter $filter) {
  79. $filter->panel();
  80. $filter->expand();
  81. $filter->equal('model')->width(2);
  82. $filter->equal('folder_id',admin_trans_label('product_category'))->select(RpcAlbumFolder::selectOptions())->width(2);
  83. });
  84. // 删除新增按钮
  85. $grid->disableCreateButton();
  86. //$grid->disableViewButton();
  87. $grid->disableEditButton();
  88. $grid->disableDeleteButton();
  89. $grid->disableBatchDelete();
  90. // 添加批量复制操作
  91. $grid->batchActions(function ($batch) {
  92. //$batch->add(new BatchCopy()); 只能2选1
  93. });
  94. $grid->tools([
  95. new RpcAlbumImport(),
  96. ]);
  97. $grid->model()->where('enabled',1)->orderBy("order",'desc')->orderBy("created_at",'desc');
  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 RpcAlbum(), function (Show $show) {
  110. $show->field('title');
  111. $show->field('model');
  112. $show->field('parameters',admin_trans_label('attribute'))->as(function ($items) {
  113. $items = json_decode($items);
  114. if (is_array($items)) {
  115. // 创建表格的表头
  116. $table = '<table class="table table-bordered table-condensed">';
  117. // 遍历数组并将数据填充到表格中
  118. foreach ($items as $item) {
  119. $item = (array)$item;
  120. $table .= '<tr>';
  121. $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>'; // 商品名称
  122. $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>'; // 数量
  123. $table .= '</tr>';
  124. }
  125. $table .= '</table>';
  126. return $table;
  127. }
  128. return ''; // 当没有数组数据时
  129. })->unescape();
  130. $show->field('cover')->as(function ($images) {
  131. $images = json_decode($images);
  132. return CommonHelper::displayImage($images,150);
  133. })->unescape();
  134. $show->field('en_detail')->as(function ($images) {
  135. $images = json_decode($images);
  136. return CommonHelper::displayImage($images,150);
  137. })->unescape();
  138. $show->field('cn_detail')->as(function ($images) {
  139. $images = json_decode($images);
  140. return CommonHelper::displayImage($images,150);
  141. })->unescape();
  142. $show->field('video')->as(function ($items) {
  143. $items = json_decode($items);
  144. return CommonHelper::displayVideo($items,'cover','video_src','150');
  145. })->unescape();
  146. $show->field('poster')->as(function ($images) {
  147. $images = json_decode($images);
  148. return CommonHelper::displayImage($images,150);
  149. })->unescape();
  150. $show->field('cert')->as(function ($images) {
  151. $images = json_decode($images);
  152. return CommonHelper::displayImage($images,150);
  153. })->unescape();
  154. $show->field('cert')->as(function ($images) {
  155. $images = json_decode($images);
  156. return CommonHelper::displayImage($images,150);
  157. })->unescape();
  158. $show->field('pdf')->as(function ($items) {
  159. $items = json_decode($items);
  160. if (is_array($items)) {
  161. // 创建表格的表头
  162. $table = '<table class="table table-bordered table-condensed">';
  163. // 遍历数组并将数据填充到表格中
  164. foreach ($items as $item) {
  165. $table .= '<tr>';
  166. $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item->pdf_title . '</td>'; // 商品名称
  167. $table .= '<td style="vertical-align: middle !important;"><a target="_blank" href="' . CommonHelper::ossUrl($item->pdf_src). '">查看</a></td>'; // 数量
  168. $table .= '</tr>';
  169. }
  170. $table .= '</table>';
  171. return $table;
  172. }
  173. return ''; // 当没有数组数据时
  174. })->unescape();
  175. // 禁用操作
  176. $show->disableEditButton();
  177. $show->disableDeleteButton();
  178. });
  179. }
  180. }