This commit is contained in:
@@ -29,6 +29,10 @@ type BatchGenerateReq struct {
|
||||
Count int `json:"count" v:"required|min:1#请输入正确的生成数量"`
|
||||
}
|
||||
|
||||
type SignRewardOptionsReq struct {
|
||||
g.Meta `path:"/signRewardOptions" method:"POST"`
|
||||
}
|
||||
|
||||
func (c *CdkController) BatchGenerate(ctx context.Context, req *BatchGenerateReq) (res *cool.BaseRes, err error) {
|
||||
data, err := service.NewCdkService().BatchGenerate(ctx, req.Count)
|
||||
if err != nil {
|
||||
@@ -36,3 +40,7 @@ func (c *CdkController) BatchGenerate(ctx context.Context, req *BatchGenerateReq
|
||||
}
|
||||
return cool.Ok(data), nil
|
||||
}
|
||||
|
||||
func (c *CdkController) SignRewardOptions(ctx context.Context, req *SignRewardOptionsReq) (res *cool.BaseRes, err error) {
|
||||
return cool.Ok(service.NewCdkService().SignRewardOptions()), nil
|
||||
}
|
||||
|
||||
@@ -145,6 +145,22 @@ func (s *CdkService) GetByID(id uint32) *model.CDKConfig {
|
||||
return item
|
||||
}
|
||||
|
||||
func (s *CdkService) GetRewardByIDIncludeDeleted(id uint32) *model.CDKConfig {
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var item *model.CDKConfig
|
||||
dbm_nocache_noenable(s.Model).Unscoped().Where("id", id).Where("type", CDKTypeReward).Scan(&item)
|
||||
return item
|
||||
}
|
||||
|
||||
func (s *CdkService) SignRewardOptions() []model.CDKConfig {
|
||||
var items []model.CDKConfig
|
||||
dbm_nocache_noenable(s.Model).Unscoped().Where("type", CDKTypeReward).OrderDesc("id").Scan(&items)
|
||||
return items
|
||||
}
|
||||
|
||||
func (s *CdkService) All() []model.CDKConfig {
|
||||
var item []model.CDKConfig
|
||||
dbm_notenable(s.Model).WhereLT("exchange_remain_count", 0).Scan(&item)
|
||||
|
||||
@@ -58,8 +58,8 @@ func (s *SignInService) ModifyBefore(ctx context.Context, method string, param g
|
||||
if cdkID == 0 {
|
||||
return fmt.Errorf("cdk_id不能为空")
|
||||
}
|
||||
if NewCdkService().GetByID(cdkID) == nil {
|
||||
return fmt.Errorf("绑定的CDK不存在")
|
||||
if NewCdkService().GetRewardByIDIncludeDeleted(cdkID) == nil {
|
||||
return fmt.Errorf("绑定的CDK不存在或不是普通奖励类型")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -7,14 +7,11 @@ import (
|
||||
// 表名常量(遵循小写+下划线的命名规范)
|
||||
const TableNameSignInRecord = "player_sign_in_log"
|
||||
|
||||
// SignInRecord 玩家签到明细记录表
|
||||
// 记录玩家每一次的签到行为,关联签到活动表
|
||||
// SignInRecord 玩家签到进度记录表
|
||||
type SignInRecord struct {
|
||||
Base
|
||||
|
||||
// 核心关联字段
|
||||
PlayerID uint32 `gorm:"not null;index:idx_player_id;comment:'玩家ID'" json:"player_id"`
|
||||
SignInID uint32 `gorm:"not null;index:idx_sign_in_id;comment:'关联的签到活动ID(对应player_sign_in表的SignInID)'" json:"sign_in_id"`
|
||||
|
||||
IsCompleted bool `gorm:"not null;default:false;comment:'签到是否完成(0-未完成 1-已完成)'" json:"is_completed"`
|
||||
ContinuousDays uint32 `gorm:"not null;default:0;comment:'连续签到天数'" json:"continuous_days"`
|
||||
|
||||
@@ -31,9 +31,9 @@ type CdkSpecialRewardAdder func(itemID uint32, count int64) bool
|
||||
// GrantConfigReward 按 cdk 配置 ID 发放奖励,不处理兑换码次数和领取资格校验。
|
||||
// 当传入 specialAdder 时,赛尔豆/累计经验/金豆/学习力会优先走在线玩家加成逻辑。
|
||||
func (s *CdkService) GrantConfigReward(cdkID uint32, specialAdders ...CdkSpecialRewardAdder) (*CdkRewardResult, error) {
|
||||
cfg := configservice.NewCdkService().GetByID(cdkID)
|
||||
cfg := configservice.NewCdkService().GetRewardByIDIncludeDeleted(cdkID)
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("绑定的CDK不存在")
|
||||
return nil, fmt.Errorf("绑定的CDK不存在或不是游戏内奖励类型")
|
||||
}
|
||||
if cfg.Type != configservice.CDKTypeReward {
|
||||
return nil, fmt.Errorf("当前CDK不是游戏内奖励类型")
|
||||
|
||||
@@ -11,8 +11,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
const signRecordID uint32 = 1
|
||||
|
||||
// SignStageState 表示一个签到阶段的当前状态。
|
||||
type SignStageState struct {
|
||||
SignType uint32 `json:"sign_type"`
|
||||
@@ -54,9 +52,7 @@ type SignClaimResult struct {
|
||||
|
||||
// SignResetResult 表示管理端执行的签到重置结果。
|
||||
type SignResetResult struct {
|
||||
SignRecordRows int64 `json:"sign_record_rows"`
|
||||
CdkLogRows int64 `json:"cdk_log_rows"`
|
||||
ResetCdkIDs []uint32 `json:"reset_cdk_ids"`
|
||||
SignRecordRows int64 `json:"sign_record_rows"`
|
||||
}
|
||||
|
||||
// SignService 管理玩家签到进度。
|
||||
@@ -136,32 +132,6 @@ func (s *SignService) ResetAll() (*SignResetResult, error) {
|
||||
result.SignRecordRows, _ = signRes.RowsAffected()
|
||||
}
|
||||
|
||||
configs := configservice.NewSignInService().GetEnabled()
|
||||
cdkIDs := make([]uint32, 0, len(configs))
|
||||
seen := make(map[uint32]struct{}, len(configs))
|
||||
for _, cfg := range configs {
|
||||
if cfg.CdkID == 0 {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[cfg.CdkID]; ok {
|
||||
continue
|
||||
}
|
||||
seen[cfg.CdkID] = struct{}{}
|
||||
cdkIDs = append(cdkIDs, cfg.CdkID)
|
||||
}
|
||||
sort.Slice(cdkIDs, func(i, j int) bool { return cdkIDs[i] < cdkIDs[j] })
|
||||
result.ResetCdkIDs = cdkIDs
|
||||
|
||||
if len(cdkIDs) > 0 {
|
||||
cdkRes, err := cool.DBM(model.NewCdkLog()).WhereIn("code_id", cdkIDs).Delete()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if cdkRes != nil {
|
||||
result.CdkLogRows, _ = cdkRes.RowsAffected()
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
@@ -291,7 +261,7 @@ func stageReachedByDays(signType, stageDays, totalDays, continuousDays uint32) b
|
||||
|
||||
func (s *SignService) getRecord() (*model.SignInRecord, error) {
|
||||
var out *model.SignInRecord
|
||||
if err := s.dbm(s.Model).Where("sign_in_id", signRecordID).Scan(&out); err != nil {
|
||||
if err := s.dbm(s.Model).Scan(&out); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
@@ -312,7 +282,6 @@ func (s *SignService) getOrInitRecord() (*model.SignInRecord, bool, error) {
|
||||
IsVip: cool.Config.ServerInfo.IsVip,
|
||||
},
|
||||
PlayerID: s.userid,
|
||||
SignInID: signRecordID,
|
||||
IsCompleted: false,
|
||||
ContinuousDays: 0,
|
||||
TotalDays: 0,
|
||||
@@ -324,7 +293,6 @@ func (s *SignService) getOrInitRecord() (*model.SignInRecord, bool, error) {
|
||||
func (s *SignService) saveRecord(record *model.SignInRecord, isNew bool) error {
|
||||
data := map[string]any{
|
||||
"player_id": record.PlayerID,
|
||||
"sign_in_id": record.SignInID,
|
||||
"is_completed": false,
|
||||
"continuous_days": record.ContinuousDays,
|
||||
"total_days": record.TotalDays,
|
||||
@@ -336,7 +304,7 @@ func (s *SignService) saveRecord(record *model.SignInRecord, isNew bool) error {
|
||||
_, err := cool.DBM(s.Model).Data(data).Insert()
|
||||
return err
|
||||
}
|
||||
_, err := s.dbm(s.Model).Where("sign_in_id", signRecordID).Data(data).Update()
|
||||
_, err := s.dbm(s.Model).Data(data).Update()
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user