Skip to content

Commit

Permalink
优化产品资源页面并添加库存相关功能
Browse files Browse the repository at this point in the history
- 重构产品列表页面的标签系统,增加了更多筛选选项,如"on-sale"、"sold-out"等
- 在产品资源中添加了"库存"相关字段,并显示库存状态
- 修改了产品状态的切换逻辑,从"上架"和"下架"改为"在售"和"停售"
- 优化了产品库存资源的显示和操作
  • Loading branch information
liushoukun committed Oct 15, 2024
1 parent 5ad8e0f commit 9689c5f
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 9 deletions.
17 changes: 14 additions & 3 deletions src/Clusters/Product/Resources/ProductResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,14 @@ public static function basicInfoFields() : array
->required()
->inline()
->boolean()
->default(false)
->default(false),

Forms\Components\Radio::make('is_brand_new')
->label(__('red-jasmine-product::product.fields.is_brand_new'))
->required()
->inline()
->boolean()
->default(false)
,


Expand Down Expand Up @@ -863,16 +870,20 @@ public static function publishFields() : array

public static function table(Table $table) : Table
{

return $table
->deferLoading()
->columns([
...static::ownerTableColumns(),
Tables\Columns\TextColumn::make('id')
->label(__('red-jasmine-product::product.fields.id'))
->sortable(),
...static::ownerTableColumns(),
Tables\Columns\TextColumn::make('title')
->label(__('red-jasmine-product::product.fields.title'))
->copyable()
->searchable(),


Tables\Columns\ImageColumn::make('image')->label(__('red-jasmine-product::product.fields.image')),

Tables\Columns\TextColumn::make('product_type')
Expand Down Expand Up @@ -1010,7 +1021,7 @@ public static function table(Table $table) : Table
})
->action(function (Model $record, Tables\Actions\Action $action) {

$status = ($record->status === ProductStatusEnum::ON_SALE) ? ProductStatusEnum::OFF_SHELF : ProductStatusEnum::ON_SALE;
$status = ($record->status === ProductStatusEnum::ON_SALE) ? ProductStatusEnum::DISCONTINUED : ProductStatusEnum::ON_SALE;
$command = ProductSetStatusCommand::from([ 'id' => $record->id, 'status' => $status ]);
$service = app(static::$commandService);
$service->setStatus($command);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,21 @@ class ListProducts extends ListRecords
public function getTabs() : array
{
return [
'all' => Tab::make()->label(__('red-jasmine-product::product.scopes.all')),
'sale' => Tab::make()->label(__('red-jasmine-product::product.scopes.sale'))->modifyQueryUsing(fn(Builder $query) => $query->sale()),
'off_shelf' => Tab::make()->label(__('red-jasmine-product::product.scopes.off_shelf'))->modifyQueryUsing(fn(Builder $query) => $query->offShelf()),
'draft' => Tab::make()->label(__('red-jasmine-product::product.scopes.draft'))->modifyQueryUsing(fn(Builder $query) => $query->draft()),
'all' => Tab::make()
->label(__('red-jasmine-product::product.scopes.all')),
'on-sale' => Tab::make()
->badge(static::getResource()::getEloquentQuery()->onSale()->count())
->label(__('red-jasmine-product::product.scopes.on-sale'))
->modifyQueryUsing(fn(Builder $query) => $query->onSale()),
'sold-out' => Tab::make()->label(__('red-jasmine-product::product.scopes.sold-out'))
->badge(static::getResource()::getEloquentQuery()->soldOut()->count())
->modifyQueryUsing(fn(Builder $query) => $query->soldOut()),
'warehoused' => Tab::make()->label(__('red-jasmine-product::product.scopes.warehoused'))
->badge(static::getResource()::getEloquentQuery()->warehoused()->count())
->modifyQueryUsing(fn(Builder $query) => $query->warehoused()),
// 'stock-alarming' => Tab::make()->label(__('red-jasmine-product::product.scopes.stock-alarming'))
// ->badge(static::getResource()::getEloquentQuery()->stockAlarming()->count())
// ->modifyQueryUsing(fn(Builder $query) => $query->stockAlarming()),

];
}
Expand Down
2 changes: 0 additions & 2 deletions src/Clusters/Product/Resources/ProductStockResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class ProductStockResource extends Resource
protected static ?int $navigationSort = 1;



public static function getModelLabel() : string
{
return __('red-jasmine-product::product-stock.labels.product-stock');
Expand All @@ -52,7 +51,6 @@ public static function table(Table $table) : Table
{

return $table

->striped()
->columns([
Tables\Columns\TextColumn::make('id')
Expand Down

0 comments on commit 9689c5f

Please sign in to comment.