pg_user_create_service.go
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package domainService
import (
"fmt"
coreDomain "github.com/linmadan/egglib-go/core/domain"
pgTransaction "github.com/linmadan/egglib-go/transaction/pg"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go-pp/partner01/pkg/infrastructure/repository"
)
type UserCreateService struct {
coreDomain.BaseEventPublisher
transactionContext *pgTransaction.TransactionContext
}
func (service *UserCreateService) CreateUser(operatorId int64, user *domain.User) (*domain.User, error) {
// 检查操作人权限
var err error
UserRepository, _ := repository.NewUserRepository(service.transactionContext)
//operator,err := UserRepository.FindOne(map[string]interface{}{"userId":operatorId})
//if err!=nil{
// return nil,err
//}
//if operator.AdminType>=domain.NormalUser{
// return nil, fmt.Errorf("权限不足")
//}
if user.UserType&domain.Partner > 0 {
if user.PartnerInfo == nil {
return nil, fmt.Errorf("合伙人信息不能为空")
}
}
user, err = UserRepository.Save(user)
if err != nil {
return nil, err
}
PhoneAuthenticationService, _ := NewPhoneAuthenticationService(service.transactionContext)
if _, err = PhoneAuthenticationService.PhoneAuth(user.UserId, user.UserInfo.UserAccount, ""); err != nil {
return nil, err
}
return user, err
}
func NewUserCreateService(transactionContext *pgTransaction.TransactionContext) (*UserCreateService, error) {
if transactionContext == nil {
return nil, fmt.Errorf("transactionContext参数不能为nil")
} else {
return &UserCreateService{
transactionContext: transactionContext,
}, nil
}
}