feat(service): 宠物添加功能增加销售计数参数并优化价格更新逻辑 - 修改PetAdd方法签名,增加salecount参数用于追踪宠物销售次数 - 在多个控制器中统一调用PetAdd方法时传入0作为初始销售次数 - 临时禁用寒流枪活动中的宠物发放功能 - 优化UPdatePrice方法,添加错误处理和价格范围验证逻辑 - 调整宠物购买逻辑,使用免费金币系统并计算递增购买
This commit is contained in:
@@ -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