refactor: 重构战斗属性和特效应用逻辑
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

This commit is contained in:
xinian
2026-04-06 03:11:38 +08:00
committed by cnb
parent a16a06e389
commit 40ec827342
9 changed files with 166 additions and 39 deletions

View File

@@ -53,6 +53,13 @@ type SignClaimResult struct {
Rewards []SignRewardResult `json:"rewards,omitempty"`
}
// SignResetResult 表示管理端执行的签到重置结果。
type SignResetResult struct {
SignRecordRows int64 `json:"sign_record_rows"`
CdkLogRows int64 `json:"cdk_log_rows"`
ResetCdkIDs []uint32 `json:"reset_cdk_ids"`
}
// SignService 管理玩家签到进度。
type SignService struct {
BaseService
@@ -117,6 +124,46 @@ func (s *SignService) Claim() (*SignClaimResult, error) {
}, nil
}
func (s *SignService) ResetAll() (*SignResetResult, error) {
result := &SignResetResult{}
signRes, err := cool.DBM(model.NewSignInRecord()).Delete()
if err != nil {
return nil, err
}
if signRes != nil {
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
}
func (s *SignService) grantReachedStageRewards(record *model.SignInRecord) ([]SignRewardResult, error) {
configs := configservice.NewSignInService().GetEnabled()
if len(configs) == 0 {