fix: wecom user update
CI / changes (push) Successful in 13s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 0s
CI / chore (push) Successful in 0s
CI / express (push) Successful in 0s
CI / product (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 32s
CI / changes (push) Successful in 13s
CI / ad (push) Successful in 0s
CI / admin (push) Successful in 0s
CI / bff (push) Successful in 0s
CI / chore (push) Successful in 0s
CI / express (push) Successful in 0s
CI / product (push) Successful in 0s
CI / sale (push) Successful in 0s
CI / user (push) Successful in 0s
CI / wecom (push) Successful in 32s
This commit is contained in:
@@ -37,22 +37,15 @@ func (l *UpdateUserLogic) UpdateUser(in *wecom.UpdateUserReq) (*wecom.Response,
|
|||||||
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
if msg := validate.ValidateFromProto(in, &req); msg != utils.StringEmpty {
|
||||||
return outResponse(utils.ErrorParams, msg), nil
|
return outResponse(utils.ErrorParams, msg), nil
|
||||||
}
|
}
|
||||||
if req.Id < utils.NumberOne && (req.UserId < utils.NumberOne || req.Type < utils.NumberOne) {
|
if req.Id < utils.NumberOne {
|
||||||
return outResponse(utils.ErrorParams, "请传入 id 或 user_id+type"), nil
|
return outResponse(utils.ErrorParams, "请传入 id"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
m := model.UserModel{}.Init()
|
m := model.UserModel{}.Init()
|
||||||
var row dao.WecomUser
|
var row dao.WecomUser
|
||||||
w := modelbase.Params{Order: "id desc"}
|
if err := m.GetOne(modelbase.Params{
|
||||||
if req.Id > utils.NumberZero {
|
Eq: map[string]string{"id": strconv.FormatInt(req.Id, utils.NumberTen)},
|
||||||
w.Eq = map[string]string{"id": strconv.FormatInt(req.Id, utils.NumberTen)}
|
}, &row); err != nil {
|
||||||
} else {
|
|
||||||
w.Eq = map[string]string{
|
|
||||||
"user_id": strconv.FormatInt(req.UserId, utils.NumberTen),
|
|
||||||
"type": strconv.FormatUint(uint64(req.Type), utils.NumberTen),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := m.GetOne(w, &row); err != nil {
|
|
||||||
l.Errorf("wecom update user get: %v", err)
|
l.Errorf("wecom update user get: %v", err)
|
||||||
return failResponse(utils.Fail), nil
|
return failResponse(utils.Fail), nil
|
||||||
}
|
}
|
||||||
@@ -60,6 +53,14 @@ func (l *UpdateUserLogic) UpdateUser(in *wecom.UpdateUserReq) (*wecom.Response,
|
|||||||
return failResponse(utils.ErrorNotFund), nil
|
return failResponse(utils.ErrorNotFund), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
userId := row.UserId
|
||||||
|
if req.UserId > utils.NumberZero {
|
||||||
|
userId = req.UserId
|
||||||
|
}
|
||||||
|
typeVal := row.Type
|
||||||
|
if req.Type > utils.NumberZero {
|
||||||
|
typeVal = uint8(req.Type)
|
||||||
|
}
|
||||||
name := row.Name
|
name := row.Name
|
||||||
if req.Name != utils.StringEmpty {
|
if req.Name != utils.StringEmpty {
|
||||||
name = req.Name
|
name = req.Name
|
||||||
@@ -68,12 +69,26 @@ func (l *UpdateUserLogic) UpdateUser(in *wecom.UpdateUserReq) (*wecom.Response,
|
|||||||
if req.Avatar != utils.StringEmpty {
|
if req.Avatar != utils.StringEmpty {
|
||||||
avatar = req.Avatar
|
avatar = req.Avatar
|
||||||
}
|
}
|
||||||
typeVal := row.Type
|
|
||||||
if req.Type > utils.NumberZero {
|
|
||||||
typeVal = uint8(req.Type)
|
|
||||||
}
|
|
||||||
userStatus := resolveStatus(req.Status, row.Status)
|
userStatus := resolveStatus(req.Status, row.Status)
|
||||||
|
|
||||||
|
// 更换 user_id / type 时校验是否与已有启用记录冲突
|
||||||
|
if userId != row.UserId || typeVal != row.Type {
|
||||||
|
var existing dao.WecomUser
|
||||||
|
if err := m.GetOne(modelbase.Params{
|
||||||
|
Eq: map[string]string{
|
||||||
|
"user_id": strconv.FormatInt(userId, utils.NumberTen),
|
||||||
|
"type": strconv.FormatUint(uint64(typeVal), utils.NumberTen),
|
||||||
|
"status": strconv.Itoa(int(dao.StatusEnabled)),
|
||||||
|
},
|
||||||
|
}, &existing); err != nil {
|
||||||
|
l.Errorf("wecom update user unique check: %v", err)
|
||||||
|
return failResponse(utils.Fail), nil
|
||||||
|
}
|
||||||
|
if existing.Id > utils.NumberZero && existing.Id != row.Id {
|
||||||
|
return failResponse(utils.ErrorDataIsExist), nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
plainMobile := utils.StringEmpty
|
plainMobile := utils.StringEmpty
|
||||||
encryptMobile := row.Mobile
|
encryptMobile := row.Mobile
|
||||||
if req.Mobile != utils.StringEmpty {
|
if req.Mobile != utils.StringEmpty {
|
||||||
@@ -93,6 +108,16 @@ func (l *UpdateUserLogic) UpdateUser(in *wecom.UpdateUserReq) (*wecom.Response,
|
|||||||
plainMobile = dec
|
plainMobile = dec
|
||||||
}
|
}
|
||||||
|
|
||||||
|
agentsJSON := row.AgentIds
|
||||||
|
if len(req.AgentIds) > utils.NumberZero {
|
||||||
|
built, aErr := buildAgentsJSON(req.AgentIds)
|
||||||
|
if aErr != nil {
|
||||||
|
l.Errorf("wecom update agents: %v", aErr)
|
||||||
|
return outResponse(utils.ErrorParams, aErr.Error()), nil
|
||||||
|
}
|
||||||
|
agentsJSON = built
|
||||||
|
}
|
||||||
|
|
||||||
if !utils.GetConfigBool("wecom.skip") {
|
if !utils.GetConfigBool("wecom.skip") {
|
||||||
updateReq := wecomuser.UpdateRequest{
|
updateReq := wecomuser.UpdateRequest{
|
||||||
UserId: row.WecomUserId,
|
UserId: row.WecomUserId,
|
||||||
@@ -109,25 +134,18 @@ func (l *UpdateUserLogic) UpdateUser(in *wecom.UpdateUserReq) (*wecom.Response,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data := map[string]interface{}{
|
if _, err := m.Edit(modelbase.Params{
|
||||||
|
Eq: map[string]string{"id": strconv.FormatInt(row.Id, utils.NumberTen)},
|
||||||
|
}, map[string]interface{}{
|
||||||
|
"user_id": userId,
|
||||||
|
"type": typeVal,
|
||||||
"name": name,
|
"name": name,
|
||||||
"mobile": encryptMobile,
|
"mobile": encryptMobile,
|
||||||
"avatar": avatar,
|
"avatar": avatar,
|
||||||
"status": userStatus,
|
"status": userStatus,
|
||||||
"type": typeVal,
|
"agent_ids": agentsJSON,
|
||||||
"updated_at": utils.Now(),
|
"updated_at": utils.Now(),
|
||||||
}
|
}); err != nil {
|
||||||
if len(req.AgentIds) > utils.NumberZero {
|
|
||||||
agentsJSON, aErr := buildAgentsJSON(req.AgentIds)
|
|
||||||
if aErr != nil {
|
|
||||||
l.Errorf("wecom update agents: %v", aErr)
|
|
||||||
return outResponse(utils.ErrorParams, aErr.Error()), nil
|
|
||||||
}
|
|
||||||
data["agent_ids"] = agentsJSON
|
|
||||||
}
|
|
||||||
if _, err := m.Edit(modelbase.Params{
|
|
||||||
Eq: map[string]string{"id": strconv.FormatInt(row.Id, utils.NumberTen)},
|
|
||||||
}, data); err != nil {
|
|
||||||
l.Errorf("wecom update user db: %v", err)
|
l.Errorf("wecom update user db: %v", err)
|
||||||
return failResponse(utils.Fail), nil
|
return failResponse(utils.Fail), nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user