feat(admin): 运营数据 - 增加余额消耗统计、通知排序与用户积分汇总
This commit is contained in:
1 parent
00fdd9e879
commit
e0778ef727
14 files changed
+84
-27
No files matched your search
@@ -17,10 +17,12 @@ var (
|
||||
)
|
||||
|
||||
type AdminUserCounts struct {
|
||||
LedgerEntries int64 `json:"ledgerEntries"`
|
||||
Tasks int64 `json:"tasks"`
|
||||
APICalls int64 `json:"apiCalls"`
|
||||
AuditEvents int64 `json:"auditEvents"`
|
||||
LedgerEntries int64 `json:"ledgerEntries"`
|
||||
Tasks int64 `json:"tasks"`
|
||||
APICalls int64 `json:"apiCalls"`
|
||||
AuditEvents int64 `json:"auditEvents"`
|
||||
RechargeMicrocredits int64 `json:"rechargeMicrocredits"`
|
||||
CheckinMicrocredits int64 `json:"checkinMicrocredits"`
|
||||
}
|
||||
|
||||
func (r *Repository) AppendAdminAudit(event *model.AdminAuditEvent) error {
|
||||
@@ -112,6 +114,14 @@ func (r *Repository) AdminUserCounts(userID string) (AdminUserCounts, error) {
|
||||
return AdminUserCounts{}, err
|
||||
}
|
||||
}
|
||||
for entryType, target := range map[model.CreditLedgerType]*int64{
|
||||
model.CreditLedgerPaymentTopup: &counts.RechargeMicrocredits,
|
||||
model.CreditLedgerCheckinBonus: &counts.CheckinMicrocredits,
|
||||
} {
|
||||
if err := r.db.Model(&model.CreditLedgerEntry{}).Where("user_id = ? AND type = ?", userID, entryType).Select("COALESCE(SUM(amount_microcredits), 0)").Scan(target).Error; err != nil {
|
||||
return AdminUserCounts{}, err
|
||||
}
|
||||
}
|
||||
return counts, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,7 @@ func (r *Repository) ActiveBannerAnnouncements(now time.Time) ([]model.BannerAnn
|
||||
Where("status = ?", "active").
|
||||
Where("starts_at IS NULL OR starts_at <= ?", now).
|
||||
Where("ends_at IS NULL OR ends_at >= ?", now).
|
||||
Order("created_at desc").
|
||||
Order("sort_order asc, created_at desc").
|
||||
Find(&banners).Error
|
||||
decodeBannerTitleRuns(banners)
|
||||
return banners, err
|
||||
@@ -104,7 +104,7 @@ func (r *Repository) AdminBannerAnnouncements(keyword string, status string, lim
|
||||
if err := query.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := query.Order("created_at desc").Limit(limit).Offset(offset).Find(&banners).Error; err != nil {
|
||||
if err := query.Order("sort_order asc, created_at desc").Limit(limit).Offset(offset).Find(&banners).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
decodeBannerTitleRuns(banners)
|
||||
|
||||
@@ -63,6 +63,12 @@ func (r *Repository) Users() ([]model.User, error) {
|
||||
return users, err
|
||||
}
|
||||
|
||||
func (r *Repository) TotalCreditBalance() (int64, error) {
|
||||
var total int64
|
||||
err := r.db.Model(&model.CreditAccount{}).Select("COALESCE(SUM(available_microcredits), 0)").Scan(&total).Error
|
||||
return total, err
|
||||
}
|
||||
|
||||
func (r *Repository) AdminUsers(keyword string, role model.UserRole, status model.UserStatus, limit int, offset int) ([]model.User, int64, error) {
|
||||
var users []model.User
|
||||
var total int64
|
||||
|
||||
Reference in new issue
Block a user