diff --git a/04_Laravel/app/Models/DiscountCode.php b/04_Laravel/app/Models/DiscountCode.php new file mode 100644 index 0000000..f4020c6 --- /dev/null +++ b/04_Laravel/app/Models/DiscountCode.php @@ -0,0 +1,18 @@ + 'datetime', + 'is_active' => 'boolean', + ]; +} diff --git a/04_Laravel/app/Models/User.php b/04_Laravel/app/Models/User.php index 8b89792..1abcdf2 100644 --- a/04_Laravel/app/Models/User.php +++ b/04_Laravel/app/Models/User.php @@ -5,6 +5,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use App\Models\Wallet; class User extends Authenticatable { @@ -54,4 +55,10 @@ class User extends Authenticatable { return $this->role === \App\Enums\UserRole::Customer; } + + //کیف پول + public function wallet() + { + return $this->hasOne(Wallet::class); + } } diff --git a/04_Laravel/app/Models/Wallet.php b/04_Laravel/app/Models/Wallet.php new file mode 100644 index 0000000..55e45bc --- /dev/null +++ b/04_Laravel/app/Models/Wallet.php @@ -0,0 +1,24 @@ +belongsTo(User::class); + } + + public function transactions(): HasMany + { + return $this->hasMany(WalletTransaction::class); + } +} diff --git a/04_Laravel/app/Models/WalletTransaction.php b/04_Laravel/app/Models/WalletTransaction.php new file mode 100644 index 0000000..c402b65 --- /dev/null +++ b/04_Laravel/app/Models/WalletTransaction.php @@ -0,0 +1,23 @@ +belongsTo(Wallet::class); + } + + public function transactionable(): MorphTo + { + return $this->morphTo(); + } +} \ No newline at end of file diff --git a/04_Laravel/database/migrations/2026_08_05_135016_create_wallets_table.php b/04_Laravel/database/migrations/2026_08_05_135016_create_wallets_table.php new file mode 100644 index 0000000..82857d8 --- /dev/null +++ b/04_Laravel/database/migrations/2026_08_05_135016_create_wallets_table.php @@ -0,0 +1,30 @@ +id(); + $table->foreignId('user_id')->unique()->constrained()->cascadeOnDelete(); + $table->decimal('balance', 15, 2)->default(0); // موجودی به ریال یا تومان + $table->timestamps(); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('wallets'); + } +}; diff --git a/04_Laravel/database/migrations/2026_08_05_135022_create_wallet_transactions_table.php b/04_Laravel/database/migrations/2026_08_05_135022_create_wallet_transactions_table.php new file mode 100644 index 0000000..713dba1 --- /dev/null +++ b/04_Laravel/database/migrations/2026_08_05_135022_create_wallet_transactions_table.php @@ -0,0 +1,35 @@ +id(); + $table->foreignId('wallet_id')->constrained()->cascadeOnDelete(); + $table->decimal('amount', 15, 2); // مثبت برای واریز، منفی برای برداشت + $table->enum('type', ['deposit', 'withdraw', 'order_payment']); // نوع تراکنش + $table->string('description')->nullable(); + $table->string('transactionable_type'); + $table->unsignedBigInteger('transactionable_id'); + $table->index(['transactionable_type', 'transactionable_id'], 'wallet_txn_morph_index'); + $table->timestamps(); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('wallet_transactions'); + } +}; diff --git a/04_Laravel/database/migrations/2026_08_05_135026_create_discount_codes_table.php b/04_Laravel/database/migrations/2026_08_05_135026_create_discount_codes_table.php new file mode 100644 index 0000000..48ada3c --- /dev/null +++ b/04_Laravel/database/migrations/2026_08_05_135026_create_discount_codes_table.php @@ -0,0 +1,36 @@ +id(); + $table->string('code')->unique(); + $table->enum('type', ['fixed', 'percent']); // مبلغ ثابت یا درصد + $table->decimal('value', 15, 2); + $table->decimal('min_order_amount', 15, 2)->default(0); + $table->integer('usage_limit')->nullable(); + $table->integer('used_count')->default(0); + $table->timestamp('expires_at')->nullable(); + $table->boolean('is_active')->default(true); + $table->timestamps(); + }); + + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('discount_codes'); + } +};