瀏覽代碼

Merge branch 'master' of https://jygit.jydev.jianyu360.cn/moapp/jypkg

fuwencai 1 年之前
父節點
當前提交
0db64187dc
共有 3 個文件被更改,包括 40 次插入29 次删除
  1. 19 11
      common/src/qfw/util/jy/userCenter.go
  2. 4 1
      common/src/qfw/util/jy/userPhoneUtil.go
  3. 17 17
      ent/entity/entity.go

+ 19 - 11
common/src/qfw/util/jy/userCenter.go

@@ -8,20 +8,28 @@ import (
 
 //获取base-user相关参数
 func AddUser(mgo mongodb.MongodbSim, userid string, req pb.UserAddReq, middleground middleground.Middleground) bool {
-	if resp := middleground.UserCenter.UserAdd(req); resp != nil {
-		//获取到baseid
+	retry := 3 // 设置重试次数
+	for i := 0; i < retry; i++ {
+		resp := middleground.UserCenter.UserAdd(req)
+		if resp == nil || resp.Data.Status != 1 {
+			continue // 如果调用失败或返回结果不是成功,则进行重试
+		}
+		// 获取到baseid
 		baseId := resp.Data.Id
-		if baseId > 0 {
-			//user表记录映射关系
-			ok := mgo.UpdateById("user", userid, map[string]interface{}{
-				"$set": map[string]interface{}{
-					"base_user_id": baseId,
-				},
-			})
-			return resp.Data.Status == 1 && ok
+		if baseId <= 0 {
+			continue // 如果获取到的baseid不合法,则进行重试
+		}
+		// user表记录映射关系
+		ok := mgo.UpdateById("user", userid, map[string]interface{}{
+			"$set": map[string]interface{}{
+				"base_user_id": baseId,
+			},
+		})
+		if ok {
+			return true // 如果MongoDB更新成功,则返回true
 		}
 	}
-	return false
+	return false // 如果重试多次后仍然失败,则返回false
 }
 
 //修改base-user相关参数

+ 4 - 1
common/src/qfw/util/jy/userPhoneUtil.go

@@ -184,7 +184,7 @@ return exists:是否存在
 
 rule 1.不存在手机号,2.存在手机号用户,但此手机号未绑定微信 3.存在手机号用户,或绑定微信和当前账户绑定微信一致
 */
-func (this *PhoneUtil) BindPhoneIsOccupy(unionId, phone string) (exists bool, relationPhoneId string) {
+func (this *PhoneUtil) BindPhoneIsOccupy(userId, unionId, phone string) (exists bool, relationPhoneId string) {
 	//已经有微信账户绑定过
 	if this.UserMgoDB.Count("user", map[string]interface{}{"i_appid": 2, "s_m_phone": phone, "s_phone": map[string]interface{}{"$exists": 0}}) > 0 {
 		return true, ""
@@ -207,6 +207,9 @@ func (this *PhoneUtil) BindPhoneIsOccupy(unionId, phone string) (exists bool, re
 		}
 	}
 	//但此手机号未绑定微信
+	if userId == relationPhoneId {
+		return true, ""
+	}
 	return false, relationPhoneId
 }
 

+ 17 - 17
ent/entity/entity.go

@@ -182,7 +182,7 @@ func (c *CurrentUser) PhoneIsOccupy(userId, phone string) (bool, int, string) {
 		if unionId == "" {
 			return true, 2, ""
 		}
-		exists, relationPhoneId := jy.NewPhoneUtil(MQFW).BindPhoneIsOccupy(unionId, phone)
+		exists, relationPhoneId := jy.NewPhoneUtil(MQFW).BindPhoneIsOccupy(userId, unionId, phone)
 		if !exists {
 			return false, 2, relationPhoneId
 		}
@@ -194,22 +194,22 @@ func (c *CurrentUser) PhoneIsOccupy(userId, phone string) (bool, int, string) {
 
 //绑定手机号
 func (c *CurrentUser) BindPhone(userId, phone, email string) (bool, int) {
-        isOccupy, appid, _ := c.PhoneIsOccupy(userId, phone)
-        if isOccupy {
-	      return false, appid
-        }
-        if appid == 2 {
-	      //商机管理绑定手机号需要和剑鱼保持一致,建立双向绑定关系
-	      //err := jy.NewPhoneUtil(MQFW).BindPhone(userId, relationPhoneId, phone, email, nil)\
-                var err error
-	      if err == nil {
-		    return true, appid
-	      }
-	      return false, appid
-        }
-        return MQFW.UpdateById("user", userId, map[string]interface{}{
-	      "$set": map[string]interface{}{"s_m_phone": phone},
-        }), appid
+	isOccupy, appid, _ := c.PhoneIsOccupy(userId, phone)
+	if isOccupy {
+		return false, appid
+	}
+	if appid == 2 {
+		//商机管理绑定手机号需要和剑鱼保持一致,建立双向绑定关系
+		//err := jy.NewPhoneUtil(MQFW).BindPhone(userId, relationPhoneId, phone, email, nil)\
+		var err error
+		if err == nil {
+			return true, appid
+		}
+		return false, appid
+	}
+	return MQFW.UpdateById("user", userId, map[string]interface{}{
+		"$set": map[string]interface{}{"s_m_phone": phone},
+	}), appid
 }
 
 //更换手机号