package models import ( "annual-lottery2/models/model" "annual-lottery2/utils" "strings" "github.com/astaxie/beego" ) // UserFilters 用户过滤 func UserFilters(lvl string) ([]model.TaUser, string) { cf := "./conf/test.conf" usrs := make([]model.TaUser, 0) notIn := make([]string, 0) beego.Info("--------> 1") if !utils.FileExists(cf) { return usrs, "" } beego.Info("--------> 2") conf, err := utils.GetConfig(cf) if err != nil { return usrs, "" } beego.Info("--------> 3") pls := conf.String("conf") if pls == "" { return usrs, "" } for _, pl := range strings.Split(pls, ",") { for _, us := range strings.Split(conf.DefaultString(pl+"::us", ""), ",") { if us == "" { continue } usArr := strings.Split(us, "-") if pl == lvl { usrs = append(usrs, model.TaUser{ UserName: usArr[1], UserOrg: usArr[0], }) } else { notIn = append(notIn, "user_name = '"+usArr[1]+"' and user_org = '"+usArr[0]+"'") } } } notExists := "" if len(notIn) > 0 { notExists = "select * from ta_user o where o.user_id = t.user_id and ((" + strings.Join(notIn, ") or (") + "))" } return usrs, notExists }