user.go
4.9 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package user
import (
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/command"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
"strings"
)
//用户信息
func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
var (
PartnerInfoService = service.NewPartnerInfoService(nil)
partnerInfo *domain.PartnerInfo
)
rsp = &protocol.UserInfoResponse{}
if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
rsp.User = protocol.User{
Id: partnerInfo.Id,
PartnerName: partnerInfo.PartnerName,
Phone: partnerInfo.Account,
CooperateCompany: protocol.Company{
Id: 1,
Name: "福州素天下有限公司",
},
JoinWay: partnerInfo.PartnerCategoryInfo(),
District: partnerInfo.RegionInfo,
SerialNo: partnerInfo.Id,
CooperateTime: partnerInfo.CooperateTime.Unix() * 1000,
}
if len(partnerInfo.Salesman) > 0 {
rsp.User.Salesman = partnerInfo.Salesman[0]
}
return
}
//验证smscode
func CheckSmsCode(header *protocol.RequestHeader, request *protocol.CheckSmsCodeRequest) (rsp *protocol.CheckSmsCodeResponse, err error) {
var (
PartnerInfoService = service.NewPartnerInfoService(nil)
partnerInfo *domain.PartnerInfo
)
if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if _, err = auth.CheckSmsCode(strings.TrimSpace(partnerInfo.Account), request.Captcha); err != nil {
log.Error(err, partnerInfo.Account, request.Captcha)
return
}
return
}
//修改手机号
func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRequest) (rsp *protocol.ChangePhoneResponse, err error) {
var (
PartnerInfoService = service.NewPartnerInfoService(nil)
)
if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if _, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Account: request.Phone}); err == nil {
err = protocol.NewErrWithMessage(2029, err) //账号不存在
return
}
if _, err = auth.CheckSmsCode(request.Phone, request.Captcha); err != nil {
log.Error(err)
return
}
if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Account: request.Phone}); err == nil {
return
}
return
}
//重置密码
func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswordRequest) (rsp *protocol.ResetPasswordResponse, err error) {
var (
PartnerInfoService = service.NewPartnerInfoService(nil)
partnerInfo *domain.PartnerInfo
)
if len(request.NewPwd) < 6 {
err = protocol.NewErrWithMessage(2027)
return
}
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
err = protocol.NewErrWithMessage(2026)
return
}
if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if _, err = auth.CheckSmsCode(partnerInfo.Account, request.Captcha); err != nil {
log.Error(err)
return
}
if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil {
return
}
return
}
//修改密码
func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePasswordRequest) (rsp *protocol.ChangePasswordResponse, err error) {
var (
PartnerInfoService = service.NewPartnerInfoService(nil)
partnerInfo *domain.PartnerInfo
)
rsp = &protocol.ChangePasswordResponse{}
if !strings.EqualFold(request.NewPwd, request.ConfirmPwd) {
err = protocol.NewErrWithMessage(2026)
return
}
if strings.EqualFold(request.NewPwd, request.OldPwd) {
err = protocol.NewErrWithMessage(2030)
return
}
if len(request.NewPwd) < 6 {
err = protocol.NewErrWithMessage(2027)
return
}
if partnerInfo, err = PartnerInfoService.GetPartnerInfo(&query.GetPartnerInfoQuery{Id: int(header.UserId)}); err != nil {
err = protocol.NewErrWithMessage(502, err) //账号不存在
return
}
if !strings.EqualFold(partnerInfo.Password, request.OldPwd) {
//密码不一致
err = protocol.NewErrWithMessage(2028, err) //账号不存在
return
}
if _, err = PartnerInfoService.UpdatePartnerInfo(&command.UpdatePartnerInfoCommand{Password: request.ConfirmPwd}); err == nil {
return
}
return
}