Merge branch 'zct-v2' of https://code.hoteas.com/golang/hotime into zhoupengwei

This commit is contained in:
zhoupengwei 2022-05-05 10:44:10 +08:00
commit afa9b173ba
50 changed files with 4583 additions and 219 deletions

0
.tgitconfig Normal file
View File

View File

@ -20,8 +20,7 @@ import (
) )
type Application struct { type Application struct {
*code.MakeCode MakeCodeRouter map[string]*code.MakeCode
MakeCodeRouter Router
MethodRouter MethodRouter
Router Router
ContextBase ContextBase
@ -71,8 +70,14 @@ func (that *Application) Run(router Router) {
that.Router = Router{} that.Router = Router{}
} }
for k, v := range router { for k, v := range router {
if that.Router[k] == nil {
that.Router[k] = v that.Router[k] = v
} }
for k1, v1 := range v {
that.Router[k][k1] = v1
}
}
//重新设置MethodRouter//直达路由 //重新设置MethodRouter//直达路由
that.MethodRouter = MethodRouter{} that.MethodRouter = MethodRouter{}
modeRouterStrict := true modeRouterStrict := true
@ -257,8 +262,8 @@ func (that *Application) SetConfig(configPath ...string) {
} }
// SetConnectListener 连接判断,返回true继续传输至控制层false则停止传输 // SetConnectListener 连接判断,返回false继续传输至控制层true则停止传输
func (that *Application) SetConnectListener(lis func(that *Context) bool) { func (that *Application) SetConnectListener(lis func(that *Context) (isFinished bool)) {
that.connectListener = append(that.connectListener, lis) that.connectListener = append(that.connectListener, lis)
} }
@ -359,16 +364,15 @@ func (that *Application) handler(w http.ResponseWriter, req *http.Request) {
//访问拦截true继续false暂停 //访问拦截true继续false暂停
connectListenerLen := len(that.connectListener) connectListenerLen := len(that.connectListener)
if connectListenerLen != 0 {
for i := 0; i < connectListenerLen; i++ {
if !that.connectListener[i](&context) { for i := connectListenerLen - 1; i >= 0; i-- {
if that.connectListener[i](&context) {
context.View() context.View()
return return
} }
} }
}
//接口服务 //接口服务
//验证接口严格模式 //验证接口严格模式
@ -526,45 +530,65 @@ func (that *Application) crossDomain(context *Context, sessionId string) {
} }
//Init 初始化application //Init 初始化application
func Init(config string) Application { func Init(config string) *Application {
appIns := Application{} appIns := Application{}
//手动模式, //手动模式,
appIns.SetConfig(config) appIns.SetConfig(config)
SetDB(&appIns) SetDB(&appIns)
appIns.SetCache() appIns.SetCache()
appIns.MakeCode = &code.MakeCode{} codeConfig := appIns.Config.GetSlice("codeConfig")
codeConfig := appIns.Config.GetMap("codeConfig")
appIns.MakeCodeRouter = Router{}
if codeConfig != nil { if codeConfig != nil {
for k, _ := range codeConfig { for k, _ := range codeConfig {
if appIns.Config.GetInt("mode") == 2 { codeMake := codeConfig.GetMap(k)
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, true) if codeMake == nil {
appIns.MakeCodeRouter[k] = Proj{} continue
} else if appIns.Config.GetInt("mode") == 3 { }
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), &appIns.Db, false) //codeMake["table"] = k
appIns.MakeCodeRouter[k] = Proj{} if appIns.MakeCodeRouter == nil {
appIns.MakeCodeRouter = map[string]*code.MakeCode{}
}
if codeMake.GetString("name") == "" {
codeMake["name"] = codeMake.GetString("table")
}
if appIns.Config.GetInt("mode") > 0 {
appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(&appIns.Db, codeMake)
} else { } else {
appIns.MakeCode.Db2JSON(k, codeConfig.GetString(k), nil, false) appIns.MakeCodeRouter[codeMake.GetString("name")] = &code.MakeCode{}
appIns.MakeCodeRouter[k] = Proj{} appIns.MakeCodeRouter[codeMake.GetString("name")].Db2JSON(nil, codeMake)
} }
//接入动态代码层 //接入动态代码层
if appIns.Router == nil { if appIns.Router == nil {
appIns.Router = Router{} appIns.Router = Router{}
} }
appIns.Router[k] = TptProject
for k1, _ := range appIns.MakeCode.TableColumns { //appIns.Router[codeMake.GetString("name")] = TptProject
appIns.Router[k][k1] = appIns.Router[k]["hotimeCommon"] appIns.Router[codeMake.GetString("name")] = Proj{}
for k2, _ := range TptProject {
appIns.Router[codeMake.GetString("name")][k2] = Ctr{}
for k3, v3 := range TptProject[k2] {
appIns.Router[codeMake.GetString("name")][k2][k3] = v3
}
} }
setMakeCodeLintener(k, &appIns) for k1, _ := range appIns.MakeCodeRouter[codeMake.GetString("name")].TableColumns {
appIns.Router[codeMake.GetString("name")][k1] = appIns.Router[codeMake.GetString("name")]["hotimeCommon"]
}
go func() {
setMakeCodeLintener(codeMake.GetString("name"), &appIns)
}()
} }
} }
return appIns return &appIns
} }
// SetDB 智能数据库设置 // SetDB 智能数据库设置
@ -625,83 +649,86 @@ func SetSqliteDB(appIns *Application, config Map) {
} }
func setMakeCodeLintener(name string, appIns *Application) { func setMakeCodeLintener(name string, appIns *Application) {
appIns.SetConnectListener(func(context *Context) bool { appIns.SetConnectListener(func(context *Context) (isFinished bool) {
if len(context.RouterString) < 2 || appIns.MakeCodeRouter[context.RouterString[0]] == nil {
return true
}
if len(context.RouterString) > 1 && context.RouterString[0] == name {
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
return true
}
if context.RouterString[1] == "hotime" && context.RouterString[2] == "logout" {
return true
}
if context.Session(name+"_id").Data == nil {
context.Display(2, "你还没有登录")
return false
}
}
codeIns := appIns.MakeCodeRouter[name]
//文件上传接口 //文件上传接口
if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" { if len(context.RouterString) == 1 && context.RouterString[0] == "file" && context.Req.Method == "POST" {
if context.Session(name+"_id").Data == nil { if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
context.Display(2, "你还没有登录") context.Display(2, "你还没有登录")
return false return true
} }
//读取网络文件 //读取网络文件
fi, fheader, err := context.Req.FormFile("file") fi, fheader, err := context.Req.FormFile("file")
if err != nil { if err != nil {
context.Display(3, err) context.Display(3, err)
return false return true
} }
filePath := context.Config.GetString("filePath") filePath := context.Config.GetString("filePath")
if filePath == "" { if filePath == "" {
filePath = "file/2006/01/02/" filePath = "/file/2006/01/02/"
} }
path := time.Now().Format(filePath) path := time.Now().Format(filePath)
e := os.MkdirAll(context.Config.GetString("tpt")+"/"+path, os.ModeDir) e := os.MkdirAll(context.Config.GetString("tpt")+path, os.ModeDir)
if e != nil { if e != nil {
context.Display(3, e) context.Display(3, e)
return false return true
} }
filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):] filePath = path + Md5(ObjToStr(RandX(100000, 9999999))) + fheader.Filename[strings.LastIndex(fheader.Filename, "."):]
newFile, e := os.Create(context.Config.GetString("tpt") + "/" + filePath) newFile, e := os.Create(context.Config.GetString("tpt") + filePath)
if e != nil { if e != nil {
context.Display(3, e) context.Display(3, e)
return false return true
} }
_, e = io.Copy(newFile, fi) _, e = io.Copy(newFile, fi)
if e != nil { if e != nil {
context.Display(3, e) context.Display(3, e)
return false return true
} }
context.Display(0, filePath) context.Display(0, filePath)
return false return true
}
if len(context.RouterString) < 2 || appIns.MakeCodeRouter[context.RouterString[0]] == nil {
return isFinished
}
if len(context.RouterString) > 1 && context.RouterString[0] == name {
if context.RouterString[1] == "hotime" && context.RouterString[2] == "login" {
return isFinished
}
if context.RouterString[1] == "hotime" && context.RouterString[2] == "logout" {
return isFinished
}
if context.Session(codeIns.FileConfig.GetString("table")+"_id").Data == nil {
context.Display(2, "你还没有登录")
return true
}
} }
if len(context.RouterString) < 2 || len(context.RouterString) > 3 || if len(context.RouterString) < 2 || len(context.RouterString) > 3 ||
!(context.Router[context.RouterString[0]] != nil && !(context.Router[context.RouterString[0]] != nil &&
context.Router[context.RouterString[0]][context.RouterString[1]] != nil) { context.Router[context.RouterString[0]][context.RouterString[1]] != nil) {
return true return isFinished
} }
//排除无效操作 //排除无效操作
if len(context.RouterString) == 2 && if len(context.RouterString) == 2 &&
context.Req.Method != "GET" && context.Req.Method != "GET" &&
context.Req.Method != "POST" { context.Req.Method != "POST" {
return true return isFinished
} }
//列表检索 //列表检索
if len(context.RouterString) == 2 && if len(context.RouterString) == 2 &&
context.Req.Method == "GET" { context.Req.Method == "GET" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil { if context.Router[context.RouterString[0]][context.RouterString[1]]["search"] == nil {
return true return isFinished
} }
context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context) context.Router[context.RouterString[0]][context.RouterString[1]]["search"](context)
} }
@ -715,14 +742,14 @@ func setMakeCodeLintener(name string, appIns *Application) {
} }
if len(context.RouterString) == 3 && if len(context.RouterString) == 3 &&
context.Req.Method == "POST" { context.Req.Method == "POST" {
return true return isFinished
} }
//查询单条 //查询单条
if len(context.RouterString) == 3 && if len(context.RouterString) == 3 &&
context.Req.Method == "GET" { context.Req.Method == "GET" {
if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil { if context.Router[context.RouterString[0]][context.RouterString[1]]["info"] == nil {
return true return isFinished
} }
context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context) context.Router[context.RouterString[0]][context.RouterString[1]]["info"](context)
@ -747,7 +774,8 @@ func setMakeCodeLintener(name string, appIns *Application) {
context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context) context.Router[context.RouterString[0]][context.RouterString[1]]["remove"](context)
} }
context.View() context.View()
return false return true
}) })
} }

18
cache/cache_db.go vendored
View File

@ -58,7 +58,7 @@ func (that *CacheDb) initDbTable() {
return return
} }
_, e := that.Db.Exec("CREATE TABLE `" + that.Db.GetPrefix() + "cached` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `ckey` varchar(60) DEFAULT NULL, `cvalue` varchar(2000) DEFAULT NULL, `time` bigint(20) DEFAULT NULL, `endtime` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=198740 DEFAULT CHARSET=utf8") _, e := that.Db.Exec("CREATE TABLE `" + that.Db.GetPrefix() + "cached` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `key` varchar(60) DEFAULT NULL, `value` varchar(2000) DEFAULT NULL, `time` bigint(20) DEFAULT NULL, `endtime` bigint(20) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB AUTO_INCREMENT=198740 DEFAULT CHARSET=utf8")
if e.GetError() == nil { if e.GetError() == nil {
that.isInit = true that.isInit = true
} }
@ -74,8 +74,8 @@ func (that *CacheDb) initDbTable() {
} }
_, e := that.Db.Exec(`CREATE TABLE "` + that.Db.GetPrefix() + `cached" ( _, e := that.Db.Exec(`CREATE TABLE "` + that.Db.GetPrefix() + `cached" (
"id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, "id" INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
"ckey" TEXT(60), "key" TEXT(60),
"cvalue" TEXT(2000), "value" TEXT(2000),
"time" integer, "time" integer,
"endtime" integer "endtime" integer
);`) );`)
@ -90,7 +90,7 @@ func (that *CacheDb) initDbTable() {
//获取Cache键只能为string类型 //获取Cache键只能为string类型
func (that *CacheDb) get(key string) interface{} { func (that *CacheDb) get(key string) interface{} {
cached := that.Db.Get("cached", "*", Map{"ckey": key}) cached := that.Db.Get("cached", "*", Map{"key": key})
if cached == nil { if cached == nil {
return nil return nil
@ -103,7 +103,7 @@ func (that *CacheDb) get(key string) interface{} {
} }
data := Map{} data := Map{}
data.JsonToMap(cached.GetString("cvalue")) data.JsonToMap(cached.GetString("value"))
return data.Get("data") return data.Get("data")
} }
@ -113,9 +113,9 @@ func (that *CacheDb) set(key string, value interface{}, tim int64) {
bte, _ := json.Marshal(Map{"data": value}) bte, _ := json.Marshal(Map{"data": value})
num := that.Db.Update("cached", Map{"cvalue": string(bte), "time": time.Now().UnixNano(), "endtime": tim}, Map{"ckey": key}) num := that.Db.Update("cached", Map{"value": string(bte), "time": time.Now().UnixNano(), "endtime": tim}, Map{"key": key})
if num == int64(0) { if num == int64(0) {
that.Db.Insert("cached", Map{"cvalue": string(bte), "time": time.Now().UnixNano(), "endtime": tim, "ckey": key}) that.Db.Insert("cached", Map{"value": string(bte), "time": time.Now().UnixNano(), "endtime": tim, "key": key})
} }
//随机执行删除命令 //随机执行删除命令
@ -130,10 +130,10 @@ func (that *CacheDb) delete(key string) {
//如果通配删除 //如果通配删除
if del != -1 { if del != -1 {
key = Substr(key, 0, del) key = Substr(key, 0, del)
that.Db.Delete("cached", Map{"ckey": key + "%"}) that.Db.Delete("cached", Map{"key": key + "%"})
} else { } else {
that.Db.Delete("cached", Map{"ckey": key}) that.Db.Delete("cached", Map{"key": key})
} }
} }

112
code.go
View File

@ -11,8 +11,9 @@ var TptProject = Proj{
"hotimeCommon": Ctr{ "hotimeCommon": Ctr{
"info": func(that *Context) { "info": func(that *Context) {
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()}) fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db) data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
where := Map{"id": that.RouterString[2]} where := Map{"id": that.RouterString[2]}
if len(inData) == 1 { if len(inData) == 1 {
@ -31,19 +32,50 @@ var TptProject = Proj{
} }
for k, v := range re { for k, v := range re {
column := that.MakeCode.TableColumns[that.RouterString[1]][k] column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
if column == nil { if column == nil {
continue continue
} }
if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { 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}) seStr:="id,"+column.GetString("value")
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"]!=nil{
seStr=seStr+",phone"
} }
link:=strings.Replace(column.GetString("name"),"_id","",-1)
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
}
}
//如果有table字段则代为link
if re["table"]!=nil&&re["table_id"]!=nil {
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][re.GetString("table")]
v:=re.GetCeilInt64("table_id")
seStr:="id,"+column.GetString("value")
if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"]!=nil{
seStr=seStr+",phone"
}
link:=strings.Replace(column.GetString("name"),"_id","",-1)
re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v})
} }
that.Display(0, re) that.Display(0, re)
}, },
"add": func(that *Context) { "add": func(that *Context) {
inData := that.MakeCode.Add(that.RouterString[1], that.Req) that.Log=Map{"table":that.RouterString[1],"type":1}
hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1],data, that.Req)
if inData == nil { if inData == nil {
that.Display(3, "请求参数不足") that.Display(3, "请求参数不足")
return return
@ -64,11 +96,17 @@ var TptProject = Proj{
inData["index"] = "," + ObjToStr(re) + "," inData["index"] = "," + ObjToStr(re) + ","
that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re}) that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re})
} }
that.Log["table_id"]=re
that.Display(0, re) that.Display(0, re)
}, },
"update": func(that *Context) { "update": func(that *Context) {
inData := that.MakeCode.Edit(that.RouterString[1], that.Req)
that.Log=Map{"table":that.RouterString[1],"type":2,"table_id":that.RouterString[2]}
hotimeName := that.RouterString[0]
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
if inData == nil { if inData == nil {
that.Display(3, "没有找到要更新的数据") that.Display(3, "没有找到要更新的数据")
return return
@ -103,7 +141,9 @@ var TptProject = Proj{
that.Display(0, re) that.Display(0, re)
}, },
"remove": func(that *Context) { "remove": func(that *Context) {
inData := that.MakeCode.Delete(that.RouterString[1], that.Req) that.Log=Map{"table":that.RouterString[1],"type":3,"table_id":that.RouterString[2]}
hotimeName := that.RouterString[0]
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
if inData == nil { if inData == nil {
that.Display(3, "请求参数不足") that.Display(3, "请求参数不足")
return return
@ -125,9 +165,11 @@ var TptProject = Proj{
"search": func(that *Context) { "search": func(that *Context) {
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()}) fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db) data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, that.Req, that.Db)
page := ObjToInt(that.Req.FormValue("page")) page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize")) pageSize := ObjToInt(that.Req.FormValue("pageSize"))
@ -145,13 +187,28 @@ var TptProject = Proj{
PageSelect(that.RouterString[1], leftJoin, columnStr, where) PageSelect(that.RouterString[1], leftJoin, columnStr, where)
for _, v := range reData { for _, v := range reData {
for k, _ := range v { v.RangeSort(func(k string, v1 interface{}) (isEnd bool) {
column := that.MakeCode.TableColumns[that.RouterString[1]][k] //如果有table字段则代为link
if v["table"]!=nil&&v["table_id"]!=nil {
id:=v.GetCeilInt64("table_id")
tableName := that.MakeCodeRouter[hotimeName].TableConfig.GetMap(v.GetString("table")).GetString("label")
v["table_table_name"]=strings.Replace(tableName,"管理","",-1)
parentC := that.Db.Get(v.GetString("table"), "name", Map{"id": id})
v["table_table_id_name"] = ""
if parentC != nil {
v["table_table_id_name"]= parentC.GetString("name")
}
}
column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
if column == nil { if column == nil {
continue return true
} }
if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { 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)}) 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")] = "" v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = ""
if parentC != nil { if parentC != nil {
@ -159,7 +216,8 @@ var TptProject = Proj{
} }
} }
} return isEnd
})
} }
that.Display(0, Map{"count": count, "data": reData}) that.Display(0, Map{"count": count, "data": reData})
@ -168,33 +226,39 @@ var TptProject = Proj{
"hotime": Ctr{ "hotime": Ctr{
"login": func(that *Context) { "login": func(that *Context) {
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
name := that.Req.FormValue("name") name := that.Req.FormValue("name")
password := that.Req.FormValue("password") password := that.Req.FormValue("password")
if name == "" || password == "" { if name == "" || password == "" {
that.Display(3, "参数不足") that.Display(3, "参数不足")
return return
} }
user := that.Db.Get(hotimeName, "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}}) user := that.Db.Get(fileConfig.GetString("table"), "*", Map{"AND": Map{"OR": Map{"name": name, "phone": name}, "password": Md5(password)}})
if user == nil { if user == nil {
that.Display(5, "登录失败") that.Display(5, "登录失败")
return return
} }
that.Session(hotimeName+"_id", user.GetCeilInt("id")) that.Session(fileConfig.GetString("table")+"_id", user.GetCeilInt("id"))
that.Session(hotimeName+"_name", name) that.Session(fileConfig.GetString("table")+"_name", name)
delete(user, "password") delete(user, "password")
that.Display(0, user) that.Display(0, user)
}, },
"logout": func(that *Context) { "logout": func(that *Context) {
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
that.Session(hotimeName+"_id", nil) fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
that.Session(hotimeName+"_name", nil) that.Session(fileConfig.GetString("table")+"_id", nil)
that.Session(fileConfig.GetString("table")+"_name", nil)
that.Display(0, "退出登录成功") that.Display(0, "退出登录成功")
}, },
"info": func(that *Context) { "info": func(that *Context) {
hotimeName := that.RouterString[0] hotimeName := that.RouterString[0]
data := that.Db.Get(hotimeName, "*", Map{"id": that.Session(hotimeName + "_id").ToCeilInt()}) fileConfig := that.MakeCodeRouter[hotimeName].FileConfig
str, inData := that.MakeCode.Info(hotimeName, data, that.Db)
where := Map{"id": that.Session(hotimeName + "_id").ToCeilInt()} data := that.Db.Get(fileConfig.GetString("table"), "*", Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()})
str, inData := that.MakeCodeRouter[hotimeName].Info(fileConfig.GetString("table"), data, that.Db)
where := Map{"id": that.Session(fileConfig.GetString("table") + "_id").ToCeilInt()}
if len(inData) == 1 { if len(inData) == 1 {
inData["id"] = where["id"] inData["id"] = where["id"]
where = Map{"AND": inData} where = Map{"AND": inData}
@ -202,13 +266,13 @@ var TptProject = Proj{
where["OR"] = inData where["OR"] = inData
where = Map{"AND": where} where = Map{"AND": where}
} }
re := that.Db.Get(hotimeName, str, where) re := that.Db.Get(fileConfig.GetString("table"), str, where)
if re == nil { if re == nil {
that.Display(4, "找不到对应信息") that.Display(4, "找不到对应信息")
return return
} }
for k, v := range re { for k, v := range re {
column := that.MakeCode.TableColumns[hotimeName][k] column := that.MakeCodeRouter[hotimeName].TableColumns[fileConfig.GetString("table")][k]
if column == nil { if column == nil {
continue continue
} }

View File

@ -64,6 +64,8 @@ var ColumnNameType = []ColumnShow{
{"idcard", false, true, true, false, "", false}, {"idcard", false, true, true, false, "", false},
{"id", true, false, true, false, "", true}, {"id", true, false, true, false, "", true},
{"parent_id", true, true, true, false, "", true}, {"parent_id", true, true, true, false, "", true},
{"content", false, false, false, false, "textArea", false},
{"info", false, true, true, false, "textArea", false},
//"sn"{true,true,true,""}, //"sn"{true,true,true,""},
{"status", true, true, true, false, "select", false}, {"status", true, true, true, false, "select", false},
{"state", true, true, true, false, "select", false}, {"state", true, true, true, false, "select", false},
@ -78,7 +80,7 @@ var ColumnNameType = []ColumnShow{
{"index", false, false, false, false, "index", false}, {"index", false, false, false, false, "index", false},
{"password", false, true, false, false, "password", false}, {"password", false, true, false, false, "password", false},
{"pwd", false, true, false, false, "password", false}, {"pwd", false, true, false, false, "password", false},
{"info", false, true, true, false, "", false},
{"version", false, false, false, false, "", false}, {"version", false, false, false, false, "", false},
{"seq", false, true, true, false, "", false}, {"seq", false, true, true, false, "", false},
{"sort", false, true, true, false, "", false}, {"sort", false, true, true, false, "", false},
@ -86,7 +88,7 @@ var ColumnNameType = []ColumnShow{
{"description", false, true, true, false, "", false}, {"description", false, true, true, false, "", false},
{"abstract", false, true, true, false, "", false}, {"abstract", false, true, true, false, "", false},
{"content", false, true, true, false, "", false}, {"content", false, true, true, false, "", false},
{"address", false, true, true, false, "", false}, {"address", true, true, true, false, "", false},
{"full_name", false, true, true, false, "", false}, {"full_name", false, true, true, false, "", false},
{"create_time", false, false, true, false, "time", true}, {"create_time", false, false, true, false, "time", true},
{"modify_time", true, false, true, false, "time", true}, {"modify_time", true, false, true, false, "time", true},
@ -97,7 +99,9 @@ var ColumnNameType = []ColumnShow{
{"file", false, true, true, false, "file", false}, {"file", false, true, true, false, "file", false},
{"age", false, true, true, false, "", false}, {"age", false, true, true, false, "", false},
{"email", false, true, true, false, "", false}, {"email", false, true, true, false, "", false},
{"time", true, true, true, true, "time", false}, {"time", true, true, true, false, "time", false},
{"level", false, false, true, false, "", false}, {"level", false, false, true, false, "", false},
{"rule", true, true, true, false, "form", false}, {"rule", true, true, true, false, "form", false},
{"table", true, false, true, false, "table", false},
{"table_id", true, false, true, false, "table_id", false},
} }

View File

@ -9,23 +9,26 @@ import (
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"sort"
"strings" "strings"
"time" "time"
) )
type MakeCode struct { type MakeCode struct {
FileConfig Map
IndexMenus Map IndexMenus Map
TableConfig Map TableConfig Map
TableColumns map[string]map[string]Map TableColumns map[string]map[string]Map
SearchColumns map[string]map[string]Map SearchColumns map[string]map[string]Map
Config Map Config Map
RuleConfig []Map
Error Error
} }
func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCode bool) { func (that *MakeCode) Db2JSON(db *db.HoTimeDB, config Map) {
isMake := false isMake := false
idSlice := Slice{} idSlice := Slice{}
that.FileConfig = config
if that.TableColumns == nil { if that.TableColumns == nil {
that.TableColumns = make(map[string]map[string]Map) that.TableColumns = make(map[string]map[string]Map)
} }
@ -34,20 +37,48 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
} }
//加载配置文件 //加载配置文件
btes, err := ioutil.ReadFile(path) btes, err := ioutil.ReadFile(config.GetString("config"))
Config["name"] = name
that.Config = DeepCopyMap(Config).(Map) that.Config = DeepCopyMap(Config).(Map)
that.Config["name"] = config.GetString("table")
if err == nil { if err == nil {
cmap := Map{} cmap := Map{}
//文件是否损坏 //文件是否损坏
cmap.JsonToMap(string(btes), &that.Error) cmap.JsonToMap(string(btes), &that.Error)
for k, v := range cmap { for k, v := range cmap {
that.Config[k] = v //程序配置 that.Config[k] = v //程序配置
Config[k] = v //系统配置 //Config[k] = v //系统配置
} }
} else { } else {
that.Error.SetError(errors.New("配置文件不存在,或者配置出错,使用缺省默认配置")) that.Error.SetError(errors.New("config配置文件不存在,或者配置出错,使用缺省默认配置"))
} }
//加载规则文件
btesRule, errRule := ioutil.ReadFile(config.GetString("rule"))
that.RuleConfig = []Map{}
if errRule == nil {
//cmap := Map{}
//文件是否损坏
ruleLis := ObjToSlice(string(btesRule), &that.Error)
//cmap.JSON()
for k, _ := range ruleLis {
that.RuleConfig = append(that.RuleConfig, ruleLis.GetMap(k))
}
} else {
for _, v := range ColumnNameType {
that.RuleConfig = append(that.RuleConfig, Map{"name": v.Name, "list": v.List, "edit": v.Edit, "info": v.Info, "must": v.Must, "strict": v.Strict, "type": v.Type})
}
if db != nil {
_ = os.MkdirAll(filepath.Dir(config.GetString("rule")), os.ModeDir)
err = ioutil.WriteFile(config.GetString("rule"), []byte(ObjToStr(that.RuleConfig)), os.ModePerm)
if err != nil {
that.Error.SetError(err)
}
}
that.Error.SetError(errors.New("rule配置文件不存在或者配置出错使用缺省默认配置"))
}
that.IndexMenus = Map{} that.IndexMenus = Map{}
menusConfig := that.Config.GetSlice("menus") menusConfig := that.Config.GetSlice("menus")
//将配置写入到内存中仅作为判断用 //将配置写入到内存中仅作为判断用
@ -119,7 +150,7 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
} }
//数据库反哺 //数据库反哺
myInit := strings.Replace(InitTpt, "{{name}}", name, -1) myInit := strings.Replace(InitTpt, "{{name}}", config.GetString("table"), -1)
ctrList := "" ctrList := ""
nowTables := make([]Map, 0) nowTables := make([]Map, 0)
@ -205,38 +236,42 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
coloum["label"] = coloum.GetString("label")[:indexNum] coloum["label"] = coloum.GetString("label")[:indexNum]
} }
for _, ColumnName := range ColumnNameType { for _, ColumnName := range that.RuleConfig {
if (ColumnName.Strict && coloum.GetString("name") == ColumnName.Name) || if (ColumnName.GetBool("strict") && coloum.GetString("name") == ColumnName.GetString("name")) ||
(!ColumnName.Strict && strings.Contains(coloum.GetString("name"), ColumnName.Name)) { (!ColumnName.GetBool("strict") && strings.Contains(coloum.GetString("name"), ColumnName.GetString("name"))) {
//全部都不需要则不加入 //全部都不需要则不加入
if ColumnName.Edit == false && ColumnName.List == false && ColumnName.Info == false { if ColumnName.GetBool("edit") == false && ColumnName.GetBool("list") == false && ColumnName.GetBool("info") == false {
coloum["notUse"] = true coloum["notUse"] = true
//continue //continue
} }
coloum["info"] = ColumnName.Info coloum["info"] = ColumnName.GetBool("info")
coloum["edit"] = ColumnName.Edit coloum["edit"] = ColumnName.GetBool("edit")
coloum["add"] = ColumnName.Edit coloum["add"] = ColumnName.GetBool("edit")
coloum["list"] = ColumnName.List coloum["list"] = ColumnName.GetBool("list")
coloum["must"] = ColumnName.Must coloum["must"] = ColumnName.GetBool("must")
if ColumnName.Info { if ColumnName.GetBool("info") {
delete(coloum, "info") delete(coloum, "info")
} }
if ColumnName.Edit { if ColumnName.GetBool("edit") {
delete(coloum, "edit") delete(coloum, "edit")
delete(coloum, "add") delete(coloum, "add")
} }
if ColumnName.List { if ColumnName.GetBool("list") {
delete(coloum, "list") delete(coloum, "list")
} }
if ColumnName.Must { if !ColumnName.GetBool("must") {
delete(coloum, "must") delete(coloum, "must")
} }
if ColumnName.Type != "" { if ColumnName.GetString("type") != "" {
coloum["type"] = ColumnName.Type if ColumnName.GetString("type") == "time" && coloum["type"] == "number" {
coloum["type"] = "unixTime"
} else {
coloum["type"] = ColumnName.GetString("type")
} }
if ColumnName.Strict && coloum.GetString("name") == ColumnName.Name { }
if ColumnName.GetBool("strict") && coloum.GetString("name") == ColumnName.GetString("name") {
break break
} }
@ -267,10 +302,10 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
} }
if coloum.GetString("type") == "select" { if coloum.GetString("type") == "select" {
coloum["must"] = true //coloum["must"] = true
coloum["options"] = options coloum["options"] = options
} else if len(options) > 0 { } else if len(options) > 0 {
coloum["must"] = true //coloum["must"] = true
coloum["options"] = options coloum["options"] = options
coloum["type"] = "select" coloum["type"] = "select"
@ -291,16 +326,16 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
} }
if makeCode { if config.GetInt("mode") != 0 {
//创建模块文件 //创建模块文件
//判断文件是否存在 //判断文件是否存在
//_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm) //_, err := os.OpenFile(name+"/"+v.GetString("name"), os.O_RDONLY, os.ModePerm)
_, err := os.Stat(name + "/" + v.GetString("name") + ".go") _, err := os.Stat(config.GetString("name") + "/" + v.GetString("name") + ".go")
if err != nil { //文件不存在,则根据模板创建 if err != nil { //文件不存在,则根据模板创建
myCtr := strings.Replace(CtrTpt, "{{name}}", name, -1) myCtr := strings.Replace(CtrTpt, "{{name}}", config.GetString("name"), -1)
myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1) myCtr = strings.Replace(myCtr, "{{table}}", v.GetString("name"), -1)
_ = os.MkdirAll(name, os.ModeDir) _ = os.MkdirAll(config.GetString("name"), os.ModeDir)
err = ioutil.WriteFile(name+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm) err = ioutil.WriteFile(config.GetString("name")+"/"+v.GetString("name")+".go", []byte(myCtr), os.ModePerm)
if err != nil { if err != nil {
that.Error.SetError(err) that.Error.SetError(err)
} }
@ -477,8 +512,17 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
v["value"] = "label" v["value"] = "label"
continue continue
} }
tempC := that.TableConfig.GetMap(tableName).GetSlice("columns")
isGet := true
for k2, _ := range tempC {
if strings.Contains(tempC.GetMap(k2).GetString("name"), "name") || strings.Contains(tempC.GetMap(k2).GetString("name"), "title") {
v["value"] = tempC.GetMap(k2).GetString("name")
isGet = false
break
}
}
if len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 { if isGet && len(that.TableConfig.GetMap(tableName).GetSlice("columns")) > 2 {
v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name") v["value"] = that.TableConfig.GetMap(tableName).GetSlice("columns").GetMap(1).GetString("name")
continue continue
} }
@ -506,25 +550,25 @@ func (that *MakeCode) Db2JSON(name string, path string, db *db.HoTimeDB, makeCod
fmt.Println(id, "---", that.Config.GetString("id")) fmt.Println(id, "---", that.Config.GetString("id"))
that.Config["id"] = id that.Config["id"] = id
if makeCode { if config.GetInt("mode") != 0 {
//init文件初始化 //init文件初始化
myInit = strings.Replace(myInit, "{{id}}", id, -1) myInit = strings.Replace(myInit, "{{id}}", id, -1)
myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1) myInit = strings.Replace(myInit, "{{tablesCtr}}", ctrList, -1)
_ = os.MkdirAll(name, os.ModeDir) _ = os.MkdirAll(config.GetString("name"), os.ModeDir)
err = ioutil.WriteFile(name+"/init.go", []byte(myInit), os.ModePerm) err = ioutil.WriteFile(config.GetString("name")+"/init.go", []byte(myInit), os.ModePerm)
if err != nil { if err != nil {
that.Error.SetError(err) that.Error.SetError(err)
} }
} }
//写入配置文件
//var configByte bytes.Buffer
//写入配置文件
//err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t") //err = json.Indent(&configByte, []byte(that.Config.ToJsonString()), "", "\t")
_ = os.MkdirAll(filepath.Dir(path), os.ModeDir) _ = os.MkdirAll(filepath.Dir(config.GetString("config")), os.ModeDir)
err = ioutil.WriteFile(path, []byte(that.Config.ToJsonString()), os.ModePerm) err = ioutil.WriteFile(config.GetString("config"), []byte(that.Config.ToJsonString()), os.ModePerm)
if err != nil { if err != nil {
that.Error.SetError(err) that.Error.SetError(err)
} }
fmt.Println("有新的代码生成,请重新运行") fmt.Println("有新的代码生成,请重新运行")
os.Exit(-1) os.Exit(-1)
@ -534,7 +578,16 @@ func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string,
reStr := "" reStr := ""
data := Map{} data := Map{}
var ruleData Map var ruleData Map
for _, v := range that.TableColumns[table] { testQu := []string{}
testQuData := that.TableColumns[table]
for key, _ := range testQuData {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := testQuData[k]
if v == nil { if v == nil {
continue continue
} }
@ -579,7 +632,7 @@ func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string,
} }
return reStr, data return reStr, data
} }
func (that *MakeCode) Add(table string, req *http.Request) Map { func (that *MakeCode) Add(table string, user Map, req *http.Request) Map {
data := Map{} data := Map{}
for _, v := range that.TableColumns[table] { for _, v := range that.TableColumns[table] {
//不可使用,未在前端展示,但在内存中保持有 //不可使用,未在前端展示,但在内存中保持有
@ -593,6 +646,17 @@ func (that *MakeCode) Add(table string, req *http.Request) Map {
if v.Get("add") == nil || v.GetBool("add") { if v.Get("add") == nil || v.GetBool("add") {
if len(req.Form[v.GetString("name")]) == 0 { if len(req.Form[v.GetString("name")]) == 0 {
if user[v.GetString("name")] != nil {
data[v.GetString("name")] = user[v.GetString("name")]
continue
}
if that.FileConfig.GetString("table")+"_id" == v.GetString("name") {
data[v.GetString("name")] = user["id"]
continue
}
if v.GetBool("must") { if v.GetBool("must") {
return nil return nil
} else { } else {
@ -614,13 +678,23 @@ func (that *MakeCode) Add(table string, req *http.Request) Map {
} }
if v.GetString("name") == "create_time" { if v.GetString("name") == "create_time" {
if v.GetString("type") == "unixTime" {
data[v.GetString("name")] = time.Now().Unix() data[v.GetString("name")] = time.Now().Unix()
}
if v.GetString("type") == "time" {
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
}
continue continue
} }
if v.GetString("name") == "modify_time" { if v.GetString("name") == "modify_time" {
if v.GetString("type") == "unixTime" {
data[v.GetString("name")] = time.Now().Unix() data[v.GetString("name")] = time.Now().Unix()
} }
if v.GetString("type") == "time" {
data[v.GetString("name")] = time.Now().Format("2006-01-02 15-04-05")
}
}
} }
if len(data) == 0 { if len(data) == 0 {
return nil return nil
@ -682,12 +756,22 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
data := Map{} data := Map{}
keyword := Map{} keyword := Map{}
daterange := Map{} daterange := Map{}
sort := Map{} sortMap := Map{}
var ruleData Map var ruleData Map
hasUser := false hasUser := false
keywordStr := req.FormValue("keyword") keywordStr := req.FormValue("keyword")
for _, v := range that.TableColumns[table] {
testQu := []string{}
testQuData := that.TableColumns[table]
for key, _ := range testQuData {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := testQuData[k]
//不可使用,未在前端展示,但在内存中保持有 //不可使用,未在前端展示,但在内存中保持有
if v.GetBool("notUse") { if v.GetBool("notUse") {
@ -702,6 +786,11 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
v.GetString("link") + "." + v.GetString("value") + " AS " + v.GetString("link") + "." + v.GetString("value") + " AS " +
v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + "," v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
if that.TableColumns[v.GetString("link")]["phone"] != nil {
reStr += table + "." + v.GetString("name") + "," +
v.GetString("link") + ".phone AS " +
v.GetString("link") + "_" + v.GetString("name") + "_phone,"
}
leftJoin["[>]"+v.GetString("link")] = leftJoin["[>]"+v.GetString("link")] =
table + "." + v.GetString("name") + "=" + table + "." + v.GetString("name") + "=" +
v.GetString("link") + ".id" v.GetString("link") + ".id"
@ -798,12 +887,17 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
//日期类型 //日期类型
if searchItemName == "daterange" && v.GetString("type") == "time" { if searchItemName == "daterange" && v.GetString("type") == "time" {
//fmt.Println(req.Form["daterange"]) //fmt.Println(req.Form["daterange"])
if len(req.Form["daterange"]) == 1 {
daterange[table+"."+v.GetString("name")+"[<]"] = req.FormValue("daterange")
} else {
daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"]) daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"])
} }
} }
}
if searchItem.GetString("name") == "sort" { if searchItem.GetString("name") == "sort" {
sort["ORDER"] = table + "." + reqValue sortMap["ORDER"] = table + "." + reqValue
} }
continue continue
@ -823,8 +917,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
data[table+"."+searchItemName] = reqValue data[table+"."+searchItemName] = reqValue
} }
if sort["ORDER"] == nil { if sortMap["ORDER"] == nil {
sort["ORDER"] = table + ".id DESC" sortMap["ORDER"] = table + ".id DESC"
} }
where := Map{} where := Map{}
@ -850,9 +944,11 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
} }
if len(daterange) > 1 { if len(daterange) > 1 {
if data["AND"] != nil { //if data["AND"] == nil {
data = Map{"AND": Map{"AND": data, "OR": daterange}} data = Map{"AND": Map{"AND": data, "OR": daterange}}
} //}else{
// data = Map{"AND": Map{"AND": data, "OR": daterange}}
//}
} }
if len(data) > 1 { if len(data) > 1 {
@ -869,8 +965,8 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
} }
if len(sort) != 0 { if len(sortMap) != 0 {
for k, v := range sort { for k, v := range sortMap {
where[k] = v where[k] = v
} }
} }

View File

@ -15,6 +15,7 @@ var Project = Proj{
{{tablesCtr}} {{tablesCtr}}
"hotime":Ctr{ "hotime":Ctr{
"login": func(that *Context) { "login": func(that *Context) {
name := that.Req.FormValue("name") name := that.Req.FormValue("name")
password := that.Req.FormValue("password") password := that.Req.FormValue("password")
if name == "" || password == "" { if name == "" || password == "" {
@ -36,8 +37,9 @@ var Project = Proj{
that.Display(0, "退出登录成功") that.Display(0, "退出登录成功")
}, },
"info": func(that *Context) { "info": func(that *Context) {
hotimeName := that.RouterString[0]
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()}) data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
str, inData := that.MakeCode.Info("admin", data, that.Db) str, inData := that.MakeCodeRouter[hotimeName].Info("admin", data, that.Db)
where := Map{"id": that.Session("admin_id").ToCeilInt()} where := Map{"id": that.Session("admin_id").ToCeilInt()}
if len(inData) ==1 { if len(inData) ==1 {
inData["id"] =where["id"] inData["id"] =where["id"]
@ -52,7 +54,7 @@ var Project = Proj{
return return
} }
for k, v := range re { for k, v := range re {
column := that.MakeCode.TableColumns["admin"][k] column := that.MakeCodeRouter[hotimeName].TableColumns["admin"][k]
if column == nil { if column == nil {
continue continue
} }
@ -76,8 +78,9 @@ import (
var {{table}}Ctr = Ctr{ var {{table}}Ctr = Ctr{
"info": func(that *Context) { "info": func(that *Context) {
hotimeName := that.RouterString[0]
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()}) data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
str, inData := that.MakeCode.Info(that.RouterString[1], data, that.Db) str, inData := that.MakeCodeRouter[hotimeName].Info(that.RouterString[1], data, that.Db)
where := Map{"id": that.RouterString[2]} where := Map{"id": that.RouterString[2]}
if len(inData) ==1 { if len(inData) ==1 {
@ -96,7 +99,7 @@ var {{table}}Ctr = Ctr{
} }
for k, v := range re { for k, v := range re {
column := that.MakeCode.TableColumns[that.RouterString[1]][k] column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
if column == nil { if column == nil {
continue continue
} }
@ -108,7 +111,8 @@ var {{table}}Ctr = Ctr{
that.Display(0, re) that.Display(0, re)
}, },
"add": func(that *Context) { "add": func(that *Context) {
inData := that.MakeCode.Add(that.RouterString[1], that.Req) hotimeName := that.RouterString[0]
inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], that.Req)
if inData == nil { if inData == nil {
that.Display(3, "请求参数不足") that.Display(3, "请求参数不足")
return return
@ -134,7 +138,8 @@ var {{table}}Ctr = Ctr{
that.Display(0, re) that.Display(0, re)
}, },
"update": func(that *Context) { "update": func(that *Context) {
inData := that.MakeCode.Edit(that.RouterString[1], that.Req) hotimeName := that.RouterString[0]
inData := that.MakeCodeRouter[hotimeName].Edit(that.RouterString[1], that.Req)
if inData == nil { if inData == nil {
that.Display(3, "没有找到要更新的数据") that.Display(3, "没有找到要更新的数据")
return return
@ -165,7 +170,8 @@ var {{table}}Ctr = Ctr{
that.Display(0, re) that.Display(0, re)
}, },
"remove": func(that *Context) { "remove": func(that *Context) {
inData := that.MakeCode.Delete(that.RouterString[1], that.Req) hotimeName := that.RouterString[0]
inData := that.MakeCodeRouter[hotimeName].Delete(that.RouterString[1], that.Req)
if inData == nil { if inData == nil {
that.Display(3, "请求参数不足") that.Display(3, "请求参数不足")
return return
@ -186,10 +192,10 @@ var {{table}}Ctr = Ctr{
}, },
"search": func(that *Context) { "search": func(that *Context) {
hotimeName := that.RouterString[0]
data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()}) data := that.Db.Get("admin", "*", Map{"id": that.Session("admin_id").ToCeilInt()})
columnStr, leftJoin, where := that.MakeCode.Search(that.RouterString[1], data, that.Req, that.Db) columnStr, leftJoin, where := that.MakeCodeRouter[hotimeName].Search(that.RouterString[1], data, that.Req, that.Db)
page := ObjToInt(that.Req.FormValue("page")) page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize")) pageSize := ObjToInt(that.Req.FormValue("pageSize"))
@ -208,7 +214,7 @@ var {{table}}Ctr = Ctr{
for _, v := range reData { for _, v := range reData {
for k, _ := range v { for k, _ := range v {
column := that.MakeCode.TableColumns[that.RouterString[1]][k] column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k]
if column == nil { if column == nil {
continue continue
} }

View File

@ -4,6 +4,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"reflect" "reflect"
"sort"
) )
//hotime的常用map //hotime的常用map
@ -98,6 +99,22 @@ func (that Map) GetBool(key string, err ...*Error) bool {
return v return v
}
func (that Map) RangeSort(callback func(k string, v interface{}) (isEnd bool)) {
testQu := []string{}
//testQuData:= qu[0].(Map)
for key, _ := range that {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
re := callback(k, that[k])
if re {
return
}
}
} }
func (that Map) GetMap(key string, err ...*Error) Map { func (that Map) GetMap(key string, err ...*Error) Map {

View File

@ -6,22 +6,26 @@ import (
. "code.hoteas.com/golang/hotime/db" . "code.hoteas.com/golang/hotime/db"
"encoding/json" "encoding/json"
"net/http" "net/http"
"time"
) )
type Context struct { type Context struct {
*Application *Application
Resp http.ResponseWriter Resp http.ResponseWriter
Req *http.Request Req *http.Request
Log Map//日志有则创建
RouterString []string RouterString []string
Config Map Config Map
Db *HoTimeDB Db *HoTimeDB
RespData Map RespData Map
RespFunc func()
CacheIns CacheIns
SessionIns SessionIns
DataSize int DataSize int
HandlerStr string //复写请求url HandlerStr string //复写请求url
} }
// Mtd 唯一标志 // Mtd 唯一标志
func (that *Context) Mtd(router [3]string) Map { func (that *Context) Mtd(router [3]string) Map {
that.Application.Router[router[0]][router[1]][router[2]](that) that.Application.Router[router[0]][router[1]][router[2]](that)
@ -57,10 +61,24 @@ func (that *Context) Display(statu int, data interface{}) {
} }
func (that *Context) View() { func (that *Context) View() {
if that.RespFunc!=nil {
that.RespFunc()
}
if that.RespData == nil { if that.RespData == nil {
return return
} }
//创建日志
if that.Log!=nil{
that.Log["time"]=time.Now().Unix()
if that.Session("admin_id").Data!=nil{
that.Log["admin_id"]=that.Session("admin_id").ToCeilInt()
}
if that.Session("user_id").Data!=nil{
that.Log["user_id"]=that.Session("user_id").ToCeilInt()
}
that.Db.Insert("logs",that.Log)
}
d, err := json.Marshal(that.RespData) d, err := json.Marshal(that.RespData)
if err != nil { if err != nil {
return return

View File

@ -10,6 +10,7 @@ import (
_ "github.com/mattn/go-sqlite3" _ "github.com/mattn/go-sqlite3"
"os" "os"
"reflect" "reflect"
"sort"
"strings" "strings"
) )
@ -42,32 +43,32 @@ func (that *HoTimeDB) GetType() string {
} }
// Action 事务如果action返回true则执行成功false则回滚 // Action 事务如果action返回true则执行成功false则回滚
func (that *HoTimeDB) Action(action func(db HoTimeDB) bool) bool { func (that *HoTimeDB) Action(action func(db HoTimeDB) (isSuccess bool)) (isSuccess bool) {
db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache, Prefix: that.Prefix} db := HoTimeDB{DB: that.DB, HoTimeCache: that.HoTimeCache, Prefix: that.Prefix}
tx, err := db.Begin() tx, err := db.Begin()
if err != nil { if err != nil {
that.LastErr.SetError(err) that.LastErr.SetError(err)
return false return isSuccess
} }
db.Tx = tx db.Tx = tx
result := action(db) isSuccess = action(db)
if !result { if !isSuccess {
err = db.Tx.Rollback() err = db.Tx.Rollback()
if err != nil { if err != nil {
that.LastErr.SetError(err) that.LastErr.SetError(err)
return false return isSuccess
} }
return result return isSuccess
} }
err = db.Tx.Commit() err = db.Tx.Commit()
if err != nil { if err != nil {
that.LastErr.SetError(err) that.LastErr.SetError(err)
return false return false
} }
return result return true
} }
func (that *HoTimeDB) InitDb(err ...*Error) *Error { func (that *HoTimeDB) InitDb(err ...*Error) *Error {
@ -447,7 +448,16 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
} }
if join { if join {
for k, v := range qu[0].(Map) { var testQu = []string{}
testQuData := qu[0].(Map)
for key, _ := range testQuData {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := testQuData[k]
switch Substr(k, 0, 3) { switch Substr(k, 0, 3) {
case "[>]": case "[>]":
query += " LEFT JOIN " + Substr(k, 3, len(k)-3) + " ON " + v.(string) query += " LEFT JOIN " + Substr(k, 3, len(k)-3) + " ON " + v.(string)
@ -560,7 +570,15 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
res := make([]interface{}, 0) res := make([]interface{}, 0)
//AND OR判断 //AND OR判断
for k, v := range data { testQu := []string{}
//testQuData:= qu[0].(Map)
for key, _ := range data {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := data[k]
x := 0 x := 0
for i := 0; i < len(condition); i++ { for i := 0; i < len(condition); i++ {
@ -607,7 +625,15 @@ func (that *HoTimeDB) where(data Map) (string, []interface{}) {
//特殊字符 //特殊字符
for j := 0; j < len(vcond); j++ { for j := 0; j < len(vcond); j++ {
for k, v := range data { testQu := []string{}
//testQuData:= qu[0].(Map)
for key, _ := range data {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := data[k]
if vcond[j] == k { if vcond[j] == k {
if k == "ORDER" { if k == "ORDER" {
where += " " + k + " BY " where += " " + k + " BY "
@ -881,7 +907,15 @@ func (that *HoTimeDB) cond(tag string, data Map) (string, []interface{}) {
res := make([]interface{}, 0) res := make([]interface{}, 0)
lens := len(data) lens := len(data)
//fmt.Println(lens) //fmt.Println(lens)
for k, v := range data { testQu := []string{}
//testQuData:= qu[0].(Map)
for key, _ := range data {
//fmt.Println(key, ":", value)
testQu = append(testQu, key)
}
sort.Strings(testQu)
for _, k := range testQu {
v := data[k]
x := 0 x := 0
for i := 0; i < len(condition); i++ { for i := 0; i < len(condition); i++ {
@ -999,6 +1033,21 @@ func (that *HoTimeDB) Insert(table string, data map[string]interface{}) int64 {
tempLen := 0 tempLen := 0
for k, v := range data { for k, v := range data {
tempLen++ tempLen++
vstr := "?"
if Substr(k, len(k)-3, 3) == "[#]" {
k = strings.Replace(k, "[#]", "", -1)
vstr = ObjToStr(v)
if tempLen < lens {
queryString += "`" + k + "`,"
valueString += vstr + ","
} else {
queryString += "`" + k + "`) "
valueString += vstr + ");"
}
} else {
values = append(values, v) values = append(values, v)
if tempLen < lens { if tempLen < lens {
queryString += "`" + k + "`," queryString += "`" + k + "`,"
@ -1007,6 +1056,7 @@ func (that *HoTimeDB) Insert(table string, data map[string]interface{}) int64 {
queryString += "`" + k + "`) " queryString += "`" + k + "`) "
valueString += "?);" valueString += "?);"
} }
}
} }
query := "INSERT INTO `" + that.Prefix + table + "` " + queryString + "VALUES" + valueString query := "INSERT INTO `" + that.Prefix + table + "` " + queryString + "VALUES" + valueString

View File

@ -58,6 +58,14 @@ func (that *company) GetCompanyOtherAll(name string) Map {
return res return res
} }
// GetCompanyBaseInfo 获取企业基础信息
func (that *company) GetCompanyList(name string) (Map, error) {
url := "/fuzzyQueryCompanyInfo/"
body, err := that.basePost(url, name)
return ObjToMap(body), err
}
// GetCompanyBaseInfo 获取企业基础信息 // GetCompanyBaseInfo 获取企业基础信息
func (that *company) GetCompanyBaseInfo(name string) (Map, error) { func (that *company) GetCompanyBaseInfo(name string) (Map, error) {
url := "/getCompanyBaseInfo/" url := "/getCompanyBaseInfo/"

79
dri/wechat/h5program.go Normal file
View File

@ -0,0 +1,79 @@
package wechat
import (
"github.com/silenceper/wechat/v2"
"github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/officialaccount"
h5config "github.com/silenceper/wechat/v2/officialaccount/config"
"github.com/silenceper/wechat/v2/officialaccount/js"
"github.com/silenceper/wechat/v2/officialaccount/oauth"
)
//基于此文档开发
//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md
type h5Program struct {
Memory *cache.Memory
Config *h5config.Config
*officialaccount.OfficialAccount
weixin *wechat.Wechat //微信登录实例
}
var H5Program = h5Program{}
// Init 初始化
func (that *h5Program) Init(appid string, appsecret string) {
that.weixin = wechat.NewWechat()
that.Memory = cache.NewMemory()
that.Config = &h5config.Config{
AppID: appid,
AppSecret: appsecret,
//Token: "xxx",
//EncodingAESKey: "xxxx",
Cache: that.Memory,
}
that.OfficialAccount = that.weixin.GetOfficialAccount(that.Config)
}
// GetUserInfo 获取用户信息
func (that *h5Program) GetUserInfo(code string) (appid string, resToken oauth.ResAccessToken, userInfo oauth.UserInfo, err error) {
auth := that.GetOauth()
//weixin.GetOpenPlatform()
resToken, err = auth.GetUserAccessToken(code)
if err != nil {
return auth.AppID, resToken, userInfo, err
}
//getUserInfo
userInfo, err = auth.GetUserInfo(resToken.AccessToken, resToken.OpenID, "")
if err != nil {
return auth.AppID, resToken, userInfo, err
}
return auth.AppID, resToken, userInfo, err
}
// GetSignUrl js url签名
func (that *h5Program) GetSignUrl(signUrl string) (*js.Config, error) {
js := that.OfficialAccount.GetJs()
cfg1, e := js.GetConfig(signUrl)
if e != nil {
return nil, e
}
return cfg1, nil
}
// GetSignUrl js url签名
//func (that *h5Program) GetJsPay(signUrl string) (*js.Config, error) {
// //
// //js := that.OfficialAccount().GetJs()
// //
// //cfg1, e := js.GetConfig(signUrl)
// //if e != nil {
// // return nil, e
// //}
//
// return cfg1, nil
//}

66
dri/wechat/miniprogram.go Normal file
View File

@ -0,0 +1,66 @@
package wechat
import (
"errors"
"github.com/silenceper/wechat/v2"
"github.com/silenceper/wechat/v2/cache"
"github.com/silenceper/wechat/v2/miniprogram"
"github.com/silenceper/wechat/v2/miniprogram/auth"
"github.com/silenceper/wechat/v2/miniprogram/config"
"github.com/silenceper/wechat/v2/miniprogram/encryptor"
)
type miniProgram struct {
Memory *cache.Memory
Config *config.Config
weixin *wechat.Wechat //微信登录实例
*miniprogram.MiniProgram
}
var MiniProgram = miniProgram{}
// Init 初始化
func (that *miniProgram) Init(appid string, appsecret string) {
that.weixin = wechat.NewWechat()
that.Memory = cache.NewMemory()
that.Config = &config.Config{
AppID: appid,
AppSecret: appsecret,
//Token: "xxx",
//EncodingAESKey: "xxxx",
Cache: that.Memory,
}
that.MiniProgram = that.weixin.GetMiniProgram(that.Config)
}
func (that *miniProgram) GetBaseUserInfo(code string) (appid string, re auth.ResCode2Session, err error) {
appid = that.Config.AppID
a := that.GetAuth()
re, err = a.Code2Session(code)
if err != nil {
return appid, re, err
}
return appid, re, err
}
func (that *miniProgram) GetPhoneNumber(sessionkey, encryptedData, iv string) (appid string, re *encryptor.PlainData, err error) {
appid = that.Config.AppID
if sessionkey == "" || encryptedData == "" || iv == "" {
return appid, re, errors.New("参数不足")
}
eny := that.GetEncryptor()
re, err = eny.Decrypt(sessionkey, encryptedData, iv)
if err != nil {
return appid, re, err
}
return appid, re, err
}

142
dri/wechat/pay.go Normal file
View File

@ -0,0 +1,142 @@
package wechat
import (
"context"
"fmt"
"github.com/go-pay/gopay"
"github.com/go-pay/gopay/wechat/v3"
"net/http"
"time"
)
//基于此文档开发
//https://github.com/silenceper/wechat/blob/v2/doc/api/officialaccount.md
type wxpay struct {
client *wechat.ClientV3
ctx context.Context
apiV3Key string
MchId string
}
var WxPay = wxpay{}
// Init 初始化
func (that *wxpay) Init(MchId, SerialNo, APIv3Key, PrivateKey string) {
client, err := wechat.NewClientV3(MchId, SerialNo, APIv3Key, PrivateKey)
if err != nil {
//xlog.Error(err)
fmt.Println(err)
return
}
that.client = client
that.apiV3Key = APIv3Key
that.MchId = MchId
// 设置微信平台API证书和序列号如开启自动验签请忽略此步骤
//client.SetPlatformCert([]byte(""), "")
that.ctx = context.Background()
// 启用自动同步返回验签并定时更新微信平台API证书开启自动验签时无需单独设置微信平台API证书和序列号
err = client.AutoVerifySign()
if err != nil {
//xlog.Error(err)
fmt.Println(err)
return
}
// 打开Debug开关输出日志默认是关闭的
client.DebugSwitch = gopay.DebugOn
}
// GetUserInfo 获取用户信息
func (that *wxpay) GetJsOrder(money int64, appid, openid, name, tradeNo, notifyUrl string) (jsApiParams *wechat.JSAPIPayParams, err error) {
fmt.Println("dasdas", money, appid, name, tradeNo, notifyUrl)
PrepayId, err := that.getPrepayId(money, appid, that.MchId, openid, name, tradeNo, notifyUrl)
if err != nil {
return nil, err
}
//小程序
jsapi, err := that.client.PaySignOfJSAPI(appid, PrepayId)
return jsapi, err
}
func (that *wxpay) CallbackJsOrder(req *http.Request) (*wechat.V3DecryptResult, error) {
notifyReq, err := wechat.V3ParseNotify(req)
if err != nil {
//xlog.Error(err)
return nil, err
}
// wxPublicKey 通过 client.WxPublicKey() 获取
err = notifyReq.VerifySignByPK(that.client.WxPublicKey())
if err != nil {
//xlog.Error(err)
return nil, err
}
// ========异步通知敏感信息解密========
// 普通支付通知解密
result, err := notifyReq.DecryptCipherText(that.apiV3Key)
//that.client.V3TransactionQueryOrder(that.ctx,result.BankType,result.OR)
return result, err
// 合单支付通知解密
//result, err := notifyReq.DecryptCombineCipherText(apiV3Key)
//// 退款通知解密
//result, err := notifyReq.DecryptRefundCipherText(apiV3Key)
// ========异步通知应答========
// 退款通知http应答码为200且返回状态码为SUCCESS才会当做商户接收成功否则会重试。
// 注意:重试过多会导致微信支付端积压过多通知而堵塞,影响其他正常通知。
// 此写法是 gin 框架返回微信的写法
//c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
//
//// 此写法是 echo 框架返回微信的写法
//return c.JSON(http.StatusOK, &wechat.V3NotifyRsp{Code: gopay.SUCCESS, Message: "成功"})
}
// GetUserInfo 获取用户信息
//func (that *wxpay) GetMiniOrder(money int64,appid,name,tradeNo,notifyUrl string) (jsApiParams *wechat.AppletParams,err error){
//
// PrepayId,err:=that.getPrepayId(money,name,tradeNo,notifyUrl)
// if err!=nil{
// return nil,err
// }
//
// //小程序
// applet, err := that.client.PaySignOfApplet(appid,PrepayId)
//
// return applet,err
//}
func (that *wxpay) getPrepayId(money int64, appid, mchid, openid, name, tradeNo, notifyUrl string) (prepayid string, err error) {
expire := time.Now().Add(10 * time.Minute).Format(time.RFC3339)
// 初始化 BodyMap
bm := make(gopay.BodyMap)
bm.Set("appid", appid).
Set("mchid", mchid).
//Set("sub_mchid", "sub_mchid").
Set("description", name).
Set("out_trade_no", tradeNo).
Set("time_expire", expire).
Set("notify_url", notifyUrl).
SetBodyMap("amount", func(bm gopay.BodyMap) {
bm.Set("total", money).
Set("currency", "CNY")
}).
SetBodyMap("payer", func(bm gopay.BodyMap) {
bm.Set("openid", openid)
})
//ctx:=context.Context()
wxRsp, err := that.client.V3TransactionJsapi(that.ctx, bm)
fmt.Println("获取PrepayId", wxRsp, err)
if err != nil {
//xlog.Error(err)
return "", err
}
return wxRsp.Response.PrepayId, nil
}

110
example/app/article.go Normal file
View File

@ -0,0 +1,110 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var ArticleCtr = Ctr{
"getdispatchs": func(that *Context) {
//判断类型
tp := that.Req.FormValue("type")
//判断类型
data := Map{"del_flag": 0}
if tp == "notify" {
data["notify_id[!]"] = nil
}
if tp == "policy" {
data["policy_id[!]"] = nil
}
if tp == "declare" {
data["declare_id[!]"] = nil
}
if len(data) > 1 {
data = Map{"AND": data, "GROUP": "dispatch_name"}
} else {
data["GROUP"] = "dispatch_name"
}
res := that.Db.Select("article", "dispatch_name", data)
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["release_date[>=]"] = startTime
}
if finishTime != "" {
data["release_date[<=]"] = finishTime
}
dispatchName := that.Req.FormValue("dispatch_name")
if dispatchName != "" {
data["dispatch_name"] = dispatchName
}
//判断类型
tp := that.Req.FormValue("type")
if tp == "notify" {
data["notify_id[!]"] = nil
}
if tp == "policy" {
data["policy_id[!]"] = nil
}
if tp == "declare" {
data["declare_id[!]"] = nil
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "release_time DESC"}
}
count := that.Db.Count("article", data)
res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,policy_id,declare_id,notify_id,dispatch_name,policy_level", data)
for _, v := range res {
if v.GetCeilInt("notify_id") > 0 {
v["notify"] = that.Db.Get("notify", "tag", Map{"id": v.GetCeilInt("notify_id")})
}
if v.GetCeilInt("policy_id") > 0 {
v["policy"] = that.Db.Get("policy", "tag", Map{"id": v.GetCeilInt("policy_id")})
}
if v.GetCeilInt("declare_id") > 0 {
v["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt("declare_id")})
}
}
that.Display(0, Map{"total": count, "data": res})
},
}

40
example/app/company.go Normal file
View File

@ -0,0 +1,40 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"code.hoteas.com/golang/hotime/dri/aliyun"
"fmt"
)
var CompanyCtr = Ctr{
"search": func(that *Context) {
keywords := that.Req.FormValue("keywords")
if keywords == "" {
keywords = that.Req.FormValue("company_name")
}
if keywords == "" {
keywords = that.Req.FormValue("name")
}
if len(keywords) < 2 {
that.Display(0, Slice{})
return
}
res, err := aliyun.Company.GetCompanyList(keywords)
if err != nil {
fmt.Println(err)
that.Display(0, Slice{})
return
}
if res.GetCeilInt64("status") != 200 {
fmt.Println(err)
that.Display(0, Slice{})
return
}
that.Display(0, res.GetMap("data").GetSlice("list"))
},
}

484
example/app/declare.go Normal file
View File

@ -0,0 +1,484 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"sort"
"strings"
)
type paixuArr []Map
func (x paixuArr) Len() int {
return len(x)
}
func (x paixuArr) Less(i, j int) bool {
return x[i].GetCeilInt64("count") > x[j].GetCeilInt64("count")
}
func (x paixuArr) Swap(i, j int) {
x[i], x[j] = x[j], x[i]
}
var DeclareCtr = Ctr{
"info": func(that *Context) {
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("declare", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到通知公告")
return
}
res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1
delete(res, "click_num_base")
res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base")
delete(res, "favorite_num_base")
article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")})
if article != nil {
article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1
delete(article, "click_num_base")
article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base")
delete(article, "favorite_num_base")
}
res["article"] = article
//浏览量加1
that.Db.Update("declare", Map{"click_num[#]": "click_num+1"}, Map{"id": id})
//浏览量加1
that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")})
//查询是否已关注
if that.Session("user_id").Data != nil {
favorite := that.Db.Get("favorite", "user_id,declare_id", Map{"AND": Map{"declare_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}})
res["favorite"] = favorite
}
that.Display(0, res)
},
//政策匹配
"match": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data})
if user == nil {
that.Display(4, "找不到用户")
return
}
companyName := that.Req.FormValue("company_name")
if companyName == "" {
that.Display(3, "参数错误")
return
}
qu := that.Req.FormValue("register_address")
qus := strings.Split(qu, "/")
for _, v := range qus {
if v != "" {
qu = v
}
}
if !strings.Contains(qu, "区") && !strings.Contains(qu, "县") {
qu = "没有此项数据随意填充的"
}
company := that.Db.Get("company", "*", Map{"user_id": that.Session("user_id").Data})
delete(company, "id")
delete(company, "salesman_id")
delete(company, "provider_id")
delete(company, "user_id")
delete(company, "del_flag")
delete(company, "state")
delete(company, "create_time")
delete(company, "modify_time")
data := Map{}
for k, _ := range company {
if that.Req.Form[k] != nil {
if k == "technology_center_flag" || k == "engineering_center_flag" || k == "engineering_laboratory_flag" || k == "key_laboratory_flag" || k == "industrial_design_center_flag" {
data[k] = ObjToStr(that.Req.Form[k])
} else {
data[k] = that.Req.FormValue(k)
}
}
}
//如果企业名称相同则允许变更企业信息
if companyName == company.GetString("name") {
that.Db.Update("company", company, Map{"user_id": that.Session("user_id").Data})
}
if companyName != company.GetString("name") {
//扫码绑定后,第一次使用匹配功能,自动进行认证,并更新企业信息
if user.GetCeilInt("certification_flag") == 0 && user.GetCeilInt64("salesman_id") != 0 {
that.Db.Update("user", Map{"certification_flag": 1}, Map{"id": user.GetCeilInt("id")})
company["name"] = companyName
that.Db.Update("company", company, Map{"user_id": that.Session("user_id").Data})
}
//其余情况,不存储数据
}
tags := that.Req.Form["tags"]
declares := map[int64]Map{}
//标签分析
if tags != nil {
for _, v := range tags {
dtag := that.Db.Select("declare_tag", Map{"[><]`declare`": "declare_tag.declare_id=declare.id"}, "declare_tag.declare_id", Map{"AND": Map{"OR": Map{"declare.policy_level": Slice{"省", "市"}, "declare.dispatch_department[~]": qu}, "declare_tag.tag_id": v}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["tag_count"] = 1
}
}
}
//企业规模分析
dtag := that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "company_scale[<=]": ObjToInt(that.Req.FormValue("company_scale"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["company_scale_count"] = 1
}
//是否是有效期内的科技型中小企业称号:0-否,1-是
if ObjToInt(that.Req.FormValue("smes_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "smes_flag": ObjToInt(that.Req.FormValue("smes_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["smes_flag_count"] = 1
}
}
//是否是有效期内的高新区技术企业称号:0-否,1-是
if ObjToInt(that.Req.FormValue("htzte_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "htzte_flag": ObjToInt(that.Req.FormValue("htzte_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["htzte_flag_count"] = 1
}
}
//是否是有效期内的工程中心称号:0-否,1-市级,2-省级,3-国家级
flags := that.Req.Form["engineering_center_flag"]
flagslice := Slice{}
if flags != nil {
for _, v := range flags {
if v == "0" {
continue
}
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_center_flag": flagslice}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["engineering_center_flag_count"] = 1
}
//是否是有效期内的工程实验室称号:0-否,1-市级,2-省级,3-国家级
flags = that.Req.Form["engineering_laboratory_flag"]
flagslice = Slice{}
if flags != nil {
for _, v := range flags {
if v == "0" {
continue
}
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "engineering_laboratory_flag": flagslice}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["engineering_laboratory_flag_count"] = 1
}
//是否是有效期内的重点实验室称号:0-否,1-市级,2-省级,3-国家级
flags = that.Req.Form["key_laboratory_flag"]
flagslice = Slice{}
if flags != nil {
for _, v := range flags {
if v == "0" {
continue
}
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "key_laboratory_flag": flagslice}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["key_laboratory_flag_count"] = 1
}
//是否是有效期内的工业设计中心称号:0-否,1-市级,2-省级,3-国家级
flags = that.Req.Form["industrial_design_center_flag"]
flagslice = Slice{}
if flags != nil {
for _, v := range flags {
if v == "0" {
continue
}
flagslice = append(flagslice, v)
}
}
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "industrial_design_center_flag": flagslice}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["industrial_design_center_flag_count"] = 1
}
//上年度有无研发投入:0-否,1-是
if ObjToInt(that.Req.FormValue("research_input_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"del_flag": 0, "research_input_flag": ObjToInt(that.Req.FormValue("research_input_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["research_input_flag_count"] = 1
}
}
//有无授权发明专利:0-否,1-是
if ObjToInt(that.Req.FormValue("invention_patent_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "invention_patent_flag": ObjToInt(that.Req.FormValue("invention_patent_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["invention_patent_flag_count"] = 1
}
}
//有无国际科技合作:0-否,1-是
if ObjToInt(that.Req.FormValue("international_cooperation_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "international_cooperation_flag": ObjToInt(that.Req.FormValue("international_cooperation_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["international_cooperation_flag_count"] = 1
}
}
//上年度有无固定资产投入:0-否,1-是
if ObjToInt(that.Req.FormValue("investment_fixed_assets_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "investment_fixed_assets_flag": ObjToInt(that.Req.FormValue("investment_fixed_assets_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["investment_fixed_assets_flag_count"] = 1
}
}
//高层次人才情况:0-否,1-3个及以上博士-1,2-1个及以上博士-2,3-知名企业中高管1个及以上
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "high_level_talents_flag": ObjToInt(that.Req.FormValue("high_level_talents_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["high_level_talents_flag_count"] = 1
}
//企业股东或成员是否有国内外高校或科研院在编、全职人员:0-否,1-是
if ObjToInt(that.Req.FormValue("shareholders_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "shareholders_flag": ObjToInt(that.Req.FormValue("shareholders_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["shareholders_flag_count"] = 1
}
}
//企业有无从外地引进博士学历人才:0-否,1-是
if ObjToInt(that.Req.FormValue("nonlocal_dr_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "nonlocal_dr_flag": ObjToInt(that.Req.FormValue("nonlocal_dr_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["nonlocal_dr_flag"] = 1
}
}
//上年度是否有贷款/融资或未来有贷款/融资计划:0-否,1-是
if ObjToInt(that.Req.FormValue("loan_flag")) > 0 {
dtag = that.Db.Select("declare", "id AS declare_id", Map{"AND": Map{"OR": Map{"policy_level": Slice{"省", "市"}, "dispatch_department[~]": qu}, "del_flag": 0, "loan_flag": ObjToInt(that.Req.FormValue("loan_flag"))}})
for _, v1 := range dtag {
if declares[v1.GetCeilInt64("declare_id")] == nil {
declares[v1.GetCeilInt64("declare_id")] = v1
}
declares[v1.GetCeilInt64("declare_id")]["count"] = declares[v1.GetCeilInt64("declare_id")].GetCeilInt64("count") + 1
declares[v1.GetCeilInt64("declare_id")]["loan_flag"] = 1
}
}
px := paixuArr{}
for _, v := range declares {
px = append(px, v)
}
//获取到排序后的数据
sort.Sort(px)
var res []Map
for _, v := range px {
id := v.GetCeilInt("declare_id")
article := that.Db.Get("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id", Map{"declare_id": id})
article["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": id})
res = append(res, article)
}
minMoney := 0
maxMoney := 0
for _, v := range res {
if v.GetMap("declare") != nil {
if v.GetMap("declare").GetInt("money_scope_min") < minMoney {
minMoney = v.GetMap("declare").GetInt("money_scope_min")
}
if v.GetMap("declare").GetInt("money_scope_max") > maxMoney {
maxMoney = v.GetMap("declare").GetInt("money_scope_max")
}
}
}
seData := Map{
"user_id": that.Session("user_id").Data,
"search_company_name": companyName,
"policy_match_count": len(res),
"json_data": ObjToStr(company),
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
}
if maxMoney != minMoney {
seData["money_scope"] = ObjToStr(minMoney) + "-" + ObjToStr(maxMoney) + "万元"
} else if maxMoney == 0 {
seData["money_scope"] = ""
} else {
seData["money_scope"] = ObjToStr(maxMoney) + "万元"
}
//匹配记录存储
that.Db.Insert("search_record", seData)
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "declare_id[!]": nil}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["release_date[>=]"] = startTime
}
if finishTime != "" {
data["release_date[<=]"] = finishTime
}
dispatchName := that.Req.FormValue("dispatch_name")
if dispatchName != "" {
data["dispatch_name"] = dispatchName
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "release_time DESC"}
}
count := that.Db.Count("article", data)
res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id,dispatch_name,policy_level", data)
for _, v := range res {
//if v.GetCeilInt("declare_id")>0{
// v["declare"]=that.Db.Get("declare","id,tag",Map{"id":v.GetCeilInt("declare_id")})
//}
//if v.GetCeilInt("declare_id")>0{
// v["declare"]=that.Db.Get("declare","tag",Map{"id":v.GetCeilInt("declare_id")})
//}
if v.GetCeilInt("declare_id") > 0 {
v["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt("declare_id")})
}
}
that.Display(0, Map{"total": count, "data": res})
},
}

241
example/app/favorite.go Normal file
View File

@ -0,0 +1,241 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var FavoriteCtr = Ctr{
//关注
"follow": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
policyId := ObjToInt(that.Req.FormValue("policy_id"))
notifyId := ObjToInt(that.Req.FormValue("notify_id"))
declareId := ObjToInt(that.Req.FormValue("declare_id"))
providerId := ObjToInt(that.Req.FormValue("provider_id"))
favorite := Map{}
data := Map{}
if providerId != 0 {
data = Map{"provider_id": providerId, "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 0
data["type"] = 1
} else if notifyId != 0 {
article := that.Db.Get("article", "id", Map{"notify_id": notifyId})
if article != nil {
data = Map{"notify_id": notifyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 0
data["type"] = 2
}
} else if policyId != 0 {
article := that.Db.Get("article", "id", Map{"policy_id": policyId})
if article != nil {
data = Map{"policy_id": policyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 0
data["type"] = 3
}
} else if declareId != 0 {
article := that.Db.Get("article", "id", Map{"declare_id": declareId})
if article != nil {
data = Map{"declare_id": declareId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 0
data["type"] = 4
}
}
if len(data) != 0 {
isFavorite := int64(0)
if favorite != nil {
isFavorite = that.Db.Update("favorite", data, Map{"id": favorite.GetCeilInt("id")})
} else {
data["create_time[#]"] = "now()"
isFavorite = that.Db.Insert("favorite", data)
}
if isFavorite != 0 {
if data.GetCeilInt("article_id") != 0 {
that.Db.Update("article", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("article_id")})
}
if data.GetCeilInt("notify_id") != 0 {
that.Db.Update("notify", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("notify_id")})
}
if data.GetCeilInt("policy_id") != 0 {
that.Db.Update("policy", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("policy_id")})
}
if data.GetCeilInt("declare_id") != 0 {
that.Db.Update("declare", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("declare_id")})
}
if data.GetCeilInt("provider_id") != 0 {
that.Db.Update("provider", Map{"favorite_num[#]": "favorite_num+1"}, Map{"id": data.GetCeilInt("provider_id")})
}
}
that.Display(0, "关注成功")
return
}
that.Display(4, "找不到关注对象")
return
},
//关注
"unfollow": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
policyId := ObjToInt(that.Req.FormValue("policy_id"))
notifyId := ObjToInt(that.Req.FormValue("notify_id"))
declareId := ObjToInt(that.Req.FormValue("declare_id"))
providerId := ObjToInt(that.Req.FormValue("provider_id"))
favorite := Map{}
data := Map{}
if providerId != 0 {
data = Map{"provider_id": providerId, "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 1
data["type"] = 1
} else if notifyId != 0 {
article := that.Db.Get("article", "id", Map{"notify_id": notifyId})
if article != nil {
data = Map{"notify_id": notifyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 1
data["type"] = 2
}
} else if policyId != 0 {
article := that.Db.Get("article", "id", Map{"policy_id": policyId})
if article != nil {
data = Map{"policy_id": policyId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 1
data["type"] = 3
}
} else if declareId != 0 {
article := that.Db.Get("article", "id", Map{"declare_id": declareId})
if article != nil {
data = Map{"declare_id": declareId, "article_id": article.GetCeilInt("id"), "user_id": that.Session("user_id").Data}
favorite = that.Db.Get("favorite", "*", Map{"AND": data})
data["modify_time[#]"] = "now()"
data["del_flag"] = 1
data["type"] = 4
}
}
if len(data) != 0 && favorite != nil {
isFavorite := that.Db.Update("favorite", data, Map{"id": favorite.GetCeilInt("id")})
if isFavorite != 0 {
if data.GetCeilInt("article_id") != 0 {
that.Db.Update("article", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("article_id")})
}
if data.GetCeilInt("notify_id") != 0 {
that.Db.Update("notify", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("notify_id")})
}
if data.GetCeilInt("policy_id") != 0 {
that.Db.Update("policy", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("policy_id")})
}
if data.GetCeilInt("declare_id") != 0 {
that.Db.Update("declare", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("declare_id")})
}
if data.GetCeilInt("provider_id") != 0 {
that.Db.Update("provider", Map{"favorite_num[#]": "favorite_num-1"}, Map{"id": data.GetCeilInt("provider_id")})
}
}
that.Display(0, "取消关注成功")
return
}
that.Display(0, "没有关注")
return
},
"search": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
tp := ObjToInt(that.Req.FormValue("type"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "user_id": that.Session("user_id").Data}
if tp != 0 {
data["type"] = tp
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "modify_time DESC"}
}
count := that.Db.Count("favorite", data)
res := that.Db.Page(page, pageSize).PageSelect("favorite", "*", data)
for _, v := range res {
if v.GetCeilInt64("policy_id") != 0 {
v["policy"] = that.Db.Get("policy", "id,tag", Map{"id": v.GetCeilInt64("policy_id")})
}
if v.GetCeilInt64("declare_id") != 0 {
v["declare"] = that.Db.Get("declare", "id,money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt64("declare_id")})
}
if v.GetCeilInt64("notify_id") != 0 {
v["notify"] = that.Db.Get("notify", "id,tag", Map{"id": v.GetCeilInt64("notify_id")})
}
if v.GetCeilInt64("article_id") != 0 {
v["article"] = that.Db.Get("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status", Map{"id": v.GetCeilInt64("article_id")})
}
if v.GetCeilInt64("provider_id") != 0 {
v["provider"] = that.Db.Get("provider", "id,name,level,discount,avatar,title,description,"+
"click_num_base+click_num AS click_num,handle_num_base+handle_num AS handle_num,favorite_num_base+favorite_num AS favorite_num,modify_time", Map{"id": v.GetCeilInt64("provider_id")})
}
}
that.Display(0, Map{"total": count, "data": res})
},
}

111
example/app/init.go Normal file
View File

@ -0,0 +1,111 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"errors"
"time"
)
// Project 管理端项目
var Project = Proj{
"article": ArticleCtr,
"company": CompanyCtr,
"declare": DeclareCtr,
"favorite": FavoriteCtr,
"lxcx": Lxcx,
"matters": MattersCtr,
"notify": NotifyCtr,
"order": OrderCtr,
"policy": PolicyCtr,
"provider": ProviderCtr,
"search_record": SearchRecordCtr,
"sms": Sms,
"tag": TagCtr,
"user": UserCtr,
"vip_order": VipOrderCtr,
"websocket": WebsocketCtr,
"wechath5": Wechath5,
"wechatmini": Wechath5,
}
//生成随机码的6位md5
func getSn() string {
x := Rand(8)
return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6)
}
//生成随机码的4位随机数
func getCode() string {
//res := ""
//for i := 0; i < 4; i++ {
res := ObjToStr(RandX(1000, 9999))
//}
return res
}
//认证公共方案
func auth(that *Context, phone, companyName string) error {
user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id", Map{"id": that.Session("user_id").ToCeilInt()})
if user == nil {
return errors.New("找不到用户")
}
//手机号与原来的不同则进行绑定
if phone != user.GetString("phone") {
//微信验证成功
if that.Session("wechat_phone").ToStr() == phone {
that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")})
if user.GetCeilInt("company_id") != 0 {
that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")})
}
user["phone"] = phone
} else if that.Req.FormValue("code") == "" || that.Session("phone").ToStr() != phone || that.Session("code").ToStr() != that.Req.FormValue("code") {
return errors.New("验证码错误")
} else {
that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")})
if user.GetCeilInt("company_id") != 0 {
that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")})
}
user["phone"] = phone
}
}
//
company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")})
if company != nil {
that.Db.Update("company", Map{"name": companyName}, Map{"id": company.GetCeilInt64("id")})
if user.GetCeilInt64("salesman_id") != 0 {
that.Db.Update("user", Map{"certification_flag": 1}, Map{"id": user.GetCeilInt("id")})
}
return nil
}
company = Map{"name": companyName,
"user_id": user.GetCeilInt("id"),
}
if user.GetCeilInt("salesman_id") != 0 {
company["salesman_id"] = user.GetCeilInt("salesman_id")
}
if user.GetCeilInt("provider_id") != 0 {
company["provider_id"] = user.GetCeilInt("provider_id")
}
if user.GetString("phone") != "" {
company["phone"] = user.GetString("phone")
}
company["id"] = that.Db.Insert("company", company)
if company.GetCeilInt64("id") == 0 {
return errors.New("新建企业失败")
}
upUser := Map{"company_id": company.GetCeilInt64("id")}
if user.GetCeilInt64("salesman_id") != 0 {
upUser["certification_flag"] = 1
}
that.Db.Update("user", upUser, Map{"id": that.Session("user_id").Data})
return nil
}

29
example/app/lxcx.go Normal file
View File

@ -0,0 +1,29 @@
package app
import (
. "code.hoteas.com/golang/hotime"
"code.hoteas.com/golang/hotime/common"
"io/ioutil"
"log"
"net/http"
"net/url"
)
var Lxcx = Ctr{
"lists": func(that *Context) {
urlStr := "https://www.ruichuangshe.com/Resources/Services/sAppInterface.ashx?type=policyprojectbycompanyname&page=1&pagesize=10&code=8eb68adf79d660e57ccd69ea4bf340162e29e43ec344df62b364bd65b886da7fca9fb995ad93a5b485d66fd268f946f34cf0&CompanyName="
companyName := that.Req.FormValue("company")
companyName = url.QueryEscape(url.QueryEscape(companyName))
resp, err := http.Get(urlStr + companyName)
if err != nil {
log.Println("err")
}
defer resp.Body.Close()
b, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Println("err")
}
that.Display(0, common.ObjToMap(string(b)))
},
}

168
example/app/matters.go Normal file
View File

@ -0,0 +1,168 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var MattersCtr = Ctr{
"create": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
sn := that.Req.FormValue("sn")
if sn == "" {
that.Display(3, "没有SN码")
return
}
serviceContent := that.Req.FormValue("service_content")
if serviceContent == "" {
that.Display(3, "没有服务内容")
return
}
salesman := that.Db.Get("salesman", "id,provider_id,name,nickname", Map{"AND": Map{"sn": sn, "del_flag": 0}})
if salesman == nil {
that.Display(4, "找不到服务商")
return
}
re := that.Db.Insert("matters", Map{
"user_id": that.Session("user_id").Data,
"salesman_id": salesman.GetCeilInt64("id"),
"provider_id": salesman.GetCeilInt64("provider_id"),
"type": 1,
"service_content": serviceContent,
"complete_flag": 0,
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
res := that.Db.Get("matters", "*", Map{"id": re})
if res == nil {
that.Display(4, "找不到事项")
return
}
res["salesman"] = that.Db.Get("salesman", "name,id", Map{"id": res.GetCeilInt64("salesman_id")})
res["provider"] = that.Db.Get("provider", "name,id", Map{"id": res.GetCeilInt64("provider_id")})
that.Display(0, res)
},
"info": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("matters", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到事项")
return
}
res["salesman"] = that.Db.Get("salesman", "name,id", Map{"id": res.GetCeilInt64("salesman_id")})
res["provider"] = that.Db.Get("provider", "name,id", Map{"id": res.GetCeilInt64("provider_id")})
that.Display(0, res)
},
"edit": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
serviceEvaluation := ObjToInt(that.Req.FormValue("service_evaluation"))
evaluationRemark := that.Req.FormValue("evaluation_remark")
if serviceEvaluation == 0 {
that.Display(3, "请求参数异常")
return
}
matters := that.Db.Get("matters", "*", Map{"AND": Map{"id": id, "user_id": that.Session("user_id").Data}})
if matters == nil {
that.Display(4, "不是属于你的评价")
return
}
if matters.GetCeilInt("complete_flag") == 1 {
that.Display(4, "已完成评价,不可重复评价")
return
}
that.Db.Update("matters", Map{"service_evaluation": serviceEvaluation, "evaluation_remark": evaluationRemark, "complete_flag": 1, "modify_time[#]": "now()"}, Map{"id": id})
that.Display(0, "评价成功")
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
tp := that.Req.FormValue("type")
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "user_id": that.Session("user_id").Data}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
if tp != "" {
data["type"] = ObjToInt(tp)
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modify_time[>=]"] = startTime
}
if finishTime != "" {
data["modify_time[<=]"] = finishTime
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "modify_time DESC"}
}
count := that.Db.Count("matters", data)
res := that.Db.Page(page, pageSize).PageSelect("matters", "*", data)
that.Display(0, Map{"total": count, "data": res})
},
}

111
example/app/notify.go Normal file
View File

@ -0,0 +1,111 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var NotifyCtr = Ctr{
"info": func(that *Context) {
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("notify", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到通知公告")
return
}
res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1
delete(res, "click_num_base")
res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base")
delete(res, "favorite_num_base")
article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")})
if article != nil {
article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1
delete(article, "click_num_base")
article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base")
delete(article, "favorite_num_base")
}
res["article"] = article
//浏览量加1
that.Db.Update("notify", Map{"click_num[#]": "click_num+1"}, Map{"id": id})
//浏览量加1
that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")})
//查询是否已关注
if that.Session("user_id").Data != nil {
favorite := that.Db.Get("favorite", "user_id,notify_id", Map{"AND": Map{"notify_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}})
res["favorite"] = favorite
}
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "notify_id[!]": nil}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["release_date[>=]"] = startTime
}
if finishTime != "" {
data["release_date[<=]"] = finishTime
}
dispatchName := that.Req.FormValue("dispatch_name")
if dispatchName != "" {
data["dispatch_name"] = dispatchName
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "release_time DESC"}
}
count := that.Db.Count("article", data)
res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,policy_id,declare_id,notify_id,dispatch_name,policy_level", data)
for _, v := range res {
if v.GetCeilInt("notify_id") > 0 {
v["notify"] = that.Db.Get("notify", "id,tag", Map{"id": v.GetCeilInt("notify_id")})
}
//if v.GetCeilInt("policy_id")>0{
// v["policy"]=that.Db.Get("policy","tag",Map{"id":v.GetCeilInt("policy_id")})
//}
//if v.GetCeilInt("declare_id")>0{
// v["declare"]=that.Db.Get("declare","money_scope_min,money_scope_max,tag,status",Map{"id":v.GetCeilInt("declare_id")})
//}
}
that.Display(0, Map{"total": count, "data": res})
},
}

207
example/app/order.go Normal file
View File

@ -0,0 +1,207 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
)
var OrderCtr = Ctr{
//创建订单
"create": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
providerId := ObjToInt(that.Req.FormValue("provider_id"))
phone := that.Req.FormValue("phone")
companyName := that.Req.FormValue("company_name")
if providerId == 0 || len(phone) != 11 || len(companyName) < 4 {
that.Display(3, "请求参数异常")
return
}
err := auth(that, phone, companyName)
if err != nil {
that.Display(3, err.Error())
return
}
declareId := ObjToInt(that.Req.FormValue("declare_id"))
tp := that.Req.FormValue("type")
//新建流程
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data})
if user == nil {
that.Display(4, "找不到用户")
return
}
company := that.Db.Get("company", "name", Map{"id": user.GetCeilInt("company_id")})
if company == nil {
that.Display(4, "找不到企业")
return
}
provider := that.Db.Get("provider", "*", Map{"id": providerId})
if provider == nil {
that.Display(4, "找不到该服务商")
return
}
//是否以前已经创建了该服务商的订单,如果创建了则直接跳转到订单详情中去
oldOrder := that.Db.Get("order", "id", Map{"AND": Map{"provider_id": providerId, "user_id": that.Session("user_id").Data, "del_flag": 0, "status": 0}})
if oldOrder != nil {
orderRecord := Map{
"order_id": oldOrder.GetCeilInt64("id"),
"user_id": user.GetCeilInt64("id"),
"remarks": user.GetString("nickname") + "向“" + provider.GetString("name") + "”服务商再次发起了订单请求",
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
}
orderRecord["id"] = that.Db.Insert("order_record", orderRecord)
that.Db.Update("order", Map{"order_record_id": orderRecord.GetCeilInt64("id"), "modify_time[#]": "now()"}, Map{"id": oldOrder.GetCeilInt64("id")})
that.Display(0, oldOrder.GetCeilInt64("id"))
return
}
data := Map{
"name": "购买“" + provider.GetString("title") + "”服务",
"sn": "SN" + time.Now().Format("20060102150405") + getSn(),
"user_id": user.GetCeilInt64("id"),
"salesman_id": provider.GetCeilInt64("salesman_id"),
"provider_id": provider.GetCeilInt64("id"),
"company_id": company.GetCeilInt64("id"),
"company_name": company.GetString("name"),
"phone": user.GetString("phone"),
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
}
if declareId != 0 {
data["policy_declare_flag"] = 1
data["declare_id"] = declareId
}
if tp == "policy_declare_flag" {
data["policy_declare_flag"] = 1
}
data["id"] = that.Db.Insert("order", data)
if data.GetCeilInt64("id") == 0 {
that.Display(4, "无法生成订单!")
return
}
orderRecord := Map{
"order_id": data["id"],
"user_id": user.GetCeilInt64("id"),
"remarks": user.GetString("nickname") + "向“" + provider.GetString("name") + "”服务商发起了订单请求",
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
}
orderRecord["id"] = that.Db.Insert("order_record", orderRecord)
if orderRecord.GetCeilInt64("id") == 0 {
that.Display(4, "无法生成订单记录!")
return
}
that.Db.Update("order", Map{"order_record_id": orderRecord.GetCeilInt64("id")}, Map{"id": data.GetCeilInt64("id")})
that.Display(0, data.GetCeilInt64("id"))
},
"info": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "user_id": that.Session("user_id").Data}})
if res == nil {
that.Display(4, "找不到对应订单")
return
}
if res.GetCeilInt("provider_id") > 0 {
res["provider"] = that.Db.Get("provider", "name,title,phone", Map{"id": res.GetCeilInt("provider_id")})
}
res["order_record"] = that.Db.Select("order_record", "remarks,modify_time", Map{"order_id": res.GetCeilInt("id"), "ORDER": "modify_time DESC"})
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
if that.Session("user_id").Data == nil {
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
}
data := Map{"del_flag": 0, "user_id": that.Session("user_id").Data}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"sn[~]": keywords, "company_name[~]": keywords, "name[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modify_time[>=]"] = startTime
}
if finishTime != "" {
data["modify_time[<=]"] = finishTime
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "modify_time DESC"}
}
count := that.Db.Count("order", data)
res := that.Db.Page(page, pageSize).PageSelect("order", "*", data)
for _, v := range res {
//if v.GetCeilInt("policy_id")>0{
// v["policy"]=that.Db.Get("policy","id,tag",Map{"id":v.GetCeilInt("policy_id")})
//}
if v.GetCeilInt("provider_id") > 0 {
v["provider"] = that.Db.Get("provider", "name,title", Map{"id": v.GetCeilInt("provider_id")})
}
if v.GetCeilInt("order_record_id") > 0 {
v["order_record"] = that.Db.Get("order_record", "remarks,modify_time", Map{"id": v.GetCeilInt("order_record_id")})
}
}
that.Display(0, Map{"total": count, "data": res})
},
}

112
example/app/policy.go Normal file
View File

@ -0,0 +1,112 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var PolicyCtr = Ctr{
"info": func(that *Context) {
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("policy", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到通知公告")
return
}
res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1
delete(res, "click_num_base")
res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base")
delete(res, "favorite_num_base")
article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")})
if article != nil {
article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1
delete(article, "click_num_base")
article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base")
delete(article, "favorite_num_base")
}
res["article"] = article
//浏览量加1
that.Db.Update("policy", Map{"click_num[#]": "click_num+1"}, Map{"id": id})
//浏览量加1
that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")})
//查询是否已关注
if that.Session("user_id").Data != nil {
favorite := that.Db.Get("favorite", "user_id,policy_id", Map{"AND": Map{"policy_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}})
res["favorite"] = favorite
}
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "policy_id[!]": nil}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["release_date[>=]"] = startTime
}
if finishTime != "" {
data["release_date[<=]"] = finishTime
}
dispatchName := that.Req.FormValue("dispatch_name")
if dispatchName != "" {
data["dispatch_name"] = dispatchName
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "release_time DESC"}
}
count := that.Db.Count("article", data)
res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,policy_id,declare_id,policy_id,dispatch_name,policy_level", data)
for _, v := range res {
//if v.GetCeilInt("policy_id")>0{
// v["policy"]=that.Db.Get("policy","id,tag",Map{"id":v.GetCeilInt("policy_id")})
//}
if v.GetCeilInt("policy_id") > 0 {
v["policy"] = that.Db.Get("policy", "tag", Map{"id": v.GetCeilInt("policy_id")})
}
//if v.GetCeilInt("declare_id")>0{
// v["declare"]=that.Db.Get("declare","money_scope_min,money_scope_max,tag,status",Map{"id":v.GetCeilInt("declare_id")})
//}
}
that.Display(0, Map{"total": count, "data": res})
},
}

92
example/app/provider.go Normal file
View File

@ -0,0 +1,92 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var ProviderCtr = Ctr{
//用户微信公众号或者小程序登录
"info": func(that *Context) {
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("provider", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到服务商")
return
}
//浏览量加1
that.Db.Update("provider", Map{"click_num[#]": "click_num+1"}, Map{"id": id})
//查询是否已关注
if that.Session("user_id").Data != nil {
favorite := that.Db.Get("favorite", "user_id,provider_id", Map{"AND": Map{"provider_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}})
res["favorite"] = favorite
}
that.Display(0, res)
},
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"name[~]": keywords, "title[~]": keywords}
}
tp := that.Req.FormValue("type")
if tp != "" {
data[tp] = 1
}
policyDeclareFlag := that.Req.FormValue("policy_declare_flag")
if policyDeclareFlag != "" {
data["policy_declare_flag"] = ObjToInt(policyDeclareFlag)
}
intellectualPropertyFlag := that.Req.FormValue("intellectual_property_flag")
if intellectualPropertyFlag != "" {
data["intellectual_property_flag"] = ObjToInt(intellectualPropertyFlag)
}
taxOnsultingFlag := that.Req.FormValue("tax_onsulting_flag")
if taxOnsultingFlag != "" {
data["tax_onsulting_flag"] = ObjToInt(taxOnsultingFlag)
}
lawFlag := that.Req.FormValue("law_flag")
if lawFlag != "" {
data["law_flag"] = ObjToInt(lawFlag)
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "id DESC"}
}
count := that.Db.Count("provider", data)
res := that.Db.Page(page, pageSize).PageSelect("provider", "id,name,level,discount,avatar,title,description,"+
"click_num_base+click_num AS click_num,handle_num_base+handle_num AS handle_num,favorite_num_base+favorite_num AS favorite_num,modify_time,policy_declare_flag,intellectual_property_flag,tax_onsulting_flag,law_flag", data)
that.Display(0, Map{"total": count, "data": res})
},
}

View File

@ -0,0 +1,51 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var SearchRecordCtr = Ctr{
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["search_company_name[~]"] = keywords
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["create_time[>=]"] = startTime
}
if finishTime != "" {
data["create_time[<=]"] = finishTime
}
if len(data) > 1 {
data = Map{"AND": data}
} else {
data["ORDER"] = "create_time DESC"
}
count := that.Db.Count("search_record", data)
res := that.Db.Page(page, pageSize).PageSelect("search_record", "id,search_company_name,policy_match_count,money_scope,create_time", data)
that.Display(0, Map{"total": count, "data": res})
},
}

30
example/app/sms.go Normal file
View File

@ -0,0 +1,30 @@
package app
import (
. "code.hoteas.com/golang/hotime"
"code.hoteas.com/golang/hotime/dri/ddsms"
)
var Sms = Ctr{
//只允许微信验证过的或者登录成功的发送短信
"send": func(that *Context) {
if that.Session("wechat_id").Data == nil && that.Session("user_id").Data == nil {
that.Display(2, "没有登录不可发送短信")
return
}
phone := that.Req.FormValue("phone")
if len(phone) < 11 {
that.Display(3, "手机号格式错误")
return
}
code := getCode()
that.Session("phone", phone)
that.Session("code", code)
ddsms.DDY.SendYZM(phone, that.Config.GetString("smsLogin"), map[string]string{"code": code})
that.Display(0, "发送成功")
},
}

83
example/app/tag.go Normal file
View File

@ -0,0 +1,83 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var TagCtr = Ctr{
"create": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
name := that.Req.FormValue("name")
oldTag := that.Db.Get("tag", "id", Map{"name": name})
if oldTag != nil {
that.Display(4, "此标签已存在")
return
}
re := that.Db.Insert("tag", Map{
"user_id": that.Session("user_id").Data,
"name": name,
"remark": "用户上传",
"create_time[#]": "now()",
"modify_time[#]": "now()",
"state": 1, //先置为异常状态,等待审核通过
"del_flag": 0,
})
if re == 0 {
that.Display(4, "添加失败")
return
}
that.Display(0, "添加成功")
return
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 40
}
data := Map{"del_flag": 0, "state": 0}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"name[~]": keywords, "remark[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modify_time[>=]"] = startTime
}
if finishTime != "" {
data["modify_time[<=]"] = finishTime
}
if len(data) > 1 {
data = Map{"AND": data}
}
count := that.Db.Count("tag", data)
res := that.Db.Page(page, pageSize).PageSelect("tag", "id,name,remark", data)
that.Display(0, Map{"total": count, "data": res})
},
}

96
example/app/user.go Normal file
View File

@ -0,0 +1,96 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var UserCtr = Ctr{
"test": func(that *Context) {
that.Session("user_id", 1)
that.Session("wechat_id", 1)
that.Display(0, 1)
},
//用户微信公众号或者小程序登录
"info": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()})
if user == nil {
that.Display(2, "获取个人信息失败")
return
}
delete(user, "password")
company := that.Db.Get("company", "id,name", Map{"id": user.GetCeilInt("company_id")})
salesman := that.Db.Get("salesman", "id,name", Map{"id": user.GetCeilInt("salesman_id")})
provider := that.Db.Get("provider", "id,name", Map{"id": user.GetCeilInt("provider_id")})
if user != nil {
user["company"] = company
user["salesman"] = salesman
user["provider"] = provider
}
that.Display(0, user)
},
"edit": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
name := that.Req.FormValue("name")
nickname := that.Req.FormValue("nickname")
sex := that.Req.FormValue("sex")
email := that.Req.FormValue("email")
avatar := that.Req.FormValue("avatar")
address := that.Req.FormValue("address")
phone := that.Req.FormValue("phone") //如果更换手机号则要有新的短信验证码
code := that.Req.FormValue("code")
data := Map{"modify_time[#]": "now()"}
if name != "" {
data["name"] = name
}
if nickname != "" {
data["nickname"] = nickname
}
if sex != "" {
data["sex"] = sex
}
if email != "" {
data["email"] = email
}
if avatar != "" {
data["avatar"] = avatar
}
if address != "" {
data["address"] = address
}
if phone != "" {
//微信验证成功
if that.Session("wechat_phone").ToStr() == phone {
data["phone"] = phone
} else if code == "" || that.Session("phone").ToStr() != phone || that.Session("code").ToStr() != code {
that.Display(3, "手机短信验证失败")
return
}
data["phone"] = phone
}
re := that.Db.Update("user", data, Map{"id": that.Session("user_id").Data})
if re == 0 {
that.Display(4, "更新失败")
return
}
that.Display(0, "修改成功")
},
}

158
example/app/vip_order.go Normal file
View File

@ -0,0 +1,158 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"code.hoteas.com/golang/hotime/dri/wechat"
"fmt"
"time"
)
var VipOrderCtr = Ctr{
//创建V订单
"create": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
phone := that.Req.FormValue("phone")
companyName := that.Req.FormValue("company_name")
if len(phone) != 11 || len(companyName) < 4 {
that.Display(3, "请求参数异常")
return
}
that.Db.Delete("vip_order", Map{"AND": Map{"user_id": that.Session("user_id").Data, "status": 0}})
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").Data})
if user == nil {
that.Display(2, "找不到此用户")
return
}
wc := that.Db.Get("wechat", "openid", Map{"AND": Map{"appid": that.Config.GetString("wechatAppID"), "user_id": that.Session("user_id").Data}})
if wc == nil {
that.Display(2, "没有获取微信个人信息")
return
}
err := auth(that, phone, companyName)
if err != nil {
that.Display(3, err.Error())
return
}
data := Map{
"sn": "SN" + time.Now().Format("20060102150405") + getSn(),
//"name":"1年VIP会员",
"amount": 72000, //720元
"user_id": user.GetCeilInt64("id"),
"company_id": user.GetCeilInt("company_id"),
"expiration_time": time.Now().Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05"),
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
"status": 0,
}
tp := "购买"
if user.GetString("expiration_time") != "" {
data["old_expiration_time"] = user.GetString("expiration_time")
t, e := time.Parse("2006-01-02 15:04:05", user.GetString("expiration_time"))
fmt.Println(e, "时间创建失败")
if t.Unix() >= time.Now().Unix() {
tp = "续订"
data["expiration_time"] = t.Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05")
}
}
if user.GetCeilInt("provider_id") != 0 {
data["provider_id"] = user.GetCeilInt("provider_id")
data["amount"] = 36000
//tp=tp
}
data["amount"] = 1
if user.GetCeilInt("salesman_id") != 0 {
data["salesman_id"] = user.GetCeilInt("salesman_id")
}
data["name"] = tp + "1年VIP会员"
jsParams, e := wechat.WxPay.GetJsOrder(data.GetCeilInt64("amount"), that.Config.GetString("wechatAppID"), wc.GetString("openid"), data.GetString("name"), data.GetString("sn"), that.Config.GetString("wechatAppNotifyUrl"))
if e != nil {
fmt.Println(e)
that.Display(4, e)
return
}
re := that.Db.Insert("vip_order", data)
fmt.Println(re)
that.Display(0, jsParams)
},
"callback": func(that *Context) {
data, e := wechat.WxPay.CallbackJsOrder(that.Req)
if e != nil {
fmt.Println(e)
//that.Display(4,e)
fmt.Println("返回数据错误", e)
return
}
sn := data.OutTradeNo
amount := int64(data.Amount.Total)
state := data.TradeState
//state:="SUCCESS"
//data := Map{"ces": "das"}
//sn := that.Req.FormValue("sn")
//amount := ObjToCeilInt64(that.Req.FormValue("amount"))
if state != "SUCCESS" {
fmt.Println("购买返回失败", data)
return
}
vipOrder := that.Db.Get("vip_order", "*", Map{"sn": sn})
if vipOrder == nil {
fmt.Println("找不到订单", vipOrder, data)
return
}
user := that.Db.Get("user", "*", Map{"id": vipOrder.GetCeilInt("user_id")})
if user == nil {
fmt.Println("找不到用户", vipOrder, data)
return
}
if vipOrder.GetCeilInt64("amount") != amount {
fmt.Println("金额不符", user, vipOrder, amount, data)
return
}
that.Db.Update("vip_order", Map{"status": 1}, Map{"id": vipOrder.GetCeilInt("id")})
idata := Map{"expiration_time": time.Now().Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05")}
if user.GetString("expiration_time") != "" {
t, e := time.Parse("2006-01-02 15:04:05", user.GetString("expiration_time"))
fmt.Println(e, "时间创建失败")
if t.Unix() >= time.Now().Unix() {
idata["expiration_time"] = t.Add(365 * 24 * time.Hour).Format("2006-01-02 15:04:05")
}
}
re := that.Db.Update("user", idata, Map{"id": user.GetCeilInt("id")})
if re == 0 {
fmt.Println("购买失败", user, vipOrder, re, data)
return
}
fmt.Println("成功购买", user, vipOrder, re, data)
return
},
}

72
example/app/websocket.go Normal file
View File

@ -0,0 +1,72 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"golang.org/x/net/websocket"
"time"
)
type WSClient struct {
ID string
*websocket.Conn
time.Time
DeadTime time.Time
IsDead bool
}
//websocket链接池
var WsUserMap = map[string][]*WSClient{}
var WSMasterID = ""
func WsSendMsg(ws *WSClient, data Map) bool {
if WsUserMap[ws.ID] == nil {
return false
}
for _, v := range WsUserMap[ws.ID] {
if v.IsDead || v == ws {
//WsUserMap[ws.ID]=WsUserMap[ws.ID][:k]
continue
}
str := data.ToJsonString()
v.Conn.Write([]byte(str))
}
return true
}
var WebsocketCtr = Ctr{
"conn": func(this *Context) {
id := this.SessionId
if WsUserMap[id] == nil {
WsUserMap[id] = []*WSClient{}
}
hdler := websocket.Handler(func(ws *websocket.Conn) {
client := &WSClient{ID: id, Conn: ws, Time: time.Now(), DeadTime: time.Now(), IsDead: false}
WsUserMap[id] = append(WsUserMap[id], client)
var message string
for true {
err := websocket.Message.Receive(ws, &message)
if err != nil {
client.DeadTime = time.Now()
client.IsDead = true
return
}
data := Map{}
data.JsonToMap(message)
WsSendMsg(client, data)
//switch data.GetString("type") {
//
//}
}
})
hdler.ServeHTTP(this.Resp, this.Req)
},
}

246
example/app/wechath5.go Normal file
View File

@ -0,0 +1,246 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"code.hoteas.com/golang/hotime/dri/wechat"
)
var Wechath5 = Ctr{
//微信注册0已经完整的注册了1还没有注册
"code": func(that *Context) {
if that.Req.FormValue("code") == "" {
that.Display(3, "参数不足")
return
}
appid, resToken, userInfo, err := wechat.H5Program.GetUserInfo(that.Req.FormValue("code"))
if err != nil {
that.Display(4, err)
return
}
//此次获取的微信信息
wechatInfo := Map{
"openid": userInfo.OpenID,
"acttoken": resToken.AccessToken,
"retoken": resToken.RefreshToken,
"appid": appid,
"unionid": userInfo.Unionid,
"nickname": userInfo.Nickname,
"avatar": userInfo.HeadImgURL,
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
"type": 1,
}
userId := 0
defer func() {
//有sn就关联业务员
parentId := ObjToInt(that.Req.FormValue("parent_id"))
if parentId == 0 {
return
}
if userId == 0 || userId == parentId {
return
}
puser := that.Db.Get("user", "`index`,id", Map{"id": parentId})
if puser == nil {
return
}
user := that.Db.Get("user", "parent_id", Map{"id": userId})
if user.GetCeilInt("parent_id") != 0 {
return
}
index1 := puser.GetString("index")
if index1 == "," {
index1 = index1 + ObjToStr(parentId) + ","
}
that.Db.Update("user", Map{"parent_id": parentId, "index": index1 + ObjToStr(userId) + ","}, Map{"id": userId})
}()
//最后验证服务商是否绑定
defer func() {
//有sn就关联业务员
sn := that.Req.FormValue("sn")
if sn == "" {
return
}
if userId == 0 {
return
}
salesman := that.Db.Get("salesman", "*", Map{"sn": sn})
if salesman.GetCeilInt("id") == 0 {
return
}
user := that.Db.Get("user", "*", Map{"id": userId})
if user == nil {
return
}
//用户都有企服人员关联
if user.GetCeilInt("salesman_id") != 0 {
return
}
//用户没有企服商id
that.Db.Update("user", Map{"salesman_id": salesman.GetCeilInt64("id"), "provider_id": salesman.GetCeilInt64("provider_id")}, Map{"id": user.GetCeilInt64("id")})
if user.GetCeilInt("company_id") == 0 {
return
}
//绑定企业
that.Db.Update("company", Map{"salesman_id": salesman.GetCeilInt64("id"), "provider_id": salesman.GetCeilInt64("provider_id")}, Map{"id": user.GetCeilInt64("company_id")})
}()
//如果有则直接返回用户信息到微信小程序里
defer func() {
if userId != 0 {
user := that.Db.Get("user", "*", Map{"id": userId})
if user == nil {
that.Display(4, "获取个人信息失败")
return
}
delete(user, "password")
company := that.Db.Get("company", "id,name", Map{"id": user.GetCeilInt("company_id")})
salesman := that.Db.Get("salesman", "id,name", Map{"id": user.GetCeilInt("salesman_id")})
provider := that.Db.Get("provider", "id,name", Map{"id": user.GetCeilInt("provider_id")})
user["company"] = company
user["salesman"] = salesman
user["provider"] = provider
that.Display(0, user)
}
}()
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": userInfo.OpenID, "del_flag": 0}})
if wechat != nil {
//有用户直接返回
if wechat.GetCeilInt("user_id") != 0 {
that.Db.Update("user", Map{"login_time[#]": "now()"}, Map{"id": wechat.GetCeilInt("user_id")})
that.Session("wechat_id", wechat.GetCeilInt("id"))
that.Session("user_id", wechat.GetCeilInt("user_id"))
userId = wechat.GetCeilInt("user_id")
//that.Display(0, "登录成功")
return
}
//没有用户继续查询数据库看是否有其他unionid
wechat1 := that.Db.Get("wechat", "*", Map{"AND": Map{"unionid": userInfo.Unionid, "openid[!]": userInfo.OpenID, "user_id[>]": 0, "del_flag": 0}})
//其他表有该数据,则更新当前表数据信息
if wechat1 != nil {
wechatInfo["user_id"] = wechat1.GetCeilInt("user_id")
that.Db.Update("wechat", wechatInfo, Map{"id": wechat.GetCeilInt("id")})
that.Db.Update("user", Map{"login_time[#]": "now()"}, Map{"id": wechat1.GetCeilInt("user_id")})
that.Session("wechat_id", wechat.GetCeilInt("id"))
that.Session("user_id", wechatInfo.GetCeilInt("user_id"))
userId = wechatInfo.GetCeilInt("user_id")
//that.Display(0, "登录成功")
return
}
//其他表也没有当前信息则生成user表并更新当前用户,一般不会走到这里来
user := Map{
"nickname": wechatInfo.GetString("nickname"),
"avatar": wechatInfo.GetString("avatar"),
"index": ",",
"create_time[#]": "now()",
"modify_time[#]": "now()",
"login_time[#]": "now()",
"del_flag": 0,
}
user["id"] = that.Db.Insert("user", user)
//创建企业
user["company_id"] = that.Db.Insert("company", Map{
"user_id": user["id"],
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
that.Db.Update("user", Map{"company_id": user["company_id"]}, Map{"id": user["id"]})
wechatInfo["user_id"] = user.GetCeilInt("id")
that.Db.Update("wechat", wechatInfo, Map{"id": wechat.GetCeilInt("id")})
that.Session("wechat_id", wechat.GetCeilInt("id"))
that.Session("user_id", wechatInfo.GetCeilInt("user_id"))
userId = wechatInfo.GetCeilInt("user_id")
//that.Display(0, "登录成功")
return
}
user := Map{
"nickname": wechatInfo.GetString("nickname"),
"avatar": wechatInfo.GetString("avatar"),
"index": ",",
"create_time[#]": "now()",
"modify_time[#]": "now()",
"login_time[#]": "now()",
"del_flag": 0,
}
user["id"] = that.Db.Insert("user", user)
user["company_id"] = that.Db.Insert("company", Map{
"user_id": user["id"],
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
that.Db.Update("user", Map{"company_id": user["company_id"]}, Map{"id": user["id"]})
wechatInfo["user_id"] = user.GetCeilInt("id")
wechatInfo["id"] = that.Db.Insert("wechat", wechatInfo)
if wechatInfo.GetCeilInt("id") == 0 {
that.Display(4, "创建用户失败")
return
}
that.Session("wechat_id", wechatInfo.GetCeilInt("id"))
that.Session("user_id", wechatInfo.GetCeilInt("user_id"))
userId = wechatInfo.GetCeilInt("user_id")
//that.Display(0, "登录成功")
},
//网页签名
"sign": func(that *Context) {
signUrl := that.Req.FormValue("url")
if signUrl == "" {
that.Display(3, "参数不足")
return
}
cfg1, e := wechat.H5Program.GetSignUrl(signUrl)
if e != nil {
that.Display(4, e)
return
}
sign := Map{
"appId": cfg1.AppID,
"timestamp": cfg1.Timestamp,
"nonceStr": cfg1.NonceStr,
"signature": cfg1.Signature,
}
that.Display(0, sign)
},
}

167
example/app/wechatmini.go Normal file
View File

@ -0,0 +1,167 @@
package app
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"code.hoteas.com/golang/hotime/dri/wechat"
"fmt"
)
var WechatMini = Ctr{
"getphone": func(that *Context) {
//sessionKey := that.Req.FormValue("sessionkey")
if that.Session("wechat_id").Data == nil {
that.Display(2, "请先登录")
return
}
encryptedData := that.Req.FormValue("encryptedData")
iv := that.Req.FormValue("iv")
if encryptedData == "" || iv == "" {
that.Display(3, "参数不足")
return
}
wechatIns := that.Db.Get("wechat", "sessionkey", Map{"id": that.Session("wechat_id").ToCeilInt()})
_, re, e := wechat.MiniProgram.GetPhoneNumber(wechatIns.GetString("sessionkey"), encryptedData, iv)
if e != nil {
that.Display(4, e)
return
}
//临时存储用于校验
that.Session("wechat_phone", re.PhoneNumber)
that.Display(0, re.PhoneNumber)
},
//检查是否已经有用户登录了如果有直接登录如果没有则查询unionid有则直接返回用户信息没有则返回null
"code": func(that *Context) {
code := that.Req.FormValue("code")
if code == "" {
that.Display(3, "缺少code")
return
}
appid, re, e := wechat.MiniProgram.GetBaseUserInfo(code)
fmt.Println(re)
if e != nil {
that.Display(4, e)
return
}
wchat := Map{"openid": re.OpenID,
"appid": appid,
"sessionkey": re.SessionKey,
"unionid": re.UnionID,
"modify_time[#]": "now()",
"del_flag": 0,
"type": 2,
}
userId := 0
//如果有则直接返回用户信息到微信小程序里
defer func() {
if userId != 0 {
user := that.Db.Get("user", "*", Map{"id": userId})
company := that.Db.Get("company", "id,name", Map{"id": user.GetCeilInt("company_id")})
salesman := that.Db.Get("salesman", "id,name", Map{"id": user.GetCeilInt("salesman_id")})
provider := that.Db.Get("provider", "id,name", Map{"id": user.GetCeilInt("provider_id")})
if user == nil {
that.Display(4, "获取个人信息失败")
return
}
delete(user, "password")
user["company"] = company
user["salesman"] = salesman
user["provider"] = provider
that.Display(0, user)
}
}()
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": re.OpenID, "user_id[!]": nil, "del_flag": 0}})
//有该用户,则登录成功
if wechat != nil {
that.Session("wechat_id", wechat.GetCeilInt("id"))
that.Session("user_id", wechat.GetCeilInt("user_id"))
//更新用户信息
that.Db.Update("wechat", wchat, Map{"id": wechat.GetCeilInt("id")})
//that.Display(0, "登录成功")
userId = wechat.GetCeilInt("user_id")
return
}
//如果其他人有相关信息,则直接取用
wechat = that.Db.Get("wechat", "*", Map{"AND": Map{"unionid": re.UnionID, "user_id[!]": nil, "del_flag": 0}})
if wechat != nil {
wechat1 := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": re.OpenID, "del_flag": 0}})
//有该信息,但没有相关的用户信息,则直接绑定其他的信息上来
if wechat1 != nil {
//更新用户信息
that.Db.Update("wechat", wchat, Map{"id": wechat1.GetCeilInt("id")})
that.Session("wechat_id", wechat1.GetCeilInt("id"))
that.Session("user_id", wechat.GetCeilInt("user_id"))
//that.Display(0, "登录成功")
userId = wechat.GetCeilInt("user_id")
return
}
//没有相关用户信息则新建wechat并完成登录
wchat["user_id"] = wechat["user_id"]
wchat["create_time[#]"] = "now()"
wchat["id"] = that.Db.Insert("wechat", wchat)
if wchat.GetCeilInt("id") == 0 {
that.Display(5, "创建wechat失败")
return
}
that.Session("wechat_id", wchat.GetCeilInt("id"))
that.Session("user_id", wchat.GetCeilInt("user_id"))
userId = wchat.GetCeilInt("user_id")
//that.Display(0, "登录成功")
return
}
user := Map{
"create_time[#]": "now()",
"modify_time[#]": "now()",
"login_time[#]": "now()",
"del_flag": 0,
}
user["id"] = that.Db.Insert("user", user)
user["company_id"] = that.Db.Insert("company", Map{
"user_id": user["id"],
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
that.Db.Update("user", Map{"company_id": user["company_id"]}, Map{"id": user["id"]})
wchat["user_id"] = user.GetCeilInt("id")
wchat["create_time[#]"] = "now()"
wchat["id"] = that.Db.Insert("wechat", wchat)
if wchat.GetCeilInt("id") == 0 {
that.Display(5, "登录失败")
return
}
that.Session("wechat_id", wchat.GetCeilInt("id"))
that.Session("user_id", wchat.GetCeilInt("user_id"))
userId = wchat.GetCeilInt("user_id")
//that.Display(0, nil)
},
}

View File

@ -1,4 +1,5 @@
{ {
"aliyunCode": "06c6a07e89dd45c88de040ee1489eef7",
"avatarPath": "avatar/2006/01/02/", "avatarPath": "avatar/2006/01/02/",
"cache": { "cache": {
"db": { "db": {
@ -11,22 +12,21 @@
"timeout": 7200 "timeout": 7200
} }
}, },
"codeConfig": { "codeConfig": [
"admin": "config/app.json" {
}, "config": "config/admin.json",
"codeConfig1": { "mode": 0,
"admin": { "name": "",
"config": "config/app.json", "rule": "config/adminRule.json",
"package": "admin", "table": "admin"
"rule": "config/rule.json"
} }
}, ],
"crossDomain": "auto", "crossDomain": "",
"db": { "db": {
"mysql": { "mysql": {
"host": "192.168.6.253", "host": "192.168.2.50",
"name": "iedc_dev", "name": "zct_v2",
"password": "dasda8454456", "password": "kct@2021",
"port": "3306", "port": "3306",
"prefix": "", "prefix": "",
"user": "root" "user": "root"
@ -41,16 +41,24 @@
"2": "访问权限异常", "2": "访问权限异常",
"3": "请求参数异常", "3": "请求参数异常",
"4": "数据处理异常", "4": "数据处理异常",
"5": "数据结果异常" "5": "数据结果异常",
"6": "需要进一步获取个人信息"
}, },
"imgPath": "img/2006/01/02/", "imgPath": "img/2006/01/02/",
"mode": 3, "mode": 2,
"port": "8081", "port": "8081",
"sessionName": "HOTIME", "sessionName": "HOTIME",
"smsKey": "b0eb4bf0198b9983cffcb85b69fdf4fa", "smsKey": "b0eb4bf0198b9983cffcb85b69fdf4fa",
"smsLogin": "【政企超链接】您的验证码为:{code}请在5分钟内使用切勿将验证码泄露于他人如非本人操作请忽略。", "smsLogin": "【政策通】您的验证码为:{code}请在5分钟内使用切勿将验证码泄露于他人如非本人操作请忽略。",
"tpt": "tpt", "tpt": "tpt",
"wechatAppID": "wx2edb802f5c3ae1ae", "wechatAppID": "wxdcc8d6360661a179",
"wechatAppSecret": "4ff97e523c3de6bad47051b568522386", "wechatAppNotifyUrl": "https://zcth5.kct.cn/app/vip_order/callback",
"wechatAppSecret": "4d793683ca915264663a9c9a33530c3c",
"wechatMiniAppID": "wx1c795e883b5b54c4",
"wechatMiniAppSecret": "d2bec12d1fa4d8b5714ccbed1c0671e4",
"wechatPayMApiV3Key": "dh33tyagd1623623GDYGGDhe1d9dh171",
"wechatPayMCHID": "1624888906",
"wechatPayPrivateKey": "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC1vs3i/4sozxsK\noiS2S95rl+csLXQDugg23bcAVzXr7ZeTM/h81sCwraQDMnAJ/V3n7LxFAZeaFwLb\nyrkQ3lv4IEtWVgjVUkjkhvKGWcAp16Q/grOpxWmmn+VlW5ZGwQQ4DL4sC6BeEyxu\nUdtZ7UVc9lqsQX01R0oiegItJGPMMXNgeLFDEeoAwyIQcL0VG2bND7qrEVeQkLTj\nFm9ZkSb0LySPkSgqxMlSpiX1MS+wWWIHpq91CvdVHNowaGFA7ajU3RztbFAuxdpl\ng9RIocbrY1QwGXouQTEOUI2KZaES9rAa2lD6oWom4mRYiQ1oNO12XlUTcKsr84P5\nTq50dOYFAgMBAAECggEAQUns/mncnOlhhn1fANnaaf5kvlsJvTj8MHGPhyDNLxbo\nB6p4zqf7Cr0mGTvqQbxyGpnRvFxpEKLJlRmLSAMJOOapCbfYboGjy+yqfRcK0D02\nNNaIIinX3VK9fp7bKkm2cUgqnPoEPydWI79mNDTnYRDi29Se3R/iAuafl4XmD/js\nOKWG5tlXEatZ+gDbhnug4hp3xEGm4pbTS1HedV7HgYiKpxAT9uc/YmiHelZUUqlG\nwa1Nda2J88pzCSZX6TsRyY9UF/sjorxSNZGfj+5waeYMccj0Cx4uEQYgBv5tm+I+\nFTRgo/riM5gT9oRTnuNuzUrNwUNLyUsldvdQdlheNQKBgQDqwhrW52q3xClFLXR4\nHu9cTPt/p96MYE+xBllO/M9VFcG/hT++9R9l26+o26Lu+iIF5euDQiYSyURniGim\nWfV0I2q8HufhPLJBamvxRPI0V8LHwbY7c6HKnRR3eDAWAVYIcmsV4RLS67bsgtnr\nCgaFUDHXnpPKjxp1b4M5K3GqxwKBgQDGMLgAQn0a3nZwquPD4D+6tjy5xTxDX4Op\nULHBQheX0lBAR9Kcurzy4ca+T5xsyHd6SPwQxobRPei/3TBmc18J1T3nxJkTbEEP\nqy8k7MOWW2es3ou4CRL5lVKPx4YDWb5iT7X3Ue55JjPFAoj6FBOHxdvRQnDYsLFy\nSuSHPc280wKBgQCqfvCZNZcnAbtrd3jIKMd0hKB/dP7HesdF7TN9j1RRGi0NmIvU\ndxgnlOa9v05VO6rsF7D1MlyOdkhM3SAL+PewMmy5VcTYq4lWwyDEKGuzoi1fgIuG\nIBPYID8WCV77DFtcZSTqzf0q3HCM0vfLoQtdVQHt9Ein60ivE579LVUvTwKBgFid\nefgrwnJcG8serb5sKzKZvyc1CE/7igwPl5sYqSHqGJXVR1dqq4dR6iI3yHJfZASa\nU5JQogE21DXNeZGlbk4gOZDCt8sWcTTHTsoMzxsQfZeu3fwImqJb4NGG3eXrn5On\nnm4aBS3IJgelrYdbqKvhjPrQ4VISFxVKZUoPGUmfAoGARZbtbyl3s8cAExWe9dK6\nyWdkA3M2wR4n623W13rTQDc3D7p/hmlgB2x8it88m+580326G4qgwdUbG93EW1WQ\nahbkkcmdxzHgPVJdsyx22fR0TkeT1gjMpoSh4k3HOsbZE4EvlI459yE9fTSLBq2A\nFzGjYRpBTlRyrsSEhyVg4G0=\n-----END PRIVATE KEY-----",
"wechatPaySerialNo": "7A92D2D26D212D6BF934BDB10D547274807C3DDB",
"wxFilePath": "wxfile/2006/01/02/" "wxFilePath": "wxfile/2006/01/02/"
} }

View File

@ -20,10 +20,16 @@
}, },
"注释": "可配置memorydbredis默认启用memory默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致缓存数据填充会自动反方向反哺加入memory缓存过期将自动从redis更新但memory永远不会更新redis如果是集群建议不要开启memory配置即启用" "注释": "可配置memorydbredis默认启用memory默认优先级为memory\u003eredis\u003edb,memory与数据库缓存设置项一致缓存数据填充会自动反方向反哺加入memory缓存过期将自动从redis更新但memory永远不会更新redis如果是集群建议不要开启memory配置即启用"
}, },
"codeConfig": { "codeConfig": [
"packageName": "默认无必须包名称以及应用名生成代码的配置文件地址比如config/app.json数据库有更新时自动更新配置文件以及对应的生成文件", "注释:配置即启用,非必须,默认无",
"注释": "配置即启用,非必须,默认无" {
}, "config": "默认config/app.json必须接口描述配置文件",
"mode": "默认0非必须0为内嵌代码模式1为生成代码模式",
"name": "默认无非必须有则生成代码到此目录无则采用缺省模式使用表名如设置为admin将在admin目录生成包名为admin的代码",
"rule": "默认config/rule.json非必须有则按改规则生成接口无则按系统内嵌方式生成",
"table": "默认admin必须根据数据库内当前表名做为用户生成数据"
}
],
"crossDomain": "默认空 非必须空字符串为不开启如果需要跨域设置auto为智能开启所有网站允许跨域http://www.baidu.com为指定域允许跨域", "crossDomain": "默认空 非必须空字符串为不开启如果需要跨域设置auto为智能开启所有网站允许跨域http://www.baidu.com为指定域允许跨域",
"db": { "db": {
"mysql": { "mysql": {

Binary file not shown.

View File

@ -1,7 +1,13 @@
package main package main
import ( import (
"code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime"
"code.hoteas.com/golang/hotime/dri/aliyun"
"code.hoteas.com/golang/hotime/dri/ddsms"
"code.hoteas.com/golang/hotime/dri/wechat"
"code.hoteas.com/golang/hotime/example/app"
"code.hoteas.com/golang/hotime/example/provider"
//. "code.hoteas.com/golang/hotime/common"
"fmt" "fmt"
"time" "time"
) )
@ -11,6 +17,38 @@ func main() {
date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00") date, _ := time.Parse("2006-01-02 15:04", time.Now().Format("2006-01-02")+" 14:00")
fmt.Println(date, date.Unix()) fmt.Println(date, date.Unix())
//fmt.Println("0123456"[1:7]) //fmt.Println("0123456"[1:7])
appIns := hotime.Init("config/config.json") appIns := Init("config/config.json")
appIns.Run(hotime.Router{})
aliyun.Company.Init(appIns.Config.GetString("aliyunCode"))
//初始化短信配置
ddsms.DDY.Init(appIns.Config.GetString("smsKey"))
//初始化公众号配置
wechat.H5Program.Init(appIns.Config.GetString("wechatAppID"), appIns.Config.GetString("wechatAppSecret"))
//初始化小程序配置
wechat.MiniProgram.Init(appIns.Config.GetString("wechatMiniAppID"), appIns.Config.GetString("wechatMiniAppSecret"))
//初始化小程序及公众号支付配置
wechat.WxPay.Init(appIns.Config.GetString("wechatPayMCHID"),
appIns.Config.GetString("wechatPaySerialNo"),
appIns.Config.GetString("wechatPayMApiV3Key"),
appIns.Config.GetString("wechatPayPrivateKey"))
//用户侧访问前设置
appIns.SetConnectListener(func(that *Context) (isFinished bool) {
//发送短信校验
return isFinished
})
//appIns.SetConnectListener(func(that *Context) (isFinished bool) {
//
// return isFinished
//})
//appIns.Db.Action(func(db db.HoTimeDB) (isSuccess bool) {
// return isSuccess
//})
appIns.Run(Router{
"provider": provider.Project,
"app": app.Project,
})
} }

View File

@ -0,0 +1,80 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var CompanyCtr = Ctr{
"info": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("company", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到企业")
return
}
//先不做限制
//if res.GetCeilInt("salesman_id")!=that.Session("salesman_id").ToCeilInt(){
// that.Display(4,"不是你的企业")
// return
//}
res["technology_center_flag"] = ObjToSlice(res["technology_center_flag"])
res["engineering_center_flag"] = ObjToSlice(res["engineering_center_flag"])
res["engineering_laboratory_flag"] = ObjToSlice(res["engineering_laboratory_flag"])
res["key_laboratory_flag"] = ObjToSlice(res["key_laboratory_flag"])
res["industrial_design_center_flag"] = ObjToSlice(res["industrial_design_center_flag"])
that.Display(0, res)
},
"edit": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
company := that.Db.Get("company", "*", Map{"id": id})
delete(company, "id")
delete(company, "salesman_id")
delete(company, "provider_id")
delete(company, "user_id")
delete(company, "del_flag")
delete(company, "state")
delete(company, "create_time")
delete(company, "modify_time")
data := Map{}
for k, _ := range company {
if that.Req.Form[k] != nil {
if k == "technology_center_flag" || k == "engineering_center_flag" || k == "engineering_laboratory_flag" || k == "key_laboratory_flag" || k == "industrial_design_center_flag" {
data[k] = ObjToStr(that.Req.Form[k])
} else {
data[k] = that.Req.FormValue(k)
}
}
}
that.Db.Update("company", company, Map{"id": id})
that.Display(0, "更新成功")
},
}

113
example/provider/declare.go Normal file
View File

@ -0,0 +1,113 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var DeclareCtr = Ctr{
"info": func(that *Context) {
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("declare", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到通知公告")
return
}
res["click_num"] = res.GetCeilInt64("click_num") + res.GetCeilInt64("click_num_base") + 1
delete(res, "click_num_base")
res["favorite_num"] = res.GetCeilInt64("favorite_num") + res.GetCeilInt64("favorite_num_base")
delete(res, "favorite_num_base")
article := that.Db.Get("article", "*", Map{"id": res.GetCeilInt64("article_id")})
if article != nil {
article["click_num"] = article.GetCeilInt64("click_num") + article.GetCeilInt64("click_num_base") + 1
delete(article, "click_num_base")
article["favorite_num"] = article.GetCeilInt64("favorite_num") + article.GetCeilInt64("favorite_num_base")
delete(article, "favorite_num_base")
}
res["article"] = article
//浏览量加1
that.Db.Update("declare", Map{"click_num[#]": "click_num+1"}, Map{"id": id})
//浏览量加1
that.Db.Update("article", Map{"click_num[#]": "click_num+1"}, Map{"id": res.GetCeilInt64("article_id")})
//查询是否已关注
if that.Session("user_id").Data != nil {
favorite := that.Db.Get("favorite", "user_id,declare_id", Map{"AND": Map{"declare_id": id, "user_id": that.Session("user_id").ToCeilInt(), "del_flag": 0}})
res["favorite"] = favorite
}
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "declare_id[!]": nil}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["release_date[>=]"] = startTime
}
if finishTime != "" {
data["release_date[<=]"] = finishTime
}
dispatchName := that.Req.FormValue("dispatch_name")
if dispatchName != "" {
data["dispatch_name"] = dispatchName
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "release_time DESC"}
}
count := that.Db.Count("article", data)
res := that.Db.Page(page, pageSize).PageSelect("article", "id,title,description,department_id,click_num+click_num_base AS click_num,"+
"favorite_num_base+favorite_num AS favorite_num,dispatch_num,dispatch_name,prepare_date,release_time,expire_date,area_id,status,declare_id,declare_id,declare_id,dispatch_name,policy_level", data)
for _, v := range res {
//if v.GetCeilInt("declare_id")>0{
// v["declare"]=that.Db.Get("declare","id,tag",Map{"id":v.GetCeilInt("declare_id")})
//}
//if v.GetCeilInt("declare_id")>0{
// v["declare"]=that.Db.Get("declare","tag",Map{"id":v.GetCeilInt("declare_id")})
//}
if v.GetCeilInt("declare_id") > 0 {
v["declare"] = that.Db.Get("declare", "money_scope_min,money_scope_max,status", Map{"id": v.GetCeilInt("declare_id")})
}
}
that.Display(0, Map{"total": count, "data": res})
},
}

35
example/provider/init.go Normal file
View File

@ -0,0 +1,35 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
)
// Project 管理端项目
var Project = Proj{
"company": CompanyCtr,
"declare": DeclareCtr,
"matters": MattersCtr,
"order": OrderCtr,
"salesman": Salesman,
"sms": Sms,
"tag": TagCtr,
"user": UserCtr,
"wechat": Wechat,
}
//生成随机码的6位md5
func getSn() string {
x := Rand(8)
return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6)
}
//生成随机码的4位随机数
func getCode() string {
//res := ""
//for i := 0; i < 4; i++ {
res := ObjToStr(RandX(1000, 9999))
//}
return res
}

108
example/provider/matters.go Normal file
View File

@ -0,0 +1,108 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var MattersCtr = Ctr{
"info": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
res := that.Db.Get("matters", "*", Map{"id": id})
if res == nil {
that.Display(4, "找不到事项")
return
}
if res.GetCeilInt("salesman_id") != that.Session("salesman_id").ToCeilInt() {
that.Display(4, "不是你的事项")
return
}
res["user"] = that.Db.Get("user", "id,name,nickname,company_id", Map{"user_id": res.GetCeilInt64("user_id")})
if res.GetMap("user") != nil && res.GetMap("user").GetCeilInt64("company_id") != 0 {
res["company"] = that.Db.Get("company", "id,name", Map{"company_id": res.GetMap("user").GetCeilInt64("company_id")})
}
that.Display(0, res)
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
userId := ObjToInt(that.Req.FormValue("id"))
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
tp := that.Req.FormValue("type")
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "salesman_id": that.Session("salesman_id").Data}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"title[~]": keywords, "description[~]": keywords, "content[~]": keywords}
}
if userId != 0 {
user := that.Db.Get("user", "id", Map{"AND": Map{"id": userId, "salesman_id": that.Session("salesman_id").Data}})
if user != nil {
data["user_id"] = userId
}
}
if tp != "" {
data["type"] = ObjToInt("tp")
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modify_time[>=]"] = startTime
}
if finishTime != "" {
data["modify_time[<=]"] = finishTime
}
if len(data) > 1 {
data = Map{"AND": data}
}
count := that.Db.Count("matters", data)
res := that.Db.Page(page, pageSize).PageSelect("matters", "*", data)
for _, v := range res {
if v.GetCeilInt64("user_id") != 0 {
v["user"] = that.Db.Get("user", "id,avatar,name,nickname,company_id", Map{"id": v.GetCeilInt64("user_id")})
if v.GetMap("user") != nil && v.GetMap("user").GetCeilInt64("company_id") != 0 {
v["company"] = that.Db.Get("company", "id,name", Map{"id": v.GetMap("user").GetCeilInt64("company_id")})
}
}
}
that.Display(0, Map{"total": count, "data": res})
},
}

239
example/provider/order.go Normal file
View File

@ -0,0 +1,239 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var OrderCtr = Ctr{
"info": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
res := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}})
if res == nil {
that.Display(4, "找不到对应订单")
return
}
//if res.GetCeilInt("salesman_id") != that.Session("salesman_id").ToCeilInt() {
// that.Display(4, "不是你的订单")
// return
//}
if res.GetCeilInt("user_id") > 0 {
res["user"] = that.Db.Get("user", "name,nickname,avatar", Map{"id": res.GetCeilInt("user_id")})
}
res["order_record"] = that.Db.Select("order_record", "remarks,modify_time", Map{"order_id": res.GetCeilInt("id"), "ORDER": "modify_time DESC"})
that.Display(0, res)
},
"create_order_record": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
remarks := that.Req.FormValue("remarks")
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
order := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}})
if order == nil {
that.Display(4, "不是属于你的订单")
return
}
if order.GetCeilInt("status") != 0 {
that.Display(4, "已完结订单,不可操作")
return
}
orderRecordId := that.Db.Insert("order_record", Map{
"order_id": id,
"user_id": order.GetCeilInt64("user_id"),
"remarks": salesman.GetString("name") + ":" + remarks,
"salesman_id": order.GetCeilInt64("salesman_id"),
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
that.Db.Update("order", Map{"order_record_id": orderRecordId}, Map{"id": id})
that.Display(0, "新增订单记录成功")
},
"edit": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
id := ObjToInt(that.Req.FormValue("id"))
if id == 0 {
that.Display(3, "请求参数异常")
return
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
policyDeclareFlag := ObjToInt(that.Req.FormValue("policy_declare_flag"))
declareId := ObjToInt(that.Req.FormValue("declare_id"))
intellectualPropertyFlag := ObjToInt(that.Req.FormValue("intellectual_property_flag"))
intellectualPropertyCount := ObjToInt(that.Req.FormValue("intellectual_property_count"))
taxOnsultingFlag := ObjToInt(that.Req.FormValue("tax_onsulting_flag"))
lawFlag := ObjToInt(that.Req.FormValue("law_flag"))
status := ObjToInt(that.Req.FormValue("status"))
data := Map{
"policy_declare_flag": policyDeclareFlag,
"intellectual_property_flag": intellectualPropertyFlag,
"intellectual_property_count": intellectualPropertyCount,
"tax_onsulting_flag": taxOnsultingFlag,
"law_flag": lawFlag,
"status": status,
"modify_time[#]": "now()",
}
if declareId != 0 {
data["declare_id"] = declareId
}
order := that.Db.Get("order", "*", Map{"AND": Map{"id": id, "provider_id": salesman.GetCeilInt64("provider_id")}})
if order == nil {
that.Display(4, "不是属于你的订单")
return
}
if order.GetCeilInt("status") != 0 {
that.Display(4, "已完结订单,不可操作")
return
}
data["order_record_id"] = that.Db.Insert("order_record", Map{
"order_id": id,
"user_id": order.GetCeilInt64("user_id"),
"remarks": salesman.GetString("name") + "变更了订单服务内容",
"salesman_id": order.GetCeilInt64("salesman_id"),
"create_time[#]": "now()",
"modify_time[#]": "now()",
"del_flag": 0,
})
re := that.Db.Update("order", data, Map{"id": id})
if re == 0 {
that.Display(4, "变更订单内容失败")
return
}
that.Display(0, "变更订单内容成功")
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
userId := ObjToInt(that.Req.FormValue("id"))
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(2, "登录错误")
return
}
data := Map{"del_flag": 0, "provider_id": salesman.GetCeilInt64("provider_id")}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"sn[~]": keywords, "name[~]": keywords}
}
if userId != 0 {
user := that.Db.Get("user", "id", Map{"AND": Map{"id": userId, "salesman_id": that.Session("salesman_id").Data}})
if user != nil {
data["user_id"] = userId
}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modify_time[>=]"] = startTime
}
if finishTime != "" {
data["modify_time[<=]"] = finishTime
}
if len(data) > 1 {
data = Map{"AND": data}
}
count := that.Db.Count("order", data)
res := that.Db.Page(page, pageSize).PageSelect("order", "*", data)
for _, v := range res {
//if v.GetCeilInt("policy_id")>0{
// v["policy"]=that.Db.Get("policy","id,tag",Map{"id":v.GetCeilInt("policy_id")})
//}
if v.GetCeilInt("user_id") > 0 {
v["user"] = that.Db.Get("user", "name,nickname,avatar", Map{"id": v.GetCeilInt("user_id")})
}
if v.GetCeilInt("order_record_id") > 0 {
v["order_record"] = that.Db.Get("order_record", "remarks,modify_time", Map{"id": v.GetCeilInt("order_record_id")})
}
}
that.Display(0, Map{"total": count, "data": res})
},
}

View File

@ -0,0 +1,132 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var Salesman = Ctr{
"test": func(that *Context) {
that.Session("salesman_id", 1)
that.Session("wechat_id", 1)
that.Display(0, 1)
},
"info": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(4, "找不到该业务员")
return
}
salesman["user"] = that.Db.Count("user", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}})
salesman["matters"] = that.Db.Count("matters", Map{"AND": Map{"salesman_id": that.Session("salesman_id").Data, "del_flag": 0}})
salesman["admin"] = that.Db.Get("admin", "id,name,avatar", Map{"id": salesman.GetCeilInt64("admin_id")})
salesman["provider"] = that.Db.Get("provider", "*", Map{"id": salesman.GetCeilInt64("provider_id")})
if salesman["provider"] != nil {
salesman["provider_salesman"] = that.Db.Get("salesman", "id,nickname,name,avatar", Map{"id": salesman.GetMap("provider").GetCeilInt64("salesman_id")})
}
that.Display(0, salesman)
},
"search": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
salesman := that.Db.Get("salesman", "*", Map{"id": that.Session("salesman_id").Data})
if salesman == nil {
that.Display(4, "找不到该业务员")
return
}
provider := that.Db.Get("provider", "*", Map{"id": salesman.GetCeilInt64("provider_id")})
if provider.GetCeilInt("salesman_id") != salesman.GetCeilInt("id") {
that.Display(0, Slice{})
return
}
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 20
}
data := Map{"del_flag": 0, "provider_id": salesman.GetCeilInt64("provider_id")}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"name[~]": keywords, "nickname[~]": keywords, "phone[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modifye_time[>=]"] = startTime
}
if finishTime != "" {
data["modifye_time[<=]"] = finishTime
}
count := that.Db.Count("salesman", data)
res := that.Db.Page(page, pageSize).PageSelect("salesman", "id,name,nickname,avatar", data)
that.Display(0, Map{"total": count, "data": res})
},
//用户微信公众号或者小程序登录
"login": func(that *Context) {
code := that.Req.FormValue("code")
phone := that.Req.FormValue("phone")
if phone != that.Session("phone").ToStr() && code == that.Session("code").ToStr() {
that.Display(3, "手机号或者验证码错误")
return
}
if that.Session("wechat_id").Data == nil {
that.Display(2, "还未登录")
return
}
wechat := that.Db.Get("wechat", "*", Map{"id": that.Session("wechat_id").ToCeilInt()})
salesman := that.Db.Get("salesman", "*", Map{"phone": phone})
if salesman == nil {
that.Display(3, "找不到企服商")
return
}
if wechat == nil {
that.Display(2, "还未绑定微信")
return
}
//有用户直接返回
if wechat.GetCeilInt("salesman_id") != 0 && wechat.GetCeilInt64("salesman_id") != salesman.GetInt64("id") {
that.Display(5, "你已经绑定了其他商户")
return
}
that.Db.Update("wechat", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": wechat.GetInt64("id")})
wechat["salesman_id"] = salesman.GetCeilInt64("id")
that.Session("salesman_id", salesman.GetCeilInt64("id"))
that.Display(0, "登录成功!")
},
}

31
example/provider/sms.go Normal file
View File

@ -0,0 +1,31 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
"code.hoteas.com/golang/hotime/dri/ddsms"
)
var Sms = Ctr{
//只允许微信验证过的或者登录成功的发送短信
"send": func(that *Context) {
phone := that.Req.FormValue("phone")
if len(phone) < 11 {
that.Display(3, "手机号格式错误")
return
}
if that.Session("wechat_id").Data == nil && that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录不可发送短信")
return
}
code := getCode()
that.Session("phone", phone)
that.Session("code", code)
ddsms.DDY.SendYZM(phone, that.Config.GetString("smsLogin"), map[string]string{"code": code})
that.Display(0, "发送成功")
},
}

83
example/provider/tag.go Normal file
View File

@ -0,0 +1,83 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
)
var TagCtr = Ctr{
"create": func(that *Context) {
if that.Session("user_id").Data == nil {
that.Display(2, "没有登录")
return
}
name := that.Req.FormValue("name")
oldTag := that.Db.Get("tag", "id", Map{"name": name})
if oldTag != nil {
that.Display(4, "此标签已存在")
return
}
re := that.Db.Insert("tag", Map{
"user_id": that.Session("user_id").Data,
"name": name,
"remark": "用户上传",
"create_time[#]": "now()",
"modify_time[#]": "now()",
"state": 1, //先置为异常状态,等待审核通过
"del_flag": 0,
})
if re == 0 {
that.Display(4, "添加失败")
return
}
that.Display(0, "添加成功")
return
},
//用户微信公众号或者小程序登录
"search": func(that *Context) {
page := ObjToInt(that.Req.FormValue("page"))
pageSize := ObjToInt(that.Req.FormValue("pageSize"))
if page < 1 {
page = 1
}
if pageSize <= 0 {
pageSize = 40
}
data := Map{"del_flag": 0, "state": 0}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"name[~]": keywords, "remark[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modify_time[>=]"] = startTime
}
if finishTime != "" {
data["modify_time[<=]"] = finishTime
}
if len(data) > 1 {
data = Map{"AND": data}
}
count := that.Db.Count("tag", data)
res := that.Db.Page(page, pageSize).PageSelect("tag", "id,name,remark", data)
that.Display(0, Map{"total": count, "data": res})
},
}

150
example/provider/user.go Normal file
View File

@ -0,0 +1,150 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
)
var UserCtr = Ctr{
//用户微信公众号或者小程序登录
"info": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
userId := ObjToInt(that.Req.FormValue("id"))
if userId == 0 {
that.Display(3, "参数错误")
return
}
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()})
if user == nil {
that.Display(4, "获取个人信息失败")
return
}
delete(user, "password")
that.Display(0, user)
},
"edit": func(that *Context) {
if that.Session("salesman_id").Data == nil {
that.Display(2, "没有登录")
return
}
userId := ObjToInt(that.Req.FormValue("id"))
if userId == 0 {
that.Display(3, "参数错误")
return
}
name := that.Req.FormValue("name")
nickname := that.Req.FormValue("nickname")
sex := that.Req.FormValue("sex")
email := that.Req.FormValue("email")
avatar := that.Req.FormValue("avatar")
address := that.Req.FormValue("address")
phone := that.Req.FormValue("phone") //如果更换手机号则要有新的短信验证码
data := Map{"modify_time[#]": "now()"}
if name != "" {
data["name"] = name
}
if nickname != "" {
data["nickname"] = nickname
}
if sex != "" {
data["sex"] = sex
}
if email != "" {
data["email"] = email
}
if avatar != "" {
data["avatar"] = avatar
}
if address != "" {
data["address"] = address
}
if phone != "" {
data["phone"] = phone
}
re := that.Db.Update("user", data, Map{"id": userId})
if re == 0 {
that.Display(4, "更新失败")
return
}
that.Display(4, "修改成功")
},
"search": func(that *Context) {
if that.Session("salesman_id").Data == nil {
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
}
tp := ObjToInt(that.Req.FormValue("type")) //0无操作1已扫码未认证2已认证3VIP会员
data := Map{"del_flag": 0, "salesman_id": that.Session("salesman_id").Data}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"name[~]": keywords, "nickname[~]": keywords, "phone[~]": keywords}
}
startTime := that.Req.FormValue("starttime")
finishTime := that.Req.FormValue("finishtime")
if startTime != "" {
data["modifye_time[>=]"] = startTime
}
if finishTime != "" {
data["modifye_time[<=]"] = finishTime
}
if tp == 1 {
data["certification_flag"] = 0
}
if tp == 2 {
data["certification_flag"] = 1
data["OR"] = Map{"expiration_time": nil, "expiration_time[#]": "now()"}
}
if tp == 3 {
data["certification_flag"] = 1
data["expiration_time[>]"] = time.Now().Format("2006-01-02 15:04:05")
}
if len(data) > 1 {
data = Map{"AND": data, "ORDER": "modify_time DESC"}
}
count := that.Db.Count("user", data)
res := that.Db.Page(page, pageSize).PageSelect("user", "*", data)
for _, v := range res {
delete(v, "password")
}
that.Display(0, Map{"total": count, "data": res})
},
}

View File

@ -0,0 +1,95 @@
package provider
import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"code.hoteas.com/golang/hotime/dri/wechat"
)
var Wechat = Ctr{
////微信注册
"code": func(that *Context) {
if that.Req.FormValue("code") == "" {
that.Display(3, "参数不足")
return
}
appid, resToken, userInfo, err := wechat.H5Program.GetUserInfo(that.Req.FormValue("code"))
if err != nil {
that.Display(4, err)
return
}
//此次获取的微信信息
wechatInfo := Map{
"openid": userInfo.OpenID,
"acttoken": resToken.AccessToken,
"retoken": resToken.RefreshToken,
"appid": appid,
"unionid": userInfo.Unionid,
"nickname": userInfo.Nickname,
"avatar": userInfo.HeadImgURL,
//"create_time[#]":"now()",
"modify_time[#]": "now()",
"del_flag": 0,
"type": 1,
}
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": userInfo.OpenID, "del_flag": 0}})
if wechat != nil {
//有用户直接返回
if wechat.GetCeilInt("salesman_id") != 0 {
that.Session("salesman_id", wechat.GetCeilInt("salesman_id"))
that.Display(0, "登录成功")
return
}
that.Session("wechat_id", wechat.GetCeilInt("id"))
that.Display(2, "暂未绑定")
return
}
wechatInfo["create_time[#]"] = "now()"
wechatInfo["id"] = that.Db.Insert("wechat", wechatInfo)
if wechatInfo.GetCeilInt("id") == 0 {
that.Display(4, "创建用户失败")
return
}
that.Session("wechat_id", wechatInfo.GetCeilInt("id"))
that.Display(2, "暂未绑定")
},
//网页签名
"sign": func(that *Context) {
signUrl := that.Req.FormValue("url")
if signUrl == "" {
that.Display(3, "参数不足")
return
}
cfg1, e := wechat.H5Program.GetSignUrl(signUrl)
if e != nil {
that.Display(4, e)
return
}
sign := Map{
"appId": cfg1.AppID,
"timestamp": cfg1.Timestamp,
"nonceStr": cfg1.NonceStr,
"signature": cfg1.Signature,
}
that.Display(0, sign)
},
}

2
go.mod
View File

@ -4,8 +4,10 @@ go 1.16
require ( require (
github.com/garyburd/redigo v1.6.3 github.com/garyburd/redigo v1.6.3
github.com/go-pay/gopay v1.5.78
github.com/go-sql-driver/mysql v1.6.0 github.com/go-sql-driver/mysql v1.6.0
github.com/mattn/go-sqlite3 v1.14.12 github.com/mattn/go-sqlite3 v1.14.12
github.com/silenceper/wechat/v2 v2.1.2
github.com/sirupsen/logrus v1.8.1 github.com/sirupsen/logrus v1.8.1
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364 github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364

47
go.sum
View File

@ -1,27 +1,72 @@
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b h1:L/QXpzIa3pOvUGt1D1lA5KjYhPBAN/3iWdP7xeFS9F0=
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b/go.mod h1:H0wQNHz2YrLsuXOZozoeDmnHXkNCRmMW0gwFWDfEZDA=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc= github.com/garyburd/redigo v1.6.3 h1:HCeeRluvAgMusMomi1+6Y5dmFOdYV/JzoRrrbFlkGIc=
github.com/garyburd/redigo v1.6.3/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw= github.com/garyburd/redigo v1.6.3/go.mod h1:rTb6epsqigu3kYKBnaF028A7Tf/Aw5s0cqA47doKKqw=
github.com/go-pay/gopay v1.5.78 h1:wIHp8g/jK0ik5bZo2MWt3jAQsktT3nkdXZxlRZvljko=
github.com/go-pay/gopay v1.5.78/go.mod h1:M6Nlk2VdZHCbWphOw3rtbnz4SiOk6Xvxg6mxwDfg+Ps=
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/gomodule/redigo v1.8.5 h1:nRAxCa+SVsyjSBrtZmG/cqb6VbTmuRzpg/PoTFlpumc=
github.com/gomodule/redigo v1.8.5/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0= github.com/mattn/go-sqlite3 v1.14.12 h1:TJ1bhYJPV44phC+IMu1u2K/i5RriLTPe+yc68XDJ1Z0=
github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= github.com/mattn/go-sqlite3 v1.14.12/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/silenceper/wechat/v2 v2.1.2 h1:+QfIMiYfwST2ZloTwmYp0O0p5Y1LYRZxfLWfMuSE30k=
github.com/silenceper/wechat/v2 v2.1.2/go.mod h1:0OprxYCCp2CZAKw06BBlnaczInTk2KxOLsKeiopshGg=
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w= github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
github.com/spf13/cast v1.3.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364 h1:X1Jws4XqrTH+p7FBQ7BpjW4qFXObKHWm0/XhW/GvqRs= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364 h1:X1Jws4XqrTH+p7FBQ7BpjW4qFXObKHWm0/XhW/GvqRs=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common v1.0.364/go.mod h1:7sCQWVkxcsR38nffDW057DRGk8mUjK1Ing/EFOK8s8Y=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364 h1:kbor60vo37v7Hu+i17gooox9Rw281fVHNna8zwtDG1w= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364 h1:kbor60vo37v7Hu+i17gooox9Rw281fVHNna8zwtDG1w=
github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364/go.mod h1:LeIUBOLhc+Y5YCEpZrULPD9lgoXXV4/EmIcoEvmHz9c= github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/ocr v1.0.364/go.mod h1:LeIUBOLhc+Y5YCEpZrULPD9lgoXXV4/EmIcoEvmHz9c=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29 h1:tkVvjkPTB7pnW3jnid7kNyAMPVWllTNOf/qKDze4p9o=
golang.org/x/crypto v0.0.0-20220331220935-ae2d96664a29/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc= golang.org/x/net v0.0.0-20220225172249-27dd8689420f h1:oA4XRj0qtSt8Yo1Zms0CUlsT3KG69V2UGQWPBxujDmc=
golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e h1:fLOSk5Q00efkSvAm+4xcoXD+RRmLmmulPn5I3Y9F2EM=
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/h2non/gock.v1 v1.0.15 h1:SzLqcIlb/fDfg7UvukMpNcWsu7sI5tWwL+KCATZqks0=
gopkg.in/h2non/gock.v1 v1.0.15/go.mod h1:sX4zAkdYX1TRGJ2JY156cFspQn4yRWn6p9EMdODlynE=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

39
var.go
View File

@ -10,15 +10,17 @@ var App = map[string]*Application{} //整个项目
//var Db = HoTimeDB{} //数据库实例 //var Db = HoTimeDB{} //数据库实例
var Config = Map{ var Config = Map{
"mode": 3, //模式 0生产模式1测试模式2开发模式,3内嵌代码模式 "mode": 2, //模式 0生产模式1测试模式2开发模式
"codeConfig": Map{ //"codeConfig": Map{
"admin": "config/app.json", // "admin": "config/app.json",
}, //},
"codeConfig1": Map{ "codeConfig": Slice{
"admin": Map{ //默认无,必须,接口类别名称 Map{
"package": "admin", //默认admin非必须有则生成代码到此目录无则采用缺省模式不生成代码只生成接口 "table": "admin", //默认admin必须有则根据数据库内当前表名做为用户生成数据
"name": "", //默认admin非必须有则生成代码到此目录无则采用缺省模式使用表名
"config": "config/app.json", //默认config/app.json必须接口描述配置文件 "config": "config/app.json", //默认config/app.json必须接口描述配置文件
"rule": "config/rule.json", //默认config/rule.json非必须有则按改规则生成接口无则按系统内嵌方式生成 "rule": "config/rule.json", //默认config/rule.json非必须有则按改规则生成接口无则按系统内嵌方式生成
"mode": 0, //默认0非必须0为内嵌代码模式1为生成代码模式
}, },
}, },
"db": Map{ "db": Map{
@ -52,12 +54,23 @@ var ConfigNote = Map{
"webConnectLogShow": "默认true非必须访问日志如果需要web访问链接、访问ip、访问时间打印false为关闭true开启此功能", "webConnectLogShow": "默认true非必须访问日志如果需要web访问链接、访问ip、访问时间打印false为关闭true开启此功能",
"webConnectLogFile": "无默认非必须webConnectLogShow开启之后才能使用如果需要存储日志文件时使用保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置", "webConnectLogFile": "无默认非必须webConnectLogShow开启之后才能使用如果需要存储日志文件时使用保存格式为:a/b/c/20060102150405.txt,将生成a/b/c/年月日时分秒.txt按需设置",
"mode": "默认0,非必须0生产模式1测试模式2开发模式3内嵌代码模式在开发模式下会显示更多的数据用于开发测试并能够辅助研发自动生成配置文件、代码等功能,web无缓存数据库不启用缓存", //debug 0关闭1开启 "mode": "默认0,非必须0生产模式1测试模式2开发模式3内嵌代码模式在开发模式下会显示更多的数据用于开发测试并能够辅助研发自动生成配置文件、代码等功能,web无缓存数据库不启用缓存", //debug 0关闭1开启
"codeConfig": Map{ //"codeConfig": Map{
"注释": "配置即启用,非必须,默认无", // "注释": "配置即启用,非必须,默认无",
//"package":"默认admin必须mode模式为2时会自动生成包文件夹和代码文件", // //"package":"默认admin必须mode模式为2时会自动生成包文件夹和代码文件",
//"path":"" // //"path":""
//
"packageName": "默认无必须包名称以及应用名生成代码的配置文件地址比如config/app.json数据库有更新时自动更新配置文件以及对应的生成文件", // "packageName": "默认无必须包名称以及应用名生成代码的配置文件地址比如config/app.json数据库有更新时自动更新配置文件以及对应的生成文件",
//},
"codeConfig": Slice{
"注释:配置即启用,非必须,默认无",
Map{ //默认无,必须,接口类别名称
//"注释": "", //
"table": "默认admin必须根据数据库内当前表名做为用户生成数据",
"name": "默认无非必须有则生成代码到此目录无则采用缺省模式使用表名如设置为admin将在admin目录生成包名为admin的代码",
"config": "默认config/app.json必须接口描述配置文件", //
"rule": "默认config/rule.json非必须有则按改规则生成接口无则按系统内嵌方式生成",
"mode": "默认0非必须0为内嵌代码模式1为生成代码模式",
},
}, },
"db": Map{ "db": Map{
"注释": "配置即启用非必须默认使用sqlite数据库", "注释": "配置即启用非必须默认使用sqlite数据库",