/** 组织结构 大会员&商机管理 企业组织架构优化 2022-2-11 王山 **/ package front import ( "fmt" "jy/src/jfw/config" "log" "net/url" "time" "github.com/gogf/gf/v2/util/gconv" "jy/src/jfw/jyutil" . "jy/src/jfw/public" "app.yhyue.com/moapp/jybase/encrypt" "app.yhyue.com/moapp/jypkg/public" util "app.yhyue.com/moapp/jybase/common" "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy" "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb" "app.yhyue.com/moapp/jybase/go-xweb/xweb" "github.com/SKatiyar/qr" ) type OrgStructure struct { *xweb.Action invitationQR xweb.Mapper `xweb:"/orgstructure/invaction/(.*)"` //邀请加入组织的二维码 参数是部门id invitationPage xweb.Mapper `xweb:"/orgstructure/invpage"` //邀请路由 authorize xweb.Mapper `xweb:"/orgstructure/authorize"` //微信用户授权 获取用户信息 autoLogon xweb.Mapper `xweb:"/orgstructure/autoLogon"` //非剑鱼用户接收邀请注册为剑鱼用户 } func (this *OrgStructure) InvitationQR(depId string) { wxWebdomain := util.ObjToString(config.Sysconfig["wxWebdomain"]) entId := this.GetString("entId") //加密后-企业id entUserId := this.GetString("entUserId") //加密后-企业用户id depcname := this.GetString("depcname") if wxWebdomain != "" { qrUrl := wxWebdomain + "/orgstructure/invpage?entUserId=" + entUserId + "&depId=" + depId + "&entId=" + entId + "&depcname=" + depcname log.Println("qrUrl:", qrUrl) //生二维码 _r, err := qr.Encode(qrUrl, qr.L) if err != nil { log.Println(err.Error()) } else { w := this.ResponseWriter w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate") w.Header().Set("Prama", "no-cache") w.Header().Set("Expires", "0") w.Header().Set("Content-Type", "image/png") w.Write((*_r).PNG()) } } } func (this *OrgStructure) InvitationPage() error { getsession := this.Session().GetMultiple() client := this.Header("User-Agent") entUserId := this.GetString("entUserId") //加密后-企业邀请人id depId := this.GetString("depId") //加密后-部门id entId := this.GetString("entId") //加密后-企业id depcname := this.GetString("depcname") registered := "0" //是否是剑鱼用户:0:未关注; 1:已关注 entUserId_str := encrypt.SE.Decode4HexByCheck(entUserId) //解密 source := this.GetString("source") entUserId_sess := this.GetSession("entUserId") OrgUrl := util.ObjToString(config.Sysconfig["wxOrgUrl"]) + "?entUserId=" + entUserId + "&depId=" + depId + "&entId=" + entId + "&depcname=" + depcname + "&source=" + source if !mobileReg.MatchString(client) { OrgUrl = util.ObjToString(config.Sysconfig["pcOrgUrl"]) + "?entUserId=" + entUserId + "&depId=" + depId + "&entId=" + entId + "&depcname=" + depcname + "&source=" + source } else if entUserId_sess == nil || util.ObjToString(entUserId_sess) != entUserId_str { userId := util.ObjToString(getsession["userId"]) openId := util.ObjToString(getsession["s_m_openid"]) phone := util.ObjToString(getsession["phone"]) isSubscribe := false //是否关注 if userId == "" { if this.GetString("state") == "wx" { //微信跳回来的 code := this.GetString("code") if code != "" { openId = jyutil.Getopenid(code) } } else if public.CheckWxBrowser(this.Request) { //所有参数都不再使用,跳到微信验证用户 return this.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(this.Site()+this.Url()), "wx"), 302) } } if openId != "" { isSubscribe = CheckUserIsSubscribe(openId) if isSubscribe { registered = "1" FindUserAndCreateSess(openId, this.Session(), "wx", false, true) phone = util.If(this.GetSession("phone") != nil, this.GetSession("phone"), "").(string) } } if phone != "" { phone = encrypt.SE.EncodeString(phone) } OrgUrl = OrgUrl + "&openId=" + encrypt.SE.EncodeString(openId) + "&phone=" + phone + "®istered=" + registered } return this.Redirect(OrgUrl) } // 暂时不用 func (this *OrgStructure) Authorize() error { openId := util.ObjToString(this.Session().Get("s_m_openid")) unionId := "" isSubscribe := false //是否关注 if openId == "" && this.GetString("state") == "authorize" { //微信授权 code := this.GetString("code") if code != "" { openId = jyutil.Getopenid(code) } } if openId != "" { isSubscribe = CheckUserIsSubscribe(openId) if isSubscribe { FindUserAndCreateSess(openId, this.Session(), "wx", false, true) } else { //获取未关注用户uninoid unionId = GetUnionid(openId) } } this.ServeJson(map[string]interface{}{ "openId": encrypt.SE.EncodeString(openId), "unionId": encrypt.SE.EncodeString(unionId), "isSubscribe": isSubscribe, "phone": util.If(this.GetSession("phone") != nil, this.GetSession("phone"), ""), }) return nil } // 移动端(PC端已注册) func (this *OrgStructure) AutoLogon() error { openId := this.GetString("openId") phone := this.GetString("phone") name := this.GetString("name") mail := this.GetString("email") source := this.GetString("source") rb := false if openId != "" && phone != "" { //解密 openId = encrypt.SE.DecodeString(openId) //当前用户未成为剑鱼用户 if !isExistsByPO(phone, openId) { unionId := GetUnionid(openId) if openId == unionId { unionId = "jyorg_" + unionId //组织机构前缀标识 } //新用户 保存新信息 微信未关注;手机号可使用 data := map[string]interface{}{ "i_ispush": 0, "i_appid": 2, "s_phone": phone, "s_m_phone": phone, "s_m_openid": openId, "s_unionid": unionId, "s_unique": "wx_" + unionId, "i_applystatus": 1, "s_registersource": "org_structure_share", //组织机构优化 邀请加入剑鱼 "l_registedate": time.Now().Unix(), "i_ts_guide": 2, "s_platform": "wx", "s_rsource": gconv.String(util.If(source != "", source, this.GetSession("RSource"))), "o_jy": map[string]interface{}{ "s_email": mail, "i_apppush": 1, "i_wxpush": 1, "i_ratemode": 2, "l_modifydate": time.Now().Unix(), }, "s_regsource": "wx_org_structure_share", "s_nickname": name, "s_myemail": mail, } if ck, err := this.GetCookie("source"); err == nil && ck.Value != "" { //cookie中记录用户的来源 data["s_newsource"] = ck.Value data["s_module"] = GetModule(ck.Value) //根据cookie中记录的来源获取模块 } if source != "" { data["s_tracksource"] = source } if resp := config.Middleground.UserCenter.UserAdd(pb.UserAddReq{ Appid: "10000", Phone: phone, Nickname: name, SOpenid: openId, Unionid: unionId, }); resp != nil && resp.Data.Id > 0 { data["base_user_id"] = resp.Data.Id if id := mongodb.Save("user", data); id != "" { referer := this.Refer() var Rref = this.GetString("rref") if this.GetSession("RReferer") != nil && util.ObjToString(this.GetSession("RReferer")) != "" { Rref = gconv.String(this.GetSession("RReferer")) } go jy.SaveUserLog(public.Mgo_Log, id, phone, "phone", jyutil.IsAndroidOrIOS(this.UserAgent()), "pc", openId, Rref, gconv.String(util.If(source != "", source, this.GetSession("RSource"))), util.GetIp(this.Request), this.UserAgent(), "", "", referer, "") nsqPath, _ := config.Sysconfig["nsq"].(string) nsq_topic, _ := config.Sysconfig["nsq_topic"].(string) jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, "task", id, jy.Jyweb_node2, map[string]interface{}{ "code": 1007, "types": "bindPhone", "num": 50, "baseUserId": resp.Data.Id, "positionId": this.GetSession("positionId"), }) if mail != "" { jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, "task", id, jy.Jyweb_node2, map[string]interface{}{ "code": 1009, "types": "bindMail", "num": 50, "baseUserId": resp.Data.Id, "positionId": this.GetSession("positionId"), }) } rb = true } } else { log.Println(phone, unionId, "调用usercenter失败") } } } this.ServeJson(map[string]interface{}{"flag": rb}) return nil }