Skip to content

Commit e653475

Browse files
authored
fix:修复出售限制未生效的问题 (#1038)
- 修改更新购买限制逻辑的位置 - `checkCanSalesFor` & `selectCanSalesFishFor`俩个函数一个是检测出售鱼竿上限,一个是检测出售鱼上限。 暂时解决俩个函数对于buff状态更新冲突的问题;下个版本打算重构一下这部分,把俩个函数合并一下。用一个函数就够了
1 parent 23c0949 commit e653475

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

plugin/mcfish/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@ func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) {
791791
userInfo.Duration = time.Now().Unix()
792792
userInfo.SalesPole = 0
793793
userInfo.BuyTing = 0
794+
userInfo.SalesFish = 0
794795
}
795796
if sales && userInfo.SalesPole < 5 {
796797
residue = 5 - userInfo.SalesPole
@@ -825,6 +826,9 @@ func (sql *fishdb) selectCanSalesFishFor(uid int64, sales int) int {
825826
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
826827
if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() {
827828
userInfo.Duration = time.Now().Unix()
829+
// 在 checkCanSalesFor 也有更新buff时间,TODO:重构 *CanSalesFishFor 俩个函数
830+
userInfo.SalesPole = 0
831+
userInfo.BuyTing = 0
828832
userInfo.SalesFish = 0
829833
err := sql.db.Insert("buff", &userInfo)
830834
if err != nil {

plugin/mcfish/store.go

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,6 @@ func init() {
194194
}
195195
}
196196

197-
// 更新交易鱼类数量
198-
if checkIsFish(thingName) {
199-
err := dbdata.updateCanSalesFishFor(uid, number)
200-
if err != nil {
201-
ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err))
202-
}
203-
}
204197
records, err := dbdata.getUserThingInfo(uid, "唱片")
205198
if err != nil {
206199
ctx.SendChain(message.Text("[ERROR at store.go.9.1]:", err))
@@ -321,6 +314,14 @@ func init() {
321314
logrus.Warnln(err)
322315
}
323316
}
317+
// 更新交易鱼类数量
318+
if checkIsFish(thingName) {
319+
err := dbdata.updateCanSalesFishFor(uid, number)
320+
if err != nil {
321+
ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err))
322+
}
323+
}
324+
324325
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("成功出售", thingName, ":", number, "个", ",你赚到了", pice*number, msg)))
325326
})
326327
engine.OnRegex(`^出售所有垃圾`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
@@ -532,13 +533,6 @@ func init() {
532533
}
533534
}
534535

535-
// 更新交易鱼类数量
536-
if checkIsFish(thingName) {
537-
err := dbdata.updateCanSalesFishFor(uid, number)
538-
if err != nil {
539-
ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err))
540-
}
541-
}
542536
thing := thingInfos[index]
543537
if thing.Number < number {
544538
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("商店数量不足")))
@@ -656,6 +650,13 @@ func init() {
656650
logrus.Warnln(err)
657651
}
658652
}
653+
// 更新交易鱼类数量
654+
if checkIsFish(thingName) {
655+
err := dbdata.updateCanSalesFishFor(uid, number)
656+
if err != nil {
657+
ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err))
658+
}
659+
}
659660
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你用", price, "购买了", number, thingName)))
660661
})
661662
}

0 commit comments

Comments
 (0)