diff --git a/app/Admin/Actions/Grid/SkuGift.php b/app/Admin/Actions/Grid/SkuGift.php new file mode 100644 index 00000000..c29a81a1 --- /dev/null +++ b/app/Admin/Actions/Grid/SkuGift.php @@ -0,0 +1,44 @@ +'; + + public function title() + { + if ($this->title) { + return $this->title.' '.__('admin_message.actions.grid.sku_gift'); + } + + return __('admin_message.actions.grid.sku_gift'); + } + + /** + * @param Model|Authenticatable|HasPermissions|null $user + * + * @return bool + */ + protected function authorize($user): bool + { + return $user->can('dcat.admin.product_skus.gift'); + } + + public function render() + { + $form = SkuGiftForm::make()->payload(['id'=>$this->getKey()]); + return Modal::make() + ->lg() + ->title($this->title()) + ->body($form) + ->button($this->title()); + } +} diff --git a/app/Admin/Controllers/ProductGiftController.php b/app/Admin/Controllers/ProductGiftController.php new file mode 100644 index 00000000..84a03737 --- /dev/null +++ b/app/Admin/Controllers/ProductGiftController.php @@ -0,0 +1,74 @@ +column('id')->sortable(); + $grid->column('sku_id'); + $grid->column('gift_sku_id'); + $grid->column('num'); + $grid->column('sent'); + $grid->column('created_at'); + $grid->column('updated_at')->sortable(); + + $grid->filter(function (Grid\Filter $filter) { + $filter->equal('id'); + + }); + }); + } + + /** + * Make a show builder. + * + * @param mixed $id + * + * @return Show + */ + protected function detail($id) + { + return Show::make($id, new ProductGift(), function (Show $show) { + $show->field('id'); + $show->field('sku_id'); + $show->field('gift_sku_id'); + $show->field('num'); + $show->field('sent'); + $show->field('created_at'); + $show->field('updated_at'); + }); + } + + /** + * Make a form builder. + * + * @return Form + */ + protected function form() + { + return Form::make(new ProductGift(), function (Form $form) { + $form->display('id'); + $form->text('sku_id'); + $form->text('gift_sku_id'); + $form->text('num'); + $form->text('sent'); + + $form->display('created_at'); + $form->display('updated_at'); + }); + } +} diff --git a/app/Admin/Forms/SkuGift.php b/app/Admin/Forms/SkuGift.php new file mode 100644 index 00000000..20735f3a --- /dev/null +++ b/app/Admin/Forms/SkuGift.php @@ -0,0 +1,78 @@ +gifts()->saveMany($giftSku); + + ProductGift::whereIn('id', $delGiftIds)->delete(); + DB::commit(); + } catch (Throwable $th) { + DB::rollBack(); + report($th); + return $this->response()->error('操作失败:'.$th->getMessage())->refresh(); + } + + return $this->response() + ->success(__('admin.update_succeeded')) + ->refresh(); + } + + /** + * Build a form here. + */ + public function form() + { + $id = $this->payload['id'] ?? 0; + $sku = ProductSku::with('gifts')->findOrFail($id); + + $this->hasMany('gifts', function (NestedForm $form) { + $form->select('gift_sku_id')->options(function ($id) { + $sku = ProductSku::find($id); + if ($sku) { + return [$sku->id => $sku->name]; + } + })->ajax(admin_route('api.product_skus'))->required(); + $form->number('num')->default(1); + $form->number('limit')->default(0); + })->customFormat(function () use ($sku) { + return $sku->gifts; + }); + $this->hidden('sku_id')->value($id); + } +} diff --git a/app/Admin/Renderable/ProductSkuTable.php b/app/Admin/Renderable/ProductSkuTable.php index ecad5eff..36a2ebaa 100644 --- a/app/Admin/Renderable/ProductSkuTable.php +++ b/app/Admin/Renderable/ProductSkuTable.php @@ -5,6 +5,7 @@ namespace App\Admin\Renderable; use App\Admin\Actions\Grid\ReleaseCancel; use App\Admin\Actions\Grid\ReleaseDown; use App\Admin\Actions\Grid\ReleaseUp; +use App\Admin\Actions\Grid\SkuGift; use App\Admin\Actions\Grid\SkuSyncSpu; use App\Admin\Extensions\Grid\Tools\Product\AddSku; use App\Admin\Extensions\Grid\Tools\Product\BatchReleaseCancel; @@ -86,6 +87,7 @@ class ProductSkuTable extends Grid $actions->append(new ReleaseDown()); } } + $actions->append(new SkuGift()); }); $grid->filter(function (Grid\Filter $filter) { diff --git a/app/Admin/Repositories/ProductGift.php b/app/Admin/Repositories/ProductGift.php new file mode 100644 index 00000000..b1008276 --- /dev/null +++ b/app/Admin/Repositories/ProductGift.php @@ -0,0 +1,16 @@ +hasMany(ProductGift::class, 'sku_id'); + } } diff --git a/database/migrations/2021_12_06_135928_create_product_gifts_table.php b/database/migrations/2021_12_06_135928_create_product_gifts_table.php new file mode 100644 index 00000000..0268ca33 --- /dev/null +++ b/database/migrations/2021_12_06_135928_create_product_gifts_table.php @@ -0,0 +1,36 @@ +id(); + $table->unsignedBigInteger('sku_id')->comment('主SKU商品ID'); + $table->unsignedBigInteger('gift_sku_id')->comment('赠品SKU商品ID'); + $table->unsignedInteger('num')->default(0)->comment('赠送数量'); + $table->unsignedInteger('limit')->default(0)->comment('上限数量'); + $table->unsignedInteger('sent')->default(0)->comment('已送数量'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('product_gifts'); + } +} diff --git a/dcat_admin_ide_helper.php b/dcat_admin_ide_helper.php index c824800c..00c560a8 100644 --- a/dcat_admin_ide_helper.php +++ b/dcat_admin_ide_helper.php @@ -18,6 +18,14 @@ namespace Dcat\Admin { * @property Grid\Column|Collection is_show * @property Grid\Column|Collection created_at * @property Grid\Column|Collection updated_at + * @property Grid\Column|Collection user_id + * @property Grid\Column|Collection consignee + * @property Grid\Column|Collection telephone + * @property Grid\Column|Collection province + * @property Grid\Column|Collection city + * @property Grid\Column|Collection district + * @property Grid\Column|Collection address + * @property Grid\Column|Collection is_default * @property Grid\Column|Collection type * @property Grid\Column|Collection version * @property Grid\Column|Collection detail @@ -33,7 +41,6 @@ namespace Dcat\Admin { * @property Grid\Column|Collection http_method * @property Grid\Column|Collection http_path * @property Grid\Column|Collection role_id - * @property Grid\Column|Collection user_id * @property Grid\Column|Collection value * @property Grid\Column|Collection username * @property Grid\Column|Collection password @@ -64,10 +71,13 @@ namespace Dcat\Admin { * @property Grid\Column|Collection abilities * @property Grid\Column|Collection last_used_at * @property Grid\Column|Collection remarks + * @property Grid\Column|Collection sku_id + * @property Grid\Column|Collection gift_sku_id + * @property Grid\Column|Collection num + * @property Grid\Column|Collection sent * @property Grid\Column|Collection attrs * @property Grid\Column|Collection specs * @property Grid\Column|Collection part_id - * @property Grid\Column|Collection sku_id * @property Grid\Column|Collection spu_id * @property Grid\Column|Collection status * @property Grid\Column|Collection images @@ -111,6 +121,14 @@ namespace Dcat\Admin { * @method Grid\Column|Collection is_show(string $label = null) * @method Grid\Column|Collection created_at(string $label = null) * @method Grid\Column|Collection updated_at(string $label = null) + * @method Grid\Column|Collection user_id(string $label = null) + * @method Grid\Column|Collection consignee(string $label = null) + * @method Grid\Column|Collection telephone(string $label = null) + * @method Grid\Column|Collection province(string $label = null) + * @method Grid\Column|Collection city(string $label = null) + * @method Grid\Column|Collection district(string $label = null) + * @method Grid\Column|Collection address(string $label = null) + * @method Grid\Column|Collection is_default(string $label = null) * @method Grid\Column|Collection type(string $label = null) * @method Grid\Column|Collection version(string $label = null) * @method Grid\Column|Collection detail(string $label = null) @@ -126,7 +144,6 @@ namespace Dcat\Admin { * @method Grid\Column|Collection http_method(string $label = null) * @method Grid\Column|Collection http_path(string $label = null) * @method Grid\Column|Collection role_id(string $label = null) - * @method Grid\Column|Collection user_id(string $label = null) * @method Grid\Column|Collection value(string $label = null) * @method Grid\Column|Collection username(string $label = null) * @method Grid\Column|Collection password(string $label = null) @@ -157,10 +174,13 @@ namespace Dcat\Admin { * @method Grid\Column|Collection abilities(string $label = null) * @method Grid\Column|Collection last_used_at(string $label = null) * @method Grid\Column|Collection remarks(string $label = null) + * @method Grid\Column|Collection sku_id(string $label = null) + * @method Grid\Column|Collection gift_sku_id(string $label = null) + * @method Grid\Column|Collection num(string $label = null) + * @method Grid\Column|Collection sent(string $label = null) * @method Grid\Column|Collection attrs(string $label = null) * @method Grid\Column|Collection specs(string $label = null) * @method Grid\Column|Collection part_id(string $label = null) - * @method Grid\Column|Collection sku_id(string $label = null) * @method Grid\Column|Collection spu_id(string $label = null) * @method Grid\Column|Collection status(string $label = null) * @method Grid\Column|Collection images(string $label = null) @@ -209,6 +229,14 @@ namespace Dcat\Admin { * @property Show\Field|Collection is_show * @property Show\Field|Collection created_at * @property Show\Field|Collection updated_at + * @property Show\Field|Collection user_id + * @property Show\Field|Collection consignee + * @property Show\Field|Collection telephone + * @property Show\Field|Collection province + * @property Show\Field|Collection city + * @property Show\Field|Collection district + * @property Show\Field|Collection address + * @property Show\Field|Collection is_default * @property Show\Field|Collection type * @property Show\Field|Collection version * @property Show\Field|Collection detail @@ -224,7 +252,6 @@ namespace Dcat\Admin { * @property Show\Field|Collection http_method * @property Show\Field|Collection http_path * @property Show\Field|Collection role_id - * @property Show\Field|Collection user_id * @property Show\Field|Collection value * @property Show\Field|Collection username * @property Show\Field|Collection password @@ -255,10 +282,13 @@ namespace Dcat\Admin { * @property Show\Field|Collection abilities * @property Show\Field|Collection last_used_at * @property Show\Field|Collection remarks + * @property Show\Field|Collection sku_id + * @property Show\Field|Collection gift_sku_id + * @property Show\Field|Collection num + * @property Show\Field|Collection sent * @property Show\Field|Collection attrs * @property Show\Field|Collection specs * @property Show\Field|Collection part_id - * @property Show\Field|Collection sku_id * @property Show\Field|Collection spu_id * @property Show\Field|Collection status * @property Show\Field|Collection images @@ -302,6 +332,14 @@ namespace Dcat\Admin { * @method Show\Field|Collection is_show(string $label = null) * @method Show\Field|Collection created_at(string $label = null) * @method Show\Field|Collection updated_at(string $label = null) + * @method Show\Field|Collection user_id(string $label = null) + * @method Show\Field|Collection consignee(string $label = null) + * @method Show\Field|Collection telephone(string $label = null) + * @method Show\Field|Collection province(string $label = null) + * @method Show\Field|Collection city(string $label = null) + * @method Show\Field|Collection district(string $label = null) + * @method Show\Field|Collection address(string $label = null) + * @method Show\Field|Collection is_default(string $label = null) * @method Show\Field|Collection type(string $label = null) * @method Show\Field|Collection version(string $label = null) * @method Show\Field|Collection detail(string $label = null) @@ -317,7 +355,6 @@ namespace Dcat\Admin { * @method Show\Field|Collection http_method(string $label = null) * @method Show\Field|Collection http_path(string $label = null) * @method Show\Field|Collection role_id(string $label = null) - * @method Show\Field|Collection user_id(string $label = null) * @method Show\Field|Collection value(string $label = null) * @method Show\Field|Collection username(string $label = null) * @method Show\Field|Collection password(string $label = null) @@ -348,10 +385,13 @@ namespace Dcat\Admin { * @method Show\Field|Collection abilities(string $label = null) * @method Show\Field|Collection last_used_at(string $label = null) * @method Show\Field|Collection remarks(string $label = null) + * @method Show\Field|Collection sku_id(string $label = null) + * @method Show\Field|Collection gift_sku_id(string $label = null) + * @method Show\Field|Collection num(string $label = null) + * @method Show\Field|Collection sent(string $label = null) * @method Show\Field|Collection attrs(string $label = null) * @method Show\Field|Collection specs(string $label = null) * @method Show\Field|Collection part_id(string $label = null) - * @method Show\Field|Collection sku_id(string $label = null) * @method Show\Field|Collection spu_id(string $label = null) * @method Show\Field|Collection status(string $label = null) * @method Show\Field|Collection images(string $label = null) diff --git a/resources/lang/zh_CN/admin_message.php b/resources/lang/zh_CN/admin_message.php index 69760e50..8c4f6b80 100644 --- a/resources/lang/zh_CN/admin_message.php +++ b/resources/lang/zh_CN/admin_message.php @@ -71,6 +71,7 @@ return [ 'sku_verify'=>'商品审核', 'disable_user'=>'禁用用户', 'enable_user'=>'启用用户', + 'sku_gift'=>'赠品管理', ], ], ]; diff --git a/resources/lang/zh_CN/product-gift.php b/resources/lang/zh_CN/product-gift.php new file mode 100644 index 00000000..4b7683de --- /dev/null +++ b/resources/lang/zh_CN/product-gift.php @@ -0,0 +1,15 @@ + [ + 'ProductGift' => 'ProductGift', + 'product-gift' => 'ProductGift', + ], + 'fields' => [ + 'sku_id' => 'SKU商品', + 'gift_sku_id' => '赠品', + 'num' => '赠送数量', + 'sent' => '已送数量', + ], + 'options' => [ + ], +]; diff --git a/resources/lang/zh_CN/product-sku.php b/resources/lang/zh_CN/product-sku.php index 2ebb9a26..170c9cd7 100644 --- a/resources/lang/zh_CN/product-sku.php +++ b/resources/lang/zh_CN/product-sku.php @@ -34,6 +34,10 @@ return [ 'verify_state'=>'状态', 'release_at' => '上架时间', 'attr_group'=>'商品分组', + 'gifts'=>'赠品', + 'gift_sku_id'=>'赠品名称', + 'num'=>'赠送数量', + 'limit'=>'限量', ], 'options' => [ 'deny' => '删除失败',