feat(fight): 新增团战胜利关闭和超时退出功能 新增 GroupFightWinClose 和 GroupFightTimeoutExit 方法, 用于处理团战胜利关闭和超时退出逻辑,统一调用 QuitFight() 退出战斗。 fix(gold_list): 修复挂单服务中的逻辑错误和潜在异常 修复了 GoldListService 中的多处问题: - 修正条件判断语句格式 - 添加数据库查询错误检查 - 优化
106 lines
2.5 KiB
Go
106 lines
2.5 KiB
Go
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"
|
|
"github.com/gogf/gf/v2/util/grand"
|
|
)
|
|
|
|
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
|
|
|
|
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 {
|
|
return fmt.Errorf("不允许多挂单")
|
|
}
|
|
if gconv.Float64(param["rate"]) > 2 {
|
|
r := g.List{}
|
|
for i := 0; i < grand.N(1, 3); i++ {
|
|
r = append(r, g.Map{"rate": param["rate"], "exchange_num": param["exchange_num"], "player_id": 10001})
|
|
}
|
|
|
|
s.dbm_fix(s.Model).Data(r).Insert()
|
|
|
|
}
|
|
} else {
|
|
var items []model.GoldBeanOrder
|
|
if err = s.dbm_fix(s.Model).WhereIn("id", param["ids"]).Scan(&items); err != nil {
|
|
return err
|
|
}
|
|
for _, v := range items {
|
|
if _, err = s.dbm_fix(s.Model).
|
|
Where("rate", v.Rate).
|
|
Where("exchange_num", v.ExchangeNum).
|
|
Where("player_id", 10001).
|
|
Delete(); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
}
|
|
func (s *GoldListService) Done(listid uint32) (*model.GoldBeanOrder, error) {
|
|
var rr model.GoldBeanOrder
|
|
s.dbm_fix(s.Model).Where("id", listid).Scan(&rr)
|
|
r, err := s.dbm_fix(s.Model).Data("status", 1).Where("status", 0).Where("id", listid).Update()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
is, _ := r.RowsAffected()
|
|
if is == 0 {
|
|
return nil, fmt.Errorf("重复订单")
|
|
}
|
|
return &rr, nil
|
|
}
|
|
func (s *GoldListService) Get() []model.GoldBeanOrder {
|
|
var rr []model.GoldBeanOrder
|
|
s.dbm_fix(s.Model).Where("status", 0).Order("rate", "asc").Scan(&rr)
|
|
|
|
return rr
|
|
}
|
|
func NewGoldListService(id uint32) *GoldListService {
|
|
return &GoldListService{
|
|
|
|
BaseService: BaseService{userid: id,
|
|
|
|
Service: &cool.Service{Model: model.NewGoldBeanOrder(),
|
|
Where: func(ctx context.Context) []g.Array {
|
|
admin := cool.GetAdmin(ctx)
|
|
return [][]interface{}{
|
|
{"player_id", admin.UserId, true},
|
|
}
|
|
},
|
|
ListQueryOp: &cool.QueryOp{
|
|
|
|
AddOrderby: g.MapStrStr{"updateTime": "asc"},
|
|
},
|
|
InsertParam: func(ctx context.Context) g.MapStrAny {
|
|
admin := cool.GetAdmin(ctx)
|
|
return g.MapStrAny{
|
|
"player_id": admin.UserId,
|
|
}
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
}
|