Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 39s
refactor(service): 修改banner和guild删除逻辑为软删除 fix(service): 修复删除操作使用软删除而非物理删除 build: 添加SQLite测试仓库实现 docs: 新增奖励管理字段拆分和批量抽奖UI改造文档 ci: 更新CI忽略文件 style: 清理无用资源文件
124 lines
4.9 KiB
Go
124 lines
4.9 KiB
Go
package activity
|
|
|
|
import (
|
|
"context"
|
|
"bindbox-game/internal/repository/mysql/dao"
|
|
)
|
|
|
|
// DeleteActivity 删除活动
|
|
// 参数: id 活动ID
|
|
// 返回: 错误信息
|
|
func (s *service) DeleteActivity(ctx context.Context, id int64) error {
|
|
return s.writeDB.Transaction(func(tx *dao.Query) error {
|
|
issues, err := tx.ActivityIssues.WithContext(ctx).Where(tx.ActivityIssues.ActivityID.Eq(id)).Find()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var issueIDs []int64
|
|
for _, is := range issues {
|
|
issueIDs = append(issueIDs, is.ID)
|
|
}
|
|
|
|
var drawLogIDs []int64
|
|
if len(issueIDs) > 0 {
|
|
logs, err := tx.ActivityDrawLogs.WithContext(ctx).Where(tx.ActivityDrawLogs.IssueID.In(issueIDs...)).Find()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, lg := range logs {
|
|
drawLogIDs = append(drawLogIDs, lg.ID)
|
|
}
|
|
}
|
|
|
|
if len(issueIDs) > 0 {
|
|
if _, err = tx.ActivityRewardSettings.WithContext(ctx).Where(tx.ActivityRewardSettings.IssueID.In(issueIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if _, err = tx.IssueRandomCommitments.WithContext(ctx).Where(tx.IssueRandomCommitments.IssueID.In(issueIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if _, err = tx.ActivityDrawEffects.WithContext(ctx).Where(tx.ActivityDrawEffects.IssueID.In(issueIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if len(drawLogIDs) > 0 {
|
|
if _, err = tx.ActivityDrawEffects.WithContext(ctx).Where(tx.ActivityDrawEffects.DrawLogID.In(drawLogIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if _, err = tx.ActivityDrawReceipts.WithContext(ctx).Where(tx.ActivityDrawReceipts.DrawLogID.In(drawLogIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if _, err = tx.UserItemCards.WithContext(ctx).Where(tx.UserItemCards.UsedDrawLogID.In(drawLogIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if _, err = tx.ActivityDrawLogs.WithContext(ctx).Where(tx.ActivityDrawLogs.ID.In(drawLogIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if _, err = tx.ActivityDrawEffects.WithContext(ctx).Where(tx.ActivityDrawEffects.ActivityID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if _, err = tx.UserItemCards.WithContext(ctx).Where(tx.UserItemCards.UsedActivityID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if len(issueIDs) > 0 {
|
|
if _, err = tx.UserItemCards.WithContext(ctx).Where(tx.UserItemCards.UsedIssueID.In(issueIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if _, err = tx.UserInventory.WithContext(ctx).Where(tx.UserInventory.ActivityID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
invs, err := tx.UserInventory.WithContext(ctx).Where(tx.UserInventory.ActivityID.Eq(id)).Find()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
var invIDs []int64
|
|
for _, iv := range invs {
|
|
invIDs = append(invIDs, iv.ID)
|
|
}
|
|
if len(invIDs) > 0 {
|
|
if _, err = tx.ShippingRecords.WithContext(ctx).Where(tx.ShippingRecords.InventoryID.In(invIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if _, err = tx.UserInventoryTransfers.WithContext(ctx).Where(tx.UserInventoryTransfers.InventoryID.In(invIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if _, err = tx.GuildContributeLogs.WithContext(ctx).Where(tx.GuildContributeLogs.ActivityID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if len(issueIDs) > 0 {
|
|
if _, err = tx.GuildContributeLogs.WithContext(ctx).Where(tx.GuildContributeLogs.IssuesID.In(issueIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if _, err = tx.SystemItemCards.WithContext(ctx).Where(tx.SystemItemCards.ActivityID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
if len(issueIDs) > 0 {
|
|
if _, err = tx.SystemItemCards.WithContext(ctx).Where(tx.SystemItemCards.IssueID.In(issueIDs...)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
if _, err = tx.SystemCoupons.WithContext(ctx).Where(tx.SystemCoupons.ActivityID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
|
|
if len(issueIDs) > 0 {
|
|
if _, err = tx.ActivityIssues.WithContext(ctx).Where(tx.ActivityIssues.ActivityID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
if _, err = tx.Activities.WithContext(ctx).Where(tx.Activities.ID.Eq(id)).Delete(); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
})
|
|
}
|