Browse Source

用户修改预约外呼手机号

xingzai 3 years ago
parent
commit
39ab54a8f4
5 changed files with 198 additions and 33 deletions
  1. 16 0
      controllers/activity.go
  2. 90 0
      controllers/user.go
  3. 11 0
      models/activity_signup.go
  4. 49 12
      models/user.go
  5. 32 21
      models/wx_user.go

+ 16 - 0
controllers/activity.go

@@ -964,6 +964,21 @@ func (this *ActivityCoAntroller) SignupAdd() {
 		resp.OperationMode = "Apply"
 		resp.PopupMsg = "您暂无权限参加 【" + activityInfo.ChartPermissionName + "】行业活动,若想参加可以申请开通哦"
 	}
+	if signupType == 1 && user.IsMsgOutboundMobile == 0 {
+		resp.GoOutboundMobile = true
+		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
+	}
 	resp.SignupType = signupType
 	resp.SignupStatus = signupStatus
 	resp.HasPermission = hasPermission
@@ -979,6 +994,7 @@ func (this *ActivityCoAntroller) SignupAdd() {
 	if total <= 1 {
 		resp.GoFollow = true
 	}
+
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "操作成功"

+ 90 - 0
controllers/user.go

@@ -1038,3 +1038,93 @@ 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 == "" {
+		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
+	}
+	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 {
+		total, err := models.GetActivityCountByIdWithUid(item.ActivityId, uid)
+		if err != nil {
+			br.Msg = "操作失败"
+			br.ErrMsg = "操作失败,Err:" + err.Error()
+			return
+		}
+		err = models.AddOutboundMobile(item, 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
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 11 - 0
models/activity_signup.go

@@ -34,6 +34,9 @@ type SignupStatus struct {
 	SellerMobile      string `description:"销售电话"`
 	MsgType           string `description:"Type : 类型 , Industry : 行业"`
 	SellerName        string `description:"销售姓名"`
+	Mobile            string `description:"外呼手机号"`
+	CountryCode       string `description:"外呼手机号区号"`
+	GoOutboundMobile  bool   `description:"是否去绑定手机号"`
 }
 
 //我的日程
@@ -320,3 +323,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
+}

+ 49 - 12
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,6 +203,10 @@ type CountryCode struct {
 	IsNeedAddCountryCode bool `description:"是否需要填写区号:需要填写,false:不需要填写"`
 }
 
+type OutboundMobile struct {
+	IsNeedAddOutboundMobile bool `description:"是否需要填写外呼手机号:需要填写,false:不需要填写"`
+}
+
 type CountryCodeItem struct {
 	CountryCode string `description:"区号"`
 }
@@ -210,3 +217,33 @@ func AddCountryCode(CountryCode string, userId int) (err error) {
 	_, err = o.Raw(sql, CountryCode, 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 = ?  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
+}

+ 32 - 21
models/wx_user.go

@@ -56,27 +56,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 +209,11 @@ 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
+}