作者 陈志颖

fix:增加修改手机号判断

... ... @@ -286,15 +286,29 @@ func (unifiedUserCenterService *UnifiedUserCenterService) SyncEmployeeCallback(s
break
case "changePhoneAllCompany": // 修改手机号
// 修改用户数据
err := employeeDao.ChangePhone(oldPhone, newPhone)
if err != nil {
if ok, err := employeeDao.EmployeeExist(oldPhone); err != nil {
return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
if ok {
err := employeeDao.ChangePhone(oldPhone, newPhone)
if err != nil {
return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
}
}
}
// 修改业务数据-素币兑换清单
errUpdateExchangeCashPersonList := cashPoolDao.UpdateExchangeCashPersonListUserInfo(oldPhone, newPhone)
if errUpdateExchangeCashPersonList != nil {
return false, application.ThrowError(application.TRANSACTION_ERROR, errUpdateExchangeCashPersonList.Error())
if ok, err := cashPoolDao.ExchangeCashPersonListExist(oldPhone); err != nil {
return false, application.ThrowError(application.TRANSACTION_ERROR, err.Error())
} else {
if ok {
errUpdateExchangeCashPersonList := cashPoolDao.UpdateExchangeCashPersonListUserInfo(oldPhone, newPhone)
if errUpdateExchangeCashPersonList != nil {
return false, application.ThrowError(application.TRANSACTION_ERROR, errUpdateExchangeCashPersonList.Error())
}
}
}
// 发布修改手机号事件
if err := changePhoneService.ChangePhone(oldPhone, newPhone); err != nil {
return nil, application.ThrowError(application.INTERNAL_SERVER_ERROR, err.Error())
... ...
... ... @@ -35,10 +35,19 @@ func (dao *CashPoolDao) CalculateActivityExchangedSuMoney(activityId int64) (map
}, nil
}
// ExchangeCashPersonListExist 判断素币兑换清单是否存在
func (dao *CashPoolDao) ExchangeCashPersonListExist(oldPhone string) (bool, error) {
tx := dao.transactionContext.PgTx
m := models.ExchangeCashPersonList{}
query := tx.Model(&m).Where("employee_account=?", oldPhone)
ok, err := query.Exists()
return ok, err
}
// UpdateExchangeCashPersonListUserInfo 更新素币兑换清单用户信息
func (dao *CashPoolDao) UpdateExchangeCashPersonListUserInfo(oldPhone string, newPhone string) error {
tx := dao.transactionContext.PgTx
if _, err := tx.QueryOne(
if _, err := tx.Query(
pg.Scan(),
"UPDATE exchange_cash_person_lists SET employee_account = ? WHERE employee_account = ?",
newPhone, oldPhone); err != nil {
... ...
... ... @@ -57,10 +57,19 @@ func (dao *EmployeeDao) ChangePrincipal(companyId int64, employeeAccount string)
return nil
}
// EmployeeExist 判断员工是否存在
func (dao *EmployeeDao) EmployeeExist(oldPhone string) (bool, error) {
tx := dao.transactionContext.PgTx
m := models.Employee{}
query := tx.Model(&m).Where("employee_account=?", oldPhone)
ok, err := query.Exists()
return ok, err
}
// ChangePhone 修改用户手机号
func (dao *EmployeeDao) ChangePhone(oldPhone string, newPhone string) error {
tx := dao.transactionContext.PgTx
if _, err := tx.QueryOne(
if _, err := tx.Query(
pg.Scan(),
"UPDATE employees SET employee_account=? WHERE employee_account=?",
newPhone, oldPhone); err != nil {
... ...
... ... @@ -16,7 +16,6 @@ func (serviceGateway *HttplibWorthServiceGateway) ChangePhoneCallback(oldPhone s
request := serviceGateway.createRequest(url, "post")
options := make(map[string]interface{})
options["phone"] = oldPhone
options["newPhone"] = newPhone
request.JSONBody(options)
response := make(map[string]interface{})
request.ToJSON(&response)
... ...