feat(pet): 添加宠物交易功能 - 新增ModPrise接口用于修改宠物售价 - 新增BuyPet接口用于购买宠物 - 修改Pet模型中SalePrice字段类型为float32 - 实现宠物购买逻辑,包括价格验证、余额检查和交易处理 - 更新查询条件以支持宠物交易状态筛选 ```
This commit is contained in:
@@ -43,6 +43,39 @@ func (s *PetService) UPdateFree(ctime uint32, free uint32) {
|
||||
"free", free,
|
||||
).Update()
|
||||
|
||||
}
|
||||
func (s *PetService) UPdatePrice(ctime uint32, Price float32) {
|
||||
|
||||
s.dbm(s.Model).Where("catch_time", ctime).Data("sale_price", Price).Update()
|
||||
|
||||
}
|
||||
func (s *PetService) BuyPet(pid uint32) error {
|
||||
var tt *model.Pet
|
||||
|
||||
s.dbm(s.Model).Where("id", pid).Scan(&tt)
|
||||
if tt == nil {
|
||||
return fmt.Errorf("没有此精灵")
|
||||
}
|
||||
if tt.IsVip != 0 {
|
||||
return fmt.Errorf("不允许交易")
|
||||
}
|
||||
if tt.IsSale == 0 {
|
||||
return fmt.Errorf("未上架")
|
||||
}
|
||||
if tt.SalePrice == 0 {
|
||||
return fmt.Errorf("未设置价格")
|
||||
}
|
||||
|
||||
if service.NewBaseSysUserService().GetGold(uint(s.userid)) < int64(tt.SalePrice)*100 {
|
||||
return fmt.Errorf("余额不足")
|
||||
}
|
||||
service.NewBaseSysUserService().UpdateGold(tt.PlayerID, int64(tt.SalePrice)*100)
|
||||
service.NewBaseSysUserService().UpdateGold(s.userid, -int64(tt.SalePrice)*100)
|
||||
s.PetAdd(&tt.Data)
|
||||
s.dbm(s.Model).Where("id", pid).Delete() //删除旧精灵
|
||||
|
||||
return nil
|
||||
|
||||
}
|
||||
func (s *PetService) UPdate(t model.PetInfo) {
|
||||
|
||||
@@ -168,14 +201,14 @@ func NewPetService(userid uint32) *PetService {
|
||||
Service: &cool.Service{
|
||||
Model: model.NewPet(),
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
FieldEQ: []string{"player_id", "free"},
|
||||
FieldEQ: []string{"player_id", "free", "is_sale"},
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
var (
|
||||
admin = cool.GetAdmin(ctx)
|
||||
userId = admin.UserId
|
||||
)
|
||||
// var (
|
||||
// admin = cool.GetAdmin(ctx)
|
||||
// // userId = admin.UserId
|
||||
// )
|
||||
return [][]interface{}{
|
||||
{"player_id", userId, true},
|
||||
// {"player_id", userId, true},
|
||||
{"free", 1, true},
|
||||
{"is_vip", 0, true},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user