org_structure.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /**
  2. 组织结构
  3. 大会员&商机管理 企业组织架构优化
  4. 2022-2-11
  5. 王山
  6. **/
  7. package front
  8. import (
  9. "fmt"
  10. "jy/src/jfw/config"
  11. "log"
  12. "net/url"
  13. "time"
  14. "github.com/gogf/gf/v2/util/gconv"
  15. "jy/src/jfw/jyutil"
  16. . "jy/src/jfw/public"
  17. "app.yhyue.com/moapp/jybase/encrypt"
  18. "app.yhyue.com/moapp/jypkg/public"
  19. util "app.yhyue.com/moapp/jybase/common"
  20. "app.yhyue.com/moapp/jypkg/common/src/qfw/util/jy"
  21. "bp.jydev.jianyu360.cn/BaseService/userCenter/rpc/pb"
  22. "app.yhyue.com/moapp/jybase/go-xweb/xweb"
  23. "github.com/SKatiyar/qr"
  24. )
  25. type OrgStructure struct {
  26. *xweb.Action
  27. invitationQR xweb.Mapper `xweb:"/orgstructure/invaction/(.*)"` //邀请加入组织的二维码 参数是部门id
  28. invitationPage xweb.Mapper `xweb:"/orgstructure/invpage"` //邀请路由
  29. authorize xweb.Mapper `xweb:"/orgstructure/authorize"` //微信用户授权 获取用户信息
  30. autoLogon xweb.Mapper `xweb:"/orgstructure/autoLogon"` //非剑鱼用户接收邀请注册为剑鱼用户
  31. }
  32. func (this *OrgStructure) InvitationQR(depId string) {
  33. wxWebdomain := util.ObjToString(config.Sysconfig["wxWebdomain"])
  34. entId := this.GetString("entId") //加密后-企业id
  35. entUserId := this.GetString("entUserId") //加密后-企业用户id
  36. depcname := this.GetString("depcname")
  37. if wxWebdomain != "" {
  38. qrUrl := wxWebdomain + "/orgstructure/invpage?entUserId=" + entUserId + "&depId=" + depId + "&entId=" + entId + "&depcname=" + depcname
  39. log.Println("qrUrl:", qrUrl)
  40. //生二维码
  41. _r, err := qr.Encode(qrUrl, qr.L)
  42. if err != nil {
  43. log.Println(err.Error())
  44. } else {
  45. w := this.ResponseWriter
  46. w.Header().Set("Cache-Control", "no-cache,no-store,must-revalidate")
  47. w.Header().Set("Prama", "no-cache")
  48. w.Header().Set("Expires", "0")
  49. w.Header().Set("Content-Type", "image/png")
  50. w.Write((*_r).PNG())
  51. }
  52. }
  53. }
  54. func (this *OrgStructure) InvitationPage() error {
  55. getsession := this.Session().GetMultiple()
  56. client := this.Header("User-Agent")
  57. entUserId := this.GetString("entUserId") //加密后-企业邀请人id
  58. depId := this.GetString("depId") //加密后-部门id
  59. entId := this.GetString("entId") //加密后-企业id
  60. depcname := this.GetString("depcname")
  61. registered := "0" //是否是剑鱼用户:0:未关注; 1:已关注
  62. entUserId_str := encrypt.SE.Decode4HexByCheck(entUserId) //解密
  63. source := this.GetString("source")
  64. entUserId_sess := this.GetSession("entUserId")
  65. OrgUrl := util.ObjToString(config.Sysconfig["wxOrgUrl"]) + "?entUserId=" + entUserId + "&depId=" + depId + "&entId=" + entId + "&depcname=" + depcname + "&source=" + source
  66. if !mobileReg.MatchString(client) {
  67. OrgUrl = util.ObjToString(config.Sysconfig["pcOrgUrl"]) + "?entUserId=" + entUserId + "&depId=" + depId + "&entId=" + entId + "&depcname=" + depcname + "&source=" + source
  68. } else if entUserId_sess == nil || util.ObjToString(entUserId_sess) != entUserId_str {
  69. userId := util.ObjToString(getsession["userId"])
  70. openId := util.ObjToString(getsession["s_m_openid"])
  71. phone := util.ObjToString(getsession["phone"])
  72. isSubscribe := false //是否关注
  73. if userId == "" {
  74. if this.GetString("state") == "wx" {
  75. //微信跳回来的
  76. code := this.GetString("code")
  77. if code != "" {
  78. openId = jyutil.Getopenid(code)
  79. }
  80. } else if public.CheckWxBrowser(this.Request) {
  81. //所有参数都不再使用,跳到微信验证用户
  82. return this.Redirect(fmt.Sprintf(config.Wxoauth, url.QueryEscape(this.Site()+this.Url()), "wx"), 302)
  83. }
  84. }
  85. if openId != "" {
  86. isSubscribe = CheckUserIsSubscribe(openId)
  87. if isSubscribe {
  88. registered = "1"
  89. FindUserAndCreateSess(openId, this.Session(), "wx", false, true)
  90. phone = util.If(this.GetSession("phone") != nil, this.GetSession("phone"), "").(string)
  91. }
  92. }
  93. if phone != "" {
  94. phone = encrypt.SE.EncodeString(phone)
  95. }
  96. OrgUrl = OrgUrl + "&openId=" + encrypt.SE.EncodeString(openId) + "&phone=" + phone + "&registered=" + registered
  97. }
  98. return this.Redirect(OrgUrl)
  99. }
  100. // 暂时不用
  101. func (this *OrgStructure) Authorize() error {
  102. openId := util.ObjToString(this.Session().Get("s_m_openid"))
  103. unionId := ""
  104. isSubscribe := false //是否关注
  105. if openId == "" && this.GetString("state") == "authorize" {
  106. //微信授权
  107. code := this.GetString("code")
  108. if code != "" {
  109. openId = jyutil.Getopenid(code)
  110. }
  111. }
  112. if openId != "" {
  113. isSubscribe = CheckUserIsSubscribe(openId)
  114. if isSubscribe {
  115. FindUserAndCreateSess(openId, this.Session(), "wx", false, true)
  116. } else { //获取未关注用户uninoid
  117. unionId = GetUnionid(openId)
  118. }
  119. }
  120. this.ServeJson(map[string]interface{}{
  121. "openId": encrypt.SE.EncodeString(openId),
  122. "unionId": encrypt.SE.EncodeString(unionId),
  123. "isSubscribe": isSubscribe,
  124. "phone": util.If(this.GetSession("phone") != nil, this.GetSession("phone"), ""),
  125. })
  126. return nil
  127. }
  128. // 移动端(PC端已注册)
  129. func (this *OrgStructure) AutoLogon() error {
  130. openId := this.GetString("openId")
  131. phone := this.GetString("phone")
  132. name := this.GetString("name")
  133. mail := this.GetString("email")
  134. source := this.GetString("source")
  135. rb := false
  136. if openId != "" && phone != "" {
  137. //解密
  138. openId = encrypt.SE.DecodeString(openId)
  139. //当前用户未成为剑鱼用户
  140. if !isExistsByPO(phone, openId) {
  141. unionId := GetUnionid(openId)
  142. if openId == unionId {
  143. unionId = "jyorg_" + unionId //组织机构前缀标识
  144. }
  145. //新用户 保存新信息 微信未关注;手机号可使用
  146. data := map[string]interface{}{
  147. "i_ispush": 0,
  148. "i_appid": 2,
  149. "s_phone": phone,
  150. "s_m_phone": phone,
  151. "s_m_openid": openId,
  152. "s_unionid": unionId,
  153. "s_unique": "wx_" + unionId,
  154. "i_applystatus": 1,
  155. "s_registersource": "org_structure_share", //组织机构优化 邀请加入剑鱼
  156. "l_registedate": time.Now().Unix(),
  157. "i_ts_guide": 2,
  158. "s_platform": "wx",
  159. "s_rsource": gconv.String(util.If(source != "", source, this.GetSession("RSource"))),
  160. "o_jy": map[string]interface{}{
  161. "s_email": mail,
  162. "i_apppush": 1,
  163. "i_wxpush": 1,
  164. "i_ratemode": 2,
  165. "l_modifydate": time.Now().Unix(),
  166. },
  167. "s_regsource": "wx_org_structure_share",
  168. "s_nickname": name,
  169. "s_myemail": mail,
  170. }
  171. if ck, err := this.GetCookie("source"); err == nil && ck.Value != "" {
  172. //cookie中记录用户的来源
  173. data["s_newsource"] = ck.Value
  174. data["s_module"] = GetModule(ck.Value) //根据cookie中记录的来源获取模块
  175. }
  176. if source != "" {
  177. data["s_tracksource"] = source
  178. }
  179. if resp := config.Middleground.UserCenter.UserAdd(pb.UserAddReq{
  180. Appid: "10000",
  181. Phone: phone,
  182. Nickname: name,
  183. SOpenid: openId,
  184. Unionid: unionId,
  185. }); resp != nil && resp.Data.Id > 0 {
  186. data["base_user_id"] = resp.Data.Id
  187. if id := mongodb.Save("user", data); id != "" {
  188. referer := this.Refer()
  189. var Rref = this.GetString("rref")
  190. if this.GetSession("RReferer") != nil && util.ObjToString(this.GetSession("RReferer")) != "" {
  191. Rref = gconv.String(this.GetSession("RReferer"))
  192. }
  193. go jy.SaveUserLog(public.Mgo_Log,
  194. id,
  195. phone,
  196. "phone",
  197. jyutil.IsAndroidOrIOS(this.UserAgent()),
  198. "pc",
  199. openId,
  200. Rref,
  201. gconv.String(util.If(source != "", source,
  202. this.GetSession("RSource"))),
  203. util.GetIp(this.Request),
  204. this.UserAgent(),
  205. "",
  206. "",
  207. referer,
  208. "")
  209. nsqPath, _ := config.Sysconfig["nsq"].(string)
  210. nsq_topic, _ := config.Sysconfig["nsq_topic"].(string)
  211. jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, "task", id, jy.Jyweb_node2, map[string]interface{}{
  212. "code": 1007,
  213. "types": "bindPhone",
  214. "num": 50,
  215. "baseUserId": resp.Data.Id,
  216. "positionId": this.GetSession("positionId"),
  217. })
  218. if mail != "" {
  219. jy.Publish(public.Mgo_Log, nsqPath, nsq_topic, "task", id, jy.Jyweb_node2, map[string]interface{}{
  220. "code": 1009,
  221. "types": "bindMail",
  222. "num": 50,
  223. "baseUserId": resp.Data.Id,
  224. "positionId": this.GetSession("positionId"),
  225. })
  226. }
  227. rb = true
  228. }
  229. } else {
  230. log.Println(phone, unionId, "调用usercenter失败")
  231. }
  232. }
  233. }
  234. this.ServeJson(map[string]interface{}{"flag": rb})
  235. return nil
  236. }