作者 yangfu

增加:密码修改,用户权限认证

@@ -140,9 +140,11 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT @@ -140,9 +140,11 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT
140 transactionContext, _ = factory.CreateTransactionContext(nil) 140 transactionContext, _ = factory.CreateTransactionContext(nil)
141 PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext) 141 PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
142 UsersRepository, _ = factory.CreateUsersRepository(transactionContext) 142 UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
  143 + CompanyRepository, _ = factory.CreateCompanyRepository(transactionContext)
143 144
144 partnerInfo *domain.PartnerInfo 145 partnerInfo *domain.PartnerInfo
145 user *domain.Users 146 user *domain.Users
  147 + company *domain.Company
146 userId int64 148 userId int64
147 ) 149 )
148 150
@@ -162,6 +164,11 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT @@ -162,6 +164,11 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT
162 err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt refrshToken (%v) valid", request.RefreshToken)) 164 err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt refrshToken (%v) valid", request.RefreshToken))
163 return 165 return
164 } 166 }
  167 + if company, err = CompanyRepository.FindOne(map[string]interface{}{"id": claim.CompanyId, "status": 1, "enable": 1}); err != nil || company == nil {
  168 + log.Error(err)
  169 + err = protocol.NewErrWithMessage(4140, err)
  170 + return
  171 + }
165 172
166 switch claim.AdminType { 173 switch claim.AdminType {
167 case int(protocolx.AdminTypePartner): 174 case int(protocolx.AdminTypePartner):
@@ -211,7 +211,11 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo @@ -211,7 +211,11 @@ func getPartners(userId int64, request *protocolx.PartnersRequest, transactionCo
211 queryOption["districts"] = districts 211 queryOption["districts"] = districts
212 } 212 }
213 if len(request.JoinWays) > 0 { 213 if len(request.JoinWays) > 0 {
214 - queryOption["joinWays"] = request.JoinWays 214 + var joinWays []int64
  215 + for i := 0; i < len(request.JoinWays); i++ {
  216 + joinWays = append(joinWays, request.JoinWays[i].Type)
  217 + }
  218 + queryOption["joinWays"] = joinWays
215 } 219 }
216 if request.StartTime > 0 { 220 if request.StartTime > 0 {
217 queryOption["startTime"] = request.StartTime / 1000 221 queryOption["startTime"] = request.StartTime / 1000
@@ -12,8 +12,9 @@ import ( @@ -12,8 +12,9 @@ import (
12 // 分红统计 12 // 分红统计
13 func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsResponse, err error) { 13 func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatisticsRequest) (rsp *protocol.DividendStatisticsResponse, err error) {
14 var ( 14 var (
15 - transactionContext, _ = factory.CreateTransactionContext(nil)  
16 - OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext) 15 + transactionContext, _ = factory.CreateTransactionContext(nil)
  16 + OrderBaseResponsitory, _ = factory.CreateOrderBaseRepository(transactionContext)
  17 + BusinessBonusRepository, _ = factory.CreateBusinessBonusRepository(transactionContext)
17 ) 18 )
18 if err = transactionContext.StartTransaction(); err != nil { 19 if err = transactionContext.StartTransaction(); err != nil {
19 return nil, err 20 return nil, err
@@ -33,6 +34,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis @@ -33,6 +34,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DividendStatis
33 } 34 }
34 bonusAll := AllBonusStatics(orderAll, 0) 35 bonusAll := AllBonusStatics(orderAll, 0)
35 bonusQuarters := QuartersBonusStatics(orderBetween, 0) 36 bonusQuarters := QuartersBonusStatics(orderBetween, 0)
  37 + if bonus, e := BusinessBonusRepository.FindOne(map[string]interface{}{"partner_id": header.UserId, "isDisable": 1}); e == nil {
  38 + bonusAll.Receivable += bonus.Bonus
  39 + }
36 rsp = &protocol.DividendStatisticsResponse{} 40 rsp = &protocol.DividendStatisticsResponse{}
37 rsp.Statistics = protocol.DividendStatistics{ 41 rsp.Statistics = protocol.DividendStatistics{
38 Received: bonusAll.Received, 42 Received: bonusAll.Received,
@@ -7,6 +7,8 @@ import ( @@ -7,6 +7,8 @@ import (
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/query"
8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/partnerInfo/service"
9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
  10 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/svr"
10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 12 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
11 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 13 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
12 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth" 14 protocolx "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol/auth"
@@ -137,6 +139,13 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe @@ -137,6 +139,13 @@ func ChangePhone(header *protocol.RequestHeader, request *protocol.ChangePhoneRe
137 defer func() { 139 defer func() {
138 transactionContext.RollbackTransaction() 140 transactionContext.RollbackTransaction()
139 }() 141 }()
  142 + // 管理员不支持修改手机号
  143 + if header.AdminType == int(protocolx.AdminTypeManager) {
  144 + //if err=changeUserPhone(header.UserId,request.Phone,transactionContext);err!=nil{
  145 + // err = protocol.NewCustomMessage(1,err.Error())
  146 + //}
  147 + return
  148 + }
140 if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { 149 if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
141 err = protocol.NewErrWithMessage(502, err) //账号不存在 150 err = protocol.NewErrWithMessage(502, err) //账号不存在
142 return 151 return
@@ -183,6 +192,12 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo @@ -183,6 +192,12 @@ func ResetPassword(header *protocol.RequestHeader, request *protocol.ResetPasswo
183 err = protocol.NewErrWithMessage(2026) 192 err = protocol.NewErrWithMessage(2026)
184 return 193 return
185 } 194 }
  195 + if header.AdminType == int(protocolx.AdminTypeManager) {
  196 + if err = changeUserInfo(header.UserId, fmt.Sprintf("%v", header.SimNum), request.NewPwd, transactionContext); err != nil {
  197 + err = protocol.NewCustomMessage(1, err.Error())
  198 + }
  199 + return
  200 + }
186 if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil { 201 if partnerInfo, err = PartnerInfoService.FindOne(map[string]interface{}{"id": header.UserId}); err != nil {
187 err = protocol.NewErrWithMessage(502, err) //账号不存在 202 err = protocol.NewErrWithMessage(502, err) //账号不存在
188 return 203 return
@@ -226,6 +241,12 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass @@ -226,6 +241,12 @@ func ChangePassword(header *protocol.RequestHeader, request *protocol.ChangePass
226 err = protocol.NewErrWithMessage(2026) 241 err = protocol.NewErrWithMessage(2026)
227 return 242 return
228 } 243 }
  244 + if header.AdminType == int(protocolx.AdminTypeManager) {
  245 + if err = changeUserPassword(header.UserId, request.NewPwd, request.OldPwd, fmt.Sprintf("%v", header.SimNum), transactionContext); err != nil {
  246 + err = protocol.NewCustomMessage(1, err.Error())
  247 + }
  248 + return
  249 + }
229 if strings.EqualFold(request.NewPwd, request.OldPwd) { 250 if strings.EqualFold(request.NewPwd, request.OldPwd) {
230 err = protocol.NewErrWithMessage(2030) 251 err = protocol.NewErrWithMessage(2030)
231 return 252 return
@@ -368,3 +389,53 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques @@ -368,3 +389,53 @@ func UserInfoV2(header *protocol.RequestHeader, request *protocol.UserInfoReques
368 err = transactionContext.CommitTransaction() 389 err = transactionContext.CommitTransaction()
369 return 390 return
370 } 391 }
  392 +
  393 +func changeUserInfo(userId int64, phone, password string, transactionContext *transaction.TransactionContext) (err error) {
  394 + var (
  395 + ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
  396 + UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
  397 + user *domain.Users
  398 + )
  399 + if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
  400 + log.Error(err)
  401 + err = fmt.Errorf("用户不存在")
  402 + return
  403 + }
  404 + _, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, password)
  405 + return
  406 +}
  407 +func changeUserPhone(userId int64, phone string, transactionContext *transaction.TransactionContext) (err error) {
  408 + var (
  409 + ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
  410 + UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
  411 + user *domain.Users
  412 + )
  413 + if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
  414 + log.Error(err)
  415 + err = fmt.Errorf("用户不存在")
  416 + return
  417 + }
  418 + if newUser, e := UsersRepository.FindOne(map[string]interface{}{"phone": phone}); e == nil || newUser != nil {
  419 + err = protocol.NewErrWithMessage(2029, err)
  420 + return
  421 + }
  422 + _, err = ucenterApiGateway.UpdateUserPassword(user.OpenId, phone, "")
  423 + if err != nil {
  424 + _, err = transactionContext.PgTx.Exec("update users set phone=? where id=?", phone, userId)
  425 + }
  426 + return
  427 +}
  428 +func changeUserPassword(userId int64, newPwd, oldPwd, phone string, transactionContext *transaction.TransactionContext) (err error) {
  429 + var (
  430 + ucenterApiGateway = svr.NewHttplibUCenterApiServiceGateway()
  431 + UsersRepository, _ = factory.CreateUsersRepository(transactionContext)
  432 + user *domain.Users
  433 + )
  434 + if user, err = UsersRepository.FindOne(map[string]interface{}{"id": userId}); err != nil || user == nil {
  435 + log.Error(err)
  436 + err = fmt.Errorf("用户不存在")
  437 + return
  438 + }
  439 + _, err = ucenterApiGateway.ChangePassword(phone, newPwd, oldPwd)
  440 + return
  441 +}
@@ -11,6 +11,9 @@ var MMM_SMS_SERVICE_HOST = "https://sms.fjmaimaimai.com:9897" @@ -11,6 +11,9 @@ var MMM_SMS_SERVICE_HOST = "https://sms.fjmaimaimai.com:9897"
11 var UCENTER_SERVICE_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com" 11 var UCENTER_SERVICE_HOST = "https://suplus-ucenter-dev.fjmaimaimai.com"
12 var UCENTER_APP_KEY = "0c2c2a23dfc64ae230f5c54ab243ab52" 12 var UCENTER_APP_KEY = "0c2c2a23dfc64ae230f5c54ab243ab52"
13 13
  14 +var BUSINESS_ADMIN_SERVICE_HOST = "http://suplus-business-admin-dev.fjmaimaimai.com"
  15 +var BUSINESS_ADMIN_PLATFORM_ID = "25" //合伙人模块
  16 +
14 func init() { 17 func init() {
15 if os.Getenv("LOG_LEVEL") != "" { 18 if os.Getenv("LOG_LEVEL") != "" {
16 LOG_LEVEL = os.Getenv("LOG_LEVEL") 19 LOG_LEVEL = os.Getenv("LOG_LEVEL")
@@ -18,4 +21,7 @@ func init() { @@ -18,4 +21,7 @@ func init() {
18 if os.Getenv("UCENTER_SERVICE_HOST") != "" { 21 if os.Getenv("UCENTER_SERVICE_HOST") != "" {
19 UCENTER_SERVICE_HOST = os.Getenv("UCENTER_SERVICE_HOST") 22 UCENTER_SERVICE_HOST = os.Getenv("UCENTER_SERVICE_HOST")
20 } 23 }
  24 + if os.Getenv("BUSINESS_ADMIN_SERVICE_HOST") != "" {
  25 + BUSINESS_ADMIN_SERVICE_HOST = os.Getenv("BUSINESS_ADMIN_SERVICE_HOST")
  26 + }
21 } 27 }
@@ -24,6 +24,8 @@ type Company struct { @@ -24,6 +24,8 @@ type Company struct {
24 UpdateAt time.Time `json:"updateAt"` 24 UpdateAt time.Time `json:"updateAt"`
25 // 删除时间 25 // 删除时间
26 DeleteAt time.Time `json:"deleteAt"` 26 DeleteAt time.Time `json:"deleteAt"`
  27 + // 是否开启合伙人模块,是否有效【1:有效】【2:无效】
  28 + Enable int8 `json:"enable"`
27 } 29 }
28 30
29 type CompanyRepository interface { 31 type CompanyRepository interface {
@@ -44,6 +44,8 @@ type Users struct { @@ -44,6 +44,8 @@ type Users struct {
44 DeleteAt time.Time `json:"deleteAt"` 44 DeleteAt time.Time `json:"deleteAt"`
45 // 可查看的合伙人信息 45 // 可查看的合伙人信息
46 AccessPartners []*PartnerInfo 46 AccessPartners []*PartnerInfo
  47 + // 1普通用户 2主管理员
  48 + AdminType int8 `json:"adminType"`
47 } 49 }
48 50
49 func (Users *Users) AccessPartnerIds() []int64 { 51 func (Users *Users) AccessPartnerIds() []int64 {
@@ -2,6 +2,7 @@ package domain_service @@ -2,6 +2,7 @@ package domain_service
2 2
3 import ( 3 import (
4 "github.com/tiptok/gocomm/xa/eda" 4 "github.com/tiptok/gocomm/xa/eda"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/domain"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/dao" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/dao"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction" 8 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
@@ -54,8 +55,12 @@ func (svr *PgLoginService) ManagerLogin(phone string, password string) (err erro @@ -54,8 +55,12 @@ func (svr *PgLoginService) ManagerLogin(phone string, password string) (err erro
54 err = protocol.NewErrWithMessage(502, err) //账号不存在 55 err = protocol.NewErrWithMessage(502, err) //账号不存在
55 return 56 return
56 } 57 }
  58 + var openid int64
57 ucenerSvr := http_gateway.NewHttplibUCenterApiServiceGateway() 59 ucenerSvr := http_gateway.NewHttplibUCenterApiServiceGateway()
58 - _, err = ucenerSvr.ServerLogin(phone, password, 1) 60 + openid, err = ucenerSvr.ServerLogin(phone, password, 1)
  61 + if err == nil && openid > 0 {
  62 + _, err = svr.transactionContext.PgTx.Exec("update users set open_id=? where phone=?", openid, phone)
  63 + }
59 return 64 return
60 } 65 }
61 66
@@ -137,7 +142,8 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { @@ -137,7 +142,8 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
137 return nil, nil 142 return nil, nil
138 } 143 }
139 var ( 144 var (
140 - companyList []*domain.Company 145 + companyList []*domain.Company
  146 + adminApiGateway = http_gateway.NewHttplibBusinessAdminApiServiceGateway()
141 ) 147 )
142 doGetCompanyIds := func() []int64 { 148 doGetCompanyIds := func() []int64 {
143 var companies []int64 149 var companies []int64
@@ -150,13 +156,23 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) { @@ -150,13 +156,23 @@ func (svr *PgLoginService) ManagerStaticInfo() (interface{}, error) {
150 var companys = make([]protocol.CompanyBase, 0) 156 var companys = make([]protocol.CompanyBase, 0)
151 for i := range companyList { 157 for i := range companyList {
152 c := companyList[i] 158 c := companyList[i]
153 - //var user *domain.Users  
154 - //for j:=range svr.Users{  
155 - // if svr.Users[j].CompanyId==c.Id{  
156 - // user = svr.Users[j]  
157 - // break  
158 - // }  
159 - //} 159 +
  160 + //通过企业平台 校验模块权限
  161 + var user *domain.Users
  162 + for j := range svr.Users {
  163 + if svr.Users[j].CompanyId == c.Id {
  164 + user = svr.Users[j]
  165 + break
  166 + }
  167 + }
  168 + if user != nil {
  169 + if code, e := adminApiGateway.UserAuth(user.Id, constant.BUSINESS_ADMIN_PLATFORM_ID); e != nil || code != 0 {
  170 + log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, code, e.Error())
  171 + continue
  172 + } else {
  173 + log.Debug("【检查权限】", svr.Phone, "【公司】", c.Id, user.Id, code, e)
  174 + }
  175 + }
160 item := newCompanyBase(c) 176 item := newCompanyBase(c)
161 companys = append(companys, item) 177 companys = append(companys, item)
162 } 178 }
@@ -25,4 +25,6 @@ type Company struct { @@ -25,4 +25,6 @@ type Company struct {
25 UpdateAt time.Time 25 UpdateAt time.Time
26 // 删除时间 26 // 删除时间
27 DeleteAt time.Time 27 DeleteAt time.Time
  28 + // 是否开启合伙人模块,是否有效【1:有效】【2:无效】
  29 + Enable int8
28 } 30 }
@@ -48,4 +48,6 @@ type Users struct { @@ -48,4 +48,6 @@ type Users struct {
48 DeleteAt time.Time 48 DeleteAt time.Time
49 // 可查看的合伙人信息 49 // 可查看的合伙人信息
50 AccessPartners []*domain.PartnerInfo 50 AccessPartners []*domain.PartnerInfo
  51 + // 1普通用户 2主管理员
  52 + AdminType int8
51 } 53 }
@@ -49,8 +49,10 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{} @@ -49,8 +49,10 @@ func (repository *CompanyRepository) FindOne(queryOptions map[string]interface{}
49 CompanyModel := new(models.Company) 49 CompanyModel := new(models.Company)
50 query := NewQuery(tx.Model(CompanyModel), queryOptions) 50 query := NewQuery(tx.Model(CompanyModel), queryOptions)
51 query.SetWhere(`"company".id = ?`, "id") 51 query.SetWhere(`"company".id = ?`, "id")
  52 + query.SetWhere(`"company".status = ?`, "status")
  53 + query.SetWhere(`"company".enable = ?`, "enable")
52 if err := query.First(); err != nil { 54 if err := query.First(); err != nil {
53 - return nil, query.HandleError(err, "没有此订单") 55 + return nil, query.HandleError(err, "没有此公司")
54 } 56 }
55 if CompanyModel.Id == 0 { 57 if CompanyModel.Id == 0 {
56 return nil, nil 58 return nil, nil
  1 +package svr
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
  6 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
  7 + "strconv"
  8 + "strings"
  9 + "time"
  10 +)
  11 +
  12 +type HttplibBusinessAdminApiServiceGateway struct {
  13 + httplibBaseServiceGateway
  14 +}
  15 +
  16 +// 服务登录
  17 +func (serviceGateway *HttplibBusinessAdminApiServiceGateway) UserAuth(userId int64, platformId string) (int, error) {
  18 + url := strings.Join([]string{serviceGateway.baseURL, "auth", "get-user-auth"}, "/")
  19 + request := serviceGateway.createRequest(url, "post")
  20 + request.Header("appKey", constant.UCENTER_APP_KEY)
  21 + options := make(map[string]interface{})
  22 + options["userId"] = fmt.Sprintf("%v", userId)
  23 + options["platformId"] = fmt.Sprintf("%v", platformId)
  24 + request.JSONBody(options)
  25 + response := make(map[string]interface{})
  26 + err := request.ToJSON(&response)
  27 + if err != nil {
  28 + log.Error("Service Gateway Fail:", err)
  29 + return 0, err
  30 + }
  31 + return serviceGateway.handlerError(response)
  32 +}
  33 +
  34 +func (serviceGateway *HttplibBusinessAdminApiServiceGateway) handlerError(in map[string]interface{}) (int, error) {
  35 + var rspCode int
  36 + var err error
  37 + if code, ok := in["code"]; ok {
  38 + rspCode, _ = strconv.Atoi(fmt.Sprintf("%v", code))
  39 + } else {
  40 + err = fmt.Errorf("网关解析错误")
  41 + }
  42 + if msg, ok := in["msg"]; ok {
  43 + msg := msg.(string)
  44 + if rspCode != 0 && len(msg) > 0 {
  45 + err = fmt.Errorf(msg)
  46 + }
  47 + }
  48 + return rspCode, err
  49 +}
  50 +
  51 +func NewHttplibBusinessAdminApiServiceGateway() *HttplibBusinessAdminApiServiceGateway {
  52 + return &HttplibBusinessAdminApiServiceGateway{
  53 + httplibBaseServiceGateway: httplibBaseServiceGateway{
  54 + baseURL: constant.BUSINESS_ADMIN_SERVICE_HOST,
  55 + connectTimeout: 100 * time.Second,
  56 + readWriteTimeout: 30 * time.Second,
  57 + },
  58 + }
  59 +}
@@ -14,7 +14,7 @@ type HttplibUCenterApiServiceGateway struct { @@ -14,7 +14,7 @@ type HttplibUCenterApiServiceGateway struct {
14 } 14 }
15 15
16 // 服务登录 16 // 服务登录
17 -func (serviceGateway *HttplibUCenterApiServiceGateway) ServerLogin(phone, password string, loginType int) (int, error) { 17 +func (serviceGateway *HttplibUCenterApiServiceGateway) ServerLogin(phone, password string, loginType int) (int64, error) {
18 url := strings.Join([]string{serviceGateway.baseURL, "auth", "serverLogin"}, "/") 18 url := strings.Join([]string{serviceGateway.baseURL, "auth", "serverLogin"}, "/")
19 request := serviceGateway.createRequest(url, "post") 19 request := serviceGateway.createRequest(url, "post")
20 request.Header("appKey", constant.UCENTER_APP_KEY) 20 request.Header("appKey", constant.UCENTER_APP_KEY)
@@ -24,28 +24,56 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ServerLogin(phone, passwo @@ -24,28 +24,56 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ServerLogin(phone, passwo
24 options["type"] = loginType 24 options["type"] = loginType
25 request.JSONBody(options) 25 request.JSONBody(options)
26 response := make(map[string]interface{}) 26 response := make(map[string]interface{})
27 - //data,_:=request.Bytes()  
28 - //fmt.Println(string(data))  
29 err := request.ToJSON(&response) 27 err := request.ToJSON(&response)
  28 + var openid int64
30 if err != nil { 29 if err != nil {
31 log.Error("Service Gateway Fail:", err) 30 log.Error("Service Gateway Fail:", err)
32 return 0, err 31 return 0, err
33 } 32 }
34 - return serviceGateway.handlerError(response) 33 + if data, ok := response["data"]; ok {
  34 + if data, ok := data.(map[string]interface{}); ok {
  35 + if data, ok := data["id"]; ok {
  36 + openid = int64(data.(float64))
  37 + //openid,err=strconv.ParseInt(fmt.Sprintf("%v",data.(float64)),10,64)
  38 + }
  39 + }
  40 + }
  41 + _, err = serviceGateway.handlerError(response)
  42 + return openid, err
35 } 43 }
36 44
37 // 修改密码 45 // 修改密码
38 func (serviceGateway *HttplibUCenterApiServiceGateway) UpdateUserPassword(uid int64, phone, password string) (int, error) { 46 func (serviceGateway *HttplibUCenterApiServiceGateway) UpdateUserPassword(uid int64, phone, password string) (int, error) {
39 url := strings.Join([]string{serviceGateway.baseURL, "users", fmt.Sprintf("%v", uid)}, "/") 47 url := strings.Join([]string{serviceGateway.baseURL, "users", fmt.Sprintf("%v", uid)}, "/")
40 request := serviceGateway.createRequest(url, "put") 48 request := serviceGateway.createRequest(url, "put")
  49 + //request.Header("appKey", constant.UCENTER_APP_KEY)
  50 + options := make(map[string]interface{})
  51 + if len(phone) > 0 {
  52 + options["phone"] = strings.TrimSpace(phone)
  53 + }
  54 + if len(password) > 0 {
  55 + options["password"] = strings.TrimSpace(password)
  56 + }
  57 + request.JSONBody(options)
  58 + response := make(map[string]interface{})
  59 + err := request.ToJSON(&response)
  60 + if err != nil {
  61 + log.Error("Service Gateway Fail:", err)
  62 + return 0, err
  63 + }
  64 + return serviceGateway.handlerError(response)
  65 +}
  66 +func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, newPwd, oldPwd string) (int, error) {
  67 + url := strings.Join([]string{serviceGateway.baseURL, "users", "changePassword"}, "/")
  68 + request := serviceGateway.createRequest(url, "post")
41 request.Header("appKey", constant.UCENTER_APP_KEY) 69 request.Header("appKey", constant.UCENTER_APP_KEY)
42 options := make(map[string]interface{}) 70 options := make(map[string]interface{})
43 options["phone"] = strings.TrimSpace(phone) 71 options["phone"] = strings.TrimSpace(phone)
44 - options["password"] = strings.TrimSpace(password) 72 + options["newPassword"] = strings.TrimSpace(newPwd)
  73 + //options["confirmPwd"] = strings.TrimSpace(confirmPwd)
  74 + options["password"] = strings.TrimSpace(oldPwd)
45 request.JSONBody(options) 75 request.JSONBody(options)
46 response := make(map[string]interface{}) 76 response := make(map[string]interface{})
47 - //data,_:=request.Bytes()  
48 - //fmt.Println(string(data))  
49 err := request.ToJSON(&response) 77 err := request.ToJSON(&response)
50 if err != nil { 78 if err != nil {
51 log.Error("Service Gateway Fail:", err) 79 log.Error("Service Gateway Fail:", err)
@@ -67,19 +67,19 @@ func (this *UserController) ChangePhone() { @@ -67,19 +67,19 @@ func (this *UserController) ChangePhone() {
67 msg = m 67 msg = m
68 return 68 return
69 } 69 }
70 - if !CacheSms.IsExist(request.OldPhone) {  
71 - msg = protocol.NewMesage(1009) //验证码失效  
72 - return  
73 - }  
74 - if v := CacheSms.Get(request.OldPhone); v != nil {  
75 - if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {  
76 - msg = protocol.NewMesage(1012) //验证码不一致  
77 - return  
78 - }  
79 - } else {  
80 - msg = protocol.NewMesage(1009) //验证码不一致  
81 - return  
82 - } 70 + //if !CacheSms.IsExist(request.OldPhone) {
  71 + // msg = protocol.NewMesage(1009) //验证码失效
  72 + // return
  73 + //}
  74 + //if v := CacheSms.Get(request.OldPhone); v != nil {
  75 + // if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {
  76 + // msg = protocol.NewMesage(1012) //验证码不一致
  77 + // return
  78 + // }
  79 + //} else {
  80 + // msg = protocol.NewMesage(1009) //验证码不一致
  81 + // return
  82 + //}
83 header := this.GetRequestHeader(this.Ctx) 83 header := this.GetRequestHeader(this.Ctx)
84 data, err := user.ChangePhone(header, request) 84 data, err := user.ChangePhone(header, request)
85 if err == nil { 85 if err == nil {
@@ -12,7 +12,7 @@ type PartnersRequest struct { @@ -12,7 +12,7 @@ type PartnersRequest struct {
12 // 区域(空或不传,即所有区域) 12 // 区域(空或不传,即所有区域)
13 Districts []Districts `json:"districts"` 13 Districts []Districts `json:"districts"`
14 // 合作类型(空或不传,即所有类型) 14 // 合作类型(空或不传,即所有类型)
15 - JoinWays []int64 `json:"joinWays"` 15 + JoinWays []JoinWays `json:"joinWays"`
16 // 分红排序(0.从多到少 1.从少到多) 16 // 分红排序(0.从多到少 1.从少到多)
17 SortBy int `json:"sortBy"` 17 SortBy int `json:"sortBy"`
18 } 18 }