- Add Enums: TransactionType, TransactionStatus, PaymentGateway - Migrations: wallets, wallet_transactions, wallet_activity_logs - Models: Wallet, WalletTransaction, WalletActivityLog - Services: WalletService with complete business logic - Controllers: WalletController, PaymentController - Filament Resources: WalletResource, WalletTransactionResource - Artisan Command: ifnex:token for API token generation - Sanctum integration with statefulApi and exception handling - Full API endpoints: balance, transactions, admin-adjust, freeze/unfreeze
150 lines
6.2 KiB
PHP
150 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources;
|
|
|
|
use App\Filament\Resources\WalletTransactionResource\Pages;
|
|
use App\Models\WalletTransaction;
|
|
use App\Enums\TransactionType;
|
|
use App\Enums\TransactionStatus;
|
|
use App\Enums\PaymentGateway;
|
|
use Filament\Forms;
|
|
use Filament\Forms\Form;
|
|
use Filament\Resources\Resource;
|
|
use Filament\Tables;
|
|
use Filament\Tables\Table;
|
|
|
|
class WalletTransactionResource extends Resource
|
|
{
|
|
protected static ?string $model = WalletTransaction::class;
|
|
protected static ?string $navigationIcon = 'heroicon-o-arrows-right-left';
|
|
protected static ?string $navigationLabel = 'تراکنشها';
|
|
protected static ?string $navigationGroup = 'مالی';
|
|
protected static ?int $navigationSort = 3;
|
|
|
|
public static function form(Form $form): Form
|
|
{
|
|
return $form->schema([
|
|
Forms\Components\Section::make('اطلاعات تراکنش')
|
|
->schema([
|
|
Forms\Components\Select::make('wallet_id')
|
|
->relationship('wallet', 'id')
|
|
->searchable()
|
|
->preload()
|
|
->required()
|
|
->label('کیف پول'),
|
|
Forms\Components\TextInput::make('amount')
|
|
->numeric()
|
|
->suffix('ریال')
|
|
->required()
|
|
->label('مبلغ'),
|
|
Forms\Components\Select::make('type')
|
|
->options(TransactionType::class)
|
|
->required()
|
|
->label('نوع'),
|
|
Forms\Components\Select::make('status')
|
|
->options(TransactionStatus::class)
|
|
->required()
|
|
->label('وضعیت'),
|
|
Forms\Components\Select::make('gateway')
|
|
->options(PaymentGateway::class)
|
|
->label('درگاه'),
|
|
Forms\Components\TextInput::make('gateway_reference_id')
|
|
->label('کد پیگیری'),
|
|
Forms\Components\Textarea::make('description')
|
|
->label('توضیحات')
|
|
->maxLength(1000),
|
|
Forms\Components\Textarea::make('admin_notes')
|
|
->label('یادداشت ادمین')
|
|
->maxLength(2000),
|
|
])
|
|
->columns(2),
|
|
]);
|
|
}
|
|
|
|
public static function table(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
Tables\Columns\TextColumn::make('id')
|
|
->label('شناسه')
|
|
->sortable(),
|
|
Tables\Columns\TextColumn::make('wallet.user.name')
|
|
->label('کاربر')
|
|
->searchable(),
|
|
Tables\Columns\TextColumn::make('amount')
|
|
->label('مبلغ')
|
|
->money('IRR', divideBy: 1)
|
|
->color(fn ($record) => $record->amount >= 0 ? 'success' : 'danger')
|
|
->sortable(),
|
|
Tables\Columns\BadgeColumn::make('type')
|
|
->label('نوع')
|
|
->getStateUsing(fn ($record) => $record->type->label())
|
|
->colors([
|
|
'success' => TransactionType::DEPOSIT,
|
|
'danger' => TransactionType::WITHDRAWAL,
|
|
'warning' => TransactionType::ORDER_PAYMENT,
|
|
'info' => TransactionType::REFUND,
|
|
]),
|
|
Tables\Columns\BadgeColumn::make('status')
|
|
->label('وضعیت')
|
|
->getStateUsing(fn ($record) => $record->status->label())
|
|
->colors([
|
|
'success' => TransactionStatus::COMPLETED,
|
|
'warning' => TransactionStatus::PENDING,
|
|
'danger' => TransactionStatus::FAILED,
|
|
'info' => TransactionStatus::REFUNDED,
|
|
]),
|
|
Tables\Columns\BadgeColumn::make('gateway')
|
|
->label('درگاه')
|
|
->getStateUsing(fn ($record) => $record->gateway?->label() ?? '-')
|
|
->colors([
|
|
'primary' => PaymentGateway::ZARINPAL,
|
|
'success' => PaymentGateway::MANUAL,
|
|
'gray' => PaymentGateway::SYSTEM,
|
|
]),
|
|
Tables\Columns\TextColumn::make('gateway_reference_id')
|
|
->label('کد پیگیری')
|
|
->searchable()
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('description')
|
|
->label('توضیحات')
|
|
->limit(50)
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('creator.name')
|
|
->label('ایجادکننده')
|
|
->toggleable(),
|
|
Tables\Columns\TextColumn::make('created_at')
|
|
->dateTime('Y/m/d H:i', 'Asia/Tehran')
|
|
->label('تاریخ')
|
|
->sortable(),
|
|
])
|
|
->defaultSort('created_at', 'desc')
|
|
->filters([
|
|
Tables\Filters\SelectFilter::make('type')
|
|
->options(TransactionType::class)
|
|
->label('نوع تراکنش'),
|
|
Tables\Filters\SelectFilter::make('status')
|
|
->options(TransactionStatus::class)
|
|
->label('وضعیت'),
|
|
Tables\Filters\SelectFilter::make('gateway')
|
|
->options(PaymentGateway::class)
|
|
->label('درگاه'),
|
|
])
|
|
->actions([
|
|
Tables\Actions\ViewAction::make(),
|
|
])
|
|
->bulkActions([
|
|
Tables\Actions\BulkActionGroup::make([
|
|
Tables\Actions\DeleteBulkAction::make(),
|
|
]),
|
|
]);
|
|
}
|
|
|
|
public static function getPages(): array
|
|
{
|
|
return [
|
|
'index' => Pages\ListWalletTransactions::route('/'),
|
|
'view' => Pages\ViewWalletTransaction::route('/{record}'),
|
|
];
|
|
}
|
|
} |