```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(player): 优化金币兑换功能

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

View File

@@ -43,8 +43,9 @@ func (c *GoldListController) DuihuanGold(ctx context.Context, req *DuihuanGoldAd
return
}
all := r.Rate * float64(r.ExchangeNum)
if base.NewBaseSysUserService().GetFreeGold(t.UserId) < int64(all*105) {
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
}
@@ -52,8 +53,8 @@ func (c *GoldListController) DuihuanGold(ctx context.Context, req *DuihuanGoldAd
err = fmt.Errorf("未到购买时间")
return
}
base.NewBaseSysUserService().UpdateGold(uint32(r.PlayerID), int64(all*95))
base.NewBaseSysUserService().UpdateFreeGold(uint32(t.UserId), -int64(all*105))
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
}