|
@@ -1,9 +1,10 @@
|
|
-package util
|
|
|
|
|
|
+package usercenter
|
|
|
|
|
|
import (
|
|
import (
|
|
"encoding/json"
|
|
"encoding/json"
|
|
"io/ioutil"
|
|
"io/ioutil"
|
|
"log"
|
|
"log"
|
|
|
|
+ "app.yhyue.com/moapp/jybase/mongodb"
|
|
"net/http"
|
|
"net/http"
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
@@ -16,6 +17,7 @@ var ContentType_Json = "application/json"
|
|
var UserCenterAdd = "/userCenter/user/add"
|
|
var UserCenterAdd = "/userCenter/user/add"
|
|
var UserCenterUpdate = "/userCenter/user/updateById"
|
|
var UserCenterUpdate = "/userCenter/user/updateById"
|
|
var UserCenterDelete = "/userCenter/user/deleteById"
|
|
var UserCenterDelete = "/userCenter/user/deleteById"
|
|
|
|
+var UserCenterGetUserIdentity = "/userCenter/user/identity"
|
|
|
|
|
|
/*
|
|
/*
|
|
修改header 的post请求
|
|
修改header 的post请求
|
|
@@ -80,3 +82,175 @@ func PostUserCenter(url, contentTpe, userid string, data map[string]interface{},
|
|
}
|
|
}
|
|
return dataM, true
|
|
return dataM, true
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+// usercenter
|
|
|
|
+type UserInfo struct {
|
|
|
|
+ S_openid string //微信openid
|
|
|
|
+ A_openid string //app 微信openid
|
|
|
|
+ Phone string //手机号
|
|
|
|
+ Nickname string //昵称
|
|
|
|
+ Headimg string //头像
|
|
|
|
+ Company string //公司
|
|
|
|
+ Position string //职位
|
|
|
|
+ Password string //密码
|
|
|
|
+ Unionid string //unionid
|
|
|
|
+ Base_user_id int64 //用户中台base_user的主键id,
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//获取base_user需要的数据
|
|
|
|
+func GetInfoForBaseUser(mg mongodb.MongodbSim, userid string) *UserInfo {
|
|
|
|
+ if userid == "" {
|
|
|
|
+ return nil
|
|
|
|
+ }
|
|
|
|
+ data, ok := mg.FindById("user", userid, `{"base_user_id":1,"s_m_openid":1,"a_m_openid":1,"s_m_phone":1,"s_phone":1,"s_nickname":1,"s_jyname":1,"s_headimageurl":1,"s_headimage":1,"s_company":1,"s_password":1,"s_unionid":1}`)
|
|
|
|
+ if ok && data != nil && len(*data) > 0 {
|
|
|
|
+ userinfo := &UserInfo{
|
|
|
|
+ Base_user_id: Int64All((*data)["base_user_id"]),
|
|
|
|
+ }
|
|
|
|
+ if s_openid := ObjToString((*data)["s_m_openid"]); s_openid != "" {
|
|
|
|
+ userinfo.S_openid = s_openid
|
|
|
|
+ }
|
|
|
|
+ if a_openid := ObjToString((*data)["a_m_openid"]); a_openid != "" {
|
|
|
|
+ userinfo.A_openid = a_openid
|
|
|
|
+ }
|
|
|
|
+ phone := ObjToString((*data)["s_phone"])
|
|
|
|
+ if phone == "" {
|
|
|
|
+ phone = ObjToString((*data)["s_m_phone"])
|
|
|
|
+ }
|
|
|
|
+ if phone != "" {
|
|
|
|
+ userinfo.Phone = phone
|
|
|
|
+ }
|
|
|
|
+ nickname := ObjToString((*data)["s_nickname"])
|
|
|
|
+ if nickname == "" {
|
|
|
|
+ nickname = ObjToString((*data)["s_jyname"])
|
|
|
|
+ }
|
|
|
|
+ if nickname != "" {
|
|
|
|
+ userinfo.Nickname = nickname
|
|
|
|
+ }
|
|
|
|
+ if unionid := ObjToString((*data)["s_unionid"]); unionid != "" {
|
|
|
|
+ userinfo.Unionid = unionid
|
|
|
|
+ }
|
|
|
|
+ if password := ObjToString((*data)["s_password"]); password != "" {
|
|
|
|
+ userinfo.Password = password
|
|
|
|
+ }
|
|
|
|
+ if headimg := ObjToString((*data)["s_headimageurl"]); headimg != "" {
|
|
|
|
+ userinfo.Headimg = headimg
|
|
|
|
+ }
|
|
|
|
+ return userinfo
|
|
|
|
+ }
|
|
|
|
+ return nil
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//获取mongodb中的base_user_id
|
|
|
|
+func GetBaseUserId(mg mongodb.MongodbSim, userid string) int64 {
|
|
|
|
+ if userid == "" {
|
|
|
|
+ return 0
|
|
|
|
+ }
|
|
|
|
+ data, ok := mg.FindById("user", userid, `{"base_user_id":1}`)
|
|
|
|
+ if ok && data != nil && len(*data) > 0 {
|
|
|
|
+ return Int64All((*data)["base_user_id"])
|
|
|
|
+ }
|
|
|
|
+ return 0
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//更新用户中台相关
|
|
|
|
+func UpdateBaseUser(mgo mongodb.MongodbSim, href, userId string, ck *http.Cookie) {
|
|
|
|
+ formdata := map[string]interface{}{
|
|
|
|
+ "appid": "10000",
|
|
|
|
+ }
|
|
|
|
+ userinfo := GetInfoForBaseUser(mgo, userId)
|
|
|
|
+ if userinfo == nil {
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ formdata["id"] = userinfo.Base_user_id
|
|
|
|
+
|
|
|
|
+ if userinfo.A_openid != "" {
|
|
|
|
+ formdata["a_openid"] = userinfo.A_openid
|
|
|
|
+ }
|
|
|
|
+ if userinfo.S_openid != "" {
|
|
|
|
+ formdata["s_openid"] = userinfo.S_openid
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if userinfo.Company != "" {
|
|
|
|
+ formdata["company"] = userinfo.Company
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if userinfo.Headimg != "" {
|
|
|
|
+ formdata["headimg"] = userinfo.Headimg
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if userinfo.Password != "" {
|
|
|
|
+ formdata["password"] = userinfo.Password
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if userinfo.Nickname != "" {
|
|
|
|
+ formdata["nickname"] = userinfo.Nickname
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if userinfo.Phone != "" {
|
|
|
|
+ formdata["phone"] = userinfo.Phone
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if userinfo.Unionid != "" {
|
|
|
|
+ formdata["unionid"] = userinfo.Unionid
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ret, ok := PostUserCenter(href+UserCenterUpdate, ContentType_Json, userId, formdata, ck)
|
|
|
|
+ if ret != nil && ok {
|
|
|
|
+ status := IntAllDef((*ret)["status"], 0)
|
|
|
|
+ if status != 1 {
|
|
|
|
+ log.Printf("mysql同步数据失败,base_user_id:%s ,user_id :%s ,%+v", formdata["id"], userId, formdata)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//新增用户中台信息。并绑定mongodb表
|
|
|
|
+func AddBaseUser(mgo mongodb.MongodbSim, href, userId string, formdata map[string]interface{}, ck *http.Cookie) {
|
|
|
|
+ ret, ok := PostUserCenter(href+UserCenterAdd, ContentType_Json, userId, formdata, ck)
|
|
|
|
+ if ret != nil && ok {
|
|
|
|
+ base_id := Int64All((*ret)["id"])
|
|
|
|
+ if base_id == 0 {
|
|
|
|
+ log.Printf("新增用户中台获取base_user_id失败,userid:%s", userId)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+ //获取到mysql的用户id存入user表中
|
|
|
|
+ if ok := mgo.UpdateById("user", userId, map[string]interface{}{
|
|
|
|
+ "$set": map[string]interface{}{"base_user_id": base_id},
|
|
|
|
+ }); !ok {
|
|
|
|
+ log.Printf("mysql同步失败,base_user_id:%s ,userid:%s", base_id, userId)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+type UserIdentity struct {
|
|
|
|
+ PersonId int64 //自然人id
|
|
|
|
+ UserAccountId int64 //个人账户id
|
|
|
|
+ EntAccountId int64 //企业账户id
|
|
|
|
+ EntUserAccountId int64 //企业雇员账户id
|
|
|
|
+ UserPositionId int64 // 个人职位id
|
|
|
|
+ EntUserPositionId int64 // 企业雇员职位id
|
|
|
|
+ UserName string //昵称
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+//获取用户中台服务 用户相关账户参数
|
|
|
|
+func GetUserIdentity(href, userId string, baseUserId, entId int64, ck *http.Cookie) *UserIdentity {
|
|
|
|
+ ret, ok := PostUserCenter(href+UserCenterGetUserIdentity, ContentType_Json, userId,
|
|
|
|
+ map[string]interface{}{
|
|
|
|
+ "appId": "10000",
|
|
|
|
+ "newUserId": baseUserId,
|
|
|
|
+ "entId": entId,
|
|
|
|
+ }, ck)
|
|
|
|
+ if ret != nil && ok {
|
|
|
|
+ return &UserIdentity{
|
|
|
|
+ PersonId: Int64All((*ret)["personId"]),
|
|
|
|
+ EntAccountId: Int64All((*ret)["entAccountId"]),
|
|
|
|
+ UserAccountId: Int64All((*ret)["userAccountId"]),
|
|
|
|
+ EntUserAccountId: Int64All((*ret)["entUserAccountId"]),
|
|
|
|
+ UserPositionId: Int64All((*ret)["userPositionId"]),
|
|
|
|
+ EntUserPositionId: Int64All((*ret)["entUserPositionId"]),
|
|
|
|
+ UserName: ObjToString((*ret)["userName"]),
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return nil
|
|
|
|
+}
|