政企超链接开始集成

This commit is contained in:
hoteas
2022-02-24 06:26:36 +08:00
parent 32319d52f0
commit 2a98f0dcad
206 changed files with 117722 additions and 997 deletions
+24 -20
View File
@@ -186,9 +186,9 @@ var analyseCtr = Ctr{
page := ObjToInt(this.Req.FormValue("page"))
pageSize := ObjToInt(this.Req.FormValue("pageSize"))
orgId := ObjToInt(this.Req.FormValue("org_id"))
search := this.Req.FormValue("search")
where := Map{}
where := Map{"state": 0}
levelStr := this.Req.FormValue("level")
if levelStr != "" {
where["level"] = ObjToInt(levelStr)
@@ -197,7 +197,9 @@ var analyseCtr = Ctr{
if industryId != 0 {
where["industry_id"] = industryId
}
if orgId != 0 {
where["org_id"] = orgId
}
if search != "" {
where["name[~]"] = search
}
@@ -229,21 +231,23 @@ var analyseCtr = Ctr{
res["upload_data"] = res.GetMap("upload_data")
res["collect_data"] = res.GetMap("collect_data")
res["collect_data"] = res.GetMap("collect_data")
//if res.GetMap("collect_data") == nil {
// path := "company/" + Md5(res.GetString("name")) + time.Now().Format("/200601021504.json")
//
// data := getCompany(res.GetString("name"), this.Config.GetString("tpt")+"/"+path)
//
// if len(data) != 0 {
// data["path"] = path
// this.Db.Update("company", Map{"collect_data": data.ToJsonString(),
// "address": data.GetString("companyAddress"),
// "sn": data.GetString("creditNo"),
// "unit": data.GetString("authority"),
// }, Map{"id": res.GetCeilInt("id")})
// res["collect_data"] = data
// }
//}
if res.GetMap("collect_data") == nil && page == 1 {
go func(res Map, this *Context) {
path := "company/" + Md5(res.GetString("name")) + time.Now().Format("/200601021504.json")
data := getCompany(res.GetString("name"), this.Config.GetString("tpt")+"/"+path)
if len(data) != 0 {
data["path"] = path
this.Db.Update("company", Map{"collect_data": data.ToJsonString(),
"address": data.GetString("companyAddress"),
"sn": data.GetString("creditNo"),
"unit": data.GetString("authority"),
}, Map{"id": res.GetCeilInt("id")})
res["collect_data"] = data
}
}(res, this)
}
}
@@ -304,14 +308,14 @@ var analyseCtr = Ctr{
return
}
res := this.Db.Get("company", "upload_data", Map{"id": id})
res := this.Db.Get("company", "upload_data,org_id", Map{"id": id})
if res == nil {
this.Display(4, "找不到该数据")
return
}
uploadData := res.GetMap("upload_data")
tags := this.Db.Select("tag", "name,sn,`unit`,description", Map{"type": 1})
tags := this.Db.Select("tag", "name,sn,`unit`,description", Map{"AND": Map{"type": 0, "org_id": res.GetCeilInt("org_id")}})
for _, v := range tags {
v["value"] = uploadData[v.GetString("sn")]
}
+82 -3
View File
@@ -5,17 +5,29 @@ import (
. "../../../hotime/common"
"../../dri/aliyun"
"../../dri/tencent"
"fmt"
"github.com/silenceper/wechat"
"github.com/silenceper/wechat/cache"
"gopkg.in/chanxuehong/wechat.v2/mch/core"
"gopkg.in/chanxuehong/wechat.v2/mch/pay"
"io/ioutil"
"os"
"path/filepath"
"time"
)
// Project 管理端项目
var Project = Proj{
//"user": UserCtr,
"tag": tagCtr,
"analyse": analyseCtr,
"tag": tagCtr,
"analyse": analyseCtr,
"user": User,
"wechat": Wechat,
"question": Question,
}
var weixin *wechat.Wechat //微信登录实例
//var appIns = Application{}
var wxpayClient *core.Client
//生成随机码的4位随机数
func getCode() string {
@@ -27,7 +39,7 @@ func getCode() string {
}
func getCompany(name, path string) Map {
os.Setenv("ZONEINFO", "config/data.zip")
res := tencent.GetCompany("AKIDklZa1qBr3B0x1G643cg8B6UO5JZm2KX8o43G", "tdda7oro526h96dvicYkep1xsWFmHkt33xvqs2K", name)
c := Map{}
base := Map{}
@@ -78,3 +90,70 @@ func getCompany(name, path string) Map {
return base
}
//微信获取个人信息
func Weixin(this *Context) *wechat.Wechat {
if weixin == nil {
cache1 := cache.Cache(WechatCache{this.CacheIns})
config := wechat.Config{Cache: cache1, AppID: this.Config.GetString("wechatAppid"), AppSecret: this.Config.GetString("wechatAppscript")}
weixin = wechat.NewWechat(&config)
}
return weixin
}
//微信获取个人信息
func WxPayClient(this *Context, sn string, money int64, openid string) Map {
if wxpayClient == nil {
wxpayClient = core.NewClient(this.Config.GetString("wechatAppid"), this.Config.GetString("wechatChid"), this.Config.GetString("wechatChkey"), nil)
}
res, err := pay.UnifiedOrder2(wxpayClient, &pay.UnifiedOrderRequest{
// 必选参数
Body: "微信充值", // 商品或支付单简要描述
OutTradeNo: sn, // 商户系统内部的订单号,32个字符内、可包含字母, 其他说明见商户订单号
TotalFee: money, // ObjToInt64(umoney*100), // `xml:"total_fee"` // 订单总金额,单位为分,详见支付金额
//SpbillCreateIP string `xml:"spbill_create_ip"` // APP和网页支付提交用户端ip,Native支付填调用微信支付API的机器IP。
NotifyURL: this.Config.GetString("wechatPayCallBack"), // string `xml:"notify_url"` // 接收微信支付异步通知回调地址,通知url必须为直接可访问的url,不能携带参数。
TradeType: "JSAPI", // string `xml:"trade_type"` // 取值如下:JSAPI,NATIVE,APP,详细说明见参数规定
// 可选参数
DeviceInfo: "WEB", // string `xml:"device_info"` // 终端设备号(门店号或收银设备ID),注意:PC网页或公众号内支付请传"WEB"
// NonceStr string `xml:"nonce_str"` // 随机字符串,不长于32位。NOTE: 如果为空则系统会自动生成一个随机字符串。
//SignType string `xml:"sign_type"` // 签名类型,默认为MD5,支持HMAC-SHA256和MD5。
// Detail:"充值",// string `xml:"detail"` // 商品名称明细列表
//Attach string `xml:"attach"` // 附加数据,在查询API和支付通知中原样返回,该字段主要用于商户携带订单的自定义数据
//FeeType string `xml:"fee_type"` // 符合ISO 4217标准的三位字母代码,默认人民币:CNY,其他值列表详见货币类型
//TimeStart time.Time `xml:"time_start"` // 订单生成时间,格式为yyyyMMddHHmmss,如2009年12月25日9点10分10秒表示为20091225091010。其他详见时间规则
//TimeExpire time.Time `xml:"time_expire"` // 订单失效时间,格式为yyyyMMddHHmmss,如2009年12月27日9点10分10秒表示为20091227091010。其他详见时间规则
//GoodsTag string `xml:"goods_tag"` // 商品标记,代金券或立减优惠功能的参数,说明详见代金券或立减优惠
// ProductId :"CHONGZHI",// string `xml:"product_id"` // trade_type=NATIVE,此参数必传。此id为二维码中包含的商品ID,商户自行定义。
// LimitPay string `xml:"limit_pay"` // no_credit--指定不能使用信用卡支付
OpenId: openid, //user.GetString("wuid"), // string `xml:"openid"` // rade_type=JSAPI,此参数必传,用户在商户appid下的唯一标识。
// SubOpenId string `xml:"sub_openid"` // trade_type=JSAPI,此参数必传,用户在子商户appid下的唯一标识。openid和sub_openid可以选传其中之一,如果选择传sub_openid,则必须传sub_appid。
// SceneInfo string `xml:"scene_info"` // 该字段用于上报支付的场景信息,针对H5支付有以下三种场景,请根据对应场景上报,H5支付不建议在APP端
})
if err != nil {
fmt.Println(err)
return nil
}
wcpay := Map{
"appId": this.Config.Get("wechatAppid"),
"timeStamp": ObjToStr(time.Now().Unix()),
"nonceStr": getSn(),
"package": "prepay_id=" + res.PrepayId,
"signType": "MD5",
}
wcpay["paySign"] = core.JsapiSign(this.Config.GetString("wechatAppid"), wcpay.GetString("timeStamp"), wcpay.GetString("nonceStr"), wcpay.GetString("package"), "MD5", this.Config.GetString("wechatChkey"))
return wcpay
}
//生成随机码的6位md5
func getSn() string {
x := Rand(8)
return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6)
}
+86
View File
@@ -0,0 +1,86 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"time"
//"strings"
)
var Question = Ctr{
//获取个人信息
"update": func(this *Context) {
if this.Session("user_id").Data == nil {
this.Display(2, "还没有登录")
return
}
questionCompanyId := ObjToInt(this.Req.FormValue("id"))
if questionCompanyId == 0 {
this.Display(3, "参数错误")
return
}
data := this.Req.FormValue("data")
if data == "" {
this.Display(3, "没有上传数据")
return
}
status := ObjToInt(this.Req.FormValue("status"))
re := this.Db.Update("question_company", Map{"question_data": data, "status": status}, Map{"id": questionCompanyId})
if re == 0 {
this.Display(4, "没有更新信息!")
return
}
this.Display(0, "更新成功")
},
//获取列表
"list": func(this *Context) {
if this.Session("user_id").Data == nil {
this.Display(2, "还没有登录")
return
}
user := this.Db.Get("user", "*", Map{"id": this.Session("user_id").Data})
t := time.Now().Unix()
questions := this.Db.Select("question", "*", Map{"AND": Map{"org_id": user.GetCeilInt("org_id"), "start_time[>=]": t, "end_time[<=]": t, "state": 0}})
re := []Map{}
for _, v := range questions {
questionCompany := this.Db.Get("question_company", "*", Map{"AND": Map{"question_id": v.GetCeilInt("id"), "company_id": user.GetCeilInt("company_id")}})
if questionCompany == nil {
questionCompany = Map{
"name": v.GetString("name"),
"question_data": v.GetString("question_data"),
"org_id": v.GetString("org_id"),
"question_id": v.GetString("id"),
"company_id": user.GetCeilInt("company_id"),
"user_id": user.GetString("id"),
"create_time": t,
"modify_time": t,
"status": 0,
"state": 0,
}
questionCompany["id"] = this.Db.Insert("question_company", questionCompany)
if questionCompany.GetCeilInt("id") == 0 {
this.Display(4, "无法创建调查数据")
return
}
}
delete(v, "question")
questionCompany["question"] = v
re = append(re, questionCompany)
}
this.Display(0, re)
},
}
+23 -12
View File
@@ -8,24 +8,35 @@ import (
var tagCtr = Ctr{
"ctg_tree": func(this *Context) {
//orgId := ObjToInt(this.Req.FormValue("org_id"))
//if orgId == 0 {
// this.Display(3, "参数错误")
// return
//}
orgId := ObjToInt(this.Req.FormValue("org_id"))
if orgId == 0 {
this.Display(3, "参数错误")
return
}
data := Map{}
run := func(t int) []Map {
//upCtg:=this.Db.Select("tag_ctg","*",Map{"parent_id":id})
//for _,v:=range upCtg{
upTag := this.Db.Select("tag", "*", Map{"type": t})
//v["tag"]=upTag
//}
return upTag
upTag := this.Db.Select("tag", "*", Map{"AND": Map{"type": t, "org_id": 2}})
upTag1 := this.Db.Select("tag", "*", Map{"AND": Map{"type": t, "org_id": orgId}})
for _, v := range upTag {
check := true
for _, v1 := range upTag1 {
if v1.GetString("sn") == v.GetString("sn") {
check = false
break
}
}
if check {
upTag1 = append(upTag1, v)
}
}
return upTag1
}
data["upload"] = run(1)
data["api"] = run(2)
data["analyse"] = run(0)
data["upload"] = run(0)
data["api"] = run(1)
data["analyse"] = run(2)
this.Display(0, data)
},
+249
View File
@@ -0,0 +1,249 @@
package app
import (
. "../../../hotime"
. "../../../hotime/common"
"encoding/base64"
"io/ioutil"
"os"
"../../../hotime/dri/download"
"time"
//"strings"
)
var User = Ctr{
"test": func(this *Context) {
this.Session("uid", 1)
this.Display(0, "开始测试")
},
//获取个人信息
"info": func(this *Context) {
if this.Session("user_id").Data == nil {
this.Display(2, "还没有登录")
return
}
user := this.Db.Get("user", "*", Map{"id": this.Session("user_id").Data})
this.Display(0, user)
},
//身份认证
"auth": func(this *Context) {
if this.Session("wechatInfo").Data == nil {
this.Display(2, "尚未登录")
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")
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 == "" {
this.Display(3, "参数异常")
return
}
t := time.Now().Unix()
company := this.Db.Get("company", "id", Map{"sn": companySn})
if company == nil {
company = Map{
"name": companyName,
"sn": companySn,
"create_time": t,
"org_id": orgId,
"modify_time": t,
"status": 1,
"state": 0,
"img": companyImg,
}
company["id"] = this.Db.Insert("company", company)
if company.GetCeilInt("id") == 0 {
this.Display(4, "无法创建企业")
return
}
} else {
company["status"] = 1
company["modify_time"] = t
company["img"] = companyImg
company["org_id"] = orgId
re := this.Db.Update("company", company, Map{"id": company.GetCeilInt("id")})
if re == 0 {
this.Display(4, "无法更新企业")
return
}
}
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}
//用户已经注册则更新
if user != nil {
re := this.Db.Update("user", data, Map{"id": user.GetCeilInt("id")})
if re == 0 {
this.Display(4, "无法更新用户")
return
}
} else {
data["nickname"] = userInfo.GetString("nickname")
data["create_time"] = t
path := time.Now().Format(this.Config.GetString("uimgPath"))
filename := Md5(ObjToStr(t)) + ".jpg"
down := download.Down(userInfo.GetString("avatar"), this.Config.GetString("tpt")+"/"+path, filename)
if down {
data["avatar"] = path + filename
}
user = data
user["id"] = this.Db.Insert("user", data)
if user.GetCeilInt("id") == 0 {
this.Display(4, "无法创建用户")
return
}
}
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")})
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, "认证成功!")
},
//修改密码g
"forget": func(this *Context) {
if this.Session("code").Data == nil {
this.Display(8, "验证码没有获取")
return
}
if this.Req.FormValue("code") == "" || this.Req.FormValue("umobile") == "" {
this.Display(3, "验证码或者手机号没有输入")
return
}
if this.Req.FormValue("umobile") != this.Session("umobile").ToStr() ||
this.Req.FormValue("code") != this.Session("code").ToStr() {
this.Display(14, "验证码验证失败")
return
}
if len(this.Req.FormValue("upwd")) < 6 {
this.Display(3, "密码没有输入")
return
}
res := this.Db.Update("user", Map{"upwd": Md5(this.Req.FormValue("upwd"))}, Map{"umobile": this.Req.FormValue("umobile")})
if res == 0 {
this.Display(5, "找不到该用户")
return
}
this.Display(0, "成功")
},
"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) //成图片文件并把文件写入到buffer
if e != nil {
this.Display(3, "无法解析图片")
return
}
//uimgPath:=time.Now().Format(this.Config.GetString("uimgPath"))
path := time.Now().Format(this.Config.GetString("imgPath"))
os.MkdirAll(this.Config.GetString("tpt")+"/"+path, os.ModeDir)
filePath := path + Md5(ObjToStr(time.Now().Unix())) + ".jpg"
err2 := ioutil.WriteFile(this.Config.GetString("tpt")+"/"+filePath, btes, 0666) //buffer输出到jpg文件中(不做处理,直接写到文件)
if err2 != nil {
this.Display(3, "图片保存失败")
return
}
this.Display(0, filePath)
},
//更新个人资料
//"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")
//
//},
}
+175
View File
@@ -0,0 +1,175 @@
package app
import (
. "../../../hotime"
. "../../../hotime/cache"
. "../../../hotime/common"
"github.com/silenceper/wechat"
"github.com/silenceper/wechat/cache"
"time"
)
type WechatCache struct {
CacheIns
}
func (this WechatCache) Get(key string) interface{} {
return this.Cache("x" + key).Data
//return nil
}
func (this WechatCache) Set(key string, val interface{}, timeout time.Duration) error {
this.Cache("x"+key, val, ObjToInt64(timeout.Seconds()))
return nil
}
func (this WechatCache) IsExist(key string) bool {
c := this.Cache("x" + key).Data
if c != nil {
return true
}
return false
}
func (this WechatCache) Delete(key string) error {
this.Cache("x"+key, nil)
return nil
}
var Wechat = Ctr{
"user": func(this *Context) {
if this.Session("wechatInfo").Data == nil {
this.Display(2, "没有登录")
}
this.Display(0, this.Session("wechatInfo").ToMap())
},
//微信注册,0已经完整的注册了,1还没有注册
"codebase": func(this *Context) {
wx := Weixin(this)
auth := wx.GetOauth(this.Req, this.Resp)
resToken, err := auth.GetUserAccessToken(this.Req.FormValue("code"))
if err != nil {
this.Display(6, "code错误")
return
}
//判断用户是否已经注册
user := this.Db.Get("wechat", Map{"[><]user": "wechat.user_id=user.id"}, "user.id,user.state", Map{"openid": resToken.OpenID})
if user != nil {
this.Session("user_id", user.Get("id"))
this.Display(0, 0)
return
}
user_id := this.Db.Insert("user", Map{"time": time.Now().Unix(), "state": 2})
if user_id == 0 {
this.Display(4, "创建用户失败")
return
}
wid := this.Db.Insert("wechat", Map{"openid": resToken.OpenID, "appid": this.Config.GetString("wechatAppID"), "state": 1, "user_id": user_id})
if wid == 0 {
this.Display(4, "关联微信失败!")
return
}
this.Session("user_id", user.Get("id"))
this.Display(0, 1)
},
//微信注册,0已经完整的注册了,1还没有注册
"code": func(this *Context) {
//orgId:=ObjToInt(this.Req.FormValue("org_id"))
//if orgId==0{
// this.Display(3, "缺少组织id")
// return
//}
wx := Weixin(this)
auth := wx.GetOauth(this.Req, this.Resp)
resToken, err := auth.GetUserAccessToken(this.Req.FormValue("code"))
if err != nil {
this.Display(6, "code错误")
return
}
//判断用户是否已经注册
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 {
this.Session("user_id", user.Get("id"))
this.Display(0, 0)
return
}
//getUserInfo
userInfo, err := auth.GetUserInfo(resToken.AccessToken, resToken.OpenID)
if err != nil {
this.Display(6, "微信个人信息无法获取")
return
}
//wechatInfo := ObjToMap(userInfo)
t := time.Now().Unix()
wechatInfo := Map{
"openid": userInfo.OpenID,
"acttoken": resToken.AccessToken,
"retoken": resToken.RefreshToken,
"appid": this.Config.GetString("wechatAppID"),
"unionid": userInfo.Unionid,
//"nickname": userInfo.Nickname,
//"avatar": userInfo.HeadImgURL,
}
wechatDb := this.Db.Get("wechat", "*", Map{"openid": wechatInfo.GetString("openid")})
if wechatDb != nil {
this.Db.Update("wechat", wechatInfo, Map{"id": wechatDb.GetCeilInt("id")})
//userInfo["wid"]=wechatDb.GetCeilInt("wid")
} else {
wechatInfo["create_time"] = t
wechatInfo["id"] = this.Db.Insert("wechat", wechatInfo)
}
wechatInfo["nickname"] = userInfo.Nickname
wechatInfo["avatar"] = userInfo.HeadImgURL
//this.Session("user_id",user.GetCeilInt("id"))
this.Session("wechatInfo", wechatInfo)
this.Display(0, 1)
},
//网页签名
"sign": func(this *Context) {
if this.Req.FormValue("sign_url") == "" {
this.Display(2, "参数不足")
return
}
if weixin == nil {
cache1 := cache.Cache(WechatCache{this.CacheIns})
config := wechat.Config{Cache: cache1, AppID: this.Config.GetString("wechatAppID"), AppSecret: this.Config.GetString("wechatAppSecret")}
weixin = wechat.NewWechat(&config)
}
js := weixin.GetJs(this.Req, this.Resp)
cfg, e := js.GetConfig(this.Req.FormValue("sign_url"))
if e != nil {
this.Display(7, e)
return
}
sign := Map{
"appId": cfg.AppID,
"timestamp": cfg.TimeStamp,
"nonceStr": cfg.NonceStr,
"signature": cfg.Signature,
}
this.Display(0, sign)
},
}