pg_auth_services.go
1.8 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
53
54
package domain_service
import (
"github.com/tiptok/gocomm/xa/eda"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
)
type PgAuthService struct {
eda.EventCenterPublisher
//transactionContext *transaction.TransactionContext
manager *PgManagerAuthService
partner *PgPartnerAuthService
}
func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
return &PgAuthService{
manager: NewPgManagerAuthService(ctx),
partner: NewPgPartnerAuthService(ctx),
}
}
func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) // 合伙人修改手机号
errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) // 高管修改手机号
return errResolve(errPartner, errManager)
}
func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
errPartner := s.partner.ChangeUserPassword(userId, newPwd, oldPwd, phone)
errManager := s.manager.ChangeUserPassword(userId, newPwd, oldPwd, phone)
return errResolve(errPartner, errManager)
}
func (s *PgAuthService) ResetUserPassword(userId int64, phone, password string) (err error) {
errPartner := s.partner.ResetUserPassword(userId, phone, password)
errManager := s.manager.ResetUserPassword(userId, phone, password)
return errResolve(errPartner, errManager)
}
func errResolve(errPartner, errManager error) (err error) {
if errPartner != nil {
log.Error("partner:", errPartner)
}
if errManager != nil {
log.Error("mannager:", errManager)
}
if errPartner != nil && errManager != nil {
err = errPartner
if err == errUserNotFound && errManager != errUserNotFound {
err = errManager
}
return
}
return
}