Files
bl/modules/player/controller/admin/gold_list.go
昔念 bd5cd9393a
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
feat(player): 优化金币兑换功能

- 在ServiceUpdate方法中返回更新后的数据而不是nil
- 新增DuihuanGold方法用于处理金币兑换逻辑
- 修改黄金列表控制器中的兑换计算逻辑,区分费用和获得金币的计算
- 在添加操作前验证用户金币余额是否充足
- 修正了兑换比例计算和余额检查逻辑
```
2026-03-19 18:36:34 +08:00

61 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package admin
import (
"blazing/cool"
base "blazing/modules/base/service"
"blazing/modules/player/service"
"context"
"fmt"
"time"
"github.com/gogf/gf/v2/frame/g"
"github.com/gogf/gf/v2/os/gtime"
)
type GoldListController struct {
*cool.Controller
}
func init() {
var task_info_controller = &GoldListController{
&cool.Controller{
Prefix: "/admin/game/goldlist",
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
Service: service.NewGoldListService(0), //因为page已经过滤所以这里需要改成0
},
}
// 注册路由
cool.RegisterController(task_info_controller)
}
type DuihuanGoldAddReq struct {
g.Meta `path:"/duihuan" method:"POST"`
Authorization string `json:"Authorization" in:"header"`
ID uint32 `json:"id"`
}
func (c *GoldListController) DuihuanGold(ctx context.Context, req *DuihuanGoldAddReq) (res *cool.BaseRes, err error) {
t := cool.GetAdmin(ctx)
r, err := service.NewGoldListService(0).Done(req.ID)
if err != nil {
return
}
costfree := r.Rate * float64(r.ExchangeNum)
getgold := 1 / r.Rate * float64(r.ExchangeNum)
if base.NewBaseSysUserService().GetFreeGold(t.UserId) < int64(costfree*100) {
err = fmt.Errorf("余额不足")
return
}
if !r.UpdateTime.Add(1 * time.Hour).Before(gtime.Now()) {
err = fmt.Errorf("未到购买时间")
return
}
base.NewBaseSysUserService().DuihuanFreeGold(uint32(r.PlayerID), int64(r.ExchangeNum*100), int64(costfree*95))
base.NewBaseSysUserService().DuihuanGold(uint32(t.UserId), int64(getgold*95), int64(costfree*100))
res = cool.Ok(nil)
return
}