feat: 新增金豆挂单管理模块及优化购买提示
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
22
modules/player/controller/admin/gold_list.go
Normal file
22
modules/player/controller/admin/gold_list.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/service"
|
||||
)
|
||||
|
||||
type GoldListController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
func init() {
|
||||
var task_info_controller = &GoldListController{
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/game/goldlist",
|
||||
Api: []string{"Delete", "Update", "Info", "List", "Page"},
|
||||
Service: service.NewGoldListService(0), //因为page已经过滤,所以这里需要改成0
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(task_info_controller)
|
||||
}
|
||||
44
modules/player/model/gold_list.go
Normal file
44
modules/player/model/gold_list.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
// 表名常量定义:金豆挂单表(金豆↔金币互换)
|
||||
const (
|
||||
TableNameGoldBeanOrder = "player_gold_bean_order" // 金豆挂单表(记录玩家金豆与金币互换的挂单、完成、取消等状态)
|
||||
)
|
||||
|
||||
// GoldBeanOrder 金豆挂单核心模型(与数据库表字段一一对应,存储互换明细)
|
||||
type GoldBeanOrder struct {
|
||||
*cool.Model // 复用通用Model(包含ID、CreatedAt、UpdatedAt等字段)
|
||||
|
||||
PlayerID uint64 `gorm:"not null;index:idx_order_player_id;comment:'所属玩家ID'" json:"player_id" description:"所属玩家ID"`
|
||||
ExchangeNum uint32 `gorm:"not null;default:0;comment:'兑换数量(金豆/金币)'" json:"exchange_num" description:"兑换数量"`
|
||||
Rate uint32 `gorm:"not null;default:0;comment:'兑换汇率(如1金豆=10金币)'" json:"rate" description:"兑换汇率"`
|
||||
}
|
||||
|
||||
// -------------------------- 核心配套方法 --------------------------
|
||||
|
||||
// TableName 指定GoldBeanOrder对应的数据库表名(遵循项目规范)
|
||||
func (*GoldBeanOrder) TableName() string {
|
||||
return TableNameGoldBeanOrder
|
||||
}
|
||||
|
||||
// GroupName 指定表所属分组(与金豆消费表保持一致)
|
||||
func (*GoldBeanOrder) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewGoldBeanOrder 创建金豆挂单记录实例(初始化通用Model及默认值)
|
||||
func NewGoldBeanOrder() *GoldBeanOrder {
|
||||
return &GoldBeanOrder{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------- 表结构自动同步 --------------------------
|
||||
func init() {
|
||||
// 程序启动时自动创建/同步金豆挂单表
|
||||
cool.CreateTable(&GoldBeanOrder{})
|
||||
}
|
||||
44
modules/player/service/gold_list.go
Normal file
44
modules/player/service/gold_list.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/util/gconv"
|
||||
)
|
||||
|
||||
type GoldListService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func (s *GoldListService) ModifyBefore(ctx context.Context, method string, param map[string]interface{}) (err error) {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
userId := admin.UserId
|
||||
s.userid = uint32(userId)
|
||||
|
||||
if method == "Add" {
|
||||
t, _ := s.dbm_fix(s.Model).Count()
|
||||
if t > 0 {
|
||||
return fmt.Errorf("不允许多挂单")
|
||||
}
|
||||
} else {
|
||||
if userId != gconv.Uint(param["player_id"]) {
|
||||
err = fmt.Errorf("修改失败")
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func NewGoldListService(id uint32) *GoldListService {
|
||||
return &GoldListService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewGoldBeanOrder()},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
@@ -105,7 +105,7 @@ func (s *PetService) BuyPet(pid uint32) error {
|
||||
return fmt.Errorf("未设置价格")
|
||||
}
|
||||
if !tt.UpdateTime.AddDate(0, 0, 1).Before(gtime.Now()) {
|
||||
return fmt.Errorf("数据异常")
|
||||
return fmt.Errorf("未到购买时间")
|
||||
}
|
||||
return g.DB().Transaction(context.TODO(), func(ctx context.Context, tx gdb.TX) error {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user