2025-05-07 18:25:31 +08:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
|
|
|
"admin/apps/game/model/dto"
|
|
|
|
"admin/internal/context"
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
2025-05-08 15:48:34 +08:00
|
|
|
"strings"
|
2025-05-07 18:25:31 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func (ctl *controller) CDKeyExportFile(ctx *context.WebContext, params *dto.CDKeyExportFileReq, rsp *dto.NilRsp) error {
|
2025-05-08 15:48:34 +08:00
|
|
|
projectId := getCtxURIProjectId(ctx)
|
|
|
|
|
|
|
|
et, keys, err := ctl.svc.GetCDKeyAllKeys(projectId, params.ID)
|
2025-05-07 18:25:31 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
content := bytes.NewBuffer(nil)
|
|
|
|
content.WriteString(fmt.Sprintf("礼包码描述:%s\n", et.GetName()))
|
2025-05-08 15:48:34 +08:00
|
|
|
content.WriteString(fmt.Sprintf("礼包码数量:%v\n", et.GetCount()))
|
|
|
|
var itemStr = make([]string, 0, len(et.Po.Attach))
|
|
|
|
for _, item := range et.Po.Attach {
|
|
|
|
itemStr = append(itemStr, fmt.Sprintf("%v*%v", item.Desc, item.Num))
|
|
|
|
}
|
|
|
|
content.WriteString(fmt.Sprintf("礼包码道具:%v\n", strings.Join(itemStr, ",")))
|
|
|
|
|
|
|
|
content.WriteString("\n")
|
2025-05-07 18:25:31 +08:00
|
|
|
content.WriteString(fmt.Sprintf("礼包码列表:\n"))
|
|
|
|
for _, key := range keys {
|
|
|
|
content.WriteString(fmt.Sprintf("%s\n", key))
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx.OkFile(fmt.Sprintf("礼包码(%v-%v个).txt", et.GetName(), et.GetCount()), content.String())
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctl *controller) CDKeyAddCount(ctx *context.WebContext, params *dto.CDKeyAddCountReq, rsp *dto.CDKeyAddCountRsp) error {
|
2025-05-08 15:48:34 +08:00
|
|
|
projectId := getCtxURIProjectId(ctx)
|
|
|
|
newCount, err := ctl.svc.CDKeyAddCount(projectId, params.ID, params.AddCount)
|
2025-05-07 18:25:31 +08:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rsp.NewCount = newCount
|
|
|
|
return nil
|
|
|
|
}
|
2025-05-08 15:48:34 +08:00
|
|
|
|
|
|
|
func (ctl *controller) CDKeyUse(ctx *context.WebContext, params *dto.CDKeyUseReq, rsp *dto.CDKeyUseRsp) error {
|
|
|
|
batchInfo, err := ctl.svc.CDKeyUse(params)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rsp.RewardItems = batchInfo.RewardItemsView()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ctl *controller) CDKeyUsedHistory(ctx *context.WebContext, params *dto.CDKeyUsedHistoryReq, rsp *dto.CDKeyUsedHistoryRsp) error {
|
|
|
|
projectId := getCtxURIProjectId(ctx)
|
|
|
|
list, err := ctl.svc.CDKeyUsedHistoryList(projectId, params.ID)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
rsp.List = list
|
|
|
|
return nil
|
|
|
|
}
|