diff --git a/db/hotimedb.go b/db/hotimedb.go index 670d67e..e524ae7 100644 --- a/db/hotimedb.go +++ b/db/hotimedb.go @@ -652,8 +652,10 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) { where := "" res := make([]interface{}, 0) length := len(k) - - if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' { + if k == "[#]" { + k = strings.Replace(k, "[#]", "", -1) + where += " " + ObjToStr(v) + " " + } else if length > 0 && strings.Contains(k, "[") && k[length-1] == ']' { def := false switch Substr(k, length-3, 3) { @@ -791,9 +793,6 @@ func (that *HoTimeDB) varCond(k string, v interface{}) (string, []interface{}) { } } - } else if k == "[#]" { - k = strings.Replace(k, "[#]", "", -1) - where += " " + ObjToStr(v) + " " } else { //fmt.Println(reflect.ValueOf(v).Type().String()) if !strings.Contains(k, ".") { diff --git a/example/app/order.go b/example/app/order.go index 29bdc5e..ee3b7f2 100644 --- a/example/app/order.go +++ b/example/app/order.go @@ -54,26 +54,30 @@ var orderCtr = Ctr{ this.Db.Update("ctg_order_date", Map{"now_sn": ctgOrderDate.GetCeilInt64("now_sn") + 1, "modify_time": time.Now().Unix()}, Map{"id": ctgOrderDate.GetCeilInt("id")}) //查询并发送短信 - category := this.Db.Get("category", "name", Map{"id": ctgOrderDate.GetCeilInt("category_id")}) - categorys := this.Db.Select("category", "org_id", Map{"index[~]": "," + ctgOrderDate.GetString("category_id") + ","}) - orgIDs := Slice{} + category := this.Db.Get("category", "`name`,`index`", Map{"id": ctgOrderDate.GetCeilInt("category_id")}) + //categorys := this.Db.Select("category", "org_id", Map{"index[~]": "," + ctgOrderDate.GetString("category_id") + ","}) + categorys := this.Db.Select("category", "org_id", Map{"[#]": "id IN (" + category.GetString("index")[1:len(category.GetString("index"))-1] + ")"}) + orgIDs := "" for _, v := range categorys { - orgs := this.Db.Select("org", "id", Map{"index[~]": v.GetCeilInt("org_id")}) + orgs := this.Db.Select("org", "id,`index`", Map{"id": v.GetCeilInt("org_id")}) for _, orgv := range orgs { - orgIDs = append(orgIDs, orgv.GetCeilInt("id")) + //orgIDs = append(orgIDs, orgv.GetCeilInt("id")) + orgIDs = orgIDs + orgv.GetString("index")[1:] } } - - admin := this.Db.Select("admin", "phone,id", Map{"org_id": orgIDs}) - user := this.Db.Get("user", "name", Map{"id": this.Session("id").ToCeilInt()}) - for _, v := range admin { - phone := v.GetString("phone") - if len(phone) == 11 { - ddsms.DefaultDDY.SendTz([]string{phone}, this.Config.GetString("smsNotice"), - map[string]string{"date": data.GetString("name"), "ctg": category.GetString("name"), - "name": user.GetString("name"), - "sn": data.GetString("sn"), - }) + if len(orgIDs) != 0 { + orgIDs = orgIDs[0 : len(orgIDs)-1] + admin := this.Db.Select("admin", "phone,id", Map{"[#]": "org_id IN (" + orgIDs + ")"}) + user := this.Db.Get("user", "name", Map{"id": this.Session("id").ToCeilInt()}) + for _, v := range admin { + phone := v.GetString("phone") + if len(phone) == 11 { + ddsms.DefaultDDY.SendTz([]string{phone}, this.Config.GetString("smsNotice"), + map[string]string{"date": data.GetString("name"), "ctg": category.GetString("name"), + "name": user.GetString("name"), + "sn": data.GetString("sn"), + }) + } } } diff --git a/example/bzyy.exe b/example/bzyy.exe index ef7c079..6c70dfc 100644 Binary files a/example/bzyy.exe and b/example/bzyy.exe differ diff --git a/example/config/config.json b/example/config/config.json index c979a6b..f8ac2b4 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -24,7 +24,7 @@ "db": { "mysql": { "host": "192.168.6.253", - "name": "bzyy", + "name": "bzyyweb", "password": "dasda8454456", "port": "3306", "prefix": "", diff --git a/example/main.go b/example/main.go index 17c95d3..5c2bd86 100644 --- a/example/main.go +++ b/example/main.go @@ -16,6 +16,7 @@ import ( func main() { date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00") fmt.Println(date, date.Unix()) + //fmt.Println("0123456"[1:7]) appIns := hotime.Init("config/config.json") //RESTfull接口适配 appIns.SetConnectListener(func(context *hotime.Context) bool {