From ed334b946b7b1264f723754f099861605626d750 Mon Sep 17 00:00:00 2001 From: huang Date: Sat, 21 Mar 2026 11:33:06 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E6=B8=85=E7=90=86=E9=87=8D?= =?UTF-8?q?=E6=9E=84=E9=81=97=E7=95=99=E7=9A=84=E6=AD=BB=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - personal_customer.Service: 删除已迁移到 client_auth 的死方法 (GetProfile/SendVerificationCode/VerifyCode),移除多余的 verificationService/jwtManager 依赖 - 删除 internal/service/customer/ 整个目录(零引用的早期残留) --- internal/bootstrap/services.go | 2 +- internal/service/customer/service.go | 126 ------------------ internal/service/personal_customer/service.go | 47 +------ 3 files changed, 8 insertions(+), 167 deletions(-) delete mode 100644 internal/service/customer/service.go diff --git a/internal/bootstrap/services.go b/internal/bootstrap/services.go index af24da4..f6da571 100644 --- a/internal/bootstrap/services.go +++ b/internal/bootstrap/services.go @@ -110,7 +110,7 @@ func initServices(s *stores, deps *Dependencies) *services { AccountAudit: accountAudit, Role: roleSvc.New(s.Role, s.Permission, s.RolePermission), Permission: permissionSvc.New(s.Permission, s.AccountRole, s.RolePermission, account, deps.Redis), - PersonalCustomer: personalCustomerSvc.NewService(s.PersonalCustomer, s.PersonalCustomerPhone, deps.VerificationService, deps.JWTManager, deps.Logger), + PersonalCustomer: personalCustomerSvc.NewService(s.PersonalCustomer, s.PersonalCustomerPhone, deps.Logger), ClientAuth: clientAuthSvc.New( deps.DB, s.PersonalCustomerOpenID, diff --git a/internal/service/customer/service.go b/internal/service/customer/service.go deleted file mode 100644 index cc892e0..0000000 --- a/internal/service/customer/service.go +++ /dev/null @@ -1,126 +0,0 @@ -// Package customer 提供客户管理的业务逻辑服务 -// 包含客户信息管理、客户查询等功能 -package customer - -import ( - "context" - - "github.com/break/junhong_cmp_fiber/internal/model" - "github.com/break/junhong_cmp_fiber/internal/model/dto" - "github.com/break/junhong_cmp_fiber/internal/store" - "github.com/break/junhong_cmp_fiber/internal/store/postgres" - "github.com/break/junhong_cmp_fiber/pkg/constants" - "github.com/break/junhong_cmp_fiber/pkg/errors" -) - -// Service 个人客户业务服务 -type Service struct { - customerStore *postgres.PersonalCustomerStore -} - -// New 创建个人客户服务 -func New(customerStore *postgres.PersonalCustomerStore) *Service { - return &Service{ - customerStore: customerStore, - } -} - -// Create 创建个人客户 -func (s *Service) Create(ctx context.Context, req *dto.CreatePersonalCustomerRequest) (*model.PersonalCustomer, error) { - // 检查手机号唯一性 - if req.Phone != "" { - existing, err := s.customerStore.GetByPhone(ctx, req.Phone) - if err == nil && existing != nil { - return nil, errors.New(errors.CodeCustomerPhoneExists, "手机号已存在") - } - } - - // 创建个人客户 - // 注意:根据新的数据模型,手机号应该存储在 PersonalCustomerPhone 表中 - // 这里暂时先创建客户记录,手机号的存储后续通过 PersonalCustomerPhoneStore 实现 - customer := &model.PersonalCustomer{ - Nickname: req.Nickname, - AvatarURL: req.AvatarURL, - WxOpenID: req.WxOpenID, - WxUnionID: req.WxUnionID, - Status: constants.StatusEnabled, - } - - if err := s.customerStore.Create(ctx, customer); err != nil { - return nil, err - } - - // TODO: 创建 PersonalCustomerPhone 记录,需要通过 PersonalCustomerPhoneStore 创建手机号关联 - - return customer, nil -} - -// Update 更新个人客户信息 -func (s *Service) Update(ctx context.Context, id uint, req *dto.UpdatePersonalCustomerRequest) (*model.PersonalCustomer, error) { - // 查询客户 - customer, err := s.customerStore.GetByID(ctx, id) - if err != nil { - return nil, errors.New(errors.CodeCustomerNotFound, "个人客户不存在") - } - - // TODO: 手机号的更新逻辑需要通过 PersonalCustomerPhoneStore 更新或创建手机号记录 - - // 更新字段 - if req.Nickname != nil { - customer.Nickname = *req.Nickname - } - if req.AvatarURL != nil { - customer.AvatarURL = *req.AvatarURL - } - - if err := s.customerStore.Update(ctx, customer); err != nil { - return nil, err - } - - return customer, nil -} - -// BindWeChat 绑定微信信息 -func (s *Service) BindWeChat(ctx context.Context, id uint, wxOpenID, wxUnionID string) error { - customer, err := s.customerStore.GetByID(ctx, id) - if err != nil { - return errors.New(errors.CodeCustomerNotFound, "个人客户不存在") - } - - customer.WxOpenID = wxOpenID - customer.WxUnionID = wxUnionID - - return s.customerStore.Update(ctx, customer) -} - -// GetByID 获取个人客户详情 -func (s *Service) GetByID(ctx context.Context, id uint) (*model.PersonalCustomer, error) { - customer, err := s.customerStore.GetByID(ctx, id) - if err != nil { - return nil, errors.New(errors.CodeCustomerNotFound, "个人客户不存在") - } - return customer, nil -} - -// GetByPhone 根据手机号获取个人客户 -func (s *Service) GetByPhone(ctx context.Context, phone string) (*model.PersonalCustomer, error) { - customer, err := s.customerStore.GetByPhone(ctx, phone) - if err != nil { - return nil, errors.New(errors.CodeCustomerNotFound, "个人客户不存在") - } - return customer, nil -} - -// GetByWxOpenID 根据微信 OpenID 获取个人客户 -func (s *Service) GetByWxOpenID(ctx context.Context, wxOpenID string) (*model.PersonalCustomer, error) { - customer, err := s.customerStore.GetByWxOpenID(ctx, wxOpenID) - if err != nil { - return nil, errors.New(errors.CodeCustomerNotFound, "个人客户不存在") - } - return customer, nil -} - -// List 查询个人客户列表 -func (s *Service) List(ctx context.Context, opts *store.QueryOptions, filters map[string]interface{}) ([]*model.PersonalCustomer, int64, error) { - return s.customerStore.List(ctx, opts, filters) -} diff --git a/internal/service/personal_customer/service.go b/internal/service/personal_customer/service.go index e74dacb..166bd30 100644 --- a/internal/service/personal_customer/service.go +++ b/internal/service/personal_customer/service.go @@ -1,14 +1,11 @@ -// Package personal_customer 提供个人客户管理的业务逻辑服务 -// 包含个人客户注册、登录、微信绑定、短信验证等功能 +// Package personal_customer 提供个人客户资料管理的业务逻辑服务 package personal_customer import ( "context" "github.com/break/junhong_cmp_fiber/internal/model" - "github.com/break/junhong_cmp_fiber/internal/service/verification" "github.com/break/junhong_cmp_fiber/internal/store/postgres" - "github.com/break/junhong_cmp_fiber/pkg/auth" "github.com/break/junhong_cmp_fiber/pkg/errors" "go.uber.org/zap" "gorm.io/gorm" @@ -16,40 +13,24 @@ import ( // Service 个人客户服务 type Service struct { - store *postgres.PersonalCustomerStore - phoneStore *postgres.PersonalCustomerPhoneStore - verificationService *verification.Service - jwtManager *auth.JWTManager - logger *zap.Logger + store *postgres.PersonalCustomerStore + phoneStore *postgres.PersonalCustomerPhoneStore + logger *zap.Logger } // NewService 创建个人客户服务实例 func NewService( store *postgres.PersonalCustomerStore, phoneStore *postgres.PersonalCustomerPhoneStore, - verificationService *verification.Service, - jwtManager *auth.JWTManager, logger *zap.Logger, ) *Service { return &Service{ - store: store, - phoneStore: phoneStore, - verificationService: verificationService, - jwtManager: jwtManager, - logger: logger, + store: store, + phoneStore: phoneStore, + logger: logger, } } -// SendVerificationCode 发送验证码 -func (s *Service) SendVerificationCode(ctx context.Context, phone string) error { - return s.verificationService.SendCode(ctx, phone) -} - -// VerifyCode 验证验证码 -func (s *Service) VerifyCode(ctx context.Context, phone string, code string) error { - return s.verificationService.VerifyCode(ctx, phone, code) -} - // UpdateProfile 更新个人资料 func (s *Service) UpdateProfile(ctx context.Context, customerID uint, nickname, avatarURL string) error { customer, err := s.store.GetByID(ctx, customerID) @@ -84,20 +65,6 @@ func (s *Service) UpdateProfile(ctx context.Context, customerID uint, nickname, return nil } -// GetProfile 获取个人资料 -func (s *Service) GetProfile(ctx context.Context, customerID uint) (*model.PersonalCustomer, error) { - customer, err := s.store.GetByID(ctx, customerID) - if err != nil { - s.logger.Error("查询个人客户失败", - zap.Uint("customer_id", customerID), - zap.Error(err), - ) - return nil, errors.Wrap(errors.CodeInternalError, err, "查询个人客户失败") - } - - return customer, nil -} - // GetProfileWithPhone 获取个人资料(包含主手机号) func (s *Service) GetProfileWithPhone(ctx context.Context, customerID uint) (*model.PersonalCustomer, string, error) { // 获取客户信息