书写前端代码

This commit is contained in:
hoteas 2021-12-11 17:59:02 +08:00
parent 0e33c2ad9d
commit 388bc5006d
14 changed files with 657 additions and 439 deletions

View File

@ -294,15 +294,21 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
// 没有保存就生成随机的session
cookie, err := req.Cookie(that.Config.GetString("sessionName"))
sessionId := Md5(strconv.Itoa(Rand(10)))
token := req.FormValue("token")
token := req.Header.Get("Authorization")
if len(token) != 32 {
token = req.Header.Get("Authorization")
}
if len(token) == 32 && cookie.Value != token {
token = req.FormValue("token")
}
//没有cookie或者cookie不等于token
//有token优先token
if len(token) == 32 {
sessionId = token
} else {
//没有token则查阅session
} else if err == nil && cookie.Value != "" {
sessionId = cookie.Value
//session也没有则判断是否创建cookie
} else {
//没有跨域设置
if that.Config.GetString("crossDomain") == "" {
http.SetCookie(w, &http.Cookie{Name: that.Config.GetString("sessionName"), Value: sessionId, Path: "/"})
@ -310,7 +316,6 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
//跨域允许需要设置cookie的允许跨域https才有效果
w.Header().Set("Set-Cookie", that.Config.GetString("sessionName")+"="+sessionId+"; Path=/; SameSite=None; Secure")
}
}
unescapeUrl, err := url.QueryUnescape(req.RequestURI)

View File

@ -5,7 +5,7 @@ import (
. "../../../hotime/common"
)
var ID = "b6e1eae6a28c3e962c4e5e6b4650209e"
var ID = "34c88440ab840823226a8b5f6ccfc1f9"
// Project 管理端项目
var Project = Proj{

53
example/app/admin.go Normal file
View File

@ -0,0 +1,53 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
)
var adminCtr = Ctr{
"token": func(this *Context) {
this.Display(0, this.SessionId)
},
"test": func(this *Context) {
this.Session("id", this.SessionId)
},
//自带的登录
"login": func(this *Context) {
name := this.Req.FormValue("name")
pwd := this.Req.FormValue("password")
if len(name) < 2 ||
len(pwd) < 3 {
this.Display(3, "数据校验不通过")
}
where := Map{"password": Md5(pwd)}
if len(name) == 11 {
where["phone"] = name
} else {
where["name"] = name
}
admin := this.Db.Get("admin", "*", Map{"AND": where})
if admin == nil {
this.Display(4, "账户密码错误")
return
}
this.Session("id", admin.GetCeilInt("id"))
admin["password"] = nil
this.Display(0, admin)
},
"info": func(this *Context) {
admin := this.Db.Get("admin", "*", Map{"id": this.Session("id").ToInt()})
if admin == nil {
this.Display(2, "登录失效,请重新登录")
return
}
admin["password"] = nil
this.Display(0, admin)
},
}

View File

@ -1,34 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
)
var categoryCtr = Ctr{
"info": func(that *Context) {
parentId := ObjToInt(that.Req.FormValue("id"))
//parentId := ObjToInt(that.RouterString[2])
childData := []Map{}
if parentId == 0 {
childData1 := that.Db.Select("category", "*", Map{"parent_id": nil})
for _, v := range childData1 {
data := that.Db.Get("category", "*", Map{"parent_id": v.GetCeilInt("id")})
if data != nil {
childData = append(childData, data)
}
}
} else {
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)
},
}

View File

@ -1,103 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"time"
)
var ctg_order_dateCtr = Ctr{
"info": func(that *Context) {
//today:=time.Now().Weekday()
id := ObjToInt(that.Req.FormValue("id"))
category := that.Db.Get("category", "*", Map{"id": id})
if category == nil {
that.Display(4, "找不到该类别!")
return
}
todayPMTime, _ := time.ParseInLocation("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00", time.Local)
todayAMTime, _ := time.ParseInLocation("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 09:00", time.Local)
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": category.GetCeilInt("id"),
"date": todayAMTime.Unix() + int64(24*60*60*(i+1))}})
if dayAM == nil {
dayAM = Map{"name": "9:00-11:30",
"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": 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": "13:30-16:30",
"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)
},
}

View File

@ -3,29 +3,17 @@ package app
import (
. "../../../hotime"
. "../../../hotime/common"
"bytes"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/x509"
"encoding/base64"
"encoding/hex"
"encoding/pem"
"fmt"
"io/ioutil"
"net/http"
"net/url"
"time"
)
// Project 管理端项目
var Project = Proj{
//"user": UserCtr,
"category": categoryCtr,
"ctg_order_date": ctg_order_dateCtr,
"order": orderCtr,
"user": userCtr,
"sms": Sms,
"product_spot_check": product_spot_checkCtr,
"product": productCtr,
"admin": adminCtr,
"sms": Sms,
"material": materialCtr,
"material_inout": material_inoutCtr,
}
//生成随机码的4位随机数
@ -36,86 +24,3 @@ func getCode() string {
//}
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
}
var privateKey = `-----BEGIN RSA Private Key-----
MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAJJuFUH/4m9H5hCCzxtd9BxpjWlG9gbejqiJpV0XJKaU1V7xDBJasswxPY7Zc15RoxWClPoKPwKrbWKm49dgBJebJq5xd4sLCSbboxRkKxpRiJHMZ4LJjYa5h9Ei9RyfoUzqGHqH4UrDy3m3IwPiP19cIBqoU50shyQf92ZpcGZhAgMBAAECgYEAiadU8pODoUs82x6tZbPALQmJN4PO+wwznfqv6sA74yGdKECAMazz0oMjtGt1SiCCqFD2jcweCftvvELZg3mvNg1V0vRQRD1ZCA8HDp8DXm20d11K3+RX39tR4KgyyM3HsSEhkUDujMxKIpYjyiB5iEtV7Ja9bZ2fROszq+mUIqUCQQDQQf6vWRMLBqfnDcU77vuDGOhXbjkF2ytLxLW3fbKaW3GWvC3n93zPM+mcvWSXgkl448+jFjpMktm1Vn+w+YX3AkEAs/+bbRbod6AcVbLu8C5E44qDRoRpu+LF7Cphp8tlSAIRjm2yGP5acMWGRUtH9MF2QJYPF0PgDzdmUSVqWnCAZwJBALnSuRri4wAKn1SmT+ALfLZcSiyBODZGeppv2ijw6qWahH8YR+ncRaxoyMFHqPMbmM1akJIXqktbGREaLnPOIb8CQQCdJycJaL3Qa98xR4dr9cm5rF6PO96g5w6M8jfO6ztjUkMHymh7f99wpFRlvaN2Y06edyV315ARWPohEPy5N44zAkBlLuDHLm1TkTTAfdlL5r2OcdjpaJYloTdn05Mp3+J+w1zTX8k6Mz8lFZtLUcoMeTfQ9rm/+u2KwxS8NljtSZWH
-----END RSA Private Key-----
`
func RSA_Decrypt(cipherTextBase64 string) string {
cipherText, _ := base64.StdEncoding.DecodeString(cipherTextBase64)
buf := []byte(privateKey)
//pem解码
block, _ := pem.Decode(buf)
//X509解码
private, err := x509.ParsePKCS8PrivateKey(block.Bytes)
if err != nil {
return ""
}
//对密文进行解密
//plainText,_:=rsa.DecryptPKCS1v15(rand.Reader,privateKey,cipherText)
v, err := rsa.DecryptPKCS1v15(rand.Reader, private.(*rsa.PrivateKey), cipherText)
if err != nil {
return ""
}
//返回明文
v1, err1 := url.QueryUnescape(string(v))
if err1 != nil {
return ""
}
return v1
}

140
example/app/material.go Normal file
View File

@ -0,0 +1,140 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"strings"
"time"
)
var materialCtr = Ctr{
"info": func(that *Context) {
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
where := Map{"id": that.RouterString[2]}
if len(inData) == 1 {
inData["id"] = where["id"]
where = Map{"AND": inData}
} else if len(inData) > 1 {
where["OR"] = inData
where = Map{"AND": where}
}
re := that.Db.Get(that.RouterString[1], str, where)
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"), "id,"+column.GetString("value"), Map{"id": v})
}
}
that.Display(0, re)
},
"add": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
name := that.Req.FormValue("name")
img := that.Req.FormValue("img")
rule := that.Req.FormValue("rule")
if name == "" || rule == "" {
that.Display(3, "参数不足,请补充参数")
return
}
data := Map{
"name": name,
"img": img,
"rule": rule,
"admin_id": adminID,
"count": 0,
"used": 0,
"saved": 0,
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
}
id := that.Db.Insert("material", data)
if id == 0 {
that.Display(4, "添加材料失败,请重新添加")
return
}
data["id"] = id
that.Display(0, data)
},
"update": func(that *Context) {
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "没有找到要更新的数据")
return
}
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
Index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": that.RouterString[2]})
parentIndex := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
inData["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
childNodes := that.Db.Select(that.RouterString[1], "id,`index`", Map{"index[~]": "," + that.RouterString[2] + ","})
for _, v := range childNodes {
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
that.Db.Update(that.RouterString[1], Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
}
}
re := that.Db.Update(that.RouterString[1], inData, Map{"id": that.RouterString[2]})
if re == 0 {
that.Display(4, "更新数据失败")
return
}
that.Display(0, re)
},
"search": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
leftJoin := Map{"[><]admin": "material.admin_id=admin.id"}
columnStr := "sn,name,img,count,used,saved,admin_id,admin.name AS admin_name,modify_time,state"
where := Map{"state": 0, "ORDER": "modify_time DESC"}
count := that.Db.Count("material", "id", where)
reData := that.Db.Page(page, pageSize).
PageSelect("material", leftJoin, columnStr, where)
that.Display(0, Map{"count": count, "data": reData})
},
}

View File

@ -0,0 +1,163 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"strings"
"time"
)
var material_inoutCtr = Ctr{
"info": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数不足,请检查参数")
return
}
re := that.Db.Get("material_inout", "*", Map{"id": id})
if re == nil {
that.Display(4, "找不到对应信息")
return
}
that.Display(0, re)
},
"add": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
img := that.Req.FormValue("img")
rule := that.Req.FormValue("rule")
materialId := ObjToInt(that.Req.FormValue("material_id"))
produceId := ObjToInt(that.Req.FormValue("produce_id"))
count := ObjToInt(that.Req.FormValue("count"))
state := ObjToInt(that.Req.FormValue("state"))
if rule == "" || materialId == 0 || count == 0 {
that.Display(3, "参数不足,请补充参数")
return
}
if state > 0 {
count = -count
}
that.Db.Update("material", Map{"count[#]": "count+" + ObjToStr(count), "saved[#]": "saved+" + ObjToStr(count)}, Map{"id": materialId})
material := that.Db.Get("material", "*", Map{"id": materialId})
data := Map{
"img": img,
"rule": rule,
"admin_id": adminID,
"material_id": materialId,
"count": count,
"saved": material.GetCeilInt("count"),
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
"produce_id": produceId,
"state": state,
}
id := that.Db.Insert("material_inout", data)
if id == 0 {
that.Display(4, "添加出入库记录失败,请重新添加")
return
}
data["id"] = id
that.Display(0, data)
},
"update": func(that *Context) {
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "没有找到要更新的数据")
return
}
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
Index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": that.RouterString[2]})
parentIndex := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
inData["index"] = parentIndex.GetString("index") + that.RouterString[2] + ","
childNodes := that.Db.Select(that.RouterString[1], "id,`index`", Map{"index[~]": "," + that.RouterString[2] + ","})
for _, v := range childNodes {
v["index"] = strings.Replace(v.GetString("index"), Index.GetString("index"), inData.GetString("index"), -1)
that.Db.Update(that.RouterString[1], Map{"index": v["index"]}, Map{"id": v.GetCeilInt("id")})
}
}
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) {
inData := that.MakeCode.Delete(that.RouterString[1], that.Req)
if inData == nil {
that.Display(3, "请求参数不足")
return
}
re := int64(0)
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetSlice("index") != nil {
re = that.Db.Delete(that.RouterString[1], Map{"index[~]": "," + that.RouterString[2] + ","})
} else {
re = that.Db.Delete(that.RouterString[1], Map{"id": that.RouterString[2]})
}
if re == 0 {
that.Display(4, "删除数据失败")
return
}
that.Display(0, "删除成功")
},
"search": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
columnStr := "sn,material.name,img,count,saved,admin_id,admin.name AS admin_name,modify_time,state"
leftJoin := Map{"[><]material": "material_inout.material_id=material.id",
"[><]admin": "material_inout.admin_id=admin.id",
}
where := Map{"ORDER": "modify_time DESC"}
count := that.Db.Count("material_inout", "id", where)
reData := that.Db.Page(page, pageSize).
PageSelect("material_inout", leftJoin, columnStr, where)
that.Display(0, Map{"count": count, "data": reData})
},
}

View File

@ -1,99 +0,0 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"../../dri/ddsms"
"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,
"name": time.Unix(ctgOrderDate.GetCeilInt64("date"), 0).Format("2006-01-02 ") + ctgOrderDate.GetString("name"),
}
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")})
//查询并发送短信
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,`index`", Map{"id": v.GetCeilInt("org_id")})
for _, orgv := range orgs {
//orgIDs = append(orgIDs, orgv.GetCeilInt("id"))
orgIDs = orgIDs + orgv.GetString("index")[1:]
}
}
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"),
})
}
}
}
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_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)
},
}

120
example/app/product.go Normal file
View File

@ -0,0 +1,120 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"time"
)
var productCtr = Ctr{
"info": func(that *Context) {
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db)
where := Map{"id": that.RouterString[2]}
if len(inData) == 1 {
inData["id"] = where["id"]
where = Map{"AND": inData}
} else if len(inData) > 1 {
where["OR"] = inData
where = Map{"AND": where}
}
re := that.Db.Get(that.RouterString[1], str, where)
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"), "id,"+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
}
//索引管理,便于检索以及权限
if inData.Get("parent_id") != nil && inData.GetString("index") != "" {
index := that.Db.Get(that.RouterString[1], "`index`", Map{"id": inData.Get("parent_id")})
inData["index"] = index.GetString("index") + ObjToStr(re) + ","
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
} else if inData.GetString("index") != "" {
inData["index"] = "," + ObjToStr(re) + ","
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
}
that.Display(0, re)
},
"update": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
ruleSpotCheck := that.Req.FormValue("rule_spot_check")
if id == 0 || ruleSpotCheck == "" {
that.Display(3, "请求参数不足,请检查参数")
return
}
re := that.Db.Update("product", Map{"rule_spot_check": ruleSpotCheck, "modify_time": time.Now().Unix()}, Map{"id": id})
if re == 0 {
that.Display(4, "更新失败,无法更新抽检参数")
return
}
that.Display(0, "更新成功")
},
"search": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
leftJoin := Map{"[><]admin": "product.admin_id=admin.id"}
columnStr := "sn,name,img,count,used,saved,spot_check_saved,admin_id,admin.name AS admin_name,modify_time,state"
where := Map{"state": 0, "ORDER": "modify_time DESC"}
count := that.Db.Count("product", "id", where)
reData := that.Db.Page(page, pageSize).
PageSelect("product", leftJoin, columnStr, where)
that.Display(0, Map{"product": count, "data": reData})
},
}

View File

@ -0,0 +1,120 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"time"
)
var product_spot_checkCtr = Ctr{
"info": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数不足,请检查参数")
return
}
re := that.Db.Get("product_spot_check",
Map{"[><]product": "product_spot_check.product_id=product.id",
"[><]produce": "product_spot_check.produce_id=produce.id",
},
"id,img,product_id,product.name AS product_name,admin_id,"+
"modify_time,state,rule,produce_id,produce.name AS produce_name", Map{"id": id})
if re == nil {
that.Display(4, "找不到对应信息")
return
}
that.Display(0, re)
},
"add": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
img := that.Req.FormValue("img")
rule := that.Req.FormValue("rule")
produceProductId := ObjToInt(that.Req.FormValue("produce_product_id"))
count := ObjToInt(that.Req.FormValue("count"))
state := ObjToInt(that.Req.FormValue("state"))
if rule == "" || produceProductId == 0 || count == 0 {
that.Display(3, "参数不足,请补充参数")
return
}
if state > 0 {
count = -count
}
produceProduct := that.Db.Get("produce_product", "*", Map{"id": produceProductId})
that.Db.Update("product", Map{"spot_check_count[#]": "spot_check_count+" + ObjToStr(count),
"spot_check_saved[#]": "spot_check_saved+" + ObjToStr(count)},
Map{"id": produceProduct.GetCeilInt("product_id")})
that.Db.Update("produce", Map{"spot_check_count[#]": "spot_check_count+" + ObjToStr(count),
"spot_check_saved[#]": "spot_check_saved+" + ObjToStr(count)},
Map{"id": produceProduct.GetCeilInt("produce_id")})
data := Map{
"img": img,
"rule": rule,
"admin_id": adminID,
"create_time": time.Now().Unix(),
"modify_time": time.Now().Unix(),
"produce_id": produceProduct.GetCeilInt("produce_id"),
"produce_product_id": produceProductId,
"state": state,
}
id := that.Db.Insert("product_spot_check", data)
if id == 0 {
that.Display(4, "添加抽检记录失败,请重新添加")
return
}
data["id"] = id
that.Display(0, data)
},
"search": func(that *Context) {
adminID := that.Session("id").ToInt()
if adminID == 0 {
that.Display(2, "登录失效,请重新登录")
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
columnStr := "sn,product.name,img,count,saved,admin_id,admin.name AS admin_name,modify_time,state"
leftJoin := Map{"[><]product": "product_spot_check.product_id=product.id",
"[><]admin": "product_spot_check.admin_id=admin.id",
}
where := Map{"ORDER": "modify_time DESC"}
count := that.Db.Count("product_spot_check", "id", where)
reData := that.Db.Page(page, pageSize).
PageSelect("product_spot_check", leftJoin, columnStr, where)
that.Display(0, Map{"count": count, "data": reData})
},
}

View File

@ -1,94 +0,0 @@
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)
},
//自带的登录
"login": func(this *Context) {
phone := RSA_Decrypt(this.Req.FormValue("phone"))
idcard := RSA_Decrypt(this.Req.FormValue("idcard"))
name := RSA_Decrypt(this.Req.FormValue("name"))
if len(phone) != 11 ||
len(idcard) != 18 ||
len(name) < 1 {
this.Display(3, "数据校验不通过")
}
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, "登录成功")
},
"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.Session("code", nil)
this.Display(0, "登录成功")
},
}

View File

@ -1,5 +1,5 @@
{
"id": "b6e1eae6a28c3e962c4e5e6b4650209e",
"id": "34c88440ab840823226a8b5f6ccfc1f9",
"label": "HoTime管理平台",
"menus": [
{
@ -19,6 +19,14 @@
"label": "原材料管理",
"table": "material"
},
{
"label": "原材料管理",
"table": "material"
},
{
"label": "原材料管理",
"table": "material"
},
{
"label": "原材料管理",
"table": "material"
@ -42,6 +50,14 @@
"label": "生产成品",
"table": "produce_product"
},
{
"label": "生产计划",
"table": "produce"
},
{
"label": "生产计划",
"table": "produce"
},
{
"label": "生产计划",
"table": "produce"
@ -69,6 +85,14 @@
"label": "产线管理",
"table": "product_line"
},
{
"label": "成品管理",
"table": "product"
},
{
"label": "成品管理",
"table": "product"
},
{
"label": "成品管理",
"table": "product"
@ -1132,6 +1156,24 @@
"label": "其他规则",
"name": "rule",
"type": "text"
},
{
"label": "抽检覆盖量",
"name": "spot_check_count",
"sortable": true,
"type": "number"
},
{
"label": "发货抽检总覆盖量",
"name": "spot_check_used",
"sortable": true,
"type": "number"
},
{
"label": "总抽检总覆盖量",
"name": "spot_check_saved",
"sortable": true,
"type": "number"
}
],
"label": "生产计划",

Binary file not shown.