123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Actions\Grid\RpcAlbumImport;
- use App\Admin\Forms\RpcAlbumImportForm;
- use App\Admin\Repositories\BaseProductCategory;
- use App\Admin\Repositories\RpcAlbum;
- use App\Admin\Repositories\RpcAlbumFolder;
- use App\Distributor\Actions\Extensions\DistProductImportForm;
- use App\Distributor\Repositories\BaseProduct;
- use App\Libraries\CommonHelper;
- use Dcat\Admin\Admin;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Http\Controllers\AdminController;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Show;
- class ImportProductController extends AdminController
- {
- /**
- * page index
- */
- public function index(Content $content)
- {
- return $content
- ->header(admin_trans( 'admin.product_import'))
- ->description('<span style="color: red; font-weight: bold;">'.admin_trans_label('select_products_to_import').'</span>')
- ->breadcrumb(['text'=>'list','url'=>''])
- ->body($this->grid());
- }
- //屏蔽删除
- public function destroy($id)
- {
- abort(404);
- }
- //屏蔽创建
- public function create(Content $content)
- {
- abort(404);
- }
- //屏蔽编辑
- public function edit($id, Content $content)
- {
- abort(404);
- }
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new RpcAlbum(), function (Grid $grid) {
- $grid->view('admin.grid.table');
- $grid->column('id')->display(function () {
- return $this->_index+1;
- })->width('8%');
- $grid->column('cover')->display(function ($images) {
- $images = json_decode($images);
- // 限制最多显示2个缩略图
- $dataImages = array_slice($images, 0, 1);
- return CommonHelper::displayImage($dataImages,100);
- });
- $grid->column('title');
- $grid->column('model');
- $grid->column('missing_content')->display(function ($missing_content) {
- $missing_content = [];
- if ($this->cover == '[]') {$missing_content[] = '主图';}
- if ($this->en_detail == '[]') {$missing_content[] = '英文详情';}
- if ($this->cn_detail == '[]') {$missing_content[] = '中文详情';}
- if ($this->video == '[]') {$missing_content[] = '视频';}
- if ($this->poster == '[]') {$missing_content[] = '海报';}
- if ($this->cert == '[]') {$missing_content[] = '证书';}
- if ($this->pdf == '[]') {$missing_content[] = 'PDF';}
- return implode(' / ', $missing_content);
- });
- $grid->column('created_at')->sortable();
- $grid->column('updated_at')->sortable();
- // 筛选
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->expand();
- $filter->equal('model')->width(2);
- $filter->equal('folder_id',admin_trans_label('product_category'))->select(RpcAlbumFolder::selectOptions())->width(2);
- });
- // 删除新增按钮
- $grid->disableCreateButton();
- //$grid->disableViewButton();
- $grid->disableEditButton();
- $grid->disableDeleteButton();
- $grid->disableBatchDelete();
- // 添加批量复制操作
- $grid->batchActions(function ($batch) {
- //$batch->add(new BatchCopy()); 只能2选1
- });
- $grid->tools([
- new RpcAlbumImport(),
- ]);
- $grid->model()->where('enabled',1)->orderBy("order",'desc')->orderBy("created_at",'desc');
- });
- }
- /**
- * Make a show builder.
- *
- * @param mixed $id
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new RpcAlbum(), function (Show $show) {
- $show->field('title');
- $show->field('model');
- $show->field('parameters',admin_trans_label('attribute'))->as(function ($items) {
- $items = json_decode($items);
- if (is_array($items)) {
- // 创建表格的表头
- $table = '<table class="table table-bordered table-condensed">';
- // 遍历数组并将数据填充到表格中
- foreach ($items as $item) {
- $item = (array)$item;
- $table .= '<tr>';
- $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item['key'] . '</td>'; // 商品名称
- $table .= '<td style="vertical-align: middle !important;">' . $item['value'] . '</td>'; // 数量
- $table .= '</tr>';
- }
- $table .= '</table>';
- return $table;
- }
- return ''; // 当没有数组数据时
- })->unescape();
- $show->field('cover')->as(function ($images) {
- $images = json_decode($images);
- return CommonHelper::displayImage($images,150);
- })->unescape();
- $show->field('en_detail')->as(function ($images) {
- $images = json_decode($images);
- return CommonHelper::displayImage($images,150);
- })->unescape();
- $show->field('cn_detail')->as(function ($images) {
- $images = json_decode($images);
- return CommonHelper::displayImage($images,150);
- })->unescape();
- $show->field('video')->as(function ($items) {
- $items = json_decode($items);
- return CommonHelper::displayVideo($items,'cover','video_src','150');
- })->unescape();
- $show->field('poster')->as(function ($images) {
- $images = json_decode($images);
- return CommonHelper::displayImage($images,150);
- })->unescape();
- $show->field('cert')->as(function ($images) {
- $images = json_decode($images);
- return CommonHelper::displayImage($images,150);
- })->unescape();
- $show->field('cert')->as(function ($images) {
- $images = json_decode($images);
- return CommonHelper::displayImage($images,150);
- })->unescape();
- $show->field('pdf')->as(function ($items) {
- $items = json_decode($items);
- if (is_array($items)) {
- // 创建表格的表头
- $table = '<table class="table table-bordered table-condensed">';
- // 遍历数组并将数据填充到表格中
- foreach ($items as $item) {
- $table .= '<tr>';
- $table .= '<td style="vertical-align: middle !important;width: 20%">' . $item->pdf_title . '</td>'; // 商品名称
- $table .= '<td style="vertical-align: middle !important;"><a target="_blank" href="' . CommonHelper::ossUrl($item->pdf_src). '">查看</a></td>'; // 数量
- $table .= '</tr>';
- }
- $table .= '</table>';
- return $table;
- }
- return ''; // 当没有数组数据时
- })->unescape();
- // 禁用操作
- $show->disableEditButton();
- $show->disableDeleteButton();
- });
- }
- }
|