作者 陈志颖

feat:添加修改用户手机号

@@ -76,7 +76,7 @@ spec: @@ -76,7 +76,7 @@ spec:
76 - name: UCENTER_SECRET 76 - name: UCENTER_SECRET
77 value: "cykbjnfqgctn" 77 value: "cykbjnfqgctn"
78 - name: UCENTER_APP_KEY 78 - name: UCENTER_APP_KEY
79 - value: "39aefef9e22744a3b2d2d3791824ae7b"s 79 + value: "39aefef9e22744a3b2d2d3791824ae7b"
80 - name: UCENTER_CHECK_ALT 80 - name: UCENTER_CHECK_ALT
81 value: "rsF0pL!6DwjBO735" 81 value: "rsF0pL!6DwjBO735"
82 - name: BUSINESS_ADMIN_HOST 82 - name: BUSINESS_ADMIN_HOST
@@ -76,6 +76,12 @@ type ImportEmployeeData struct { @@ -76,6 +76,12 @@ type ImportEmployeeData struct {
76 Edit []EmployeeData `json:"edit"` 76 Edit []EmployeeData `json:"edit"`
77 } 77 }
78 78
  79 +// ChangePhoneData 修改手机号
  80 +type ChangePhoneData struct {
  81 + OldPhone string `json:"oldPhone"`
  82 + NewPhone string `json:"newPhone"`
  83 +}
  84 +
79 //SyncEmployeeService 同步用户数据 85 //SyncEmployeeService 同步用户数据
80 type SyncEmployeeService struct{} 86 type SyncEmployeeService struct{}
81 87
@@ -144,6 +150,18 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro @@ -144,6 +150,18 @@ func (service SyncEmployeeService) DoAction(action string, byteData []byte) erro
144 // case "batchRemove": 150 // case "batchRemove":
145 // //移动通讯录用户部门 暂时不需要 151 // //移动通讯录用户部门 暂时不需要
146 // return nil 152 // return nil
  153 + case "changePhone": // TODO 修改手机号
  154 + // 修改手机号
  155 + var (
  156 + err error
  157 + data ChangePhoneData
  158 + )
  159 + err = json.Unmarshal(byteData, &data)
  160 + if err != nil {
  161 + return fmt.Errorf("数据解析失败:%s", err)
  162 + }
  163 +
  164 + return nil
147 case "import": 165 case "import":
148 //批量导入 166 //批量导入
149 var ( 167 var (
@@ -428,6 +446,31 @@ func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) e @@ -428,6 +446,31 @@ func (service SyncEmployeeService) updateUsersStatus(data ForbidAllowUserData) e
428 return err 446 return err
429 } 447 }
430 448
  449 +// ChangePhone 修改手机号
  450 +func (service SyncEmployeeService) changePhone(data ChangePhoneData) error {
  451 + var (
  452 + transactionContext, _ = factory.CreateTransactionContext(nil)
  453 + err error
  454 + )
  455 + if err = transactionContext.StartTransaction(); err != nil {
  456 + return err
  457 + }
  458 + defer func() {
  459 + _ = transactionContext.RollbackTransaction()
  460 + }()
  461 + var uDao *dao.UsersDao
  462 + if uDao, err = factory.CreateUsersDao(map[string]interface{}{
  463 + "transactionContext": transactionContext,
  464 + }); err != nil {
  465 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  466 + }
  467 + if err = uDao.UpdateUserPhone(data.OldPhone, data.NewPhone); err != nil {
  468 + return lib.ThrowError(lib.INTERNAL_SERVER_ERROR, err.Error())
  469 + }
  470 + err = transactionContext.CommitTransaction()
  471 + return err
  472 +}
  473 +
431 //ChangeAdmin 变更公司负责人,超级管理员 474 //ChangeAdmin 变更公司负责人,超级管理员
432 func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdminCommand) error { 475 func (service SyncEmployeeService) ChangeSuperAdmin(cmd command.ChanceSuperAdminCommand) error {
433 var ( 476 var (
@@ -30,3 +30,14 @@ func (dao UsersDao) UpdateUserStatus(ids []int64, ststus int8) error { @@ -30,3 +30,14 @@ func (dao UsersDao) UpdateUserStatus(ids []int64, ststus int8) error {
30 Update() 30 Update()
31 return err 31 return err
32 } 32 }
  33 +
  34 +// UpdateUserPhone 更新用户手机号
  35 +func (dao UsersDao) UpdateUserPhone(oldPhone string, newPhone string) error {
  36 + tx := dao.transactionContext.PgTx
  37 + m := &models.Users{}
  38 + _, err := tx.Model(m).
  39 + Set("phone", newPhone).
  40 + Where("phone = ?", oldPhone).
  41 + Update()
  42 + return err
  43 +}