From b480659a22b9d2ec97b6c02b368ea4e63d62781b Mon Sep 17 00:00:00 2001 From: hoteas <925970985@qq.com> Date: Sat, 28 Aug 2021 13:06:00 +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 --- example/app/admin.go | 107 ++++++++++++++++++++++++++++++++++ example/app/category.go | 24 ++++++++ example/app/ctg_order_date.go | 100 +++++++++++++++++++++++++++++++ example/app/init.go | 89 ++++++++++++++++++++++++++++ example/app/order.go | 66 +++++++++++++++++++++ example/app/org.go | 107 ++++++++++++++++++++++++++++++++++ example/app/role.go | 107 ++++++++++++++++++++++++++++++++++ example/app/user.go | 54 +++++++++++++++++ 8 files changed, 654 insertions(+) create mode 100644 example/app/admin.go create mode 100644 example/app/category.go create mode 100644 example/app/ctg_order_date.go create mode 100644 example/app/init.go create mode 100644 example/app/order.go create mode 100644 example/app/org.go create mode 100644 example/app/role.go create mode 100644 example/app/user.go diff --git a/example/app/admin.go b/example/app/admin.go new file mode 100644 index 0000000..fa75973 --- /dev/null +++ b/example/app/admin.go @@ -0,0 +1,107 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" +) + +var adminCtr = Ctr{ + "info": func(that *Context) { + re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) + + if re == nil { + that.Display(4, "找不到对应信息") + return + } + + for k, v := range re { + + column := that.MakeCode.TableColumns[that.RouterString[1]][k] + if column == nil { + continue + } + if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { + re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) + } + } + + that.Display(0, re) + }, + "add": func(that *Context) { + inData := that.MakeCode.Add(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "请求参数不足") + return + } + re := that.Db.Insert(that.RouterString[1], inData) + + if re == 0 { + that.Display(4, "无法插入对应数据") + return + } + + that.Display(0, re) + }, + "update": func(that *Context) { + inData := that.MakeCode.Edit(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "没有找到要更新的数据") + return + } + re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) + + if re == 0 { + that.Display(4, "更新数据失败") + return + } + + that.Display(0, re) + }, + "remove": func(that *Context) { + re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) + + if re == 0 { + that.Display(4, "删除数据失败") + return + } + that.Display(0, re) + }, + "search": func(that *Context) { + + columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], that.Req, that.Db) + page := ObjToInt(that.Req.FormValue("page")) + pageSize := ObjToInt(that.Req.FormValue("pageSize")) + + if page < 1 { + page = 1 + } + + if pageSize <= 0 { + pageSize = 20 + } + + count := that.Db.Count(that.RouterString[1], leftJoin, where) + reData := that.Db.Page(page, pageSize). + PageSelect(that.RouterString[1], leftJoin, columnStr, where) + + for _, v := range reData { + for k, _ := range v { + column := that.MakeCode.TableColumns[that.RouterString[1]][k] + if column == nil { + continue + } + + if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { + parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = "" + if parentC != nil { + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value")) + } + } + + } + } + + that.Display(0, Map{"count": count, "data": reData}) + }, +} diff --git a/example/app/category.go b/example/app/category.go new file mode 100644 index 0000000..654a6fc --- /dev/null +++ b/example/app/category.go @@ -0,0 +1,24 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" +) + +var categoryCtr = Ctr{ + "info": func(that *Context) { + //parentId:=ObjToInt(that.Req.FormValue("parent_id")) + parentId := ObjToInt(that.RouterString[2]) + if parentId == 0 { + parentId = 1 + } + + childData := that.Db.Select("category", "*", Map{"parent_id": parentId}) + + for _, v := range childData { + v["child"] = that.Db.Select("category", "*", Map{"parent_id": v.GetCeilInt("id")}) + } + + that.Display(0, childData) + }, +} diff --git a/example/app/ctg_order_date.go b/example/app/ctg_order_date.go new file mode 100644 index 0000000..554015b --- /dev/null +++ b/example/app/ctg_order_date.go @@ -0,0 +1,100 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" + "fmt" + "time" +) + +var ctg_order_dateCtr = Ctr{ + + "info": func(that *Context) { + + //today:=time.Now().Weekday() + category := that.Db.Get("category", "*", Map{"id": that.RouterString[2]}) + if category == nil { + that.Display(4, "找不到该类别!") + return + } + + todayPMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00") + todayAMTime, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02"+" 09:00")) + + weekDay := 1 + + switch time.Now().Weekday().String() { + case "Monday": + weekDay = 1 + case "Tuesday": + weekDay = 2 + case "Wednesday": + weekDay = 3 + case "Thursday": + weekDay = 4 + case "Friday": + weekDay = 5 + case "Saturday": + weekDay = 6 + case "Sunday": + weekDay = 7 + + } + + ////future:=that.Db.Select("ctg_order_date","*",Map{"category_id":that.RouterString[2],"date[>]":time}) + date := Slice{} + for i := 0; i < 7; i++ { + day := weekDay + i + 1 + + if day > 7 { + day = day - 7 + } + 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))}}) + if dayAM == nil { + dayAM = Map{"name": "9:00-12:00", + "date": todayAMTime.Unix() + int64(24*60*60*(i+1)), + "create_time": time.Now().Unix(), + "modify_time": time.Now().Unix(), + "start_sn": category.GetCeilInt("start_sn"), + "max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("am"+ObjToStr(day)), + "now_sn": category.GetCeilInt("start_sn"), + "category_id": category.GetCeilInt("id"), + } + dayAM["id"] = that.Db.Insert("ctg_order_date", dayAM) + if dayAM.GetCeilInt64("id") == 0 { + that.Display(4, "内部错误!") + return + } + } + + dayPM := that.Db.Get("ctg_order_date", "*", Map{"AND": Map{"category_id": that.RouterString[2], "date": todayPMTime.Unix() + int64(24*60*60*(i+1))}}) + if dayPM == nil { + dayPM = Map{"name": "14:00-16:00", + "date": todayPMTime.Unix() + int64(24*60*60*(i+1)), + "create_time": time.Now().Unix(), + "modify_time": time.Now().Unix(), + "start_sn": category.GetCeilInt("start_sn"), + "max_sn": category.GetCeilInt("start_sn") + category.GetCeilInt("pm"+ObjToStr(day)), + "now_sn": category.GetCeilInt("start_sn"), + "category_id": category.GetCeilInt("id"), + } + dayPM["id"] = that.Db.Insert("ctg_order_date", dayPM) + if dayPM.GetCeilInt64("id") == 0 { + that.Display(4, "内部错误!") + return + } + } + + date = append(date, Map{"name": "星期" + ObjToStr(day) + "(" + time.Unix(todayPMTime.Unix()+int64(24*60*60*(i+1)), 0).Format("01-02") + ")", + "am": dayAM, + "pm": dayPM, + }) + } + + that.Display(0, date) + }, +} diff --git a/example/app/init.go b/example/app/init.go new file mode 100644 index 0000000..9d5dd0a --- /dev/null +++ b/example/app/init.go @@ -0,0 +1,89 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" + "bytes" + "crypto/sha256" + "encoding/hex" + "fmt" + "io/ioutil" + "net/http" + "time" +) + +var ID = "aad1472b19e575a71ee8f75629e27867" + +// Project 管理端项目 +var Project = Proj{ + //"user": UserCtr, + "admin": adminCtr, + "category": categoryCtr, + "ctg_order_date": ctg_order_dateCtr, + "order": orderCtr, + "org": orgCtr, + "role": roleCtr, + "user": userCtr, + "sms": Sms, +} + +//生成随机码的4位随机数 +func getCode() string { + //res := "" + //for i := 0; i < 4; i++ { + res := ObjToStr(RandX(1000, 9999)) + //} + return res +} + +func tencentSendYzm(umobile, code string) error { + + random := RandX(999999, 9999999) + url := "https://yun.tim.qq.com/v5/tlssmssvr/sendsms?sdkappid=1400235813&random=" + ObjToStr(random) + fmt.Println("URL:>", url) + + h := sha256.New() + h.Write([]byte(`appkey=d511de15e5ccb43fc171772dbb8b599f&random=` + ObjToStr(random) + `&time=` + ObjToStr(time.Now().Unix()) + `&mobile=` + umobile)) + bs := h.Sum(nil) + s256 := hex.EncodeToString(bs) + + //json序列化 + post := `{ + "ext": "", + "extend": "", + "params": [ + "` + code + `" + ], + "sig": "` + s256 + `", + "sign": "乐呵呵旅游网", + "tel": { + "mobile": "` + umobile + `", + "nationcode": "86" + }, + "time": ` + ObjToStr(time.Now().Unix()) + `, + "tpl_id": 378916 +}` + + fmt.Println(url, "post", post) + + var jsonStr = []byte(post) + fmt.Println("jsonStr", jsonStr) + fmt.Println("new_str", bytes.NewBuffer(jsonStr)) + + req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) + // req.Header.Set("X-Custom-Header", "myvalue") + req.Header.Set("Content-Type", "application/json") + + client := &http.Client{} + resp, err := client.Do(req) + if err != nil { + return err + } + defer resp.Body.Close() + + fmt.Println("response Status:", resp.Status) + fmt.Println("response Headers:", resp.Header) + body, _ := ioutil.ReadAll(resp.Body) + fmt.Println("response Body:", string(body)) + return nil +} diff --git a/example/app/order.go b/example/app/order.go new file mode 100644 index 0000000..a0a4283 --- /dev/null +++ b/example/app/order.go @@ -0,0 +1,66 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" + "time" +) + +var orderCtr = Ctr{ + "count": func(this *Context) { + if this.Session("id").ToCeilInt() == 0 { + this.Display(2, "没有登录!") + return + } + re := Map{} + re["total"] = this.Db.Count("order", Map{"user_id": this.Session("id").ToCeilInt()}) + re["finish"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 2}}) + re["late"] = this.Db.Count("order", Map{"AND": Map{"user_id": this.Session("id").ToCeilInt(), "status": 3}}) + + this.Display(0, re) + }, + "add": func(this *Context) { + if this.Session("id").ToCeilInt() == 0 { + this.Display(2, "没有登录!") + return + } + ctgOrderDateId := ObjToInt(this.Req.FormValue("ctg_order_date_id")) + //ctgId:=ObjToInt(this.Req.FormValue("category_id")) + ctgOrderDate := this.Db.Get("ctg_order_date", "*", Map{"id": ctgOrderDateId}) + + if ctgOrderDate.GetCeilInt64("now_sn")+1 > ctgOrderDate.GetCeilInt64("max_sn") { + this.Display(5, "当前排号已经用完") + return + } + + data := Map{"create_time": time.Now().Unix(), + "modify_time": time.Now().Unix(), + "user_id": this.Session("id").ToCeilInt(), + "date": ctgOrderDate.GetString("date"), + "sn": ctgOrderDate.GetCeilInt64("now_sn") + 1, + "category_id": ctgOrderDate.GetCeilInt("category_id"), + "admin_id": 1, + "status": 1, + } + + data["id"] = this.Db.Insert("order", data) + + if data.GetCeilInt("id") == 0 { + this.Display(5, "预约失败") + return + } + + this.Db.Update("ctg_order_date", Map{"now_sn": ctgOrderDate.GetCeilInt64("now_sn") + 1, "modify_time": time.Now().Unix()}, Map{"id": ctgOrderDate.GetCeilInt("id")}) + this.Display(0, data) + }, + "search": func(that *Context) { + if that.Session("id").ToCeilInt() == 0 { + that.Display(2, "没有登录!") + 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()}) + that.Display(0, data) + }, +} diff --git a/example/app/org.go b/example/app/org.go new file mode 100644 index 0000000..99f0b6b --- /dev/null +++ b/example/app/org.go @@ -0,0 +1,107 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" +) + +var orgCtr = Ctr{ + "info": func(that *Context) { + re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) + + if re == nil { + that.Display(4, "找不到对应信息") + return + } + + for k, v := range re { + + column := that.MakeCode.TableColumns[that.RouterString[1]][k] + if column == nil { + continue + } + if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { + re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) + } + } + + that.Display(0, re) + }, + "add": func(that *Context) { + inData := that.MakeCode.Add(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "请求参数不足") + return + } + re := that.Db.Insert(that.RouterString[1], inData) + + if re == 0 { + that.Display(4, "无法插入对应数据") + return + } + + that.Display(0, re) + }, + "update": func(that *Context) { + inData := that.MakeCode.Edit(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "没有找到要更新的数据") + return + } + re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) + + if re == 0 { + that.Display(4, "更新数据失败") + return + } + + that.Display(0, re) + }, + "remove": func(that *Context) { + re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) + + if re == 0 { + that.Display(4, "删除数据失败") + return + } + that.Display(0, re) + }, + "search": func(that *Context) { + + columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], that.Req, that.Db) + page := ObjToInt(that.Req.FormValue("page")) + pageSize := ObjToInt(that.Req.FormValue("pageSize")) + + if page < 1 { + page = 1 + } + + if pageSize <= 0 { + pageSize = 20 + } + + count := that.Db.Count(that.RouterString[1], leftJoin, where) + reData := that.Db.Page(page, pageSize). + PageSelect(that.RouterString[1], leftJoin, columnStr, where) + + for _, v := range reData { + for k, _ := range v { + column := that.MakeCode.TableColumns[that.RouterString[1]][k] + if column == nil { + continue + } + + if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { + parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = "" + if parentC != nil { + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value")) + } + } + + } + } + + that.Display(0, Map{"count": count, "data": reData}) + }, +} diff --git a/example/app/role.go b/example/app/role.go new file mode 100644 index 0000000..70542c6 --- /dev/null +++ b/example/app/role.go @@ -0,0 +1,107 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" +) + +var roleCtr = Ctr{ + "info": func(that *Context) { + re := that.Db.Get(that.RouterString[1], that.MakeCode.Info(that.RouterString[1]), Map{"id": that.RouterString[2]}) + + if re == nil { + that.Display(4, "找不到对应信息") + return + } + + for k, v := range re { + + column := that.MakeCode.TableColumns[that.RouterString[1]][k] + if column == nil { + continue + } + if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { + re[column.GetString("link")] = that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v}) + } + } + + that.Display(0, re) + }, + "add": func(that *Context) { + inData := that.MakeCode.Add(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "请求参数不足") + return + } + re := that.Db.Insert(that.RouterString[1], inData) + + if re == 0 { + that.Display(4, "无法插入对应数据") + return + } + + that.Display(0, re) + }, + "update": func(that *Context) { + inData := that.MakeCode.Edit(that.RouterString[1], that.Req) + if inData == nil { + that.Display(3, "没有找到要更新的数据") + return + } + re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]}) + + if re == 0 { + that.Display(4, "更新数据失败") + return + } + + that.Display(0, re) + }, + "remove": func(that *Context) { + re := that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]}) + + if re == 0 { + that.Display(4, "删除数据失败") + return + } + that.Display(0, re) + }, + "search": func(that *Context) { + + columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], that.Req, that.Db) + page := ObjToInt(that.Req.FormValue("page")) + pageSize := ObjToInt(that.Req.FormValue("pageSize")) + + if page < 1 { + page = 1 + } + + if pageSize <= 0 { + pageSize = 20 + } + + count := that.Db.Count(that.RouterString[1], leftJoin, where) + reData := that.Db.Page(page, pageSize). + PageSelect(that.RouterString[1], leftJoin, columnStr, where) + + for _, v := range reData { + for k, _ := range v { + column := that.MakeCode.TableColumns[that.RouterString[1]][k] + if column == nil { + continue + } + + if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { + parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = "" + if parentC != nil { + v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = parentC.GetString(column.GetString("value")) + } + } + + } + } + + that.Display(0, Map{"count": count, "data": reData}) + }, +} diff --git a/example/app/user.go b/example/app/user.go new file mode 100644 index 0000000..65b6752 --- /dev/null +++ b/example/app/user.go @@ -0,0 +1,54 @@ +package app + +import ( + . "../../../hotime" + . "../../../hotime/common" + "time" +) + +var userCtr = Ctr{ + "token": func(this *Context) { + this.Display(0, this.SessionId) + }, + "test": func(this *Context) { + this.Session("id", 1) + }, + "add": func(this *Context) { + if this.Req.FormValue("code") != this.Session("code").ToStr() || + this.Req.FormValue("phone") != this.Session("phone").ToStr() { + this.Display(3, "短信验证不通过") + return + } + + phone := this.Req.FormValue("phone") + idcard := this.Req.FormValue("idcard") + name := this.Req.FormValue("name") + + user := this.Db.Get("user", "*", Map{"phone": phone}) + + if user == nil { + user = Map{"phone": phone, "idcard": idcard, "name": name, "create_time": time.Now().Unix(), "modify_time": time.Now().Unix()} + user["id"] = this.Db.Insert("user", user) + + } else { + user["phone"] = phone + user["idcard"] = idcard + user["name"] = name + user["modify_time"] = time.Now().Unix() + re := this.Db.Update("user", user, Map{"id": user.GetCeilInt64("id")}) + if re == 0 { + this.Display(4, "系统错误") + return + } + } + + if user.GetCeilInt64("id") == 0 { + this.Display(5, "登录失败") + return + } + + this.Session("id", user.GetCeilInt("id")) + this.Display(0, "登录成功") + + }, +}