Browse Source

no message

xingzai 8 months ago
parent
commit
d5b266fbc6
6 changed files with 312 additions and 17 deletions
  1. 196 17
      controllers/user.go
  2. 1 0
      models/db.go
  3. 3 0
      models/user.go
  4. 70 0
      models/user_password.go
  5. 18 0
      routers/commentsRouter.go
  6. 24 0
      services/user.go

+ 196 - 17
controllers/user.go

@@ -48,31 +48,66 @@ func (this *UserCommonController) Login() {
 		br.ErrMsg = "参数错误,手机号为空"
 		return
 	}
-	code := req.VCode
-	if code == "" {
-		br.Msg = "参数错误"
-		br.ErrMsg = "Code 为空"
-		return
-	}
+
 	authorization := req.Token
 	inviteShareCode := req.InviteShareCode
 
-	item, err := models.GetMsgCode(req.Mobile, req.VCode)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			br.Msg = "验证码错误,请重新输入"
-			br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+	password := req.Password
+	loginType := req.LoginType
+
+	if loginType == 1 {
+		if password == "" {
+			br.Msg = "参数错误"
+			br.ErrMsg = "Password 为空"
 			return
-		} else {
+		}
+
+		total, err := models.GetCygxUserPasswordCountByMobileAdnPss(mobile, password)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败 GetCygxUserPasswordCountByMobileAdnPss err" + err.Error()
+		}
+		if total == 0 {
+			br.Msg = "密码错误,请重新输入"
+			return
+		}
+		userByps, err := models.GetWxUserItemByUserMobile(mobile)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取信息失败,Err:" + err.Error()
+			return
+		}
+
+		specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(userByps) //用户是否没开通研选专栏以及,专栏信息是否完善
+		if !specialAuthorCheck.IsAuthor {
+			br.Msg = "该账号不是专栏作者,请使用验证码登录。"
+			return
+		}
+
+	} else {
+		code := req.VCode
+		if code == "" {
+			br.Msg = "参数错误"
+			br.ErrMsg = "Code 为空"
+			return
+		}
+		item, err := models.GetMsgCode(req.Mobile, req.VCode)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			} else {
+				br.Msg = "验证码错误,请重新输入"
+				br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+				return
+			}
+		}
+		if item == nil {
 			br.Msg = "验证码错误,请重新输入"
-			br.ErrMsg = "校验验证码失败,Err:" + err.Error()
 			return
 		}
 	}
-	if item == nil {
-		br.Msg = "验证码错误,请重新输入"
-		return
-	}
 
 	user, err := services.BindWxUser(mobile, "86", inviteShareCode)
 	//user, err := models.GetWxUserItemByMobile(mobile)
@@ -327,6 +362,7 @@ func (this *UserController) Detail() {
 	resp.SpecialColumnId = specialAuthorCheck.SpecialColumnId
 	resp.IsImproveInformation = specialAuthorCheck.IsImproveInformation
 	resp.HasPermission = hasPermission
+	resp.IsSetPassword = services.GetIsSetPassword(user.Mobile)
 	br.Ret = 200
 	br.Success = true
 	br.Msg = "获取成功"
@@ -1893,3 +1929,146 @@ func (this *UserController) EmailBinding() {
 	br.Success = true
 	br.Msg = "操作成功"
 }
+
+// @Title 设置密码接口
+// @Description 设置密码接口
+// @Param	request	body models.SetUserPasswordReq true "type json string"
+// @Success 200 {object}
+// @router /set_pass [post]
+func (this *UserCommonController) SetPass() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	var req models.SetUserPasswordReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	mobile := req.Mobile
+	mobile = strings.Trim(mobile, " ")
+	if mobile == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误,手机号为空"
+		return
+	}
+	code := req.VCode
+	if code == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "Code 为空"
+		return
+	}
+	password := req.Password
+	if password == "" {
+		br.Msg = "参数错误"
+		br.ErrMsg = "Password 为空"
+		return
+	}
+
+	item, err := models.GetMsgCode(req.Mobile, req.VCode)
+	if err != nil {
+		if err.Error() == utils.ErrNoRow() {
+			br.Msg = "验证码错误,请重新输入"
+			br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+			return
+		} else {
+			br.Msg = "验证码错误,请重新输入"
+			br.ErrMsg = "校验验证码失败,Err:" + err.Error()
+			return
+		}
+	}
+	if item == nil {
+		br.Msg = "验证码错误,请重新输入"
+		return
+	}
+
+	user, err := models.GetWxUserItemByUserMobile(mobile)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取信息失败,Err:" + err.Error()
+		return
+	}
+
+	specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
+	if !specialAuthorCheck.IsAuthor {
+		br.Msg = "该账号不是专栏作者,请使用验证码登录。"
+		return
+	}
+	isSetPassword := services.GetIsSetPassword(mobile)
+	if isSetPassword {
+		err = models.UpdateCygxUserPassword(mobile, password)
+	} else {
+		itemps := new(models.CygxUserPassword)
+		itemps.UserId = user.UserId
+		itemps.Mobile = mobile
+		itemps.RealName = user.RealName
+		itemps.Password = password
+		itemps.CreateTime = time.Now()
+		itemps.ModifyTime = time.Now()
+		err = models.AddCygxUserPassword(itemps)
+	}
+	if err != nil {
+		br.Msg = "设置失败"
+		br.ErrMsg = "设置失败 err" + err.Error()
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}
+
+// @Title 修改密码接口
+// @Description 修改密码接口
+// @Param	request	body models.UpdateUserPasswordReq true "type json string"
+// @Success 200 {object}
+// @router /update_pass [post]
+func (this *UserController) UpdatePass() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	mobile := user.Mobile
+	var req models.UpdateUserPasswordReq
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	oldPassword := req.OldPassword
+	newPassword := req.NewPassword
+
+	total, err := models.GetCygxUserPasswordCountByMobileAdnPss(mobile, oldPassword)
+	if err != nil {
+		br.Msg = "设置失败"
+		br.ErrMsg = "设置失败 err" + err.Error()
+	}
+	if total == 0 {
+		br.Msg = "原密码错误"
+		return
+	}
+
+	specialAuthorCheck := services.GetYanxuanSpecialAuthorInfo(user) //用户是否没开通研选专栏以及,专栏信息是否完善
+	if !specialAuthorCheck.IsAuthor {
+		br.Msg = "非专栏作者无法设置登录密码"
+		return
+	}
+	err = models.UpdateCygxUserPassword(mobile, newPassword)
+	if err != nil {
+		br.Msg = "设置失败"
+		br.ErrMsg = "设置失败 err" + err.Error()
+	}
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 1 - 0
models/db.go

@@ -107,6 +107,7 @@ func init() {
 		new(CygxActivityVideoHistory),
 		new(CygxUserAdminShareHistory),
 		new(CygxUserAdminShareCode),
+		new(CygxUserPassword),
 	)
 
 	initOrder() // 订单模块

+ 3 - 0
models/user.go

@@ -48,6 +48,8 @@ type LoginReq struct {
 	VCode           string `description:"验证码"`
 	Token           string `description:"微信扫码登录之后返回的Token"`
 	InviteShareCode string `description:"销售账号邀请码"`
+	Password        string `comment:"密码"`
+	LoginType       int    `comment:"登录方式 1 密码登录,其他不用传"`
 }
 
 type WxBindMobileReq struct {
@@ -159,6 +161,7 @@ type UserDetailResp struct {
 	UserCardType         int      `description:"权益卡类型,0:未开通、1日卡、2月卡"`
 	UserCardEndDate      string   `description:"权益卡有效期"`
 	IsShowWxPaySet       bool     `description:"是否展示微信支付全局设置"` // 配合前端支付进入详情页使用
+	IsSetPassword        bool     `description:"是否设置了登录密码"`
 }
 
 type CheckStatusResp struct {

+ 70 - 0
models/user_password.go

@@ -0,0 +1,70 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+// 买方研选网页版用户设置登录密码
+type CygxUserPassword struct {
+	UserPasswordId int       `orm:"column(user_password_id);pk";comment:"主键ID"`
+	UserId         int       `comment:"用户ID"`
+	Mobile         string    `comment:"手机号"`
+	RealName       string    `comment:"用户实际名称"`
+	Password       string    `comment:"密码"`
+	CreateTime     time.Time `comment:"创建时间"`
+	ModifyTime     time.Time `comment:"修改时间"`
+}
+
+type SetUserPasswordReq struct {
+	Mobile   string `comment:"手机号"`
+	VCode    string `description:"验证码"`
+	Password string `comment:"密码"`
+}
+
+type UpdateUserPasswordReq struct {
+	OldPassword string `comment:"旧密码"`
+	NewPassword string `comment:"新密码"`
+}
+
+// 获取数量
+func GetCygxUserPasswordCountByMobile(mobile string) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_password WHERE mobile = ?  `
+	err = o.Raw(sqlCount, mobile).QueryRow(&count)
+	return
+}
+
+// 获取数量
+func GetCygxUserPasswordCountByMobileAdnPss(mobile, password string) (count int, err error) {
+	o := orm.NewOrm()
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_password WHERE mobile = ?  AND    password = ?`
+	err = o.Raw(sqlCount, mobile, password).QueryRow(&count)
+	return
+}
+
+// 添加
+func AddCygxUserPassword(item *CygxUserPassword) (err error) {
+	o := orm.NewOrm()
+	_, err = o.Insert(item)
+	return
+}
+
+// 根据手机号修改密码
+func UpdateCygxUserPassword(mobile, password string) (err error) {
+	o := orm.NewOrm()
+	updateParams := make(map[string]interface{})
+	updateParams["Password"] = password
+	updateParams["ModifyTime"] = time.Now()
+	ptrStructOrTableName := "cygx_user_password"
+	whereParam := map[string]interface{}{"mobile": mobile}
+	qs := o.QueryTable(ptrStructOrTableName)
+	for expr, exprV := range whereParam {
+		qs = qs.Filter(expr, exprV)
+	}
+	_, err = qs.Update(updateParams)
+	if err != nil {
+		return
+	}
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -844,6 +844,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserCommonController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserCommonController"],
+        beego.ControllerComments{
+            Method: "SetPass",
+            Router: `/set_pass`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserController"],
         beego.ControllerComments{
             Method: "ApplyTryOut",
@@ -943,6 +952,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserController"],
+        beego.ControllerComments{
+            Method: "UpdatePass",
+            Router: `/update_pass`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserController"] = append(beego.GlobalControllerRouter["hongze/hongze_web_mfyx/controllers:UserController"],
         beego.ControllerComments{
             Method: "UploadUserBusinessCard",

+ 24 - 0
services/user.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hongze_web_mfyx/models"
 	"hongze/hongze_web_mfyx/utils"
 	"strings"
@@ -684,3 +685,26 @@ func GetUserhasPermission(user *models.WxUserItem) (hasPermission int, err error
 	}
 	return
 }
+
+// 获取研选专栏用户是否设置了登录密码
+func GetIsSetPassword(mobile string) (isSetPassword bool) {
+	if mobile == "" {
+		return
+	}
+	var err error
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg(fmt.Sprint("获取研选专栏用户是否设置了登录密码 失败,GetIsSetPassword Err ", err, "mobile", mobile), 2)
+		}
+	}()
+
+	total, e := models.GetCygxUserPasswordCountByMobile(mobile)
+	if e != nil {
+		err = errors.New("GetCygxUserPasswordCountByMobile, Err: " + e.Error())
+		return
+	}
+	if total > 0 {
+		isSetPassword = true
+	}
+	return
+}