作者 陈志颖

chore:精简docker镜像

1 -FROM golang:1.14  
2 -ENV APP_DIR $GOPATH/src/partner  
3 -RUN mkdir -p $APP_DIR  
4 -WORKDIR $APP_DIR/  
5 -COPY ./pkg pkg  
6 -COPY ./conf conf  
7 -COPY ./go.mod go.mod  
8 -COPY ./main.go main.go  
9 -RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]  
10 -ENV GO111MODULE on  
11 -ENV GOPROXY https://goproxy.cn,direct  
12 -RUN ["go","mod","tidy"]  
13 -RUN ["go","build"]  
14 -EXPOSE 8082  
15 -ENTRYPOINT ["./partner"]  
  1 +#FROM golang:1.14
  2 +#ENV APP_DIR $GOPATH/src/partner
  3 +#RUN mkdir -p $APP_DIR
  4 +#WORKDIR $APP_DIR/
  5 +#COPY ./pkg pkg
  6 +#COPY ./conf conf
  7 +#COPY ./go.mod go.mod
  8 +#COPY ./main.go main.go
  9 +#RUN ["ln","-sf","/usr/share/zoneinfo/Asia/Shanghai","/etc/localtime"]
  10 +#ENV GO111MODULE on
  11 +#ENV GOPROXY https://goproxy.cn,direct
  12 +#RUN ["go","mod","tidy"]
  13 +#RUN ["go","build"]
  14 +#EXPOSE 8082
  15 +#ENTRYPOINT ["./partner"]
  16 +
  17 +############################
  18 +# STEP 1 build executable binary
  19 +############################
  20 +FROM golang:alpine AS builder
  21 +
  22 +RUN mkdir /app
  23 +COPY . /app
  24 +WORKDIR /app
  25 +RUN GO111MODULE="on" GOPROXY="https://goproxy.cn" GOFLAGS=-mod=vendor CGO_ENABLED=0 GOOS=linux go build -o partner
  26 +
  27 +############################
  28 +# STEP 2 build a small image
  29 +###########################
  30 +FROM scratch as final
  31 +COPY --from=builder /app/partner /app/partner
  32 +COPY --from=builder /app/conf/ /app/conf
  33 +ENTRYPOINT ["./app/partner"]
  1 +version: v1
  2 +kind: Attribute
  3 +metadata:
  4 + name: orderId
  5 + description: 订单编号
  6 + type:
  7 + primitive: int64
  1 +version: v1
  2 +kind: Project
  3 +metadata:
  4 + name: partner
  5 + description: 合伙人
  6 + version: 0.8.0
  7 + repository: gitlab.fjmaimaimai.com/mmm-go/partner
  8 + contact:
  9 + name: SteveChan
  10 + email: steve.d.chan@qq.com
不能预览此文件类型
@@ -381,7 +381,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -381,7 +381,7 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
381 381
382 // 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去 382 // 通过密码或校验码登录的普通用户或通过校验码登录的游客,注册一个账号到配置的公司去
383 if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword { 383 if request.GrantType == protocol.LoginBySmsCode || request.GrantType == protocol.LoginByPassword {
384 - userErr := loginSvr.RegistryUser(request.Phone) 384 + userErr := loginSvr.RegistryGuest(request.Phone)
385 if userErr != nil { 385 if userErr != nil {
386 log.Error(userErr) 386 log.Error(userErr)
387 } 387 }
@@ -403,25 +403,30 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom @@ -403,25 +403,30 @@ func CompaniesLogin(header *protocol.RequestHeader, request *protocolx.CenterCom
403 return 403 return
404 } 404 }
405 405
406 - manageLoginErr := loginSvr.ManagerLogin(request.Phone, request.Password)  
407 - fmt.Print("用户登录:", manageLoginErr, "\n")  
408 - partnerLoginErr := loginSvr.PartnerLogin(request.Phone, request.Password)  
409 - fmt.Print("合伙人登录:", partnerLoginErr, "\n") 406 + //manageLoginErr := loginSvr.ManagerLogin(request.Phone, request.Password)
  407 + //fmt.Print("用户登录:", manageLoginErr, "\n")
  408 + //partnerLoginErr := loginSvr.PartnerLogin(request.Phone, request.Password)
  409 + //fmt.Print("合伙人登录:", partnerLoginErr, "\n")
  410 + //
  411 + //if manageLoginErr != nil && partnerLoginErr != nil {
  412 + // //if len(loginSvr.PartnerInfo) == 0 { // 不存在有效用户
  413 + // // err = protocol.NewErrWithMessage(10008)
  414 + // // return
  415 + // //}
  416 + // err = protocol.NewCustomMessage(1, "密码输入有误!")
  417 + // return
  418 + //} else if manageLoginErr != nil && partnerLoginErr == nil {
  419 + // if len(loginSvr.PartnerInfo) == 1 && len(loginSvr.NormalUsers) == 0 {
  420 + // if loginSvr.PartnerInfo[0].CompanyId == int64(constant.DEFAULT_GUEST_COMPANY) {
  421 + // err = protocol.NewCustomMessage(1, "密码输入有误!")
  422 + // return
  423 + // }
  424 + // }
  425 + //}
410 426
411 - if manageLoginErr != nil && partnerLoginErr != nil {  
412 - if len(loginSvr.PartnerInfo) == 0 { // 不存在有效用户  
413 - err = protocol.NewErrWithMessage(10008)  
414 - return  
415 - } 427 + if loginSvr.ManagerLogin(request.Phone, request.Password) != nil && loginSvr.PartnerLogin(request.Phone, request.Password) != nil {
416 err = protocol.NewCustomMessage(1, "密码输入有误!") 428 err = protocol.NewCustomMessage(1, "密码输入有误!")
417 return 429 return
418 - } else if manageLoginErr != nil && partnerLoginErr == nil {  
419 - if len(loginSvr.PartnerInfo) == 1 && len(loginSvr.NormalUsers) == 0 {  
420 - if loginSvr.PartnerInfo[0].CompanyId == int64(constant.DEFAULT_GUEST_COMPANY) {  
421 - err = protocol.NewCustomMessage(1, "密码输入有误!")  
422 - return  
423 - }  
424 - }  
425 } 430 }
426 break 431 break
427 case protocol.LoginBySmsCode: 432 case protocol.LoginBySmsCode:
@@ -454,7 +454,7 @@ func (svr *PgLoginService) RegistryUser(phone string) error { @@ -454,7 +454,7 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
454 isUserSenior bool 454 isUserSenior bool
455 ) 455 )
456 456
457 - partnerInfo, _ := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否存在 457 + partnerInfo, errPartner := PartnerInfoService.FindOne(map[string]interface{}{"account": phone, "isNot": constant.DEFAULT_GUEST_COMPANY}) // 合伙人在正常公司是否存在
458 if partnerInfo == nil { 458 if partnerInfo == nil {
459 isPartner = false 459 isPartner = false
460 } else { 460 } else {
@@ -480,7 +480,7 @@ func (svr *PgLoginService) RegistryUser(phone string) error { @@ -480,7 +480,7 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
480 isGuestPartnerAvailable = true 480 isGuestPartnerAvailable = true
481 } 481 }
482 482
483 - user, _ := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在 483 + user, errUser := UsersRepository.FindOne(map[string]interface{}{"phone": phone, "deleteAtIsNull": true}) // 用户是否存在
484 if user == nil { 484 if user == nil {
485 isUser = false 485 isUser = false
486 } else { 486 } else {
@@ -571,27 +571,27 @@ func (svr *PgLoginService) RegistryUser(phone string) error { @@ -571,27 +571,27 @@ func (svr *PgLoginService) RegistryUser(phone string) error {
571 571
572 // 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户 572 // 合伙人不存在、用户存在、非高管(普通用户)-> 注册用户
573 // 合伙人不存在、用户不存在(游客)-> 注册用户 573 // 合伙人不存在、用户不存在(游客)-> 注册用户
574 - //if errPartner != nil && errUser == nil && errSenior == nil || errPartner != nil && errUser != nil {  
575 - // id := time.Now().Unix()  
576 - // errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{  
577 - // Id: id,  
578 - // CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),  
579 - // PartnerName: phone,  
580 - // Account: phone,  
581 - // Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",  
582 - // Status: 1,  
583 - // PartnerCategory: 1,  
584 - // RegionInfo: &domain.RegionInfo{  
585 - // RegionName: "客户区域",  
586 - // RegionId: 0,  
587 - // },  
588 - // CooperateTime: time.Now(),  
589 - // CreateAt: time.Now(),  
590 - // UpdateAt: time.Now(),  
591 - // PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},  
592 - // Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},  
593 - // })  
594 - //} 574 + if errPartner != nil && errUser == nil {
  575 + id := time.Now().Unix()
  576 + errPartner = svr.transactionContext.PgDd.Insert(&models.PartnerInfo{
  577 + Id: id,
  578 + CompanyId: int64(constant.DEFAULT_GUEST_COMPANY),
  579 + PartnerName: phone,
  580 + Account: phone,
  581 + Password: "7c4a8d09ca3762af61e59520943dc26494f8941b",
  582 + Status: 1,
  583 + PartnerCategory: 1,
  584 + RegionInfo: &domain.RegionInfo{
  585 + RegionName: "客户区域",
  586 + RegionId: 0,
  587 + },
  588 + CooperateTime: time.Now(),
  589 + CreateAt: time.Now(),
  590 + UpdateAt: time.Now(),
  591 + PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
  592 + Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
  593 + })
  594 + }
595 595
596 return errPartner 596 return errPartner
597 } 597 }
@@ -627,7 +627,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error { @@ -627,7 +627,7 @@ func (svr *PgLoginService) RegistryGuest(phone string) error {
627 CooperateTime: time.Now(), 627 CooperateTime: time.Now(),
628 CreateAt: time.Now(), 628 CreateAt: time.Now(),
629 UpdateAt: time.Now(), 629 UpdateAt: time.Now(),
630 - PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1}}, 630 + PartnerCategoryInfos: []*models.PartnerCategoryInfo{&models.PartnerCategoryInfo{Id: 1, Code: phone}},
631 Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}}, 631 Salesman: []*domain.Salesman{&domain.Salesman{Name: phone, Telephone: phone}},
632 }) 632 })
633 } 633 }