fix(analytics): 运行总览 - 兼容旧测试数据缺少积分账户表
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user