作者 陈志颖

fix:增加修改手机号判断

@@ -286,15 +286,29 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s @@ -286,15 +286,29 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
286 break 286 break
287 case "changePhoneAllCompany": // 修改手机号 287 case "changePhoneAllCompany": // 修改手机号
288 // 修改用户数据 288 // 修改用户数据
  289 + if ok, err := employeeDao.EmployeeExist(oldPhone); err != nil {
  290 + return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  291 + } else {
  292 + if ok {
289 err := employeeDao.ChangePhone(oldPhone, newPhone) 293 err := employeeDao.ChangePhone(oldPhone, newPhone)
290 if err != nil { 294 if err != nil {
291 return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error()) 295 return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
292 } 296 }
  297 + }
  298 + }
  299 +
293 // 修改业务数据-素币兑换清单 300 // 修改业务数据-素币兑换清单
  301 + if ok, err := cashPoolDao.ExchangeCashPersonListExist(oldPhone); err != nil {
  302 + return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
  303 + } else {
  304 + if ok {
294 errUpdateExchangeCashPersonList := cashPoolDao.UpdateExchangeCashPersonListUserInfo(oldPhone, newPhone) 305 errUpdateExchangeCashPersonList := cashPoolDao.UpdateExchangeCashPersonListUserInfo(oldPhone, newPhone)
295 if errUpdateExchangeCashPersonList != nil { 306 if errUpdateExchangeCashPersonList != nil {
296 return false, application.ThrowError(application.TRANSACTION_ERROR, errUpdateExchangeCashPersonList.Error()) 307 return false, application.ThrowError(application.TRANSACTION_ERROR, errUpdateExchangeCashPersonList.Error())
297 } 308 }
  309 + }
  310 + }
  311 +
298 // 发布修改手机号事件 312 // 发布修改手机号事件
299 if err := changePhoneService.ChangePhone(oldPhone, newPhone); err != nil { 313 if err := changePhoneService.ChangePhone(oldPhone, newPhone); err != nil {
300 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error()) 314 return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
@@ -35,10 +35,19 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map @@ -35,10 +35,19 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
35 }, nil 35 }, nil
36 } 36 }
37 37
  38 +// ExchangeCashPersonListExist 判断素币兑换清单是否存在
  39 +func (dao *CashPoolDao) ExchangeCashPersonListExist(oldPhone string) (bool, error) {
  40 + tx := dao.transactionContext.PgTx
  41 + m := models.ExchangeCashPersonList{}
  42 + query := tx.Model(&m).Where("employee_account=?", oldPhone)
  43 + ok, err := query.Exists()
  44 + return ok, err
  45 +}
  46 +
38 // UpdateExchangeCashPersonListUserInfo 更新素币兑换清单用户信息 47 // UpdateExchangeCashPersonListUserInfo 更新素币兑换清单用户信息
39 func (dao *CashPoolDao) UpdateExchangeCashPersonListUserInfo(oldPhone string, newPhone string) error { 48 func (dao *CashPoolDao) UpdateExchangeCashPersonListUserInfo(oldPhone string, newPhone string) error {
40 tx := dao.transactionContext.PgTx 49 tx := dao.transactionContext.PgTx
41 - if _, err := tx.QueryOne( 50 + if _, err := tx.Query(
42 pg.Scan(), 51 pg.Scan(),
43 "UPDATE exchange_cash_person_lists SET employee_account = ? WHERE employee_account = ?", 52 "UPDATE exchange_cash_person_lists SET employee_account = ? WHERE employee_account = ?",
44 newPhone, oldPhone); err != nil { 53 newPhone, oldPhone); err != nil {
@@ -57,10 +57,19 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string) @@ -57,10 +57,19 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string)
57 return nil 57 return nil
58 } 58 }
59 59
  60 +// EmployeeExist 判断员工是否存在
  61 +func (dao *EmployeeDao) EmployeeExist(oldPhone string) (bool, error) {
  62 + tx := dao.transactionContext.PgTx
  63 + m := models.Employee{}
  64 + query := tx.Model(&m).Where("employee_account=?", oldPhone)
  65 + ok, err := query.Exists()
  66 + return ok, err
  67 +}
  68 +
60 // ChangePhone 修改用户手机号 69 // ChangePhone 修改用户手机号
61 func (dao *EmployeeDao) ChangePhone(oldPhone string, newPhone string) error { 70 func (dao *EmployeeDao) ChangePhone(oldPhone string, newPhone string) error {
62 tx := dao.transactionContext.PgTx 71 tx := dao.transactionContext.PgTx
63 - if _, err := tx.QueryOne( 72 + if _, err := tx.Query(
64 pg.Scan(), 73 pg.Scan(),
65 "UPDATE employees SET employee_account=? WHERE employee_account=?", 74 "UPDATE employees SET employee_account=? WHERE employee_account=?",
66 newPhone, oldPhone); err != nil { 75 newPhone, oldPhone); err != nil {
@@ -16,7 +16,6 @@ func (serviceGateway *HttplibWorthServiceGateway) ChangePhoneCallback(oldPhone s @@ -16,7 +16,6 @@ func (serviceGateway *HttplibWorthServiceGateway) ChangePhoneCallback(oldPhone s
16 request := serviceGateway.createRequest(url, "post") 16 request := serviceGateway.createRequest(url, "post")
17 options := make(map[string]interface{}) 17 options := make(map[string]interface{})
18 options["phone"] = oldPhone 18 options["phone"] = oldPhone
19 - options["newPhone"] = newPhone  
20 request.JSONBody(options) 19 request.JSONBody(options)
21 response := make(map[string]interface{}) 20 response := make(map[string]interface{})
22 request.ToJSON(&response) 21 request.ToJSON(&response)