123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250 |
- /**
- 组织结构
- 大会员&商机管理 企业组织架构优化
- 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
- }
|