Browse Source

添加用户手机号登录的author权限校验 v2

xingzai 2 years ago
parent
commit
7af8c5e326
2 changed files with 20 additions and 1 deletions
  1. 1 1
      controllers/base_auth_mobile.go
  2. 19 0
      models/wx_user.go

+ 1 - 1
controllers/base_auth_mobile.go

@@ -64,7 +64,7 @@ func (this *BaseAuthMobileController) Prepare() {
 				return
 			}
 			//wxUser, err := models.GetWxUserItemByUserId(session.UserId)
-			wxUser, err := models.GetWxUserItemByMobile(session.Mobile)
+			wxUser, err := models.GetWxUserAouthByMobile(session.Mobile)
 			if err != nil && err != services.ERR_USER_NOT_BIND {
 				if err.Error() == utils.ErrNoRow() {
 					this.JSON(models.BaseResponse{Ret: 408, Msg: "信息已变更,请重新登陆!", ErrMsg: "获取信息失败 " + strconv.Itoa(session.UserId)}, false, false)

+ 19 - 0
models/wx_user.go

@@ -194,6 +194,25 @@ func GetWxUserItemByMobile(mobile string) (item *WxUserItem, err error) {
 	return
 }
 
+//根据用户手机号获取相关信息
+func GetWxUserAouthByMobile(mobile string) (item *WxUserItem, err error) {
+	sql := `SELECT
+			a.*,
+			s.mobile,
+			b.company_name 
+		FROM
+			cygx_session_mobile AS s
+			LEFT JOIN wx_user AS a ON a.mobile = s.mobile
+			LEFT JOIN company AS b ON a.company_id = b.company_id 
+		WHERE
+			s.mobile = ?
+		ORDER BY
+			a.company_id DESC 
+			LIMIT 1`
+	err = orm.NewOrm().Raw(sql, mobile).QueryRow(&item)
+	return
+}
+
 func GetWxUserItemByEmail(email string) (item *WxUserItem, err error) {
 	sql := `SELECT * FROM wx_user WHERE email=? `
 	err = orm.NewOrm().Raw(sql, email).QueryRow(&item)