作者 yangfu

用户基础信息修改

@@ -4,10 +4,9 @@ go 1.16 @@ -4,10 +4,9 @@ go 1.16
4 4
5 require ( 5 require (
6 github.com/beego/beego/v2 v2.0.1 6 github.com/beego/beego/v2 v2.0.1
7 - github.com/boombuler/barcode v1.0.1  
8 github.com/dgrijalva/jwt-go v3.2.0+incompatible 7 github.com/dgrijalva/jwt-go v3.2.0+incompatible
9 github.com/go-pg/pg/v10 v10.10.1 8 github.com/go-pg/pg/v10 v10.10.1
10 github.com/go-redis/redis v6.14.2+incompatible 9 github.com/go-redis/redis v6.14.2+incompatible
  10 + github.com/google/uuid v1.1.1
11 github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6 11 github.com/linmadan/egglib-go v0.0.0-20210527091316-06b0732fb5f6
12 - github.com/sony/sonyflake v1.0.0  
13 ) 12 )
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type CompanySignUpCommand struct {
  12 + // 企业名称
  13 + CompanyName string `cname:"企业名称" json:"companyName" valid:"Required"`
  14 + // 联系人
  15 + Contacts string `cname:"联系人" json:"contacts" valid:"Required"`
  16 + // 手机号码
  17 + Phone string `cname:"手机号码" json:"phone" valid:"Required"`
  18 + // 规模
  19 + Scale string `cname:"规模" json:"scale" valid:"Required"`
  20 + // 所属行业
  21 + IndustryCategory string `cname:"所属行业" json:"industryCategory" valid:"Required"`
  22 + // 密码
  23 + Password string `cname:"密码" json:"password" valid:"Required"`
  24 + // 短信验证码
  25 + SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
  26 +}
  27 +
  28 +func (companySignUpCommand *CompanySignUpCommand) Valid(validation *validation.Validation) {
  29 + //validation.SetError("CustomValid", "未实现的自定义认证")
  30 +}
  31 +
  32 +func (companySignUpCommand *CompanySignUpCommand) ValidateCommand() error {
  33 + valid := validation.Validation{}
  34 + b, err := valid.Valid(companySignUpCommand)
  35 + if err != nil {
  36 + return err
  37 + }
  38 + if !b {
  39 + elem := reflect.TypeOf(companySignUpCommand).Elem()
  40 + for _, validErr := range valid.Errors {
  41 + field, isExist := elem.FieldByName(validErr.Field)
  42 + if isExist {
  43 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  44 + } else {
  45 + return fmt.Errorf(validErr.Message)
  46 + }
  47 + }
  48 + }
  49 + return nil
  50 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "reflect"
  6 + "strings"
  7 +
  8 + "github.com/beego/beego/v2/core/validation"
  9 +)
  10 +
  11 +type ResetPasswordCommand struct {
  12 + // 手机号码
  13 + // Phone string `cname:"手机号码" json:"phone" valid:"Required"`
  14 + // 密码
  15 + Password string `cname:"密码" json:"newPassword"`
  16 + // 密码
  17 + RepeatNewPassword string `cname:"密码" json:"repeatNewPassword" valid:"Required"`
  18 + // 密码
  19 + SmsCodeIdentity string `cname:"密码" json:"smsCodeIdentity" valid:"Required"`
  20 +}
  21 +
  22 +func (resetPasswordCommand *ResetPasswordCommand) Valid(validation *validation.Validation) {
  23 + if len(resetPasswordCommand.Password) == 0 {
  24 + validation.Error("登录密码不能为空")
  25 + return
  26 + }
  27 + if resetPasswordCommand.Password != resetPasswordCommand.RepeatNewPassword {
  28 + validation.Error("两次密码输入不一致")
  29 + return
  30 + }
  31 +}
  32 +
  33 +func (resetPasswordCommand *ResetPasswordCommand) ValidateCommand() error {
  34 + valid := validation.Validation{}
  35 + b, err := valid.Valid(resetPasswordCommand)
  36 + if err != nil {
  37 + return err
  38 + }
  39 + if !b {
  40 + elem := reflect.TypeOf(resetPasswordCommand).Elem()
  41 + for _, validErr := range valid.Errors {
  42 + field, isExist := elem.FieldByName(validErr.Field)
  43 + if isExist {
  44 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  45 + } else {
  46 + return fmt.Errorf(validErr.Message)
  47 + }
  48 + }
  49 + }
  50 + return nil
  51 +}
@@ -2,6 +2,7 @@ package service @@ -2,6 +2,7 @@ package service
2 2
3 import ( 3 import (
4 "errors" 4 "errors"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
5 "time" 6 "time"
6 7
7 "github.com/linmadan/egglib-go/core/application" 8 "github.com/linmadan/egglib-go/core/application"
@@ -342,7 +343,7 @@ loopUser1: @@ -342,7 +343,7 @@ loopUser1:
342 func (srv AuthService) GetUserInfo(userInfoCommand *command.UserInfoCommand) (interface{}, error) { 343 func (srv AuthService) GetUserInfo(userInfoCommand *command.UserInfoCommand) (interface{}, error) {
343 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser( 344 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
344 userInfoCommand.Operator) 345 userInfoCommand.Operator)
345 - resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGateUser{ 346 + resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
346 UserId: int(userInfoCommand.Operator.UserId), 347 UserId: int(userInfoCommand.Operator.UserId),
347 }) 348 })
348 if err != nil { 349 if err != nil {
@@ -413,3 +414,49 @@ func (srv AuthService) GetUserOrg(userOrgCommand *command.UserOrgCommand) (inter @@ -413,3 +414,49 @@ func (srv AuthService) GetUserOrg(userOrgCommand *command.UserOrgCommand) (inter
413 } 414 }
414 return res, nil 415 return res, nil
415 } 416 }
  417 +
  418 +// CompanySignUp 企业注册
  419 +func (srv AuthService) CompanySignUp(companySignUpCommand *command.CompanySignUpCommand) (interface{}, error) {
  420 + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
  421 + err := smsServeGateway.CheckSmsCode(companySignUpCommand.Phone, companySignUpCommand.SmsCode)
  422 + if err != nil {
  423 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  424 + }
  425 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  426 + result, err := creationUserGateway.AuthCompanySignUp(allied_creation_user.ReqAuthCompanySignUp{
  427 + CompanyName: companySignUpCommand.CompanyName,
  428 + Phone: companySignUpCommand.Phone,
  429 + Password: companySignUpCommand.Password,
  430 + Contacts: companySignUpCommand.Contacts,
  431 + IndustryCategory: companySignUpCommand.IndustryCategory,
  432 + Scale: companySignUpCommand.Scale,
  433 + })
  434 + if err != nil {
  435 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  436 + }
  437 + return result, err
  438 +}
  439 +
  440 +// ResetPassword 重置密码(找回密码)
  441 +func (srv AuthService) ResetPassword(resetPasswordCommand *command.ResetPasswordCommand) (interface{}, error) {
  442 + if err := resetPasswordCommand.ValidateCommand(); err != nil {
  443 + return nil, application.ThrowError(application.ARG_ERROR, err.Error())
  444 + }
  445 + //var phone string
  446 + pcc := cache.PhoneCheckCache{}
  447 + var item = &cache.PhoneCheckItem{}
  448 + if err := pcc.Get(resetPasswordCommand.SmsCodeIdentity, item); err != nil {
  449 + log.Logger.Error(err.Error())
  450 + return nil, application.ThrowError(application.BUSINESS_ERROR, "验证码已失效")
  451 + }
  452 + // 2.重置密码
  453 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  454 + result, err := creationUserGateway.AuthResetPassword(allied_creation_user.ReqAuthResetPassword{
  455 + Phone: item.Phone,
  456 + Password: resetPasswordCommand.Password,
  457 + })
  458 + if err != nil {
  459 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  460 + }
  461 + return result, err
  462 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type ChangePasswordCommand struct {
  13 + //操作人
  14 + Operator domain.Operator `json:"-"`
  15 + // 手机号
  16 + Phone string `cname:"手机号" json:"phone" valid:"Required"`
  17 + // 短信验证码
  18 + SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
  19 + // 新密码
  20 + NewPassword string `cname:"新密码" json:"newPassword" valid:"Required"`
  21 +}
  22 +
  23 +func (phoneAuthChangePasswordCommand *ChangePasswordCommand) Valid(validation *validation.Validation) {
  24 +
  25 +}
  26 +
  27 +func (phoneAuthChangePasswordCommand *ChangePasswordCommand) ValidateCommand() error {
  28 + valid := validation.Validation{}
  29 + b, err := valid.Valid(phoneAuthChangePasswordCommand)
  30 + if err != nil {
  31 + return err
  32 + }
  33 + if !b {
  34 + elem := reflect.TypeOf(phoneAuthChangePasswordCommand).Elem()
  35 + for _, validErr := range valid.Errors {
  36 + field, isExist := elem.FieldByName(validErr.Field)
  37 + if isExist {
  38 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  39 + } else {
  40 + return fmt.Errorf(validErr.Message)
  41 + }
  42 + }
  43 + }
  44 + return nil
  45 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 +
  6 + "github.com/beego/beego/v2/core/validation"
  7 +)
  8 +
  9 +type CheckSmsCodeCommand struct {
  10 + Phone string `json:"phone" valid:"Required"`
  11 + SmsCode string `json:"smsCode" valid:"Required"`
  12 + // [1:登录][2:修改密码][3:找回密码][4:注册][5:修改手机号]
  13 + Action int `json:"action" valid:"Required"`
  14 +}
  15 +
  16 +func (checkSmsCodeCommand *CheckSmsCodeCommand) Valid(validation *validation.Validation) {
  17 +
  18 +}
  19 +
  20 +func (checkSmsCodeCommand *CheckSmsCodeCommand) ValidateCommand() error {
  21 + valid := validation.Validation{}
  22 + b, err := valid.Valid(checkSmsCodeCommand)
  23 + if err != nil {
  24 + return err
  25 + }
  26 + if !b {
  27 + for _, validErr := range valid.Errors {
  28 + return fmt.Errorf("%s %s", validErr.Key, validErr.Message)
  29 + }
  30 + }
  31 + return nil
  32 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type ResetPhoneCommand struct {
  13 + //操作人
  14 + Operator domain.Operator `json:"-"`
  15 + // 短信验证码
  16 + SmsCode string `cname:"短信验证码" json:"smsCode" valid:"Required"`
  17 + OldPhone string `cname:"" json:"oldPhone" valid:"Required"`
  18 + NewPhone string `cname:"" json:"newPhone" valid:"Required"`
  19 +}
  20 +
  21 +func (phoneAuthResetPhoneCommand *ResetPhoneCommand) Valid(validation *validation.Validation) {
  22 +
  23 +}
  24 +
  25 +func (phoneAuthResetPhoneCommand *ResetPhoneCommand) ValidateCommand() error {
  26 + valid := validation.Validation{}
  27 + b, err := valid.Valid(phoneAuthResetPhoneCommand)
  28 + if err != nil {
  29 + return err
  30 + }
  31 + if !b {
  32 + elem := reflect.TypeOf(phoneAuthResetPhoneCommand).Elem()
  33 + for _, validErr := range valid.Errors {
  34 + field, isExist := elem.FieldByName(validErr.Field)
  35 + if isExist {
  36 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  37 + } else {
  38 + return fmt.Errorf(validErr.Message)
  39 + }
  40 + }
  41 + }
  42 + return nil
  43 +}
  1 +package command
  2 +
  3 +import (
  4 + "fmt"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  6 + "reflect"
  7 + "strings"
  8 +
  9 + "github.com/beego/beego/v2/core/validation"
  10 +)
  11 +
  12 +type UpdateUserInfoCommand struct {
  13 + //操作人
  14 + Operator domain.Operator `json:"-"`
  15 + // 头像
  16 + Avatar string `cname:"头像" json:"avatar" valid:"Required"`
  17 + // 用户姓名
  18 + UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
  19 +}
  20 +
  21 +func (phoneAuthResetPhoneCommand *UpdateUserInfoCommand) Valid(validation *validation.Validation) {
  22 +
  23 +}
  24 +
  25 +func (phoneAuthResetPhoneCommand *UpdateUserInfoCommand) ValidateCommand() error {
  26 + valid := validation.Validation{}
  27 + b, err := valid.Valid(phoneAuthResetPhoneCommand)
  28 + if err != nil {
  29 + return err
  30 + }
  31 + if !b {
  32 + elem := reflect.TypeOf(phoneAuthResetPhoneCommand).Elem()
  33 + for _, validErr := range valid.Errors {
  34 + field, isExist := elem.FieldByName(validErr.Field)
  35 + if isExist {
  36 + return fmt.Errorf(strings.Replace(validErr.Message, validErr.Field, field.Tag.Get("cname"), -1))
  37 + } else {
  38 + return fmt.Errorf(validErr.Message)
  39 + }
  40 + }
  41 + }
  42 + return nil
  43 +}
1 package service 1 package service
2 2
3 import ( 3 import (
  4 + "github.com/google/uuid"
4 "github.com/linmadan/egglib-go/core/application" 5 "github.com/linmadan/egglib-go/core/application"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/application/mobile/user/command"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/domain"
  8 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/cache"
  9 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/allied_creation_user"
6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve" 10 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/service_gateway/sms_serve"
  11 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
7 ) 12 )
8 13
9 type UserService struct { 14 type UserService struct {
@@ -18,3 +23,86 @@ func (srv UserService) SendSmsCaptcha(smsCodeCommand *command.SendSmsCodeCommand @@ -18,3 +23,86 @@ func (srv UserService) SendSmsCaptcha(smsCodeCommand *command.SendSmsCodeCommand
18 } 23 }
19 return nil 24 return nil
20 } 25 }
  26 +
  27 +//CheckSmsCode 验证手机短信验证码
  28 +func (srv UserService) CheckSmsCode(smsCodeCommand *command.CheckSmsCodeCommand) (interface{}, error) {
  29 + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
  30 + err := smsServeGateway.CheckSmsCode(smsCodeCommand.Phone, smsCodeCommand.SmsCode)
  31 + if err != nil {
  32 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  33 + }
  34 + uid := uuid.New()
  35 + pcc := cache.PhoneCheckCache{}
  36 + if err := pcc.Add(uid.String(), cache.PhoneCheckItem{
  37 + Phone: smsCodeCommand.Phone,
  38 + SmsCodeIdentity: uid.String(),
  39 + Action: smsCodeCommand.Action,
  40 + }); err != nil {
  41 + log.Logger.Error(err.Error())
  42 + return nil, application.ThrowError(application.BUSINESS_ERROR, "系统错误")
  43 + }
  44 + return map[string]interface{}{
  45 + "smsCodeIdentity": uid.String(),
  46 + }, nil
  47 +}
  48 +
  49 +//ChangePassword 修改密码
  50 +func (srv UserService) ChangePassword(changePasswordCommand *command.ChangePasswordCommand) (interface{}, error) {
  51 + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
  52 + err := smsServeGateway.CheckSmsCode(changePasswordCommand.Phone, changePasswordCommand.SmsCode)
  53 + if err != nil {
  54 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  55 + }
  56 + // 2.重置密码
  57 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  58 + _, err = creationUserGateway.AuthResetPassword(allied_creation_user.ReqAuthResetPassword{
  59 + Phone: changePasswordCommand.Phone,
  60 + Password: changePasswordCommand.NewPassword,
  61 + })
  62 + if err != nil {
  63 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  64 + }
  65 + return struct{}{}, nil
  66 +}
  67 +
  68 +//ChangePassword 修改密码
  69 +func (srv UserService) ChangePhone(resetPhoneCommand *command.ResetPhoneCommand) (interface{}, error) {
  70 + smsServeGateway := sms_serve.NewHttplibHttplibSmsServe()
  71 + err := smsServeGateway.CheckSmsCode(resetPhoneCommand.NewPhone, resetPhoneCommand.SmsCode)
  72 + if err != nil {
  73 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  74 + }
  75 + // 2.重置手机号
  76 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  77 + _, err = creationUserGateway.AuthResetPhone(allied_creation_user.ReqAuthResetPhone{
  78 + UserId: resetPhoneCommand.Operator.UserId,
  79 + OldPhone: resetPhoneCommand.OldPhone,
  80 + NewPhone: resetPhoneCommand.NewPhone,
  81 + })
  82 + if err != nil {
  83 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  84 + }
  85 + return struct{}{}, nil
  86 +}
  87 +
  88 +//UpdateUserInfo 更新用户信息
  89 +func (srv UserService) UpdateUserInfo(updateUserInfoCommand *command.UpdateUserInfoCommand) (interface{}, error) {
  90 + creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(domain.Operator{})
  91 + user, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
  92 + UserId: int(updateUserInfoCommand.Operator.UserId),
  93 + })
  94 + if err != nil {
  95 + return nil, application.ThrowError(application.BUSINESS_ERROR, "用户不存在")
  96 + }
  97 + _, err = creationUserGateway.UserUpdateBaseInfo(allied_creation_user.ReqUserUpdateBaseInfo{
  98 + UserId: int64(user.UserId),
  99 + UserName: updateUserInfoCommand.UserName,
  100 + Avatar: updateUserInfoCommand.Avatar,
  101 + Phone: user.UserInfo.Phone,
  102 + Email: user.UserInfo.Email,
  103 + })
  104 + if err != nil {
  105 + return nil, application.ThrowError(application.BUSINESS_ERROR, err.Error())
  106 + }
  107 + return struct{}{}, nil
  108 +}
@@ -8,6 +8,7 @@ type CompanyUserItem struct { @@ -8,6 +8,7 @@ type CompanyUserItem struct {
8 UserCode string `json:"userCode"` 8 UserCode string `json:"userCode"`
9 UserId string `json:"userId"` 9 UserId string `json:"userId"`
10 UserName string `json:"userName"` 10 UserName string `json:"userName"`
  11 + UserType int `json:"userType"`
11 } 12 }
12 13
13 //CompanyUserInfo 用户数据详情 14 //CompanyUserInfo 用户数据详情
@@ -27,7 +27,7 @@ func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.Comp @@ -27,7 +27,7 @@ func (usersService *UsersService) CompanyUserGet(companyUserGetQuery *query.Comp
27 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser( 27 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
28 companyUserGetQuery.Operator) 28 companyUserGetQuery.Operator)
29 userid, _ := strconv.Atoi(companyUserGetQuery.UsersId) 29 userid, _ := strconv.Atoi(companyUserGetQuery.UsersId)
30 - resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGateUser{ 30 + resultUser, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
31 UserId: userid, 31 UserId: userid,
32 }) 32 })
33 if err != nil { 33 if err != nil {
@@ -117,7 +117,7 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command. @@ -117,7 +117,7 @@ func (usersService *UsersService) CompanyUserAdd(companyUserAddCommand *command.
117 result, err := creationUserGateway.UserCreate(allied_creation_user.ReqCreateUser{ 117 result, err := creationUserGateway.UserCreate(allied_creation_user.ReqCreateUser{
118 CompanyId: companyUserAddCommand.Operator.CompanyId, 118 CompanyId: companyUserAddCommand.Operator.CompanyId,
119 // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加) 119 // 用户类型 1:企业内部用户(内部添加) 2:共创用户 1024:企业注册用户(注册添加)
120 - UserType: 1, 120 + UserType: domain.UserTypeEmployee,
121 UserCode: companyUserAddCommand.UsersCode, 121 UserCode: companyUserAddCommand.UsersCode,
122 OrganizationId: int64(orgId), 122 OrganizationId: int64(orgId),
123 DepartmentId: int64(departmentId), 123 DepartmentId: int64(departmentId),
@@ -197,6 +197,7 @@ func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.Co @@ -197,6 +197,7 @@ func (usersService *UsersService) CompanyUserList(companyUserListQuery *query.Co
197 UserCode: v.UserCode, 197 UserCode: v.UserCode,
198 UserId: strconv.Itoa(v.UserId), 198 UserId: strconv.Itoa(v.UserId),
199 UserName: v.UserInfo.UserName, 199 UserName: v.UserInfo.UserName,
  200 + UserType: v.UserType,
200 } 201 }
201 listData = append(listData, item) 202 listData = append(listData, item)
202 } 203 }
@@ -317,7 +318,7 @@ func (usersService *UsersService) CooperationUserGet(cooperationUserGetQuery *qu @@ -317,7 +318,7 @@ func (usersService *UsersService) CooperationUserGet(cooperationUserGetQuery *qu
317 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser( 318 creationUserGateway := allied_creation_user.NewHttplibAlliedCreationUser(
318 cooperationUserGetQuery.Operator) 319 cooperationUserGetQuery.Operator)
319 userId, _ := strconv.Atoi(cooperationUserGetQuery.UserId) 320 userId, _ := strconv.Atoi(cooperationUserGetQuery.UserId)
320 - result, err := creationUserGateway.UserGet(allied_creation_user.ReqGateUser{ 321 + result, err := creationUserGateway.UserGet(allied_creation_user.ReqGetUser{
321 UserId: userId, 322 UserId: userId,
322 }) 323 })
323 if err != nil { 324 if err != nil {
@@ -16,7 +16,7 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081" @@ -16,7 +16,7 @@ var ALLIED_CREATION_USER_HOST = "http://localhost:8081"
16 var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082" 16 var ALLIED_CREATION_COOPERATION_HOST = "http://localhost:8082"
17 17
18 //通用模块短信服务 18 //通用模块短信服务
19 -var SMS_SERVE_HOST = "http://localhost:8081" 19 +var SMS_SERVE_HOST = "https://sms.fjmaimaimai.com:9897"
20 20
21 func init() { 21 func init() {
22 if os.Getenv("LOG_LEVEL") != "" { 22 if os.Getenv("LOG_LEVEL") != "" {
  1 +package cache
  2 +
  3 +import (
  4 + "encoding/json"
  5 + "time"
  6 +)
  7 +
  8 +const phoneCheckExpire = 60 * 5
  9 +
  10 +//短信验证码验证缓存
  11 +type PhoneCheckCache struct {
  12 +}
  13 +
  14 +func (ca PhoneCheckCache) phoneCheckKey(smsCodeIdentity string) string {
  15 + str := KEY_PREFIX + "phone-check:" + smsCodeIdentity
  16 + return str
  17 +}
  18 +
  19 +func (ca PhoneCheckCache) Add(smsCodeIdentity string, value interface{}) error {
  20 + key := ca.phoneCheckKey(smsCodeIdentity)
  21 + data, err := json.Marshal(value)
  22 + if err != nil {
  23 + return err
  24 + }
  25 + result := clientRedis.Set(key, string(data), time.Duration(phoneCheckExpire*time.Second))
  26 + return result.Err()
  27 +}
  28 +
  29 +func (ca PhoneCheckCache) Get(smsCodeIdentity string, value interface{}) error {
  30 + key := ca.phoneCheckKey(smsCodeIdentity)
  31 + result := clientRedis.Get(key)
  32 + if result.Err() != nil {
  33 + return result.Err()
  34 + }
  35 + err := json.Unmarshal([]byte(result.Val()), value)
  36 + return err
  37 +}
  38 +
  39 +type PhoneCheckItem struct {
  40 + Phone string `json:"phone"`
  41 + SmsCodeIdentity string `json:"smsCodeIdentity"`
  42 + Action int `json:"action"`
  43 +}
1 package pg 1 package pg
2 2
3 import ( 3 import (
  4 + "context"
4 "fmt" 5 "fmt"
  6 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/pg/models"
  7 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/log"
5 8
6 "github.com/go-pg/pg/v10" 9 "github.com/go-pg/pg/v10"
7 "github.com/go-pg/pg/v10/orm" 10 "github.com/go-pg/pg/v10/orm"
8 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant" 11 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/constant"
9 -  
10 - //_ "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/infrastructure/pg/models"  
11 - "github.com/linmadan/egglib-go/persistent/pg/hooks"  
12 ) 12 )
13 13
14 var DB *pg.DB 14 var DB *pg.DB
@@ -21,9 +21,11 @@ func init() { @@ -21,9 +21,11 @@ func init() {
21 Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT), 21 Addr: fmt.Sprintf("%s:%s", constant.POSTGRESQL_HOST, constant.POSTGRESQL_PORT),
22 }) 22 })
23 if !constant.DISABLE_SQL_GENERATE_PRINT { 23 if !constant.DISABLE_SQL_GENERATE_PRINT {
24 - DB.AddQueryHook(hooks.SqlGeneratePrintHook{}) 24 + DB.AddQueryHook(SqlGeneratePrintHook{})
  25 + }
  26 + m := []interface{}{
  27 + &models.LoginAccess{},
25 } 28 }
26 - m := []interface{}{}  
27 if !constant.DISABLE_CREATE_TABLE { 29 if !constant.DISABLE_CREATE_TABLE {
28 for _, model := range m { 30 for _, model := range m {
29 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{ 31 err := DB.Model(model).CreateTable(&orm.CreateTableOptions{
@@ -37,3 +39,18 @@ func init() { @@ -37,3 +39,18 @@ func init() {
37 } 39 }
38 } 40 }
39 } 41 }
  42 +
  43 +type SqlGeneratePrintHook struct{}
  44 +
  45 +func (hook SqlGeneratePrintHook) BeforeQuery(c context.Context, q *pg.QueryEvent) (context.Context, error) {
  46 + return c, nil
  47 +}
  48 +
  49 +func (hook SqlGeneratePrintHook) AfterQuery(c context.Context, q *pg.QueryEvent) error {
  50 + sqlStr, err := q.FormattedQuery()
  51 + if err != nil {
  52 + return err
  53 + }
  54 + log.Logger.Debug(string(sqlStr))
  55 + return nil
  56 +}
@@ -106,7 +106,7 @@ func (gateway HttplibAlliedCreationUser) UserUpdate(param ReqUpdateUser) (*DataU @@ -106,7 +106,7 @@ func (gateway HttplibAlliedCreationUser) UserUpdate(param ReqUpdateUser) (*DataU
106 } 106 }
107 107
108 //UserGet 获取用户 108 //UserGet 获取用户
109 -func (gateway HttplibAlliedCreationUser) UserGet(param ReqGateUser) (*DataGateUser, error) { 109 +func (gateway HttplibAlliedCreationUser) UserGet(param ReqGetUser) (*DataGateUser, error) {
110 url := fmt.Sprintf("%s%s%d", gateway.baseUrL, "/user/", param.UserId) 110 url := fmt.Sprintf("%s%s%d", gateway.baseUrL, "/user/", param.UserId)
111 method := "get" 111 method := "get"
112 req := gateway.CreateRequest(url, method) 112 req := gateway.CreateRequest(url, method)
@@ -332,7 +332,7 @@ func (gateway HttplibAlliedCreationUser) UserProfile(param ReqUserProfile) (*Dat @@ -332,7 +332,7 @@ func (gateway HttplibAlliedCreationUser) UserProfile(param ReqUserProfile) (*Dat
332 //UserUpdateBaseInfo 更新用户基础数据 332 //UserUpdateBaseInfo 更新用户基础数据
333 func (gateway HttplibAlliedCreationUser) UserUpdateBaseInfo(param ReqUserUpdateBaseInfo) (*DataUserUpdateBaseInfo, error) { 333 func (gateway HttplibAlliedCreationUser) UserUpdateBaseInfo(param ReqUserUpdateBaseInfo) (*DataUserUpdateBaseInfo, error) {
334 url := fmt.Sprintf("%s%s%d%s", gateway.baseUrL, "/user/", param.UserId, "/base-info") 334 url := fmt.Sprintf("%s%s%d%s", gateway.baseUrL, "/user/", param.UserId, "/base-info")
335 - method := "get" 335 + method := "put"
336 req := gateway.CreateRequest(url, method) 336 req := gateway.CreateRequest(url, method)
337 //TODO traceID 337 //TODO traceID
338 log.Logger.Debug("向用户模块请求数据:更新用户基础数据。", map[string]interface{}{ 338 log.Logger.Debug("向用户模块请求数据:更新用户基础数据。", map[string]interface{}{
@@ -50,13 +50,23 @@ type ( @@ -50,13 +50,23 @@ type (
50 50
51 //重置手机号 51 //重置手机号
52 type ( 52 type (
53 - ReqAuthResetPhone struct{} 53 + ReqAuthResetPhone struct {
  54 + // 用户Id 用户唯一标识
  55 + UserId int64 `cname:"用户Id 用户唯一标识" json:"userId"`
  56 + OldPhone string `cname:"" json:"oldPhone" valid:"Required"`
  57 + NewPhone string `cname:"" json:"newPhone" valid:"Required"`
  58 + }
54 DataAuthResetPhone struct{} 59 DataAuthResetPhone struct{}
55 ) 60 )
56 61
57 //重置密码(忘记密码) 62 //重置密码(忘记密码)
58 type ( 63 type (
59 - ReqAuthResetPassword struct{} 64 + ReqAuthResetPassword struct {
  65 + // 手机号码
  66 + Phone string `cname:"手机号码" json:"phone" valid:"Required"`
  67 + // 密码
  68 + Password string `cname:"密码" json:"password" valid:"Required"`
  69 + }
60 DataAuthResetPassword struct{} 70 DataAuthResetPassword struct{}
61 ) 71 )
62 72
@@ -182,7 +182,7 @@ type ( @@ -182,7 +182,7 @@ type (
182 182
183 //获取用户 183 //获取用户
184 type ( 184 type (
185 - ReqGateUser struct { 185 + ReqGetUser struct {
186 UserId int `json:"userId"` 186 UserId int `json:"userId"`
187 } 187 }
188 188
@@ -293,6 +293,14 @@ type ( @@ -293,6 +293,14 @@ type (
293 type ( 293 type (
294 ReqUserUpdateBaseInfo struct { 294 ReqUserUpdateBaseInfo struct {
295 UserId int64 `json:"userId"` 295 UserId int64 `json:"userId"`
  296 + // 用户姓名
  297 + UserName string `cname:"用户姓名" json:"userName" valid:"Required"`
  298 + // 头像
  299 + Avatar string `cname:"头像" json:"avatar" valid:"Required"`
  300 + // 手机号码
  301 + Phone string `cname:"手机号码" json:"phone" valid:"Required"`
  302 + // 邮箱
  303 + Email string `cname:"邮箱" json:"email" valid:"Required"`
296 } 304 }
297 DataUserUpdateBaseInfo struct { 305 DataUserUpdateBaseInfo struct {
298 } 306 }
@@ -23,7 +23,7 @@ func NewHttplibHttplibSmsServe() *HttplibSmsServe { @@ -23,7 +23,7 @@ func NewHttplibHttplibSmsServe() *HttplibSmsServe {
23 ConnectTimeout: 100 * time.Second, 23 ConnectTimeout: 100 * time.Second,
24 ReadWriteTimeout: 30 * time.Second, 24 ReadWriteTimeout: 30 * time.Second,
25 }, 25 },
26 - baseUrL: constant.ALLIED_CREATION_USER_HOST, 26 + baseUrL: constant.SMS_SERVE_HOST,
27 } 27 }
28 28
29 } 29 }
@@ -65,7 +65,7 @@ func (smsServe HttplibSmsServe) SendSms(phone string) error { @@ -65,7 +65,7 @@ func (smsServe HttplibSmsServe) SendSms(phone string) error {
65 65
66 //CheckSmsCode 公共短信验证码服务 校验验证码 66 //CheckSmsCode 公共短信验证码服务 校验验证码
67 func (smsServe HttplibSmsServe) CheckSmsCode(phone string, code string) error { 67 func (smsServe HttplibSmsServe) CheckSmsCode(phone string, code string) error {
68 - url := smsServe.baseUrL + "/service/sendSms" 68 + url := smsServe.baseUrL + "/service/checkSmsCode"
69 method := "post" 69 method := "post"
70 req := smsServe.CreateRequest(url, method) 70 req := smsServe.CreateRequest(url, method)
71 param := map[string]string{ 71 param := map[string]string{
@@ -83,3 +83,29 @@ func (controller *AuthController) GetUserOrg() { @@ -83,3 +83,29 @@ func (controller *AuthController) GetUserOrg() {
83 data, err := authService.GetUserOrg(userOrgCommand) 83 data, err := authService.GetUserOrg(userOrgCommand)
84 controller.Response(data, err) 84 controller.Response(data, err)
85 } 85 }
  86 +
  87 +func (controller *AuthController) CompanySignUp() {
  88 + authService := service.AuthService{}
  89 + userOrgCommand := &command.CompanySignUpCommand{}
  90 + err := controller.Unmarshal(userOrgCommand)
  91 + if err != nil {
  92 + controller.Response(nil, err)
  93 + return
  94 + }
  95 + //userOrgCommand.Operator = controller.GetOperator()
  96 + data, err := authService.CompanySignUp(userOrgCommand)
  97 + controller.Response(data, err)
  98 +}
  99 +
  100 +func (controller *AuthController) ResetPassword() {
  101 + authService := service.AuthService{}
  102 + userOrgCommand := &command.ResetPasswordCommand{}
  103 + err := controller.Unmarshal(userOrgCommand)
  104 + if err != nil {
  105 + controller.Response(nil, err)
  106 + return
  107 + }
  108 + //userOrgCommand.Operator = controller.GetOperator()
  109 + data, err := authService.ResetPassword(userOrgCommand)
  110 + controller.Response(data, err)
  111 +}
@@ -11,12 +11,63 @@ type UserController struct { @@ -11,12 +11,63 @@ type UserController struct {
11 11
12 func (controller *UserController) SendSmsCode() { 12 func (controller *UserController) SendSmsCode() {
13 authService := service.UserService{} 13 authService := service.UserService{}
14 - smsCodeCmd := &command.SendSmsCodeCommand{}  
15 - err := controller.Unmarshal(smsCodeCmd) 14 + cmd := &command.SendSmsCodeCommand{}
  15 + err := controller.Unmarshal(cmd)
16 if err != nil { 16 if err != nil {
17 controller.Response(nil, err) 17 controller.Response(nil, err)
18 return 18 return
19 } 19 }
20 - err = authService.SendSmsCaptcha(smsCodeCmd) 20 + err = authService.SendSmsCaptcha(cmd)
21 controller.Response(nil, err) 21 controller.Response(nil, err)
22 } 22 }
  23 +
  24 +func (controller *UserController) CheckSmsCode() {
  25 + authService := service.UserService{}
  26 + cmd := &command.CheckSmsCodeCommand{}
  27 + err := controller.Unmarshal(cmd)
  28 + if err != nil {
  29 + controller.Response(nil, err)
  30 + return
  31 + }
  32 + data, err := authService.CheckSmsCode(cmd)
  33 + controller.Response(data, err)
  34 +}
  35 +
  36 +func (controller *UserController) ChangePassword() {
  37 + authService := service.UserService{}
  38 + cmd := &command.ChangePasswordCommand{}
  39 + err := controller.Unmarshal(cmd)
  40 + if err != nil {
  41 + controller.Response(nil, err)
  42 + return
  43 + }
  44 + cmd.Operator = controller.GetOperator()
  45 + data, err := authService.ChangePassword(cmd)
  46 + controller.Response(data, err)
  47 +}
  48 +
  49 +func (controller *UserController) ChangePhone() {
  50 + authService := service.UserService{}
  51 + cmd := &command.ResetPhoneCommand{}
  52 + err := controller.Unmarshal(cmd)
  53 + if err != nil {
  54 + controller.Response(nil, err)
  55 + return
  56 + }
  57 + cmd.Operator = controller.GetOperator()
  58 + data, err := authService.ChangePhone(cmd)
  59 + controller.Response(data, err)
  60 +}
  61 +
  62 +func (controller *UserController) UpdateUserInfo() {
  63 + authService := service.UserService{}
  64 + cmd := &command.UpdateUserInfoCommand{}
  65 + err := controller.Unmarshal(cmd)
  66 + if err != nil {
  67 + controller.Response(nil, err)
  68 + return
  69 + }
  70 + cmd.Operator = controller.GetOperator()
  71 + data, err := authService.UpdateUserInfo(cmd)
  72 + controller.Response(data, err)
  73 +}
@@ -57,6 +57,18 @@ func (controller *CooperationModeController) RemoveCooperationMode() { @@ -57,6 +57,18 @@ func (controller *CooperationModeController) RemoveCooperationMode() {
57 controller.Response(data, err) 57 controller.Response(data, err)
58 } 58 }
59 59
  60 +func (controller *CooperationModeController) SearchCooperationMode() {
  61 + cooperationModeService := service.NewCooperationModeService(nil)
  62 + listCooperationModeQuery := &query.ListCooperationModeQuery{}
  63 + err := controller.Unmarshal(listCooperationModeQuery)
  64 + if err != nil {
  65 + log.Logger.Debug("json err:" + err.Error())
  66 + }
  67 + listCooperationModeQuery.Operator = controller.GetOperator()
  68 + cnt, data, err := cooperationModeService.ListCooperationMode(listCooperationModeQuery)
  69 + controller.returnPageListData(cnt, data, err, listCooperationModeQuery.PageNumber)
  70 +}
  71 +
60 func (controller *CooperationModeController) ListCooperationMode() { 72 func (controller *CooperationModeController) ListCooperationMode() {
61 cooperationModeService := service.NewCooperationModeService(nil) 73 cooperationModeService := service.NewCooperationModeService(nil)
62 listCooperationModeQuery := &query.ListCooperationModeQuery{} 74 listCooperationModeQuery := &query.ListCooperationModeQuery{}
@@ -15,4 +15,7 @@ func init() { @@ -15,4 +15,7 @@ func init() {
15 web.Router("/v1/app/user/user-info", &mobile_client.AuthController{}, "Post:GetUserInfo") 15 web.Router("/v1/app/user/user-info", &mobile_client.AuthController{}, "Post:GetUserInfo")
16 web.Router("/v1/app/user/user-menu", &mobile_client.AuthController{}, "Post:GetUserMenus") 16 web.Router("/v1/app/user/user-menu", &mobile_client.AuthController{}, "Post:GetUserMenus")
17 web.Router("/v1/app/user/user-orgs", &mobile_client.AuthController{}, "Post:GetUserOrg") 17 web.Router("/v1/app/user/user-orgs", &mobile_client.AuthController{}, "Post:GetUserOrg")
  18 +
  19 + web.Router("/v1/app/auth/company-sign-up", &mobile_client.AuthController{}, "Post:CompanySignUp")
  20 + web.Router("/v1/app/auth/reset-password", &mobile_client.AuthController{}, "Post:ResetPassword")
18 } 21 }
@@ -6,5 +6,10 @@ import ( @@ -6,5 +6,10 @@ import (
6 ) 6 )
7 7
8 func init() { 8 func init() {
9 - web.Router("/v1/app/users/smsCode", &mobile_client.UserController{}, "Post:SendSmsCode") 9 + web.Router("/v1/app/auth/smsCode", &mobile_client.UserController{}, "Post:SendSmsCode")
  10 + web.Router("/v1/app/auth/check-phone", &mobile_client.UserController{}, "Post:CheckSmsCode")
  11 +
  12 + web.Router("/v1/app/users/change-password", &mobile_client.UserController{}, "Post:ChangePassword")
  13 + web.Router("/v1/app/users/change-phone", &mobile_client.UserController{}, "Post:ChangePhone")
  14 + web.Router("/v1/app/users/personal", &mobile_client.UserController{}, "Post:UpdateUserInfo")
10 } 15 }
@@ -2,6 +2,7 @@ package routers @@ -2,6 +2,7 @@ package routers
2 2
3 import ( 3 import (
4 "github.com/beego/beego/v2/server/web" 4 "github.com/beego/beego/v2/server/web"
  5 + "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/mobile_client"
5 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client" 6 "gitlab.fjmaimaimai.com/allied-creation/allied-creation-gateway/pkg/port/beego/controllers/web_client"
6 ) 7 )
7 8
@@ -21,4 +22,6 @@ func init() { @@ -21,4 +22,6 @@ func init() {
21 web.Router("/v1/web/users/selector/org", &web_client.UsersController{}, "Post:SelectorCompanyOrg") 22 web.Router("/v1/web/users/selector/org", &web_client.UsersController{}, "Post:SelectorCompanyOrg")
22 web.Router("/v1/web/users/selector/role", &web_client.UsersController{}, "Post:SelectorCompanyRole") 23 web.Router("/v1/web/users/selector/role", &web_client.UsersController{}, "Post:SelectorCompanyRole")
23 web.Router("/v1/web/users/selector/org/all", &web_client.UsersController{}, "Post:SelectorCompanyOrgAll") 24 web.Router("/v1/web/users/selector/org/all", &web_client.UsersController{}, "Post:SelectorCompanyOrgAll")
  25 +
  26 + web.Router("/v1/web/auth/users-info", &mobile_client.AuthController{}, "Post:GetUserInfo")
24 } 27 }