作者 陈志颖

合并分支 'dev' 到 'test'

Dev



查看合并请求 !16
@@ -66,6 +66,8 @@ spec: @@ -66,6 +66,8 @@ spec:
66 value: "31543" 66 value: "31543"
67 - name: LOG_LEVEL 67 - name: LOG_LEVEL
68 value: "debug" 68 value: "debug"
  69 + - name: LOG_PREFIX
  70 + value: "[partner_dev]"
69 - name: ERROR_BASE_CODE 71 - name: ERROR_BASE_CODE
70 value: "1" 72 value: "1"
71 - name: ERROR_BASE_CODE_MULTIPLE 73 - name: ERROR_BASE_CODE_MULTIPLE
@@ -66,6 +66,8 @@ spec: @@ -66,6 +66,8 @@ spec:
66 value: "15432" 66 value: "15432"
67 - name: LOG_LEVEL 67 - name: LOG_LEVEL
68 value: "debug" 68 value: "debug"
  69 + - name: LOG_PREFIX
  70 + value: "[partner_prd]"
69 - name: ERROR_BASE_CODE 71 - name: ERROR_BASE_CODE
70 value: "1" 72 value: "1"
71 - name: ERROR_BASE_CODE_MULTIPLE 73 - name: ERROR_BASE_CODE_MULTIPLE
@@ -66,6 +66,8 @@ spec: @@ -66,6 +66,8 @@ spec:
66 value: "31543" 66 value: "31543"
67 - name: LOG_LEVEL 67 - name: LOG_LEVEL
68 value: "debug" 68 value: "debug"
  69 + - name: LOG_PREFIX
  70 + value: "[partner_test]"
69 - name: ERROR_BASE_CODE 71 - name: ERROR_BASE_CODE
70 value: "1" 72 value: "1"
71 - name: ERROR_BASE_CODE_MULTIPLE 73 - name: ERROR_BASE_CODE_MULTIPLE
@@ -8,6 +8,8 @@ import ( @@ -8,6 +8,8 @@ import (
8 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg" 8 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg"
9 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis" 9 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/redis"
10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
  11 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama"
  12 +
11 //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr" 13 //"gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/ginsvr"
12 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr" 14 _ "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/appsvr"
13 ) 15 )
@@ -23,5 +25,8 @@ func main() { @@ -23,5 +25,8 @@ func main() {
23 //注册事件 25 //注册事件
24 event.InitEventCenter() 26 event.InitEventCenter()
25 27
  28 + //启动kafaka消息订阅
  29 + go sarama.Run()
  30 +
26 beego.Run() 31 beego.Run()
27 } 32 }
@@ -301,6 +301,48 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol. @@ -301,6 +301,48 @@ func UCenterRevoke(header *protocol.RequestHeader, userId int64) (rsp *protocol.
301 return 301 return
302 } 302 }
303 303
  304 +// 企业平台-密码校验
  305 +func PasswordLogin(header *protocol.RequestHeader, request *protocol.LoginRequest) (v interface{}, err error) {
  306 + var (
  307 + transactionContext, _ = factory.CreateTransactionContext(nil)
  308 + loginSvr = domain_service.NewPgLoginService(transactionContext)
  309 + )
  310 +
  311 + if err = transactionContext.StartTransaction(); err != nil {
  312 + log.Error(err)
  313 + return nil, err
  314 + }
  315 +
  316 + defer func() {
  317 + transactionContext.RollbackTransaction()
  318 + }()
  319 +
  320 + // loginSvr 初始化
  321 + loginSvr.Init(request.Phone)
  322 +
  323 + if len(loginSvr.Users) == 0 && len(loginSvr.PartnerInfo) == 0 {
  324 + v = map[string]interface{}{}
  325 + err = protocol.NewErrWithMessage(10001)
  326 + return
  327 + }
  328 +
  329 + if len(request.Password) == 0 {
  330 + v = map[string]interface{}{}
  331 + err = protocol.NewCustomMessage(1, "密码不能为空!")
  332 + return
  333 + }
  334 +
  335 + if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
  336 + v = map[string]interface{}{}
  337 + err = protocol.NewCustomMessage(1, "密码输入有误!")
  338 + return
  339 + }
  340 +
  341 + v = map[string]interface{}{}
  342 + err = transactionContext.CommitTransaction()
  343 + return
  344 +}
  345 +
304 // 企业平台-多公司登录 346 // 企业平台-多公司登录
305 func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) { 347 func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCompanysRequest) (v interface{}, err error) {
306 var ( 348 var (
@@ -9,6 +9,7 @@ const SERVICE_NAME = "partner" @@ -9,6 +9,7 @@ const SERVICE_NAME = "partner"
9 9
10 var LOG_LEVEL = "debug" 10 var LOG_LEVEL = "debug"
11 var LOG_File = "app.log" 11 var LOG_File = "app.log"
  12 +var LOG_PREFIX = "[partner_dev]"
12 13
13 var MMM_SMS_SERVICE_HOST = "https://sms.fjmaimaimai.com:9897" 14 var MMM_SMS_SERVICE_HOST = "https://sms.fjmaimaimai.com:9897"
14 var UCENTER_SERVICE_HOST = "https://suplus-ucenter-test.fjmaimaimai.com" 15 var UCENTER_SERVICE_HOST = "https://suplus-ucenter-test.fjmaimaimai.com"
@@ -28,6 +29,9 @@ func init() { @@ -28,6 +29,9 @@ func init() {
28 if os.Getenv("LOG_LEVEL") != "" { 29 if os.Getenv("LOG_LEVEL") != "" {
29 LOG_LEVEL = os.Getenv("LOG_LEVEL") 30 LOG_LEVEL = os.Getenv("LOG_LEVEL")
30 } 31 }
  32 + if os.Getenv("LOG_PREFIX") != "" {
  33 + LOG_PREFIX = os.Getenv("LOG_PREFIX")
  34 + }
31 if os.Getenv("UCENTER_SERVICE_HOST") != "" { 35 if os.Getenv("UCENTER_SERVICE_HOST") != "" {
32 UCENTER_SERVICE_HOST = os.Getenv("UCENTER_SERVICE_HOST") 36 UCENTER_SERVICE_HOST = os.Getenv("UCENTER_SERVICE_HOST")
33 } 37 }
@@ -21,8 +21,8 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService { @@ -21,8 +21,8 @@ func NewPgAuthService(ctx *transaction.TransactionContext) *PgAuthService {
21 } 21 }
22 22
23 func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) { 23 func (s *PgAuthService) ChangeUserPhone(userId int64, newPhone, oldPhone string) (err error) {
24 - errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone)  
25 - errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) 24 + errPartner := s.partner.ChangeUserPhone(userId, newPhone, oldPhone) // 合伙人修改手机号
  25 + errManager := s.manager.ChangeUserPhone(userId, newPhone, oldPhone) // 高管修改手机号
26 return errResolve(errPartner, errManager) 26 return errResolve(errPartner, errManager)
27 } 27 }
28 func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) { 28 func (s *PgAuthService) ChangeUserPassword(userId int64, newPwd, oldPwd, phone string) (err error) {
@@ -81,6 +81,7 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, new @@ -81,6 +81,7 @@ func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePassword(phone, new
81 } 81 }
82 return serviceGateway.handlerError(response) 82 return serviceGateway.handlerError(response)
83 } 83 }
  84 +
84 func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePhone(newPhone, oldPhone string) (int, error) { 85 func (serviceGateway *HttplibUCenterApiServiceGateway) ChangePhone(newPhone, oldPhone string) (int, error) {
85 url := strings.Join([]string{serviceGateway.baseURL, "user", "change-phone"}, "/") 86 url := strings.Join([]string{serviceGateway.baseURL, "user", "change-phone"}, "/")
86 request := serviceGateway.createRequest(url, "post") 87 request := serviceGateway.createRequest(url, "post")
@@ -39,6 +39,7 @@ func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger { @@ -39,6 +39,7 @@ func NewBeegoLogger(conf LoggerConfig) *logs.BeeLogger {
39 log.SetLevel(ilv) 39 log.SetLevel(ilv)
40 log.EnableFuncCallDepth(true) 40 log.EnableFuncCallDepth(true)
41 log.SetLogFuncCallDepth(5) 41 log.SetLogFuncCallDepth(5)
  42 + log.SetPrefix(constant.LOG_PREFIX)
42 return log 43 return log
43 } 44 }
44 45
@@ -272,3 +272,32 @@ func (this *AuthController) UCenterRevoke() { @@ -272,3 +272,32 @@ func (this *AuthController) UCenterRevoke() {
272 } 272 }
273 msg = protocol.NewReturnResponse(auth.UCenterRevoke(nil, int64(uid))) 273 msg = protocol.NewReturnResponse(auth.UCenterRevoke(nil, int64(uid)))
274 } 274 }
  275 +
  276 +/**
  277 + * @Author SteveChan
  278 + * @Description //校验密码
  279 + * @Date 01:00 2021/1/8
  280 + * @Param
  281 + * @return
  282 + **/
  283 +func (this *AuthController) CheckPassword() {
  284 + var msg *protocol.ResponseMessage
  285 + defer func() {
  286 + this.Resp(msg)
  287 + }()
  288 + var request *protocol.LoginRequest
  289 + if err := this.JsonUnmarshal(&request); err != nil {
  290 + msg = protocol.BadRequestParam(1)
  291 + return
  292 + }
  293 + if b, m := this.Valid(request); !b {
  294 + msg = m
  295 + return
  296 + }
  297 + header := this.GetRequestHeader(this.Ctx)
  298 + data, err := auth.PasswordLogin(header, request)
  299 + if err != nil {
  300 + log.Error(err)
  301 + }
  302 + msg = protocol.NewReturnResponse(data, err)
  303 +}
@@ -2,9 +2,11 @@ package controllers @@ -2,9 +2,11 @@ package controllers
2 2
3 import ( 3 import (
4 "fmt" 4 "fmt"
  5 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/auth"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/application/user"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol" 7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/protocol"
7 "strings" 8 "strings"
  9 + "time"
8 ) 10 )
9 11
10 type UserController struct { 12 type UserController struct {
@@ -51,14 +53,25 @@ func (this *UserController) CheckSmsCode() { @@ -51,14 +53,25 @@ func (this *UserController) CheckSmsCode() {
51 msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request)) 53 msg = protocol.NewReturnResponse(user.CheckSmsCode(header, request))
52 } 54 }
53 55
54 -//ChangePhone  
55 -// @router /changePhone [post] 56 +/**
  57 + * @Author SteveChan
  58 + * @Description //TODO 修改手机号
  59 + * @Date 00:29 2021/1/8
  60 + * @Param
  61 + * @return
  62 + * @router /changePhone [post]
  63 + **/
56 func (this *UserController) ChangePhone() { 64 func (this *UserController) ChangePhone() {
57 var msg *protocol.ResponseMessage 65 var msg *protocol.ResponseMessage
  66 +
58 defer func() { 67 defer func() {
59 this.Resp(msg) 68 this.Resp(msg)
60 }() 69 }()
  70 +
61 var request *protocol.ChangePhoneRequest 71 var request *protocol.ChangePhoneRequest
  72 +
  73 + header := this.GetRequestHeader(this.Ctx)
  74 +
62 if err := this.JsonUnmarshal(&request); err != nil { 75 if err := this.JsonUnmarshal(&request); err != nil {
63 msg = protocol.BadRequestParam(1) 76 msg = protocol.BadRequestParam(1)
64 return 77 return
@@ -67,20 +80,42 @@ func (this *UserController) ChangePhone() { @@ -67,20 +80,42 @@ func (this *UserController) ChangePhone() {
67 msg = m 80 msg = m
68 return 81 return
69 } 82 }
70 - if !CacheSms.IsExist(request.OldPhone) { 83 +
  84 + // 校验短信验证码
  85 + var authCheckSmsCodeRequest *protocol.AuthCheckSmsCodeRequest
  86 + if err := this.JsonUnmarshal(&authCheckSmsCodeRequest); err != nil {
  87 + msg = protocol.BadRequestParam(1)
  88 + return
  89 + }
  90 + if b, m := this.Valid(authCheckSmsCodeRequest); !b {
  91 + msg = m
  92 + return
  93 + }
  94 + rsp, err := auth.AuthCheckSmsCode(header, authCheckSmsCodeRequest)
  95 + if err != nil {
  96 + msg = protocol.NewReturnResponse(rsp, err)
  97 + return
  98 + }
  99 + err = CacheSms.Put(request.Phone, rsp.CaptchaCertificate, 5*time.Minute)
  100 + if err != nil {
  101 + msg = protocol.NewReturnResponse(rsp, err)
  102 + return
  103 + }
  104 +
  105 + if !CacheSms.IsExist(request.Phone) {
71 msg = protocol.NewMesage(1009) //验证码失效 106 msg = protocol.NewMesage(1009) //验证码失效
72 return 107 return
73 } 108 }
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 - } 109 + if v := CacheSms.Get(request.Phone); v != nil {
  110 + //if !strings.EqualFold(fmt.Sprintf("%v", v), strings.TrimSpace(request.CaptchaCertificate)) {
  111 + // msg = protocol.NewMesage(1012) //验证码不一致
  112 + // return
  113 + //}
79 } else { 114 } else {
80 msg = protocol.NewMesage(1009) //验证码不一致 115 msg = protocol.NewMesage(1009) //验证码不一致
81 return 116 return
82 } 117 }
83 - header := this.GetRequestHeader(this.Ctx) 118 +
84 data, err := user.ChangePhone(header, request) 119 data, err := user.ChangePhone(header, request)
85 if err == nil { 120 if err == nil {
86 msg = protocol.NewResponseMessage(0, "修改手机号成功") 121 msg = protocol.NewResponseMessage(0, "修改手机号成功")
@@ -8,6 +8,7 @@ import ( @@ -8,6 +8,7 @@ import (
8 func init() { 8 func init() {
9 nsV1 := beego.NewNamespace("v1") //, beego.NSBefore(middleware.CheckJWTToken) 9 nsV1 := beego.NewNamespace("v1") //, beego.NSBefore(middleware.CheckJWTToken)
10 nsV1.Router("/auth/login", &controllers.AuthController{}, "Post:Login") 10 nsV1.Router("/auth/login", &controllers.AuthController{}, "Post:Login")
  11 + nsV1.Router("/auth/checkPassword", &controllers.AuthController{}, "Post:CheckPassword") // 校验密码
11 nsV1.Router("/auth/smsCode", &controllers.AuthController{}, "Post:SmsCode") 12 nsV1.Router("/auth/smsCode", &controllers.AuthController{}, "Post:SmsCode")
12 nsV1.Router("/auth/accessToken", &controllers.AuthController{}, "Post:AccessToken") 13 nsV1.Router("/auth/accessToken", &controllers.AuthController{}, "Post:AccessToken")
13 nsV1.Router("/auth/refreshToken", &controllers.AuthController{}, "Post:RefreshToken") 14 nsV1.Router("/auth/refreshToken", &controllers.AuthController{}, "Post:RefreshToken")
@@ -2,10 +2,10 @@ package messageHandler @@ -2,10 +2,10 @@ package messageHandler
2 2
3 import "github.com/Shopify/sarama" 3 import "github.com/Shopify/sarama"
4 4
5 -type UcenterMessageCommand struct { 5 +type UCenterMessageCommand struct {
6 } 6 }
7 7
8 -func (c *UcenterMessageCommand) ChangePhoneHandler(message interface{}) error { 8 +func (c *UCenterMessageCommand) ChangePhoneHandler(message interface{}) error {
9 msg, ok := message.(*sarama.Message) 9 msg, ok := message.(*sarama.Message)
10 if !ok && msg == nil { 10 if !ok && msg == nil {
11 return nil 11 return nil
1 package sarama 1 package sarama
2 2
3 import ( 3 import (
  4 + "fmt"
4 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant" 5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/constant"
5 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/kafkax" 6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/kafkax"
  7 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/message/models"
  8 + "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/infrastructure/pg/transaction"
6 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log" 9 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/log"
7 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama/messageHandler" 10 "gitlab.fjmaimaimai.com/mmm-go/partner/pkg/port/sarama/messageHandler"
8 //"suplus-message/pkg/constant" 11 //"suplus-message/pkg/constant"
9 //"suplus-message/pkg/port/sarama/messageHandler" 12 //"suplus-message/pkg/port/sarama/messageHandler"
10 ) 13 )
11 14
  15 +type PgMessageReceiverRepository struct {
  16 + transactionContext *transaction.TransactionContext
  17 +}
  18 +
  19 +func NewPgMessageReceiverRepository(transactionContext *transaction.TransactionContext) *PgMessageReceiverRepository {
  20 + return &PgMessageReceiverRepository{
  21 + transactionContext: transactionContext,
  22 + }
  23 +}
  24 +
  25 +func (repository *PgMessageReceiverRepository) ReceiveMessage(params map[string]interface{}) error {
  26 + var num int
  27 + checkSql := `select count(0) from sys_message_consume where "offset" =? and topic=?`
  28 + _, err := repository.transactionContext.PgDd.Query(&num, checkSql, params["offset"], params["topic"])
  29 + if err != nil {
  30 + return err
  31 + }
  32 + if num > 0 {
  33 + return fmt.Errorf("receive repeate message [%v]", params)
  34 + }
  35 +
  36 + sql := `insert into sys_message_consume(topic,partition,"offset",key,value,msg_time,create_at,status)values(?,?,?,?,?,?,?,?)`
  37 + _, err = repository.transactionContext.PgDd.Exec(sql, params["topic"], params["partition"], params["offset"], params["key"], params["value"], params["msg_time"], params["create_at"], params["status"])
  38 + return err
  39 +}
  40 +
  41 +func (repository *PgMessageReceiverRepository) ConfirmReceive(params map[string]interface{}) error {
  42 + fmt.Println(params)
  43 + _, err := repository.transactionContext.PgDd.Exec(`update sys_message_consume set status=? where "offset" =? and topic=?`, int(models.Finished), params["offset"], params["topic"])
  44 + return err
  45 +}
  46 +
12 func Run() { 47 func Run() {
13 var ( 48 var (
14 - ucenterMessage = &messageHandler.UcenterMessageCommand{} 49 + uCenterMessage = &messageHandler.UCenterMessageCommand{}
15 ) 50 )
16 51
17 saramaConsumer := kafkax.NewSaramaConsumer(constant.KAFKA_HOSTS, constant.SERVICE_NAME) 52 saramaConsumer := kafkax.NewSaramaConsumer(constant.KAFKA_HOSTS, constant.SERVICE_NAME)
18 - saramaConsumer.WithTopicHandler(constant.TOPIC_UCENT_USER_CHANGE_PHONE, ucenterMessage.ChangePhoneHandler) 53 + saramaConsumer.WithTopicHandler(constant.TOPIC_UCENT_USER_CHANGE_PHONE, uCenterMessage.ChangePhoneHandler)
  54 + saramaConsumer.WithMessageReceiver(NewPgMessageReceiverRepository(nil)) // 持久化
19 55
20 err := saramaConsumer.StartConsume() 56 err := saramaConsumer.StartConsume()
21 if err != nil { 57 if err != nil {
@@ -55,9 +55,10 @@ type ChangePhoneRequest struct { @@ -55,9 +55,10 @@ type ChangePhoneRequest struct {
55 Phone string `json:"phone" valid:"Required"` 55 Phone string `json:"phone" valid:"Required"`
56 Captcha string `json:"captcha" valid:"Required"` 56 Captcha string `json:"captcha" valid:"Required"`
57 57
58 - OldPhone string `json:"oldPhone" valid:"Required"`  
59 - CaptchaCertificate string `json:"captchaCertificate" valid:"Required"` 58 + OldPhone string `json:"oldPhone" valid:"Required"`
  59 + //CaptchaCertificate string `json:"captchaCertificate" valid:"Required"`
60 } 60 }
  61 +
61 type ChangePhoneResponse struct { 62 type ChangePhoneResponse struct {
62 } 63 }
63 64