feat(user): implement OTP login, user creation, and profile management

- Added SendOTP method for simulating OTP sending.
- Implemented LoginWithOTP method for user login/registration via OTP, including user creation if not found.
- Added Me method to retrieve current user information.
- Implemented Update method for updating user profile details.
- Added RealName method for real-name verification.
- Implemented GetNotifications method to fetch user notifications.
- Created user_test.go for comprehensive unit tests covering login, profile retrieval, updates, real-name verification, and notifications.
- Updated database models to use appropriate consts for fields like gender, status, and roles.
This commit is contained in:
2025-12-29 10:55:13 +08:00
parent bc2064639f
commit b78f1e1c84
17 changed files with 497 additions and 120 deletions

View File

@@ -8,6 +8,8 @@ import (
"context"
"time"
"quyun/v2/pkg/consts"
"go.ipao.vip/gen"
"go.ipao.vip/gen/types"
)
@@ -16,24 +18,24 @@ const TableNameOrder = "orders"
// Order mapped from table <orders>
type Order struct {
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
Type string `gorm:"column:type;type:character varying(32);default:content_purchase" json:"type"`
Status string `gorm:"column:status;type:character varying(32);default:created" json:"status"`
Currency string `gorm:"column:currency;type:character varying(16);default:CNY" json:"currency"`
AmountOriginal int64 `gorm:"column:amount_original;type:bigint;not null" json:"amount_original"`
AmountDiscount int64 `gorm:"column:amount_discount;type:bigint;not null" json:"amount_discount"`
AmountPaid int64 `gorm:"column:amount_paid;type:bigint;not null" json:"amount_paid"`
Snapshot types.JSON `gorm:"column:snapshot;type:jsonb;default:{}" json:"snapshot"`
IdempotencyKey string `gorm:"column:idempotency_key;type:character varying(128);not null" json:"idempotency_key"`
PaidAt time.Time `gorm:"column:paid_at;type:timestamp with time zone" json:"paid_at"`
RefundedAt time.Time `gorm:"column:refunded_at;type:timestamp with time zone" json:"refunded_at"`
RefundForced bool `gorm:"column:refund_forced;type:boolean" json:"refund_forced"`
RefundOperatorUserID int64 `gorm:"column:refund_operator_user_id;type:bigint" json:"refund_operator_user_id"`
RefundReason string `gorm:"column:refund_reason;type:character varying(255)" json:"refund_reason"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true" json:"id"`
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null" json:"tenant_id"`
UserID int64 `gorm:"column:user_id;type:bigint;not null" json:"user_id"`
Type consts.OrderType `gorm:"column:type;type:character varying(32);default:content_purchase" json:"type"`
Status consts.OrderStatus `gorm:"column:status;type:character varying(32);default:created" json:"status"`
Currency string `gorm:"column:currency;type:character varying(16);default:CNY" json:"currency"`
AmountOriginal int64 `gorm:"column:amount_original;type:bigint;not null" json:"amount_original"`
AmountDiscount int64 `gorm:"column:amount_discount;type:bigint;not null" json:"amount_discount"`
AmountPaid int64 `gorm:"column:amount_paid;type:bigint;not null" json:"amount_paid"`
Snapshot types.JSON `gorm:"column:snapshot;type:jsonb;default:{}" json:"snapshot"`
IdempotencyKey string `gorm:"column:idempotency_key;type:character varying(128);not null" json:"idempotency_key"`
PaidAt time.Time `gorm:"column:paid_at;type:timestamp with time zone" json:"paid_at"`
RefundedAt time.Time `gorm:"column:refunded_at;type:timestamp with time zone" json:"refunded_at"`
RefundForced bool `gorm:"column:refund_forced;type:boolean" json:"refund_forced"`
RefundOperatorUserID int64 `gorm:"column:refund_operator_user_id;type:bigint" json:"refund_operator_user_id"`
RefundReason string `gorm:"column:refund_reason;type:character varying(255)" json:"refund_reason"`
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;default:now()" json:"created_at"`
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;default:now()" json:"updated_at"`
}
// Quick operations without importing query package