zwxi 1 năm trước cách đây
mục cha
commit
32b341742f

+ 1 - 1
controllers/base_auth.go

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

+ 21 - 0
controllers/wechat.go

@@ -107,6 +107,8 @@ func (this *WechatCommonController) WechatLoginByGzh() {
 	items.Country = wxUserInfo.Country
 	items.Headimgurl = wxUserInfo.Headimgurl
 	items.CreateTime = time.Now()
+	items.Subscribe = 1
+	items.SubscribeTime = time.Now()
 	if user != nil {
 		items.CygxUserId = user.UserId
 		items.CygxBindAccount = user.Mobile
@@ -119,6 +121,25 @@ func (this *WechatCommonController) WechatLoginByGzh() {
 			return
 		}
 	}
+	userRecord := &models.UserRecord{
+		OpenId:         openId,  //用户open_id
+		UnionId:        unionId, //用户union_id
+		Subscribe:      0,
+		NickName:       wxUserInfo.Nickname,   //用户昵称,最大长度:32
+		RealName:       "",   //用户实际名称,最大长度:32
+		Sex:            wxUserInfo.Sex,        //普通用户性别,1为男性,2为女性
+		Province:       wxUserInfo.Province,   //普通用户个人资料填写的省份,最大长度:30
+		City:           wxUserInfo.City,       //普通用户个人资料填写的城市,最大长度:30
+		Country:        wxUserInfo.Country,    //国家,如中国为CN,最大长度:30
+		Headimgurl:     wxUserInfo.Headimgurl, //用户第三方(微信)头像,最大长度:512
+		CreateTime:     time.Now(), //创建时间,关系添加时间、用户授权时间
+		CreatePlatform: 12,   //注册平台,1:日度点评公众号,2:管理后台,3:pc端网站,4:查研观向小程序;默认:1
+		SessionKey:     wxUserInfo.SessionKey, //微信小程序会话密钥,最大长度:255
+	}
+	_, err = models.AddUserRecord(userRecord)
+	if err != nil {
+		return
+	}
 	timeUnix := time.Now().Unix()
 	timeUnixStr := strconv.FormatInt(timeUnix, 10)
 

+ 3 - 1
models/cygx_mfyx_gzh_user_record.go

@@ -11,6 +11,8 @@ type CygxMfyxGzhUserRecord struct {
 	UnionId         string    `description:"用户unionid,最大长度:64"`
 	NickName        string    `descritpion:"用户昵称,最大长度:32"`
 	Sex             int       `descritpion:"普通用户性别,1为男性,2为女性"`
+	Subscribe       int       `description:"是否关注"`
+	SubscribeTime   time.Time `description:"关注时间"`
 	Province        string    `description:"普通用户个人资料填写的省份,最大长度:30"`
 	City            string    `description:"普通用户个人资料填写的城市,最大长度:30"`
 	Country         string    `description:"国家,如中国为CN,最大长度:30"`
@@ -78,4 +80,4 @@ func GetUserRecordByUserId(userId, platform int) (item *UserRecord, err error) {
 	sql := `SELECT * FROM user_record WHERE user_id=? AND create_platform = ?`
 	err = o.Raw(sql, userId, platform).QueryRow(&item)
 	return
-}
+}

+ 9 - 2
models/user_record.go

@@ -24,6 +24,13 @@ type UserRecord struct {
 	UserId         int       `description:"用户id"`
 }
 
+// 添加用户关系
+func AddUserRecord(record *UserRecord) (recordId int64, err error) {
+	o := orm.NewOrmUsingDB("weekly_report")
+	recordId, err = o.Insert(record)
+	return
+}
+
 // 根据openid获取用户关系
 // 12是买方研选   create_platform
 func GetUserRecordByUnionId(unionId string) (item *UserRecord, err error) {
@@ -65,8 +72,8 @@ func GetUserRecordList(condition string, pars []interface{}) (items []*UserRecor
 
 // 根据openid获取用户关系
 func GetUserRecordByOpenId(openId string) (item *UserRecord, err error) {
-	o := orm.NewOrmUsingDB("weekly_report")
-	sql := `SELECT * FROM user_record WHERE open_id=? `
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_mfyx_gzh_user_record WHERE open_id=? `
 	err = o.Raw(sql, openId).QueryRow(&item)
 	return
 }