feat(server): admin 批次列表/作废改指 codes 库新表,清理被取代的旧 store 方法(#codes-lib)
This commit is contained in:
@@ -31,7 +31,7 @@ func (s *Store) ListBatches(ctx context.Context, limit, offset int) ([]BatchInfo
|
||||
}
|
||||
|
||||
var total int
|
||||
if err := s.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM code_batches`).Scan(&total); err != nil {
|
||||
if err := s.db.QueryRowContext(ctx, `SELECT COUNT(*) FROM codes_batches`).Scan(&total); err != nil {
|
||||
return nil, 0, fmt.Errorf("store.ListBatches count: %w", err)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ func (s *Store) ListBatches(ctx context.Context, limit, offset int) ([]BatchInfo
|
||||
SUM(c.status = 'redeemed'),
|
||||
SUM(c.status = 'void'),
|
||||
SUM(c.status = 'unused')
|
||||
FROM code_batches b
|
||||
FROM codes_batches b
|
||||
LEFT JOIN codes c ON c.batch_id = b.id
|
||||
GROUP BY b.id, b.channel, b.created_by, b.note, b.created_at
|
||||
ORDER BY b.id DESC
|
||||
@@ -73,7 +73,7 @@ func (s *Store) ListBatches(ctx context.Context, limit, offset int) ([]BatchInfo
|
||||
// number of codes voided. Already-redeemed codes are left untouched.
|
||||
func (s *Store) VoidBatch(ctx context.Context, batchID int64) (int64, error) {
|
||||
res, err := s.db.ExecContext(ctx,
|
||||
`UPDATE codes SET status = 'void' WHERE batch_id = ? AND status = 'unused'`, batchID)
|
||||
`UPDATE codes SET status = 'void', void_reason = 'batch_void' WHERE batch_id = ? AND status = 'unused'`, batchID)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("store.VoidBatch: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user