feat: 添加金豆消费记录功能
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

添加金豆消费记录表和相关服务,用于记录用户金豆消耗明细
在购买逻辑中预留记录消费的注释位置
This commit is contained in:
xinian
2026-02-23 07:47:06 +08:00
committed by cnb
parent 84768e3406
commit 75cfc7bcb1
5 changed files with 27 additions and 13 deletions

View File

@@ -131,6 +131,7 @@ func (h Controller) BuyGoldItem(data *item.C2S_GOLD_BUY_PRODUCT, player *player.
case 1:
player.User.UpdateGold(player.Info.UserID, -int64(usegold))
//购买成功,执行记录
}

View File

@@ -55,12 +55,6 @@ func (s *BaseSysUserService) SetdepartmentId(userId, departmentId uint32) (res *
// 单位是分
func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) {
// updateData := g.Map{
// "views": &gdb.Counter{
// Field: "goldbean",
// Value: 1,
// },
// }
if cool.Config.ServerInfo.IsVip != 0 {
cool.Logger.Info(context.TODO(), "测试服不操作金币")
@@ -68,10 +62,6 @@ func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) {
}
m := cool.DBM(s.Model).Where("id", userId)
m.Increment("goldbean", gold)
// // UPDATE `article` SET `views`=`views`+1 WHERE `id`=1
// result, err := db.Update("article", updateData, "id", 1)
//res.GoldBean, _ = alpacadecimal.NewFromFloat(float64(gold)).Div(alpacadecimal.NewFromFloat(100)).Float64()
}
func (s *BaseSysUserService) GetGold(userId uint) (res int64) {

View File

@@ -12,9 +12,9 @@ const (
// 通过金豆消费时间来确认金豆物品的购买重置周期
// GoldBeanConsume 金豆消费核心模型(与数据库表字段一一对应,存储消费明细)
type GoldBeanConsume struct {
Base
*cool.Model
UID uint32 `gorm:"not null;default:0;index;comment:'玩家唯一ID关联玩家表主键'" json:"uid" description:"玩家ID"`
PlayerID uint64 `gorm:"not null;uniqueIndex;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"`
///消费年份
@@ -40,7 +40,7 @@ func (*GoldBeanConsume) GroupName() string {
// NewGoldBeanConsume 创建金豆消费记录实例初始化通用Model及默认值
func NewGoldBeanConsume() *GoldBeanConsume {
return &GoldBeanConsume{
Base: *NewBase(),
Model: cool.NewModel(),
}
}

View File

@@ -0,0 +1,21 @@
package service
import (
"blazing/cool"
"blazing/modules/player/model"
)
type GoldService struct {
BaseService
}
func NewGoldService(id uint32) *GoldService {
return &GoldService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewGoldBeanConsume()},
},
}
}

View File

@@ -22,6 +22,7 @@ type UserService struct {
Cdk *CdkService //cdk
Friend *FriendService //好友
Egg *EggService //孵化
GoldLog *GoldService
}
func NewUserService(id uint32) *UserService {
@@ -39,6 +40,7 @@ func NewUserService(id uint32) *UserService {
Cdk: NewCdkService(id),
Friend: NewFriendService(id),
Egg: NewEggService(id),
GoldLog: NewGoldService(id),
}
}