From bd5cd9393ab5b7d0d4b81925d6782b876171c6cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Thu, 19 Mar 2026 18:36:34 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(player):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E9=87=91=E5=B8=81=E5=85=91=E6=8D=A2=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ServiceUpdate方法中返回更新后的数据而不是nil - 新增DuihuanGold方法用于处理金币兑换逻辑 - 修改黄金列表控制器中的兑换计算逻辑,区分费用和获得金币的计算 - 在添加操作前验证用户金币余额是否充足 - 修正了兑换比例计算和余额检查逻辑 ``` --- common/cool/service.go | 2 +- modules/base/service/base_sys_user.go | 7 +++++++ modules/player/controller/admin/gold_list.go | 9 +++++---- modules/player/service/gold_list.go | 6 +++++- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/common/cool/service.go b/common/cool/service.go index 97f303373..53b75237b 100644 --- a/common/cool/service.go +++ b/common/cool/service.go @@ -169,7 +169,7 @@ func (s *Service) ServiceUpdate(ctx context.Context, req *UpdateReq) (data sql.R } } //rmap["id"] = nil - _, err = m.Data(rmap).Where("id", rmap["id"]).Update() + data, err = m.Data(rmap).Where("id", rmap["id"]).Update() return } diff --git a/modules/base/service/base_sys_user.go b/modules/base/service/base_sys_user.go index d8c6979c8..e48b852d8 100644 --- a/modules/base/service/base_sys_user.go +++ b/modules/base/service/base_sys_user.go @@ -60,7 +60,14 @@ func (s *BaseSysUserService) DuihuanFreeGold(userId uint32, gold, free int64) { }).Update() } +func (s *BaseSysUserService) DuihuanGold(userId uint32, gold, free int64) { + m := cool.DBM(s.Model).Where("id", userId) + m.Data(g.Map{ + "goldbean": gdb.Raw("goldbean+" + gconv.String(gold)), + "free_gold": gdb.Raw("free_gold-" + gconv.String(free)), + }).Update() +} func (s *BaseSysUserService) UpdateFreeGold(userId uint32, gold int64) { m := cool.DBM(s.Model).Where("id", userId) diff --git a/modules/player/controller/admin/gold_list.go b/modules/player/controller/admin/gold_list.go index 797fb0b34..5671c6ba0 100644 --- a/modules/player/controller/admin/gold_list.go +++ b/modules/player/controller/admin/gold_list.go @@ -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 } diff --git a/modules/player/service/gold_list.go b/modules/player/service/gold_list.go index 8718399d5..b48445a74 100644 --- a/modules/player/service/gold_list.go +++ b/modules/player/service/gold_list.go @@ -2,11 +2,13 @@ package service import ( "blazing/cool" + "blazing/modules/base/service" "blazing/modules/player/model" "context" "fmt" "github.com/gogf/gf/v2/frame/g" + "github.com/gogf/gf/v2/util/gconv" ) type GoldListService struct { @@ -17,8 +19,10 @@ func (s *GoldListService) ModifyBefore(ctx context.Context, method string, param admin := cool.GetAdmin(ctx) userId := admin.UserId - g.RequestFromCtx(ctx).SetParam("player_id", userId) if method == "Add" { + if service.NewBaseSysUserService().GetGold(userId) < gconv.Int64(param["exchange_num"])*100 { + return fmt.Errorf("金额不足") + } t, _ := s.dbm_fix(s.Model).Where("player_id", userId).Where("status", 0).Count() if t > 0 {