forked from golang/hotime
增加表关联新建功能,同时修复数据库bug
This commit is contained in:
parent
09b1d37ae3
commit
b480659a22
107
example/app/admin.go
Normal file
107
example/app/admin.go
Normal file
@ -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})
|
||||||
|
},
|
||||||
|
}
|
24
example/app/category.go
Normal file
24
example/app/category.go
Normal file
@ -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)
|
||||||
|
},
|
||||||
|
}
|
100
example/app/ctg_order_date.go
Normal file
100
example/app/ctg_order_date.go
Normal file
@ -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)
|
||||||
|
},
|
||||||
|
}
|
89
example/app/init.go
Normal file
89
example/app/init.go
Normal file
@ -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
|
||||||
|
}
|
66
example/app/order.go
Normal file
66
example/app/order.go
Normal file
@ -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)
|
||||||
|
},
|
||||||
|
}
|
107
example/app/org.go
Normal file
107
example/app/org.go
Normal file
@ -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})
|
||||||
|
},
|
||||||
|
}
|
107
example/app/role.go
Normal file
107
example/app/role.go
Normal file
@ -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})
|
||||||
|
},
|
||||||
|
}
|
54
example/app/user.go
Normal file
54
example/app/user.go
Normal file
@ -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, "登录成功")
|
||||||
|
|
||||||
|
},
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user