feat(pet): 添加宠物自由状态管理功能 - 在ServiceList和ServicePage方法中添加WhereNot条件支持 - 将宠物销售状态改为自由状态,新增free字段来标识三种状态: 0为放入仓库,1为放生,2为上架 - 修改PetInfo、UPdateFree、UPdatePrice等方法以支持新的状态逻辑 - 更新BuyPet方法中的验证逻辑 - 调整查询操作中的字段过滤条件 ```
This commit is contained in:
@@ -254,6 +254,8 @@ func (s *Service) ServiceList(ctx context.Context, req *ListReq) (data interface
|
||||
if len(v) == 3 {
|
||||
if gconv.Bool(v[2]) {
|
||||
m.Where(v[0], v[1])
|
||||
} else {
|
||||
m.WhereNot(gconv.String(v[0]), v[1])
|
||||
}
|
||||
}
|
||||
if len(v) == 2 {
|
||||
@@ -357,6 +359,8 @@ func (s *Service) ServicePage(ctx context.Context, req *PageReq) (data interface
|
||||
if len(v) == 3 {
|
||||
if gconv.Bool(v[2]) {
|
||||
m.Where(v[0], v[1])
|
||||
} else {
|
||||
m.WhereNot(gconv.String(v[0]), v[1])
|
||||
}
|
||||
}
|
||||
if len(v) == 2 {
|
||||
|
||||
@@ -90,7 +90,7 @@ type PriseReq struct {
|
||||
g.Meta `path:"/modpirse" method:"POST"`
|
||||
Ctime uint32 `json:"catch_time"`
|
||||
Price uint32 `json:"sale_price"`
|
||||
IsSale uint32 `json:"is_sale"`
|
||||
Free uint32 `json:"free"`
|
||||
}
|
||||
|
||||
func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *cool.BaseRes, err error) {
|
||||
@@ -100,7 +100,7 @@ func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *co
|
||||
if req.Price < 5 {
|
||||
req.Price = 5
|
||||
}
|
||||
if req.IsSale == 1 {
|
||||
if req.Free == 2 {
|
||||
|
||||
if base.NewBaseSysUserService().GetFreeGold(admin.UserId) < 0 {
|
||||
err = fmt.Errorf("金币不足")
|
||||
@@ -108,7 +108,7 @@ func (c *PetBagController) ModPrise(ctx context.Context, req *PriseReq) (res *co
|
||||
}
|
||||
|
||||
}
|
||||
err = service.NewPetService(uint32(admin.UserId)).UPdatePrice(req.Ctime, req.Price, req.IsSale)
|
||||
err = service.NewPetService(uint32(admin.UserId)).UPdatePrice(req.Ctime, req.Price, req.Free)
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -26,9 +26,9 @@ const TableNamePet = "player_pet"
|
||||
type Pet struct {
|
||||
Base
|
||||
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为放入背包
|
||||
Free int `gorm:"not null;default:0;comment:'是否放生'" json:"free"` //"0为放入仓库,1为放生,2为上架
|
||||
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"` //仅作为存储
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
// 获取精灵信息 0是仓库,1是放生
|
||||
func (s *PetService) PetInfo(flag int) []model.Pet {
|
||||
var tt []model.Pet
|
||||
err := s.dbm(s.Model).Where("free", flag).Where("is_sale", 0).Scan(&tt)
|
||||
err := s.dbm(s.Model).Where("free", flag).Scan(&tt)
|
||||
if err != nil {
|
||||
return []model.Pet{}
|
||||
}
|
||||
@@ -43,19 +43,19 @@ func (s *PetService) PetCount(flag int) int {
|
||||
|
||||
func (s *PetService) UPdateFree(ctime uint32, free uint32) bool {
|
||||
|
||||
res, _ := s.dbm(s.Model).Where("catch_time", ctime).Where("is_sale", 0).Data(
|
||||
res, _ := s.dbm(s.Model).Where("catch_time", ctime).Data(
|
||||
|
||||
"free", free,
|
||||
).Update()
|
||||
r, _ := res.RowsAffected()
|
||||
return r > 0
|
||||
}
|
||||
func (s *PetService) UPdatePrice(ctime uint32, Price uint32, is_sale uint32) error {
|
||||
func (s *PetService) UPdatePrice(ctime uint32, Price uint32, free uint32) error {
|
||||
var item1 model.Pet
|
||||
var feeRate float64
|
||||
var err1 error
|
||||
if is_sale == 1 {
|
||||
t, _ := s.dbm(s.Model).Where("is_sale", 1).Count()
|
||||
if free == 2 {
|
||||
t, _ := s.dbm(s.Model).Where("free", 1).Count()
|
||||
if t > 3 {
|
||||
return fmt.Errorf("精灵数量已满")
|
||||
}
|
||||
@@ -73,10 +73,10 @@ func (s *PetService) UPdatePrice(ctime uint32, Price uint32, is_sale uint32) err
|
||||
//Where("sale_price = ?", 0). // 只筛选 sale_price=0 的记录
|
||||
Data(g.Map{
|
||||
"sale_price": Price,
|
||||
"is_sale": is_sale,
|
||||
"free": free,
|
||||
}).Update()
|
||||
g, _ := res.RowsAffected()
|
||||
if g > 0 && is_sale == 0 && feeRate != 0 {
|
||||
if g > 0 && free != 2 && feeRate != 0 {
|
||||
|
||||
amount1 := item1.CalculateOffShelfAmount(feeRate)
|
||||
service.NewBaseSysUserService().UpdateFreeGold(s.userid, -int64(amount1*100))
|
||||
@@ -93,12 +93,9 @@ func (s *PetService) BuyPet(pid uint32) error {
|
||||
if tt.IsVip != 0 {
|
||||
return fmt.Errorf("不允许交易")
|
||||
}
|
||||
if tt.IsSale == 0 {
|
||||
if tt.Free != 2 {
|
||||
return fmt.Errorf("未上架")
|
||||
}
|
||||
if tt.Free == 0 {
|
||||
return fmt.Errorf("没有此精灵")
|
||||
}
|
||||
if tt.SalePrice == 0 {
|
||||
return fmt.Errorf("未设置价格")
|
||||
}
|
||||
@@ -311,19 +308,19 @@ func NewPetService(userid uint32) *PetService {
|
||||
Model: model.NewPet(),
|
||||
ListQueryOp: &cool.QueryOp{
|
||||
AddOrderby: g.MapStrStr{"updateTime": "asc"},
|
||||
FieldEQ: []string{"player_id", "free", "is_sale"},
|
||||
FieldEQ: []string{"player_id", "free"},
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
|
||||
return [][]interface{}{
|
||||
// {"player_id", userId, true},
|
||||
{"free", 1, true},
|
||||
{"free", 0, false},
|
||||
|
||||
{"is_vip", 0, true},
|
||||
}
|
||||
|
||||
},
|
||||
},
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
FieldEQ: []string{"player_id", "free", "is_sale"},
|
||||
FieldEQ: []string{"player_id", "free"},
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
// var (
|
||||
// admin = cool.GetAdmin(ctx)
|
||||
@@ -331,7 +328,7 @@ func NewPetService(userid uint32) *PetService {
|
||||
// )
|
||||
return [][]interface{}{
|
||||
// {"player_id", userId, true},
|
||||
{"free", 1, true},
|
||||
{"free", 0, false},
|
||||
{"is_vip", 0, true},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user