From f21d4c649f43f11d97039f6a0dba11e14a98510e Mon Sep 17 00:00:00 2001 From: TremblingV5 Date: Wed, 26 Mar 2025 22:40:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(account):=20=E8=B4=A6=E6=88=B7=E7=BB=91?= =?UTF-8?q?=E5=AE=9A=E5=87=AD=E8=AF=81service?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../accountserviceiface/interface.go | 1 + .../internal/domain/repoiface/account.go | 1 + .../domain/service/accountservice/service.go | 23 +++++++++++++++++++ .../repositories/accountrepo/repository.go | 7 ++++++ 4 files changed, 32 insertions(+) diff --git a/backend/baseService/internal/applications/interface/accountserviceiface/interface.go b/backend/baseService/internal/applications/interface/accountserviceiface/interface.go index 4fc0a57..4d6f9c8 100644 --- a/backend/baseService/internal/applications/interface/accountserviceiface/interface.go +++ b/backend/baseService/internal/applications/interface/accountserviceiface/interface.go @@ -14,6 +14,7 @@ type AccountService interface { CheckPasswordByEmail(ctx context.Context, email, password string) (int64, error) ModifyPassword(ctx context.Context, id int64, oldPassword, newPassword string) error Unbind(ctx context.Context, id int64, voucherType api.VoucherType) error + Bind(ctx context.Context, id int64, voucherType api.VoucherType, voucher string) error } var _ AccountService = (*accountservice.Service)(nil) diff --git a/backend/baseService/internal/domain/repoiface/account.go b/backend/baseService/internal/domain/repoiface/account.go index 6b234c8..82bb878 100644 --- a/backend/baseService/internal/domain/repoiface/account.go +++ b/backend/baseService/internal/domain/repoiface/account.go @@ -16,4 +16,5 @@ type AccountRepository interface { IsMobileExist(ctx context.Context, mobile string) (bool, error) IsEmailExist(ctx context.Context, email string) (bool, error) ClearColumn(ctx context.Context, column field.Expr) error + UpdateColumn(ctx context.Context, column field.Expr, value interface{}) error } diff --git a/backend/baseService/internal/domain/service/accountservice/service.go b/backend/baseService/internal/domain/service/accountservice/service.go index 699f0bc..cf0e7f4 100644 --- a/backend/baseService/internal/domain/service/accountservice/service.go +++ b/backend/baseService/internal/domain/service/accountservice/service.go @@ -166,3 +166,26 @@ func (s *Service) Unbind(ctx context.Context, id int64, voucherType api.VoucherT return s.account.ClearColumn(ctx, column) } + +func (s *Service) Bind(ctx context.Context, id int64, voucherType api.VoucherType, voucher string) (err error) { + ctx, persist := dbtx.WithTXPersist(ctx) + defer func() { + persist(err) + }() + + if id == 0 { + return errors.New("账户id不能为空") + } + + var column field.Expr + switch voucherType { + case api.VoucherType_VOUCHER_EMAIL: + column = query.Q.Account.Email + case api.VoucherType_VOUCHER_PHONE: + column = query.Q.Account.Mobile + default: + return errors.New("不支持的类型") + } + + return s.account.UpdateColumn(ctx, column, voucher) +} diff --git a/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go b/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go index 27e890d..67d0263 100644 --- a/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go +++ b/backend/baseService/internal/infrastructure/repositories/accountrepo/repository.go @@ -79,3 +79,10 @@ func (r *PersistRepository) ClearColumn(ctx context.Context, column field.Expr) return err }) } + +func (r *PersistRepository) UpdateColumn(ctx context.Context, column field.Expr, voucher interface{}) error { + return dbtx.TxDo(ctx, func(tx *query.QueryTx) error { + _, err := tx.WithContext(ctx).Account.Update(column, voucher) + return err + }) +}