feat: add TenantLedger model and query generation
- Introduced TenantLedger model with fields for managing tenant transactions, including ID, TenantID, UserID, OrderID, transaction Type, Amount, and balance details. - Implemented CRUD operations for TenantLedger with methods for Create, Update, Delete, and Reload. - Generated query methods for TenantLedger to facilitate database interactions, including filtering, pagination, and aggregation functions. - Established relationships with Order model for foreign key references.
This commit is contained in:
@@ -17,15 +17,15 @@ const TableNameContentAccess = "content_access"
|
||||
|
||||
// ContentAccess mapped from table <content_access>
|
||||
type ContentAccess 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"`
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null" json:"content_id"`
|
||||
OrderID int64 `gorm:"column:order_id;type:bigint" json:"order_id"`
|
||||
Status consts.ContentAccessStatus `gorm:"column:status;type:character varying(16);not null;default:active" json:"status"`
|
||||
RevokedAt time.Time `gorm:"column:revoked_at;type:timestamp with time zone" json:"revoked_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增" json:"id"` // 主键ID:自增
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离;与内容、用户归属一致" json:"tenant_id"` // 租户ID:多租户隔离;与内容、用户归属一致
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:权益所属用户;用于访问校验" json:"user_id"` // 用户ID:权益所属用户;用于访问校验
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null;comment:内容ID:权益对应内容;唯一约束 (tenant_id, user_id, content_id)" json:"content_id"` // 内容ID:权益对应内容;唯一约束 (tenant_id, user_id, content_id)
|
||||
OrderID int64 `gorm:"column:order_id;type:bigint;comment:订单ID:产生该权益的订单;可为空(例如后台补发/迁移)" json:"order_id"` // 订单ID:产生该权益的订单;可为空(例如后台补发/迁移)
|
||||
Status consts.ContentAccessStatus `gorm:"column:status;type:character varying(16);not null;default:active;comment:权益状态:active/revoked/expired;revoked 表示立即失效(例如退款/违规)" json:"status"` // 权益状态:active/revoked/expired;revoked 表示立即失效(例如退款/违规)
|
||||
RevokedAt time.Time `gorm:"column:revoked_at;type:timestamp with time zone;comment:撤销时间:当 status=revoked 时写入;用于审计与追责" json:"revoked_at"` // 撤销时间:当 status=revoked 时写入;用于审计与追责
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计" json:"created_at"` // 创建时间:默认 now();用于审计
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();更新 status 时写入" json:"updated_at"` // 更新时间:默认 now();更新 status 时写入
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -44,15 +44,15 @@ type contentAccessQuery struct {
|
||||
contentAccessQueryDo contentAccessQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
ContentID field.Int64
|
||||
OrderID field.Int64
|
||||
Status field.Field
|
||||
RevokedAt field.Time
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
ID field.Int64 // 主键ID:自增
|
||||
TenantID field.Int64 // 租户ID:多租户隔离;与内容、用户归属一致
|
||||
UserID field.Int64 // 用户ID:权益所属用户;用于访问校验
|
||||
ContentID field.Int64 // 内容ID:权益对应内容;唯一约束 (tenant_id, user_id, content_id)
|
||||
OrderID field.Int64 // 订单ID:产生该权益的订单;可为空(例如后台补发/迁移)
|
||||
Status field.Field // 权益状态:active/revoked/expired;revoked 表示立即失效(例如退款/违规)
|
||||
RevokedAt field.Time // 撤销时间:当 status=revoked 时写入;用于审计与追责
|
||||
CreatedAt field.Time // 创建时间:默认 now();用于审计
|
||||
UpdatedAt field.Time // 更新时间:默认 now();更新 status 时写入
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ const TableNameContentAsset = "content_assets"
|
||||
|
||||
// ContentAsset mapped from table <content_assets>
|
||||
type ContentAsset 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"`
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null" json:"content_id"`
|
||||
AssetID int64 `gorm:"column:asset_id;type:bigint;not null" json:"asset_id"`
|
||||
Role consts.ContentAssetRole `gorm:"column:role;type:character varying(32);not null;default:main" json:"role"`
|
||||
Sort int32 `gorm:"column:sort;type:integer;not null" json:"sort"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增" json:"id"` // 主键ID:自增
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离;必须与 content_id、asset_id 所属租户一致" json:"tenant_id"` // 租户ID:多租户隔离;必须与 content_id、asset_id 所属租户一致
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:操作人/绑定人;用于审计(通常为租户管理员或作者)" json:"user_id"` // 用户ID:操作人/绑定人;用于审计(通常为租户管理员或作者)
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null;comment:内容ID:关联 contents.id;用于查询内容下资源列表" json:"content_id"` // 内容ID:关联 contents.id;用于查询内容下资源列表
|
||||
AssetID int64 `gorm:"column:asset_id;type:bigint;not null;comment:资源ID:关联 media_assets.id;用于查询资源归属内容" json:"asset_id"` // 资源ID:关联 media_assets.id;用于查询资源归属内容
|
||||
Role consts.ContentAssetRole `gorm:"column:role;type:character varying(32);not null;default:main;comment:资源角色:main/cover/preview;preview 必须为独立资源以满足禁下载与防绕过" json:"role"` // 资源角色:main/cover/preview;preview 必须为独立资源以满足禁下载与防绕过
|
||||
Sort int32 `gorm:"column:sort;type:integer;not null;comment:排序:同一 role 下的展示顺序,数值越小越靠前" json:"sort"` // 排序:同一 role 下的展示顺序,数值越小越靠前
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计" json:"created_at"` // 创建时间:默认 now();用于审计
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();更新 sort/role 时写入" json:"updated_at"` // 更新时间:默认 now();更新 sort/role 时写入
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -44,15 +44,15 @@ type contentAssetQuery struct {
|
||||
contentAssetQueryDo contentAssetQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
ContentID field.Int64
|
||||
AssetID field.Int64
|
||||
Role field.Field
|
||||
Sort field.Int32
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
ID field.Int64 // 主键ID:自增
|
||||
TenantID field.Int64 // 租户ID:多租户隔离;必须与 content_id、asset_id 所属租户一致
|
||||
UserID field.Int64 // 用户ID:操作人/绑定人;用于审计(通常为租户管理员或作者)
|
||||
ContentID field.Int64 // 内容ID:关联 contents.id;用于查询内容下资源列表
|
||||
AssetID field.Int64 // 资源ID:关联 media_assets.id;用于查询资源归属内容
|
||||
Role field.Field // 资源角色:main/cover/preview;preview 必须为独立资源以满足禁下载与防绕过
|
||||
Sort field.Int32 // 排序:同一 role 下的展示顺序,数值越小越靠前
|
||||
CreatedAt field.Time // 创建时间:默认 now();用于审计
|
||||
UpdatedAt field.Time // 更新时间:默认 now();更新 sort/role 时写入
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@ const TableNameContentPrice = "content_prices"
|
||||
|
||||
// ContentPrice mapped from table <content_prices>
|
||||
type ContentPrice 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"`
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null" json:"content_id"`
|
||||
Currency consts.Currency `gorm:"column:currency;type:character varying(16);not null;default:CNY" json:"currency"`
|
||||
PriceAmount int64 `gorm:"column:price_amount;type:bigint;not null" json:"price_amount"`
|
||||
DiscountType consts.DiscountType `gorm:"column:discount_type;type:character varying(16);not null;default:none" json:"discount_type"`
|
||||
DiscountValue int64 `gorm:"column:discount_value;type:bigint;not null" json:"discount_value"`
|
||||
DiscountStartAt time.Time `gorm:"column:discount_start_at;type:timestamp with time zone" json:"discount_start_at"`
|
||||
DiscountEndAt time.Time `gorm:"column:discount_end_at;type:timestamp with time zone" json:"discount_end_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增" json:"id"` // 主键ID:自增
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离;与内容归属一致" json:"tenant_id"` // 租户ID:多租户隔离;与内容归属一致
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:设置/更新价格的操作人(通常为 tenant_admin);用于审计" json:"user_id"` // 用户ID:设置/更新价格的操作人(通常为 tenant_admin);用于审计
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null;comment:内容ID:唯一约束 (tenant_id, content_id);一个内容在一个租户内仅一份定价" json:"content_id"` // 内容ID:唯一约束 (tenant_id, content_id);一个内容在一个租户内仅一份定价
|
||||
Currency consts.Currency `gorm:"column:currency;type:character varying(16);not null;default:CNY;comment:币种:当前固定 CNY;金额单位为分" json:"currency"` // 币种:当前固定 CNY;金额单位为分
|
||||
PriceAmount int64 `gorm:"column:price_amount;type:bigint;not null;comment:基础价格:分;0 表示免费(可直接访问正片资源)" json:"price_amount"` // 基础价格:分;0 表示免费(可直接访问正片资源)
|
||||
DiscountType consts.DiscountType `gorm:"column:discount_type;type:character varying(16);not null;default:none;comment:折扣类型:none/percent/amount;仅影响下单时成交价,需写入订单快照" json:"discount_type"` // 折扣类型:none/percent/amount;仅影响下单时成交价,需写入订单快照
|
||||
DiscountValue int64 `gorm:"column:discount_value;type:bigint;not null;comment:折扣值:percent=0-100(按业务校验);amount=分;none 时忽略" json:"discount_value"` // 折扣值:percent=0-100(按业务校验);amount=分;none 时忽略
|
||||
DiscountStartAt time.Time `gorm:"column:discount_start_at;type:timestamp with time zone;comment:折扣开始时间:可为空;为空表示立即生效(由业务逻辑解释)" json:"discount_start_at"` // 折扣开始时间:可为空;为空表示立即生效(由业务逻辑解释)
|
||||
DiscountEndAt time.Time `gorm:"column:discount_end_at;type:timestamp with time zone;comment:折扣结束时间:可为空;为空表示长期有效(由业务逻辑解释)" json:"discount_end_at"` // 折扣结束时间:可为空;为空表示长期有效(由业务逻辑解释)
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计" json:"created_at"` // 创建时间:默认 now();用于审计
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();更新价格/折扣时写入" json:"updated_at"` // 更新时间:默认 now();更新价格/折扣时写入
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -47,18 +47,18 @@ type contentPriceQuery struct {
|
||||
contentPriceQueryDo contentPriceQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
ContentID field.Int64
|
||||
Currency field.Field
|
||||
PriceAmount field.Int64
|
||||
DiscountType field.Field
|
||||
DiscountValue field.Int64
|
||||
DiscountStartAt field.Time
|
||||
DiscountEndAt field.Time
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
ID field.Int64 // 主键ID:自增
|
||||
TenantID field.Int64 // 租户ID:多租户隔离;与内容归属一致
|
||||
UserID field.Int64 // 用户ID:设置/更新价格的操作人(通常为 tenant_admin);用于审计
|
||||
ContentID field.Int64 // 内容ID:唯一约束 (tenant_id, content_id);一个内容在一个租户内仅一份定价
|
||||
Currency field.Field // 币种:当前固定 CNY;金额单位为分
|
||||
PriceAmount field.Int64 // 基础价格:分;0 表示免费(可直接访问正片资源)
|
||||
DiscountType field.Field // 折扣类型:none/percent/amount;仅影响下单时成交价,需写入订单快照
|
||||
DiscountValue field.Int64 // 折扣值:percent=0-100(按业务校验);amount=分;none 时忽略
|
||||
DiscountStartAt field.Time // 折扣开始时间:可为空;为空表示立即生效(由业务逻辑解释)
|
||||
DiscountEndAt field.Time // 折扣结束时间:可为空;为空表示长期有效(由业务逻辑解释)
|
||||
CreatedAt field.Time // 创建时间:默认 now();用于审计
|
||||
UpdatedAt field.Time // 更新时间:默认 now();更新价格/折扣时写入
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -18,19 +18,19 @@ const TableNameContent = "contents"
|
||||
|
||||
// Content mapped from table <contents>
|
||||
type Content 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"`
|
||||
Title string `gorm:"column:title;type:character varying(255);not null" json:"title"`
|
||||
Description string `gorm:"column:description;type:text;not null" json:"description"`
|
||||
Status consts.ContentStatus `gorm:"column:status;type:character varying(32);not null;default:draft" json:"status"`
|
||||
Visibility consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);not null;default:tenant_only" json:"visibility"`
|
||||
PreviewSeconds int32 `gorm:"column:preview_seconds;type:integer;not null;default:60" json:"preview_seconds"`
|
||||
PreviewDownloadable bool `gorm:"column:preview_downloadable;type:boolean;not null" json:"preview_downloadable"`
|
||||
PublishedAt time.Time `gorm:"column:published_at;type:timestamp with time zone" json:"published_at"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增;用于内容引用" json:"id"` // 主键ID:自增;用于内容引用
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id" json:"tenant_id"` // 租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:内容创建者/发布者;用于权限与审计(例如私有内容仅作者可见)" json:"user_id"` // 用户ID:内容创建者/发布者;用于权限与审计(例如私有内容仅作者可见)
|
||||
Title string `gorm:"column:title;type:character varying(255);not null;comment:标题:用于列表展示与搜索;建议限制长度(由业务校验)" json:"title"` // 标题:用于列表展示与搜索;建议限制长度(由业务校验)
|
||||
Description string `gorm:"column:description;type:text;not null;comment:描述:用于详情页展示;可为空字符串" json:"description"` // 描述:用于详情页展示;可为空字符串
|
||||
Status consts.ContentStatus `gorm:"column:status;type:character varying(32);not null;default:draft;comment:状态:draft/reviewing/published/unpublished/blocked;published 才对外展示" json:"status"` // 状态:draft/reviewing/published/unpublished/blocked;published 才对外展示
|
||||
Visibility consts.ContentVisibility `gorm:"column:visibility;type:character varying(32);not null;default:tenant_only;comment:可见性:public/tenant_only/private;仅控制详情可见,正片资源仍需按价格/权益校验" json:"visibility"` // 可见性:public/tenant_only/private;仅控制详情可见,正片资源仍需按价格/权益校验
|
||||
PreviewSeconds int32 `gorm:"column:preview_seconds;type:integer;not null;default:60;comment:试看秒数:默认 60;只对 preview 资源生效;必须为正整数" json:"preview_seconds"` // 试看秒数:默认 60;只对 preview 资源生效;必须为正整数
|
||||
PreviewDownloadable bool `gorm:"column:preview_downloadable;type:boolean;not null;comment:试看是否允许下载:默认 false;当前策略固定为不允许下载(仅 streaming)" json:"preview_downloadable"` // 试看是否允许下载:默认 false;当前策略固定为不允许下载(仅 streaming)
|
||||
PublishedAt time.Time `gorm:"column:published_at;type:timestamp with time zone;comment:发布时间:首次发布时写入;用于时间窗与排序" json:"published_at"` // 发布时间:首次发布时写入;用于时间窗与排序
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone;comment:软删除时间:非空表示已删除;对外接口需过滤" json:"deleted_at"` // 软删除时间:非空表示已删除;对外接口需过滤
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计与排序" json:"created_at"` // 创建时间:默认 now();用于审计与排序
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();编辑内容时写入" json:"updated_at"` // 更新时间:默认 now();编辑内容时写入
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -48,19 +48,19 @@ type contentQuery struct {
|
||||
contentQueryDo contentQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
Title field.String
|
||||
Description field.String
|
||||
Status field.Field
|
||||
Visibility field.Field
|
||||
PreviewSeconds field.Int32
|
||||
PreviewDownloadable field.Bool
|
||||
PublishedAt field.Time
|
||||
DeletedAt field.Field
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
ID field.Int64 // 主键ID:自增;用于内容引用
|
||||
TenantID field.Int64 // 租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id
|
||||
UserID field.Int64 // 用户ID:内容创建者/发布者;用于权限与审计(例如私有内容仅作者可见)
|
||||
Title field.String // 标题:用于列表展示与搜索;建议限制长度(由业务校验)
|
||||
Description field.String // 描述:用于详情页展示;可为空字符串
|
||||
Status field.Field // 状态:draft/reviewing/published/unpublished/blocked;published 才对外展示
|
||||
Visibility field.Field // 可见性:public/tenant_only/private;仅控制详情可见,正片资源仍需按价格/权益校验
|
||||
PreviewSeconds field.Int32 // 试看秒数:默认 60;只对 preview 资源生效;必须为正整数
|
||||
PreviewDownloadable field.Bool // 试看是否允许下载:默认 false;当前策略固定为不允许下载(仅 streaming)
|
||||
PublishedAt field.Time // 发布时间:首次发布时写入;用于时间窗与排序
|
||||
DeletedAt field.Field // 软删除时间:非空表示已删除;对外接口需过滤
|
||||
CreatedAt field.Time // 创建时间:默认 now();用于审计与排序
|
||||
UpdatedAt field.Time // 更新时间:默认 now();编辑内容时写入
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
@@ -19,18 +19,18 @@ const TableNameMediaAsset = "media_assets"
|
||||
|
||||
// MediaAsset mapped from table <media_assets>
|
||||
type MediaAsset 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 consts.MediaAssetType `gorm:"column:type;type:character varying(32);not null;default:video" json:"type"`
|
||||
Status consts.MediaAssetStatus `gorm:"column:status;type:character varying(32);not null;default:uploaded" json:"status"`
|
||||
Provider string `gorm:"column:provider;type:character varying(64);not null" json:"provider"`
|
||||
Bucket string `gorm:"column:bucket;type:character varying(128);not null" json:"bucket"`
|
||||
ObjectKey string `gorm:"column:object_key;type:character varying(512);not null" json:"object_key"`
|
||||
Meta types.JSON `gorm:"column:meta;type:jsonb;not null;default:{}" json:"meta"`
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone" json:"deleted_at"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增;仅用于内部关联" json:"id"` // 主键ID:自增;仅用于内部关联
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id" json:"tenant_id"` // 租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:资源上传者;用于审计与权限控制" json:"user_id"` // 用户ID:资源上传者;用于审计与权限控制
|
||||
Type consts.MediaAssetType `gorm:"column:type;type:character varying(32);not null;default:video;comment:资源类型:video/audio/image;决定后续处理流程(转码/缩略图/封面等)" json:"type"` // 资源类型:video/audio/image;决定后续处理流程(转码/缩略图/封面等)
|
||||
Status consts.MediaAssetStatus `gorm:"column:status;type:character varying(32);not null;default:uploaded;comment:处理状态:uploaded/processing/ready/failed/deleted;ready 才可被内容引用对外提供" json:"status"` // 处理状态:uploaded/processing/ready/failed/deleted;ready 才可被内容引用对外提供
|
||||
Provider string `gorm:"column:provider;type:character varying(64);not null;comment:存储提供方:例如 s3/minio/oss;便于多存储扩展" json:"provider"` // 存储提供方:例如 s3/minio/oss;便于多存储扩展
|
||||
Bucket string `gorm:"column:bucket;type:character varying(128);not null;comment:存储桶:对象所在 bucket;与 provider 组合确定存储定位" json:"bucket"` // 存储桶:对象所在 bucket;与 provider 组合确定存储定位
|
||||
ObjectKey string `gorm:"column:object_key;type:character varying(512);not null;comment:对象键:对象在 bucket 内的 key;不得暴露可长期复用的直链(通过签名URL/token下发)" json:"object_key"` // 对象键:对象在 bucket 内的 key;不得暴露可长期复用的直链(通过签名URL/token下发)
|
||||
Meta types.JSON `gorm:"column:meta;type:jsonb;not null;default:{};comment:元数据:JSON;包含 hash、duration、width、height、bitrate、codec 等;用于展示与计费/风控" json:"meta"` // 元数据:JSON;包含 hash、duration、width、height、bitrate、codec 等;用于展示与计费/风控
|
||||
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone;comment:软删除时间:非空表示已删除;对外接口需过滤" json:"deleted_at"` // 软删除时间:非空表示已删除;对外接口需过滤
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计与排序" json:"created_at"` // 创建时间:默认 now();用于审计与排序
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();更新状态/元数据时写入" json:"updated_at"` // 更新时间:默认 now();更新状态/元数据时写入
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -47,18 +47,18 @@ type mediaAssetQuery struct {
|
||||
mediaAssetQueryDo mediaAssetQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
Type field.Field
|
||||
Status field.Field
|
||||
Provider field.String
|
||||
Bucket field.String
|
||||
ObjectKey field.String
|
||||
Meta field.JSONB
|
||||
DeletedAt field.Field
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
ID field.Int64 // 主键ID:自增;仅用于内部关联
|
||||
TenantID field.Int64 // 租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id
|
||||
UserID field.Int64 // 用户ID:资源上传者;用于审计与权限控制
|
||||
Type field.Field // 资源类型:video/audio/image;决定后续处理流程(转码/缩略图/封面等)
|
||||
Status field.Field // 处理状态:uploaded/processing/ready/failed/deleted;ready 才可被内容引用对外提供
|
||||
Provider field.String // 存储提供方:例如 s3/minio/oss;便于多存储扩展
|
||||
Bucket field.String // 存储桶:对象所在 bucket;与 provider 组合确定存储定位
|
||||
ObjectKey field.String // 对象键:对象在 bucket 内的 key;不得暴露可长期复用的直链(通过签名URL/token下发)
|
||||
Meta field.JSONB // 元数据:JSON;包含 hash、duration、width、height、bitrate、codec 等;用于展示与计费/风控
|
||||
DeletedAt field.Field // 软删除时间:非空表示已删除;对外接口需过滤
|
||||
CreatedAt field.Time // 创建时间:默认 now();用于审计与排序
|
||||
UpdatedAt field.Time // 更新时间:默认 now();更新状态/元数据时写入
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
63
backend/database/models/order_items.gen.go
Normal file
63
backend/database/models/order_items.gen.go
Normal file
@@ -0,0 +1,63 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/types"
|
||||
)
|
||||
|
||||
const TableNameOrderItem = "order_items"
|
||||
|
||||
// OrderItem mapped from table <order_items>
|
||||
type OrderItem struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增" json:"id"` // 主键ID:自增
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离关键字段;必须与 orders.tenant_id 一致" json:"tenant_id"` // 租户ID:多租户隔离关键字段;必须与 orders.tenant_id 一致
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:下单用户(buyer);冗余字段用于查询加速与审计" json:"user_id"` // 用户ID:下单用户(buyer);冗余字段用于查询加速与审计
|
||||
OrderID int64 `gorm:"column:order_id;type:bigint;not null;comment:订单ID:关联 orders.id;用于聚合订单明细" json:"order_id"` // 订单ID:关联 orders.id;用于聚合订单明细
|
||||
ContentID int64 `gorm:"column:content_id;type:bigint;not null;comment:内容ID:关联 contents.id;用于生成/撤销 content_access" json:"content_id"` // 内容ID:关联 contents.id;用于生成/撤销 content_access
|
||||
ContentUserID int64 `gorm:"column:content_user_id;type:bigint;not null;comment:内容作者用户ID:用于后续分成/对账扩展;当前可为 0 或写入内容创建者" json:"content_user_id"` // 内容作者用户ID:用于后续分成/对账扩展;当前可为 0 或写入内容创建者
|
||||
AmountPaid int64 `gorm:"column:amount_paid;type:bigint;not null;comment:该行实付金额:分;通常等于订单 amount_paid(单内容场景)" json:"amount_paid"` // 该行实付金额:分;通常等于订单 amount_paid(单内容场景)
|
||||
Snapshot types.JSON `gorm:"column:snapshot;type:jsonb;not null;default:{};comment:内容快照:JSON;建议包含 title/price/discount 等,用于历史展示与审计" json:"snapshot"` // 内容快照:JSON;建议包含 title/price/discount 等,用于历史展示与审计
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now()" json:"created_at"` // 创建时间:默认 now()
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now()" json:"updated_at"` // 更新时间:默认 now()
|
||||
Order *Order `gorm:"foreignKey:OrderID;references:ID" json:"order,omitempty"`
|
||||
Content *Content `gorm:"foreignKey:ContentID;references:ID" json:"content,omitempty"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *OrderItem) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.OrderItem.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *OrderItem) Save(ctx context.Context) error { return Q.OrderItem.WithContext(ctx).Save(m) }
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *OrderItem) Create(ctx context.Context) error { return Q.OrderItem.WithContext(ctx).Create(m) }
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *OrderItem) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.OrderItem.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *OrderItem) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.OrderItem.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *OrderItem) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.OrderItem.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
680
backend/database/models/order_items.query.gen.go
Normal file
680
backend/database/models/order_items.query.gen.go
Normal file
@@ -0,0 +1,680 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newOrderItem(db *gorm.DB, opts ...gen.DOOption) orderItemQuery {
|
||||
_orderItemQuery := orderItemQuery{}
|
||||
|
||||
_orderItemQuery.orderItemQueryDo.UseDB(db, opts...)
|
||||
_orderItemQuery.orderItemQueryDo.UseModel(&OrderItem{})
|
||||
|
||||
tableName := _orderItemQuery.orderItemQueryDo.TableName()
|
||||
_orderItemQuery.ALL = field.NewAsterisk(tableName)
|
||||
_orderItemQuery.ID = field.NewInt64(tableName, "id")
|
||||
_orderItemQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_orderItemQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_orderItemQuery.OrderID = field.NewInt64(tableName, "order_id")
|
||||
_orderItemQuery.ContentID = field.NewInt64(tableName, "content_id")
|
||||
_orderItemQuery.ContentUserID = field.NewInt64(tableName, "content_user_id")
|
||||
_orderItemQuery.AmountPaid = field.NewInt64(tableName, "amount_paid")
|
||||
_orderItemQuery.Snapshot = field.NewJSONB(tableName, "snapshot")
|
||||
_orderItemQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_orderItemQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_orderItemQuery.Order = orderItemQueryBelongsToOrder{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Order", "Order"),
|
||||
}
|
||||
|
||||
_orderItemQuery.Content = orderItemQueryBelongsToContent{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Content", "Content"),
|
||||
}
|
||||
|
||||
_orderItemQuery.fillFieldMap()
|
||||
|
||||
return _orderItemQuery
|
||||
}
|
||||
|
||||
type orderItemQuery struct {
|
||||
orderItemQueryDo orderItemQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID:自增
|
||||
TenantID field.Int64 // 租户ID:多租户隔离关键字段;必须与 orders.tenant_id 一致
|
||||
UserID field.Int64 // 用户ID:下单用户(buyer);冗余字段用于查询加速与审计
|
||||
OrderID field.Int64 // 订单ID:关联 orders.id;用于聚合订单明细
|
||||
ContentID field.Int64 // 内容ID:关联 contents.id;用于生成/撤销 content_access
|
||||
ContentUserID field.Int64 // 内容作者用户ID:用于后续分成/对账扩展;当前可为 0 或写入内容创建者
|
||||
AmountPaid field.Int64 // 该行实付金额:分;通常等于订单 amount_paid(单内容场景)
|
||||
Snapshot field.JSONB // 内容快照:JSON;建议包含 title/price/discount 等,用于历史展示与审计
|
||||
CreatedAt field.Time // 创建时间:默认 now()
|
||||
UpdatedAt field.Time // 更新时间:默认 now()
|
||||
Order orderItemQueryBelongsToOrder
|
||||
|
||||
Content orderItemQueryBelongsToContent
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (o orderItemQuery) Table(newTableName string) *orderItemQuery {
|
||||
o.orderItemQueryDo.UseTable(newTableName)
|
||||
return o.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (o orderItemQuery) As(alias string) *orderItemQuery {
|
||||
o.orderItemQueryDo.DO = *(o.orderItemQueryDo.As(alias).(*gen.DO))
|
||||
return o.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (o *orderItemQuery) updateTableName(table string) *orderItemQuery {
|
||||
o.ALL = field.NewAsterisk(table)
|
||||
o.ID = field.NewInt64(table, "id")
|
||||
o.TenantID = field.NewInt64(table, "tenant_id")
|
||||
o.UserID = field.NewInt64(table, "user_id")
|
||||
o.OrderID = field.NewInt64(table, "order_id")
|
||||
o.ContentID = field.NewInt64(table, "content_id")
|
||||
o.ContentUserID = field.NewInt64(table, "content_user_id")
|
||||
o.AmountPaid = field.NewInt64(table, "amount_paid")
|
||||
o.Snapshot = field.NewJSONB(table, "snapshot")
|
||||
o.CreatedAt = field.NewTime(table, "created_at")
|
||||
o.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
o.fillFieldMap()
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *orderItemQuery) QueryContext(ctx context.Context) (*orderItemQuery, *orderItemQueryDo) {
|
||||
return o, o.orderItemQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (o *orderItemQuery) WithContext(ctx context.Context) *orderItemQueryDo {
|
||||
return o.orderItemQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (o orderItemQuery) TableName() string { return o.orderItemQueryDo.TableName() }
|
||||
|
||||
func (o orderItemQuery) Alias() string { return o.orderItemQueryDo.Alias() }
|
||||
|
||||
func (o orderItemQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return o.orderItemQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (o *orderItemQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := o.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (o *orderItemQuery) fillFieldMap() {
|
||||
o.fieldMap = make(map[string]field.Expr, 12)
|
||||
o.fieldMap["id"] = o.ID
|
||||
o.fieldMap["tenant_id"] = o.TenantID
|
||||
o.fieldMap["user_id"] = o.UserID
|
||||
o.fieldMap["order_id"] = o.OrderID
|
||||
o.fieldMap["content_id"] = o.ContentID
|
||||
o.fieldMap["content_user_id"] = o.ContentUserID
|
||||
o.fieldMap["amount_paid"] = o.AmountPaid
|
||||
o.fieldMap["snapshot"] = o.Snapshot
|
||||
o.fieldMap["created_at"] = o.CreatedAt
|
||||
o.fieldMap["updated_at"] = o.UpdatedAt
|
||||
|
||||
}
|
||||
|
||||
func (o orderItemQuery) clone(db *gorm.DB) orderItemQuery {
|
||||
o.orderItemQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
o.Order.db = db.Session(&gorm.Session{Initialized: true})
|
||||
o.Order.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
o.Content.db = db.Session(&gorm.Session{Initialized: true})
|
||||
o.Content.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return o
|
||||
}
|
||||
|
||||
func (o orderItemQuery) replaceDB(db *gorm.DB) orderItemQuery {
|
||||
o.orderItemQueryDo.ReplaceDB(db)
|
||||
o.Order.db = db.Session(&gorm.Session{})
|
||||
o.Content.db = db.Session(&gorm.Session{})
|
||||
return o
|
||||
}
|
||||
|
||||
type orderItemQueryBelongsToOrder struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrder) Where(conds ...field.Expr) *orderItemQueryBelongsToOrder {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrder) WithContext(ctx context.Context) *orderItemQueryBelongsToOrder {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrder) Session(session *gorm.Session) *orderItemQueryBelongsToOrder {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrder) Model(m *OrderItem) *orderItemQueryBelongsToOrderTx {
|
||||
return &orderItemQueryBelongsToOrderTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrder) Unscoped() *orderItemQueryBelongsToOrder {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type orderItemQueryBelongsToOrderTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a orderItemQueryBelongsToOrderTx) Find() (result *Order, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrderTx) Append(values ...*Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrderTx) Replace(values ...*Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrderTx) Delete(values ...*Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrderTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrderTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToOrderTx) Unscoped() *orderItemQueryBelongsToOrderTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type orderItemQueryBelongsToContent struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContent) Where(conds ...field.Expr) *orderItemQueryBelongsToContent {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContent) WithContext(ctx context.Context) *orderItemQueryBelongsToContent {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContent) Session(session *gorm.Session) *orderItemQueryBelongsToContent {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContent) Model(m *OrderItem) *orderItemQueryBelongsToContentTx {
|
||||
return &orderItemQueryBelongsToContentTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContent) Unscoped() *orderItemQueryBelongsToContent {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type orderItemQueryBelongsToContentTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a orderItemQueryBelongsToContentTx) Find() (result *Content, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContentTx) Append(values ...*Content) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContentTx) Replace(values ...*Content) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContentTx) Delete(values ...*Content) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContentTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContentTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a orderItemQueryBelongsToContentTx) Unscoped() *orderItemQueryBelongsToContentTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type orderItemQueryDo struct{ gen.DO }
|
||||
|
||||
func (o orderItemQueryDo) Debug() *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Debug())
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) WithContext(ctx context.Context) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) ReadDB() *orderItemQueryDo {
|
||||
return o.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) WriteDB() *orderItemQueryDo {
|
||||
return o.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Session(config *gorm.Session) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Session(config))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Clauses(conds ...clause.Expression) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Returning(value interface{}, columns ...string) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Not(conds ...gen.Condition) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Or(conds ...gen.Condition) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Select(conds ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Where(conds ...gen.Condition) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Order(conds ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Distinct(cols ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Omit(cols ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Join(table schema.Tabler, on ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Group(cols ...field.Expr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Having(conds ...gen.Condition) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Limit(limit int) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Offset(offset int) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Unscoped() *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Create(values ...*OrderItem) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return o.DO.Create(values)
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) CreateInBatches(values []*OrderItem, batchSize int) error {
|
||||
return o.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (o orderItemQueryDo) Save(values ...*OrderItem) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return o.DO.Save(values)
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) First() (*OrderItem, error) {
|
||||
if result, err := o.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*OrderItem), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Take() (*OrderItem, error) {
|
||||
if result, err := o.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*OrderItem), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Last() (*OrderItem, error) {
|
||||
if result, err := o.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*OrderItem), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Find() ([]*OrderItem, error) {
|
||||
result, err := o.DO.Find()
|
||||
return result.([]*OrderItem), err
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*OrderItem, err error) {
|
||||
buf := make([]*OrderItem, 0, batchSize)
|
||||
err = o.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) FindInBatches(result *[]*OrderItem, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return o.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Attrs(attrs ...field.AssignExpr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Assign(attrs ...field.AssignExpr) *orderItemQueryDo {
|
||||
return o.withDO(o.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Joins(fields ...field.RelationField) *orderItemQueryDo {
|
||||
for _, _f := range fields {
|
||||
o = *o.withDO(o.DO.Joins(_f))
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Preload(fields ...field.RelationField) *orderItemQueryDo {
|
||||
for _, _f := range fields {
|
||||
o = *o.withDO(o.DO.Preload(_f))
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) FirstOrInit() (*OrderItem, error) {
|
||||
if result, err := o.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*OrderItem), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) FirstOrCreate() (*OrderItem, error) {
|
||||
if result, err := o.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*OrderItem), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) FindByPage(offset int, limit int) (result []*OrderItem, count int64, err error) {
|
||||
result, err = o.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = o.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = o.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = o.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Scan(result interface{}) (err error) {
|
||||
return o.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (o orderItemQueryDo) Delete(models ...*OrderItem) (result gen.ResultInfo, err error) {
|
||||
return o.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (o orderItemQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return o.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (o orderItemQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return o.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (o orderItemQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return o.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (o orderItemQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (o orderItemQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (o orderItemQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (o orderItemQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// PluckMap returns a map[key]value for selected key/value expressions within current scope.
|
||||
func (o orderItemQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := o.Select(key, val)
|
||||
rows, err := do.DO.Rows()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
mm := make(map[interface{}]interface{})
|
||||
for rows.Next() {
|
||||
var k interface{}
|
||||
var v interface{}
|
||||
if err := rows.Scan(&k, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mm[k] = v
|
||||
}
|
||||
return mm, rows.Err()
|
||||
}
|
||||
|
||||
// Exists returns true if any record matches the given conditions.
|
||||
func (o orderItemQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := o.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (o orderItemQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
if err := o.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (o orderItemQueryDo) GetByID(id int64) (*OrderItem, error) {
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (o orderItemQueryDo) GetByIDs(ids ...int64) ([]*OrderItem, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*OrderItem{}, nil
|
||||
}
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (o orderItemQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (o orderItemQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (o *orderItemQueryDo) withDO(do gen.Dao) *orderItemQueryDo {
|
||||
o.DO = *do.(*gen.DO)
|
||||
return o
|
||||
}
|
||||
72
backend/database/models/orders.gen.go
Normal file
72
backend/database/models/orders.gen.go
Normal file
@@ -0,0 +1,72 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/types"
|
||||
)
|
||||
|
||||
const TableNameOrder = "orders"
|
||||
|
||||
// Order mapped from table <orders>
|
||||
type Order struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增;用于关联订单明细、账本流水、权益等" json:"id"` // 主键ID:自增;用于关联订单明细、账本流水、权益等
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id" json:"tenant_id"` // 租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:下单用户(buyer);余额扣款与权益归属以该 user_id 为准" json:"user_id"` // 用户ID:下单用户(buyer);余额扣款与权益归属以该 user_id 为准
|
||||
Type consts.OrderType `gorm:"column:type;type:character varying(32);not null;default:content_purchase;comment:订单类型:content_purchase(购买内容)/topup(充值)等;当前默认 content_purchase" json:"type"` // 订单类型:content_purchase(购买内容)/topup(充值)等;当前默认 content_purchase
|
||||
Status consts.OrderStatus `gorm:"column:status;type:character varying(32);not null;default:created;comment:订单状态:created/paid/refunding/refunded/canceled/failed;状态变更需与账本/权益保持一致" json:"status"` // 订单状态:created/paid/refunding/refunded/canceled/failed;状态变更需与账本/权益保持一致
|
||||
Currency consts.Currency `gorm:"column:currency;type:character varying(16);not null;default:CNY;comment:币种:当前固定 CNY;金额单位为分" json:"currency"` // 币种:当前固定 CNY;金额单位为分
|
||||
AmountOriginal int64 `gorm:"column:amount_original;type:bigint;not null;comment:原价金额:分;未折扣前金额(用于展示与对账)" json:"amount_original"` // 原价金额:分;未折扣前金额(用于展示与对账)
|
||||
AmountDiscount int64 `gorm:"column:amount_discount;type:bigint;not null;comment:优惠金额:分;amount_paid = amount_original - amount_discount(下单时快照)" json:"amount_discount"` // 优惠金额:分;amount_paid = amount_original - amount_discount(下单时快照)
|
||||
AmountPaid int64 `gorm:"column:amount_paid;type:bigint;not null;comment:实付金额:分;从租户内余额扣款的金额(下单时快照)" json:"amount_paid"` // 实付金额:分;从租户内余额扣款的金额(下单时快照)
|
||||
Snapshot types.JSON `gorm:"column:snapshot;type:jsonb;not null;default:{};comment:订单快照:JSON;建议包含 content 标题/定价/折扣、请求来源等,避免改价影响历史展示" json:"snapshot"` // 订单快照:JSON;建议包含 content 标题/定价/折扣、请求来源等,避免改价影响历史展示
|
||||
IdempotencyKey string `gorm:"column:idempotency_key;type:character varying(128);not null;comment:幂等键:同一租户同一用户同一业务请求可用;用于防重复下单/重复扣款(建议由客户端生成)" json:"idempotency_key"` // 幂等键:同一租户同一用户同一业务请求可用;用于防重复下单/重复扣款(建议由客户端生成)
|
||||
PaidAt time.Time `gorm:"column:paid_at;type:timestamp with time zone;comment:支付/扣款完成时间:余额支付在 debit_purchase 成功后写入" json:"paid_at"` // 支付/扣款完成时间:余额支付在 debit_purchase 成功后写入
|
||||
RefundedAt time.Time `gorm:"column:refunded_at;type:timestamp with time zone;comment:退款完成时间:退款落账成功后写入" json:"refunded_at"` // 退款完成时间:退款落账成功后写入
|
||||
RefundForced bool `gorm:"column:refund_forced;type:boolean;not null;comment:是否强制退款:true 表示租户管理侧绕过时间窗执行退款(需审计)" json:"refund_forced"` // 是否强制退款:true 表示租户管理侧绕过时间窗执行退款(需审计)
|
||||
RefundOperatorUserID int64 `gorm:"column:refund_operator_user_id;type:bigint;comment:退款操作人用户ID:租户管理员/系统;用于审计与追责" json:"refund_operator_user_id"` // 退款操作人用户ID:租户管理员/系统;用于审计与追责
|
||||
RefundReason string `gorm:"column:refund_reason;type:character varying(255);not null;comment:退款原因:后台/用户发起退款的原因说明;用于审计" json:"refund_reason"` // 退款原因:后台/用户发起退款的原因说明;用于审计
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计与排序" json:"created_at"` // 创建时间:默认 now();用于审计与排序
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();状态变更/退款写入时更新" json:"updated_at"` // 更新时间:默认 now();状态变更/退款写入时更新
|
||||
Items []*OrderItem `gorm:"foreignKey:OrderID;references:ID" json:"items,omitempty"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *Order) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Order.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *Order) Save(ctx context.Context) error { return Q.Order.WithContext(ctx).Save(m) }
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *Order) Create(ctx context.Context) error { return Q.Order.WithContext(ctx).Create(m) }
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *Order) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Order.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *Order) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.Order.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *Order) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.Order.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
618
backend/database/models/orders.query.gen.go
Normal file
618
backend/database/models/orders.query.gen.go
Normal file
@@ -0,0 +1,618 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newOrder(db *gorm.DB, opts ...gen.DOOption) orderQuery {
|
||||
_orderQuery := orderQuery{}
|
||||
|
||||
_orderQuery.orderQueryDo.UseDB(db, opts...)
|
||||
_orderQuery.orderQueryDo.UseModel(&Order{})
|
||||
|
||||
tableName := _orderQuery.orderQueryDo.TableName()
|
||||
_orderQuery.ALL = field.NewAsterisk(tableName)
|
||||
_orderQuery.ID = field.NewInt64(tableName, "id")
|
||||
_orderQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_orderQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_orderQuery.Type = field.NewField(tableName, "type")
|
||||
_orderQuery.Status = field.NewField(tableName, "status")
|
||||
_orderQuery.Currency = field.NewField(tableName, "currency")
|
||||
_orderQuery.AmountOriginal = field.NewInt64(tableName, "amount_original")
|
||||
_orderQuery.AmountDiscount = field.NewInt64(tableName, "amount_discount")
|
||||
_orderQuery.AmountPaid = field.NewInt64(tableName, "amount_paid")
|
||||
_orderQuery.Snapshot = field.NewJSONB(tableName, "snapshot")
|
||||
_orderQuery.IdempotencyKey = field.NewString(tableName, "idempotency_key")
|
||||
_orderQuery.PaidAt = field.NewTime(tableName, "paid_at")
|
||||
_orderQuery.RefundedAt = field.NewTime(tableName, "refunded_at")
|
||||
_orderQuery.RefundForced = field.NewBool(tableName, "refund_forced")
|
||||
_orderQuery.RefundOperatorUserID = field.NewInt64(tableName, "refund_operator_user_id")
|
||||
_orderQuery.RefundReason = field.NewString(tableName, "refund_reason")
|
||||
_orderQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_orderQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_orderQuery.Items = orderQueryHasManyItems{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Items", "OrderItem"),
|
||||
}
|
||||
|
||||
_orderQuery.fillFieldMap()
|
||||
|
||||
return _orderQuery
|
||||
}
|
||||
|
||||
type orderQuery struct {
|
||||
orderQueryDo orderQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID:自增;用于关联订单明细、账本流水、权益等
|
||||
TenantID field.Int64 // 租户ID:多租户隔离关键字段;所有查询/写入必须限定 tenant_id
|
||||
UserID field.Int64 // 用户ID:下单用户(buyer);余额扣款与权益归属以该 user_id 为准
|
||||
Type field.Field // 订单类型:content_purchase(购买内容)/topup(充值)等;当前默认 content_purchase
|
||||
Status field.Field // 订单状态:created/paid/refunding/refunded/canceled/failed;状态变更需与账本/权益保持一致
|
||||
Currency field.Field // 币种:当前固定 CNY;金额单位为分
|
||||
AmountOriginal field.Int64 // 原价金额:分;未折扣前金额(用于展示与对账)
|
||||
AmountDiscount field.Int64 // 优惠金额:分;amount_paid = amount_original - amount_discount(下单时快照)
|
||||
AmountPaid field.Int64 // 实付金额:分;从租户内余额扣款的金额(下单时快照)
|
||||
Snapshot field.JSONB // 订单快照:JSON;建议包含 content 标题/定价/折扣、请求来源等,避免改价影响历史展示
|
||||
IdempotencyKey field.String // 幂等键:同一租户同一用户同一业务请求可用;用于防重复下单/重复扣款(建议由客户端生成)
|
||||
PaidAt field.Time // 支付/扣款完成时间:余额支付在 debit_purchase 成功后写入
|
||||
RefundedAt field.Time // 退款完成时间:退款落账成功后写入
|
||||
RefundForced field.Bool // 是否强制退款:true 表示租户管理侧绕过时间窗执行退款(需审计)
|
||||
RefundOperatorUserID field.Int64 // 退款操作人用户ID:租户管理员/系统;用于审计与追责
|
||||
RefundReason field.String // 退款原因:后台/用户发起退款的原因说明;用于审计
|
||||
CreatedAt field.Time // 创建时间:默认 now();用于审计与排序
|
||||
UpdatedAt field.Time // 更新时间:默认 now();状态变更/退款写入时更新
|
||||
Items orderQueryHasManyItems
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (o orderQuery) Table(newTableName string) *orderQuery {
|
||||
o.orderQueryDo.UseTable(newTableName)
|
||||
return o.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (o orderQuery) As(alias string) *orderQuery {
|
||||
o.orderQueryDo.DO = *(o.orderQueryDo.As(alias).(*gen.DO))
|
||||
return o.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (o *orderQuery) updateTableName(table string) *orderQuery {
|
||||
o.ALL = field.NewAsterisk(table)
|
||||
o.ID = field.NewInt64(table, "id")
|
||||
o.TenantID = field.NewInt64(table, "tenant_id")
|
||||
o.UserID = field.NewInt64(table, "user_id")
|
||||
o.Type = field.NewField(table, "type")
|
||||
o.Status = field.NewField(table, "status")
|
||||
o.Currency = field.NewField(table, "currency")
|
||||
o.AmountOriginal = field.NewInt64(table, "amount_original")
|
||||
o.AmountDiscount = field.NewInt64(table, "amount_discount")
|
||||
o.AmountPaid = field.NewInt64(table, "amount_paid")
|
||||
o.Snapshot = field.NewJSONB(table, "snapshot")
|
||||
o.IdempotencyKey = field.NewString(table, "idempotency_key")
|
||||
o.PaidAt = field.NewTime(table, "paid_at")
|
||||
o.RefundedAt = field.NewTime(table, "refunded_at")
|
||||
o.RefundForced = field.NewBool(table, "refund_forced")
|
||||
o.RefundOperatorUserID = field.NewInt64(table, "refund_operator_user_id")
|
||||
o.RefundReason = field.NewString(table, "refund_reason")
|
||||
o.CreatedAt = field.NewTime(table, "created_at")
|
||||
o.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
o.fillFieldMap()
|
||||
|
||||
return o
|
||||
}
|
||||
|
||||
func (o *orderQuery) QueryContext(ctx context.Context) (*orderQuery, *orderQueryDo) {
|
||||
return o, o.orderQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (o *orderQuery) WithContext(ctx context.Context) *orderQueryDo {
|
||||
return o.orderQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (o orderQuery) TableName() string { return o.orderQueryDo.TableName() }
|
||||
|
||||
func (o orderQuery) Alias() string { return o.orderQueryDo.Alias() }
|
||||
|
||||
func (o orderQuery) Columns(cols ...field.Expr) gen.Columns { return o.orderQueryDo.Columns(cols...) }
|
||||
|
||||
func (o *orderQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := o.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (o *orderQuery) fillFieldMap() {
|
||||
o.fieldMap = make(map[string]field.Expr, 19)
|
||||
o.fieldMap["id"] = o.ID
|
||||
o.fieldMap["tenant_id"] = o.TenantID
|
||||
o.fieldMap["user_id"] = o.UserID
|
||||
o.fieldMap["type"] = o.Type
|
||||
o.fieldMap["status"] = o.Status
|
||||
o.fieldMap["currency"] = o.Currency
|
||||
o.fieldMap["amount_original"] = o.AmountOriginal
|
||||
o.fieldMap["amount_discount"] = o.AmountDiscount
|
||||
o.fieldMap["amount_paid"] = o.AmountPaid
|
||||
o.fieldMap["snapshot"] = o.Snapshot
|
||||
o.fieldMap["idempotency_key"] = o.IdempotencyKey
|
||||
o.fieldMap["paid_at"] = o.PaidAt
|
||||
o.fieldMap["refunded_at"] = o.RefundedAt
|
||||
o.fieldMap["refund_forced"] = o.RefundForced
|
||||
o.fieldMap["refund_operator_user_id"] = o.RefundOperatorUserID
|
||||
o.fieldMap["refund_reason"] = o.RefundReason
|
||||
o.fieldMap["created_at"] = o.CreatedAt
|
||||
o.fieldMap["updated_at"] = o.UpdatedAt
|
||||
|
||||
}
|
||||
|
||||
func (o orderQuery) clone(db *gorm.DB) orderQuery {
|
||||
o.orderQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
o.Items.db = db.Session(&gorm.Session{Initialized: true})
|
||||
o.Items.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return o
|
||||
}
|
||||
|
||||
func (o orderQuery) replaceDB(db *gorm.DB) orderQuery {
|
||||
o.orderQueryDo.ReplaceDB(db)
|
||||
o.Items.db = db.Session(&gorm.Session{})
|
||||
return o
|
||||
}
|
||||
|
||||
type orderQueryHasManyItems struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItems) Where(conds ...field.Expr) *orderQueryHasManyItems {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItems) WithContext(ctx context.Context) *orderQueryHasManyItems {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItems) Session(session *gorm.Session) *orderQueryHasManyItems {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItems) Model(m *Order) *orderQueryHasManyItemsTx {
|
||||
return &orderQueryHasManyItemsTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItems) Unscoped() *orderQueryHasManyItems {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type orderQueryHasManyItemsTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a orderQueryHasManyItemsTx) Find() (result []*OrderItem, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItemsTx) Append(values ...*OrderItem) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItemsTx) Replace(values ...*OrderItem) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItemsTx) Delete(values ...*OrderItem) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItemsTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItemsTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a orderQueryHasManyItemsTx) Unscoped() *orderQueryHasManyItemsTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type orderQueryDo struct{ gen.DO }
|
||||
|
||||
func (o orderQueryDo) Debug() *orderQueryDo {
|
||||
return o.withDO(o.DO.Debug())
|
||||
}
|
||||
|
||||
func (o orderQueryDo) WithContext(ctx context.Context) *orderQueryDo {
|
||||
return o.withDO(o.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) ReadDB() *orderQueryDo {
|
||||
return o.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (o orderQueryDo) WriteDB() *orderQueryDo {
|
||||
return o.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Session(config *gorm.Session) *orderQueryDo {
|
||||
return o.withDO(o.DO.Session(config))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Clauses(conds ...clause.Expression) *orderQueryDo {
|
||||
return o.withDO(o.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Returning(value interface{}, columns ...string) *orderQueryDo {
|
||||
return o.withDO(o.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Not(conds ...gen.Condition) *orderQueryDo {
|
||||
return o.withDO(o.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Or(conds ...gen.Condition) *orderQueryDo {
|
||||
return o.withDO(o.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Select(conds ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Where(conds ...gen.Condition) *orderQueryDo {
|
||||
return o.withDO(o.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Order(conds ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Distinct(cols ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Omit(cols ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Join(table schema.Tabler, on ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Group(cols ...field.Expr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Having(conds ...gen.Condition) *orderQueryDo {
|
||||
return o.withDO(o.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Limit(limit int) *orderQueryDo {
|
||||
return o.withDO(o.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Offset(offset int) *orderQueryDo {
|
||||
return o.withDO(o.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *orderQueryDo {
|
||||
return o.withDO(o.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Unscoped() *orderQueryDo {
|
||||
return o.withDO(o.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Create(values ...*Order) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return o.DO.Create(values)
|
||||
}
|
||||
|
||||
func (o orderQueryDo) CreateInBatches(values []*Order, batchSize int) error {
|
||||
return o.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (o orderQueryDo) Save(values ...*Order) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return o.DO.Save(values)
|
||||
}
|
||||
|
||||
func (o orderQueryDo) First() (*Order, error) {
|
||||
if result, err := o.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Order), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Take() (*Order, error) {
|
||||
if result, err := o.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Order), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Last() (*Order, error) {
|
||||
if result, err := o.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Order), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Find() ([]*Order, error) {
|
||||
result, err := o.DO.Find()
|
||||
return result.([]*Order), err
|
||||
}
|
||||
|
||||
func (o orderQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*Order, err error) {
|
||||
buf := make([]*Order, 0, batchSize)
|
||||
err = o.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (o orderQueryDo) FindInBatches(result *[]*Order, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return o.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Attrs(attrs ...field.AssignExpr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Assign(attrs ...field.AssignExpr) *orderQueryDo {
|
||||
return o.withDO(o.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Joins(fields ...field.RelationField) *orderQueryDo {
|
||||
for _, _f := range fields {
|
||||
o = *o.withDO(o.DO.Joins(_f))
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Preload(fields ...field.RelationField) *orderQueryDo {
|
||||
for _, _f := range fields {
|
||||
o = *o.withDO(o.DO.Preload(_f))
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
func (o orderQueryDo) FirstOrInit() (*Order, error) {
|
||||
if result, err := o.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Order), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderQueryDo) FirstOrCreate() (*Order, error) {
|
||||
if result, err := o.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*Order), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (o orderQueryDo) FindByPage(offset int, limit int) (result []*Order, count int64, err error) {
|
||||
result, err = o.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = o.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (o orderQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = o.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = o.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Scan(result interface{}) (err error) {
|
||||
return o.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (o orderQueryDo) Delete(models ...*Order) (result gen.ResultInfo, err error) {
|
||||
return o.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (o orderQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return o.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (o orderQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return o.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (o orderQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return o.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (o orderQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (o orderQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (o orderQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (o orderQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := o.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// PluckMap returns a map[key]value for selected key/value expressions within current scope.
|
||||
func (o orderQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := o.Select(key, val)
|
||||
rows, err := do.DO.Rows()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
mm := make(map[interface{}]interface{})
|
||||
for rows.Next() {
|
||||
var k interface{}
|
||||
var v interface{}
|
||||
if err := rows.Scan(&k, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mm[k] = v
|
||||
}
|
||||
return mm, rows.Err()
|
||||
}
|
||||
|
||||
// Exists returns true if any record matches the given conditions.
|
||||
func (o orderQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := o.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (o orderQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
if err := o.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (o orderQueryDo) GetByID(id int64) (*Order, error) {
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (o orderQueryDo) GetByIDs(ids ...int64) ([]*Order, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*Order{}, nil
|
||||
}
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (o orderQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (o orderQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(o.TableName(), "id")
|
||||
return o.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (o *orderQueryDo) withDO(do gen.Dao) *orderQueryDo {
|
||||
o.DO = *do.(*gen.DO)
|
||||
return o
|
||||
}
|
||||
@@ -22,7 +22,10 @@ var (
|
||||
ContentAssetQuery *contentAssetQuery
|
||||
ContentPriceQuery *contentPriceQuery
|
||||
MediaAssetQuery *mediaAssetQuery
|
||||
OrderQuery *orderQuery
|
||||
OrderItemQuery *orderItemQuery
|
||||
TenantQuery *tenantQuery
|
||||
TenantLedgerQuery *tenantLedgerQuery
|
||||
TenantUserQuery *tenantUserQuery
|
||||
UserQuery *userQuery
|
||||
)
|
||||
@@ -34,7 +37,10 @@ func SetDefault(db *gorm.DB, opts ...gen.DOOption) {
|
||||
ContentAssetQuery = &Q.ContentAsset
|
||||
ContentPriceQuery = &Q.ContentPrice
|
||||
MediaAssetQuery = &Q.MediaAsset
|
||||
OrderQuery = &Q.Order
|
||||
OrderItemQuery = &Q.OrderItem
|
||||
TenantQuery = &Q.Tenant
|
||||
TenantLedgerQuery = &Q.TenantLedger
|
||||
TenantUserQuery = &Q.TenantUser
|
||||
UserQuery = &Q.User
|
||||
}
|
||||
@@ -47,7 +53,10 @@ func Use(db *gorm.DB, opts ...gen.DOOption) *Query {
|
||||
ContentAsset: newContentAsset(db, opts...),
|
||||
ContentPrice: newContentPrice(db, opts...),
|
||||
MediaAsset: newMediaAsset(db, opts...),
|
||||
Order: newOrder(db, opts...),
|
||||
OrderItem: newOrderItem(db, opts...),
|
||||
Tenant: newTenant(db, opts...),
|
||||
TenantLedger: newTenantLedger(db, opts...),
|
||||
TenantUser: newTenantUser(db, opts...),
|
||||
User: newUser(db, opts...),
|
||||
}
|
||||
@@ -61,7 +70,10 @@ type Query struct {
|
||||
ContentAsset contentAssetQuery
|
||||
ContentPrice contentPriceQuery
|
||||
MediaAsset mediaAssetQuery
|
||||
Order orderQuery
|
||||
OrderItem orderItemQuery
|
||||
Tenant tenantQuery
|
||||
TenantLedger tenantLedgerQuery
|
||||
TenantUser tenantUserQuery
|
||||
User userQuery
|
||||
}
|
||||
@@ -76,7 +88,10 @@ func (q *Query) clone(db *gorm.DB) *Query {
|
||||
ContentAsset: q.ContentAsset.clone(db),
|
||||
ContentPrice: q.ContentPrice.clone(db),
|
||||
MediaAsset: q.MediaAsset.clone(db),
|
||||
Order: q.Order.clone(db),
|
||||
OrderItem: q.OrderItem.clone(db),
|
||||
Tenant: q.Tenant.clone(db),
|
||||
TenantLedger: q.TenantLedger.clone(db),
|
||||
TenantUser: q.TenantUser.clone(db),
|
||||
User: q.User.clone(db),
|
||||
}
|
||||
@@ -98,7 +113,10 @@ func (q *Query) ReplaceDB(db *gorm.DB) *Query {
|
||||
ContentAsset: q.ContentAsset.replaceDB(db),
|
||||
ContentPrice: q.ContentPrice.replaceDB(db),
|
||||
MediaAsset: q.MediaAsset.replaceDB(db),
|
||||
Order: q.Order.replaceDB(db),
|
||||
OrderItem: q.OrderItem.replaceDB(db),
|
||||
Tenant: q.Tenant.replaceDB(db),
|
||||
TenantLedger: q.TenantLedger.replaceDB(db),
|
||||
TenantUser: q.TenantUser.replaceDB(db),
|
||||
User: q.User.replaceDB(db),
|
||||
}
|
||||
@@ -110,7 +128,10 @@ type queryCtx struct {
|
||||
ContentAsset *contentAssetQueryDo
|
||||
ContentPrice *contentPriceQueryDo
|
||||
MediaAsset *mediaAssetQueryDo
|
||||
Order *orderQueryDo
|
||||
OrderItem *orderItemQueryDo
|
||||
Tenant *tenantQueryDo
|
||||
TenantLedger *tenantLedgerQueryDo
|
||||
TenantUser *tenantUserQueryDo
|
||||
User *userQueryDo
|
||||
}
|
||||
@@ -122,7 +143,10 @@ func (q *Query) WithContext(ctx context.Context) *queryCtx {
|
||||
ContentAsset: q.ContentAsset.WithContext(ctx),
|
||||
ContentPrice: q.ContentPrice.WithContext(ctx),
|
||||
MediaAsset: q.MediaAsset.WithContext(ctx),
|
||||
Order: q.Order.WithContext(ctx),
|
||||
OrderItem: q.OrderItem.WithContext(ctx),
|
||||
Tenant: q.Tenant.WithContext(ctx),
|
||||
TenantLedger: q.TenantLedger.WithContext(ctx),
|
||||
TenantUser: q.TenantUser.WithContext(ctx),
|
||||
User: q.User.WithContext(ctx),
|
||||
}
|
||||
|
||||
71
backend/database/models/tenant_ledgers.gen.go
Normal file
71
backend/database/models/tenant_ledgers.gen.go
Normal file
@@ -0,0 +1,71 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
)
|
||||
|
||||
const TableNameTenantLedger = "tenant_ledgers"
|
||||
|
||||
// TenantLedger mapped from table <tenant_ledgers>
|
||||
type TenantLedger struct {
|
||||
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID:自增" json:"id"` // 主键ID:自增
|
||||
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID:多租户隔离关键字段;必须与 tenant_users.tenant_id 一致" json:"tenant_id"` // 租户ID:多租户隔离关键字段;必须与 tenant_users.tenant_id 一致
|
||||
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID:余额账户归属用户;对应 tenant_users.user_id" json:"user_id"` // 用户ID:余额账户归属用户;对应 tenant_users.user_id
|
||||
OrderID int64 `gorm:"column:order_id;type:bigint;comment:关联订单ID:购买/退款类流水应关联 orders.id;非订单类可为空" json:"order_id"` // 关联订单ID:购买/退款类流水应关联 orders.id;非订单类可为空
|
||||
Type consts.TenantLedgerType `gorm:"column:type;type:character varying(32);not null;comment:流水类型:credit_topup/debit_purchase/credit_refund/freeze/unfreeze/adjustment;不同类型决定余额/冻结余额的变更方向" json:"type"` // 流水类型:credit_topup/debit_purchase/credit_refund/freeze/unfreeze/adjustment;不同类型决定余额/冻结余额的变更方向
|
||||
Amount int64 `gorm:"column:amount;type:bigint;not null;comment:流水金额:分/最小货币单位;通常为正数,方向由 type 决定(由业务层约束)" json:"amount"` // 流水金额:分/最小货币单位;通常为正数,方向由 type 决定(由业务层约束)
|
||||
BalanceBefore int64 `gorm:"column:balance_before;type:bigint;not null;comment:变更前可用余额:用于审计与对账回放" json:"balance_before"` // 变更前可用余额:用于审计与对账回放
|
||||
BalanceAfter int64 `gorm:"column:balance_after;type:bigint;not null;comment:变更后可用余额:用于审计与对账回放" json:"balance_after"` // 变更后可用余额:用于审计与对账回放
|
||||
FrozenBefore int64 `gorm:"column:frozen_before;type:bigint;not null;comment:变更前冻结余额:用于审计与对账回放" json:"frozen_before"` // 变更前冻结余额:用于审计与对账回放
|
||||
FrozenAfter int64 `gorm:"column:frozen_after;type:bigint;not null;comment:变更后冻结余额:用于审计与对账回放" json:"frozen_after"` // 变更后冻结余额:用于审计与对账回放
|
||||
IdempotencyKey string `gorm:"column:idempotency_key;type:character varying(128);not null;comment:幂等键:同一租户同一用户同一业务操作固定;用于防止重复落账(建议由业务层生成)" json:"idempotency_key"` // 幂等键:同一租户同一用户同一业务操作固定;用于防止重复落账(建议由业务层生成)
|
||||
Remark string `gorm:"column:remark;type:character varying(255);not null;comment:备注:业务说明/后台操作原因等;用于审计" json:"remark"` // 备注:业务说明/后台操作原因等;用于审计
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now()" json:"created_at"` // 创建时间:默认 now()
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now()" json:"updated_at"` // 更新时间:默认 now()
|
||||
Order *Order `gorm:"foreignKey:OrderID;references:ID" json:"order,omitempty"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
// Update applies changed fields to the database using the default DB.
|
||||
func (m *TenantLedger) Update(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.TenantLedger.WithContext(ctx).Updates(m)
|
||||
}
|
||||
|
||||
// Save upserts the model using the default DB.
|
||||
func (m *TenantLedger) Save(ctx context.Context) error {
|
||||
return Q.TenantLedger.WithContext(ctx).Save(m)
|
||||
}
|
||||
|
||||
// Create inserts the model using the default DB.
|
||||
func (m *TenantLedger) Create(ctx context.Context) error {
|
||||
return Q.TenantLedger.WithContext(ctx).Create(m)
|
||||
}
|
||||
|
||||
// Delete removes the row represented by the model using the default DB.
|
||||
func (m *TenantLedger) Delete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.TenantLedger.WithContext(ctx).Delete(m)
|
||||
}
|
||||
|
||||
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
|
||||
func (m *TenantLedger) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
|
||||
return Q.TenantLedger.WithContext(ctx).Unscoped().Delete(m)
|
||||
}
|
||||
|
||||
// Reload reloads the model from database by its primary key and overwrites current fields.
|
||||
func (m *TenantLedger) Reload(ctx context.Context) error {
|
||||
fresh, err := Q.TenantLedger.WithContext(ctx).GetByID(m.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*m = *fresh
|
||||
return nil
|
||||
}
|
||||
604
backend/database/models/tenant_ledgers.query.gen.go
Normal file
604
backend/database/models/tenant_ledgers.query.gen.go
Normal file
@@ -0,0 +1,604 @@
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
|
||||
|
||||
package models
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/clause"
|
||||
"gorm.io/gorm/schema"
|
||||
|
||||
"go.ipao.vip/gen"
|
||||
"go.ipao.vip/gen/field"
|
||||
|
||||
"gorm.io/plugin/dbresolver"
|
||||
)
|
||||
|
||||
func newTenantLedger(db *gorm.DB, opts ...gen.DOOption) tenantLedgerQuery {
|
||||
_tenantLedgerQuery := tenantLedgerQuery{}
|
||||
|
||||
_tenantLedgerQuery.tenantLedgerQueryDo.UseDB(db, opts...)
|
||||
_tenantLedgerQuery.tenantLedgerQueryDo.UseModel(&TenantLedger{})
|
||||
|
||||
tableName := _tenantLedgerQuery.tenantLedgerQueryDo.TableName()
|
||||
_tenantLedgerQuery.ALL = field.NewAsterisk(tableName)
|
||||
_tenantLedgerQuery.ID = field.NewInt64(tableName, "id")
|
||||
_tenantLedgerQuery.TenantID = field.NewInt64(tableName, "tenant_id")
|
||||
_tenantLedgerQuery.UserID = field.NewInt64(tableName, "user_id")
|
||||
_tenantLedgerQuery.OrderID = field.NewInt64(tableName, "order_id")
|
||||
_tenantLedgerQuery.Type = field.NewField(tableName, "type")
|
||||
_tenantLedgerQuery.Amount = field.NewInt64(tableName, "amount")
|
||||
_tenantLedgerQuery.BalanceBefore = field.NewInt64(tableName, "balance_before")
|
||||
_tenantLedgerQuery.BalanceAfter = field.NewInt64(tableName, "balance_after")
|
||||
_tenantLedgerQuery.FrozenBefore = field.NewInt64(tableName, "frozen_before")
|
||||
_tenantLedgerQuery.FrozenAfter = field.NewInt64(tableName, "frozen_after")
|
||||
_tenantLedgerQuery.IdempotencyKey = field.NewString(tableName, "idempotency_key")
|
||||
_tenantLedgerQuery.Remark = field.NewString(tableName, "remark")
|
||||
_tenantLedgerQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_tenantLedgerQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_tenantLedgerQuery.Order = tenantLedgerQueryBelongsToOrder{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Order", "Order"),
|
||||
}
|
||||
|
||||
_tenantLedgerQuery.fillFieldMap()
|
||||
|
||||
return _tenantLedgerQuery
|
||||
}
|
||||
|
||||
type tenantLedgerQuery struct {
|
||||
tenantLedgerQueryDo tenantLedgerQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64 // 主键ID:自增
|
||||
TenantID field.Int64 // 租户ID:多租户隔离关键字段;必须与 tenant_users.tenant_id 一致
|
||||
UserID field.Int64 // 用户ID:余额账户归属用户;对应 tenant_users.user_id
|
||||
OrderID field.Int64 // 关联订单ID:购买/退款类流水应关联 orders.id;非订单类可为空
|
||||
Type field.Field // 流水类型:credit_topup/debit_purchase/credit_refund/freeze/unfreeze/adjustment;不同类型决定余额/冻结余额的变更方向
|
||||
Amount field.Int64 // 流水金额:分/最小货币单位;通常为正数,方向由 type 决定(由业务层约束)
|
||||
BalanceBefore field.Int64 // 变更前可用余额:用于审计与对账回放
|
||||
BalanceAfter field.Int64 // 变更后可用余额:用于审计与对账回放
|
||||
FrozenBefore field.Int64 // 变更前冻结余额:用于审计与对账回放
|
||||
FrozenAfter field.Int64 // 变更后冻结余额:用于审计与对账回放
|
||||
IdempotencyKey field.String // 幂等键:同一租户同一用户同一业务操作固定;用于防止重复落账(建议由业务层生成)
|
||||
Remark field.String // 备注:业务说明/后台操作原因等;用于审计
|
||||
CreatedAt field.Time // 创建时间:默认 now()
|
||||
UpdatedAt field.Time // 更新时间:默认 now()
|
||||
Order tenantLedgerQueryBelongsToOrder
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
|
||||
func (t tenantLedgerQuery) Table(newTableName string) *tenantLedgerQuery {
|
||||
t.tenantLedgerQueryDo.UseTable(newTableName)
|
||||
return t.updateTableName(newTableName)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQuery) As(alias string) *tenantLedgerQuery {
|
||||
t.tenantLedgerQueryDo.DO = *(t.tenantLedgerQueryDo.As(alias).(*gen.DO))
|
||||
return t.updateTableName(alias)
|
||||
}
|
||||
|
||||
func (t *tenantLedgerQuery) updateTableName(table string) *tenantLedgerQuery {
|
||||
t.ALL = field.NewAsterisk(table)
|
||||
t.ID = field.NewInt64(table, "id")
|
||||
t.TenantID = field.NewInt64(table, "tenant_id")
|
||||
t.UserID = field.NewInt64(table, "user_id")
|
||||
t.OrderID = field.NewInt64(table, "order_id")
|
||||
t.Type = field.NewField(table, "type")
|
||||
t.Amount = field.NewInt64(table, "amount")
|
||||
t.BalanceBefore = field.NewInt64(table, "balance_before")
|
||||
t.BalanceAfter = field.NewInt64(table, "balance_after")
|
||||
t.FrozenBefore = field.NewInt64(table, "frozen_before")
|
||||
t.FrozenAfter = field.NewInt64(table, "frozen_after")
|
||||
t.IdempotencyKey = field.NewString(table, "idempotency_key")
|
||||
t.Remark = field.NewString(table, "remark")
|
||||
t.CreatedAt = field.NewTime(table, "created_at")
|
||||
t.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
func (t *tenantLedgerQuery) QueryContext(ctx context.Context) (*tenantLedgerQuery, *tenantLedgerQueryDo) {
|
||||
return t, t.tenantLedgerQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (t *tenantLedgerQuery) WithContext(ctx context.Context) *tenantLedgerQueryDo {
|
||||
return t.tenantLedgerQueryDo.WithContext(ctx)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQuery) TableName() string { return t.tenantLedgerQueryDo.TableName() }
|
||||
|
||||
func (t tenantLedgerQuery) Alias() string { return t.tenantLedgerQueryDo.Alias() }
|
||||
|
||||
func (t tenantLedgerQuery) Columns(cols ...field.Expr) gen.Columns {
|
||||
return t.tenantLedgerQueryDo.Columns(cols...)
|
||||
}
|
||||
|
||||
func (t *tenantLedgerQuery) GetFieldByName(fieldName string) (field.OrderExpr, bool) {
|
||||
_f, ok := t.fieldMap[fieldName]
|
||||
if !ok || _f == nil {
|
||||
return nil, false
|
||||
}
|
||||
_oe, ok := _f.(field.OrderExpr)
|
||||
return _oe, ok
|
||||
}
|
||||
|
||||
func (t *tenantLedgerQuery) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 15)
|
||||
t.fieldMap["id"] = t.ID
|
||||
t.fieldMap["tenant_id"] = t.TenantID
|
||||
t.fieldMap["user_id"] = t.UserID
|
||||
t.fieldMap["order_id"] = t.OrderID
|
||||
t.fieldMap["type"] = t.Type
|
||||
t.fieldMap["amount"] = t.Amount
|
||||
t.fieldMap["balance_before"] = t.BalanceBefore
|
||||
t.fieldMap["balance_after"] = t.BalanceAfter
|
||||
t.fieldMap["frozen_before"] = t.FrozenBefore
|
||||
t.fieldMap["frozen_after"] = t.FrozenAfter
|
||||
t.fieldMap["idempotency_key"] = t.IdempotencyKey
|
||||
t.fieldMap["remark"] = t.Remark
|
||||
t.fieldMap["created_at"] = t.CreatedAt
|
||||
t.fieldMap["updated_at"] = t.UpdatedAt
|
||||
|
||||
}
|
||||
|
||||
func (t tenantLedgerQuery) clone(db *gorm.DB) tenantLedgerQuery {
|
||||
t.tenantLedgerQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
t.Order.db = db.Session(&gorm.Session{Initialized: true})
|
||||
t.Order.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return t
|
||||
}
|
||||
|
||||
func (t tenantLedgerQuery) replaceDB(db *gorm.DB) tenantLedgerQuery {
|
||||
t.tenantLedgerQueryDo.ReplaceDB(db)
|
||||
t.Order.db = db.Session(&gorm.Session{})
|
||||
return t
|
||||
}
|
||||
|
||||
type tenantLedgerQueryBelongsToOrder struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrder) Where(conds ...field.Expr) *tenantLedgerQueryBelongsToOrder {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrder) WithContext(ctx context.Context) *tenantLedgerQueryBelongsToOrder {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrder) Session(session *gorm.Session) *tenantLedgerQueryBelongsToOrder {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrder) Model(m *TenantLedger) *tenantLedgerQueryBelongsToOrderTx {
|
||||
return &tenantLedgerQueryBelongsToOrderTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrder) Unscoped() *tenantLedgerQueryBelongsToOrder {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type tenantLedgerQueryBelongsToOrderTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrderTx) Find() (result *Order, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrderTx) Append(values ...*Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrderTx) Replace(values ...*Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrderTx) Delete(values ...*Order) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrderTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrderTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a tenantLedgerQueryBelongsToOrderTx) Unscoped() *tenantLedgerQueryBelongsToOrderTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type tenantLedgerQueryDo struct{ gen.DO }
|
||||
|
||||
func (t tenantLedgerQueryDo) Debug() *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Debug())
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) WithContext(ctx context.Context) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.WithContext(ctx))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) ReadDB() *tenantLedgerQueryDo {
|
||||
return t.Clauses(dbresolver.Read)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) WriteDB() *tenantLedgerQueryDo {
|
||||
return t.Clauses(dbresolver.Write)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Session(config *gorm.Session) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Session(config))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Clauses(conds ...clause.Expression) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Clauses(conds...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Returning(value interface{}, columns ...string) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Returning(value, columns...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Not(conds ...gen.Condition) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Not(conds...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Or(conds ...gen.Condition) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Or(conds...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Select(conds ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Select(conds...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Where(conds ...gen.Condition) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Where(conds...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Order(conds ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Order(conds...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Distinct(cols ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Distinct(cols...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Omit(cols ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Omit(cols...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Join(table schema.Tabler, on ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Join(table, on...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) LeftJoin(table schema.Tabler, on ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.LeftJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) RightJoin(table schema.Tabler, on ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.RightJoin(table, on...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Group(cols ...field.Expr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Group(cols...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Having(conds ...gen.Condition) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Having(conds...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Limit(limit int) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Limit(limit))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Offset(offset int) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Offset(offset))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Scopes(funcs ...func(gen.Dao) gen.Dao) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Scopes(funcs...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Unscoped() *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Unscoped())
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Create(values ...*TenantLedger) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Create(values)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) CreateInBatches(values []*TenantLedger, batchSize int) error {
|
||||
return t.DO.CreateInBatches(values, batchSize)
|
||||
}
|
||||
|
||||
// Save : !!! underlying implementation is different with GORM
|
||||
// The method is equivalent to executing the statement: db.Clauses(clause.OnConflict{UpdateAll: true}).Create(values)
|
||||
func (t tenantLedgerQueryDo) Save(values ...*TenantLedger) error {
|
||||
if len(values) == 0 {
|
||||
return nil
|
||||
}
|
||||
return t.DO.Save(values)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) First() (*TenantLedger, error) {
|
||||
if result, err := t.DO.First(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*TenantLedger), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Take() (*TenantLedger, error) {
|
||||
if result, err := t.DO.Take(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*TenantLedger), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Last() (*TenantLedger, error) {
|
||||
if result, err := t.DO.Last(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*TenantLedger), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Find() ([]*TenantLedger, error) {
|
||||
result, err := t.DO.Find()
|
||||
return result.([]*TenantLedger), err
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) FindInBatch(batchSize int, fc func(tx gen.Dao, batch int) error) (results []*TenantLedger, err error) {
|
||||
buf := make([]*TenantLedger, 0, batchSize)
|
||||
err = t.DO.FindInBatches(&buf, batchSize, func(tx gen.Dao, batch int) error {
|
||||
defer func() { results = append(results, buf...) }()
|
||||
return fc(tx, batch)
|
||||
})
|
||||
return results, err
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) FindInBatches(result *[]*TenantLedger, batchSize int, fc func(tx gen.Dao, batch int) error) error {
|
||||
return t.DO.FindInBatches(result, batchSize, fc)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Attrs(attrs ...field.AssignExpr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Attrs(attrs...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Assign(attrs ...field.AssignExpr) *tenantLedgerQueryDo {
|
||||
return t.withDO(t.DO.Assign(attrs...))
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Joins(fields ...field.RelationField) *tenantLedgerQueryDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Joins(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Preload(fields ...field.RelationField) *tenantLedgerQueryDo {
|
||||
for _, _f := range fields {
|
||||
t = *t.withDO(t.DO.Preload(_f))
|
||||
}
|
||||
return &t
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) FirstOrInit() (*TenantLedger, error) {
|
||||
if result, err := t.DO.FirstOrInit(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*TenantLedger), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) FirstOrCreate() (*TenantLedger, error) {
|
||||
if result, err := t.DO.FirstOrCreate(); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return result.(*TenantLedger), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) FindByPage(offset int, limit int) (result []*TenantLedger, count int64, err error) {
|
||||
result, err = t.Offset(offset).Limit(limit).Find()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if size := len(result); 0 < limit && 0 < size && size < limit {
|
||||
count = int64(size + offset)
|
||||
return
|
||||
}
|
||||
|
||||
count, err = t.Offset(-1).Limit(-1).Count()
|
||||
return
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) ScanByPage(result interface{}, offset int, limit int) (count int64, err error) {
|
||||
count, err = t.Count()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = t.Offset(offset).Limit(limit).Scan(result)
|
||||
return
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Scan(result interface{}) (err error) {
|
||||
return t.DO.Scan(result)
|
||||
}
|
||||
|
||||
func (t tenantLedgerQueryDo) Delete(models ...*TenantLedger) (result gen.ResultInfo, err error) {
|
||||
return t.DO.Delete(models)
|
||||
}
|
||||
|
||||
// ForceDelete performs a permanent delete (ignores soft-delete) for current scope.
|
||||
func (t tenantLedgerQueryDo) ForceDelete() (gen.ResultInfo, error) {
|
||||
return t.Unscoped().Delete()
|
||||
}
|
||||
|
||||
// Inc increases the given column by step for current scope.
|
||||
func (t tenantLedgerQueryDo) Inc(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column + step
|
||||
e := field.NewUnsafeFieldRaw("?+?", column.RawExpr(), step)
|
||||
return t.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Dec decreases the given column by step for current scope.
|
||||
func (t tenantLedgerQueryDo) Dec(column field.Expr, step int64) (gen.ResultInfo, error) {
|
||||
// column = column - step
|
||||
e := field.NewUnsafeFieldRaw("?-?", column.RawExpr(), step)
|
||||
return t.DO.UpdateColumn(column, e)
|
||||
}
|
||||
|
||||
// Sum returns SUM(column) for current scope.
|
||||
func (t tenantLedgerQueryDo) Sum(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("SUM(?)", column.RawExpr())
|
||||
if err := t.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Avg returns AVG(column) for current scope.
|
||||
func (t tenantLedgerQueryDo) Avg(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("AVG(?)", column.RawExpr())
|
||||
if err := t.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Min returns MIN(column) for current scope.
|
||||
func (t tenantLedgerQueryDo) Min(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MIN(?)", column.RawExpr())
|
||||
if err := t.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// Max returns MAX(column) for current scope.
|
||||
func (t tenantLedgerQueryDo) Max(column field.Expr) (float64, error) {
|
||||
var _v float64
|
||||
agg := field.NewUnsafeFieldRaw("MAX(?)", column.RawExpr())
|
||||
if err := t.Select(agg).Scan(&_v); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return _v, nil
|
||||
}
|
||||
|
||||
// PluckMap returns a map[key]value for selected key/value expressions within current scope.
|
||||
func (t tenantLedgerQueryDo) PluckMap(key, val field.Expr) (map[interface{}]interface{}, error) {
|
||||
do := t.Select(key, val)
|
||||
rows, err := do.DO.Rows()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
mm := make(map[interface{}]interface{})
|
||||
for rows.Next() {
|
||||
var k interface{}
|
||||
var v interface{}
|
||||
if err := rows.Scan(&k, &v); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
mm[k] = v
|
||||
}
|
||||
return mm, rows.Err()
|
||||
}
|
||||
|
||||
// Exists returns true if any record matches the given conditions.
|
||||
func (t tenantLedgerQueryDo) Exists(conds ...gen.Condition) (bool, error) {
|
||||
cnt, err := t.Where(conds...).Count()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return cnt > 0, nil
|
||||
}
|
||||
|
||||
// PluckIDs returns all primary key values under current scope.
|
||||
func (t tenantLedgerQueryDo) PluckIDs() ([]int64, error) {
|
||||
ids := make([]int64, 0, 16)
|
||||
pk := field.NewInt64(t.TableName(), "id")
|
||||
if err := t.DO.Pluck(pk, &ids); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ids, nil
|
||||
}
|
||||
|
||||
// GetByID finds a single record by primary key.
|
||||
func (t tenantLedgerQueryDo) GetByID(id int64) (*TenantLedger, error) {
|
||||
pk := field.NewInt64(t.TableName(), "id")
|
||||
return t.Where(pk.Eq(id)).First()
|
||||
}
|
||||
|
||||
// GetByIDs finds records by primary key list.
|
||||
func (t tenantLedgerQueryDo) GetByIDs(ids ...int64) ([]*TenantLedger, error) {
|
||||
if len(ids) == 0 {
|
||||
return []*TenantLedger{}, nil
|
||||
}
|
||||
pk := field.NewInt64(t.TableName(), "id")
|
||||
return t.Where(pk.In(ids...)).Find()
|
||||
}
|
||||
|
||||
// DeleteByID deletes records by primary key.
|
||||
func (t tenantLedgerQueryDo) DeleteByID(id int64) (gen.ResultInfo, error) {
|
||||
pk := field.NewInt64(t.TableName(), "id")
|
||||
return t.Where(pk.Eq(id)).Delete()
|
||||
}
|
||||
|
||||
// DeleteByIDs deletes records by a list of primary keys.
|
||||
func (t tenantLedgerQueryDo) DeleteByIDs(ids ...int64) (gen.ResultInfo, error) {
|
||||
if len(ids) == 0 {
|
||||
return gen.ResultInfo{RowsAffected: 0, Error: nil}, nil
|
||||
}
|
||||
pk := field.NewInt64(t.TableName(), "id")
|
||||
return t.Where(pk.In(ids...)).Delete()
|
||||
}
|
||||
|
||||
func (t *tenantLedgerQueryDo) withDO(do gen.Dao) *tenantLedgerQueryDo {
|
||||
t.DO = *do.(*gen.DO)
|
||||
return t
|
||||
}
|
||||
@@ -18,14 +18,15 @@ const TableNameTenantUser = "tenant_users"
|
||||
|
||||
// TenantUser mapped from table <tenant_users>
|
||||
type TenantUser 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"`
|
||||
Role types.Array[consts.TenantUserRole] `gorm:"column:role;type:text[];not null;default:ARRAY['member" json:"role"`
|
||||
Balance int64 `gorm:"column:balance;type:bigint;not null" json:"balance"`
|
||||
Status consts.UserStatus `gorm:"column:status;type:character varying(50);not null;default:active" json:"status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;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"`
|
||||
Role types.Array[consts.TenantUserRole] `gorm:"column:role;type:text[];not null;default:ARRAY['member" json:"role"`
|
||||
Balance int64 `gorm:"column:balance;type:bigint;not null" json:"balance"`
|
||||
Status consts.UserStatus `gorm:"column:status;type:character varying(50);not null;default:active" json:"status"`
|
||||
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now()" json:"created_at"`
|
||||
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now()" json:"updated_at"`
|
||||
BalanceFrozen int64 `gorm:"column:balance_frozen;type:bigint;not null;comment:冻结余额:分/最小货币单位;下单冻结时从可用余额转入,最终扣款或回滚时转出;默认 0" json:"balance_frozen"` // 冻结余额:分/最小货币单位;下单冻结时从可用余额转入,最终扣款或回滚时转出;默认 0
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -33,6 +33,7 @@ func newTenantUser(db *gorm.DB, opts ...gen.DOOption) tenantUserQuery {
|
||||
_tenantUserQuery.Status = field.NewField(tableName, "status")
|
||||
_tenantUserQuery.CreatedAt = field.NewTime(tableName, "created_at")
|
||||
_tenantUserQuery.UpdatedAt = field.NewTime(tableName, "updated_at")
|
||||
_tenantUserQuery.BalanceFrozen = field.NewInt64(tableName, "balance_frozen")
|
||||
|
||||
_tenantUserQuery.fillFieldMap()
|
||||
|
||||
@@ -42,15 +43,16 @@ func newTenantUser(db *gorm.DB, opts ...gen.DOOption) tenantUserQuery {
|
||||
type tenantUserQuery struct {
|
||||
tenantUserQueryDo tenantUserQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
Role field.Array
|
||||
Balance field.Int64
|
||||
Status field.Field
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
TenantID field.Int64
|
||||
UserID field.Int64
|
||||
Role field.Array
|
||||
Balance field.Int64
|
||||
Status field.Field
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
BalanceFrozen field.Int64 // 冻结余额:分/最小货币单位;下单冻结时从可用余额转入,最终扣款或回滚时转出;默认 0
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -75,6 +77,7 @@ func (t *tenantUserQuery) updateTableName(table string) *tenantUserQuery {
|
||||
t.Status = field.NewField(table, "status")
|
||||
t.CreatedAt = field.NewTime(table, "created_at")
|
||||
t.UpdatedAt = field.NewTime(table, "updated_at")
|
||||
t.BalanceFrozen = field.NewInt64(table, "balance_frozen")
|
||||
|
||||
t.fillFieldMap()
|
||||
|
||||
@@ -107,7 +110,7 @@ func (t *tenantUserQuery) GetFieldByName(fieldName string) (field.OrderExpr, boo
|
||||
}
|
||||
|
||||
func (t *tenantUserQuery) fillFieldMap() {
|
||||
t.fieldMap = make(map[string]field.Expr, 8)
|
||||
t.fieldMap = make(map[string]field.Expr, 9)
|
||||
t.fieldMap["id"] = t.ID
|
||||
t.fieldMap["tenant_id"] = t.TenantID
|
||||
t.fieldMap["user_id"] = t.UserID
|
||||
@@ -116,6 +119,7 @@ func (t *tenantUserQuery) fillFieldMap() {
|
||||
t.fieldMap["status"] = t.Status
|
||||
t.fieldMap["created_at"] = t.CreatedAt
|
||||
t.fieldMap["updated_at"] = t.UpdatedAt
|
||||
t.fieldMap["balance_frozen"] = t.BalanceFrozen
|
||||
}
|
||||
|
||||
func (t tenantUserQuery) clone(db *gorm.DB) tenantUserQuery {
|
||||
|
||||
@@ -29,8 +29,8 @@ type User struct {
|
||||
Status consts.UserStatus `gorm:"column:status;type:character varying(50);not null;default:active" json:"status"`
|
||||
Metas types.JSON `gorm:"column:metas;type:jsonb;not null;default:{}" json:"metas"`
|
||||
VerifiedAt time.Time `gorm:"column:verified_at;type:timestamp with time zone" json:"verified_at"`
|
||||
OwnedTenant *Tenant `json:"owned,omitempty"`
|
||||
Tenants []*Tenant `gorm:"joinForeignKey:UserID;joinReferences:TenantID;many2many:tenant_users" json:"tenants,omitempty"`
|
||||
OwnedTenant *Tenant `json:"owned,omitempty"`
|
||||
}
|
||||
|
||||
// Quick operations without importing query package
|
||||
|
||||
@@ -35,18 +35,18 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) userQuery {
|
||||
_userQuery.Status = field.NewField(tableName, "status")
|
||||
_userQuery.Metas = field.NewJSONB(tableName, "metas")
|
||||
_userQuery.VerifiedAt = field.NewTime(tableName, "verified_at")
|
||||
_userQuery.OwnedTenant = userQueryBelongsToOwnedTenant{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("OwnedTenant", "Tenant"),
|
||||
}
|
||||
|
||||
_userQuery.Tenants = userQueryManyToManyTenants{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("Tenants", "Tenant"),
|
||||
}
|
||||
|
||||
_userQuery.OwnedTenant = userQueryBelongsToOwnedTenant{
|
||||
db: db.Session(&gorm.Session{}),
|
||||
|
||||
RelationField: field.NewRelation("OwnedTenant", "Tenant"),
|
||||
}
|
||||
|
||||
_userQuery.fillFieldMap()
|
||||
|
||||
return _userQuery
|
||||
@@ -55,20 +55,20 @@ func newUser(db *gorm.DB, opts ...gen.DOOption) userQuery {
|
||||
type userQuery struct {
|
||||
userQueryDo userQueryDo
|
||||
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Username field.String
|
||||
Password field.String
|
||||
Roles field.Array
|
||||
Status field.Field
|
||||
Metas field.JSONB
|
||||
VerifiedAt field.Time
|
||||
OwnedTenant userQueryBelongsToOwnedTenant
|
||||
ALL field.Asterisk
|
||||
ID field.Int64
|
||||
CreatedAt field.Time
|
||||
UpdatedAt field.Time
|
||||
DeletedAt field.Field
|
||||
Username field.String
|
||||
Password field.String
|
||||
Roles field.Array
|
||||
Status field.Field
|
||||
Metas field.JSONB
|
||||
VerifiedAt field.Time
|
||||
Tenants userQueryManyToManyTenants
|
||||
|
||||
Tenants userQueryManyToManyTenants
|
||||
OwnedTenant userQueryBelongsToOwnedTenant
|
||||
|
||||
fieldMap map[string]field.Expr
|
||||
}
|
||||
@@ -141,101 +141,20 @@ func (u *userQuery) fillFieldMap() {
|
||||
|
||||
func (u userQuery) clone(db *gorm.DB) userQuery {
|
||||
u.userQueryDo.ReplaceConnPool(db.Statement.ConnPool)
|
||||
u.OwnedTenant.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.OwnedTenant.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
u.Tenants.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.Tenants.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
u.OwnedTenant.db = db.Session(&gorm.Session{Initialized: true})
|
||||
u.OwnedTenant.db.Statement.ConnPool = db.Statement.ConnPool
|
||||
return u
|
||||
}
|
||||
|
||||
func (u userQuery) replaceDB(db *gorm.DB) userQuery {
|
||||
u.userQueryDo.ReplaceDB(db)
|
||||
u.OwnedTenant.db = db.Session(&gorm.Session{})
|
||||
u.Tenants.db = db.Session(&gorm.Session{})
|
||||
u.OwnedTenant.db = db.Session(&gorm.Session{})
|
||||
return u
|
||||
}
|
||||
|
||||
type userQueryBelongsToOwnedTenant struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Where(conds ...field.Expr) *userQueryBelongsToOwnedTenant {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) WithContext(ctx context.Context) *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Session(session *gorm.Session) *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Model(m *User) *userQueryBelongsToOwnedTenantTx {
|
||||
return &userQueryBelongsToOwnedTenantTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Unscoped() *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryBelongsToOwnedTenantTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Find() (result *Tenant, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Append(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Replace(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Delete(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Unscoped() *userQueryBelongsToOwnedTenantTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryManyToManyTenants struct {
|
||||
db *gorm.DB
|
||||
|
||||
@@ -317,6 +236,87 @@ func (a userQueryManyToManyTenantsTx) Unscoped() *userQueryManyToManyTenantsTx {
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryBelongsToOwnedTenant struct {
|
||||
db *gorm.DB
|
||||
|
||||
field.RelationField
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Where(conds ...field.Expr) *userQueryBelongsToOwnedTenant {
|
||||
if len(conds) == 0 {
|
||||
return &a
|
||||
}
|
||||
|
||||
exprs := make([]clause.Expression, 0, len(conds))
|
||||
for _, cond := range conds {
|
||||
exprs = append(exprs, cond.BeCond().(clause.Expression))
|
||||
}
|
||||
a.db = a.db.Clauses(clause.Where{Exprs: exprs})
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) WithContext(ctx context.Context) *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.WithContext(ctx)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Session(session *gorm.Session) *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.Session(session)
|
||||
return &a
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Model(m *User) *userQueryBelongsToOwnedTenantTx {
|
||||
return &userQueryBelongsToOwnedTenantTx{a.db.Model(m).Association(a.Name())}
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenant) Unscoped() *userQueryBelongsToOwnedTenant {
|
||||
a.db = a.db.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryBelongsToOwnedTenantTx struct{ tx *gorm.Association }
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Find() (result *Tenant, err error) {
|
||||
return result, a.tx.Find(&result)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Append(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Append(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Replace(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Replace(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Delete(values ...*Tenant) (err error) {
|
||||
targetValues := make([]interface{}, len(values))
|
||||
for i, v := range values {
|
||||
targetValues[i] = v
|
||||
}
|
||||
return a.tx.Delete(targetValues...)
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Clear() error {
|
||||
return a.tx.Clear()
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Count() int64 {
|
||||
return a.tx.Count()
|
||||
}
|
||||
|
||||
func (a userQueryBelongsToOwnedTenantTx) Unscoped() *userQueryBelongsToOwnedTenantTx {
|
||||
a.tx = a.tx.Unscoped()
|
||||
return &a
|
||||
}
|
||||
|
||||
type userQueryDo struct{ gen.DO }
|
||||
|
||||
func (u userQueryDo) Debug() *userQueryDo {
|
||||
|
||||
Reference in New Issue
Block a user