Model层:新增金额分字段定义

- 所有 Model 添加对应的 *Cent int64 字段
- 旧的 float64 字段保留但不输出到 JSON (json:"-")
- 涉及文件:user.go, listing.go, order.go, order_checkout.go, wallet.go, withdrawal.go
- 目标:为后续业务逻辑切换到分存储做准备

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
yml
2026-06-09 13:31:29 +08:00
co-authored by Claude Opus 4.8
parent eaa10d839c
commit b80719d538
6 changed files with 119 additions and 94 deletions
+15 -13
View File
@@ -29,19 +29,21 @@ func (GameAccount) TableName() string {
} }
type RentalListing struct { type RentalListing struct {
ID uint64 `gorm:"primaryKey" json:"id"` ID uint64 `gorm:"primaryKey" json:"id"`
ListingNo string `gorm:"column:listing_no;size:20;not null;uniqueIndex" json:"listing_no"` ListingNo string `gorm:"column:listing_no;size:20;not null;uniqueIndex" json:"listing_no"`
AccountID uint64 `gorm:"not null;index" json:"account_id"` AccountID uint64 `gorm:"not null;index" json:"account_id"`
OwnerID uint64 `gorm:"not null;index" json:"owner_id"` OwnerID uint64 `gorm:"not null;index" json:"owner_id"`
Price float64 `gorm:"type:decimal(12,2);not null;default:0" json:"price"` Price float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
DepositAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"deposit_amount"` PriceCent int64 `gorm:"not null;default:0" json:"-"`
InTransaction bool `gorm:"not null;default:false" json:"in_transaction"` DepositAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
Status string `gorm:"size:32;not null;default:'draft'" json:"status"` DepositAmountCent int64 `gorm:"not null;default:0" json:"-"`
ReviewStatus string `gorm:"size:32;not null;default:'none'" json:"review_status"` InTransaction bool `gorm:"not null;default:false" json:"in_transaction"`
ReviewReason string `gorm:"size:255;not null;default:''" json:"review_reason"` Status string `gorm:"size:32;not null;default:'draft'" json:"status"`
PublishedAt *time.Time `json:"published_at"` ReviewStatus string `gorm:"size:32;not null;default:'none'" json:"review_status"`
CreatedAt time.Time `json:"created_at"` ReviewReason string `gorm:"size:255;not null;default:''" json:"review_reason"`
UpdatedAt time.Time `json:"updated_at"` PublishedAt *time.Time `json:"published_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} }
func (RentalListing) TableName() string { func (RentalListing) TableName() string {
+31 -25
View File
@@ -7,31 +7,37 @@ import (
) )
type RentalOrder struct { type RentalOrder struct {
ID uint64 `gorm:"primaryKey" json:"id"` ID uint64 `gorm:"primaryKey" json:"id"`
OrderNo string `gorm:"size:64;not null;uniqueIndex" json:"order_no"` OrderNo string `gorm:"size:64;not null;uniqueIndex" json:"order_no"`
ListingID uint64 `gorm:"not null;index" json:"listing_id"` ListingID uint64 `gorm:"not null;index" json:"listing_id"`
AccountID uint64 `gorm:"not null;index" json:"account_id"` AccountID uint64 `gorm:"not null;index" json:"account_id"`
OwnerID uint64 `gorm:"not null;index" json:"owner_id"` OwnerID uint64 `gorm:"not null;index" json:"owner_id"`
RenterID uint64 `gorm:"not null;index" json:"renter_id"` RenterID uint64 `gorm:"not null;index" json:"renter_id"`
RentedAt *time.Time `json:"rented_at"` RentedAt *time.Time `json:"rented_at"`
EstimatedDurationHours int `gorm:"not null;default:24" json:"estimated_duration_hours"` EstimatedDurationHours int `gorm:"not null;default:24" json:"estimated_duration_hours"`
RentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"rent_amount"` RentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
OwnerRentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"owner_rent_amount"` RentAmountCent int64 `gorm:"not null;default:0" json:"-"`
DepositAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"deposit_amount"` OwnerRentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
DepositOriginalAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"deposit_original_amount"` OwnerRentAmountCent int64 `gorm:"not null;default:0" json:"-"`
DepositWaivedAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"deposit_waived_amount"` DepositAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
PlatformFee float64 `gorm:"type:decimal(12,2);not null;default:0" json:"platform_fee"` DepositAmountCent int64 `gorm:"not null;default:0" json:"-"`
AccountSnapshot datatypes.JSON `json:"account_snapshot"` DepositOriginalAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
Status string `gorm:"size:32;not null;default:'pending_payment'" json:"status"` DepositOriginalAmountCent int64 `gorm:"not null;default:0" json:"-"`
HandoffStatus string `gorm:"size:32;not null;default:'none'" json:"handoff_status"` DepositWaivedAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
SettlementStatus string `gorm:"size:32;not null;default:'unsettled'" json:"settlement_status"` DepositWaivedAmountCent int64 `gorm:"not null;default:0" json:"-"`
RefundStatus string `gorm:"size:32;not null;default:'none';index" json:"refund_status"` PlatformFee float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
RefundAmountCent int64 `gorm:"not null;default:0" json:"refund_amount_cent"` PlatformFeeCent int64 `gorm:"not null;default:0" json:"-"`
RefundedAt *time.Time `json:"refunded_at"` AccountSnapshot datatypes.JSON `json:"account_snapshot"`
OwnerSettledAt *time.Time `json:"owner_settled_at"` Status string `gorm:"size:32;not null;default:'pending_payment'" json:"status"`
SettledAt *time.Time `json:"settled_at"` HandoffStatus string `gorm:"size:32;not null;default:'none'" json:"handoff_status"`
CreatedAt time.Time `json:"created_at"` SettlementStatus string `gorm:"size:32;not null;default:'unsettled'" json:"settlement_status"`
UpdatedAt time.Time `json:"updated_at"` RefundStatus string `gorm:"size:32;not null;default:'none';index" json:"refund_status"`
RefundAmountCent int64 `gorm:"not null;default:0" json:"refund_amount_cent"`
RefundedAt *time.Time `json:"refunded_at"`
OwnerSettledAt *time.Time `json:"owner_settled_at"`
SettledAt *time.Time `json:"settled_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} }
func (RentalOrder) TableName() string { func (RentalOrder) TableName() string {
+31 -22
View File
@@ -7,28 +7,37 @@ import (
) )
type OrderCheckout struct { type OrderCheckout struct {
ID uint64 `gorm:"primaryKey" json:"id"` ID uint64 `gorm:"primaryKey" json:"id"`
OrderID uint64 `gorm:"not null;index" json:"order_id"` OrderID uint64 `gorm:"not null;index" json:"order_id"`
InitiatedBy uint64 `gorm:"not null" json:"initiated_by"` InitiatedBy uint64 `gorm:"not null" json:"initiated_by"`
Status string `gorm:"size:32;not null;default:'submitted'" json:"status"` Status string `gorm:"size:32;not null;default:'submitted'" json:"status"`
RentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"rent_amount"` RentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
OwnerRentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"owner_rent_amount"` RentAmountCent int64 `gorm:"not null;default:0" json:"-"`
PlatformFee float64 `gorm:"type:decimal(12,2);not null;default:0" json:"platform_fee"` OwnerRentAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
DepositAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"deposit_amount"` OwnerRentAmountCent int64 `gorm:"not null;default:0" json:"-"`
ConsumableAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"consumable_amount"` PlatformFee float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
CoinConsumedM float64 `gorm:"type:decimal(12,2);not null;default:0" json:"coin_consumed_m"` PlatformFeeCent int64 `gorm:"not null;default:0" json:"-"`
OtherAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"other_amount"` DepositAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
DepositDeductAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"deposit_deduct_amount"` DepositAmountCent int64 `gorm:"not null;default:0" json:"-"`
RenterRefundAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"renter_refund_amount"` ConsumableAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
OwnerIncomeAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"owner_income_amount"` ConsumableAmountCent int64 `gorm:"not null;default:0" json:"-"`
Content string `json:"content"` CoinConsumedM float64 `gorm:"type:decimal(12,2);not null;default:0" json:"coin_consumed_m"`
EvidenceURLS datatypes.JSON `gorm:"column:evidence_urls" json:"evidence_urls"` OtherAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
OwnerAdjustmentReason string `json:"owner_adjustment_reason"` OtherAmountCent int64 `gorm:"not null;default:0" json:"-"`
OwnerAdjustedAt *time.Time `json:"owner_adjusted_at"` DepositDeductAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
RenterConfirmedAt *time.Time `json:"renter_confirmed_at"` DepositDeductAmountCent int64 `gorm:"not null;default:0" json:"-"`
RenterRejectedAt *time.Time `json:"renter_rejected_at"` RenterRefundAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
CreatedAt time.Time `json:"created_at"` RenterRefundAmountCent int64 `gorm:"not null;default:0" json:"-"`
UpdatedAt time.Time `json:"updated_at"` OwnerIncomeAmount float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
OwnerIncomeAmountCent int64 `gorm:"not null;default:0" json:"-"`
Content string `json:"content"`
EvidenceURLS datatypes.JSON `gorm:"column:evidence_urls" json:"evidence_urls"`
OwnerAdjustmentReason string `json:"owner_adjustment_reason"`
OwnerAdjustedAt *time.Time `json:"owner_adjusted_at"`
RenterConfirmedAt *time.Time `json:"renter_confirmed_at"`
RenterRejectedAt *time.Time `json:"renter_rejected_at"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} }
func (OrderCheckout) TableName() string { func (OrderCheckout) TableName() string {
+13 -12
View File
@@ -3,18 +3,19 @@ package model
import "time" import "time"
type User struct { type User struct {
ID uint64 `gorm:"primaryKey" json:"id"` ID uint64 `gorm:"primaryKey" json:"id"`
Phone string `gorm:"size:32;not null;uniqueIndex" json:"phone"` Phone string `gorm:"size:32;not null;uniqueIndex" json:"phone"`
Nickname string `gorm:"size:64;not null;default:''" json:"nickname"` Nickname string `gorm:"size:64;not null;default:''" json:"nickname"`
AvatarURL string `gorm:"size:512;not null;default:''" json:"avatar_url"` AvatarURL string `gorm:"size:512;not null;default:''" json:"avatar_url"`
RealnameStatus string `gorm:"size:32;not null;default:'unverified'" json:"realname_status"` RealnameStatus string `gorm:"size:32;not null;default:'unverified'" json:"realname_status"`
RiskStatus string `gorm:"size:32;not null;default:'normal'" json:"risk_status"` RiskStatus string `gorm:"size:32;not null;default:'normal'" json:"risk_status"`
CreditScore int `gorm:"not null;default:100" json:"credit_score"` CreditScore int `gorm:"not null;default:100" json:"credit_score"`
DepositFreeQuota float64 `gorm:"type:decimal(12,2);not null;default:0" json:"deposit_free_quota"` DepositFreeQuota float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
Status string `gorm:"size:32;not null;default:'active'" json:"status"` DepositFreeQuotaCent int64 `gorm:"not null;default:0" json:"-"`
LastLoginAt *time.Time `json:"last_login_at"` Status string `gorm:"size:32;not null;default:'active'" json:"status"`
CreatedAt time.Time `json:"created_at"` LastLoginAt *time.Time `json:"last_login_at"`
UpdatedAt time.Time `json:"updated_at"` CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} }
func (User) TableName() string { func (User) TableName() string {
+23 -19
View File
@@ -3,13 +3,15 @@ package model
import "time" import "time"
type WalletAccount struct { type WalletAccount struct {
ID uint64 `gorm:"primaryKey" json:"id"` ID uint64 `gorm:"primaryKey" json:"id"`
UserID uint64 `gorm:"not null;uniqueIndex" json:"user_id"` UserID uint64 `gorm:"not null;uniqueIndex" json:"user_id"`
AvailableBalance float64 `gorm:"type:decimal(12,2);not null;default:0" json:"available_balance"` AvailableBalance float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
FrozenBalance float64 `gorm:"type:decimal(12,2);not null;default:0" json:"frozen_balance"` AvailableBalanceCent int64 `gorm:"not null;default:0" json:"-"`
Status string `gorm:"size:32;not null;default:'active'" json:"status"` FrozenBalance float64 `gorm:"type:decimal(12,2);not null;default:0" json:"-"`
CreatedAt time.Time `json:"created_at"` FrozenBalanceCent int64 `gorm:"not null;default:0" json:"-"`
UpdatedAt time.Time `json:"updated_at"` Status string `gorm:"size:32;not null;default:'active'" json:"status"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
} }
func (WalletAccount) TableName() string { func (WalletAccount) TableName() string {
@@ -17,18 +19,20 @@ func (WalletAccount) TableName() string {
} }
type WalletLedger struct { type WalletLedger struct {
ID uint64 `gorm:"primaryKey" json:"id"` ID uint64 `gorm:"primaryKey" json:"id"`
LedgerNo string `gorm:"size:64;not null;uniqueIndex" json:"ledger_no"` LedgerNo string `gorm:"size:64;not null;uniqueIndex" json:"ledger_no"`
UserID uint64 `gorm:"not null;index" json:"user_id"` UserID uint64 `gorm:"not null;index" json:"user_id"`
OrderID *uint64 `json:"order_id"` OrderID *uint64 `json:"order_id"`
Direction string `gorm:"size:16;not null" json:"direction"` Direction string `gorm:"size:16;not null" json:"direction"`
Amount float64 `gorm:"type:decimal(12,2);not null" json:"amount"` Amount float64 `gorm:"type:decimal(12,2);not null" json:"-"`
BalanceAfter float64 `gorm:"type:decimal(12,2);not null" json:"balance_after"` AmountCent int64 `gorm:"not null;default:0" json:"-"`
BalanceType string `gorm:"size:32;not null" json:"balance_type"` BalanceAfter float64 `gorm:"type:decimal(12,2);not null" json:"-"`
BizType string `gorm:"size:32;not null" json:"biz_type"` BalanceAfterCent int64 `gorm:"not null;default:0" json:"-"`
BizNo string `gorm:"size:64;not null" json:"biz_no"` BalanceType string `gorm:"size:32;not null" json:"balance_type"`
Remark string `gorm:"size:255;not null;default:''" json:"remark"` BizType string `gorm:"size:32;not null" json:"biz_type"`
CreatedAt time.Time `json:"created_at"` BizNo string `gorm:"size:64;not null" json:"biz_no"`
Remark string `gorm:"size:255;not null;default:''" json:"remark"`
CreatedAt time.Time `json:"created_at"`
} }
func (WalletLedger) TableName() string { func (WalletLedger) TableName() string {
+6 -3
View File
@@ -6,9 +6,12 @@ type WithdrawalRequest struct {
ID uint64 `gorm:"primaryKey" json:"id"` ID uint64 `gorm:"primaryKey" json:"id"`
WithdrawNo string `gorm:"size:64;not null;uniqueIndex" json:"withdraw_no"` WithdrawNo string `gorm:"size:64;not null;uniqueIndex" json:"withdraw_no"`
UserID uint64 `gorm:"not null;index" json:"user_id"` UserID uint64 `gorm:"not null;index" json:"user_id"`
Amount float64 `gorm:"type:decimal(12,2);not null" json:"amount"` Amount float64 `gorm:"type:decimal(12,2);not null" json:"-"`
Fee float64 `gorm:"type:decimal(12,2);not null;default:0.00" json:"fee"` AmountCent int64 `gorm:"not null;default:0" json:"-"`
ActualAmount float64 `gorm:"type:decimal(12,2);not null" json:"actual_amount"` Fee float64 `gorm:"type:decimal(12,2);not null;default:0.00" json:"-"`
FeeCent int64 `gorm:"not null;default:0" json:"-"`
ActualAmount float64 `gorm:"type:decimal(12,2);not null" json:"-"`
ActualAmountCent int64 `gorm:"not null;default:0" json:"-"`
PaymentAccountID *uint64 `json:"payment_account_id"` PaymentAccountID *uint64 `json:"payment_account_id"`
AccountType string `gorm:"size:32;not null" json:"account_type"` AccountType string `gorm:"size:32;not null" json:"account_type"`
AccountName string `gorm:"size:128;not null" json:"account_name"` AccountName string `gorm:"size:128;not null" json:"account_name"`