From 478dbe153178eb549c6555e4b523a70181dc5d75 Mon Sep 17 00:00:00 2001 From: vine_liutk <961510893@qq.com> Date: Mon, 15 Jan 2024 13:50:18 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9A=82=E6=97=B6=E4=BF=9D=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Admin/Components.php | 2 +- app/Admin/Controllers/ProductController.php | 111 ++++++++++++++++++ app/Admin/routes.php | 2 + app/Models/Filters/ProductFilter.php | 16 +++ app/Models/Product.php | 10 ++ app/Services/Admin/ProductService.php | 21 ++++ ...024_01_02_114101_create_products_table.php | 5 +- lang/zh_CN/admin.php | 29 +++++ 8 files changed, 194 insertions(+), 2 deletions(-) create mode 100644 app/Admin/Controllers/ProductController.php create mode 100644 app/Models/Filters/ProductFilter.php create mode 100644 app/Services/Admin/ProductService.php diff --git a/app/Admin/Components.php b/app/Admin/Components.php index 51a1dd5..6084a47 100644 --- a/app/Admin/Components.php +++ b/app/Admin/Components.php @@ -35,7 +35,7 @@ class Components extends BaseRenderer { * 2位小数输入框 */ public function decimalControl($name ='decimal', $label = null){ - return amisMake()->NumberControl() + return amisMake()->NumberControl()->size('sm') ->name($name)->label($label ?? __('admin.components.decimal')) ->kilobitSeparator(true) ->percision(2) diff --git a/app/Admin/Controllers/ProductController.php b/app/Admin/Controllers/ProductController.php new file mode 100644 index 0000000..f796b9b --- /dev/null +++ b/app/Admin/Controllers/ProductController.php @@ -0,0 +1,111 @@ +baseCRUD()->tableLayout('fixed') + ->headerToolbar([ + $this->createButton(), + ...$this->baseHeaderToolBar(), + ]) + ->filter($this->baseFilter()->body([ + amis()->GroupControl()->mode('horizontal')->body([ + amis()->TextControl('sku', __('admin.products.sku')) + ->placeholder(__('admin.products.sku')), + amis()->TextControl('name', __('admin.products.name')) + ->placeholder(__('admin.products.name')), + ]), + ])) + ->columns([ + amis()->TableColumn('name', __('admin.products.name'))->width('300px'), + amis()->TableColumn('sku', __('admin.sku'))->sortable(true), + amis()->TableColumn('category.name', __('admin.products.category')), + amis()->TableColumn('cover', __('admin.products.cover'))->type('image')->height('50px')->width('50px')->enlargeAble(true), + amis()->TableColumn('is_sale', __('admin.products.is_sale'))->type('switch'), + amis()->TableColumn('is_recommend', __('admin.products.is_recommend'))->type('switch'), + amis()->Operation()->label(__('admin.actions'))->buttons([ + $this->rowEditButton(), + $this->rowDeleteButton(), + ]) + ]); + + return $this->baseList($crud); + } + + public function form(): Form + { + return $this->baseForm()->panelClassName('px-0')->body([ + amis()->Tabs()->tabsMode('line')->tabs([ + //基础信息 + amis()->Tab()->title(__('admin.products.tab1'))->body([ + amis()->Grid()->columns([ + amis()->Wrapper()->body([ + amis()->TextControl('name', __('admin.products.name'))->required(true), + Components::make()->parentControl(admin_url('api/product_categories/tree-list'), 'category_id', __('admin.products.category')), + + amis()->TextControl('spu', __('admin.products.spu'))->description('*未填写则自动生成唯一spu'), + amis()->TextareaControl('sub_title', __('admin.products.sub_title'))->minRows(5), + + Components::make()->sortControl('virtual_sales', __('admin.products.virtual_sales')), + Components::make()->sortControl('stocks', __('admin.products.stocks'))->description('*已销售过的商品无法直接编辑库存,需前往商品库存中操作。'), + + Components::make()->decimalControl('price', __('admin.products.price')), + + amis()->SwitchControl('is_sale', __('admin.products.is_sale'))->value(false), + amis()->SwitchControl('is_show', __('admin.products.is_show'))->value(false), + + ])->md(4), + amis()->Wrapper()->body([ + Components::make()->imageControl('photos', __('admin.products.photos'))->multiple(true)->draggable(true)->required(true), + Components::make()->cropImageControl('cover', __('admin.products.cover'))->description('*若不选择上传,则默认为相册第一张'), + + Components::make()->sortControl('sort', __('admin.products.sort')), + + amis()->SwitchControl('is_recommend', __('admin.products.is_recommend'))->value(false), + amis()->SwitchControl('is_hot', __('admin.products.is_hot'))->value(false), + amis()->SwitchControl('is_new', __('admin.products.is_new'))->value(false), + + ])->md(8) + ]), + ]), + //详情,信息 + amis()->Tab()->title(__('admin.products.tab2'))->body([ + //详情,基础信息,运费模板,属性标签, + amis()->Grid()->columns([ + amis()->Wrapper()->body([ + Components::make()->keywordsTagControl('t_ids', __('admin.products.tags'), 'product_tag'), + amis()->SelectControl('shipping_tmp_id', __('admin.products.shipping_tmp_id'))->required(true), + amis()->InputKV()->name('base_info')->label('参数信息')->keyPlaceholder('属性')->valuePlaceholder('值'), + ])->md(4), + amis()->Wrapper()->body([ + Components::make()->fuEditorControl('description', __('admin.products.description')), + ])->md(8), + ]), + ]), + //多属性商品 + amis()->Tab()->title(__('admin.products.tab3'))->body([ + + ]) + ]) + ]); + } + + public function detail(): Form + { + return $this->baseDetail()->body([]); + } + +} \ No newline at end of file diff --git a/app/Admin/routes.php b/app/Admin/routes.php index 4ff5e14..a29a4e2 100644 --- a/app/Admin/routes.php +++ b/app/Admin/routes.php @@ -36,6 +36,8 @@ Route::group([ $router->resource('product_categories', \App\Admin\Controllers\ProductCategoryController::class); + $router->resource('products', \App\Admin\Controllers\ProductController::class); + //修改上传 $router->post('upload_file', [\App\Admin\Controllers\IndexController::class, 'uploadFile']); $router->post('upload_image', [\App\Admin\Controllers\IndexController::class, 'uploadImage']); diff --git a/app/Models/Filters/ProductFilter.php b/app/Models/Filters/ProductFilter.php new file mode 100644 index 0000000..b962bc6 --- /dev/null +++ b/app/Models/Filters/ProductFilter.php @@ -0,0 +1,16 @@ +where('name','like', '%'.$name.'%'); + } +} diff --git a/app/Models/Product.php b/app/Models/Product.php index c2ae1d8..5ce1890 100644 --- a/app/Models/Product.php +++ b/app/Models/Product.php @@ -10,4 +10,14 @@ class Product extends Model { use HasFactory; use Filterable; + + protected function serializeDate(\DateTimeInterface $date) + { + return $date->format('Y-m-d H:i:s'); + } + + protected $fillable = [ + 'name', 'sub_title', 'cover', 'photos', 'base_info', 'description', + 'spu', 'sku', 'parent_id', 'category_id', 't_ids', + ]; } diff --git a/app/Services/Admin/ProductService.php b/app/Services/Admin/ProductService.php new file mode 100644 index 0000000..f558e55 --- /dev/null +++ b/app/Services/Admin/ProductService.php @@ -0,0 +1,21 @@ +string('name')->comment('名称'); $table->string('spu')->nullable()->comment('spu'); $table->string('sku')->nullable()->unique()->comment('sku'); + $table->unsignedBigInteger('parent_id')->nullable()->comment('父级'); $table->unsignedBigInteger('category_id')->nullable()->comment('分类'); $table->string('t_ids')->nullable()->comment('标签'); + $table->text('sub_title')->nullable()->comment('副标题'); $table->string('cover')->nullable()->comment('封面'); - $table->text('photo')->nullable()->comment('图片'); + $table->text('photos')->nullable()->comment('图片'); $table->text('base_info')->nullable()->comment('基础信息'); $table->text('description')->nullable()->comment('详情'); @@ -37,6 +39,7 @@ return new class extends Migration $table->unsignedTinyInteger('is_new')->default(0)->comment('上新开关'); $table->unsignedDecimal('sale_price', 10, 2)->default(0.00)->comment('售价'); + $table->unsignedBigInteger('shipping_tmp_id')->nullable()->comment('运费模板'); $table->unsignedInteger('stocks')->default(0)->comment('库存'); $table->timestamps(); diff --git a/lang/zh_CN/admin.php b/lang/zh_CN/admin.php index c73a8d1..c34acb9 100644 --- a/lang/zh_CN/admin.php +++ b/lang/zh_CN/admin.php @@ -320,5 +320,34 @@ return [ 'is_enable' => '启用', 'is_show' => '展示', 'is_recommend' => '推荐' + ], + 'products' => [ + 'name' => '名称', + 'spu' => 'SPU', + 'sku' => 'SKU', + 'category' => '分类', + 'sub_title'=> '副标题', + 'cover' => '封面', + 'photos' => '相册', + 'base_info' => '基础信息', + 'description' => '详情', + 'price' => '售价', + 'virtual_sales' => '虚拟销量', + 'stocks' => '库存', + 'tags' => '标签', + 'shipping_tmp_id' => '运费模板', + + 'sort' => '排序', + + 'is_sale' => '上架', + 'is_show' => '展示', + + 'is_recommend' => '推荐', + 'is_hot' => '热销', + 'is_new' => '新品', + + 'tab1' => '基础信息', + 'tab2' => '详细信息', + 'tab3' => '规格属性', ] ];