feat(withdrawal): 增加提现审核对账与历史记录
This commit is contained in:
@@ -32,6 +32,75 @@ func toDTO(w model.WithdrawalRequest) WithdrawalDTO {
|
||||
}
|
||||
}
|
||||
|
||||
// toAdminListItems 批量装配提现分页列表依赖的用户和站点信息,避免每条记录分别查库。
|
||||
func (r *Repository) toAdminListItems(ctx context.Context, withdrawals []model.WithdrawalRequest) ([]WithdrawalListItemDTO, error) {
|
||||
items := make([]WithdrawalListItemDTO, 0, len(withdrawals))
|
||||
if len(withdrawals) == 0 {
|
||||
return items, nil
|
||||
}
|
||||
|
||||
userIDs := make([]uint64, 0, len(withdrawals))
|
||||
siteIDs := make([]uint64, 0, len(withdrawals))
|
||||
seenUsers := make(map[uint64]struct{}, len(withdrawals))
|
||||
seenSites := make(map[uint64]struct{}, len(withdrawals))
|
||||
for _, withdrawal := range withdrawals {
|
||||
if _, ok := seenUsers[withdrawal.UserID]; !ok {
|
||||
seenUsers[withdrawal.UserID] = struct{}{}
|
||||
userIDs = append(userIDs, withdrawal.UserID)
|
||||
}
|
||||
if withdrawal.DistributionSiteID > 0 {
|
||||
if _, ok := seenSites[withdrawal.DistributionSiteID]; !ok {
|
||||
seenSites[withdrawal.DistributionSiteID] = struct{}{}
|
||||
siteIDs = append(siteIDs, withdrawal.DistributionSiteID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
usersByID := make(map[uint64]model.User, len(userIDs))
|
||||
var users []model.User
|
||||
if err := r.db.WithContext(ctx).Select("id, nickname, phone").Where("id IN ?", userIDs).Find(&users).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, user := range users {
|
||||
usersByID[user.ID] = user
|
||||
}
|
||||
|
||||
sitesByID := make(map[uint64]model.DistributionSite, len(siteIDs))
|
||||
if len(siteIDs) > 0 {
|
||||
var sites []model.DistributionSite
|
||||
if err := r.db.WithContext(ctx).Select("id, site_name").Where("id IN ?", siteIDs).Find(&sites).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, site := range sites {
|
||||
sitesByID[site.ID] = site
|
||||
}
|
||||
}
|
||||
|
||||
for _, withdrawal := range withdrawals {
|
||||
user := usersByID[withdrawal.UserID]
|
||||
site := sitesByID[withdrawal.DistributionSiteID]
|
||||
items = append(items, WithdrawalListItemDTO{
|
||||
ID: withdrawal.ID,
|
||||
WithdrawNo: withdrawal.WithdrawNo,
|
||||
UserID: withdrawal.UserID,
|
||||
DistributionSiteID: withdrawal.DistributionSiteID,
|
||||
DistributionSiteName: site.SiteName,
|
||||
UserNickname: user.Nickname,
|
||||
UserPhone: user.Phone,
|
||||
AmountCent: withdrawal.AmountCent,
|
||||
FeeCent: withdrawal.FeeCent,
|
||||
ActualAmountCent: withdrawal.ActualAmountCent,
|
||||
AccountType: withdrawal.AccountType,
|
||||
AccountName: withdrawal.AccountName,
|
||||
AccountNo: withdrawal.AccountNo,
|
||||
BankName: withdrawal.BankName,
|
||||
Status: withdrawal.Status,
|
||||
CreatedAt: withdrawal.CreatedAt,
|
||||
})
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// 转换为管理员详细DTO
|
||||
|
||||
// 转换为管理员详细DTO
|
||||
|
||||
Reference in New Issue
Block a user