Browse Source

Merge branch 'fix_need_cygx3.2' of hongze/hongze_cygx into master

hongze 3 years ago
parent
commit
e1542fadb2
10 changed files with 507 additions and 112 deletions
  1. 63 13
      controllers/activity.go
  2. 129 9
      controllers/user.go
  3. 77 0
      models/activity_signup.go
  4. 81 15
      models/user.go
  5. 105 61
      models/wx_user.go
  6. 24 0
      services/activity.go
  7. 2 1
      services/task.go
  8. 17 11
      services/user.go
  9. 6 0
      utils/common.go
  10. 3 2
      utils/constants.go

+ 63 - 13
controllers/activity.go

@@ -644,6 +644,9 @@ func (this *ActivityCoAntroller) SignupAdd() {
 	activityId := req.ActivityId
 	signupType := req.SignupType
 	hasPermission := 0
+	if signupType == 1 && user.Mobile == "" && user.OutboundMobile == "" {
+		resp.GoBindEmail = true
+	}
 	//判断是否已经申请过
 	applyCount, err := models.GetApplyRecordCount(uid)
 	if err != nil && err.Error() != utils.ErrNoRow() {
@@ -834,7 +837,7 @@ func (this *ActivityCoAntroller) SignupAdd() {
 					return
 				}
 				//解除报名限制之后二次报名相同活动
-				if totalUserRestrictCount > 0 && totalRestrict == 0 {
+				if totalUserRestrictCount > 0 && totalRestrict == 0 && resp.GoBindEmail != true {
 					item.UserId = uid
 					item.ActivityId = activityId
 					item.CreateTime = time.Now()
@@ -878,7 +881,7 @@ func (this *ActivityCoAntroller) SignupAdd() {
 					return
 				}
 
-				if signupStatus != "Success" && totalMy == 0 {
+				if signupStatus != "Success" && totalMy == 0 && resp.GoBindEmail != true {
 					item.UserId = uid
 					item.ActivityId = activityId
 					item.CreateTime = time.Now()
@@ -888,13 +891,21 @@ func (this *ActivityCoAntroller) SignupAdd() {
 					item.CompanyName = user.CompanyName
 					item.SignupType = signupType
 					item.DoFailType = item.FailType
-					item.OutboundMobile = user.Mobile
-					if user.CountryCode == "" {
-						item.CountryCode = "86"
+					if user.OutboundMobile != "" {
+						item.OutboundMobile = user.OutboundMobile
+						if user.OutboundCountryCode == "" {
+							item.CountryCode = "86"
+						} else {
+							item.CountryCode = user.OutboundCountryCode
+						}
 					} else {
-						item.CountryCode = user.CountryCode
+						item.OutboundMobile = user.Mobile
+						if user.CountryCode == "" {
+							item.CountryCode = "86"
+						} else {
+							item.CountryCode = user.CountryCode
+						}
 					}
-
 					//添加报名信息,但是不加入日程
 					_, errSignup := models.AddActivitySignupNoSchedule(item)
 					if errSignup != nil {
@@ -905,8 +916,6 @@ func (this *ActivityCoAntroller) SignupAdd() {
 				}
 			}
 			totalMySuccess, err := models.GetActivitySignupCount(uid, activityId)
-			fmt.Println(totalMySuccess)
-			fmt.Println(signupStatus)
 			if err != nil {
 				br.Msg = "获取失败"
 				br.ErrMsg = "获取失败,Err:" + err.Error()
@@ -916,7 +925,7 @@ func (this *ActivityCoAntroller) SignupAdd() {
 				br.Msg = "您已报名这个活动"
 				return
 			}
-			if signupStatus == "Success" {
+			if signupStatus == "Success" && resp.GoBindEmail != true {
 				item.UserId = uid
 				item.ActivityId = activityId
 				item.CreateTime = time.Now()
@@ -928,10 +937,20 @@ func (this *ActivityCoAntroller) SignupAdd() {
 				item.FailType = 0
 				item.DoFailType = 0
 				item.OutboundMobile = user.Mobile
-				if user.CountryCode == "" {
-					item.CountryCode = "86"
+				if user.OutboundMobile != "" {
+					item.OutboundMobile = user.OutboundMobile
+					if user.OutboundCountryCode == "" {
+						item.CountryCode = "86"
+					} else {
+						item.CountryCode = user.OutboundCountryCode
+					}
 				} else {
-					item.CountryCode = user.CountryCode
+					item.OutboundMobile = user.Mobile
+					if user.CountryCode == "" {
+						item.CountryCode = "86"
+					} else {
+						item.CountryCode = user.CountryCode
+					}
 				}
 				_, errSignup := models.AddActivitySignup(item)
 				if errSignup != nil {
@@ -964,6 +983,37 @@ func (this *ActivityCoAntroller) SignupAdd() {
 		resp.OperationMode = "Apply"
 		resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
 	}
+	if signupType == 1 && user.IsMsgOutboundMobile == 0 {
+		resp.GoOutboundMobile = true
+		if user.Mobile != "" || user.OutboundMobile != "" {
+			go models.ModifyWxUserIsMsgOutboundMobile(user.UserId)
+		}
+	}
+	if user.OutboundMobile == "" {
+		resp.Mobile = user.Mobile
+		if user.CountryCode == "" && len(user.Mobile) == 11 {
+			resp.CountryCode = "86"
+		} else {
+			resp.CountryCode = user.CountryCode
+		}
+	} else {
+		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

+ 129 - 9
controllers/user.go

@@ -986,16 +986,21 @@ func (this *UserController) CountryCcode() {
 		br.Ret = 408
 		return
 	}
-	detail, err := models.GetUserDetailByUserId(uid)
-	if err != nil {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取信息失败,Err:" + err.Error()
-		return
-	}
 	resp := new(models.CountryCode)
-	if len(detail.Mobile) != 11 && detail.CountryCode == "" {
+	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 != "" {
+		resp.IsNeedAddCountryCode = false
+	}
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -1014,7 +1019,6 @@ func (this *UserController) AddCountryCcode() {
 		this.ServeJSON()
 	}()
 	user := this.User
-	uid := user.UserId
 	if user == nil {
 		br.Msg = "请登录"
 		br.ErrMsg = "请登录,用户信息为空"
@@ -1028,7 +1032,7 @@ func (this *UserController) AddCountryCcode() {
 		br.ErrMsg = "参数解析失败,Err:" + err.Error()
 		return
 	}
-	err = models.AddCountryCode(req.CountryCode, uid)
+	err = models.AddCountryCode(req.CountryCode, user)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取信息失败,Err:" + err.Error()
@@ -1038,3 +1042,119 @@ func (this *UserController) AddCountryCcode() {
 	br.Success = true
 	br.Msg = "新增成功"
 }
+
+//// @Title 是否需要填写外呼手机号
+//// @Description 获取是否需要填写外呼手机号接口
+//// @Success 200 {object} models.CountryCode
+//// @router /countryCcode/isNeedAddOutbound [get]
+//func (this *UserController) OutboundMobile() {
+//	br := new(models.BaseResponse).Init()
+//	defer func() {
+//		this.Data["json"] = br
+//		this.ServeJSON()
+//	}()
+//	user := this.User
+//	uid := user.UserId
+//	if user == nil {
+//		br.Msg = "请登录"
+//		br.ErrMsg = "请登录,用户信息为空"
+//		br.Ret = 408
+//		return
+//	}
+//	if uid == 0 {
+//		br.Msg = "请登录"
+//		br.ErrMsg = "请登录,用户信息为空"
+//		br.Ret = 408
+//		return
+//	}
+//	resp := new(models.OutboundMobile)
+//	if user.OutboundMobile == "" && user.CountryCode == "" {
+//		resp.IsNeedAddOutboundMobile = true
+//	}
+//	br.Ret = 200
+//	br.Success = true
+//	br.Msg = "获取成功"
+//	br.Data = resp
+//}
+
+// @Title 用户修改外呼手机号以及区号
+// @Description 用户修改外呼手机号以及区号接口
+// @Param	request	body models.OutboundMobileItem true "type json string"
+// @Success Ret=200 操作成功
+// @router /countryCcode/addOutboundMobile [POST]
+func (this *UserController) AddOutboundMobile() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	uid := user.UserId
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req models.OutboundMobileItem
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	if !utils.ValidateFixedTelephoneFormatat(req.OutboundMobile) && !utils.ValidateMobileFormatat(req.OutboundMobile) {
+		br.Msg = "号码格式有误,请重新填写!"
+		br.ErrMsg = "号码格式有误,请重新填写" + req.OutboundMobile
+		return
+	}
+	if req.OutboundMobile == "" {
+		br.Msg = "请填写区号!"
+		return
+	}
+	item := new(models.OutboundMobileItem)
+	item.OutboundMobile = req.OutboundMobile
+	item.OutboundCountryCode = req.OutboundCountryCode
+	item.ActivityId = req.ActivityId
+	if req.ActivityId == 0 {
+		err = models.AddOutboundMobile(item, uid)
+	} else {
+		if user.Mobile == "" && user.OutboundMobile == "" {
+			items := new(models.CygxActivitySignup)
+			items.UserId = uid
+			items.ActivityId = req.ActivityId
+			items.CreateTime = time.Now()
+			items.Mobile = user.Mobile
+			items.Email = user.Email
+			items.CompanyId = user.CompanyId
+			items.CompanyName = user.CompanyName
+			items.SignupType = 1
+			items.FailType = 0
+			items.DoFailType = 0
+			items.OutboundMobile = req.OutboundMobile
+			items.CountryCode = req.OutboundCountryCode
+			_, err = models.AddActivitySignupFromEmail(items)
+		} else {
+			total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
+			if total == 0 {
+				br.Msg = "报名信息不存在"
+				br.ErrMsg = "报名信息不存在,Err:" + "活动ActivityId:" + strconv.Itoa(item.ActivityId) + "用户Uid:" + strconv.Itoa(uid)
+				return
+			}
+			if err != nil {
+				br.Msg = "操作失败"
+				br.ErrMsg = "操作失败,Err:" + err.Error()
+				return
+			}
+			err = models.AddOutboundMobile(item, uid)
+		}
+	}
+	if err != nil {
+		br.Msg = "操作失败"
+		br.ErrMsg = "操作失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 77 - 0
models/activity_signup.go

@@ -34,6 +34,10 @@ type SignupStatus struct {
 	SellerMobile      string `description:"销售电话"`
 	MsgType           string `description:"Type : 类型 , Industry : 行业"`
 	SellerName        string `description:"销售姓名"`
+	Mobile            string `description:"外呼手机号"`
+	CountryCode       string `description:"外呼手机号区号"`
+	GoOutboundMobile  bool   `description:"是否去绑定手机号"`
+	GoBindEmail       bool   `description:"是否去绑定邮箱"`
 }
 
 //我的日程
@@ -121,6 +125,71 @@ func AddActivitySignup(item *CygxActivitySignup) (lastId int64, err error) {
 	return
 }
 
+//仅绑定邮箱的用户修改报名后,添加报名信息
+func AddActivitySignupFromEmail(item *CygxActivitySignup) (lastId int64, err error) {
+	o := orm.NewOrm()
+	o.Begin()
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	var count int
+	var countMySchedule int
+	sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ? ,is_msg_outbound_mobile = 1   WHERE user_id=? `
+	_, err = o.Raw(sql, item.OutboundMobile, item.CountryCode, item.UserId).Exec()
+	if err != nil {
+		return
+	}
+	sql = `SELECT COUNT(1) AS count FROM cygx_my_schedule WHERE user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&countMySchedule)
+	if err != nil {
+		return
+	}
+	if countMySchedule == 0 {
+		itemMy := new(CygxMySchedule)
+		itemMy.UserId = item.UserId
+		itemMy.ActivityId = item.ActivityId
+		itemMy.CreateTime = time.Now()
+		itemMy.Mobile = item.Mobile
+		itemMy.Email = item.Email
+		itemMy.CompanyId = item.CompanyId
+		itemMy.CompanyName = item.CompanyName
+		lastId, err = o.Insert(itemMy)
+		if err != nil {
+			return
+		}
+	}
+	sql = `SELECT COUNT(1) AS count FROM cygx_activity_signup WHERE user_id=? AND activity_id=? `
+	err = o.Raw(sql, item.UserId, item.ActivityId).QueryRow(&count)
+	if err != nil {
+		return
+	}
+	if count > 0 {
+		sql := `UPDATE cygx_activity_signup SET is_cancel = 0 ,do_fail_type = 0, signup_type=? WHERE user_id=?  AND activity_id=? `
+		_, err = o.Raw(sql, item.SignupType, item.UserId, item.ActivityId).Exec()
+	} else {
+		lastId, err = o.Insert(item)
+	}
+	if err != nil {
+		return
+	}
+	itemLog := new(CygxActivitySignupLog)
+	itemLog.UserId = item.UserId
+	itemLog.ActivityId = item.ActivityId
+	itemLog.CreateTime = time.Now()
+	itemLog.Mobile = item.Mobile
+	itemLog.Email = item.Email
+	itemLog.CompanyId = item.CompanyId
+	itemLog.CompanyName = item.CompanyName
+	itemLog.Type = 1
+	lastId, err = o.Insert(itemLog)
+	return
+}
+
 //添加报名信息
 func AddActivitySignupNoSchedule(item *CygxActivitySignup) (lastId int64, err error) {
 	o := orm.NewOrm()
@@ -320,3 +389,11 @@ func UPdateSignup(item *CygxActivitySignup) (err error) {
 	_, err = o.Raw(sql, item.Mobile, item.Id).Exec()
 	return
 }
+
+//获取数量
+func GetActivityCountByIdWithUid(activityId, Uid int) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := `SELECT COUNT(1) AS count  FROM cygx_activity_signup WHERE activity_id = ? AND user_id = ?`
+	err = o.Raw(sqlCount, activityId, Uid).QueryRow(&count)
+	return
+}

+ 81 - 15
models/user.go

@@ -1,6 +1,7 @@
 package models
 
 import (
+	"fmt"
 	"hongze/hongze_cygx/utils"
 	"rdluck_tools/orm"
 	"rdluck_tools/paging"
@@ -8,18 +9,20 @@ import (
 )
 
 type UserDetail struct {
-	Headimgurl     string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
-	Mobile         string `description:"手机号码"`
-	Email          string `description:"邮箱"`
-	NickName       string `description:"用户昵称"`
-	RealName       string `description:"用户实际名称"`
-	CompanyName    string `description:"公司名称"`
-	PermissionName string `description:"拥有权限分类,多个用英文逗号分隔"`
-	HasPermission  int    `description:"1:无该行业权限,不存在权益客户下,2:潜在客户,未提交过申请,3:潜在客户,已提交过申请"`
-	SellerMobile   string `description:"销售手机号"`
-	SellerName     string `description:"销售名称"`
-	Note           string `json:"-" description:"申请提交时,公司名称"`
-	CountryCode    string `description:"区号"`
+	Headimgurl          string `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	Mobile              string `description:"手机号码"`
+	Email               string `description:"邮箱"`
+	NickName            string `description:"用户昵称"`
+	RealName            string `description:"用户实际名称"`
+	CompanyName         string `description:"公司名称"`
+	PermissionName      string `description:"拥有权限分类,多个用英文逗号分隔"`
+	HasPermission       int    `description:"1:无该行业权限,不存在权益客户下,2:潜在客户,未提交过申请,3:潜在客户,已提交过申请"`
+	SellerMobile        string `description:"销售手机号"`
+	SellerName          string `description:"销售名称"`
+	Note                string `json:"-" description:"申请提交时,公司名称"`
+	CountryCode         string `description:"区号"`
+	OutboundMobile      string `description:"外呼手机号"`
+	OutboundCountryCode string `description:"外呼手机号区号"`
 }
 
 func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
@@ -200,13 +203,76 @@ type CountryCode struct {
 	IsNeedAddCountryCode bool `description:"是否需要填写区号:需要填写,false:不需要填写"`
 }
 
+type OutboundMobile struct {
+	IsNeedAddOutboundMobile bool `description:"是否需要填写外呼手机号:需要填写,false:不需要填写"`
+}
+
 type CountryCodeItem struct {
 	CountryCode string `description:"区号"`
 }
 
-func AddCountryCode(CountryCode string, userId int) (err error) {
+func AddCountryCode(CountryCode string, user *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	if user.OutboundCountryCode == "" {
+		sql := `UPDATE wx_user SET country_code=?,outbound_mobile=?,outbound_country_code=?  WHERE user_id=? `
+		_, err = o.Raw(sql, CountryCode, user.OutboundMobile, user.OutboundCountryCode, user.UserId).Exec()
+	} else {
+		sql := `UPDATE wx_user SET country_code=? WHERE user_id=? `
+		_, err = o.Raw(sql, CountryCode, user.UserId).Exec()
+	}
+	return
+}
+
+//修改外呼手机号
+type OutboundMobileItem struct {
+	OutboundMobile      string `description:"外呼手机号"`
+	OutboundCountryCode string `description:"外呼手机号区号"`
+	ActivityId          int    `description:"活动ID"`
+}
+
+func AddOutboundMobile(item *OutboundMobileItem, userId int) (err error) {
+	o := orm.NewOrm()
+	o.Begin()
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, is_msg_outbound_mobile= 1 WHERE user_id=? `
+	_, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId).Exec()
+	if err != nil {
+		return
+	}
+	if item.ActivityId > 0 {
+		sql = `UPDATE cygx_activity_signup SET outbound_mobile=? ,country_code = ?  WHERE user_id=? AND  activity_id = ?`
+		_, err = o.Raw(sql, item.OutboundMobile, item.OutboundCountryCode, userId, item.ActivityId).Exec()
+	}
+	return
+}
+
+//用户绑定手机号时同时绑定外呼手机号
+func BindUserOutboundMobile(mobile, countryCode string, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET outbound_mobile=? ,outbound_country_code = ?, country_code= ? WHERE user_id=? `
+	_, 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=? WHERE user_id=? `
-	_, err = o.Raw(sql, CountryCode, userId).Exec()
+	sql := `UPDATE wx_user SET country_code = 86 WHERE user_id=? `
+	_, err = o.Raw(sql, userId).Exec()
 	return
 }

+ 105 - 61
models/wx_user.go

@@ -6,46 +6,48 @@ import (
 )
 
 type WxUser struct {
-	UserId           int       `orm:"column(user_id);pk"`
-	OpenId           string    `description:"open_id"`
-	UnionId          string    `description:"union_id"`
-	Subscribe        string    `description:"是否关注"`
-	CompanyId        int       `description:"客户id"`
-	NickName         string    `description:"用户昵称"`
-	RealName         string    `description:"用户实际名称"`
-	UserCode         string    `description:"用户编码"`
-	Mobile           string    `description:"手机号码"`
-	BindAccount      string    `description:"绑定时的账号"`
-	WxCode           string    `description:"微信号"`
-	Profession       string    `description:"职业"`
-	Email            string    `description:"邮箱"`
-	Telephone        string    `description:"座机"`
-	Sex              int       `description:"普通用户性别,1为男性,2为女性"`
-	Province         string    `description:"普通用户个人资料填写的省份"`
-	City             string    `description:"普通用户个人资料填写的城市"`
-	Country          string    `description:"国家,如中国为CN"`
-	SubscribeTime    int       `description:"关注时间"`
-	Remark           string    `description:"备注"`
-	Headimgurl       string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
-	Privilege        string    `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
-	Unionid          string    `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
-	FirstLogin       int       `description:"是否第一次登陆"`
-	Enabled          int       `description:"是否可用"`
-	CreatedTime      time.Time `description:"创建时间"`
-	LastUpdatedTime  time.Time `description:"最新一次修改时间"`
-	Seller           string    `description:"销售员"`
-	Note             string    `description:"客户备份信息"`
-	IsNote           int       `description:"是否备注过信息"`
-	FromType         string    `description:"report' COMMENT 'report:研报,teleconference:电话会"`
-	ApplyMethod      int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
-	RegisterTime     time.Time `description:"注册时间"`
-	RegisterPlatform int       `description:"注册平台,1:微信端,2:PC网页端"`
-	IsFreeLogin      bool      `description:"是否免登陆,true:免登陆,false:非免登陆"`
-	LoginTime        time.Time `description:"最近一次登录时间"`
-	SessionKey       string    `description:"微信小程序会话密钥"`
-	IsRegister       int       `description:"是否注册:1:已注册,0:未注册"`
-	Source           int       `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
-	CountryCode      string    `description:"区号"`
+	UserId              int       `orm:"column(user_id);pk"`
+	OpenId              string    `description:"open_id"`
+	UnionId             string    `description:"union_id"`
+	Subscribe           string    `description:"是否关注"`
+	CompanyId           int       `description:"客户id"`
+	NickName            string    `description:"用户昵称"`
+	RealName            string    `description:"用户实际名称"`
+	UserCode            string    `description:"用户编码"`
+	Mobile              string    `description:"手机号码"`
+	BindAccount         string    `description:"绑定时的账号"`
+	WxCode              string    `description:"微信号"`
+	Profession          string    `description:"职业"`
+	Email               string    `description:"邮箱"`
+	Telephone           string    `description:"座机"`
+	Sex                 int       `description:"普通用户性别,1为男性,2为女性"`
+	Province            string    `description:"普通用户个人资料填写的省份"`
+	City                string    `description:"普通用户个人资料填写的城市"`
+	Country             string    `description:"国家,如中国为CN"`
+	SubscribeTime       int       `description:"关注时间"`
+	Remark              string    `description:"备注"`
+	Headimgurl          string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	Privilege           string    `description:"用户特权信息,json数组,如微信沃卡用户为(chinaunicom)"`
+	Unionid             string    `description:"用户统一标识。针对一个微信开放平台帐号下的应用,同一用户的unionid是唯一的。"`
+	FirstLogin          int       `description:"是否第一次登陆"`
+	Enabled             int       `description:"是否可用"`
+	CreatedTime         time.Time `description:"创建时间"`
+	LastUpdatedTime     time.Time `description:"最新一次修改时间"`
+	Seller              string    `description:"销售员"`
+	Note                string    `description:"客户备份信息"`
+	IsNote              int       `description:"是否备注过信息"`
+	FromType            string    `description:"report' COMMENT 'report:研报,teleconference:电话会"`
+	ApplyMethod         int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
+	RegisterTime        time.Time `description:"注册时间"`
+	RegisterPlatform    int       `description:"注册平台,1:微信端,2:PC网页端"`
+	IsFreeLogin         bool      `description:"是否免登陆,true:免登陆,false:非免登陆"`
+	LoginTime           time.Time `description:"最近一次登录时间"`
+	SessionKey          string    `description:"微信小程序会话密钥"`
+	IsRegister          int       `description:"是否注册:1:已注册,0:未注册"`
+	Source              int       `description:"绑定来源,1:微信端,2:pc网页端,3:查研观向小程序,4:每日咨询"`
+	CountryCode         string    `description:"区号"`
+	OutboundMobile      string    `description:"外呼手机号"`
+	OutboundCountryCode string    `description:"外呼手机号区号"`
 }
 
 //添加用户信息
@@ -56,27 +58,30 @@ func AddWxUser(item *WxUser) (lastId int64, err error) {
 }
 
 type WxUserItem struct {
-	UserId          int       `description:"用户id"`
-	OpenId          string    `description:"open_id"`
-	UnionId         string    `description:"union_id"`
-	CompanyId       int       `description:"客户id"`
-	NickName        string    `description:"用户昵称"`
-	RealName        string    `description:"用户实际名称"`
-	Mobile          string    `description:"手机号码"`
-	BindAccount     string    `description:"绑定时的账号"`
-	Email           string    `description:"邮箱"`
-	Headimgurl      string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
-	ApplyMethod     int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
-	FirstLogin      int       `description:"是否第一次登陆"`
-	IsFreeLogin     int       `description:"是否免登陆,true:免登陆,false:非免登陆"`
-	LoginTime       time.Time `description:"登录时间"`
-	CreatedTime     time.Time `description:"创建时间"`
-	LastUpdatedTime time.Time `description:"最近一次修改时间"`
-	SessionKey      string    `description:"微信小程序会话密钥"`
-	CompanyName     string    `description:"公司名称"`
-	IsRegister      int       `description:"是否注册:1:已注册,0:未注册"`
-	CountryCode     string    `description:"手机国家区号"`
-	Source          int
+	UserId              int       `description:"用户id"`
+	OpenId              string    `description:"open_id"`
+	UnionId             string    `description:"union_id"`
+	CompanyId           int       `description:"客户id"`
+	NickName            string    `description:"用户昵称"`
+	RealName            string    `description:"用户实际名称"`
+	Mobile              string    `description:"手机号码"`
+	BindAccount         string    `description:"绑定时的账号"`
+	Email               string    `description:"邮箱"`
+	Headimgurl          string    `description:"用户头像,最后一个数值代表正方形头像大小(有0、46、64、96、132数值可选,0代表640*640正方形头像),用户没有头像时该项为空"`
+	ApplyMethod         int       `description:"0:未申请,1:已付费客户申请试用,2:非客户申请试用"`
+	FirstLogin          int       `description:"是否第一次登陆"`
+	IsFreeLogin         int       `description:"是否免登陆,true:免登陆,false:非免登陆"`
+	LoginTime           time.Time `description:"登录时间"`
+	CreatedTime         time.Time `description:"创建时间"`
+	LastUpdatedTime     time.Time `description:"最近一次修改时间"`
+	SessionKey          string    `description:"微信小程序会话密钥"`
+	CompanyName         string    `description:"公司名称"`
+	IsRegister          int       `description:"是否注册:1:已注册,0:未注册"`
+	CountryCode         string    `description:"手机国家区号"`
+	OutboundMobile      string    `description:"外呼手机号"`
+	OutboundCountryCode string    `description:"外呼手机号区号"`
+	IsMsgOutboundMobile int       `description:"是否弹窗过绑定外呼手机号区号"`
+	Source              int
 }
 
 func GetWxUserItemByUnionid(unionid string) (item *WxUserItem, err error) {
@@ -206,3 +211,42 @@ func ModifyWxUserRegisterStatus(userId int) (err error) {
 	_, err = o.Raw(sql, 1, userId).Exec()
 	return
 }
+
+//修改用户是否绑定外呼手机号弹窗
+func ModifyWxUserIsMsgOutboundMobile(userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET is_msg_outbound_mobile=1 WHERE user_id=? `
+	_, err = o.Raw(sql, userId).Exec()
+	return
+}
+
+//列表
+func GetUserListAll() (items []*WxUserItem, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM wx_user  WHERE mobile <>'' AND outbound_mobile = ''`
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}
+
+//修改手机号区号  8位号码+852,9位号码+886,10位号码+1,11位及以上号码+86
+func UPdateUserCountryCode(item *WxUserItem) (err error) {
+	o := orm.NewOrm()
+	if item.CountryCode == "" && len(item.Mobile) >= 11 {
+		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=86 , country_code=86  WHERE user_id = ?`
+		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
+	} else if item.CountryCode == "" && len(item.Mobile) == 8 {
+		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=852 , country_code=852  WHERE user_id = ?`
+		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
+	} else if item.CountryCode == "" && len(item.Mobile) == 9 {
+		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=886 , country_code=886  WHERE user_id = ?`
+		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
+	} else if item.CountryCode == "" && len(item.Mobile) == 10 {
+		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=1 , country_code=1  WHERE user_id = ?`
+		_, err = o.Raw(sql, item.Mobile, item.UserId).Exec()
+	} else {
+		sql := ` UPDATE wx_user SET  outbound_mobile= ? , outbound_country_code=?  WHERE user_id = ?`
+		_, err = o.Raw(sql, item.Mobile, item.CountryCode, item.UserId).Exec()
+	}
+
+	return
+}

+ 24 - 0
services/activity.go

@@ -277,3 +277,27 @@ func EditOutboundMobile(cont context.Context) (err error) {
 	fmt.Println("修改完成")
 	return
 }
+
+//同步用户绑定手机号以及区号
+func EditUserOutboundMobile(cont context.Context) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println("发送失败,Err:", err.Error())
+		}
+	}()
+
+	list, err := models.GetUserListAll()
+	if err != nil {
+		fmt.Println("GetActivitySendMsgListAll Err:", err.Error())
+		return
+	}
+	for _, v := range list {
+		err = models.UPdateUserCountryCode(v)
+		fmt.Println("修改:", strconv.Itoa(v.UserId))
+		if err != nil {
+			fmt.Println("发送失败,Err:", err.Error()+strconv.Itoa(v.UserId))
+		}
+	}
+	fmt.Println("修改完成")
+	return
+}

+ 2 - 1
services/task.go

@@ -53,7 +53,8 @@ func Task() {
 
 	//editOutboundMobile := task.NewTask("editOutboundMobile", "0 */1 8-22 * * *", EditOutboundMobile) //同步外呼号码与手机号
 	//task.AddTask("sendEmailFileToExpert", editOutboundMobile)
-	//UpdateActivitySattus()
+	//editUserOutboundMobile := task.NewTask("editUserOutboundMobile", "0 27 14 * * *   ", EditUserOutboundMobile) //同步外呼号码与手机号
+	//task.AddTask("editUserOutboundMobile", editUserOutboundMobile)
 	task.StartTask()
 	fmt.Println("end")
 }

+ 17 - 11
services/user.go

@@ -202,17 +202,19 @@ func BindWxUser(openid, mobile, email, countryCode string) (wxUser *models.WxUse
 	//如果查询出来的用户是nil,那么需要新增用户
 	if wxUser == nil {
 		user := &models.WxUser{
-			CompanyId:        1,
-			CreatedTime:      time.Now(),
-			FirstLogin:       1,
-			Enabled:          1,
-			RegisterPlatform: 4,
-			RegisterTime:     time.Now(),
-			Mobile:           mobile,
-			Email:            email,
-			IsRegister:       1,
-			Source:           3,
-			CountryCode:      countryCode,
+			CompanyId:           1,
+			CreatedTime:         time.Now(),
+			FirstLogin:          1,
+			Enabled:             1,
+			RegisterPlatform:    4,
+			RegisterTime:        time.Now(),
+			Mobile:              mobile,
+			Email:               email,
+			IsRegister:          1,
+			Source:              3,
+			CountryCode:         countryCode,
+			OutboundMobile:      mobile,
+			OutboundCountryCode: countryCode,
 		}
 		tmpUserId, addUserErr := models.AddWxUser(user)
 		if err != nil {
@@ -224,6 +226,10 @@ func BindWxUser(openid, mobile, email, countryCode string) (wxUser *models.WxUse
 		wxUser, err = models.GetWxUserItemByUserId(userId)
 	} else {
 		userId = wxUser.UserId
+		err = models.BindUserOutboundMobile(mobile, countryCode, userId)
+		if err != nil {
+			return
+		}
 		if wxUser.IsRegister == 0 {
 			models.ModifyWxUserRegisterStatus(userId)
 		}

+ 6 - 0
utils/common.go

@@ -215,6 +215,12 @@ func ValidateMobileFormatat(mobileNum string) bool {
 	return reg.MatchString(mobileNum)
 }
 
+//验证是否是固定电话
+func ValidateFixedTelephoneFormatat(mobileNum string) bool {
+	reg := regexp.MustCompile(RegularFixedTelephone)
+	return reg.MatchString(mobileNum)
+}
+
 //判断文件是否存在
 func FileIsExist(filePath string) bool {
 	_, err := os.Stat(filePath)

+ 3 - 2
utils/constants.go

@@ -26,8 +26,9 @@ const (
 
 //手机号,电子邮箱正则
 const (
-	RegularMobile = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
-	RegularEmail  = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
+	RegularMobile         = "^((13[0-9])|(14[5|7])|(15([0-3]|[5-9]))|(18[0-9])|(17[0-9])|(16[0-9])|(19[0-9]))\\d{8}$" //手机号码
+	RegularFixedTelephone = "^(\\(\\d{3,4}\\)|\\d{3,4}-|\\s)?\\d{7,14}$"                                              //手机号码
+	RegularEmail          = `\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*`                                             //匹配电子邮箱
 )
 
 //聚合短信