uniugm/admin/apps/game/server/ctl_cdkey.go
2025-05-08 15:48:34 +08:00

67 lines
1.9 KiB
Go

package server
import (
"admin/apps/game/model/dto"
"admin/internal/context"
"bytes"
"fmt"
"strings"
)
func (ctl *controller) CDKeyExportFile(ctx *context.WebContext, params *dto.CDKeyExportFileReq, rsp *dto.NilRsp) error {
projectId := getCtxURIProjectId(ctx)
et, keys, err := ctl.svc.GetCDKeyAllKeys(projectId, params.ID)
if err != nil {
return err
}
content := bytes.NewBuffer(nil)
content.WriteString(fmt.Sprintf("礼包码描述:%s\n", et.GetName()))
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")
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 {
projectId := getCtxURIProjectId(ctx)
newCount, err := ctl.svc.CDKeyAddCount(projectId, params.ID, params.AddCount)
if err != nil {
return err
}
rsp.NewCount = newCount
return nil
}
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
}