This commit is contained in:
@@ -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 {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user