xingzai 3 年之前
父節點
當前提交
7df185eec4
共有 3 個文件被更改,包括 39 次插入1 次删除
  1. 14 0
      controllers/activity.go
  2. 9 1
      controllers/user.go
  3. 16 0
      models/user.go

+ 14 - 0
controllers/activity.go

@@ -1000,6 +1000,20 @@ func (this *ActivityCoAntroller) SignupAdd() {
 		resp.Mobile = user.OutboundMobile
 		resp.CountryCode = user.OutboundCountryCode
 	}
+	//如果用户有绑定手机号,但是没有绑定外呼手机号
+	if signupType == 1 && user.Mobile != "" && user.OutboundMobile == "" {
+		var countryCode string
+		if len(user.Mobile) == 8 {
+			countryCode = "852"
+		} else if len(user.Mobile) == 9 {
+			countryCode = "886"
+		} else if len(user.Mobile) == 10 {
+			countryCode = "1"
+		} else if len(user.Mobile) >= 11 {
+			countryCode = "86"
+		}
+		models.BindUserOutboundMobileByMobile(user.Mobile, countryCode, uid)
+	}
 	resp.SignupType = signupType
 	resp.SignupStatus = signupStatus
 	resp.HasPermission = hasPermission

+ 9 - 1
controllers/user.go

@@ -987,7 +987,15 @@ func (this *UserController) CountryCcode() {
 		return
 	}
 	resp := new(models.CountryCode)
-	if user.CountryCode == "" && user.Mobile != "" {
+	if user.CountryCode == "" && len(user.Mobile) >= 11 {
+		err := models.ChangeUserOutboundMobileByMobile(uid)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
+	}
+	if user.CountryCode == "" && user.Mobile != "" && len(user.Mobile) < 11 {
 		resp.IsNeedAddCountryCode = true
 	}
 	if user.OutboundMobile != "" {

+ 16 - 0
models/user.go

@@ -260,3 +260,19 @@ func BindUserOutboundMobile(mobile, countryCode string, userId int) (err error)
 	_, err = o.Raw(sql, mobile, countryCode, countryCode, userId).Exec()
 	return
 }
+
+//已经绑定手机号,没有绑定外呼手机号的的用户,预约外呼的时候,将外呼手机号同步成手机号
+func BindUserOutboundMobileByMobile(mobile, countryCode string, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? WHERE user_id=? `
+	_, err = o.Raw(sql, mobile, countryCode, userId).Exec()
+	return
+}
+
+//将手机号为11位的用户,区号默认设置为86
+func ChangeUserOutboundMobileByMobile(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET country_code = 86 WHERE user_id=? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}