Skip to content

Commit

Permalink
产品模块功能优化与新增
Browse files Browse the repository at this point in the history
- 优化产品列表操作,增加上架/下架功能
- 新增产品状态设置逻辑及相应图标
- 调整产品相关资源的字段与过滤器
- 优化产品更新时的时间记录- 增加产品状态变更的国际化支持
  • Loading branch information
liushoukun committed Oct 14, 2024
1 parent a1ca985 commit 5ad8e0f
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 41 deletions.
2 changes: 1 addition & 1 deletion src/Clusters/Product/Resources/ProductGroupResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static function table(Table $table) : Table

])
->filters([
TreeParent::make('tree')->label(__('red-jasmine-product::product-group.fields.parent_id')),
TreeParent::make('parents')->label(__('red-jasmine-product::product-group.fields.parent_id')),
Tables\Filters\SelectFilter::make('status')
->label(__('red-jasmine-product::product-group.fields.status'))
->options(GroupStatusEnum::options()),
Expand Down
123 changes: 83 additions & 40 deletions src/Clusters/Product/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
use Filament\Forms;
use Filament\Forms\Components\Repeater;
use Filament\Forms\Form;
use Filament\Notifications\Notification;
use Filament\Resources\Resource;
use Filament\Support\Facades\FilamentIcon;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Model;
Expand All @@ -27,6 +29,7 @@
use RedJasmine\Product\Application\Product\Services\ProductQueryService;
use RedJasmine\Product\Application\Product\UserCases\Commands\ProductCreateCommand;
use RedJasmine\Product\Application\Product\UserCases\Commands\ProductDeleteCommand;
use RedJasmine\Product\Application\Product\UserCases\Commands\ProductSetStatusCommand;
use RedJasmine\Product\Application\Product\UserCases\Commands\ProductUpdateCommand;
use RedJasmine\Product\Application\Property\Services\PropertyValidateService;
use RedJasmine\Product\Domain\Product\Models\Enums\FreightPayerEnum;
Expand All @@ -44,6 +47,9 @@ class ProductResource extends Resource

use ResourcePageHelper;

/**
* @var class-string<ProductCommandService::class>
*/
protected static ?string $commandService = ProductCommandService::class;
protected static ?string $queryService = ProductQueryService::class;
protected static ?string $createCommand = ProductCreateCommand::class;
Expand Down Expand Up @@ -111,41 +117,6 @@ public static function form(Form $form) : Form
->columns(1);
}

public static function publishFields() : array
{

return [
Forms\Components\ToggleButtons::make('status')
->label(__('red-jasmine-product::product.fields.status'))
->required()
->inline()
->default(ProductStatusEnum::ON_SALE)
->useEnum(ProductStatusEnum::class)
->options(function ($operation, ?Model $record) {
if ($operation == 'edit') {
return $record->status->updatingAllowed();
}
if ($operation == 'create') {
return ProductStatusEnum::creatingAllowed();
}
return ProductStatusEnum::options();

})->live()
,
Forms\Components\DateTimePicker::make('start_sale_time')
->nullable()
->label(__('red-jasmine-product::product.fields.start_sale_time'))
->format('Y-m-d\TH:i:sP')
,

Forms\Components\DateTimePicker::make('end_sale_time')
->nullable()
->label(__('red-jasmine-product::product.fields.end_sale_time'))
->format('Y-m-d\TH:i:sP'),
];

}

public static function basicInfoFields() : array
{
return [
Expand Down Expand Up @@ -353,7 +324,6 @@ protected static function basicProps() : Repeater
->reorderable(false);
}


protected static function customizeProps() : Repeater
{
return Repeater::make('customize_props')
Expand Down Expand Up @@ -432,7 +402,7 @@ protected static function specifications() : array


$oldSku = $get('skus') ?? [];
if($oldSku === null){
if ($oldSku === null) {
$oldSku = [];
}
$service = app(PropertyValidateService::class);
Expand Down Expand Up @@ -856,6 +826,41 @@ public static function otherFields() : array
];
}

public static function publishFields() : array
{

return [
Forms\Components\ToggleButtons::make('status')
->label(__('red-jasmine-product::product.fields.status'))
->required()
->inline()
->default(ProductStatusEnum::ON_SALE)
->useEnum(ProductStatusEnum::class)
->options(function ($operation, ?Model $record) {
if ($operation == 'edit') {
return $record->status->updatingAllowed();
}
if ($operation == 'create') {
return ProductStatusEnum::creatingAllowed();
}
return ProductStatusEnum::options();

})->live()
,
Forms\Components\DateTimePicker::make('start_sale_time')
->nullable()
->label(__('red-jasmine-product::product.fields.start_sale_time'))
->format('Y-m-d\TH:i:sP')
,

Forms\Components\DateTimePicker::make('end_sale_time')
->nullable()
->label(__('red-jasmine-product::product.fields.end_sale_time'))
->format('Y-m-d\TH:i:sP'),
];

}

public static function table(Table $table) : Table
{
return $table
Expand Down Expand Up @@ -981,9 +986,47 @@ public static function table(Table $table) : Table
->deferFilters()
->recordUrl(null)
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\ActionGroup::make(
[
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
Tables\Actions\DeleteAction::make(),
Tables\Actions\Action::make('listing-removal')
->label(function (Model $record) {
return $record->status !== ProductStatusEnum::ON_SALE ?

__('red-jasmine-product::product.actions.listing')
:
__('red-jasmine-product::product.actions.removal');
})
->successNotificationTitle('ok')
->icon(function (Model $record) {
return $record->status === ProductStatusEnum::ON_SALE ?

FilamentIcon::resolve('product.actions.listing') ?? 'heroicon-o-arrow-up-circle'
:
FilamentIcon::resolve('product.actions.removal') ?? 'heroicon-o-arrow-down-circle';

})
->action(function (Model $record, Tables\Actions\Action $action) {

$status = ($record->status === ProductStatusEnum::ON_SALE) ? ProductStatusEnum::OFF_SHELF : ProductStatusEnum::ON_SALE;
$command = ProductSetStatusCommand::from([ 'id' => $record->id, 'status' => $status ]);
$service = app(static::$commandService);
$service->setStatus($command);
$action->success();

}),

]
)->visible(static function (Model $record) : bool {
if (method_exists($record, 'trashed')) {
return !$record->trashed();
}
return true;

}),

Tables\Actions\RestoreAction::make(),
Tables\Actions\ForceDeleteAction::make(),
])
Expand Down

0 comments on commit 5ad8e0f

Please sign in to comment.