File tree Expand file tree Collapse file tree 2 files changed +24
-11
lines changed
Expand file tree Collapse file tree 2 files changed +24
-11
lines changed Original file line number Diff line number Diff line change 1- // bank 包提供银行相关的核心功能,包括存款、取款、贷款等操作。
1+ // Package bank 银行
22package bank
33
44import (
@@ -144,15 +144,25 @@ func calculateDailyCurrentInterest() {
144144
145145// 加载利息信息
146146func 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// 保存利息信息
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments