refactor: 清理重构遗留的死代码
Some checks failed
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Has been cancelled

- personal_customer.Service: 删除已迁移到 client_auth 的死方法
  (GetProfile/SendVerificationCode/VerifyCode),移除多余的
  verificationService/jwtManager 依赖
- 删除 internal/service/customer/ 整个目录(零引用的早期残留)
This commit is contained in:
2026-03-21 11:33:06 +08:00
parent 95b2334658
commit ed334b946b
3 changed files with 8 additions and 167 deletions

View File

@@ -110,7 +110,7 @@ func initServices(s *stores, deps *Dependencies) *services {
AccountAudit: accountAudit, AccountAudit: accountAudit,
Role: roleSvc.New(s.Role, s.Permission, s.RolePermission), Role: roleSvc.New(s.Role, s.Permission, s.RolePermission),
Permission: permissionSvc.New(s.Permission, s.AccountRole, s.RolePermission, account, deps.Redis), 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( ClientAuth: clientAuthSvc.New(
deps.DB, deps.DB,
s.PersonalCustomerOpenID, s.PersonalCustomerOpenID,

View File

@@ -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)
}

View File

@@ -1,14 +1,11 @@
// Package personal_customer 提供个人客户管理的业务逻辑服务 // Package personal_customer 提供个人客户资料管理的业务逻辑服务
// 包含个人客户注册、登录、微信绑定、短信验证等功能
package personal_customer package personal_customer
import ( import (
"context" "context"
"github.com/break/junhong_cmp_fiber/internal/model" "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/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/auth"
"github.com/break/junhong_cmp_fiber/pkg/errors" "github.com/break/junhong_cmp_fiber/pkg/errors"
"go.uber.org/zap" "go.uber.org/zap"
"gorm.io/gorm" "gorm.io/gorm"
@@ -16,40 +13,24 @@ import (
// Service 个人客户服务 // Service 个人客户服务
type Service struct { type Service struct {
store *postgres.PersonalCustomerStore store *postgres.PersonalCustomerStore
phoneStore *postgres.PersonalCustomerPhoneStore phoneStore *postgres.PersonalCustomerPhoneStore
verificationService *verification.Service logger *zap.Logger
jwtManager *auth.JWTManager
logger *zap.Logger
} }
// NewService 创建个人客户服务实例 // NewService 创建个人客户服务实例
func NewService( func NewService(
store *postgres.PersonalCustomerStore, store *postgres.PersonalCustomerStore,
phoneStore *postgres.PersonalCustomerPhoneStore, phoneStore *postgres.PersonalCustomerPhoneStore,
verificationService *verification.Service,
jwtManager *auth.JWTManager,
logger *zap.Logger, logger *zap.Logger,
) *Service { ) *Service {
return &Service{ return &Service{
store: store, store: store,
phoneStore: phoneStore, phoneStore: phoneStore,
verificationService: verificationService, logger: logger,
jwtManager: jwtManager,
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 更新个人资料 // UpdateProfile 更新个人资料
func (s *Service) UpdateProfile(ctx context.Context, customerID uint, nickname, avatarURL string) error { func (s *Service) UpdateProfile(ctx context.Context, customerID uint, nickname, avatarURL string) error {
customer, err := s.store.GetByID(ctx, customerID) customer, err := s.store.GetByID(ctx, customerID)
@@ -84,20 +65,6 @@ func (s *Service) UpdateProfile(ctx context.Context, customerID uint, nickname,
return nil 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 获取个人资料(包含主手机号) // GetProfileWithPhone 获取个人资料(包含主手机号)
func (s *Service) GetProfileWithPhone(ctx context.Context, customerID uint) (*model.PersonalCustomer, string, error) { func (s *Service) GetProfileWithPhone(ctx context.Context, customerID uint) (*model.PersonalCustomer, string, error) {
// 获取客户信息 // 获取客户信息