...
|
...
|
@@ -7,6 +7,8 @@ import ( |
|
|
"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/infrastructure/pg/transaction"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
|
|
|
"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
|
|
|
protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth"
|
...
|
...
|
@@ -137,6 +139,13 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe |
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
// 管理员不支持修改手机号
|
|
|
if header.AdminType == int(protocolx.AdminTypeManager) {
|
|
|
//if err=changeUserPhone(header.UserId,request.Phone,transactionContext);err!=nil{
|
|
|
// err = protocol.NewCustomMessage(1,err.Error())
|
|
|
//}
|
|
|
return
|
|
|
}
|
|
|
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
return
|
...
|
...
|
@@ -183,6 +192,12 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo |
|
|
err = protocol.NewErrWithMessage(2026)
|
|
|
return
|
|
|
}
|
|
|
if header.AdminType == int(protocolx.AdminTypeManager) {
|
|
|
if err = changeUserInfo(header.UserId, fmt.Sprintf("%v", header.SimNum), request.NewPwd, transactionContext); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, err.Error())
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
|
|
|
err = protocol.NewErrWithMessage(502, err) //账号不存在
|
|
|
return
|
...
|
...
|
@@ -226,6 +241,12 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass |
|
|
err = protocol.NewErrWithMessage(2026)
|
|
|
return
|
|
|
}
|
|
|
if header.AdminType == int(protocolx.AdminTypeManager) {
|
|
|
if err = changeUserPassword(header.UserId, request.NewPwd, request.OldPwd, fmt.Sprintf("%v", header.SimNum), transactionContext); err != nil {
|
|
|
err = protocol.NewCustomMessage(1, err.Error())
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
if strings.EqualFold(request.NewPwd, request.OldPwd) {
|
|
|
err = protocol.NewErrWithMessage(2030)
|
|
|
return
|
...
|
...
|
@@ -368,3 +389,53 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques |
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
|
|
func changeUserInfo(userId int64, phone, password string, transactionContext *transaction.TransactionContext) (err error) {
|
|
|
var (
|
|
|
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
|
|
|
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
|
|
|
user *domain.Users
|
|
|
)
|
|
|
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
|
|
|
log.Error(err)
|
|
|
err = fmt.Errorf("用户不存在")
|
|
|
return
|
|
|
}
|
|
|
_, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, password)
|
|
|
return
|
|
|
}
|
|
|
func changeUserPhone(userId int64, phone string, transactionContext *transaction.TransactionContext) (err error) {
|
|
|
var (
|
|
|
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
|
|
|
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
|
|
|
user *domain.Users
|
|
|
)
|
|
|
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
|
|
|
log.Error(err)
|
|
|
err = fmt.Errorf("用户不存在")
|
|
|
return
|
|
|
}
|
|
|
if newUser, e := UsersRepository.FindOne(map[string]interface{}{"phone": phone}); e == nil || newUser != nil {
|
|
|
err = protocol.NewErrWithMessage(2029, err)
|
|
|
return
|
|
|
}
|
|
|
_, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, "")
|
|
|
if err != nil {
|
|
|
_, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId)
|
|
|
}
|
|
|
return
|
|
|
}
|
|
|
func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) {
|
|
|
var (
|
|
|
ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
|
|
|
UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
|
|
|
user *domain.Users
|
|
|
)
|
|
|
if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
|
|
|
log.Error(err)
|
|
|
err = fmt.Errorf("用户不存在")
|
|
|
return
|
|
|
}
|
|
|
_, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd)
|
|
|
return
|
|
|
} |
...
|
...
|
|