Browse Source

no message

xingzai 2 years ago
parent
commit
61c8e755d6
4 changed files with 35 additions and 8 deletions
  1. 10 0
      controllers/user.go
  2. 9 8
      controllers/wechat.go
  3. 8 0
      models/session.go
  4. 8 0
      models/xzs_choose_send.go

+ 10 - 0
controllers/user.go

@@ -87,6 +87,16 @@ func (this *UserController) ChooseDetail() {
 	if count == 0 {
 		resp.IsObjective = 1
 		resp.IsSubjective = 1
+	} else {
+		detail, err := models.GetCygxXzsChooseSendByMobile(mobile)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "GetCygxXzsChooseSendByMobile,Err:" + err.Error()
+			return
+		}
+		resp.IsObjective = detail.IsObjective
+		resp.IsSubjective = detail.IsSubjective
+		resp.IsRefuse = detail.IsRefuse
 	}
 	resp.List = permissionList
 	br.Ret = 200

+ 9 - 8
controllers/wechat.go

@@ -34,6 +34,7 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 		br.ErrMsg = "Code 为空"
 		return
 	}
+	var token string
 	item, err := services.WxGetUserOpenIdByCodeXzs(code)
 	if err != nil {
 		br.Msg = "获取用户信息失败"
@@ -108,7 +109,7 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 	}
 	timeUnix := time.Now().Unix()
 	timeUnixStr := strconv.FormatInt(timeUnix, 10)
-	token := utils.MD5(unionId) + utils.MD5(timeUnixStr)
+
 	user, err := models.GetWxUserItemByUserUnionId(unionId)
 	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取用户信息失败"
@@ -116,13 +117,14 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 		return
 	}
 
-	totalToken, err := models.GetXzsSessionCountByToken(token)
-	if err != nil {
+	totalItem, err := models.GetTokenByOpenId(openId)
+	if err != nil && err.Error() != utils.ErrNoRow() {
 		br.Msg = "获取用户信息失败"
 		br.ErrMsg = "查询数量失败,Err:" + err.Error()
 		return
 	}
-	if totalToken == 0 {
+	if totalItem == nil {
+		token := utils.MD5(unionId) + utils.MD5(timeUnixStr)
 		itemsSession := new(models.CygxXzsSession)
 		itemsSession.UnionId = unionId
 		itemsSession.OpenId = openId
@@ -139,6 +141,8 @@ func (this *WechatCommonController) WechatLoginByxzs() {
 			br.ErrMsg = "添加Token失败,Err:" + err.Error()
 			return
 		}
+	} else {
+		token = totalItem.AccessToken
 	}
 
 	if user == nil {
@@ -256,10 +260,7 @@ func (this *WechatController) UserInfo() {
 			resp.RealName = user.RealName
 			resp.HasPermission = 2
 		}
-		resp.Headimgurl = user.HeadimgurlRecord
-	}
-	if resp.Headimgurl == "" {
-		resp.Headimgurl = utils.HeadimgurlDefault
+		resp.Headimgurl = user.Headimgurl
 	}
 	br.Ret = 200
 	br.Success = true

+ 8 - 0
models/session.go

@@ -44,3 +44,11 @@ func GetUnionidByToken(token string) (item *CygxXzsSession, err error) {
 	err = o.Raw(sql, token).QueryRow(&item)
 	return
 }
+
+//根据用户openid获取token
+func GetTokenByOpenId(openId string) (item *CygxXzsSession, err error) {
+	sql := `SELECT * FROM cygx_xzs_session WHERE open_id=? AND expire_time> NOW() ORDER BY session_id DESC LIMIT 1 `
+	o := orm.NewOrm()
+	err = o.Raw(sql, openId).QueryRow(&item)
+	return
+}

+ 8 - 0
models/xzs_choose_send.go

@@ -111,3 +111,11 @@ func UpdateCygxXzsChooseSend(item *CygxXzsChooseSend, itemsFllow []*CygxIndustry
 	err = UpdateByExpr(CygxXzsChooseSend{}, whereParam, updateParams)
 	return
 }
+
+//根据用户openid获取token
+func GetCygxXzsChooseSendByMobile(mobile string) (item *CygxXzsChooseSend, err error) {
+	sql := `SELECT * FROM cygx_xzs_choose_send WHERE mobile=?  LIMIT 1 `
+	o := orm.NewOrm()
+	err = o.Raw(sql, mobile).QueryRow(&item)
+	return
+}