Skip to content

Commit f8fe7a6

Browse files
committed
再次修复pr中出现的问题
1 parent 5850f19 commit f8fe7a6

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

plugin/bank/bank.go

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// bank 包提供银行相关的核心功能,包括存款、取款、贷款等操作。
1+
// Package bank 银行
22
package bank
33

44
import (
@@ -144,15 +144,25 @@ func calculateDailyCurrentInterest() {
144144

145145
// 加载利息信息
146146
func loadInterestInfo() {
147-
if !file.IsExist(interestPath) {
148-
saveInterestInfo()
149-
return
150-
}
151-
data, err := os.ReadFile(interestPath)
152-
if err != nil {
153-
return
154-
}
155-
_ = yaml.Unmarshal(data, dailyInterest)
147+
if !file.IsExist(interestPath) {
148+
// 检查 saveInterestInfo 的错误返回值
149+
if err := saveInterestInfo(); err != nil {
150+
fmt.Printf("加载利息信息失败:首次创建利息文件时出错 - %v", err)
151+
return
152+
}
153+
return
154+
}
155+
156+
data, err := os.ReadFile(interestPath)
157+
if err != nil {
158+
fmt.Printf("读取利息信息文件失败:%v", err) // 补充错误日志
159+
return
160+
}
161+
162+
// 检查 yaml 解析错误
163+
if err := yaml.Unmarshal(data, dailyInterest); err != nil {
164+
fmt.Printf("解析利息信息失败:%v", err)
165+
}
156166
}
157167

158168
// 保存利息信息

plugin/bank/main.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,10 @@ func init() {
569569

570570
loan.RepaidAmount += actualDeduct
571571
account.LastUpdate = time.Now()
572-
SaveAccount(account)
572+
if err := SaveAccount(account); err != nil {
573+
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("还款记录保存失败:", err))
574+
return
575+
}
573576

574577
if amount > remaining {
575578
refund := amount - remaining

0 commit comments

Comments
 (0)