ImportProductController.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace App\Distributor\Controllers;
  3. use App\Distributor\Actions\Extensions\DistProductImportForm;
  4. use App\Distributor\Repositories\BaseProduct;
  5. use App\Admin\Repositories\BaseProductCategory;
  6. use App\Distributor\Actions\BatchCopy;
  7. use App\Distributor\Repositories\DistProductCategory;
  8. use App\Libraries\CommonHelper;
  9. use Dcat\Admin\Form;
  10. use Dcat\Admin\Grid;
  11. use Dcat\Admin\Show;
  12. use Dcat\Admin\Http\Controllers\AdminController;
  13. use Dcat\Admin\Layout\Content;
  14. use Dcat\Admin\Admin;
  15. class ImportProductController extends AdminDistController
  16. {
  17. /**
  18. * page index
  19. */
  20. public function index(Content $content)
  21. {
  22. return $content
  23. ->header(admin_trans( 'admin.product_import'))
  24. ->description('<span style="color: red; font-weight: bold;">'.admin_trans_label('select_products_to_import').'</span>')
  25. ->breadcrumb(['text'=>'list','url'=>''])
  26. ->body($this->grid());
  27. }
  28. //屏蔽删除
  29. public function destroy($id)
  30. {
  31. abort(404);
  32. }
  33. //屏蔽创建
  34. public function create(Content $content)
  35. {
  36. abort(404);
  37. }
  38. //屏蔽编辑
  39. public function edit($id, Content $content)
  40. {
  41. abort(404);
  42. }
  43. /**
  44. * Make a grid builder.
  45. *
  46. * @return Grid
  47. */
  48. protected function grid()
  49. {
  50. return Grid::make(BaseProduct::with(['baseProductCategory','images']), function (Grid $grid) {
  51. $grid->view('admin.grid.table');
  52. $grid->column('id')->display(function () {
  53. return $this->_index+1;
  54. });
  55. $grid->column('title');
  56. $grid->column('sku');
  57. $grid->column('base_product_category.name',admin_trans_label('category_name'));
  58. $grid->column('keywords');
  59. $grid->column('description');
  60. //$grid->column('created_at')->sortable();
  61. //$grid->column('issuance_date');
  62. // 筛选
  63. $grid->filter(function (Grid\Filter $filter) {
  64. $filter->panel();
  65. $filter->expand();
  66. $filter->equal('sku')->width(2);
  67. $filter->like('title')->width(2);
  68. $filter->equal('category_id',admin_trans_label('category'))->select(BaseProductCategory::selectOptions())->width(2);
  69. //$filter->equal('enabled', admin_trans_label('enabled'))->select(admin_trans_array( config('dictionary.enabled')))->width(2);
  70. });
  71. // 删除新增按钮
  72. $grid->disableCreateButton();
  73. //$grid->disableViewButton();
  74. $grid->disableEditButton();
  75. $grid->disableDeleteButton();
  76. $grid->disableBatchDelete();
  77. // 添加批量复制操作
  78. $grid->batchActions(function ($batch) {
  79. //$batch->add(new BatchCopy()); 只能2选1
  80. });
  81. $grid->tools([
  82. new DistProductImportForm(),
  83. ]);
  84. $grid->model()->where('enabled',1)->orderBy("order",'desc')->orderBy("created_at",'desc');
  85. });
  86. }
  87. /**
  88. * Make a show builder.
  89. *
  90. * @param mixed $id
  91. *
  92. * @return Show
  93. */
  94. protected function detail($id)
  95. {
  96. return Show::make($id, BaseProduct::with(['baseProductCategory','images']), function (Show $show) {
  97. // $show->field('id');
  98. $show->field('title');
  99. $show->field('sku');
  100. $show->field('base_product_category.name',admin_trans_label('category_name'));
  101. $show->field('keywords');
  102. $show->field('description');
  103. $show->field('issuance_date');
  104. $show->field('parameters',admin_trans_label('attribute'))->as(function ($items) {
  105. if (is_array($items)) {
  106. // 创建表格的表头
  107. $table = '<table class="table table-bordered table-condensed">';
  108. // 遍历数组并将数据填充到表格中
  109. foreach ($items as $item) {
  110. $table .= '<tr>';
  111. $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>'; // 商品名称
  112. $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>'; // 数量
  113. $table .= '</tr>';
  114. }
  115. $table .= '</table>';
  116. return $table;
  117. }
  118. return ''; // 当没有数组数据时
  119. })->unescape();
  120. $show->field('images')->as(function ($images) {
  121. // 开始生成 HTML
  122. $dataImages = array_column($images, 'image_url');
  123. return CommonHelper::displayImage($dataImages,150);
  124. })->unescape();
  125. $show->field('content')->unescape();
  126. $show->field('seo_title');
  127. $show->field('seo_keywords');
  128. $show->field('seo_description');
  129. $show->field('created_at');
  130. //$show->field('updated_at');
  131. // 禁用操作
  132. $show->disableEditButton();
  133. $show->disableDeleteButton();
  134. });
  135. }
  136. }