From e1f4876621e80957e97f05fc9cf4fd0bec914455 Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Sun, 29 Aug 2021 06:08:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=A1=A8=E5=85=B3=E8=81=94?= =?UTF-8?q?=E6=96=B0=E5=BB=BA=E5=8A=9F=E8=83=BD=EF=BC=8C=E5=90=8C=E6=97=B6?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=95=B0=E6=8D=AE=E5=BA=93bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cache/cache_memory.go | 3 ++- example/app/category.go | 4 ++-- example/app/ctg_order_date.go | 12 ++++++++---- example/app/order.go | 8 ++++++-- example/config/config.json | 4 ++++ example/main.go | 4 ++++ 6 files changed, 26 insertions(+), 9 deletions(-) diff --git a/cache/cache_memory.go b/cache/cache_memory.go index 9247b3e..5dfa965 100644 --- a/cache/cache_memory.go +++ b/cache/cache_memory.go @@ -95,7 +95,8 @@ func (this *CacheMemory) delete(key string) { key = Substr(key, 0, del) for k, _ := range this.Map { if strings.Index(k, key) != -1 { - delete(this.Map, key) + delete(this.Map, k) + } } diff --git a/example/app/category.go b/example/app/category.go index 654a6fc..0597a2c 100644 --- a/example/app/category.go +++ b/example/app/category.go @@ -7,8 +7,8 @@ import ( var categoryCtr = Ctr{ "info": func(that *Context) { - //parentId:=ObjToInt(that.Req.FormValue("parent_id")) - parentId := ObjToInt(that.RouterString[2]) + parentId := ObjToInt(that.Req.FormValue("id")) + //parentId := ObjToInt(that.RouterString[2]) if parentId == 0 { parentId = 1 } diff --git a/example/app/ctg_order_date.go b/example/app/ctg_order_date.go index 554015b..b4feefa 100644 --- a/example/app/ctg_order_date.go +++ b/example/app/ctg_order_date.go @@ -12,7 +12,8 @@ var ctg_order_dateCtr = Ctr{ "info": func(that *Context) { //today:=time.Now().Weekday() - category := that.Db.Get("category", "*", Map{"id": that.RouterString[2]}) + id := ObjToInt(that.Req.FormValue("id")) + category := that.Db.Get("category", "*", Map{"id": id}) if category == nil { that.Display(4, "找不到该类别!") return @@ -52,8 +53,9 @@ var ctg_order_dateCtr = Ctr{ if day == 6 || day == 7 { continue } - fmt.Println(todayAMTime.Unix() + int64(24*60*60*(i+1))) - dayAM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": that.RouterString[2], "date": todayAMTime.Unix() + int64(24*60*60*(i+1))}}) + //fmt.Println(todayAMTime.Unix() + int64(24*60*60*(i+1))) + dayAM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"), + "date": todayAMTime.Unix() + int64(24*60*60*(i+1))}}) if dayAM == nil { dayAM = Map{"name": "9:00-12:00", "date": todayAMTime.Unix() + int64(24*60*60*(i+1)), @@ -71,8 +73,10 @@ var ctg_order_dateCtr = Ctr{ } } - dayPM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": that.RouterString[2], "date": todayPMTime.Unix() + int64(24*60*60*(i+1))}}) + dayPM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": category.GetCeilInt("id"), "date": todayPMTime.Unix() + int64(24*60*60*(i+1))}}) + fmt.Println(that.Db.LastQuery, that.Db.LastData, dayPM, that.Db.LastErr) if dayPM == nil { + fmt.Println("dasdasdasda") dayPM = Map{"name": "14:00-16:00", "date": todayPMTime.Unix() + int64(24*60*60*(i+1)), "create_time": time.Now().Unix(), diff --git a/example/app/order.go b/example/app/order.go index a0a4283..a8bb279 100644 --- a/example/app/order.go +++ b/example/app/order.go @@ -41,6 +41,7 @@ var orderCtr = Ctr{ "category_id": ctgOrderDate.GetCeilInt("category_id"), "admin_id": 1, "status": 1, + "name": time.Unix(ctgOrderDate.GetCeilInt64("date"), 0).Format("2006-01-02 ") + ctgOrderDate.GetString("name"), } data["id"] = this.Db.Insert("order", data) @@ -59,8 +60,11 @@ var orderCtr = Ctr{ return } - data := that.Db.Select("order", Map{"[><]user": "order.user_id=user.id", - "[><]category": "order.category_id=category.id"}, "*", Map{"user_id": that.Session("id").ToCeilInt()}) + data := that.Db.Select("order", "*", Map{"user_id": that.Session("id").ToCeilInt()}) + for _, v := range data { + v["category"] = that.Db.Get("category", "*", Map{"id": v.GetCeilInt("category_id")}) + v["parent_category"] = that.Db.Get("category", "id,name", Map{"id": v.GetMap("category").GetCeilInt("parent_id")}) + } that.Display(0, data) }, } diff --git a/example/config/config.json b/example/config/config.json index 535164a..58216aa 100644 --- a/example/config/config.json +++ b/example/config/config.json @@ -1,5 +1,9 @@ { "cache": { + "db": { + "db": false, + "session": true + }, "memory": { "db": true, "session": true, diff --git a/example/main.go b/example/main.go index 56ed4b4..a19ef5f 100644 --- a/example/main.go +++ b/example/main.go @@ -85,6 +85,10 @@ func main() { } context.Router[context.RouterString[0]][context.RouterString[1]]["add"](context) } + if len(context.RouterString) == 3 && + context.Req.Method == "POST" { + return true + } //查询单条 if len(context.RouterString) == 3 && context.Req.Method == "GET" {