diff --git a/internal/repository/mysql/dao/activity_reward_settings.gen.go b/internal/repository/mysql/dao/activity_reward_settings.gen.go index 4537262..2a94873 100755 --- a/internal/repository/mysql/dao/activity_reward_settings.gen.go +++ b/internal/repository/mysql/dao/activity_reward_settings.gen.go @@ -32,6 +32,8 @@ func newActivityRewardSettings(db *gorm.DB, opts ...gen.DOOption) activityReward _activityRewardSettings.UpdatedAt = field.NewTime(tableName, "updated_at") _activityRewardSettings.IssueID = field.NewInt64(tableName, "issue_id") _activityRewardSettings.ProductID = field.NewInt64(tableName, "product_id") + _activityRewardSettings.PriceSnapshotCents = field.NewInt64(tableName, "price_snapshot_cents") + _activityRewardSettings.PriceSnapshotAt = field.NewTime(tableName, "price_snapshot_at") _activityRewardSettings.Weight = field.NewInt32(tableName, "weight") _activityRewardSettings.Quantity = field.NewInt64(tableName, "quantity") _activityRewardSettings.OriginalQty = field.NewInt64(tableName, "original_qty") @@ -50,20 +52,22 @@ func newActivityRewardSettings(db *gorm.DB, opts ...gen.DOOption) activityReward type activityRewardSettings struct { activityRewardSettingsDo - ALL field.Asterisk - ID field.Int64 // 主键ID - CreatedAt field.Time // 创建时间 - UpdatedAt field.Time // 更新时间 - IssueID field.Int64 // 期ID(activity_issues.id) - ProductID field.Int64 // 奖品对应商品ID(实物奖可填) - Weight field.Int32 // 抽中权重(越大越易中) - Quantity field.Int64 // 当前可发数量(扣减) - OriginalQty field.Int64 // 初始配置数量 - Level field.Int32 // 奖级(如1=S 2=A 3=B) - Sort field.Int32 // 排序 - IsBoss field.Int32 // Boss 1 是 0 不是 - DeletedAt field.Field - MinScore field.Int64 // 最低得分/碰数要求 + ALL field.Asterisk + ID field.Int64 // 主键ID + CreatedAt field.Time // 创建时间 + UpdatedAt field.Time // 更新时间 + IssueID field.Int64 // 期ID(activity_issues.id) + ProductID field.Int64 // 奖品对应商品ID(实物奖可填) + PriceSnapshotCents field.Int64 // 奖品配置时商品价格快照(分) + PriceSnapshotAt field.Time // 奖品价格快照时间 + Weight field.Int32 // 抽中权重(越大越易中) + Quantity field.Int64 // 当前可发数量(扣减) + OriginalQty field.Int64 // 初始配置数量 + Level field.Int32 // 奖级(如1=S 2=A 3=B) + Sort field.Int32 // 排序 + IsBoss field.Int32 // Boss 1 是 0 不是 + DeletedAt field.Field + MinScore field.Int64 // 最低得分/碰数要求 fieldMap map[string]field.Expr } @@ -85,6 +89,8 @@ func (a *activityRewardSettings) updateTableName(table string) *activityRewardSe a.UpdatedAt = field.NewTime(table, "updated_at") a.IssueID = field.NewInt64(table, "issue_id") a.ProductID = field.NewInt64(table, "product_id") + a.PriceSnapshotCents = field.NewInt64(table, "price_snapshot_cents") + a.PriceSnapshotAt = field.NewTime(table, "price_snapshot_at") a.Weight = field.NewInt32(table, "weight") a.Quantity = field.NewInt64(table, "quantity") a.OriginalQty = field.NewInt64(table, "original_qty") @@ -109,12 +115,14 @@ func (a *activityRewardSettings) GetFieldByName(fieldName string) (field.OrderEx } func (a *activityRewardSettings) fillFieldMap() { - a.fieldMap = make(map[string]field.Expr, 13) + a.fieldMap = make(map[string]field.Expr, 15) a.fieldMap["id"] = a.ID a.fieldMap["created_at"] = a.CreatedAt a.fieldMap["updated_at"] = a.UpdatedAt a.fieldMap["issue_id"] = a.IssueID a.fieldMap["product_id"] = a.ProductID + a.fieldMap["price_snapshot_cents"] = a.PriceSnapshotCents + a.fieldMap["price_snapshot_at"] = a.PriceSnapshotAt a.fieldMap["weight"] = a.Weight a.fieldMap["quantity"] = a.Quantity a.fieldMap["original_qty"] = a.OriginalQty diff --git a/internal/repository/mysql/dao/user_inventory.gen.go b/internal/repository/mysql/dao/user_inventory.gen.go index bb19b62..c404d4e 100755 --- a/internal/repository/mysql/dao/user_inventory.gen.go +++ b/internal/repository/mysql/dao/user_inventory.gen.go @@ -32,6 +32,9 @@ func newUserInventory(db *gorm.DB, opts ...gen.DOOption) userInventory { _userInventory.UpdatedAt = field.NewTime(tableName, "updated_at") _userInventory.UserID = field.NewInt64(tableName, "user_id") _userInventory.ProductID = field.NewInt64(tableName, "product_id") + _userInventory.ValueCents = field.NewInt64(tableName, "value_cents") + _userInventory.ValueSource = field.NewInt32(tableName, "value_source") + _userInventory.ValueSnapshotAt = field.NewTime(tableName, "value_snapshot_at") _userInventory.OrderID = field.NewInt64(tableName, "order_id") _userInventory.ActivityID = field.NewInt64(tableName, "activity_id") _userInventory.RewardID = field.NewInt64(tableName, "reward_id") @@ -48,18 +51,21 @@ func newUserInventory(db *gorm.DB, opts ...gen.DOOption) userInventory { type userInventory struct { userInventoryDo - ALL field.Asterisk - ID field.Int64 // 主键ID - CreatedAt field.Time // 创建时间 - UpdatedAt field.Time // 更新时间 - UserID field.Int64 // 资产归属用户ID - ProductID field.Int64 // 资产对应商品ID(实物奖/商品) - OrderID field.Int64 // 来源订单ID - ActivityID field.Int64 // 来源活动ID - RewardID field.Int64 // 来源奖励ID(activity_reward_settings.id) - Status field.Int32 // 状态:1持有 2作废 3已使用/发货 - ShippingNo field.String // 发货单号 - Remark field.String // 备注 + ALL field.Asterisk + ID field.Int64 // 主键ID + CreatedAt field.Time // 创建时间 + UpdatedAt field.Time // 更新时间 + UserID field.Int64 // 资产归属用户ID + ProductID field.Int64 // 资产对应商品ID(实物奖/商品) + ValueCents field.Int64 // 资产价值快照(分) + ValueSource field.Int32 // 价值来源:0未知 1奖励快照 2商品回退 3人工修复 + ValueSnapshotAt field.Time // 资产价值快照时间 + OrderID field.Int64 // 来源订单ID + ActivityID field.Int64 // 来源活动ID + RewardID field.Int64 // 来源奖励ID(activity_reward_settings.id) + Status field.Int32 // 状态:1持有 2作废 3已使用/发货 + ShippingNo field.String // 发货单号 + Remark field.String // 备注 fieldMap map[string]field.Expr } @@ -81,6 +87,9 @@ func (u *userInventory) updateTableName(table string) *userInventory { u.UpdatedAt = field.NewTime(table, "updated_at") u.UserID = field.NewInt64(table, "user_id") u.ProductID = field.NewInt64(table, "product_id") + u.ValueCents = field.NewInt64(table, "value_cents") + u.ValueSource = field.NewInt32(table, "value_source") + u.ValueSnapshotAt = field.NewTime(table, "value_snapshot_at") u.OrderID = field.NewInt64(table, "order_id") u.ActivityID = field.NewInt64(table, "activity_id") u.RewardID = field.NewInt64(table, "reward_id") @@ -103,12 +112,15 @@ func (u *userInventory) GetFieldByName(fieldName string) (field.OrderExpr, bool) } func (u *userInventory) fillFieldMap() { - u.fieldMap = make(map[string]field.Expr, 11) + u.fieldMap = make(map[string]field.Expr, 14) u.fieldMap["id"] = u.ID u.fieldMap["created_at"] = u.CreatedAt u.fieldMap["updated_at"] = u.UpdatedAt u.fieldMap["user_id"] = u.UserID u.fieldMap["product_id"] = u.ProductID + u.fieldMap["value_cents"] = u.ValueCents + u.fieldMap["value_source"] = u.ValueSource + u.fieldMap["value_snapshot_at"] = u.ValueSnapshotAt u.fieldMap["order_id"] = u.OrderID u.fieldMap["activity_id"] = u.ActivityID u.fieldMap["reward_id"] = u.RewardID diff --git a/internal/repository/mysql/model/activity_reward_settings.gen.go b/internal/repository/mysql/model/activity_reward_settings.gen.go index 4b9a680..007cf0f 100755 --- a/internal/repository/mysql/model/activity_reward_settings.gen.go +++ b/internal/repository/mysql/model/activity_reward_settings.gen.go @@ -14,19 +14,21 @@ const TableNameActivityRewardSettings = "activity_reward_settings" // ActivityRewardSettings 活动期-奖励配置 type ActivityRewardSettings struct { - ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键ID" json:"id"` // 主键ID - CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP(3);comment:创建时间" json:"created_at"` // 创建时间 - UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP(3);comment:更新时间" json:"updated_at"` // 更新时间 - IssueID int64 `gorm:"column:issue_id;not null;comment:期ID(activity_issues.id)" json:"issue_id"` // 期ID(activity_issues.id) - ProductID int64 `gorm:"column:product_id;comment:奖品对应商品ID(实物奖可填)" json:"product_id"` // 奖品对应商品ID(实物奖可填) - Weight int32 `gorm:"column:weight;not null;comment:抽中权重(越大越易中)" json:"weight"` // 抽中权重(越大越易中) - Quantity int64 `gorm:"column:quantity;not null;comment:当前可发数量(扣减)" json:"quantity"` // 当前可发数量(扣减) - OriginalQty int64 `gorm:"column:original_qty;not null;comment:初始配置数量" json:"original_qty"` // 初始配置数量 - Level int32 `gorm:"column:level;not null;comment:奖级(如1=S 2=A 3=B)" json:"level"` // 奖级(如1=S 2=A 3=B) - Sort int32 `gorm:"column:sort;comment:排序" json:"sort"` // 排序 - IsBoss int32 `gorm:"column:is_boss;comment:Boss 1 是 0 不是" json:"is_boss"` // Boss 1 是 0 不是 - DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"` - MinScore int64 `gorm:"column:min_score;not null;comment:最低得分/碰数要求" json:"min_score"` // 最低得分/碰数要求 + ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键ID" json:"id"` // 主键ID + CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP(3);comment:创建时间" json:"created_at"` // 创建时间 + UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP(3);comment:更新时间" json:"updated_at"` // 更新时间 + IssueID int64 `gorm:"column:issue_id;not null;comment:期ID(activity_issues.id)" json:"issue_id"` // 期ID(activity_issues.id) + ProductID int64 `gorm:"column:product_id;comment:奖品对应商品ID(实物奖可填)" json:"product_id"` // 奖品对应商品ID(实物奖可填) + PriceSnapshotCents int64 `gorm:"column:price_snapshot_cents;not null;comment:奖品配置时商品价格快照(分)" json:"price_snapshot_cents"` // 奖品配置时商品价格快照(分) + PriceSnapshotAt time.Time `gorm:"column:price_snapshot_at;comment:奖品价格快照时间" json:"price_snapshot_at"` // 奖品价格快照时间 + Weight int32 `gorm:"column:weight;not null;comment:抽中权重(越大越易中)" json:"weight"` // 抽中权重(越大越易中) + Quantity int64 `gorm:"column:quantity;not null;comment:当前可发数量(扣减)" json:"quantity"` // 当前可发数量(扣减) + OriginalQty int64 `gorm:"column:original_qty;not null;comment:初始配置数量" json:"original_qty"` // 初始配置数量 + Level int32 `gorm:"column:level;not null;comment:奖级(如1=S 2=A 3=B)" json:"level"` // 奖级(如1=S 2=A 3=B) + Sort int32 `gorm:"column:sort;comment:排序" json:"sort"` // 排序 + IsBoss int32 `gorm:"column:is_boss;comment:Boss 1 是 0 不是" json:"is_boss"` // Boss 1 是 0 不是 + DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"deleted_at"` + MinScore int64 `gorm:"column:min_score;not null;comment:最低得分/碰数要求" json:"min_score"` // 最低得分/碰数要求 } // TableName ActivityRewardSettings's table name diff --git a/internal/repository/mysql/model/user_inventory.gen.go b/internal/repository/mysql/model/user_inventory.gen.go index 208d5dd..6bc8147 100755 --- a/internal/repository/mysql/model/user_inventory.gen.go +++ b/internal/repository/mysql/model/user_inventory.gen.go @@ -12,17 +12,20 @@ const TableNameUserInventory = "user_inventory" // UserInventory 用户资产(资产) type UserInventory struct { - ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键ID" json:"id"` // 主键ID - CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP(3);comment:创建时间" json:"created_at"` // 创建时间 - UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP(3);comment:更新时间" json:"updated_at"` // 更新时间 - UserID int64 `gorm:"column:user_id;not null;comment:资产归属用户ID" json:"user_id"` // 资产归属用户ID - ProductID int64 `gorm:"column:product_id;comment:资产对应商品ID(实物奖/商品)" json:"product_id"` // 资产对应商品ID(实物奖/商品) - OrderID int64 `gorm:"column:order_id;comment:来源订单ID" json:"order_id"` // 来源订单ID - ActivityID int64 `gorm:"column:activity_id;comment:来源活动ID" json:"activity_id"` // 来源活动ID - RewardID int64 `gorm:"column:reward_id;comment:来源奖励ID(activity_reward_settings.id)" json:"reward_id"` // 来源奖励ID(activity_reward_settings.id) - Status int32 `gorm:"column:status;not null;default:1;comment:状态:1持有 2作废 3已使用/发货" json:"status"` // 状态:1持有 2作废 3已使用/发货 - ShippingNo string `gorm:"column:shipping_no;not null;comment:发货单号" json:"shipping_no"` // 发货单号 - Remark string `gorm:"column:remark;comment:备注" json:"remark"` // 备注 + ID int64 `gorm:"column:id;primaryKey;autoIncrement:true;comment:主键ID" json:"id"` // 主键ID + CreatedAt time.Time `gorm:"column:created_at;not null;default:CURRENT_TIMESTAMP(3);comment:创建时间" json:"created_at"` // 创建时间 + UpdatedAt time.Time `gorm:"column:updated_at;not null;default:CURRENT_TIMESTAMP(3);comment:更新时间" json:"updated_at"` // 更新时间 + UserID int64 `gorm:"column:user_id;not null;comment:资产归属用户ID" json:"user_id"` // 资产归属用户ID + ProductID int64 `gorm:"column:product_id;comment:资产对应商品ID(实物奖/商品)" json:"product_id"` // 资产对应商品ID(实物奖/商品) + ValueCents int64 `gorm:"column:value_cents;not null;comment:资产价值快照(分)" json:"value_cents"` // 资产价值快照(分) + ValueSource int32 `gorm:"column:value_source;not null;comment:价值来源:0未知 1奖励快照 2商品回退 3人工修复" json:"value_source"` // 价值来源:0未知 1奖励快照 2商品回退 3人工修复 + ValueSnapshotAt time.Time `gorm:"column:value_snapshot_at;comment:资产价值快照时间" json:"value_snapshot_at"` // 资产价值快照时间 + OrderID int64 `gorm:"column:order_id;comment:来源订单ID" json:"order_id"` // 来源订单ID + ActivityID int64 `gorm:"column:activity_id;comment:来源活动ID" json:"activity_id"` // 来源活动ID + RewardID int64 `gorm:"column:reward_id;comment:来源奖励ID(activity_reward_settings.id)" json:"reward_id"` // 来源奖励ID(activity_reward_settings.id) + Status int32 `gorm:"column:status;not null;default:1;comment:状态:1持有 2作废 3已使用/发货" json:"status"` // 状态:1持有 2作废 3已使用/发货 + ShippingNo string `gorm:"column:shipping_no;not null;comment:发货单号" json:"shipping_no"` // 发货单号 + Remark string `gorm:"column:remark;comment:备注" json:"remark"` // 备注 } // TableName UserInventory's table name diff --git a/migrations/20260221_add_reward_inventory_value_snapshots.sql b/migrations/20260221_add_reward_inventory_value_snapshots.sql new file mode 100644 index 0000000..45c797d --- /dev/null +++ b/migrations/20260221_add_reward_inventory_value_snapshots.sql @@ -0,0 +1,30 @@ +ALTER TABLE `activity_reward_settings` + ADD COLUMN `price_snapshot_cents` BIGINT NOT NULL DEFAULT 0 COMMENT '奖品配置时商品价格快照(分)' AFTER `product_id`, + ADD COLUMN `price_snapshot_at` DATETIME(3) NULL COMMENT '奖品价格快照时间' AFTER `price_snapshot_cents`; + +ALTER TABLE `user_inventory` + ADD COLUMN `value_cents` BIGINT NOT NULL DEFAULT 0 COMMENT '资产价值快照(分)' AFTER `product_id`, + ADD COLUMN `value_source` TINYINT NOT NULL DEFAULT 0 COMMENT '价值来源:0未知 1奖励快照 2商品回退 3人工修复' AFTER `value_cents`, + ADD COLUMN `value_snapshot_at` DATETIME(3) NULL COMMENT '资产价值快照时间' AFTER `value_source`; + +UPDATE `activity_reward_settings` ars +LEFT JOIN `products` p ON p.id = ars.product_id +SET ars.price_snapshot_cents = COALESCE(p.price, 0), + ars.price_snapshot_at = NOW(3) +WHERE ars.price_snapshot_cents = 0; + +UPDATE `user_inventory` ui +LEFT JOIN `activity_reward_settings` ars ON ars.id = ui.reward_id +SET ui.value_cents = ars.price_snapshot_cents, + ui.value_source = 1, + ui.value_snapshot_at = COALESCE(ars.price_snapshot_at, NOW(3)) +WHERE ui.value_cents = 0 + AND ui.reward_id > 0 + AND ars.price_snapshot_cents > 0; + +UPDATE `user_inventory` ui +LEFT JOIN `products` p ON p.id = ui.product_id +SET ui.value_cents = COALESCE(p.price, 0), + ui.value_source = 2, + ui.value_snapshot_at = NOW(3) +WHERE ui.value_cents = 0;