Example #1
0
func (s *accountRouter) getAccountManagePCA(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	//查询场所条件
	qm := make(tool.RequestMongoKeyMap)
	issa, shopids, err := accountmanager.GetAccountManageShopIdsByAccountId(r.FormValue("accountid"))
	if err != nil {
		return httputils.WriteJSON(w, http.StatusOK, errors.ErrorCodeOther.WithArgs("get manager shop error"))
	} else {
		if issa != true {
			if shopids != nil && len(shopids) > 0 {
				qm.SetInStringArray("_id", shopids)
			} else {
				return httputils.WriteJSON(w, http.StatusOK, errors.ErrorCodeOther.WithArgs("get manager shop error"))
			}
		}
	}
	res, err := accountmanager.GetAccountManageShopSimplesPCA(qm.ParseRequestToMongoQuery())
	pcasmap := map[string]int{}
	rolecount := 0
	for _, shop := range res {
		arr := make([]string, 3)
		arr[0] = shop.Province
		arr[1] = shop.City
		arr[2] = shop.Area
		if shop.Province != "" {
			pcastr := strings.Join(arr, ",")
			if pcasmap[pcastr] != 1 {
				pcasmap[strings.Join(arr, ",")] = 1
				rolecount++
			}
		}
	}
	roles := make([]accountmodel.Role, rolecount)
	pcaarr := make([]string, 3)
	roleiter := 0
	for key, _ := range pcasmap {
		pcaarr = strings.Split(key, ",")
		roles[roleiter] = accountmodel.Role{Province: pcaarr[0], City: pcaarr[1], Area: pcaarr[2]}
		roleiter++
	}
	if res != nil {
		return httputils.WriteJSON(w, http.StatusOK, tool.ResponsePage{List: roles})
	} else if err != nil {
		return httputils.WriteError(w, errors.ErrorCodeOther.WithArgs(err.Error()))
	} else {
		return httputils.WriteJSON(w, http.StatusOK, tool.ResponsePage{List: nil})
	}
}
Example #2
0
func (s *accountRouter) GetAccountById(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	accountid := vars["id"]
	if accountid == "" {
		return httputils.WriteError(w, accountmanager.ErrorCodeInvalidAccountId)
	}
	res, err := accountdao.GetAccountById(accountid)
	if res != nil {
		return httputils.WriteJSON(w, http.StatusOK, tool.ResponseItem{Item: res})
	} else if err == nil {
		return httputils.WriteError(w, accountmanager.ErrorCodeIdGetNULL.WithArgs(accountid))
	} else {
		return httputils.WriteError(w, err)
	}
}
Example #3
0
func (s *accountRouter) GetAccountsPage(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
	httputils.ParseForm(r)
	meta := httputils.GetPagination(r)
	qm := make(tool.RequestMongoKeyMap)
	qm.SetMgoQKey("truename", r.FormValue("truename"))
	qm.SetMgoQKey("email", r.FormValue("email"))
	qm.SetMgoQKey("name", r.FormValue("name"))
	qm.SetMgoQKey("telphone", r.FormValue("telphone"))
	accountid := r.FormValue("accountid")
	account, err := accountdao.GetAccountById(accountid)
	fmt.Println(account, err)
	manageraccountids := []bson.ObjectId{}
	if err != nil {
		return httputils.WriteError(w, errors.ErrorCodeOther.WithArgs(err.Error()))
	}
	if account.IsSuperAdmin == false {
		ajrs, _ := accountmanager.GetAccountJustRoles(nil, 0, 0)
		for _, ajr := range ajrs {
			for _, role := range ajr.Roles {
				str := role.ToPCAString()
				if CheckHasPermi(str, account.Roles) == true {
					fmt.Println(str)
					manageraccountids = append(manageraccountids, ajr.Id)
					break
				}
			}
		}
		qm.SetInMgoIdArray("_id", manageraccountids)
	}
	res, err := accountmanager.GetAccountsPage(meta, qm.ParseRequestToMongoQuery())
	if res != nil {
		return httputils.WriteJSON(w, http.StatusOK, res)
	} else if err == nil {
		return httputils.WriteError(w, errors.ErrorCodeOther.WithArgs(err.Error()))
	} else {
		return httputils.WriteError(w, err)
	}
}
Example #4
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)
}