fix(analytics): 运行总览 - 兼容旧测试数据缺少积分账户表

This commit is contained in:
ddcat666
2026-10-10 07:24:50 +08:00
parent 18d47d7852
commit 6e72922ca3

View File

@@ -66,6 +66,11 @@ func (r *Repository) Users() ([]model.User, error) {
func (r *Repository) TotalCreditBalance() (int64, error) {
var total int64
err := r.db.Model(&model.CreditAccount{}).Select("COALESCE(SUM(available_microcredits), 0)").Scan(&total).Error
// Some analytics fixtures predate the wallet table; the balance card is a
// read-only enhancement and must not make the existing overview unavailable.
if err != nil && (strings.Contains(err.Error(), "no such table") || strings.Contains(strings.ToLower(err.Error()), "does not exist")) {
return 0, nil
}
return total, err
}