package service

import (
	"blazing/cool"
	"blazing/modules/blazing/model"
)

// 获取精灵信息   0是仓库,1是背包,2是放生
func (s *UserService) PetInfo(flag int) []model.PetEX {
	var tt []model.PetEX
	err := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("in_bag", flag).Scan(&tt)
	if err != nil {
		return []model.PetEX{}
	}
	return tt

}

func (s *UserService) PetInfo_One_exec(cachetime uint32, t func(*model.PetEX)) {

	m := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
	var tt model.PetEX
	m.Scan(&tt)
	t(&tt)
	m.Update(tt)
}
func (s *UserService) PetInfo_One(cachetime uint32) model.PetEX {

	m := cool.DBM(s.pet.Model).Where("player_id", s.userid).Where("catch_time", cachetime)
	var tt model.PetEX
	m.Scan(&tt)
	return tt
}
func (s *UserService) PetAdd(y model.PetInfo) {

	m1 := cool.DBM(s.pet.Model).Where("player_id", s.userid)
	var player model.PetEX
	player.PlayerID = s.userid
	player.CatchTime = y.CatchTime
	player.InBag = 0

	m1.Insert(player)

}
