diff --git a/packages/filament-order/resources/views/resources/order-resource/pages/shipping.blade.php b/packages/filament-order/resources/views/resources/order-resource/pages/shipping.blade.php index e2faecaf..0404a488 100644 --- a/packages/filament-order/resources/views/resources/order-resource/pages/shipping.blade.php +++ b/packages/filament-order/resources/views/resources/order-resource/pages/shipping.blade.php @@ -1,17 +1,25 @@ + @if ($this->hasInfolist()) + {{ $this->infolist }} + @endif + @foreach($forms as $form) + + {{ $this->{$form} }} + + + + + + @endforeach - - {{ $this->form }} - - diff --git a/packages/filament-order/src/Clusters/Order/Resources/OrderResource.php b/packages/filament-order/src/Clusters/Order/Resources/OrderResource.php index 02442633..3e5b2d66 100644 --- a/packages/filament-order/src/Clusters/Order/Resources/OrderResource.php +++ b/packages/filament-order/src/Clusters/Order/Resources/OrderResource.php @@ -57,7 +57,7 @@ public static function getModelLabel() : string public static function infolist(Infolist $infoList) : Infolist { $infoList->schema([ - Section::make(fn(Model $record) => $record->id) + Section::make(static fn(Model $record) => $record->id) ->schema([ TextEntry::make('order_status') ->badge() @@ -462,8 +462,12 @@ public static function table(Table $table) : Table Tables\Actions\ViewAction::make(), Tables\Actions\Action::make('shipping') ->url( fn($record)=>static::getUrl('shipping',['record'=>$record->id])) + ->visible(fn($record)=>$record->shipping_status !== ShippingStatusEnum::SHIPPED) , + OrderCluster\Resources\OrderResource\Actions\SellerRemarksAction::make('seller_remarks'), + OrderCluster\Resources\OrderResource\Actions\SellerRemarksAction::make('seller_message'), + ]) ->bulkActions([ Tables\Actions\BulkActionGroup::make([ diff --git a/packages/filament-order/src/Clusters/Order/Resources/OrderResource/Actions/SellerRemarksAction.php b/packages/filament-order/src/Clusters/Order/Resources/OrderResource/Actions/SellerRemarksAction.php new file mode 100644 index 00000000..b1000c97 --- /dev/null +++ b/packages/filament-order/src/Clusters/Order/Resources/OrderResource/Actions/SellerRemarksAction.php @@ -0,0 +1,35 @@ +label('卖家备注'); + $this->color('primary'); + $this->modalWidth('lg'); + $this->modalHeading('卖家备注'); + $this->fillForm(fn($record) : array => [ + + 'remarks' => $record->info->{$this->name} + ]); + $this->form([ + Forms\Components\Textarea::make('remarks') + ]); + + $this->action(function ($data, $record) { + + + dd($this->name, $data, $record); + }); + } + +} diff --git a/packages/filament-order/src/Clusters/Order/Resources/OrderResource/Pages/Shipping.php b/packages/filament-order/src/Clusters/Order/Resources/OrderResource/Pages/Shipping.php index 626653d6..84d3da0a 100644 --- a/packages/filament-order/src/Clusters/Order/Resources/OrderResource/Pages/Shipping.php +++ b/packages/filament-order/src/Clusters/Order/Resources/OrderResource/Pages/Shipping.php @@ -5,6 +5,7 @@ use Filament\Actions\Action; use Filament\Forms; use Filament\Forms\Form; +use Filament\Infolists\Infolist; use Filament\Notifications\Notification; use Filament\Pages\Concerns\InteractsWithFormActions; use Filament\Resources\Pages\Concerns\InteractsWithRecord; @@ -13,25 +14,50 @@ use RedJasmine\FilamentCore\Helpers\ResourcePageHelper; use RedJasmine\FilamentOrder\Clusters\Order\Resources\OrderResource; use RedJasmine\Order\Application\UserCases\Commands\Shipping\OrderDummyShippingCommand; +use RedJasmine\Order\Application\UserCases\Commands\Shipping\OrderLogisticsShippingCommand; use RedJasmine\Support\Exceptions\AbstractException; use Throwable; /** - * @property Form $form + * @property Form $dummy + * @property Form $logistics */ class Shipping extends Page { - protected static string $resource = OrderResource::class; + + use InteractsWithRecord, ResourcePageHelper { InteractsWithRecord::resolveRecord insteadof ResourcePageHelper; } public ?array $data = []; - + protected function getViewData(): array + { + return [ + 'forms'=>$this->getForms() + ]; + } use InteractsWithFormActions; + public function infolist(Infolist $infolist): Infolist + { + return static::getResource()::infolist($infolist); + } + + protected function makeInfolist(): Infolist + { + return parent::makeInfolist() + ->record($this->getRecord()) + ->columns($this->hasInlineLabels() ? 1 : 2) + ->inlineLabel($this->hasInlineLabels()); + } + protected function hasInfolist(): bool + { + return (bool) count($this->getInfolist('infolist')->getComponents()); + } + public function mount(int|string $record) : void { @@ -39,12 +65,16 @@ public function mount(int|string $record) : void $this->record = $this->resolveRecord($record); - $this->form->fill([ + $this->dummy->fill([ 'order_products' => $this->record->products->pluck('id')->toArray(), 'is_finished' => true, ]); + $this->logistics->fill([ + 'is_split'=>false, + + ]); } protected function getFormActions() : array @@ -56,43 +86,14 @@ protected function getFormActions() : array } - public function save() - { - //$data = $this->form->getState(); - dd($this->form->getState()); - - - } - - - public function dummy() - { - $data = $this->form->getState(); - $data['id'] = $this->record->id; - $command = OrderDummyShippingCommand::from($data); - - - try { - app(static::getResource()::getCommandService())->dummyShipping($command); - }catch (AbstractException $abstractException){ - Notification::make()->danger() - ->title($abstractException->getMessage()) - ->send(); - return; - } - Notification::make()->success() - ->title('OK') - ->send(); - $this->redirect(static::getResource()::getUrl('index')); - } protected function getSaveFormAction() : Action { - return Action::make('dummy') + return Action::make('save') ->label('发货') - ->submit('dummy'); + ->submit('save'); } @@ -100,21 +101,26 @@ protected function getSaveFormAction() : Action public function getHeading() : string { - return 'getHeading'; + return $this->getRecord()->id; } - public static function getNavigationLabel() : string - { - return '大号'; - } + public function getTitle() : string|Htmlable { - return '这个啥z'; + return $this->getRecord()->id; } - public function form(Form $form) : Form + protected function getForms() : array + { + return [ + 'dummy', + 'logistics', + ]; + } + + public function dummy(Form $form) : Form { $record = $this->record; return $form->schema([ @@ -128,17 +134,78 @@ public function form(Form $form) : Form ->boolean() ]) - ->statePath('data') + ->statePath('data.dummy') ->columns(1); } + public function dummySubmit() + { + $data = $this->dummy->getState(); + $data['id'] = $this->record->id; + $command = OrderDummyShippingCommand::from($data); + + + try { + app(static::getResource()::getCommandService())->dummyShipping($command); + } catch (AbstractException $abstractException) { + Notification::make()->danger() + ->title($abstractException->getMessage()) + ->send(); + return; + } + Notification::make()->success() + ->title('OK') + ->send(); + + $this->redirect(static::getResource()::getUrl('index')); + + } + + public function logistics(Form $form) : Form + { + + $record = $this->record; + return $form->schema([ + + Forms\Components\ToggleButtons::make('is_split') + ->default(false) + ->grouped() + ->boolean(), + Forms\Components\CheckboxList::make('order_products') + ->options($record->products->pluck('title', 'id')->toArray()), + + Forms\Components\TextInput::make('express_company_code')->required(), + Forms\Components\TextInput::make('express_no')->required(), + + ]) + ->statePath('data.logistics'); + } + public function logisticsSubmit() + { + $data = $this->logistics->getState(); + + $data['id'] = $this->record->id; + $command = OrderLogisticsShippingCommand::from($data); + try { + app(static::getResource()::getCommandService())->logisticsShipping($command); + } catch (AbstractException $abstractException) { + Notification::make()->danger() + ->title($abstractException->getMessage()) + ->send(); + return; + } + Notification::make()->success() + ->title('OK') + ->send(); + + $this->redirect(static::getResource()::getUrl('index')); + + } + protected function getHeaderActions() : array { return [ - Action::make('test')->button(), - Action::make('test')->button(), - Action::make('test')->button(), - Action::make('test')->button(), + ]; diff --git a/packages/order/src/Application/Services/Handlers/Shipping/OrderLogisticsShippingCommandHandler.php b/packages/order/src/Application/Services/Handlers/Shipping/OrderLogisticsShippingCommandHandler.php index 4c10a673..194c0bf4 100644 --- a/packages/order/src/Application/Services/Handlers/Shipping/OrderLogisticsShippingCommandHandler.php +++ b/packages/order/src/Application/Services/Handlers/Shipping/OrderLogisticsShippingCommandHandler.php @@ -32,8 +32,10 @@ public function handle(OrderLogisticsShippingCommand $command) : void $order = $this->find($command->id); $orderLogistics = OrderLogistics::newModel(); $orderLogistics->shippable_id = $order->id; - $orderLogistics->seller = $order->seller; - $orderLogistics->buyer = $order->buyer; + $orderLogistics->seller_type = $order->seller_type; + $orderLogistics->seller_id = $order->seller_id; + $orderLogistics->buyer_type = $order->buyer_type; + $orderLogistics->buyer_id = $order->buyer_id; $orderLogistics->shipper = LogisticsShipperEnum::SELLER; $orderLogistics->order_product_id = $command->orderProducts; $orderLogistics->express_company_code = $command->expressCompanyCode;