商品导入
parent
be44da76fa
commit
dca26e9da2
|
|
@ -25,9 +25,9 @@ return [
|
|||
'brand' => [
|
||||
'name' => '品牌',
|
||||
],
|
||||
'type_id' => '类别',
|
||||
'type_id' => '类型',
|
||||
'type' => [
|
||||
'name' => '类别',
|
||||
'name' => '类型',
|
||||
],
|
||||
'name' => '名称',
|
||||
'goods_sn' => '编号',
|
||||
|
|
|
|||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Goods\Action;
|
||||
|
||||
use Dcat\Admin\Grid\Tools\AbstractTool;
|
||||
use Dcat\Admin\Widgets\Modal;
|
||||
use Peidikeji\Goods\Form\Goods\ImportForm;
|
||||
|
||||
class GridImportGoods extends AbstractTool
|
||||
{
|
||||
protected $title = '导入';
|
||||
|
||||
protected function html()
|
||||
{
|
||||
return Modal::make()
|
||||
->lg()
|
||||
->body(ImportForm::make())
|
||||
->title($this->title)
|
||||
->button('<button type="button" class="btn btn-primary grid-refresh btn-mini btn-outline"><i class="feather icon-upload"></i> '.$this->title.' </button>');
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Goods\Form\Goods;
|
||||
|
||||
use Dcat\Admin\Widgets\Form;
|
||||
use Dcat\EasyExcel\Excel;
|
||||
use Dcat\EasyExcel\Support\SheetCollection;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ImportForm extends Form
|
||||
{
|
||||
protected $buttons = ['reset' => false, 'submit' => true, 'back' => false];
|
||||
|
||||
public function handle(array $input)
|
||||
{
|
||||
$disk = Storage::disk('public');
|
||||
Excel::import($disk->path($input['file']))->headings(false)->first()->chunk(500, function (SheetCollection $collection) {
|
||||
$rows = $collection->toArray();
|
||||
// dd($rows);
|
||||
});
|
||||
|
||||
return $this->response()->success('导入成功');
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
$this->file('file')->autoUpload()->uniqueName()->move('goods/import')->accept('xlsx,xls')->disk('public');
|
||||
}
|
||||
}
|
||||
|
|
@ -12,9 +12,9 @@ use Dcat\Admin\Layout\Content;
|
|||
use Dcat\Admin\Layout\Row;
|
||||
use Dcat\Admin\Show;
|
||||
use Dcat\Admin\Show\Tools;
|
||||
use Dcat\Admin\Widgets\Card;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Peidikeji\Goods\Action\GridImportGoods;
|
||||
use Peidikeji\Goods\Action\RowGoodsSale;
|
||||
use Peidikeji\Goods\Form\Goods\AttrForm;
|
||||
use Peidikeji\Goods\Form\Goods\PartForm;
|
||||
|
|
@ -93,6 +93,7 @@ class GoodsController extends AdminController
|
|||
protected function grid()
|
||||
{
|
||||
return Grid::make(Goods::with(['category', 'brand', 'type', 'skus']), function (Grid $grid) {
|
||||
$grid->export();
|
||||
$grid->model()->sort();
|
||||
|
||||
$grid->selector(function (Selector $selector) {
|
||||
|
|
@ -165,6 +166,7 @@ class GoodsController extends AdminController
|
|||
|
||||
$actions->delete($user->can('dcat.admin.goods.destroy') && ! $row->on_sale);
|
||||
});
|
||||
$grid->tools(new GridImportGoods());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -270,6 +272,8 @@ class GoodsController extends AdminController
|
|||
$form->disableCreatingCheck();
|
||||
$form->disableViewCheck();
|
||||
$form->disableEditingCheck();
|
||||
$form->disableDeleteButton();
|
||||
$form->disableViewButton();
|
||||
|
||||
$form->creating(function (Form $form) {
|
||||
if (! $form->goods_sn) {
|
||||
|
|
|
|||
|
|
@ -58,9 +58,10 @@ class GoodsSkuController extends Controller
|
|||
}
|
||||
|
||||
$user = Admin::user();
|
||||
$grid->showCreateButton($user->can('dcat.admin.goods_sku.create'));
|
||||
$grid->showDeleteButton($user->can('dcat.admin.goods_sku.destroy'));
|
||||
$grid->showEditButton($user->can('dcat.admin.goods_sku.edit'));
|
||||
$grid->showCreateButton(!$goods->on_sale && $user->can('dcat.admin.goods_sku.create'));
|
||||
$grid->showDeleteButton(!$goods->on_sale && $user->can('dcat.admin.goods_sku.destroy'));
|
||||
$grid->showEditButton(!$goods->on_sale && $user->can('dcat.admin.goods_sku.edit'));
|
||||
$grid->showViewButton($user->can('dcat.admin.goods_sku.show'));
|
||||
});
|
||||
|
||||
return $content
|
||||
|
|
@ -177,7 +178,7 @@ class GoodsSkuController extends Controller
|
|||
if ($goods->spec) {
|
||||
$form->checkbox('name_append', '')->options([1 => '是否在名称上面追加属性值']);
|
||||
}
|
||||
$form->number('price')->min(0)->default($goods->price);
|
||||
$form->currency('price')->symbol('¥')->default($goods->price);
|
||||
if ($goods->spec) {
|
||||
$form->checkbox('price_append', '')->options([1 => '是否在价格上面追加属性的加价'])->default([1]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue