feat(service): 宠物添加功能增加销售计数参数并优化价格更新逻辑 - 修改PetAdd方法签名,增加salecount参数用于追踪宠物销售次数 - 在多个控制器中统一调用PetAdd方法时传入0作为初始销售次数 - 临时禁用寒流枪活动中的宠物发放功能 - 优化UPdatePrice方法,添加错误处理和价格范围验证逻辑 - 调整宠物购买逻辑,使用免费金币系统并计算递增购买
This commit is contained in:
@@ -68,7 +68,7 @@ func (h Controller) DASHIbeiR(data *C2s_MASTER_REWARDSR, c *player.Player) (resu
|
||||
|
||||
if taskInfo.Pet != nil {
|
||||
|
||||
c.Service.Pet.PetAdd(taskInfo.Pet)
|
||||
c.Service.Pet.PetAdd(taskInfo.Pet, 0)
|
||||
result.CaptureTime = taskInfo.Pet.CatchTime
|
||||
result.PetTypeId = taskInfo.Pet.ID
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ func (h Controller) EggGamePlay(data1 *C2S_EGG_GAME_PLAY, c *player.Player) (res
|
||||
newPet.RandomByWeightShiny()
|
||||
}
|
||||
|
||||
c.Service.Pet.PetAdd(newPet)
|
||||
c.Service.Pet.PetAdd(newPet, 0)
|
||||
|
||||
result.HadTime = newPet.CatchTime
|
||||
result.PetID = newPet.ID
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"blazing/logic/service/common"
|
||||
"blazing/logic/service/fight"
|
||||
"blazing/logic/service/player"
|
||||
"blazing/modules/player/model"
|
||||
)
|
||||
|
||||
// CatchPet 传送仓抓稀有宠物
|
||||
@@ -24,15 +23,15 @@ func (h Controller) HanLiuQiang(data *C2S_2608, c *player.Player) (result *fight
|
||||
}
|
||||
c.ItemAdd(500655, 1)
|
||||
|
||||
pet := model.GenPetInfo(426, 31, -1, -1, 100, nil, 0)
|
||||
// pet := model.GenPetInfo(426, 31, -1, -1, 100, nil, 0)
|
||||
|
||||
c.Service.Pet.PetAdd(pet)
|
||||
pet = model.GenPetInfo(1567, 31, -1, -1, 100, nil, 0)
|
||||
// c.Service.Pet.PetAdd(pet, 0)
|
||||
// pet = model.GenPetInfo(1567, 31, -1, -1, 100, nil, 0)
|
||||
|
||||
c.Service.Pet.PetAdd(pet)
|
||||
pet = model.GenPetInfo(1905, 31, -1, -1, 100, nil, 0)
|
||||
// c.Service.Pet.PetAdd(pet)
|
||||
// pet = model.GenPetInfo(1905, 31, -1, -1, 100, nil, 0)
|
||||
|
||||
c.Service.Pet.PetAdd(pet)
|
||||
// c.Service.Pet.PetAdd(pet)
|
||||
return result, -1
|
||||
}
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ func (h Controller) PetFusion(data *pet.C2S_PetFusion, c *player.Player) (result
|
||||
r.RandomByWeightShiny()
|
||||
|
||||
}
|
||||
c.Service.Pet.PetAdd(r)
|
||||
c.Service.Pet.PetAdd(r, 0)
|
||||
println(c.Info.UserID, "进行融合", len(c.Info.PetList), Mcatchpetinfo.ID, Auxpetinfo.ID, r.ID)
|
||||
|
||||
c.PetDel(data.Mcatchtime)
|
||||
|
||||
@@ -86,7 +86,7 @@ func (h Controller) Collect(
|
||||
r.Set(uint(data.Type))
|
||||
te.Data = r.Bytes()
|
||||
r := model.GenPetInfo(int(data.ID), -1, -1, 0, 1, nil, 0)
|
||||
c.Service.Pet.PetAdd(r)
|
||||
c.Service.Pet.PetAdd(r, 0)
|
||||
result.CatchTime = r.CatchTime
|
||||
|
||||
return true
|
||||
|
||||
@@ -185,7 +185,7 @@ func (ctl Controller) GetHatchPet(
|
||||
if r == nil {
|
||||
return nil, errorcode.ErrorCodes.ErrSystemError
|
||||
}
|
||||
playerObj.Service.Pet.PetAdd(r)
|
||||
playerObj.Service.Pet.PetAdd(r, 0)
|
||||
|
||||
result.PetID = r.ID
|
||||
result.CatchTime = r.CatchTime
|
||||
|
||||
@@ -35,7 +35,7 @@ func (h Controller) CDK(data *user.C2S_GET_GIFT_COMPLETE, player *player.Player)
|
||||
pet := service.NewPetRewardService().Get(v)
|
||||
if pet != nil {
|
||||
peti := model.GenPetInfo(int(pet.MonID), int(pet.DV), int(pet.Nature), int(pet.Effect), int(pet.Lv), nil, 0)
|
||||
player.Service.Pet.PetAdd(peti)
|
||||
player.Service.Pet.PetAdd(peti, 0)
|
||||
result.PetGift = append(result.PetGift, user.PetGiftInfo{PetID: peti.ID, CacthTime: peti.CatchTime})
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ func (h Controller) CompleteTask(data1 *task.CompleteTaskInboundInfo, c *player.
|
||||
|
||||
if taskInfo.Pet != nil {
|
||||
|
||||
c.Service.Pet.PetAdd(taskInfo.Pet)
|
||||
c.Service.Pet.PetAdd(taskInfo.Pet, 0)
|
||||
result.CaptureTime = taskInfo.Pet.CatchTime
|
||||
result.PetTypeId = taskInfo.Pet.ID
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ func (f *FightC) battleLoop() {
|
||||
f.WinnerId = f.ownerID
|
||||
|
||||
addpet.EffectInfo = nil //清空特性信息
|
||||
f.Our.Player.(*player.Player).Service.Pet.PetAdd(&addpet)
|
||||
f.Our.Player.(*player.Player).Service.Pet.PetAdd(&addpet, 0)
|
||||
|
||||
f.Our.Player.SendPackCmd(2409, &info.CatchMonsterOutboundInfo{
|
||||
CatchTime: uint32(addpet.CatchTime),
|
||||
|
||||
@@ -47,7 +47,7 @@ func (p *Player) TawerCompletedTask(taskID int, ot int) {
|
||||
return
|
||||
}
|
||||
// 处理默认分支(ot=-1):仅奖励存在时才完成主任务
|
||||
if p.Info.GetTask(taskID) != model.Completed {
|
||||
if p.Info.GetTask(taskID) != model.Completed {
|
||||
defaultGift := p.getTaskGift(taskID, -1)
|
||||
if defaultGift != nil { // 奖励存在才标记主任务完成
|
||||
p.Info.SetTask(taskID, model.Completed)
|
||||
@@ -94,7 +94,7 @@ func (p *Player) bossgive(taskID int, ot int) {
|
||||
|
||||
// 发放宠物奖励
|
||||
if gift.Pet != nil {
|
||||
p.Service.Pet.PetAdd(gift.Pet)
|
||||
p.Service.Pet.PetAdd(gift.Pet, 0)
|
||||
res.PetID = gift.Pet.ID
|
||||
res.CaptureTm = gift.Pet.CatchTime
|
||||
}
|
||||
|
||||
@@ -168,3 +168,22 @@ func (c *BaseSysUserController) GoldAdd(ctx context.Context, req *UserGoldAddReq
|
||||
res = cool.Ok(nil)
|
||||
return
|
||||
}
|
||||
|
||||
type DuihuanGoldAddReq struct {
|
||||
g.Meta `path:"/duihuan" method:"POST"`
|
||||
Authorization string `json:"Authorization" in:"header"`
|
||||
|
||||
Gold float32 `json:"gold"`
|
||||
}
|
||||
|
||||
func (c *BaseSysUserController) DuihuanGold(ctx context.Context, req *DuihuanGoldAddReq) (res *cool.BaseRes, err error) {
|
||||
t := cool.GetAdmin(ctx)
|
||||
|
||||
if service.NewBaseSysUserService().GetGold(t.UserId) < int64(req.Gold*100) {
|
||||
res = cool.Fail("余额不足")
|
||||
return
|
||||
}
|
||||
service.NewBaseSysUserService().DuihuanFreeGold(uint32(t.UserId), int64(req.Gold*100))
|
||||
res = cool.Ok(nil)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -20,7 +20,8 @@ type BaseSysUser struct {
|
||||
Email *string `gorm:"column:email;type:varchar(255)" json:"email"` // 邮箱
|
||||
Status *int32 `gorm:"column:status;not null;default:1" json:"status"` // 状态 0:禁用 1:启用
|
||||
GoldBean int64 `gorm:"column:goldbean;type:bigint;default:0" json:"goldbean"`
|
||||
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
|
||||
FreeGold int64 `gorm:"column:free_gold;type:bigint;default:0" json:"free_gold"` //集市金豆
|
||||
Remark *string `gorm:"column:remark;type:varchar(255)" json:"remark"` // 备注
|
||||
//Debug int32 `gorm:"column:debug;type:int;not null;default:0" json:"debug"` // 是否可以进入2服 测试服
|
||||
Maxts uint32 `gorm:"column:max_ts;type:int;not null;default:0" json:"max_ts"` //最后生成的时间记录表
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import (
|
||||
|
||||
"blazing/modules/base/model"
|
||||
|
||||
"github.com/alpacahq/alpacadecimal"
|
||||
"github.com/gogf/gf/v2/container/garray"
|
||||
"github.com/gogf/gf/v2/container/gset"
|
||||
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||
@@ -52,6 +51,20 @@ func (s *BaseSysUserService) SetdepartmentId(userId, departmentId uint32) (res *
|
||||
|
||||
return
|
||||
}
|
||||
func (s *BaseSysUserService) DuihuanFreeGold(userId uint32, free int64) {
|
||||
m := cool.DBM(s.Model).Where("id", userId)
|
||||
m.Data(g.Map{
|
||||
"goldbean": gdb.Raw("goldbean-" + gconv.String(free)),
|
||||
"free_gold": gdb.Raw("free_gold+" + gconv.String(free)),
|
||||
}).Update()
|
||||
|
||||
}
|
||||
func (s *BaseSysUserService) UpdateFreeGold(userId uint32, gold int64) {
|
||||
|
||||
m := cool.DBM(s.Model).Where("id", userId)
|
||||
m.Increment("free_gold", gold)
|
||||
|
||||
}
|
||||
|
||||
// 单位是分
|
||||
func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) {
|
||||
@@ -67,10 +80,16 @@ func (s *BaseSysUserService) UpdateGold(userId uint32, gold int64) {
|
||||
func (s *BaseSysUserService) GetGold(userId uint) (res int64) {
|
||||
var res1 model.BaseSysUser
|
||||
m := cool.DBM(s.Model)
|
||||
m.Where("id", userId).FieldsEx("password").Scan(&res1)
|
||||
m.Where("id", userId).Fields("goldbean").Scan(&res1)
|
||||
|
||||
r1 := alpacadecimal.NewFromInt(res1.GoldBean)
|
||||
return r1.IntPart()
|
||||
return res1.GoldBean
|
||||
}
|
||||
func (s *BaseSysUserService) GetFreeGold(userId uint) (res int64) {
|
||||
var res1 model.BaseSysUser
|
||||
m := cool.DBM(s.Model)
|
||||
m.Where("id", userId).Fields("free_gold").Scan(&res1)
|
||||
|
||||
return res1.GoldBean
|
||||
}
|
||||
func (s *BaseSysUserService) GetEamil(userId string) (res *model.BaseSysUser) {
|
||||
m := cool.DBM(s.Model)
|
||||
|
||||
@@ -49,7 +49,7 @@ func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res
|
||||
req.PetTypeId, req.IndividualValue, req.NatureId, req.AbilityTypeEnum, req.Level, shiny, -1)
|
||||
t.CatchRect = 1 //代表这是人工合成的
|
||||
|
||||
service.NewUserService(uint32(req.UserID)).Pet.PetAdd(t)
|
||||
service.NewUserService(uint32(req.UserID)).Pet.PetAdd(t, 0)
|
||||
return
|
||||
|
||||
}
|
||||
@@ -98,7 +98,7 @@ func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *co
|
||||
if req.Price < 5 {
|
||||
req.Price = 5
|
||||
}
|
||||
service.NewPetService(uint32(admin.UserId)).UPdatePrice(req.Ctime, req.Price, req.IsSale)
|
||||
err = service.NewPetService(uint32(admin.UserId)).UPdatePrice(req.Ctime, req.Price, req.IsSale)
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ type Pet struct {
|
||||
CatchTime uint32 `gorm:"not null;comment:'捕捉时间'" json:"catch_time"` //唯一键
|
||||
IsSale int `gorm:"not null;default:0;comment:'是否出售'" json:"is_sale"`
|
||||
SalePrice uint32 `gorm:"not null;default:0;comment:'出售价格'" json:"sale_price"`
|
||||
SaleCount uint32 `gorm:"not null;default:0;comment:'出售次数'" json:"sale_count"`
|
||||
// Owner uint32 `struc:"skip"` //仅作为存储
|
||||
// FreedTime uint32 `struc:"skip"` //放生时间
|
||||
//是否可交易,这里应该定义在精灵ID里
|
||||
|
||||
@@ -19,10 +19,7 @@ func (s *ItemService) Exist(itemid uint32) bool {
|
||||
func (s *ItemService) Get(min, max uint32) []model.Item {
|
||||
|
||||
var ttt []model.Item
|
||||
s.dbm(s.Model).Where(g.Map{
|
||||
"item_id <=": max,
|
||||
"item_id >=": min,
|
||||
}).Where("item_cnt >", 0).Scan(&ttt)
|
||||
s.dbm(s.Model).WhereBetween("item_id", min, max).Where("item_cnt >", 0).Scan(&ttt)
|
||||
|
||||
return ttt
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/os/gtime"
|
||||
)
|
||||
|
||||
@@ -46,9 +47,30 @@ func (s *PetService) UPdateFree(ctime uint32, free uint32) {
|
||||
).Update()
|
||||
|
||||
}
|
||||
func (s *PetService) UPdatePrice(ctime uint32, Price uint32, is_sale uint32) {
|
||||
s.dbm(s.Model).Where("catch_time", ctime).Data("sale_price", Price, "is_sale", is_sale).Update()
|
||||
func (s *PetService) UPdatePrice(ctime uint32, Price uint32, is_sale uint32) error {
|
||||
res0, err := s.dbm(s.Model).
|
||||
Where("catch_time", ctime). // 限定 ctime,避免全表更新
|
||||
Where("sale_price = ?", 0). // 只筛选 sale_price=0 的记录
|
||||
Data(g.Map{
|
||||
"sale_price": Price,
|
||||
"is_sale": is_sale,
|
||||
}).Update()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("修改 sale_price=0 的记录失败:%w", err)
|
||||
}
|
||||
affected0, _ := res0.RowsAffected()
|
||||
if affected0 == 0 {
|
||||
priceUpper := Price * 110 / 100 // 上限 = Price * 1.1(整数运算避免浮点误差)
|
||||
priceLower := Price * 90 / 100 // 下限 = Price * 0.9
|
||||
res, _ := s.dbm(s.Model).Where("catch_time", ctime).WhereBetween("sale_price", priceLower, priceUpper).Data("sale_price", Price, "is_sale", is_sale).Update()
|
||||
t, _ := res.RowsAffected()
|
||||
if t < 0 {
|
||||
return fmt.Errorf("修改失败")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (s *PetService) BuyPet(pid uint32) error {
|
||||
|
||||
@@ -72,15 +94,16 @@ func (s *PetService) BuyPet(pid uint32) error {
|
||||
if !tt.UpdateTime.AddDate(0, 0, 1).Before(gtime.Now()) {
|
||||
return fmt.Errorf("数据异常")
|
||||
}
|
||||
useglod := int64(tt.SalePrice)*102 + int64(tt.SaleCount)*5
|
||||
|
||||
if service.NewBaseSysUserService().GetGold(uint(s.userid)) < int64(tt.SalePrice)*102 {
|
||||
if service.NewBaseSysUserService().GetFreeGold(uint(s.userid)) < useglod {
|
||||
return fmt.Errorf("余额不足")
|
||||
}
|
||||
|
||||
service.NewBaseSysUserService().UpdateGold(s.userid, -int64(tt.SalePrice)*102)
|
||||
service.NewBaseSysUserService().UpdateFreeGold(s.userid, -useglod)
|
||||
NewPetService(tt.PlayerID).Pet_del(tt.CatchTime)
|
||||
service.NewBaseSysUserService().UpdateGold(tt.PlayerID, int64(tt.SalePrice)*98)
|
||||
s.PetAdd(&tt.Data)
|
||||
service.NewBaseSysUserService().UpdateFreeGold(tt.PlayerID, int64(tt.SalePrice)*98)
|
||||
s.PetAdd(&tt.Data, tt.SaleCount+1)
|
||||
|
||||
return nil
|
||||
|
||||
@@ -160,7 +183,7 @@ func (s *PetService) Pet_LEVEL_all() []model.Pet {
|
||||
}
|
||||
|
||||
// 精灵真正添加后的捕捉时间才是真正的时间
|
||||
func (s *PetService) PetAdd(y *model.PetInfo) uint32 {
|
||||
func (s *PetService) PetAdd(y *model.PetInfo, salecount uint32) uint32 {
|
||||
if y == nil {
|
||||
return 0
|
||||
}
|
||||
@@ -184,6 +207,7 @@ RETURNING max_ts;
|
||||
player.Data = *y
|
||||
player.CatchTime = y.CatchTime
|
||||
player.Free = 0
|
||||
player.SaleCount = salecount
|
||||
player.IsVip = cool.Config.ServerInfo.IsVip
|
||||
|
||||
_, err := m1.Insert(player)
|
||||
|
||||
Reference in New Issue
Block a user