From 8cf54ce25b8317727897647d821d6a145d38fbf4 Mon Sep 17 00:00:00 2001 From: hoteas <等> Date: Fri, 6 May 2022 11:35:40 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=99=90=E5=88=B6=E6=9D=A1?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code.go | 51 +++++++++++++++++++++------------------- code/makecode.go | 43 +++++++++++++++++++++++---------- example/app/init.go | 15 +++++++----- example/app/order.go | 5 ++-- example/app/upan.go | 8 ++++++- example/app/vip_order.go | 6 +++-- example/provider/sms.go | 7 ++++++ 7 files changed, 87 insertions(+), 48 deletions(-) diff --git a/code.go b/code.go index f2be290..bbdbce1 100644 --- a/code.go +++ b/code.go @@ -38,31 +38,33 @@ var TptProject = Proj{ } if (column["list"] == nil || column.GetBool("list")) && column.GetString("link") != "" { - seStr:="id,"+column.GetString("value") - if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"]!=nil{ - seStr=seStr+",phone" + 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) + 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 { + if re["table"] != nil && re["table_id"] != nil { column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][re.GetString("table")] - v:=re.GetCeilInt64("table_id") + v := re.GetCeilInt64("table_id") - seStr:="id,"+column.GetString("value") + seStr := "id," + column.GetString("value") - if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"]!=nil{ - seStr=seStr+",phone" + if that.MakeCodeRouter[hotimeName].TableColumns[column.GetString("link")]["phone"] != nil { + seStr = seStr + ",phone" } - link:=strings.Replace(column.GetString("name"),"_id","",-1) - + link := strings.Replace(column.GetString("name"), "_id", "", -1) + if link == "parent" { + link = that.RouterString[1] + } re[link] = that.Db.Get(column.GetString("link"), seStr, Map{"id": v}) } @@ -70,12 +72,12 @@ var TptProject = Proj{ that.Display(0, re) }, "add": func(that *Context) { - that.Log=Map{"table":that.RouterString[1],"type":1} + 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) + inData := that.MakeCodeRouter[hotimeName].Add(that.RouterString[1], data, that.Req) if inData == nil { that.Display(3, "请求参数不足") return @@ -96,17 +98,16 @@ var TptProject = Proj{ inData["index"] = "," + ObjToStr(re) + "," that.Db.Update(that.RouterString[1], Map{"index": inData["index"]}, Map{"id": re}) } - that.Log["table_id"]=re + that.Log["table_id"] = re that.Display(0, re) }, "update": func(that *Context) { - that.Log=Map{"table":that.RouterString[1],"type":2,"table_id":that.RouterString[2]} + 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 { that.Display(3, "没有找到要更新的数据") return @@ -141,7 +142,7 @@ var TptProject = Proj{ that.Display(0, re) }, "remove": func(that *Context) { - that.Log=Map{"table":that.RouterString[1],"type":3,"table_id":that.RouterString[2]} + 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 { @@ -188,26 +189,28 @@ var TptProject = Proj{ for _, v := range reData { v.RangeSort(func(k string, v1 interface{}) (isEnd bool) { - //如果有table字段则代为link - if v["table"]!=nil&&v["table_id"]!=nil { - id:=v.GetCeilInt64("table_id") + //如果有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) + 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") + v["table_table_id_name"] = parentC.GetString("name") } } column := that.MakeCodeRouter[hotimeName].TableColumns[that.RouterString[1]][k] + if column == nil { - return true + return isEnd } - if column["list"] != false && column["name"] == "parent_id" && column.GetString("link") != "" { + if (column["list"] == nil || column["list"] == true) && column["name"] == "parent_id" && column.GetString("link") != "" { parentC := that.Db.Get(column.GetString("link"), column.GetString("value"), Map{"id": v.GetCeilInt(k)}) v[column.GetString("link")+"_"+column.GetString("name")+"_"+column.GetString("value")] = "" diff --git a/code/makecode.go b/code/makecode.go index 7bbcb9e..8537282 100644 --- a/code/makecode.go +++ b/code/makecode.go @@ -598,7 +598,7 @@ func (that *MakeCode) Info(table string, userData Map, db *db.HoTimeDB) (string, //初始化ruleData if ruleData == nil { ruleData = Map{} - for _, v := range that.TableColumns["admin"] { + for _, v := range that.TableColumns[that.FileConfig.GetString("table")] { if v.GetString("link") != "" && v.GetString("name") != "parent_id" && userData.Get(v.GetString("name")) != nil { @@ -814,7 +814,7 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db * //初始化ruleData if ruleData == nil { ruleData = Map{} - for _, v := range that.TableColumns["admin"] { + for _, v := range that.TableColumns[that.FileConfig.GetString("table")] { if v.GetString("link") != "" && v.GetString("name") != "parent_id" && userData.Get(v.GetString("name")) != nil { @@ -885,14 +885,31 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db * continue } //日期类型 - if searchItemName == "daterange" && v.GetString("type") == "time" { - //fmt.Println(req.Form["daterange"]) - if len(req.Form["daterange"]) == 1 { - daterange[table+"."+v.GetString("name")+"[<]"] = req.FormValue("daterange") - } else { + if searchItemName == "daterange" { + if v.GetString("type") == "unixtime" { + //fmt.Println(req.Form["daterange"]) + if len(req.Form["daterange"]) == 1 { + daterange[table+"."+v.GetString("name")+"[<]"] = req.FormValue("daterange") + } else if len(req.Form["daterange"]) == 2 { - daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"]) + daterange[table+"."+v.GetString("name")+"[<>]"] = ObjToSlice(req.Form["daterange"]) + } } + if v.GetString("type") == "time" { + //fmt.Println(req.Form["daterange"]) + + if len(req.Form["daterange"]) == 1 { + t := time.Unix(ObjToCeilInt64(req.FormValue("daterange")), 0).Format("2006-01-02 15:04:05") + + daterange[table+"."+v.GetString("name")+"[<]"] = t + + } else if len(req.Form["daterange"]) == 2 { + t1 := time.Unix(ObjToCeilInt64(req.Form["daterange"][0]), 0).Format("2006-01-02 15:04:05") + t2 := time.Unix(ObjToCeilInt64(req.Form["daterange"][1]), 0).Format("2006-01-02 15:04:05") + daterange[table+"."+v.GetString("name")+"[<>]"] = Slice{t1, t2} + } + } + } } @@ -944,11 +961,11 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db * } if len(daterange) > 1 { - //if data["AND"] == nil { - data = Map{"AND": Map{"AND": data, "OR": daterange}} - //}else{ - // data = Map{"AND": Map{"AND": data, "OR": daterange}} - //} + if data == nil || len(data) == 0 { + data = Map{"OR": daterange} + } else { + data = Map{"AND": Map{"AND": data, "OR": daterange}} + } } if len(data) > 1 { diff --git a/example/app/init.go b/example/app/init.go index 19c5f70..945f996 100644 --- a/example/app/init.go +++ b/example/app/init.go @@ -47,15 +47,18 @@ func getCode() string { } //认证公共方案 -func auth(that *Context, phone, companyName string) error { +func auth(that *Context, phone, companyName, userName string) error { - user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id", Map{"id": that.Session("user_id").ToCeilInt()}) + user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id,name", Map{"id": that.Session("user_id").ToCeilInt()}) if user == nil { return errors.New("找不到用户") } - + company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")}) + if company == nil { + return errors.New("找不到企业") + } //手机号与原来的不同则进行绑定 - if phone != user.GetString("phone") { + if phone != user.GetString("phone") || companyName != company.GetString("name") || user.GetString("name") != userName { //微信验证成功 if that.Session("wechat_phone").ToStr() == phone { that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")}) @@ -67,7 +70,7 @@ func auth(that *Context, phone, companyName string) error { return errors.New("验证码错误") } else { - that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")}) + that.Db.Update("user", Map{"phone": phone, "name": userName}, Map{"id": user.GetCeilInt("id")}) if user.GetCeilInt("company_id") != 0 { that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")}) } @@ -76,7 +79,7 @@ func auth(that *Context, phone, companyName string) error { } // - company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")}) + //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 { diff --git a/example/app/order.go b/example/app/order.go index dff0d06..1a05c74 100644 --- a/example/app/order.go +++ b/example/app/order.go @@ -17,12 +17,13 @@ var OrderCtr = Ctr{ 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 { + userName := that.Req.FormValue("user_name") + if providerId == 0 || len(phone) != 11 || len(companyName) < 4 || len(userName) < 2 { that.Display(3, "请求参数异常") return } - err := auth(that, phone, companyName) + err := auth(that, phone, companyName, userName) if err != nil { that.Display(3, err.Error()) return diff --git a/example/app/upan.go b/example/app/upan.go index 182340e..76ea011 100644 --- a/example/app/upan.go +++ b/example/app/upan.go @@ -65,8 +65,14 @@ var UpanCtr = Ctr{ phone := that.Req.FormValue("phone") companyName := that.Req.FormValue("company_name") + userName := that.Req.FormValue("user_name") + + if len(phone) != 11 || len(companyName) < 4 || len(userName) < 2 { + that.Display(3, "请求参数异常") + return + } //验证不成功则反馈 - err := auth(that, phone, companyName) + err := auth(that, phone, companyName, userName) if err != nil { fmt.Println(err) that.Display(3, err.Error()) diff --git a/example/app/vip_order.go b/example/app/vip_order.go index 17ee5aa..c41a5fb 100644 --- a/example/app/vip_order.go +++ b/example/app/vip_order.go @@ -18,7 +18,8 @@ var VipOrderCtr = Ctr{ phone := that.Req.FormValue("phone") companyName := that.Req.FormValue("company_name") - if len(phone) != 11 || len(companyName) < 4 { + userName := that.Req.FormValue("user_name") + if len(phone) != 11 || len(companyName) < 4 || len(userName) < 2 { that.Display(3, "请求参数异常") return } @@ -37,7 +38,8 @@ var VipOrderCtr = Ctr{ return } - err := auth(that, phone, companyName) + err := auth(that, phone, companyName, userName) + if err != nil { that.Display(3, err.Error()) return diff --git a/example/provider/sms.go b/example/provider/sms.go index 0c93247..233d055 100644 --- a/example/provider/sms.go +++ b/example/provider/sms.go @@ -2,6 +2,7 @@ package provider import ( . "code.hoteas.com/golang/hotime" + "code.hoteas.com/golang/hotime/common" "code.hoteas.com/golang/hotime/dri/ddsms" ) @@ -20,6 +21,12 @@ var Sms = Ctr{ return } + salesman := that.Db.Get("salesman", "id", common.Map{"phone": phone}) + if salesman == nil { + that.Display(3, "你还不是企服人员,请联系管理员") + return + } + code := getCode() that.Session("phone", phone) that.Session("code", code)