政企超链接开始集成

This commit is contained in:
hoteas
2022-03-03 21:23:57 +08:00
parent e4ef9230c2
commit cac0214271
97 changed files with 379 additions and 117 deletions
+19
View File
@@ -0,0 +1,19 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
//"strings"
)
var Category = Ctr{
//获取列表
"list": func(this *Context) {
re := this.Db.Select("category", "*", Map{"parent_id": 1})
this.Display(0, re)
},
}
+2
View File
@@ -24,6 +24,8 @@ var Project = Proj{
"user": User,
"wechat": Wechat,
"question": Question,
"category": Category,
"sms": Sms,
}
var weixin *wechat.Wechat //微信登录实例
//var appIns = Application{}
+33
View File
@@ -0,0 +1,33 @@
package app
import (
. "../../../hotime"
"../../dri/ddsms"
)
var Sms = Ctr{
//只允许微信验证过的或者登录成功的发送短信
"send": func(this *Context) {
//if this.Session("uid").Data == nil && this.Session("wechatInfo").Data == nil {
// this.Display(2, "没有授权")
// return
//}
//if len(this.Req.FormValue("token")) != 32 {
// this.Display(2, "没有授权")
// return
//}
phone := this.Req.FormValue("phone")
if len(phone) < 11 {
this.Display(3, "手机号格式错误")
return
}
code := getCode()
this.Session("phone", phone)
this.Session("code", code)
ddsms.DefaultDDY.SendYZM(phone, this.Config.GetString("smsLogin"), map[string]string{"code": code})
this.Display(0, "发送成功")
},
}
+131 -85
View File
@@ -4,7 +4,9 @@ import (
. "../../../hotime"
. "../../../hotime/common"
"../../../hotime/dri/download"
"../../../hotime/dri/tencent"
"encoding/base64"
"fmt"
"io/ioutil"
"os"
"strings"
@@ -13,27 +15,40 @@ import (
)
var User = Ctr{
"token": func(this *Context) {
this.Display(0, this.SessionId)
},
"test": func(this *Context) {
this.Session("uid", 1)
fmt.Println(this.SessionId)
//this.Session("user_id", 1)
wechat := this.Db.Get("wechat", "*")
this.Session("wechatInfo", wechat)
this.Display(0, "开始测试")
},
//获取个人信息
"info": func(this *Context) {
//this.Session("user_id", 1)
//wechat:=this.Db.Get("wechat","*")
//this.Session("wechatInfo",wechat)
if this.Session("user_id").Data == nil {
this.Display(2, "还没有登录")
return
}
if this.Session("user_id").Data == nil {
if this.Session("wechatInfo").Data != nil {
this.Display(6, "需要认证")
return
}
this.Display(2, "还没有登录")
return
}
user := this.Db.Get("user", "*", Map{"id": this.Session("user_id").Data})
if user == nil {
fmt.Println(this.Session("user_id").Data, ":fsdfsd")
this.Display(4, "找不到该用户")
return
}
org := this.Db.Get("org", "contact", Map{"id": user.GetCeilInt("org_id")})
user["org"] = org
company := this.Db.Get("company", "id,name,status", Map{"id": user.GetCeilInt("company_id")})
user["company"] = company
@@ -77,48 +92,70 @@ var User = Ctr{
//身份认证
"auth": func(this *Context) {
//if this.Session("wechatInfo").Data == nil {
// this.Display(2, "尚未登录")
wechat := this.Session("wechatInfo").ToMap()
if wechat == nil {
if this.Session("user_id").Data == nil {
this.Display(6, "还没有登录")
return
}
wechat := this.Db.Get("wechat", "*", Map{"user_id": this.Session("user_id").ToCeilInt()})
if wechat == nil {
this.Display(6, "没有微信登录")
return
}
}
if this.Session("code").Data == nil {
this.Display(8, "验证码没有获取")
return
}
//orgId := ObjToInt(this.Req.FormValue("org_id"))
////questionCompanyId:=ObjToInt(this.Req.FormValue("id"))
//if orgId == 0 {
// this.Display(3, "没有选择组织")
// return
//}
//if this.Session("code").Data == nil {
// this.Display(8, "验证码没有获取")
// return
//}
orgId := ObjToInt(this.Req.FormValue("org_id"))
//questionCompanyId:=ObjToInt(this.Req.FormValue("id"))
if orgId == 0 {
this.Display(3, "没有选择组织")
return
}
name := this.Req.FormValue("name")
phone := this.Req.FormValue("phone")
idcard := this.Req.FormValue("idcard")
idcardFrontImg := this.Req.FormValue("idcard_front_img")
idcardBackImg := this.Req.FormValue("idcard_back_img")
code := this.Req.FormValue("code")
authImg := this.Req.FormValue("auth_img")
categoryId := ObjToInt(this.Req.FormValue("category_id"))
companyImg := this.Req.FormValue("company_img")
companyName := this.Req.FormValue("company_name")
companySn := this.Req.FormValue("company_sn")
if name == "" || phone == "" || idcard == "" || idcardFrontImg == "" || idcardBackImg == "" || companyImg == "" || companyName == "" || companySn == "" {
if code != this.Session("code").ToStr() {
this.Display(8, "验证码错误")
return
}
if name == "" || phone == "" || authImg == "" || categoryId == 0 || companyImg == "" || companyName == "" || companySn == "" {
this.Display(3, "参数异常")
return
}
t := time.Now().Unix()
orgId := wechat.GetInt("org_id")
company := this.Db.Get("company", "id", Map{"sn": companySn})
if company == nil {
company = Map{
"name": companyName,
"sn": companySn,
"create_time": t,
"org_id": orgId,
"category_id": categoryId,
//"org_id": orgId,
"modify_time": t,
"status": 1,
"state": 0,
"img": companyImg,
}
if wechat.GetInt("status") == 0 && orgId != 0 {
company["org_id"] = orgId
}
company["id"] = this.Db.Insert("company", company)
@@ -130,9 +167,11 @@ var User = Ctr{
company["status"] = 1
company["modify_time"] = t
company["img"] = companyImg
company["org_id"] = orgId
company["name"] = companyName
//company["img"] = companyImg
company["img"] = companyImg
if wechat.GetInt("status") == 0 && orgId != 0 {
company["org_id"] = orgId
}
re := this.Db.Update("company", company, Map{"id": company.GetCeilInt("id")})
if re == 0 {
this.Display(4, "无法更新企业")
@@ -140,18 +179,21 @@ var User = Ctr{
}
}
userInfo := this.Session("wechatInfo").ToMap()
user := this.Db.Get("user", "*", Map{"phone": phone})
data := Map{"name": name,
"phone": phone,
"org_id": orgId,
"idcard": idcard,
"idcard_front_img": idcardFrontImg,
"company_id": company.GetCeilInt("id"),
"idcard_back_img": idcardBackImg,
"modify_time": t,
"status": 1,
"company_img": companyImg}
"phone": phone,
//"org_id": orgId,
//"idcard": idcard,
//"idcard_front_img": idcardFrontImg,
"company_id": company.GetCeilInt("id"),
//"idcard_back_img": idcardBackImg,
"auth_img": authImg,
"modify_time": t,
"status": 1,
"company_img": companyImg}
if wechat.GetInt("status") == 0 && orgId != 0 {
data["org_id"] = orgId
}
//用户已经注册则更新
if user != nil {
@@ -162,11 +204,11 @@ var User = Ctr{
}
} else {
data["create_time"] = t
if userInfo != nil {
data["nickname"] = userInfo.GetString("nickname")
if wechat != nil {
data["nickname"] = wechat.GetString("nickname")
path := time.Now().Format(this.Config.GetString("imgPath"))
filename := Md5(ObjToStr(t)) + ".jpg"
down := download.Down(userInfo.GetString("avatar"), this.Config.GetString("tpt")+"/"+path, filename)
down := download.Down(wechat.GetString("avatar"), this.Config.GetString("tpt")+"/"+path, filename)
if down {
data["avatar"] = path + filename
}
@@ -178,23 +220,9 @@ var User = Ctr{
return
}
}
if userInfo != nil {
delete(userInfo, "avatar")
delete(userInfo, "nickname")
userInfo["modify_time"] = t
userInfo["user_id"] = user.GetCeilInt("id")
wechatDb := this.Db.Get("wechat", "*", Map{"openid": userInfo.GetString("openid")})
this.Db.Update("wechat", Map{"status": 1, "user_id": user.GetCeilInt("id")}, Map{"id": wechat.GetInt("id")})
if wechatDb != nil {
this.Db.Update("wechat", userInfo, Map{"id": wechatDb.GetCeilInt("id")})
//userInfo["wid"]=wechatDb.GetCeilInt("wid")
} else {
userInfo["create_time"] = t
userInfo["id"] = this.Db.Insert("wechat", userInfo)
}
}
this.Session("user_id", user.GetCeilInt("id"))
this.Display(0, this.SessionId)
@@ -235,11 +263,14 @@ var User = Ctr{
"upload": func(this *Context) {
file := this.Req.FormValue("file")
if len(file) < 100 {
this.Display(3, "图片上传错误")
return
}
//fmt.Println(uimg)
btes, e := base64.StdEncoding.DecodeString(file[strings.Index(file, ",")+1:]) //成图片文件并把文件写入到buffer
//btes, e := base64.StdEncoding.DecodeString(file) //成图片文件并把文件写入到buffer
if e != nil {
@@ -258,6 +289,34 @@ var User = Ctr{
this.Display(3, "图片保存失败")
return
}
tp := this.Req.FormValue("type")
if tp == "company" {
data := tencent.OCRCOMPANY(file)
c := ObjToMap(data)
if c != nil {
c = c.GetMap("Response")
c["url"] = filePath
} else {
c = Map{"url": filePath}
}
this.Display(0, c)
return
}
if tp == "common" {
data := tencent.OCR(file)
c := ObjToMap(data)
if c != nil {
c = c.GetMap("Response")
c["url"] = filePath
} else {
c = Map{"url": filePath}
}
this.Display(0, c)
return
}
this.Display(0, filePath)
},
//"upload": func(this *Context) {
@@ -307,37 +366,24 @@ var User = Ctr{
//
//},
//更新个人资料
//"update": func(this *Context) {
// if this.Req.Form["unickname"] == nil ||
// this.Req.Form["uemail"] == nil ||
// this.Req.Form["usex"] == nil ||
// this.Req.Form["ubirthday"] == nil ||
// this.Req.Form["ubelieve"] == nil ||
// this.Req.Form["utaste"] == nil ||
// this.Req.Form["uname"] == nil ||
// this.Req.Form["uaddreman"] == nil ||
// this.Req.Form["uaddremobile"] == nil ||
// this.Req.Form["uaddre"] == nil ||
// this.Req.Form["uidcard"] == nil {
// this.Display(3, "参数不足")
// }
// //更新代码
// update := Map{
// "unickname": this.Req.FormValue("unickname"),
// "uemail": this.Req.FormValue("uemail"),
// "usex": this.Req.FormValue("usex"),
// "ubelieve": this.Req.FormValue("ubelieve"),
// "utaste": this.Req.FormValue("utaste"),
// "uaddreman": this.Req.FormValue("uaddreman"),
// "uidcard": this.Req.FormValue("uidcard"),
// "ubirthday": this.Req.FormValue("ubirthday"),
// "uaddremobile": this.Req.FormValue("uaddremobile"),
// "uaddre": this.Req.FormValue("uaddre"),
// "uname": this.Req.FormValue("uname"),
// }
//
// this.Db.Update("user", update, Map{"uid": this.Session("user_id").Data})
// this.Display(0, "ok")
//
//},
"update": func(this *Context) {
if this.Req.Form["email"] == nil ||
this.Req.Form["name"] == nil ||
//this.Req.Form["phone"] == nil ||
this.Req.Form["avatar"] == nil ||
this.Req.Form["idcard"] == nil {
this.Display(3, "参数不足")
}
//更新代码
update := Map{
"email": this.Req.FormValue("email"),
"idcard": this.Req.FormValue("idcard"),
"avatar": this.Req.FormValue("avatar"),
"name": this.Req.FormValue("name"),
}
this.Db.Update("user", update, Map{"id": this.Session("user_id").Data})
this.Display(0, "ok")
},
}
+13 -12
View File
@@ -4,6 +4,7 @@ import (
. "../../../hotime"
. "../../../hotime/cache"
. "../../../hotime/common"
"fmt"
"github.com/silenceper/wechat"
"github.com/silenceper/wechat/cache"
"time"
@@ -80,7 +81,7 @@ var Wechat = Ctr{
//微信注册,0已经完整的注册了,1还没有注册
"code": func(this *Context) {
//orgId:=ObjToInt(this.Req.FormValue("org_id"))
orgId := ObjToInt(this.Req.FormValue("org_id"))
//if orgId==0{
// this.Display(3, "缺少组织id")
// return
@@ -96,7 +97,7 @@ var Wechat = Ctr{
//判断用户是否已经注册
user := this.Db.Get("wechat", Map{"[><]user": "wechat.user_id=user.id"}, "user.id,user.state", Map{"openid": resToken.OpenID})
if user != nil && user.GetCeilInt("state") == 0 {
if user != nil && user.GetCeilInt("id") != 0 && user.GetCeilInt("state") == 0 {
this.Session("user_id", user.Get("id"))
this.Display(0, Map{"type": 0, "token": this.SessionId})
return
@@ -116,8 +117,12 @@ var Wechat = Ctr{
"retoken": resToken.RefreshToken,
"appid": this.Config.GetString("wechatAppID"),
"unionid": userInfo.Unionid,
//"nickname": userInfo.Nickname,
//"avatar": userInfo.HeadImgURL,
"nickname": userInfo.Nickname,
"avatar": userInfo.HeadImgURL,
}
if orgId != 0 {
wechatInfo["org_id"] = orgId
wechatInfo["status"] = 0
}
wechatDb := this.Db.Get("wechat", "*", Map{"openid": wechatInfo.GetString("openid")})
@@ -130,15 +135,11 @@ var Wechat = Ctr{
wechatInfo["create_time"] = t
wechatInfo["id"] = this.Db.Insert("wechat", wechatInfo)
}
wechatDb = this.Db.Get("wechat", "*", Map{"openid": wechatInfo.GetString("openid")})
wechatInfo["nickname"] = userInfo.Nickname
wechatInfo["avatar"] = userInfo.HeadImgURL
//this.Session("user_id",user.GetCeilInt("id"))
this.Session("wechatInfo", wechatInfo)
this.Session("wechatInfo", wechatDb)
fmt.Println(wechatDb)
fmt.Println(this.Session("wechatInfo"))
//this.Display(0, 1)
this.Display(0, Map{"type": 1, "token": this.SessionId})
},