feat: Magic Wallet Phase 6 + Daya restriction + purchase cycle count
- ActivateClubMembershipCommandHandler: block activation in Magic mode - CheckAndProcessDayaLoansCommandHandler: reject Daya after first cycle - userwallet.proto: add purchase_cycle_count to GetMagicWalletStatusResponse - UserWalletService: query ClubMembershipCycles count for cycle info - EF Migration u21: ClubMembershipCycle table + UserWallet Magic fields
This commit is contained in:
+12
@@ -88,6 +88,18 @@ public class ActivateClubMembershipCommandHandler : IRequestHandler<ActivateClub
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 3.5. بررسی وضعیت کیفپول جادویی — اگر در حالت Magic است، فعالسازی مجاز نیست
|
||||||
|
if (wallet.WalletMode == WalletMode.Magic)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(
|
||||||
|
"User {UserId} cannot activate club while in Magic wallet mode",
|
||||||
|
request.UserId
|
||||||
|
);
|
||||||
|
throw new BadRequestException(
|
||||||
|
"ابتدا باید چرخه کیفپول جادویی تکمیل شود"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 4. پیدا کردن UserOrder با PackageId
|
// 4. پیدا کردن UserOrder با PackageId
|
||||||
var packageOrder = await _context.UserOrders
|
var packageOrder = await _context.UserOrders
|
||||||
.Include(o => o.Transaction)
|
.Include(o => o.Transaction)
|
||||||
|
|||||||
+11
@@ -72,6 +72,17 @@ public class CheckAndProcessDayaLoansCommandHandler : IRequestHandler<CheckAndPr
|
|||||||
|
|
||||||
result.UserId = user.Id;
|
result.UserId = user.Id;
|
||||||
|
|
||||||
|
// 2.5. بررسی محدودیت دایا — پس از اولین دور، فقط IPG مجاز است
|
||||||
|
var hasPreviousCycle = await _context.ClubMembershipCycles
|
||||||
|
.AnyAsync(c => c.UserId == user.Id, cancellationToken);
|
||||||
|
|
||||||
|
if (hasPreviousCycle)
|
||||||
|
{
|
||||||
|
result.Message = "کاربرانی که دور اول را تکمیل کردهاند فقط از طریق درگاه بانکی میتوانند پکیج خریداری کنند";
|
||||||
|
results.Add(result);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// 3. ذخیره/بهروزرسانی DayaLoanContract
|
// 3. ذخیره/بهروزرسانی DayaLoanContract
|
||||||
var contract = await _context.DayaLoanContracts
|
var contract = await _context.DayaLoanContracts
|
||||||
.FirstOrDefaultAsync(d => d.NationalCode == dayaResult.NationalCode, cancellationToken);
|
.FirstOrDefaultAsync(d => d.NationalCode == dayaResult.NationalCode, cancellationToken);
|
||||||
|
|||||||
+4781
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,145 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class u21 : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "MagicActivatedAt",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets",
|
||||||
|
type: "datetime2",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<DateTime>(
|
||||||
|
name: "MagicCompletedAt",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets",
|
||||||
|
type: "datetime2",
|
||||||
|
nullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<long>(
|
||||||
|
name: "MagicTotalCredited",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets",
|
||||||
|
type: "bigint",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0L);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<long>(
|
||||||
|
name: "MagicTotalDeposited",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets",
|
||||||
|
type: "bigint",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0L);
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "WalletMode",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets",
|
||||||
|
type: "int",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ClubMembershipCycles",
|
||||||
|
schema: "CMS",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<long>(type: "bigint", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
UserId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
ClubMembershipId = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
CycleNumber = table.Column<int>(type: "int", nullable: false),
|
||||||
|
PackagePurchasedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
MagicStartedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||||
|
MagicCompletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||||
|
PurchaseMethod = table.Column<int>(type: "int", nullable: false),
|
||||||
|
PackageAmount = table.Column<long>(type: "bigint", nullable: false),
|
||||||
|
IsCurrentCycle = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
|
||||||
|
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||||
|
LastModifiedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
|
||||||
|
IsDeleted = table.Column<bool>(type: "bit", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ClubMembershipCycles", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ClubMembershipCycles_ClubMemberships_ClubMembershipId",
|
||||||
|
column: x => x.ClubMembershipId,
|
||||||
|
principalSchema: "CMS",
|
||||||
|
principalTable: "ClubMemberships",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ClubMembershipCycles_Users_UserId",
|
||||||
|
column: x => x.UserId,
|
||||||
|
principalSchema: "CMS",
|
||||||
|
principalTable: "Users",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Restrict);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ClubMembershipCycle_PackagePurchasedAt",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "ClubMembershipCycles",
|
||||||
|
column: "PackagePurchasedAt");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ClubMembershipCycle_UserId_IsCurrentCycle",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "ClubMembershipCycles",
|
||||||
|
columns: new[] { "UserId", "IsCurrentCycle" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ClubMembershipCycles_ClubMembershipId",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "ClubMembershipCycles",
|
||||||
|
column: "ClubMembershipId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ClubMembershipCycles",
|
||||||
|
schema: "CMS");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "MagicActivatedAt",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "MagicCompletedAt",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "MagicTotalCredited",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "MagicTotalDeposited",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "WalletMode",
|
||||||
|
schema: "CMS",
|
||||||
|
table: "UserWallets");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+107
@@ -439,6 +439,71 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
|||||||
b.ToTable("ClubMemberships", "CMS");
|
b.ToTable("ClubMemberships", "CMS");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Club.ClubMembershipCycle", b =>
|
||||||
|
{
|
||||||
|
b.Property<long>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
|
||||||
|
|
||||||
|
b.Property<long>("ClubMembershipId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<DateTime>("Created")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("CreatedBy")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("CycleNumber")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<bool>("IsCurrentCycle")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bit")
|
||||||
|
.HasDefaultValue(false);
|
||||||
|
|
||||||
|
b.Property<bool>("IsDeleted")
|
||||||
|
.HasColumnType("bit");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("LastModified")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("LastModifiedBy")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("MagicCompletedAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("MagicStartedAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<long>("PackageAmount")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<DateTime>("PackagePurchasedAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PurchaseMethod")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<long>("UserId")
|
||||||
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ClubMembershipId");
|
||||||
|
|
||||||
|
b.HasIndex("PackagePurchasedAt")
|
||||||
|
.HasDatabaseName("IX_ClubMembershipCycle_PackagePurchasedAt");
|
||||||
|
|
||||||
|
b.HasIndex("UserId", "IsCurrentCycle")
|
||||||
|
.HasDatabaseName("IX_ClubMembershipCycle_UserId_IsCurrentCycle");
|
||||||
|
|
||||||
|
b.ToTable("ClubMembershipCycles", "CMS");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Club.UserClubFeature", b =>
|
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Club.UserClubFeature", b =>
|
||||||
{
|
{
|
||||||
b.Property<long>("Id")
|
b.Property<long>("Id")
|
||||||
@@ -3576,12 +3641,33 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
|||||||
b.Property<string>("LastModifiedBy")
|
b.Property<string>("LastModifiedBy")
|
||||||
.HasColumnType("nvarchar(max)");
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("MagicActivatedAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("MagicCompletedAt")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<long>("MagicTotalCredited")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint")
|
||||||
|
.HasDefaultValue(0L);
|
||||||
|
|
||||||
|
b.Property<long>("MagicTotalDeposited")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("bigint")
|
||||||
|
.HasDefaultValue(0L);
|
||||||
|
|
||||||
b.Property<long>("NetworkBalance")
|
b.Property<long>("NetworkBalance")
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
b.Property<long>("UserId")
|
b.Property<long>("UserId")
|
||||||
.HasColumnType("bigint");
|
.HasColumnType("bigint");
|
||||||
|
|
||||||
|
b.Property<int>("WalletMode")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int")
|
||||||
|
.HasDefaultValue(0);
|
||||||
|
|
||||||
b.HasKey("Id");
|
b.HasKey("Id");
|
||||||
|
|
||||||
b.HasIndex("UserId");
|
b.HasIndex("UserId");
|
||||||
@@ -3871,6 +3957,25 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
|||||||
b.Navigation("User");
|
b.Navigation("User");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Club.ClubMembershipCycle", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("CMSMicroservice.Domain.Entities.Club.ClubMembership", "ClubMembership")
|
||||||
|
.WithMany("Cycles")
|
||||||
|
.HasForeignKey("ClubMembershipId")
|
||||||
|
.OnDelete(DeleteBehavior.Restrict)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("CMSMicroservice.Domain.Entities.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Restrict)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("ClubMembership");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Club.UserClubFeature", b =>
|
modelBuilder.Entity("CMSMicroservice.Domain.Entities.Club.UserClubFeature", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("CMSMicroservice.Domain.Entities.Club.ClubFeature", "ClubFeature")
|
b.HasOne("CMSMicroservice.Domain.Entities.Club.ClubFeature", "ClubFeature")
|
||||||
@@ -4496,6 +4601,8 @@ namespace CMSMicroservice.Infrastructure.Persistence.Migrations
|
|||||||
{
|
{
|
||||||
b.Navigation("ClubMembershipHistories");
|
b.Navigation("ClubMembershipHistories");
|
||||||
|
|
||||||
|
b.Navigation("Cycles");
|
||||||
|
|
||||||
b.Navigation("UserClubFeatures");
|
b.Navigation("UserClubFeatures");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -240,4 +240,5 @@ message GetMagicWalletStatusResponse
|
|||||||
int64 magic_remaining_deposit = 5;
|
int64 magic_remaining_deposit = 5;
|
||||||
int64 balance = 6;
|
int64 balance = 6;
|
||||||
google.protobuf.Timestamp magic_activated_at = 7;
|
google.protobuf.Timestamp magic_activated_at = 7;
|
||||||
|
int32 purchase_cycle_count = 8; // تعداد دورهای خرید پکیج (0 = هنوز هیچ دوری تکمیل نشده)
|
||||||
}
|
}
|
||||||
@@ -181,6 +181,9 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
|||||||
if (wallet == null)
|
if (wallet == null)
|
||||||
throw new RpcException(new Status(StatusCode.NotFound, "کیف پول یافت نشد"));
|
throw new RpcException(new Status(StatusCode.NotFound, "کیف پول یافت نشد"));
|
||||||
|
|
||||||
|
var cycleCount = await _context.ClubMembershipCycles
|
||||||
|
.CountAsync(c => c.UserId == userId, context.CancellationToken);
|
||||||
|
|
||||||
var response = new GetMagicWalletStatusResponse
|
var response = new GetMagicWalletStatusResponse
|
||||||
{
|
{
|
||||||
WalletMode = (int)wallet.WalletMode,
|
WalletMode = (int)wallet.WalletMode,
|
||||||
@@ -188,7 +191,8 @@ public class UserWalletService : UserWalletContract.UserWalletContractBase
|
|||||||
MagicTotalCredited = wallet.MagicTotalCredited,
|
MagicTotalCredited = wallet.MagicTotalCredited,
|
||||||
MagicMaxDeposit = SystemConstants.MagicWalletMaxDeposit,
|
MagicMaxDeposit = SystemConstants.MagicWalletMaxDeposit,
|
||||||
MagicRemainingDeposit = Math.Max(0, SystemConstants.MagicWalletMaxDeposit - wallet.MagicTotalDeposited),
|
MagicRemainingDeposit = Math.Max(0, SystemConstants.MagicWalletMaxDeposit - wallet.MagicTotalDeposited),
|
||||||
Balance = wallet.Balance
|
Balance = wallet.Balance,
|
||||||
|
PurchaseCycleCount = cycleCount
|
||||||
};
|
};
|
||||||
|
|
||||||
if (wallet.MagicActivatedAt.HasValue)
|
if (wallet.MagicActivatedAt.HasValue)
|
||||||
|
|||||||
Reference in New Issue
Block a user