batch goods sale
parent
f013e73d61
commit
c1adaf8dc4
|
|
@ -35,7 +35,7 @@ $menus = [
|
|||
['title' => '商品分类', 'icon' => '', 'uri' => '/goods-category', 'permission' => 'goods_category'],
|
||||
['title' => '商品品牌', 'icon' => '', 'uri' => '/goods-brand', 'permission' => 'goods_brand'],
|
||||
['title' => '商品类别', 'icon' => '', 'uri' => '/goods-type', 'permission' => 'goods_type'],
|
||||
['title' => '商品管理', 'icon' => '', 'uri' => '/goods', 'permission' => 'goods'],
|
||||
['title' => '商品管理', 'icon' => '', 'uri' => '/goods', 'permission' => 'goods', 'children' => ['import' => '导入']],
|
||||
]],
|
||||
];
|
||||
```
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Goods\Action;
|
||||
|
||||
use Dcat\Admin\Grid\BatchAction;
|
||||
use Peidikeji\Goods\Models\Goods;
|
||||
|
||||
class BatchGoodsDown extends BatchAction
|
||||
{
|
||||
protected $title = '下架';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$ids = $this->getKey();
|
||||
Goods::whereIn('id', $ids)->update(['on_sale' => 0]);
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
||||
public function confirm()
|
||||
{
|
||||
return ['是否确定?'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace Peidikeji\Goods\Action;
|
||||
|
||||
use Dcat\Admin\Grid\BatchAction;
|
||||
use Peidikeji\Goods\Models\Goods;
|
||||
|
||||
class BatchGoodsUp extends BatchAction
|
||||
{
|
||||
protected $title = '上架';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$ids = $this->getKey();
|
||||
Goods::whereIn('id', $ids)->update(['on_sale' => 1]);
|
||||
|
||||
return $this->response()->success('操作成功')->refresh();
|
||||
}
|
||||
|
||||
public function confirm()
|
||||
{
|
||||
return ['是否确定?'];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -35,20 +35,20 @@ class ImportForm extends Form
|
|||
array_shift($rows);
|
||||
foreach ($rows as $row) {
|
||||
$index = 0;
|
||||
$sn = $row[$index];
|
||||
$category = $row[++$index];
|
||||
$brand = $row[++$index];
|
||||
$type = $row[++$index];
|
||||
$name = $row[++$index];
|
||||
$description = $row[++$index];
|
||||
$cover = $row[++$index];
|
||||
$images = $row[++$index];
|
||||
$content = $row[++$index];
|
||||
$price = $row[++$index];
|
||||
$stock = $row[++$index];
|
||||
$attr = $row[++$index];
|
||||
$spec = $row[++$index];
|
||||
$part = $row[++$index];
|
||||
$sn = data_get($row, $index);
|
||||
$category = data_get($row, ++$index);
|
||||
$brand = data_get($row, ++$index);
|
||||
$type = data_get($row, ++$index);
|
||||
$name = data_get($row, ++$index);
|
||||
$description = data_get($row, ++$index);
|
||||
$cover = data_get($row, ++$index);
|
||||
$images = data_get($row, ++$index);
|
||||
$content = data_get($row, ++$index);
|
||||
$price = data_get($row, ++$index);
|
||||
$stock = data_get($row, ++$index);
|
||||
$attr = data_get($row, ++$index);
|
||||
$spec = data_get($row, ++$index);
|
||||
$part = data_get($row, ++$index);
|
||||
|
||||
if (!$sn) {
|
||||
throw new \Exception('编号必填');
|
||||
|
|
@ -68,13 +68,13 @@ class ImportForm extends Form
|
|||
}
|
||||
$attributes = [
|
||||
'category_id' => $category->id,
|
||||
'brand_id' => $brand?->id,
|
||||
'type_id' => $type?->id,
|
||||
'brand_id' => data_get($brand, 'id'),
|
||||
'type_id' => data_get($type, 'id'),
|
||||
'name' => $name,
|
||||
'description' => $description,
|
||||
'cover_image' => $cover,
|
||||
'images' => $images,
|
||||
'content' => $content,
|
||||
'cover_image' => $this->parseFile($cover),
|
||||
'images' => $this->parseFiles($images),
|
||||
'content' => $this->parseFiles($content),
|
||||
'price' => $price,
|
||||
'stock' => $stock,
|
||||
'attr' => $this->parseAttr($attr),
|
||||
|
|
@ -82,11 +82,7 @@ class ImportForm extends Form
|
|||
'part' => $this->parseAttr($part),
|
||||
];
|
||||
|
||||
$goods = Goods::where('goods_sn', $sn)->first();
|
||||
if (!$goods) {
|
||||
$goods = new Goods();
|
||||
}
|
||||
$goods->updateQuietly($attributes);
|
||||
Goods::updateOrCreate(['goods_sn' => $sn], $attributes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +99,7 @@ class ImportForm extends Form
|
|||
$matches = [$str];
|
||||
}
|
||||
foreach($matches as $item) {
|
||||
preg_match_all('/(.*)\[(.*)\]/', $item[0], $itemMatch);
|
||||
preg_match_all('/(.*)\[(.*)\]/', $item, $itemMatch);
|
||||
$name = data_get($itemMatch, '1.0');
|
||||
$values = [];
|
||||
foreach(explode(',', data_get($itemMatch, '2.0')) as $k) {
|
||||
|
|
@ -118,4 +114,33 @@ class ImportForm extends Form
|
|||
|
||||
return $attr;
|
||||
}
|
||||
|
||||
protected function parseFile($path = null)
|
||||
{
|
||||
if (!$path) {
|
||||
return null;
|
||||
}
|
||||
if (Str::startsWith($path, ['http://', 'https://'])) {
|
||||
return $path;
|
||||
}
|
||||
$disk = Storage::disk('public');
|
||||
|
||||
return $disk->url($path);
|
||||
}
|
||||
|
||||
protected function parseFiles($paths = null)
|
||||
{
|
||||
if (!$paths) {
|
||||
return null;
|
||||
}
|
||||
if (!is_array($paths)) {
|
||||
$paths = explode(',', $paths);
|
||||
}
|
||||
$data = [];
|
||||
foreach($paths as $path) {
|
||||
array_push($data, $this->parseFile($path));
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use Dcat\Admin\Admin;
|
|||
use Dcat\Admin\Form;
|
||||
use Dcat\Admin\Grid;
|
||||
use Dcat\Admin\Grid\Displayers\Actions;
|
||||
use Dcat\Admin\Grid\Tools\BatchActions;
|
||||
use Dcat\Admin\Grid\Tools\Selector;
|
||||
use Dcat\Admin\Http\Controllers\AdminController;
|
||||
use Dcat\Admin\Layout\Content;
|
||||
|
|
@ -14,6 +15,8 @@ use Dcat\Admin\Show;
|
|||
use Dcat\Admin\Show\Tools;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Peidikeji\Goods\Action\BatchGoodsDown;
|
||||
use Peidikeji\Goods\Action\BatchGoodsUp;
|
||||
use Peidikeji\Goods\Action\GridImportGoods;
|
||||
use Peidikeji\Goods\Action\RowGoodsSale;
|
||||
use Peidikeji\Goods\Form\Goods\AttrForm;
|
||||
|
|
@ -137,7 +140,6 @@ class GoodsController extends AdminController
|
|||
$grid->column('is_recommend')->switch();
|
||||
$grid->column('sold_count');
|
||||
|
||||
$grid->disableRowSelector();
|
||||
$grid->createMode(Grid::CREATE_MODE_DEFAULT);
|
||||
|
||||
$user = Admin::user();
|
||||
|
|
@ -166,7 +168,18 @@ class GoodsController extends AdminController
|
|||
|
||||
$actions->delete($user->can('dcat.admin.goods.destroy') && !$row->on_sale);
|
||||
});
|
||||
$grid->tools(new GridImportGoods());
|
||||
$grid->tools(function (Grid\Tools $tools) use ($user) {
|
||||
if ($user->can('dcat.admin.goods.import')) {
|
||||
$tools->append(new GridImportGoods());
|
||||
}
|
||||
});
|
||||
$grid->batchActions(function (BatchActions $batch) use ($user) {
|
||||
if ($user->can('dcat.admin.goods.edit')) {
|
||||
$batch->add(new BatchGoodsUp());
|
||||
$batch->add(new BatchGoodsDown());
|
||||
}
|
||||
$batch->disableDelete($user->cannot('dcat.admin.goods.destroy'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -243,21 +256,31 @@ class GoodsController extends AdminController
|
|||
$form->select('brand_id')->options(GoodsBrand::pluck('name', 'id'));
|
||||
$form->text('name')->required();
|
||||
$form->text('description');
|
||||
$form->text('goods_sn')->rules([$unique], [
|
||||
'unique' => '商品编号已经存在',
|
||||
]);
|
||||
$form->text('goods_sn')->rules([$unique], ['unique' => '商品编号已经存在']);
|
||||
$form->image('cover_image')
|
||||
->uniqueName()
|
||||
->autoUpload()
|
||||
->saveFullUrl()
|
||||
->retainable()
|
||||
->removable(false)
|
||||
->autoSave(false)
|
||||
->move('goods/cover-image')
|
||||
->required();
|
||||
$form->multipleImage('images')
|
||||
->uniqueName()
|
||||
->autoUpload()
|
||||
->saveFullUrl()
|
||||
->retainable()
|
||||
->removable(false)
|
||||
->autoSave(false)
|
||||
->move('goods/images');
|
||||
$form->multipleImage('content')
|
||||
->uniqueName()
|
||||
->autoUpload()
|
||||
->saveFullUrl()
|
||||
->retainable()
|
||||
->removable(false)
|
||||
->autoSave(false)
|
||||
->move('goods/content');
|
||||
|
||||
if ($isCreating || !$model->spec) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue