From 3b2a317d2be3c5dd9267c45b8009e5308d7fb716 Mon Sep 17 00:00:00 2001
From: hoteas <等>
Date: Thu, 5 May 2022 16:07:01 +0800
Subject: [PATCH 1/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0U=E7=9B=98=E7=99=BB?=
=?UTF-8?q?=E5=BD=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/app/AES.go | 106 +++++++++++++++++++++++++++++++++++
example/app/declare.go | 16 +++---
example/app/init.go | 14 +++++
example/app/upan.go | 84 +++++++++++++++++++++++++++
example/app/vip_order.go | 4 +-
example/app/wechath5.go | 2 +-
example/provider/init.go | 13 +++++
example/provider/salesman.go | 9 +++
example/provider/wechat.go | 2 +-
example/tpt/pc.html | 32 +++++++++++
10 files changed, 270 insertions(+), 12 deletions(-)
create mode 100644 example/app/AES.go
create mode 100644 example/app/upan.go
create mode 100644 example/tpt/pc.html
diff --git a/example/app/AES.go b/example/app/AES.go
new file mode 100644
index 0000000..72b8510
--- /dev/null
+++ b/example/app/AES.go
@@ -0,0 +1,106 @@
+package app
+
+import (
+ "bytes"
+ "crypto/aes"
+ "crypto/cipher"
+ "encoding/base64"
+ "errors"
+)
+
+//高级加密标准(Adevanced Encryption Standard ,AES)
+
+//16,24,32位字符串的话,分别对应AES-128,AES-192,AES-256 加密方法
+//key不能泄露
+var PwdKey = []byte("mif022h3g9geAHUHY432,:da1adag389")
+
+//PKCS7 填充模式
+func pKCS7Padding(ciphertext []byte, blockSize int) []byte {
+ padding := blockSize - len(ciphertext)%blockSize
+ //Repeat()函数的功能是把切片[]byte{byte(padding)}复制padding个,然后合并成新的字节切片返回
+ padtext := bytes.Repeat([]byte{byte(padding)}, padding)
+ return append(ciphertext, padtext...)
+}
+
+//填充的反向操作,删除填充字符串
+func pKCS7UnPadding(origData []byte) ([]byte, error) {
+ //获取数据长度
+ length := len(origData)
+ if length == 0 {
+ return nil, errors.New("加密字符串错误!")
+ } else {
+ //获取填充字符串长度
+ unpadding := int(origData[length-1])
+ //截取切片,删除填充字节,并且返回明文
+ return origData[:(length - unpadding)], nil
+ }
+}
+
+//实现加密
+func AesEcrypt(origData []byte, key []byte) ([]byte, error) {
+ //创建加密算法实例
+ block, err := aes.NewCipher(key)
+ if err != nil {
+ return nil, err
+ }
+ //获取块的大小
+ blockSize := block.BlockSize()
+ //对数据进行填充,让数据长度满足需求
+ origData = pKCS7Padding(origData, blockSize)
+ //采用AES加密方法中CBC加密模式
+ blocMode := cipher.NewCBCEncrypter(block, key[:blockSize])
+ crypted := make([]byte, len(origData))
+ //执行加密
+ blocMode.CryptBlocks(crypted, origData)
+ return crypted, nil
+}
+
+//实现解密
+func AesDeCrypt(cypted []byte, key []byte) ([]byte, error) {
+ //创建加密算法实例
+ block, err := aes.NewCipher(key)
+ if err != nil {
+ return nil, err
+ }
+ //获取块大小
+ blockSize := block.BlockSize()
+ //创建加密客户端实例
+ blockMode := cipher.NewCBCDecrypter(block, key[:blockSize])
+ origData := make([]byte, len(cypted))
+ //这个函数也可以用来解密
+ blockMode.CryptBlocks(origData, cypted)
+ //去除填充字符串
+ origData, err = pKCS7UnPadding(origData)
+ if err != nil {
+ return nil, err
+ }
+ return origData, err
+}
+
+//加密base64
+func EnPwdCode(pwd []byte) (string, error) {
+ result, err := AesEcrypt(pwd, PwdKey)
+ if err != nil {
+ return "", err
+ }
+ return base64.StdEncoding.EncodeToString(result), err
+}
+
+//解密
+func DePwdCode(pwd string) ([]byte, error) {
+ //解密base64字符串
+ pwdByte, err := base64.StdEncoding.DecodeString(pwd)
+ if err != nil {
+ return nil, err
+ }
+ //执行AES解密
+ return AesDeCrypt(pwdByte, PwdKey)
+
+}
+
+//func main() {
+// str := []byte("12fff我是ww.topgoer.com的站长枯藤")
+// pwd, _ := EnPwdCode(str)
+// bytes, _ := DePwdCode(pwd)
+// fmt.Println(string(bytes))
+//}
diff --git a/example/app/declare.go b/example/app/declare.go
index 5730008..d151ee5 100644
--- a/example/app/declare.go
+++ b/example/app/declare.go
@@ -388,15 +388,15 @@ var DeclareCtr = Ctr{
res = append(res, article)
}
- minMoney := 0
- maxMoney := 0
+ minMoney := float64(0)
+ maxMoney := float64(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").GetFloat64("money_scope_min") < minMoney {
+ minMoney = v.GetMap("declare").GetFloat64("money_scope_min")
}
- if v.GetMap("declare").GetInt("money_scope_max") > maxMoney {
- maxMoney = v.GetMap("declare").GetInt("money_scope_max")
+ if v.GetMap("declare").GetFloat64("money_scope_max") > maxMoney {
+ maxMoney = v.GetMap("declare").GetFloat64("money_scope_max")
}
}
}
@@ -410,11 +410,11 @@ var DeclareCtr = Ctr{
"del_flag": 0,
}
if maxMoney != minMoney {
- seData["money_scope"] = ObjToStr(minMoney) + "-" + ObjToStr(maxMoney) + "万元"
+ seData["money_scope"] = ObjToStr(ObjToInt(minMoney)) + "-" + ObjToStr(ObjToInt(maxMoney)) + ""
} else if maxMoney == 0 {
seData["money_scope"] = ""
} else {
- seData["money_scope"] = ObjToStr(maxMoney) + "万元"
+ seData["money_scope"] = ObjToStr(ObjToInt(maxMoney)) + ""
}
//匹配记录存储
diff --git a/example/app/init.go b/example/app/init.go
index 3f996be..19c5f70 100644
--- a/example/app/init.go
+++ b/example/app/init.go
@@ -5,6 +5,7 @@ import (
. "code.hoteas.com/golang/hotime/common"
"errors"
"time"
+ "unicode/utf8"
)
// Project 管理端项目
@@ -22,6 +23,7 @@ var Project = Proj{
"search_record": SearchRecordCtr,
"sms": Sms,
"tag": TagCtr,
+ "upan": UpanCtr,
"user": UserCtr,
"vip_order": VipOrderCtr,
"websocket": WebsocketCtr,
@@ -109,3 +111,15 @@ func auth(that *Context, phone, companyName string) error {
return nil
}
+
+// FilterEmoji 过滤 emoji 表情
+func FilterEmoji(content string) string {
+ new_content := ""
+ for _, value := range content {
+ _, size := utf8.DecodeRuneInString(string(value))
+ if size <= 3 {
+ new_content += string(value)
+ }
+ }
+ return new_content
+}
diff --git a/example/app/upan.go b/example/app/upan.go
new file mode 100644
index 0000000..182340e
--- /dev/null
+++ b/example/app/upan.go
@@ -0,0 +1,84 @@
+package app
+
+import (
+ . "code.hoteas.com/golang/hotime"
+ "code.hoteas.com/golang/hotime/common"
+ "fmt"
+ "strings"
+)
+
+var UpanCtr = Ctr{
+ "login": func(that *Context) {
+ timestamp := that.Req.FormValue("timestamp")
+ sn := that.Req.FormValue("sn")
+
+ //str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))//
+ re, e := DePwdCode(sn)
+
+ if e != nil {
+ that.Display(3, "数据异常")
+ return
+ }
+ reStr := string(re)
+ realSn := strings.Replace(reStr, ":"+timestamp, "", -1)
+ if len(realSn)+len(timestamp)+1 != len(reStr) {
+ that.Display(4, "数据验证失败")
+ return
+ }
+ fmt.Println("U盘校验", realSn)
+ user := that.Db.Get("user", "*", common.Map{"upankey": realSn})
+ if user == nil {
+ that.Display(5, "还没有绑定用户")
+ return
+ }
+
+ that.Session("user_id", user.GetCeilInt("id"))
+ that.Display(0, "登录成功")
+ },
+
+ "create": func(that *Context) {
+ timestamp := that.Req.FormValue("timestamp")
+ sn := that.Req.FormValue("sn")
+
+ //str,_:=EnPwdCode([]byte(lus[len(lus)-1]+":"+ObjToStr(t)))//
+ re, e := DePwdCode(sn)
+
+ if e != nil {
+ that.Display(3, "数据异常")
+ return
+ }
+ reStr := string(re)
+ realSn := strings.Replace(reStr, ":"+timestamp, "", -1)
+ if len(realSn)+len(timestamp)+1 != len(reStr) {
+ that.Display(4, "数据验证失败")
+ return
+ }
+
+ fmt.Println("U盘校验", realSn)
+
+ uuser := that.Db.Get("user", "id", common.Map{"upankey": realSn})
+
+ if uuser != nil {
+ that.Display(4, "已经绑定了其他企业")
+ return
+ }
+
+ phone := that.Req.FormValue("phone")
+ companyName := that.Req.FormValue("company_name")
+ //验证不成功则反馈
+ err := auth(that, phone, companyName)
+ if err != nil {
+ fmt.Println(err)
+ that.Display(3, err.Error())
+ return
+ }
+
+ num := that.Db.Update("user", common.Map{"upankey": realSn}, common.Map{"id": that.Session("user_id").Data})
+ if num == 0 {
+ that.Display(4, "更新失败")
+ return
+ }
+ that.Display(0, "绑定成功")
+
+ },
+}
diff --git a/example/app/vip_order.go b/example/app/vip_order.go
index 9eed5d7..17ee5aa 100644
--- a/example/app/vip_order.go
+++ b/example/app/vip_order.go
@@ -46,7 +46,7 @@ var VipOrderCtr = Ctr{
data := Map{
"sn": "SN" + time.Now().Format("20060102150405") + getSn(),
//"name":"1年VIP会员",
- "amount": 72000, //720元
+ "amount": 36000, //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"),
@@ -73,7 +73,7 @@ var VipOrderCtr = Ctr{
data["amount"] = 36000
//tp=tp
}
- data["amount"] = 1
+ //data["amount"] = 1
if user.GetCeilInt("salesman_id") != 0 {
data["salesman_id"] = user.GetCeilInt("salesman_id")
diff --git a/example/app/wechath5.go b/example/app/wechath5.go
index 9afaab7..2e2fa08 100644
--- a/example/app/wechath5.go
+++ b/example/app/wechath5.go
@@ -29,7 +29,7 @@ var Wechath5 = Ctr{
"retoken": resToken.RefreshToken,
"appid": appid,
"unionid": userInfo.Unionid,
- "nickname": userInfo.Nickname,
+ "nickname": FilterEmoji(userInfo.Nickname),
"avatar": userInfo.HeadImgURL,
"create_time[#]": "now()",
"modify_time[#]": "now()",
diff --git a/example/provider/init.go b/example/provider/init.go
index c859752..d735eae 100644
--- a/example/provider/init.go
+++ b/example/provider/init.go
@@ -4,6 +4,7 @@ import (
. "code.hoteas.com/golang/hotime"
. "code.hoteas.com/golang/hotime/common"
"time"
+ "unicode/utf8"
)
// Project 管理端项目
@@ -33,3 +34,15 @@ func getCode() string {
//}
return res
}
+
+// 过滤 emoji 表情
+func FilterEmoji(content string) string {
+ new_content := ""
+ for _, value := range content {
+ _, size := utf8.DecodeRuneInString(string(value))
+ if size <= 3 {
+ new_content += string(value)
+ }
+ }
+ return new_content
+}
diff --git a/example/provider/salesman.go b/example/provider/salesman.go
index e325acc..b0f41fd 100644
--- a/example/provider/salesman.go
+++ b/example/provider/salesman.go
@@ -22,6 +22,15 @@ var Salesman = Ctr{
that.Display(4, "找不到该业务员")
return
}
+
+ if salesman.GetString("nickname") == "" {
+ wechat := that.Db.Get("wechat", "*", Map{"salesman_id": salesman.GetCeilInt64("id")})
+ if wechat != nil {
+ salesman["nickname"] = wechat.GetString("nickname")
+ salesman["avatar"] = wechat.GetString("avatar")
+ that.Db.Update("salesman", Map{"nickname": wechat.GetString("nickname"), "avatar": wechat.GetString("avatar")}, Map{"id": salesman.GetCeilInt64("id")})
+ }
+ }
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}})
diff --git a/example/provider/wechat.go b/example/provider/wechat.go
index 21c5638..2d1b9ee 100644
--- a/example/provider/wechat.go
+++ b/example/provider/wechat.go
@@ -29,7 +29,7 @@ var Wechat = Ctr{
"retoken": resToken.RefreshToken,
"appid": appid,
"unionid": userInfo.Unionid,
- "nickname": userInfo.Nickname,
+ "nickname": FilterEmoji(userInfo.Nickname),
"avatar": userInfo.HeadImgURL,
//"create_time[#]":"now()",
"modify_time[#]": "now()",
diff --git a/example/tpt/pc.html b/example/tpt/pc.html
new file mode 100644
index 0000000..e4cd5a2
--- /dev/null
+++ b/example/tpt/pc.html
@@ -0,0 +1,32 @@
+
+
+
+
+ 微信登录
+
+
+
+
+
+
From 22d00739ff3f8dd988c2bb7221be367de54552cb Mon Sep 17 00:00:00 2001
From: hoteas <等>
Date: Thu, 5 May 2022 18:33:27 +0800
Subject: [PATCH 2/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0join=E7=9A=84orm=E5=85=BC?=
=?UTF-8?q?=E5=AE=B9=E6=80=A7?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
db/hotimedb.go | 8 ++++----
example/app/declare.go | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/db/hotimedb.go b/db/hotimedb.go
index c93eb61..442e36d 100644
--- a/db/hotimedb.go
+++ b/db/hotimedb.go
@@ -460,15 +460,15 @@ func (that *HoTimeDB) Select(table string, qu ...interface{}) []Map {
v := testQuData[k]
switch Substr(k, 0, 3) {
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)
case "[<]":
- query += " RIGHT JOIN " + Substr(k, 3, len(k)-3) + " ON " + v.(string)
+ query += " RIGHT JOIN `" + Substr(k, 3, len(k)-3) + "` ON " + v.(string)
}
switch Substr(k, 0, 4) {
case "[<>]":
- query += " FULL JOIN " + Substr(k, 4, len(k)-4) + " ON " + v.(string)
+ query += " FULL JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
case "[><]":
- query += " INNER JOIN " + Substr(k, 4, len(k)-4) + " ON " + v.(string)
+ query += " INNER JOIN `" + Substr(k, 4, len(k)-4) + "` ON " + v.(string)
}
}
}
diff --git a/example/app/declare.go b/example/app/declare.go
index d151ee5..2382d5f 100644
--- a/example/app/declare.go
+++ b/example/app/declare.go
@@ -139,7 +139,7 @@ var DeclareCtr = Ctr{
//标签分析
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}})
+ 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
From 8cf54ce25b8317727897647d821d6a145d38fbf4 Mon Sep 17 00:00:00 2001
From: hoteas <等>
Date: Fri, 6 May 2022 11:35:40 +0800
Subject: [PATCH 3/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=99=90=E5=88=B6?=
=?UTF-8?q?=E6=9D=A1=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)
From 9ba182d65c5b035617b1d10e6b5e4be5ae1a0f22 Mon Sep 17 00:00:00 2001
From: hoteas <等>
Date: Fri, 6 May 2022 13:08:13 +0800
Subject: [PATCH 4/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=99=90=E5=88=B6?=
=?UTF-8?q?=E6=9D=A1=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
code.go | 4 +++-
example/app/AES.go | 14 +++++++++++++-
example/app/upan.go | 1 +
3 files changed, 17 insertions(+), 2 deletions(-)
diff --git a/code.go b/code.go
index bbdbce1..2e9134b 100644
--- a/code.go
+++ b/code.go
@@ -44,7 +44,9 @@ var TptProject = Proj{
}
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})
}
}
diff --git a/example/app/AES.go b/example/app/AES.go
index 72b8510..a90b7eb 100644
--- a/example/app/AES.go
+++ b/example/app/AES.go
@@ -2,10 +2,12 @@ package app
import (
"bytes"
+ "code.hoteas.com/golang/hotime/common"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"errors"
+ "fmt"
)
//高级加密标准(Adevanced Encryption Standard ,AES)
@@ -56,12 +58,21 @@ func AesEcrypt(origData []byte, key []byte) ([]byte, error) {
}
//实现解密
-func AesDeCrypt(cypted []byte, key []byte) ([]byte, error) {
+func AesDeCrypt(cypted []byte, key []byte) (bytes []byte, err error) {
+ //异常处理
+ defer func() {
+ if e := recover(); e != nil {
+ //that.SetError(errors.New(fmt.Sprint(err)), LOG_FMT)
+ fmt.Println(err)
+ err = errors.New(common.ObjToStr(e))
+ }
+ }()
//创建加密算法实例
block, err := aes.NewCipher(key)
if err != nil {
return nil, err
}
+
//获取块大小
blockSize := block.BlockSize()
//创建加密客户端实例
@@ -91,6 +102,7 @@ func DePwdCode(pwd string) ([]byte, error) {
//解密base64字符串
pwdByte, err := base64.StdEncoding.DecodeString(pwd)
if err != nil {
+ fmt.Println(err)
return nil, err
}
//执行AES解密
diff --git a/example/app/upan.go b/example/app/upan.go
index 76ea011..beb1d93 100644
--- a/example/app/upan.go
+++ b/example/app/upan.go
@@ -44,6 +44,7 @@ var UpanCtr = Ctr{
re, e := DePwdCode(sn)
if e != nil {
+ fmt.Println(e)
that.Display(3, "数据异常")
return
}
From 918b88332b1d1ced7561a14a7ee7862dc59b8070 Mon Sep 17 00:00:00 2001
From: hoteas <等>
Date: Sat, 7 May 2022 11:02:12 +0800
Subject: [PATCH 5/7] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E9=99=90=E5=88=B6?=
=?UTF-8?q?=E6=9D=A1=E4=BB=B6?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
code/config.go | 1 +
code/makecode.go | 9 +++++++--
example/app/init.go | 1 +
example/app/user.go | 11 +++++++++++
example/app/wechath5.go | 2 ++
5 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/code/config.go b/code/config.go
index efc3ff9..96d6a40 100644
--- a/code/config.go
+++ b/code/config.go
@@ -64,6 +64,7 @@ var ColumnNameType = []ColumnShow{
{"idcard", false, true, true, false, "", false},
{"id", true, false, true, false, "", true},
{"parent_id", true, true, true, false, "", true},
+ {"amount", true, true, true, false, "money", true},
{"content", false, false, false, false, "textArea", false},
{"info", false, true, true, false, "textArea", false},
//"sn"{true,true,true,""},
diff --git a/code/makecode.go b/code/makecode.go
index 8537282..fdda12b 100644
--- a/code/makecode.go
+++ b/code/makecode.go
@@ -786,11 +786,16 @@ func (that *MakeCode) Search(table string, userData Map, req *http.Request, db *
v.GetString("link") + "." + v.GetString("value") + " AS " +
v.GetString("link") + "_" + v.GetString("name") + "_" + v.GetString("value") + ","
+ if v.GetString("value") == "name" && that.TableColumns[v.GetString("link")]["nickname"] != nil {
+ reStr += v.GetString("link") + ".nickname AS " +
+ v.GetString("link") + "_" + v.GetString("name") + "_nickname,"
+ }
+
if that.TableColumns[v.GetString("link")]["phone"] != nil {
- reStr += table + "." + v.GetString("name") + "," +
- v.GetString("link") + ".phone AS " +
+ reStr += v.GetString("link") + ".phone AS " +
v.GetString("link") + "_" + v.GetString("name") + "_phone,"
}
+
leftJoin["[>]"+v.GetString("link")] =
table + "." + v.GetString("name") + "=" +
v.GetString("link") + ".id"
diff --git a/example/app/init.go b/example/app/init.go
index 945f996..a03dbc6 100644
--- a/example/app/init.go
+++ b/example/app/init.go
@@ -54,6 +54,7 @@ func auth(that *Context, phone, companyName, userName string) error {
return errors.New("找不到用户")
}
company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")})
+
if company == nil {
return errors.New("找不到企业")
}
diff --git a/example/app/user.go b/example/app/user.go
index e437b99..0358952 100644
--- a/example/app/user.go
+++ b/example/app/user.go
@@ -24,6 +24,17 @@ var UserCtr = Ctr{
return
}
+ if user.GetCeilInt("company_id") == 0 {
+ companyId := that.Db.Insert("company", Map{
+ "user_id": user["id"],
+ "create_time[#]": "now()",
+ "modify_time[#]": "now()",
+ "del_flag": 0,
+ })
+ user["company_id"] = companyId
+ that.Db.Update("user", Map{"company_id": companyId}, Map{"id": user.GetCeilInt("id")})
+ }
+
delete(user, "password")
company := that.Db.Get("company", "id,name", Map{"id": user.GetCeilInt("company_id")})
diff --git a/example/app/wechath5.go b/example/app/wechath5.go
index 2e2fa08..98805ab 100644
--- a/example/app/wechath5.go
+++ b/example/app/wechath5.go
@@ -39,6 +39,7 @@ var Wechath5 = Ctr{
userId := 0
defer func() {
+
//有sn就关联业务员
parentId := ObjToInt(that.Req.FormValue("parent_id"))
if parentId == 0 {
@@ -83,6 +84,7 @@ var Wechath5 = Ctr{
if user == nil {
return
}
+
//用户都有企服人员关联
if user.GetCeilInt("salesman_id") != 0 {
From 3754734130de434d4c0fa4a42384036449267f3b Mon Sep 17 00:00:00 2001
From: hoteas <等>
Date: Sat, 7 May 2022 11:08:11 +0800
Subject: [PATCH 6/7] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E5=A2=9E=E5=8A=A0state?=
=?UTF-8?q?=E4=B8=BA1=E4=BC=81=E6=9C=8D=E5=95=86=E5=88=97=E8=A1=A8?=
=?UTF-8?q?=E4=B8=8D=E6=98=BE=E7=A4=BA=E4=BC=81=E4=B8=9A?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/app/provider.go | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/example/app/provider.go b/example/app/provider.go
index 911d7b5..85e8abb 100644
--- a/example/app/provider.go
+++ b/example/app/provider.go
@@ -47,7 +47,7 @@ var ProviderCtr = Ctr{
pageSize = 20
}
- data := Map{"del_flag": 0}
+ data := Map{"del_flag": 0, "state": 0}
keywords := that.Req.FormValue("keywords")
if keywords != "" {
data["OR"] = Map{"name[~]": keywords, "title[~]": keywords}
From b48ad793da305402255350db0e092a03578ae0b6 Mon Sep 17 00:00:00 2001
From: hoteas <等>
Date: Sat, 7 May 2022 13:55:57 +0800
Subject: [PATCH 7/7] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E4=BC=81=E6=9C=8D?=
=?UTF-8?q?=E5=95=86=E9=82=A3=E8=BE=B9=E4=B8=8D=E6=98=BE=E7=A4=BA=E5=90=8D?=
=?UTF-8?q?=E7=A7=B0=E9=97=AE=E9=A2=98?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
example/provider/matters.go | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/example/provider/matters.go b/example/provider/matters.go
index 735cdd3..d6df3d4 100644
--- a/example/provider/matters.go
+++ b/example/provider/matters.go
@@ -30,9 +30,9 @@ var MattersCtr = Ctr{
return
}
- res["user"] = that.Db.Get("user", "id,name,nickname,company_id", Map{"user_id": res.GetCeilInt64("user_id")})
+ res["user"] = that.Db.Get("user", "id,name,nickname,company_id", Map{"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")})
+ res["company"] = that.Db.Get("company", "id,name", Map{"id": res.GetMap("user").GetCeilInt64("company_id")})
}
that.Display(0, res)
},