fix: 修复商品购买和服务相关逻辑问题
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed

This commit is contained in:
xinian
2026-03-27 12:56:29 +08:00
committed by cnb
parent f6745bd2a6
commit 40411ba84b
10 changed files with 27 additions and 147 deletions

View File

@@ -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))
}

View File

@@ -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
}

View File

@@ -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,

View File

@@ -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:"限购类型"`
}
// -------------------------- 核心配套方法(遵循项目规范)--------------------------

View File

@@ -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

View File

@@ -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{})
}

View File

@@ -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"`
}

View File

@@ -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()},
},
}
}

View File

@@ -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)
}

View File

@@ -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),
}
}