From e653475e08d3f9c6c242d7e017ca7b0e5a203909 Mon Sep 17 00:00:00 2001 From: vatebur <67186678+vatebur@users.noreply.github.com> Date: Tue, 15 Oct 2024 22:39:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E5=87=BA=E5=94=AE?= =?UTF-8?q?=E9=99=90=E5=88=B6=E6=9C=AA=E7=94=9F=E6=95=88=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=20(#1038)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改更新购买限制逻辑的位置 - `checkCanSalesFor` & `selectCanSalesFishFor`俩个函数一个是检测出售鱼竿上限,一个是检测出售鱼上限。 暂时解决俩个函数对于buff状态更新冲突的问题;下个版本打算重构一下这部分,把俩个函数合并一下。用一个函数就够了 --- plugin/mcfish/main.go | 4 ++++ plugin/mcfish/store.go | 29 +++++++++++++++-------------- 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/plugin/mcfish/main.go b/plugin/mcfish/main.go index 5ecd5ba8..c4501709 100644 --- a/plugin/mcfish/main.go +++ b/plugin/mcfish/main.go @@ -791,6 +791,7 @@ func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) { userInfo.Duration = time.Now().Unix() userInfo.SalesPole = 0 userInfo.BuyTing = 0 + userInfo.SalesFish = 0 } if sales && userInfo.SalesPole < 5 { residue = 5 - userInfo.SalesPole @@ -825,6 +826,9 @@ func (sql *fishdb) selectCanSalesFishFor(uid int64, sales int) int { _ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10)) if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() { userInfo.Duration = time.Now().Unix() + // 在 checkCanSalesFor 也有更新buff时间,TODO:重构 *CanSalesFishFor 俩个函数 + userInfo.SalesPole = 0 + userInfo.BuyTing = 0 userInfo.SalesFish = 0 err := sql.db.Insert("buff", &userInfo) if err != nil { diff --git a/plugin/mcfish/store.go b/plugin/mcfish/store.go index 8e04bc8b..216e995b 100644 --- a/plugin/mcfish/store.go +++ b/plugin/mcfish/store.go @@ -194,13 +194,6 @@ func init() { } } - // 更新交易鱼类数量 - if checkIsFish(thingName) { - err := dbdata.updateCanSalesFishFor(uid, number) - if err != nil { - ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err)) - } - } records, err := dbdata.getUserThingInfo(uid, "唱片") if err != nil { ctx.SendChain(message.Text("[ERROR at store.go.9.1]:", err)) @@ -321,6 +314,14 @@ func init() { logrus.Warnln(err) } } + // 更新交易鱼类数量 + if checkIsFish(thingName) { + err := dbdata.updateCanSalesFishFor(uid, number) + if err != nil { + ctx.SendChain(message.Text("[ERROR,记录鱼类交易数量失败,此次交易不记录]:", err)) + } + } + ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("成功出售", thingName, ":", number, "个", ",你赚到了", pice*number, msg))) }) engine.OnRegex(`^出售所有垃圾`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) { @@ -532,13 +533,6 @@ func init() { } } - // 更新交易鱼类数量 - if checkIsFish(thingName) { - err := dbdata.updateCanSalesFishFor(uid, number) - if err != nil { - ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err)) - } - } thing := thingInfos[index] if thing.Number < number { ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("商店数量不足"))) @@ -656,6 +650,13 @@ func init() { logrus.Warnln(err) } } + // 更新交易鱼类数量 + if checkIsFish(thingName) { + err := dbdata.updateCanSalesFishFor(uid, number) + if err != nil { + ctx.SendChain(message.Text("[ERROR,更新鱼类交易数量失败,此次交易不记录]:", err)) + } + } ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你用", price, "购买了", number, thingName))) }) }