feat: improve application access and money precision

This commit is contained in:
hectorzhao
2026-07-16 17:54:05 +08:00
parent 9d5c507007
commit faa716b8d0
49 changed files with 1699 additions and 489 deletions
@@ -0,0 +1,41 @@
-- Monetary values were historically stored as integer cents. The platform now
-- stores integer units of 0.0001 yuan. Convert existing values by 100 while
-- widening columns to bigint so balances and report aggregates do not inherit
-- PostgreSQL integer's ~214,748 yuan ceiling at the new scale.
ALTER TABLE "TenantAccount"
ALTER COLUMN "balanceCents" TYPE BIGINT USING ("balanceCents"::BIGINT * 100),
ALTER COLUMN "creditCents" TYPE BIGINT USING ("creditCents"::BIGINT * 100);
ALTER TABLE "AccountTransaction"
ALTER COLUMN "amountCents" TYPE BIGINT USING ("amountCents"::BIGINT * 100),
ALTER COLUMN "balanceAfter" TYPE BIGINT USING ("balanceAfter"::BIGINT * 100);
ALTER TABLE "BillingRule"
ALTER COLUMN "unitPrice" TYPE BIGINT USING ("unitPrice"::BIGINT * 100);
ALTER TABLE "RechargeOrder"
ALTER COLUMN "amountCents" TYPE BIGINT USING ("amountCents"::BIGINT * 100);
ALTER TABLE "SmsBillingRecord"
ALTER COLUMN "unitPrice" TYPE BIGINT USING ("unitPrice"::BIGINT * 100),
ALTER COLUMN "amountCents" TYPE BIGINT USING ("amountCents"::BIGINT * 100);
ALTER TABLE "SmsApplication"
ALTER COLUMN "customerUnitPrice" TYPE BIGINT USING ("customerUnitPrice"::BIGINT * 100);
ALTER TABLE "SmsChannel"
ALTER COLUMN "unitPrice" TYPE BIGINT USING ("unitPrice"::BIGINT * 100);
ALTER TABLE "SmsMessageRecord"
ALTER COLUMN "unitPrice" TYPE BIGINT USING ("unitPrice"::BIGINT * 100),
ALTER COLUMN "amountCents" TYPE BIGINT USING ("amountCents"::BIGINT * 100);
ALTER TABLE "SmsSubmitRecord"
ALTER COLUMN "costUnitPrice" TYPE BIGINT USING ("costUnitPrice"::BIGINT * 100),
ALTER COLUMN "costAmountCents" TYPE BIGINT USING ("costAmountCents"::BIGINT * 100);
ALTER TABLE "DailyProfitReport"
ALTER COLUMN "revenueCents" TYPE BIGINT USING ("revenueCents"::BIGINT * 100),
ALTER COLUMN "costCents" TYPE BIGINT USING ("costCents"::BIGINT * 100),
ALTER COLUMN "profitCents" TYPE BIGINT USING ("profitCents"::BIGINT * 100);
+17 -17
View File
@@ -269,8 +269,8 @@ model DrainageField {
model TenantAccount {
id String @id @default(cuid())
tenantId String
balanceCents Int @default(0)
creditCents Int @default(0)
balanceCents BigInt @default(0)
creditCents BigInt @default(0)
status String @default("active")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -284,8 +284,8 @@ model AccountTransaction {
id String @id @default(cuid())
tenantId String
transactionType String
amountCents Int @default(0)
balanceAfter Int @default(0)
amountCents BigInt @default(0)
balanceAfter BigInt @default(0)
relatedType String?
relatedId String?
remark String?
@@ -302,7 +302,7 @@ model BillingRule {
code String @unique
name String
chargeBasis String @default("submit_success")
unitPrice Int
unitPrice BigInt
status String @default("active")
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@ -312,7 +312,7 @@ model RechargeOrder {
id String @id @default(cuid())
tenantId String
orderNo String @unique
amountCents Int
amountCents BigInt
status String @default("created")
payMethod String?
paidAt DateTime?
@@ -335,8 +335,8 @@ model SmsBillingRecord {
phoneNumber String?
contentLength Int
billingUnits Int
unitPrice Int
amountCents Int
unitPrice BigInt
amountCents BigInt
billingStatus String @default("estimated")
transactionId String?
createdAt DateTime @default(now())
@@ -367,7 +367,7 @@ model SmsApplication {
cmppMaxConnections Int @default(1)
cmppWindowSize Int @default(16)
dailyLimit Int?
customerUnitPrice Int @default(0)
customerUnitPrice BigInt @default(0)
queuePriority String @default("normal")
maxPhonesPerTask Int @default(1000000)
templateMismatchMode String @default("reject")
@@ -730,7 +730,7 @@ model SmsChannel {
srcId String
cmppVersion String @default("2.0")
rateLimitPerSecond Int @default(100)
unitPrice Int @default(0)
unitPrice BigInt @default(0)
status String @default("active")
config Json?
createdAt DateTime @default(now())
@@ -1317,8 +1317,8 @@ model SmsMessageRecord {
province String?
content String
billingUnits Int @default(1)
unitPrice Int @default(0)
amountCents Int @default(0)
unitPrice BigInt @default(0)
amountCents BigInt @default(0)
queuePriority String @default("normal")
channelId String?
submitId String?
@@ -1389,8 +1389,8 @@ model SmsSubmitRecord {
sequenceId Int?
gatewayMessageId String?
submitStatus String @default("queued")
costUnitPrice Int @default(0)
costAmountCents Int @default(0)
costUnitPrice BigInt @default(0)
costAmountCents BigInt @default(0)
errorCode String?
errorMessage String?
submittedAt DateTime?
@@ -1439,9 +1439,9 @@ model DailyProfitReport {
channelId String?
sentUnits Int @default(0)
successUnits Int @default(0)
revenueCents Int @default(0)
costCents Int @default(0)
profitCents Int @default(0)
revenueCents BigInt @default(0)
costCents BigInt @default(0)
profitCents BigInt @default(0)
profitRateBps Int @default(0)
generatedAt DateTime @default(now())
updatedAt DateTime @updatedAt