Exemple #1
0
func (s *accountRouter) UpdateAccountInfo(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	//不能直接接收一个json 对象,比较悲剧
	id := r.FormValue("id")
	qm := make(tool.RequestMongoKeyMap)
	kmaps := tool.KeyMaps{
		{MgoKey: "email"},
		{MgoKey: "telphone"},
		{MgoKey: "truename"},
		{MgoKey: "noticemessage"},
		{MgoKey: "noticeemail"},
	}
	kmaps.SetReqKeys()
	for _, kmap := range kmaps {
		qm.SetMgoQKey(kmap.MgoKey, r.FormValue(kmap.ReqKey))
	}
	qm.SetMgoQKeyBool("isnoticeemail", r.FormValue("isnoticeemail"), httputils.BoolValueOrDefault(r, "isnoticeemail", false))
	qm.SetMgoQKeyBool("isnoticemessage", r.FormValue("isnoticemessage"), httputils.BoolValueOrDefault(r, "isnoticemessage", false))
	qm.SetMgoQKeyValue("roles", getRoles(r))
	fmt.Println(qm.ParseUpdateToMongoSet())
	res, err := accountmanager.UpdateAccountById(id, qm.ParseUpdateToMongoSet())
	fmt.Println(res, err)
	if err == nil && res == true {
		operaaccount, _ := accountdao.GetAccountById(r.FormValue("accountid"))
		operalogdao.InsertAccountOperalog(operaaccount, operalogmodel.AccountUpdate, id, qm.ParseUpdateToMongoSet())
		return httputils.WriteSuccess(w, http.StatusOK)
	} else {
		return httputils.WriteError(w, accountmanager.ErrorCodeUpdateFAILD)
	}
}
Exemple #2
0
func (s *accountRouter) UpdateAccountById(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	res, _ := accountmanager.UpdateAccountById("", nil)
	return httputils.WriteJSON(w, http.StatusOK, res)
}