4
0
Fork 0

goods-brand

master
panliang 2022-08-01 15:52:00 +08:00
parent a08604bf82
commit 9fcd37b646
14 changed files with 185 additions and 10 deletions

View File

@ -0,0 +1,3 @@
<?php
return [];

View File

@ -0,0 +1,3 @@
<?php
return [];

View File

@ -0,0 +1,13 @@
<?php
return [
'labels' => [
'GoodsBrand' => '品牌管理',
'goods' => '商品管理',
'brand' => '品牌',
],
'fields' => [
'name' => '名称',
'image' => '图片',
]
];

View File

@ -0,0 +1,16 @@
<?php
return [
'labels' => [
'GoodsType' => '商品类别',
'goods' => '商品管理',
'brand' => '类别',
],
'fields' => [
'name' => '名称',
'spec' => '规格',
'attr' => '属性',
'part' => '配件',
'values' => '可选值',
]
];

View File

@ -0,0 +1,15 @@
<!-- $model 当前行数据 -->
<!-- $name 字段名称 -->
<!-- $value 为当前列的值 -->
@if($value)
@foreach($value as $item)
<div class="mt-1">
<span class="label bg-info">{{ $item['name'] }}</span>
@if($item['values'])
@foreach($item['values'] as $subItem)
<span>{{ $subItem }}</span>
@endforeach
@endif
</div>
@endforeach
@endif

View File

@ -5,9 +5,11 @@
@foreach($value as $item)
<div class="mt-1">
<span class="label bg-info">{{ $item['name'] }}</span>
@foreach($item['values'] as $value)
<span>{{ $value['value'] }}({{ $value['price'] }})</span>
@if($item['values'])
@foreach($item['values'] as $subItem)
<span>{{ $subItem['value'] }}({{ $subItem['price'] }})</span>
@endforeach
@endif
</div>
@endforeach
@endif

View File

@ -10,6 +10,8 @@ class GoodsServiceProvider extends ServiceProvider
protected $menu = [
['title' => '商品管理', 'uri' => '', 'icon' => ''],
['title' => '商品分类', 'uri' => 'goods/category', 'icon' => '', 'parent' => '商品管理'],
['title' => '品牌管理', 'uri' => 'goods/brand', 'icon' => '', 'parent' => '商品管理'],
['title' => '商品类别', 'uri' => 'goods/type', 'icon' => '', 'parent' => '商品管理'],
['title' => '商品信息', 'uri' => 'goods', 'icon' => '', 'parent' => '商品管理'],
];
}

View File

@ -0,0 +1,50 @@
<?php
namespace Peidikeji\Goods\Http\Controllers\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Peidikeji\Goods\Models\Goods;
use Peidikeji\Goods\Models\GoodsBrand;
class GoodsBrandController extends AdminController
{
protected $translation = 'peidikeji.dcat-admin-extension-goods::goods-brand';
protected function grid()
{
return Grid::make(new GoodsBrand(), function (Grid $grid) {
$grid->disableRowSelector();
$grid->disableViewButton();
$grid->column('name');
$grid->column('image')->image('', 120);
});
}
protected function form()
{
return Form::make(new GoodsBrand(), function (Form $form) {
$form->text('name');
$form->image('image')->autoUpload()->saveFullUrl()->move('goods/brand');
$form->disableResetButton();
$form->disableCreatingCheck();
$form->disableViewCheck();
$form->disableEditingCheck();
$form->deleting(function (Form $form) {
$data = $form->model()->toArray();
foreach($data as $item) {
$id = data_get($item, 'id');
// 品牌下面包含商品, 阻止删除
if (Goods::where('brand_id', $id)->exists()) {
return $form->response()->error('请先删除关联的商品');
}
}
});
});
}
}

View File

@ -35,7 +35,7 @@ class GoodsCategoryController extends AdminController
$form->text('name')->required();
$form->image('image')
->uniqueName()
->move('article-category')
->move('goods/category')
->autoUpload();
$form->number('sort')
->min(0)

View File

@ -93,16 +93,16 @@ class GoodsController extends AdminController
$form->image('cover_image')
->autoUpload()
->saveFullUrl()
->move('goods')
->move('goods/goods')
->required();
$form->multipleImage('images')
->autoUpload()
->saveFullUrl()
->move('goods');
->move('goods/goods');
$form->multipleImage('content')
->autoUpload()
->saveFullUrl()
->move('goods');
->move('goods/goods');
$form->number('price')->min(0)->attribute('step', 0.01);
$form->switch('on_sale');

View File

@ -0,0 +1,64 @@
<?php
namespace Peidikeji\Goods\Http\Controllers\Admin;
use Dcat\Admin\Form;
use Dcat\Admin\Form\NestedForm;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Peidikeji\Goods\Models\Goods;
use Peidikeji\Goods\Models\GoodsType;
class GoodsTypeController extends AdminController
{
protected $translation = 'peidikeji.dcat-admin-extension-goods::goods-type';
protected function grid()
{
return Grid::make(new GoodsType(), function (Grid $grid) {
$grid->disableRowSelector();
$grid->disableViewButton();
$grid->column('name');
$grid->column('attr')->view('peidikeji.dcat-admin-extension-goods::grid.part');
$grid->column('spec')->view('peidikeji.dcat-admin-extension-goods::grid.part');
$grid->column('part')->view('peidikeji.dcat-admin-extension-goods::grid.part');
});
}
protected function form()
{
return Form::make(new GoodsType(), function (Form $form) {
$form->text('name');
$form->array('attr', function (NestedForm $table) {
$table->text('name')->required();
$table->list('values');
});
$form->array('spec', function (NestedForm $table) {
$table->text('name')->required();
$table->list('values');
});
$form->array('part', function (NestedForm $table) {
$table->text('name')->required();
$table->list('values');
});
$form->disableResetButton();
$form->disableCreatingCheck();
$form->disableViewCheck();
$form->disableEditingCheck();
$form->deleting(function (Form $form) {
$data = $form->model()->toArray();
foreach($data as $item) {
$id = data_get($item, 'id');
// 下面包含商品, 阻止删除
if (Goods::where('type_id', $id)->exists()) {
return $form->response()->error('请先删除关联的商品');
}
}
});
});
}
}

View File

@ -5,5 +5,7 @@ namespace Peidikeji\Goods\Http\Controllers\Admin;
use Illuminate\Support\Facades\Route;
Route::resource('goods/category', GoodsCategoryController::class);
Route::resource('goods/brand', GoodsBrandController::class);
Route::resource('goods/type', GoodsTypeController::class);
Route::resource('goods', GoodsController::class);

View File

@ -11,4 +11,9 @@ class GoodsBrand extends Model
protected $fillable = ['name', 'image'];
public $timestamps = false;
public function goods()
{
return $this->hasMany(Goods::class, 'brand_id');
}
}

View File

@ -59,9 +59,9 @@ class CreateGoodsTable extends Migration
$table->unsignedInteger('stock')->default(0)->comment('库存');
$table->unsignedInteger('sold_count')->default(0)->comment('销量');
$table->decimal('price', 12, 2)->comment('售价');
$table->json('attr')->nullable()->comment('属性');
$table->json('spec')->nullable()->comment('规格');
$table->json('part')->nullable()->comment('配件');
$table->json('attr')->nullable()->comment('属性[{name, value}]');
$table->json('spec')->nullable()->comment('规格[{name, values: [{value, price}]}]');
$table->json('part')->nullable()->comment('配件[{name, values: [{value, price}]}]');
$table->timestamps();
$table->softDeletes();
@ -79,7 +79,7 @@ class CreateGoodsTable extends Migration
$table->string('name')->comment('名称');
$table->decimal('price', 12, 2)->comment('价格');
$table->unsignedInteger('stock')->comment('库存');
$table->json('spec')->nullable()->comment('规格');
$table->json('spec')->nullable()->comment('规格[{name, value, price}]');
$table->foreign('goods_id')->references('id')->on('goods');