Ver código fonte

区号添加

xingzai 3 anos atrás
pai
commit
5da609dcc9
2 arquivos alterados com 87 adições e 0 exclusões
  1. 71 0
      controllers/user.go
  2. 16 0
      models/user.go

+ 71 - 0
controllers/user.go

@@ -961,3 +961,74 @@ func sentMsgToSeller() {
 //	return
 //	fmt.Println("end")
 //}
+
+// @Title 是否需要填写区号
+// @Description 获取是否需要填写区号接口
+// @Success 200 {object} models.CountryCode
+// @router /countryCcode/isNeedAdd [get]
+func (this *UserController) CountryCcode() {
+	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
+	}
+	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 == "" {
+		resp.IsNeedAddCountryCode = true
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "获取成功"
+	br.Data = resp
+}
+
+// @Title 上传用户区号
+// @Description 上传用户区号接口
+// @Param	request	body models.CountryCodeItem true "type json string"
+// @Success Ret=200 新增成功
+// @router /countryCcode/Add [POST]
+func (this *UserController) AddCountryCcode() {
+	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.CountryCodeItem
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	err = models.AddCountryCode(req.CountryCode, uid)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "新增成功"
+}

+ 16 - 0
models/user.go

@@ -19,6 +19,7 @@ type UserDetail struct {
 	SellerMobile   string `description:"销售手机号"`
 	SellerName     string `description:"销售名称"`
 	Note           string `json:"-" description:"申请提交时,公司名称"`
+	CountryCode    string `description:"区号"`
 }
 
 func GetUserDetailByUserId(userId int) (item *UserDetail, err error) {
@@ -194,3 +195,18 @@ type ApplyTryReq struct {
 	CompanyName     string `description:"公司名称"`
 	ApplyMethod     int    `description:"1:已付费客户申请试用,2:非客户申请试用,3:非客户申请试用(ficc下,不需要进行数据校验)"`
 }
+
+type CountryCode struct {
+	IsNeedAddCountryCode bool `description:"是否需要填写区号:需要填写,false:不需要填写"`
+}
+
+type CountryCodeItem struct {
+	CountryCode string `description:"区号"`
+}
+
+func AddCountryCode(CountryCode string, userId int) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE wx_user SET country_code=? WHERE user_id=? `
+	_, err = o.Raw(sql, CountryCode, userId).Exec()
+	return
+}