This commit is contained in:
2025-08-02 02:54:21 +08:00
parent 934dce2776
commit 66845d3fe0
74 changed files with 8686 additions and 212 deletions

View File

@@ -31,6 +31,19 @@ type EnterpriseInfoItem struct {
LegalPersonPhone string `json:"legal_person_phone"`
EnterpriseAddress string `json:"enterprise_address"`
CreatedAt time.Time `json:"created_at"`
// 合同信息
Contracts []*ContractInfoItem `json:"contracts,omitempty"`
}
// ContractInfoItem 合同信息项
type ContractInfoItem struct {
ID string `json:"id"`
ContractName string `json:"contract_name"`
ContractType string `json:"contract_type"` // 合同类型代码
ContractTypeName string `json:"contract_type_name"` // 合同类型中文名称
ContractFileURL string `json:"contract_file_url"`
CreatedAt time.Time `json:"created_at"`
}
// UserListResponse 用户列表响应
@@ -46,4 +59,9 @@ type UserStatsResponse struct {
TotalUsers int64 `json:"total_users"`
ActiveUsers int64 `json:"active_users"`
CertifiedUsers int64 `json:"certified_users"`
}
// UserDetailResponse 用户详情响应
type UserDetailResponse struct {
*UserListItem
}

View File

@@ -20,5 +20,6 @@ type UserApplicationService interface {
// 管理员功能
ListUsers(ctx context.Context, query *queries.ListUsersQuery) (*responses.UserListResponse, error)
GetUserDetail(ctx context.Context, userID string) (*responses.UserDetailResponse, error)
GetUserStats(ctx context.Context) (*responses.UserStatsResponse, error)
}

View File

@@ -24,6 +24,7 @@ type UserApplicationServiceImpl struct {
userAuthService *user_service.UserAuthService
smsCodeService *user_service.SMSCodeService
walletService finance_service.WalletAggregateService
contractService user_service.ContractAggregateService
eventBus interfaces.EventBus
jwtAuth *middleware.JWTAuthMiddleware
logger *zap.Logger
@@ -35,6 +36,7 @@ func NewUserApplicationService(
userAuthService *user_service.UserAuthService,
smsCodeService *user_service.SMSCodeService,
walletService finance_service.WalletAggregateService,
contractService user_service.ContractAggregateService,
eventBus interfaces.EventBus,
jwtAuth *middleware.JWTAuthMiddleware,
logger *zap.Logger,
@@ -44,6 +46,7 @@ func NewUserApplicationService(
userAuthService: userAuthService,
smsCodeService: smsCodeService,
walletService: walletService,
contractService: contractService,
eventBus: eventBus,
jwtAuth: jwtAuth,
logger: logger,
@@ -342,6 +345,23 @@ func (s *UserApplicationServiceImpl) ListUsers(ctx context.Context, query *queri
EnterpriseAddress: user.EnterpriseInfo.EnterpriseAddress,
CreatedAt: user.EnterpriseInfo.CreatedAt,
}
// 获取企业合同信息
contracts, err := s.contractService.FindByUserID(ctx, user.ID)
if err == nil && len(contracts) > 0 {
contractItems := make([]*responses.ContractInfoItem, 0, len(contracts))
for _, contract := range contracts {
contractItems = append(contractItems, &responses.ContractInfoItem{
ID: contract.ID,
ContractName: contract.ContractName,
ContractType: string(contract.ContractType),
ContractTypeName: contract.GetContractTypeName(),
ContractFileURL: contract.ContractFileURL,
CreatedAt: contract.CreatedAt,
})
}
item.EnterpriseInfo.Contracts = contractItems
}
}
// 添加钱包余额信息
@@ -363,6 +383,72 @@ func (s *UserApplicationServiceImpl) ListUsers(ctx context.Context, query *queri
}, nil
}
// GetUserDetail 获取用户详情(管理员功能)
// 业务流程1. 查询用户详情 2. 构建响应数据
func (s *UserApplicationServiceImpl) GetUserDetail(ctx context.Context, userID string) (*responses.UserDetailResponse, error) {
// 1. 查询用户详情(包含企业信息)
user, err := s.userAggregateService.GetUserWithEnterpriseInfo(ctx, userID)
if err != nil {
return nil, err
}
// 2. 构建响应数据
item := &responses.UserListItem{
ID: user.ID,
Phone: user.Phone,
UserType: user.UserType,
Username: user.Username,
IsActive: user.Active,
IsCertified: user.IsCertified,
LoginCount: user.LoginCount,
LastLoginAt: user.LastLoginAt,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
}
// 添加企业信息
if user.EnterpriseInfo != nil {
item.EnterpriseInfo = &responses.EnterpriseInfoItem{
ID: user.EnterpriseInfo.ID,
CompanyName: user.EnterpriseInfo.CompanyName,
UnifiedSocialCode: user.EnterpriseInfo.UnifiedSocialCode,
LegalPersonName: user.EnterpriseInfo.LegalPersonName,
LegalPersonPhone: user.EnterpriseInfo.LegalPersonPhone,
EnterpriseAddress: user.EnterpriseInfo.EnterpriseAddress,
CreatedAt: user.EnterpriseInfo.CreatedAt,
}
// 获取企业合同信息
contracts, err := s.contractService.FindByUserID(ctx, user.ID)
if err == nil && len(contracts) > 0 {
contractItems := make([]*responses.ContractInfoItem, 0, len(contracts))
for _, contract := range contracts {
contractItems = append(contractItems, &responses.ContractInfoItem{
ID: contract.ID,
ContractName: contract.ContractName,
ContractType: string(contract.ContractType),
ContractTypeName: contract.GetContractTypeName(),
ContractFileURL: contract.ContractFileURL,
CreatedAt: contract.CreatedAt,
})
}
item.EnterpriseInfo.Contracts = contractItems
}
}
// 添加钱包余额信息
wallet, err := s.walletService.LoadWalletByUserId(ctx, user.ID)
if err == nil && wallet != nil {
item.WalletBalance = wallet.Balance.String()
} else {
item.WalletBalance = "0"
}
return &responses.UserDetailResponse{
UserListItem: item,
}, nil
}
// GetUserStats 获取用户统计信息(管理员功能)
// 业务流程1. 查询用户统计信息 2. 构建响应数据
func (s *UserApplicationServiceImpl) GetUserStats(ctx context.Context) (*responses.UserStatsResponse, error) {