This commit is contained in:
@@ -133,6 +133,34 @@ func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *co
|
||||
return
|
||||
}
|
||||
|
||||
type PetShowReq struct {
|
||||
g.Meta `path:"/show" method:"POST"`
|
||||
CatchTime uint32 `json:"catch_time"`
|
||||
IsShow int `json:"is_show"` // 1=展示 0=取消展示
|
||||
}
|
||||
|
||||
func (c *PetBagController) Show(ctx context.Context, req *PetShowReq) (res *cool.BaseRes, err error) {
|
||||
admin := cool.GetAdmin(ctx)
|
||||
res = &cool.BaseRes{}
|
||||
if req.CatchTime == 0 {
|
||||
err = fmt.Errorf("invalid catch_time")
|
||||
return
|
||||
}
|
||||
if req.IsShow != 0 && req.IsShow != 1 {
|
||||
req.IsShow = 0
|
||||
}
|
||||
petSvc := service.NewPetService(uint32(admin.UserId))
|
||||
pet := petSvc.PetInfoOneByCatchTime(req.CatchTime)
|
||||
if pet == nil {
|
||||
err = fmt.Errorf("pet not found")
|
||||
return
|
||||
}
|
||||
if !petSvc.UpdateIsShow(req.CatchTime, req.IsShow) {
|
||||
err = fmt.Errorf("update failed")
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type BuyPetReq struct {
|
||||
g.Meta `path:"/buy" method:"POST"`
|
||||
Cid uint32 `json:"id"`
|
||||
|
||||
@@ -27,6 +27,7 @@ type Pet struct {
|
||||
PlayerID uint32 `gorm:"not null;index:idx_pet_by_player_id;comment:'所属玩家ID'" json:"player_id"`
|
||||
Free int `gorm:"not null;default:0;comment:'是否放生'" json:"free"` //"0为放入仓库,1为放生,2为上架
|
||||
CatchTime uint32 `gorm:"not null;comment:'捕捉时间'" json:"catch_time"` //唯一键
|
||||
IsShow int `gorm:"not null;default:0;comment:'是否基地展示'" json:"is_show"` //1=基地展示 0=未展示
|
||||
|
||||
SalePrice uint32 `gorm:"not null;default:0;comment:'出售价格'" json:"sale_price"`
|
||||
SaleCount uint32 `gorm:"not null;default:0;comment:'出售次数'" json:"sale_count"`
|
||||
|
||||
@@ -22,9 +22,9 @@ type BaseHouse struct {
|
||||
// 基础关联字段
|
||||
PlayerID uint64 `gorm:"not null;index:idx_player_house;comment:'所属玩家ID'" json:"player_id"`
|
||||
|
||||
// 核心业务字段
|
||||
// ShowPokemon 基地展示精灵ID列表(支持展示多个精灵)
|
||||
ShowPokemon []uint32 `gorm:"type:jsonb;default:'[]';comment:'基地展示精灵ID列表'" json:"show_pokemon"`
|
||||
// // 核心业务字段
|
||||
// // ShowPokemon 基地展示精灵ID列表(支持展示多个精灵)
|
||||
// ShowPokemon []uint32 `gorm:"type:jsonb;default:'[]';comment:'基地展示精灵ID列表'" json:"show_pokemon"`
|
||||
|
||||
UsedItems string `gorm:"type:jsonb;default:'{}';comment:'用户物品列表(物品ID:数量)'" json:"used_items"`
|
||||
|
||||
@@ -57,11 +57,6 @@ type FitmentShowInfo struct {
|
||||
Status uint32 `json:"status"`
|
||||
}
|
||||
|
||||
// UpdateShowPokemon 更新基地展示精灵列表
|
||||
func (bh *BaseHouse) UpdateShowPokemon(pokemonIDs []uint32) {
|
||||
bh.ShowPokemon = pokemonIDs
|
||||
}
|
||||
|
||||
// --------------- 初始化创建表 ---------------
|
||||
func init() {
|
||||
// 初始化时创建基地房型表(与现有Talk表初始化逻辑一致)
|
||||
|
||||
@@ -76,11 +76,39 @@ func (s *PetService) PetCount(flag int) int {
|
||||
return ret
|
||||
}
|
||||
|
||||
// GetShowPets 获取基地展示的精灵列表(is_show=1)
|
||||
func (s *PetService) GetShowPets() []model.Pet {
|
||||
var tt []model.Pet
|
||||
if err := s.dbm_fix(s.Model).Where("is_show", 1).Scan(&tt); err != nil {
|
||||
return nil
|
||||
}
|
||||
for i := range tt {
|
||||
tt[i].Data.CatchTime = tt[i].CatchTime
|
||||
}
|
||||
return tt
|
||||
}
|
||||
|
||||
// UpdateIsShow 更新精灵基地展示状态
|
||||
func (s *PetService) UpdateIsShow(catchTime uint32, isShow int) bool {
|
||||
res, err := s.dbm(s.Model).
|
||||
Where("catch_time", catchTime).
|
||||
Data("is_show", isShow).
|
||||
Update()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
r, _ := res.RowsAffected()
|
||||
return r > 0
|
||||
}
|
||||
|
||||
func (s *PetService) UpdateFree(catchTime, fromFree, toFree uint32) bool {
|
||||
res, err := s.dbm(s.Model).
|
||||
Where("catch_time", catchTime).
|
||||
Where("free", fromFree).
|
||||
Data("free", toFree).
|
||||
Data(g.Map{
|
||||
"free": toFree,
|
||||
"is_show": 0, // 放回背包/放生时取消基地展示
|
||||
}).
|
||||
Update()
|
||||
if err != nil {
|
||||
return false
|
||||
@@ -109,6 +137,7 @@ func (s *PetService) UpdatePrice(catchTime, price, free uint32) error {
|
||||
res, _ := s.dbm(s.Model).Where("catch_time", catchTime).Data(g.Map{
|
||||
"sale_price": price,
|
||||
"free": free,
|
||||
"is_show": 0, // 上架/下架时取消基地展示
|
||||
}).Update()
|
||||
affected, _ := res.RowsAffected()
|
||||
if affected > 0 && free != 2 && feeRate != 0 {
|
||||
|
||||
@@ -41,19 +41,6 @@ func (s *RoomService) Set(id []model.FitmentShowInfo) {
|
||||
ttt.PlayerID = uint64(s.userid)
|
||||
m.Save(ttt)
|
||||
|
||||
}
|
||||
func (s *RoomService) Show(cactime []uint32) {
|
||||
|
||||
//todo待测试
|
||||
var ttt model.BaseHouseEx
|
||||
m := s.dbm(s.Model)
|
||||
|
||||
m.Scan(&ttt)
|
||||
ttt.ShowPokemon = cactime
|
||||
|
||||
ttt.PlayerID = uint64(s.userid)
|
||||
m.Save(ttt)
|
||||
|
||||
}
|
||||
|
||||
// /添加进来的物品一定是保证存在的
|
||||
|
||||
Reference in New Issue
Block a user