- products 表新增 cost_price 字段(成本价/分) - activity_reward_settings 新增 drop_quantity(单次产出数量,默认1) 和 cost_snapshot_cents(成本价快照) - 奖品创建/修改时自动快照成本价,drop_quantity 限制 1-100 - 抽奖发放逻辑按 drop_quantity 循环创建多个库存项 - 抽奖结果接口按 drop_quantity 返回多条 item,前端自动合并显示 - 抽奖记录接口返回 drop_quantity 字段 - 商品管理 API 全链路支持 cost_price
76 lines
1.9 KiB
Go
Executable File
76 lines
1.9 KiB
Go
Executable File
package activity
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"bindbox-game/internal/repository/mysql/model"
|
|
)
|
|
|
|
// ModifyIssueReward 修改期奖励
|
|
// 参数: rewardID 奖励ID, in 修改输入
|
|
// 返回: 错误信息
|
|
func (s *service) ModifyIssueReward(ctx context.Context, rewardID int64, in ModifyRewardInput) error {
|
|
item, err := s.readDB.ActivityRewardSettings.WithContext(ctx).Where(s.readDB.ActivityRewardSettings.ID.Eq(rewardID)).First()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if in.ProductID != nil {
|
|
item.ProductID = *in.ProductID
|
|
priceSnapshot := int64(0)
|
|
costSnapshot := int64(0)
|
|
if *in.ProductID > 0 {
|
|
product, err := s.readDB.Products.WithContext(ctx).Where(s.readDB.Products.ID.Eq(*in.ProductID)).First()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
priceSnapshot = product.Price
|
|
costSnapshot = product.CostPrice
|
|
}
|
|
item.PriceSnapshotCents = priceSnapshot
|
|
item.CostSnapshotCents = costSnapshot
|
|
item.PriceSnapshotAt = time.Now()
|
|
}
|
|
if in.Weight != nil {
|
|
item.Weight = int32(*in.Weight)
|
|
}
|
|
if in.Quantity != nil {
|
|
item.Quantity = *in.Quantity
|
|
}
|
|
if in.OriginalQty != nil {
|
|
item.OriginalQty = *in.OriginalQty
|
|
}
|
|
if in.Level != nil {
|
|
item.Level = *in.Level
|
|
}
|
|
if in.Sort != nil {
|
|
item.Sort = *in.Sort
|
|
}
|
|
if in.IsBoss != nil {
|
|
item.IsBoss = *in.IsBoss
|
|
}
|
|
if in.MinScore != nil {
|
|
item.MinScore = *in.MinScore
|
|
}
|
|
if in.DropQuantity != nil {
|
|
dq := *in.DropQuantity
|
|
if dq < 1 {
|
|
dq = 1
|
|
}
|
|
if dq > 100 {
|
|
dq = 100
|
|
}
|
|
item.DropQuantity = dq
|
|
}
|
|
item.UpdatedAt = time.Now()
|
|
return s.writeDB.ActivityRewardSettings.WithContext(ctx).Save(item)
|
|
}
|
|
|
|
// DeleteIssueReward 删除期奖励
|
|
// 参数: rewardID 奖励ID
|
|
// 返回: 错误信息
|
|
func (s *service) DeleteIssueReward(ctx context.Context, rewardID int64) error {
|
|
_, err := s.writeDB.ActivityRewardSettings.WithContext(ctx).Where(s.writeDB.ActivityRewardSettings.ID.Eq(rewardID)).Delete(&model.ActivityRewardSettings{})
|
|
return err
|
|
}
|