1
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed

This commit is contained in:
昔念
2026-04-02 12:38:51 +08:00
parent 6aa601bb06
commit 2f220bb863
2 changed files with 44 additions and 31 deletions

View File

@@ -1,4 +1,4 @@
package admin
package admin
import (
"blazing/common/data"
@@ -20,13 +20,12 @@ type PetGetReq struct {
g.Meta `path:"/genpet" method:"POST"`
UserID uint32 `json:"user_id"`
IsVIP int `json:"is_vip"`
// 新增:精灵相关参数(完全对齐自定义表单配置)
PetTypeId int `json:"petTypeId" v:"required|min:1" comment:"精灵类型ID必填正整数最小1无0或负数类型对应GenPetInfo的id参数"`
IndividualValue int `json:"individualValue" v:"required|between:-1,31" comment:"精灵个体值,必填,范围-1~31-1表示随机生成满个体0~31为固定值决定基础属性上限"`
NatureId int `json:"natureId" v:"required|between:-1,24" comment:"精灵性格ID必填范围-1~24-1表示随机0~24对应25种固定性格影响属性加成"`
AbilityTypeEnum int `json:"abilityTypeEnum" v:"required|min:-1" comment:"精灵特性类型ID必填最小值-1-1表示随机选择1个特性0及以上为固定特性ID需与PlayerEffectMAP匹配"`
IsShiny int `json:"isShiny" v:"min:-1" comment:"精灵异色闪光ID必填最小值-1-1表示随机0及以上为固定异色状态稀有精灵特殊外观/属性原表单hidden但需保留必填逻辑"`
Level int `json:"level" v:"required|between:1,100" comment:"精灵等级必填范围1~100常规游戏等级上限影响精灵当前属性强度"`
// 閺傛澘顤冮敍姘辩翱閻忕數娴夐崗鍐插棘閺佸府绱欑€瑰苯鍙忕€靛綊缍堥懛顏勭暰娑斿銆冮崡鏇㈠帳缂冾噯绱? PetTypeId int `json:"petTypeId" v:"required|min:1" comment:"缁墽浼掔猾璇茬€稩D閿涘苯绻€婵夘偓绱濆锝嗘殻閺佸府绱欓張鈧亸?閿涘本妫?閹存牞绀嬮弫鎵閸ㄥ绱氶敍灞筋嚠鎼存摜enPetInfo閻ㄥ埇d閸欏倹鏆?`
IndividualValue int `json:"individualValue" v:"required|between:-1,31" comment:"缁墽浼掓稉顏冪秼閸婄》绱濊箛鍛綖閿涘矁瀵栭崶?1~31閿?1鐞涖劎銇氶梾蹇旀簚閻㈢喐鍨氬鈥查嚋娴搫绱?~31娑撳搫娴愮€规艾鈧》绱濋崘鍐茬暰閸╄櫣顢呯仦鐐粹偓褌绗傞梽鎰剁礆"`
NatureId int `json:"natureId" v:"required|between:-1,24" comment:"缁墽浼掗幀褎鐗窱D閿涘苯绻€婵夘偓绱濋懠鍐ㄦ纯-1~24閿?1鐞涖劎銇氶梾蹇旀簚閿?~24鐎电懓绨?5缁夊秴娴愮€规碍鈧勭壐閿涘苯濂栭崫宥呯潣閹冨閹存劧绱?`
AbilityTypeEnum int `json:"abilityTypeEnum" v:"required|min:-1" comment:"缁墽浼掗悧瑙勨偓褏琚崹濠璂閿涘苯绻€婵夘偓绱濋張鈧亸蹇撯偓?1閿?1鐞涖劎銇氶梾蹇旀簚闁瀚?娑擃亞澹掗幀褝绱?閸欏﹣浜掓稉濠佽礋閸ュ搫鐣鹃悧瑙勨偓顪廌閿涘矂娓舵稉宥眑ayerEffectMAP閸栧綊鍘ら敍?`
IsShiny int `json:"isShiny" v:"min:-1" comment:"缁墽浼掑鍌濆閿涘牓妫崗澶涚礆ID閿涘苯绻€婵夘偓绱濋張鈧亸蹇撯偓?1閿?1鐞涖劎銇氶梾蹇旀簚閿?閸欏﹣浜掓稉濠佽礋閸ュ搫鐣惧鍌濆閻樿埖鈧緤绱濈粙鈧張澶岀翱閻忕數澹掑▓濠傤樆鐟?鐏炵偞鈧嶇礆閿涘苯甯悰銊ュ礋hidden娴棝娓舵穱婵堟殌韫囧懎锝為柅鏄忕帆"`
Level int `json:"level" v:"required|between:1,100" comment:"缁墽浼掔粵澶岄獓閿涘苯绻€婵夘偓绱濋懠鍐ㄦ纯1~100閿涘牆鐖剁憴鍕埗閹村繒鐡戠痪褌绗傞梽鎰剁礉瑜板崬鎼风划鍓т紥瑜版挸澧犵仦鐐粹偓褍宸辨惔锔肩礆"`
}
func init() {
@@ -34,10 +33,10 @@ func init() {
&cool.Controller{
Prefix: "/admin/monster/bag",
Api: []string{"Delete", "Update", "Info", "List", "Page"},
Service: service.NewPetService(0), //因为page已经过滤所以这里需要改成0
Service: service.NewPetService(0), //閸ョ姳璐焢age瀹歌尙绮℃潻鍥ㄦ姢閿涘本澧嶆禒銉ㄧ箹闁插矂娓剁憰浣规暭閹?
},
}
// 注册路由
// 濞夈劌鍞界捄顖滄暠
cool.RegisterController(task_info_controller)
}
func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res *cool.BaseRes, err error) {
@@ -50,7 +49,7 @@ func (c *PetBagController) GetSession(ctx context.Context, req *PetGetReq) (res
t := model.GenPetInfo(
req.PetTypeId, req.IndividualValue, req.NatureId, req.AbilityTypeEnum, req.Level, shiny, 0)
t.CatchRect = 1 //代表这是人工合成的
t.CatchRect = 1 //娴狅綀銆冩潻娆愭Ц娴滃搫浼愰崥鍫熷灇閻?
if req.IsShiny == -1 {
t.RandomByWeightShiny()
}
@@ -79,13 +78,25 @@ func (c *PetBagController) Level(ctx context.Context, req *PetLevelReq) (res *co
}
type PetStorageReq struct {
g.Meta `path:"/storage" method:"POST"`
IsVIP int `json:"is_vip"`
}
func (c *PetBagController) Storage(ctx context.Context, req *PetStorageReq) (res *cool.BaseRes, err error) {
admin := cool.GetAdmin(ctx)
res = &cool.BaseRes{}
res.Data = service.NewPetService(uint32(admin.UserId)).StorageInfo(req.IsVIP)
return
}
type PetLevelReq struct {
g.Meta `path:"/getlevel" method:"GET"`
// 新增:精灵相关参数(完全对齐自定义表单配置)
}
// 閺傛澘顤冮敍姘辩翱閻忕數娴夐崗鍐插棘閺佸府绱欑€瑰苯鍙忕€靛綊缍堥懛顏勭暰娑斿銆冮崡鏇㈠帳缂冾噯绱?}
type PetLevelRes struct {
UserID int `json:"user_id"`
//等级PetLevelRes
//缁涘楠嘝etLevelRes
Level int `json:"level"`
//ID
ID int `json:"id"`
@@ -107,7 +118,7 @@ func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *co
if req.Free == 2 {
if base.NewBaseSysUserService().GetFreeGold(admin.UserId) < 0 {
err = fmt.Errorf("金币不足")
err = fmt.Errorf("闁叉垵绔垫稉宥堝喕")
return
}
@@ -133,3 +144,4 @@ func (c *PetBagController) BuyPet(ctx context.Context, req *BuyPetReq) (res *coo
return
}

View File

@@ -1,4 +1,4 @@
package service
package service
import (
"blazing/cool"
@@ -13,7 +13,7 @@ import (
"github.com/gogf/gf/v2/os/gtime"
)
// nextCatchTime 生成下一个唯一捕捉时间戳(原子递增 max_ts
// nextCatchTime 鐢熸垚涓嬩竴涓敮涓€鎹曟崏鏃堕棿鎴筹紙鍘熷瓙閫掑 max_ts锛?
func (s *PetService) nextCatchTime(m ...*gdb.Model) (uint32, error) {
dbm := cool.DBM(service.NewBaseSysUserService().Model)
if len(m) > 0 {
@@ -30,23 +30,23 @@ RETURNING max_ts;`, service.NewBaseSysUserService().Model.TableName())
ret, err := dbm.Raw(sql, s.userid).All()
if err != nil {
return 0, fmt.Errorf("生成捕捉时间失败: %w", err)
return 0, fmt.Errorf("鐢熸垚鎹曟崏鏃堕棿澶辫触: %w", err)
}
arr := ret.Array()
if len(arr) == 0 {
return 0, fmt.Errorf("生成捕捉时间失败: 无返回数据")
return 0, fmt.Errorf("鐢熸垚鎹曟崏鏃堕棿澶辫触: 鏃犺繑鍥炴暟鎹?)
}
return arr[0].Uint32(), nil
}
// setCatchTime Pet.CatchTime 同步到 Pet.Data.CatchTime
// setCatchTime 灏?Pet.CatchTime 鍚屾鍒?Pet.Data.CatchTime
func setCatchTime(pet *model.Pet) {
if pet != nil {
pet.Data.CatchTime = pet.CatchTime
}
}
// 获取精灵信息 0是仓库,1是放生
// 鑾峰彇绮剧伒淇℃伅 0鏄粨搴?1鏄斁鐢?
func (s *PetService) PetInfo(flag int) []model.Pet {
var tt []model.Pet
if err := s.dbm(s.Model).Where("free", flag).Scan(&tt); err != nil {
@@ -82,14 +82,14 @@ func (s *PetService) UpdatePrice(catchTime, price, free uint32) error {
if free == 2 {
t, _ := s.dbm(s.Model).Where("free", 2).Count()
if t > 3 {
return fmt.Errorf("精灵数量已满")
return fmt.Errorf("绮剧伒鏁伴噺宸叉弧")
}
} else {
if err := s.dbm(s.Model).Where("catch_time", catchTime).Scan(&item); err != nil {
return err
}
_, feeRate, _ = item.GetOffShelfFee()
_ = feeRate // feeRate 仅在 non-2 分支使用,在此声明以统一作用域
_ = feeRate // feeRate 浠呭湪 non-2 鍒嗘敮浣跨敤锛屽湪姝ゅ0鏄庝互缁熶竴浣滅敤鍩?
}
res, _ := s.dbm(s.Model).Where("catch_time", catchTime).Data(g.Map{
@@ -107,19 +107,19 @@ func (s *PetService) UpdatePrice(catchTime, price, free uint32) error {
func (s *PetService) BuyPet(pid uint32) error {
tt := NewPetService(0).PetInfoOneByID(pid)
if tt == nil {
return fmt.Errorf("没有此精灵")
return fmt.Errorf("湁姝ょ簿鐏?)
}
if tt.IsVip != 0 {
return fmt.Errorf("不允许交易")
return fmt.Errorf("涓嶅厑璁镐氦鏄?)
}
if tt.Free != 2 {
return fmt.Errorf("未上架")
return fmt.Errorf("笂鏋?)
}
if tt.SalePrice == 0 {
return fmt.Errorf("未设置价格")
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 {
@@ -130,7 +130,7 @@ func (s *PetService) BuyPet(pid uint32) error {
return err
}
if user.FreeGold < useGold {
return fmt.Errorf("余额不足")
return fmt.Errorf("浣欓涓嶈冻")
}
if _, err := tx.Model(basemodel.BaseSysUser{}).Where("id", s.userid).Increment("free_gold", -useGold); err != nil {
@@ -143,7 +143,7 @@ func (s *PetService) BuyPet(pid uint32) error {
}
affected, _ := res.RowsAffected()
if affected == 0 {
return fmt.Errorf("重复订单")
return fmt.Errorf("閲嶅")
}
if _, err := tx.Model(basemodel.BaseSysUser{}).Where("id", tt.PlayerID).Increment("free_gold", int64(tt.SalePrice)*98); err != nil {
@@ -225,7 +225,7 @@ func (s *PetService) PetLevelAll() []model.Pet {
return tt
}
// PetAdd 精灵真正添加后的捕捉时间才是真正的时间
// PetAdd 绮剧伒鐪熸娣诲姞鍚庣殑鎹曟崏鏃堕棿鎵嶆槸鐪熸鐨勬椂闂?
func (s *PetService) PetAdd(y *model.PetInfo, saleCount uint32) (uint32, error) {
if y == nil {
return 0, nil
@@ -285,3 +285,4 @@ func NewPetService(userid uint32) *PetService {
},
}
}