Merge branch 'master' of https://gitee.com/paddy_technology/dcat-admin
commit
8f06474e7f
|
|
@ -1,3 +1,9 @@
|
|||
# Dcat Admin Extension
|
||||
# Dcat Admin Extension Goods
|
||||
|
||||
Dcat-admin 基础商品管理
|
||||
|
||||
## 安装
|
||||
|
||||
- 先安装 [dcat-admin](git@gitee.com:paddy_technology/dcat-admin.git)
|
||||
- `composer config repositories.peidikeji/dcat-admin-extension-goods git git@gitee.com:paddy_technology/dcat-admin-extension-goods.git`
|
||||
- `composer require peidikeji/dcat-admin-extension-goods`
|
||||
|
|
|
|||
|
|
@ -14,5 +14,6 @@ return [
|
|||
'stock' => '库存',
|
||||
'spec' => '规格',
|
||||
'origin_price' => '原价',
|
||||
'discount_price' => '折扣价',
|
||||
]
|
||||
];
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ return [
|
|||
'goods_sn' => '编号',
|
||||
'cover_image' => '封面图',
|
||||
'price' => '售价',
|
||||
'discount_price' => '折扣价',
|
||||
'spec' => '规格',
|
||||
'attr' => '属性',
|
||||
'part' => '配件',
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ class GoodsService
|
|||
{
|
||||
$spec = data_get($options, 'spec', $goods->spec);
|
||||
$price = data_get($options, 'price', $goods->price);
|
||||
$discountPrice = data_get($options, 'discount_price', $goods->discount_price);
|
||||
$name = data_get($options, 'name', $goods->name);
|
||||
$stock = data_get($options, 'stock', $goods->stock);
|
||||
$nameAdd = !!data_get($options, 'name_add', false);
|
||||
|
|
@ -53,11 +54,13 @@ class GoodsService
|
|||
$cartesianList = $this->cartesianProduct($specList);
|
||||
foreach($cartesianList as $items) {
|
||||
$specPrice = $priceAdd ? $price + array_sum(array_column($items, 'price')) : $price;
|
||||
$specDiscountPrice = $priceAdd ? $discountPrice + array_sum(array_column($items, 'price')) : $discountPrice;
|
||||
$specName = $nameAdd ? $name . ' ' . implode(' ', array_column($items, 'value')) : $name;
|
||||
$exists = $goods->skus()->jsonArray($items)->exists();
|
||||
$attributes = [
|
||||
'name' => $specName,
|
||||
'price' => $specPrice,
|
||||
'discount_price' => $specDiscountPrice,
|
||||
'stock' => $stock,
|
||||
'spec' => $items,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ class GoodsServiceProvider extends ServiceProvider
|
|||
protected $css = [
|
||||
'goods.css'
|
||||
];
|
||||
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' => '商品管理'],
|
||||
];
|
||||
// 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' => '商品管理'],
|
||||
// ];
|
||||
|
||||
public function init()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -32,12 +32,6 @@ class GoodsBrandController extends AdminController
|
|||
->autoUpload()
|
||||
->saveFullUrl()
|
||||
->move('goods/brand');
|
||||
// $form->oss('file')->config([
|
||||
// 'accessId' => 'LTAI5tFMaynxgZ9aDMNLxpU9',
|
||||
// 'accessKey' => 'pecJA3LX2sQyWxWDMUUb5NhsMe4Czu',
|
||||
// 'host' => 'https://zcs-test.oss-cn-chengdu.aliyuncs.com',
|
||||
// 'dir' => 'mv',
|
||||
// ]);
|
||||
|
||||
$form->disableResetButton();
|
||||
$form->disableCreatingCheck();
|
||||
|
|
|
|||
|
|
@ -125,6 +125,7 @@ class GoodsController extends AdminController
|
|||
$show->field('type.name');
|
||||
$show->field('name');
|
||||
$show->field('price');
|
||||
$show->field('discount_price');
|
||||
$show->field('cover_image')->image('', 100);
|
||||
$show->field('images')->image('', 100);
|
||||
$show->field('content')->image('');
|
||||
|
|
@ -174,6 +175,7 @@ class GoodsController extends AdminController
|
|||
->move('goods/content');
|
||||
|
||||
$form->number('price')->min(0)->attribute('step', 0.01);
|
||||
$form->number('discount_price')->min(0)->attribute('step', 0.01);
|
||||
$form->switch('on_sale');
|
||||
|
||||
$form->disableResetButton();
|
||||
|
|
|
|||
|
|
@ -73,17 +73,9 @@ class GoodsSkuController extends Controller
|
|||
$show->field('sn');
|
||||
$show->field('name');
|
||||
$show->field('price');
|
||||
$show->field('discount_price');
|
||||
$show->field('stock');
|
||||
$show->field('spec')->view('peidikeji.dcat-admin-extension-goods::grid.spec');
|
||||
// $goods = $show->model()->goods;
|
||||
// foreach($goods->spec as $key => $item) {
|
||||
// $show->field('spec_' . $key, $item['name'])->as(function () use ($item) {
|
||||
// $filtered = current(array_filter($this->spec, fn($subItem) => $subItem['name'] === $item['name']));
|
||||
// $value = data_get($filtered, 'value');
|
||||
// $price = data_get($filtered, 'price');
|
||||
// return '<span class="label bg-info">'.$value.'</span>';
|
||||
// })->unescape();
|
||||
// }
|
||||
});
|
||||
return $content
|
||||
->translation($this->translation)
|
||||
|
|
@ -98,7 +90,8 @@ class GoodsSkuController extends Controller
|
|||
$unqiue = Rule::unique('goods_sku', 'sn')->ignore($form->model()->id);
|
||||
$form->text('sn')->rules([$unqiue], ['unique' => '货号已经存在'])->required();
|
||||
$form->text('name')->default($goods->name);
|
||||
$form->number('price')->min(0)->default($goods->price);
|
||||
$form->number('price')->min(0)->attribute('step', 0.01)->default($goods->price);
|
||||
$form->number('discount_price')->min(0)->attribute('step', 0.01)->default($goods->discount_price);
|
||||
$form->number('stock')->min(0)->default($goods->stock);
|
||||
$form->hidden('spec')->customFormat(fn($v) => json_encode($v));
|
||||
$form->hidden('goods_id')->default($goods->id);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class Goods extends Model
|
|||
|
||||
protected $table = 'goods';
|
||||
|
||||
protected $fillable = ['attr', 'category_id', 'type_id', 'brand_id', 'content', 'cover_image', 'deleted_at', 'description', 'goods_sn', 'images', 'name', 'on_sale', 'part', 'price', 'sold_count', 'spec', 'stock'];
|
||||
protected $fillable = ['attr', 'category_id', 'type_id', 'brand_id', 'content', 'cover_image', 'deleted_at', 'description', 'goods_sn', 'images', 'name', 'on_sale', 'part', 'price', 'discount_price', 'sold_count', 'spec', 'stock'];
|
||||
|
||||
protected $casts = [
|
||||
'attr' => 'array',
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ class GoodsSku extends Model
|
|||
{
|
||||
protected $table = 'goods_sku';
|
||||
|
||||
protected $fillable = ['sn', 'goods_id', 'name', 'price', 'stock', 'spec'];
|
||||
protected $fillable = ['sn', 'goods_id', 'name', 'price', 'discount_price', 'stock', 'spec'];
|
||||
|
||||
protected $casts = [
|
||||
'spec' => 'array',
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@ class CreateGoodsTable extends Migration
|
|||
$table->unsignedInteger('stock')->default(0)->comment('库存');
|
||||
$table->unsignedInteger('sold_count')->default(0)->comment('销量');
|
||||
$table->decimal('price', 12, 2)->comment('售价');
|
||||
$table->decimal('discount_price', 12, 2)->comment('折扣价');
|
||||
$table->json('attr')->nullable()->comment('属性[{name, values: [{name, value}]}]');
|
||||
$table->json('spec')->nullable()->comment('规格[{name, values: [{name, value}]}]');
|
||||
$table->json('part')->nullable()->comment('配件[{name, values: [{name, value}]}]');
|
||||
|
|
@ -79,6 +80,7 @@ class CreateGoodsTable extends Migration
|
|||
$table->unsignedBigInteger('goods_id')->comment('所属商品, 关联 goods.id');
|
||||
$table->string('name')->comment('名称');
|
||||
$table->decimal('price', 12, 2)->comment('价格');
|
||||
$table->decimal('discount_price', 12, 2)->comment('折扣价');
|
||||
$table->unsignedInteger('stock')->comment('库存');
|
||||
$table->json('spec')->nullable()->comment('规格[{name, value, price}]');
|
||||
|
||||
|
|
|
|||
|
|
@ -89,6 +89,7 @@ class GoodsTableSeeder extends Seeder
|
|||
],
|
||||
'stock' => 100,
|
||||
'price' => 6499.00,
|
||||
'discount_price' => 6499,
|
||||
'attr' => [
|
||||
['name' => '主体', 'values' => [
|
||||
['name' => '入网型号', 'value' => '5G'],
|
||||
|
|
@ -132,6 +133,7 @@ class GoodsTableSeeder extends Seeder
|
|||
],
|
||||
'stock' => 150,
|
||||
'price' => 17999.00,
|
||||
'discount_price' => 17999,
|
||||
'attr' => [
|
||||
['name' => '显示器', 'values' => [
|
||||
['name' => '屏幕类型', 'value' => 'LED 背光显示屏'],
|
||||
|
|
|
|||
Loading…
Reference in New Issue