Преглед изворни кода

feat:接受邀请注册成为剑鱼用户

wangshan пре 3 година
родитељ
комит
ee9ccfdb83
1 измењених фајлова са 99 додато и 6 уклоњено
  1. 99 6
      src/jfw/front/org_structure.go

+ 99 - 6
src/jfw/front/org_structure.go

@@ -14,6 +14,7 @@ import (
 	"jfw/public"
 	"log"
 	"net/url"
+	"time"
 
 	"qfw/util"
 
@@ -25,6 +26,8 @@ type OrgStructure struct {
 	*xweb.Action
 	invitationQR   xweb.Mapper `xweb:"/orgstructure/invaction/(.*)"` //邀请加入组织的二维码 参数是部门id
 	invitationPage xweb.Mapper `xweb:"/orgstructure/invpage.html"`   //邀请页面
+	authorize      xweb.Mapper `xweb:"/orgstructure/authorize"`      //微信用户授权 获取用户信息
+	autoLogon      xweb.Mapper `xweb:"/orgstructure/autoLogon"`      //非剑鱼用户接收邀请注册为剑鱼用户
 }
 
 //
@@ -53,8 +56,9 @@ func (this *OrgStructure) InvitationQR(depId string) {
 //
 func (this *OrgStructure) InvitationPage() error {
 	openId := util.ObjToString(this.Session().Get("s_m_openid"))
-	unionId := ""
+	phone := ""
 	isSubscribe := false //是否关注
+	log.Println(this.GetString("state"), "-----", this.GetString("code"))
 	if openId == "" {
 		if this.GetString("state") == "wx" {
 			//微信跳回来的
@@ -69,6 +73,29 @@ func (this *OrgStructure) InvitationPage() error {
 			}
 		}
 	}
+	if openId != "" {
+		isSubscribe = CheckUserIsSubscribe(openId)
+		if isSubscribe {
+			FindUserAndCreateSess(openId, this.Session(), "wx", false)
+		}
+		phone = util.If(this.GetSession("phone") != nil, this.GetSession("phone"), "").(string)
+		log.Println("---:", phone)
+	}
+	return this.Redirect("/orgstructure/autoLogon?openId=" + openId + "&phone=" + phone)
+}
+
+//暂时不用
+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 {
@@ -76,10 +103,76 @@ func (this *OrgStructure) InvitationPage() error {
 		} else { //获取未关注用户uninoid
 			unionId = public.GetUnionid(openId)
 		}
-		this.T["openId"] = util.SE.EncodeString(openId)
-		this.T["unionId"] = util.SE.EncodeString(unionId)
-		this.T["isSubscribe"] = isSubscribe
-		this.T["phone"] = util.If(this.GetSession("phone") != nil, this.GetSession("phone"), "")
 	}
-	return this.Render("/weixin/orgStructure/invitationPage.html", &this.T)
+	this.ServeJson(map[string]interface{}{
+		"openId":      util.SE.EncodeString(openId),
+		"unionId":     util.SE.EncodeString(unionId),
+		"isSubscribe": isSubscribe,
+		"phone":       util.If(this.GetSession("phone") != nil, this.GetSession("phone"), ""),
+	})
+	return nil
+}
+
+//
+func (this *OrgStructure) AutoLogon() error {
+	openId := this.GetString("openId")
+	phone := this.GetString("phone")
+	name := this.GetString("name")
+	mail := this.GetString("mail")
+	rb := false
+	if openId != "" && phone != "" {
+		//解密
+		openId = util.SE.DecodeString(openId)
+		//取关用户 更新手机号
+		if uid := GetUserId(openId); uid != "" {
+			rb = public.MQFW.UpdateById("user", uid, map[string]interface{}{
+				"$set": map[string]interface{}{
+					"s_m_phone": phone,
+					"s_phone":   phone,
+				},
+			})
+		} else {
+			unionId := public.GetUnionid(openId)
+			if openId == unionId {
+				unionId = "uni_" + 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",
+				"o_jy": map[string]interface{}{
+					"i_apppush":    1,
+					"i_ratemode":   2,
+					"l_modifydate": time.Now().Unix(),
+				},
+				"s_regsource": "wx",
+				"s_nickname":  name,
+				"s_myemail":   mail,
+			}
+			source := this.GetString("source")
+			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 mongodb.Save("user", data) != "" {
+				rb = true
+			}
+		}
+	}
+	this.ServeJson(map[string]interface{}{"flag": rb})
+	return nil
 }