|
@@ -4,6 +4,7 @@ import (
|
|
|
"encoding/json"
|
|
|
"io/ioutil"
|
|
|
"log"
|
|
|
+ "mongodb"
|
|
|
"net/http"
|
|
|
"qfw/util/jwt"
|
|
|
"strings"
|
|
@@ -11,8 +12,6 @@ import (
|
|
|
|
|
|
var ContentType_Json = "application/json"
|
|
|
|
|
|
-// var UserCenterAdd = "http://192.168.21.47:9999/userCenter/user/add"
|
|
|
-// var UserCenterAdd = "http://192.168.3.240:9999/userCenter/user/add"
|
|
|
var UserCenterAdd = "/userCenter/user/add"
|
|
|
var UserCenterUpdate = "/userCenter/user/updateById"
|
|
|
var UserCenterDelete = "/userCenter/user/deleteById"
|
|
@@ -52,6 +51,7 @@ func PostUserCenter(url, contentTpe, userid string, data map[string]interface{},
|
|
|
return nil, false
|
|
|
}
|
|
|
log.Println("token jwt:", token)
|
|
|
+ log.Println("data:", data)
|
|
|
data_str, err := json.Marshal(data)
|
|
|
if err != nil {
|
|
|
log.Printf("%s序列化失败%+v", userid, data)
|
|
@@ -79,3 +79,142 @@ func PostUserCenter(url, contentTpe, userid string, data map[string]interface{},
|
|
|
}
|
|
|
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)
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|