f
This commit is contained in:
@@ -199,3 +199,67 @@ func (r *GormSubordinateRepository) ListWalletAllocationsByParentAndChild(ctx co
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
// CreateQuotaPurchase 创建额度购买记录
|
||||
func (r *GormSubordinateRepository) CreateQuotaPurchase(ctx context.Context, p *entities.SubordinateQuotaPurchase) error {
|
||||
return r.withCtx(ctx).Create(p).Error
|
||||
}
|
||||
|
||||
// ListQuotaPurchasesByParentAndChild 查询主对子额度购买记录
|
||||
func (r *GormSubordinateRepository) ListQuotaPurchasesByParentAndChild(ctx context.Context, parentUserID, childUserID string, limit, offset int) ([]*entities.SubordinateQuotaPurchase, int64, error) {
|
||||
var list []entities.SubordinateQuotaPurchase
|
||||
var total int64
|
||||
q := r.withCtx(ctx).Model(&entities.SubordinateQuotaPurchase{}).Where("parent_user_id = ? AND child_user_id = ?", parentUserID, childUserID)
|
||||
if err := q.Count(&total).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
if err := q.Order("created_at DESC").Limit(limit).Offset(offset).Find(&list).Error; err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
out := make([]*entities.SubordinateQuotaPurchase, len(list))
|
||||
for i := range list {
|
||||
out[i] = &list[i]
|
||||
}
|
||||
return out, total, nil
|
||||
}
|
||||
|
||||
// FindQuotaAccount 查询用户产品额度账户
|
||||
func (r *GormSubordinateRepository) FindQuotaAccount(ctx context.Context, userID, productID string) (*entities.UserProductQuotaAccount, error) {
|
||||
var account entities.UserProductQuotaAccount
|
||||
err := r.withCtx(ctx).Where("user_id = ? AND product_id = ?", userID, productID).First(&account).Error
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
return &account, nil
|
||||
}
|
||||
|
||||
// CreateQuotaAccount 创建额度账户
|
||||
func (r *GormSubordinateRepository) CreateQuotaAccount(ctx context.Context, account *entities.UserProductQuotaAccount) error {
|
||||
return r.withCtx(ctx).Create(account).Error
|
||||
}
|
||||
|
||||
// UpdateQuotaAccount 更新额度账户
|
||||
func (r *GormSubordinateRepository) UpdateQuotaAccount(ctx context.Context, account *entities.UserProductQuotaAccount) error {
|
||||
return r.withCtx(ctx).Save(account).Error
|
||||
}
|
||||
|
||||
// ListQuotaAccountsByUser 查询用户全部额度账户
|
||||
func (r *GormSubordinateRepository) ListQuotaAccountsByUser(ctx context.Context, userID string) ([]*entities.UserProductQuotaAccount, error) {
|
||||
var list []entities.UserProductQuotaAccount
|
||||
if err := r.withCtx(ctx).Where("user_id = ?", userID).Order("updated_at DESC").Find(&list).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out := make([]*entities.UserProductQuotaAccount, len(list))
|
||||
for i := range list {
|
||||
out[i] = &list[i]
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// CreateQuotaLedger 创建额度流水
|
||||
func (r *GormSubordinateRepository) CreateQuotaLedger(ctx context.Context, ledger *entities.UserProductQuotaLedger) error {
|
||||
return r.withCtx(ctx).Create(ledger).Error
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user