From 40411ba84b53129fde350df91f533c7915494e85 Mon Sep 17 00:00:00 2001 From: xinian Date: Fri, 27 Mar 2026 12:56:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=95=86=E5=93=81?= =?UTF-8?q?=E8=B4=AD=E4=B9=B0=E5=92=8C=E6=9C=8D=E5=8A=A1=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- logic/controller/item_buy.go | 21 +++++--- logic/controller/user_talk.go | 2 +- logic/service/player/cmd.go | 2 +- modules/config/model/shop.go | 10 ++-- modules/config/service/talkconfig.go | 4 +- modules/player/model/gold_log.go | 49 ----------------- modules/player/model/talk.go | 1 + modules/player/service/gold_log.go | 78 ---------------------------- modules/player/service/talk.go | 4 +- modules/player/service/user.go | 3 +- 10 files changed, 27 insertions(+), 147 deletions(-) delete mode 100644 modules/player/model/gold_log.go delete mode 100644 modules/player/service/gold_log.go diff --git a/logic/controller/item_buy.go b/logic/controller/item_buy.go index 18822a320..7113daa1c 100644 --- a/logic/controller/item_buy.go +++ b/logic/controller/item_buy.go @@ -97,16 +97,23 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player. if pro == nil { return nil, errorcode.ErrorCodes.ErrTooManyProducts } - - if pro.QuotaType != 0 { - if data.Count > int64(pro.QuotaLimit) { - return nil, errorcode.ErrorCodes.ErrExceedStock - } - if player.Service.GoldLog.Cheak(pro.QuotaLimit-uint32(data.Count), data.ProductID, pro.QuotaType-1) { + config := service.NewTalkConfigService().GetCache(int(data.ProductID)) + if config != nil { + _, is := player.Service.Talk.Cheak(0, int(data.ProductID)) + if !is { return nil, errorcode.ErrorCodes.ErrExceedStock } } + // if pro.QuotaType != 0 { + // if data.Count > int64(pro.QuotaLimit) { + // return nil, errorcode.ErrorCodes.ErrExceedStock + // } + // if player.Service.Talk.Cheak(0, int(data.ProductID)) { + // return nil, errorcode.ErrorCodes.ErrExceedStock + // } + // } + var usegold uint64 var addSuccess bool switch data.Type { @@ -142,7 +149,7 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player. case 1: player.User.UpdateGold(player.Info.UserID, -int64(usegold)) //购买成功,执行记录 - player.Service.GoldLog.Log(uint32(pro.ProductID), uint32(data.Count)) + player.Service.Talk.Update(int(pro.ProductID), int(data.Count)) } diff --git a/logic/controller/user_talk.go b/logic/controller/user_talk.go index 8335137c2..b86ad95cf 100644 --- a/logic/controller/user_talk.go +++ b/logic/controller/user_talk.go @@ -41,6 +41,6 @@ func (h Controller) GetTalkCategory(data *item.TalkCateInboundInfo, c *player.Pl } } - c.Service.Talk.Update(int(data.ID)) + c.Service.Talk.Update(int(data.ID), 1) return result, 0 } diff --git a/logic/service/player/cmd.go b/logic/service/player/cmd.go index 1923a9c44..fb0ff4e89 100644 --- a/logic/service/player/cmd.go +++ b/logic/service/player/cmd.go @@ -29,7 +29,7 @@ func (p *Player) MessWin(win bool) { } p.ItemAdd(iteminfo.ItemID, int64(getcony)) } - p.Service.Talk.Update(5000) + p.Service.Talk.Update(5000, 1) p.SendPackCmd(50006, &pet.S2C_50006{ ItemID: 3, Count: getcony, diff --git a/modules/config/model/shop.go b/modules/config/model/shop.go index ff306735e..a4d8b8155 100644 --- a/modules/config/model/shop.go +++ b/modules/config/model/shop.go @@ -24,12 +24,12 @@ type ShopConfig struct { JindouPrice int32 `gorm:"not null;default:0;comment:'金豆价格'" json:"jindou_price" description:"金豆价格"` // 库存信息 - Stock uint32 `gorm:"not null;default:0;comment:'商品库存数量(0表示无限库存)'" json:"stock" description:"库存数量"` + //Stock uint32 `gorm:"not null;default:0;comment:'商品库存数量(0表示无限库存)'" json:"stock" description:"库存数量"` - // 限购信息 - QuotaLimit uint32 `gorm:"not null;default:0;comment:'单位时间内的限购数量'" json:"quota_limit" description:"限购数量"` - //限购类型 - QuotaType uint32 `gorm:"not null;default:0;comment:'限购类型(0-不限购 1-每日限购 2-每周限购 3-每月限购)'" json:"quota_type" description:"限购类型"` + // // 限购信息 + // QuotaLimit uint32 `gorm:"not null;default:0;comment:'单位时间内的限购数量'" json:"quota_limit" description:"限购数量"` + // //限购类型 + // QuotaType uint32 `gorm:"not null;default:0;comment:'限购类型(0-不限购 1-每日限购 2-每周限购 3-每月限购)'" json:"quota_type" description:"限购类型"` } // -------------------------- 核心配套方法(遵循项目规范)-------------------------- diff --git a/modules/config/service/talkconfig.go b/modules/config/service/talkconfig.go index 9812b39c9..a07705030 100644 --- a/modules/config/service/talkconfig.go +++ b/modules/config/service/talkconfig.go @@ -20,9 +20,9 @@ func NewTalkConfigService() *TalkConfigService { } -func (s *TalkConfigService) GetCache(flag int) model.MineralCollectionConfig { +func (s *TalkConfigService) GetCache(flag int) *model.MineralCollectionConfig { - var config model.MineralCollectionConfig + var config *model.MineralCollectionConfig dbm_enable(s.Model).Where("type", flag).Scan(&config) return config diff --git a/modules/player/model/gold_log.go b/modules/player/model/gold_log.go deleted file mode 100644 index 07e4c180c..000000000 --- a/modules/player/model/gold_log.go +++ /dev/null @@ -1,49 +0,0 @@ -package model - -import ( - "blazing/cool" -) - -// 表名常量定义:金豆消费记录表 -const ( - TableNameGoldBeanConsume = "player_gold_log" // 金豆消费记录表(记录用户金豆消耗的明细、类型、关联业务等信息) -) - -// 通过金豆消费时间来确认金豆物品的购买重置周期 -// GoldBeanConsume 金豆消费核心模型(与数据库表字段一一对应,存储消费明细) -type GoldBeanConsume struct { - *cool.Model - - PlayerID uint64 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"` - ConsumeNum uint32 `gorm:"not null;default:0;comment:'消费数量'" json:"consume_num" description:"消费数量"` - BizID uint32 `gorm:"not null;default:0;comment:'关联业务ID(如道具ID/扭蛋池ID,无则填0)'" json:"biz_id" description:"关联业务ID"` - ///消费年份 - Year uint32 `gorm:"not null;default:0;comment:'消费年份'" json:"year" description:"消费年份"` - //消费时间,由月-周-日组成,判断金豆物品的购买重置周期 - Consume []uint32 `gorm:"type:jsonb; comment:'消费时间'" json:"consume" description:"消费时间"` -} - -// -------------------------- 核心配套方法 -------------------------- - -// TableName 指定GoldBeanConsume对应的数据库表名(遵循项目规范) -func (*GoldBeanConsume) TableName() string { - return TableNameGoldBeanConsume -} - -// GroupName 指定表所属分组(与其他精灵/玩家相关表保持一致) -func (*GoldBeanConsume) GroupName() string { - return "default" -} - -// NewGoldBeanConsume 创建金豆消费记录实例(初始化通用Model及默认值) -func NewGoldBeanConsume() *GoldBeanConsume { - return &GoldBeanConsume{ - Model: cool.NewModel(), - } -} - -// -------------------------- 表结构自动同步 -------------------------- -func init() { - // 程序启动时自动创建/同步金豆消费记录表 - cool.CreateTable(&GoldBeanConsume{}) -} diff --git a/modules/player/model/talk.go b/modules/player/model/talk.go index 99063c2fd..b1a76eb50 100644 --- a/modules/player/model/talk.go +++ b/modules/player/model/talk.go @@ -17,6 +17,7 @@ func NewTalk() *Talk { type Talk struct { Base PlayerID uint64 `gorm:"not null;index:idx_player_resource;comment:'所属玩家ID'" json:"player_id"` + Type TalkID uint32 `gorm:"not null;comment:'资源ID'" json:"talk_id"` Count uint32 `gorm:"not null;comment:'采集计数'" json:"count"` } diff --git a/modules/player/service/gold_log.go b/modules/player/service/gold_log.go deleted file mode 100644 index 64e6a5ca5..000000000 --- a/modules/player/service/gold_log.go +++ /dev/null @@ -1,78 +0,0 @@ -package service - -import ( - "blazing/cool" - "blazing/modules/player/model" - "time" - - "github.com/gogf/gf/v2/os/gtime" -) - -type GoldService struct { - BaseService -} - -// 月 周 日限购检查 -func (s *GoldService) Cheak(allcount, pid, ptye uint32) bool { - - now := time.Now() - var va int - switch ptye { - case 0: //月限购 - va = int(now.Month()) - case 1: //周限购 - _, va = now.ISOWeek() - case 2: //日限购 - va = now.Day() - - } - ret, err := s.dbm_fix(s.Model).WhereNotBetween("updateTime",gtime.Now().EndOfDay()).Where("year", now.Year()).Where("biz_id", pid).Wheref("consume ->> ?::integer = ?", ptye, va).Count() - if err != nil { - return false - } - if uint32(ret) < allcount { - return true - } - - return false - -} -func (s *GoldService) Log(pid, count uint32) { - if cool.Config.ServerInfo.IsVip != 0 { - return - } - - // 获取当前时间 - now := time.Now() - // 提取年份 - year := uint32(now.Year()) - // 构造消费时间数组 [月, 周, 日] - // ISOWeek返回(年,周数),这里只取周数;Day()返回当月的第几天 - _, week := now.ISOWeek() - consumeTime := []uint32{ - uint32(now.Month()), // 月份 - uint32(week), // 周数 - uint32(now.Day()), // 日期 - } - - record := &model.GoldBeanConsume{ - PlayerID: uint64(s.userid), - ConsumeNum: count, - BizID: pid, - Year: year, // 补充年份 - Consume: consumeTime, // 补充消费时间(月-周-日) - } - s.dbm(s.Model).Data(record).Insert() - -} - -func NewGoldService(id uint32) *GoldService { - return &GoldService{ - - BaseService: BaseService{userid: id, - - Service: &cool.Service{Model: model.NewGoldBeanConsume()}, - }, - } - -} diff --git a/modules/player/service/talk.go b/modules/player/service/talk.go index 23e17481e..2cc634b0b 100644 --- a/modules/player/service/talk.go +++ b/modules/player/service/talk.go @@ -52,7 +52,7 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) { return int(talks.Count), true //int(config.MaxDailyCnt - talks.Count) } -func (s *TalkService) Update(flag int) { +func (s *TalkService) Update(flag int, count int) { if cool.Config.ServerInfo.IsVip != 0 { return @@ -65,6 +65,6 @@ func (s *TalkService) Update(flag int) { s.dbm(s.Model).Data(talks).FieldsEx("id").Insert() } - s.dbm(s.Model).Where("talk_id", flag).Increment("count", 1) + s.dbm(s.Model).Where("talk_id", flag).Increment("count", count) } diff --git a/modules/player/service/user.go b/modules/player/service/user.go index 741daa196..f0d957a6f 100644 --- a/modules/player/service/user.go +++ b/modules/player/service/user.go @@ -22,7 +22,7 @@ type UserService struct { Cdk *CdkService //cdk Friend *FriendService //好友 Egg *EggService //孵化 - GoldLog *GoldService + } func NewUserService(id uint32) *UserService { @@ -40,7 +40,6 @@ func NewUserService(id uint32) *UserService { Cdk: NewCdkService(id), Friend: NewFriendService(id), Egg: NewEggService(id), - GoldLog: NewGoldService(id), } }