From 213c80c4f40f9e5b458931da098541192b445c62 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Tue, 7 Apr 2020 14:09:26 +0800 Subject: [PATCH] add watch num --- controllers/client/login.go | 54 +++++++++++++++++++++++++++++++++----- controllers/client/sign.go | 2 +- controllers/common/wechat_oauth.go | 4 ++- models/live_config.go | 2 +- 4 files changed, 52 insertions(+), 10 deletions(-) diff --git a/controllers/client/login.go b/controllers/client/login.go index 1f374c0..891c498 100644 --- a/controllers/client/login.go +++ b/controllers/client/login.go @@ -91,10 +91,22 @@ func (t *UserCtl) WxLogin() { session, err := wechat.MiniAuth(wxcode) t.CheckErr(err) user.Openid = session.OpenId + exist, err = user.GetUserByOpenid(user.Openid) + t.CheckErr(err) + if exist { + _, err = core.GetXormAuto().Insert(user) + t.CheckErr(err) + } } else if _type == "base" { token, err := wechat.GetToken(wxcode) t.CheckErr(err) user.Openid = token.OpenId + exist, err = user.GetUserByOpenid(user.Openid) + t.CheckErr(err) + if exist { + _, err = core.GetXormAuto().Insert(user) + t.CheckErr(err) + } } else if _type == "" { token, err := wechat.GetToken(wxcode) t.CheckErr(err) @@ -103,6 +115,10 @@ func (t *UserCtl) WxLogin() { } info, err := wechat.GetUserInfo(token) t.CheckErr(err) + + exist, err = user.GetUserByOpenid(info.OpenId) + t.CheckErr(err) + user.Nickname = info.Nickname user.Openid = info.OpenId user.Gender = func() string { @@ -118,11 +134,14 @@ func (t *UserCtl) WxLogin() { user.Country = info.Country user.CreatedAt = time.Now() user.UpdatedAt = time.Now() + if !exist { + _, err = core.GetXormAuto().Insert(user) + } else { + _, err = user.SaveUserInfo(user.Id) + } + t.CheckErr(err) } - err = user.SaveAndUpdateWithOpenId() - t.CheckErr(err) - history := new(models.SignHistory) signExist, err := history.GetByUserId(activityId, user.Id, activity.RehearsalId, area.Id) t.CheckErr(err) @@ -164,10 +183,22 @@ func (t *UserCtl) Login() { session, err := wechat.MiniAuth(wxcode) t.CheckErr(err) user.Openid = session.OpenId + exist, err := user.GetUserByOpenid(user.Openid) + t.CheckErr(err) + if exist { + _, err = core.GetXormAuto().Insert(user) + t.CheckErr(err) + } } else if _type == "base" { token, err := wechat.GetToken(wxcode) t.CheckErr(err) user.Openid = token.OpenId + exist, err := user.GetUserByOpenid(user.Openid) + t.CheckErr(err) + if exist { + _, err = core.GetXormAuto().Insert(user) + t.CheckErr(err) + } } else if _type == "" || _type == "userinfo" { //token, err := wx.GetToken(wxcode) token, err := wechat.GetToken(wxcode) @@ -178,6 +209,8 @@ func (t *UserCtl) Login() { //info, err := wx.GetUserInfo(token.AccessToken, token.OpenId) info, err := wechat.GetUserInfo(token) t.CheckErr(err) + exist, err := user.GetUserByOpenid(info.OpenId) + t.CheckErr(err) user.Nickname = info.Nickname user.Openid = info.OpenId user.Gender = func() string { @@ -193,12 +226,14 @@ func (t *UserCtl) Login() { user.Country = info.Country user.CreatedAt = time.Now() user.UpdatedAt = time.Now() - + if !exist { + _, err = core.GetXormAuto().Insert(user) + } else { + _, err = user.SaveUserInfo(user.Id) + } + t.CheckErr(err) } - err := user.SaveAndUpdateWithOpenId() - t.CheckErr(err) - jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, 0, 0, 0, 0) t.CheckErr(err) t.SetSession(define.TOKEN, jwtToken) @@ -275,7 +310,12 @@ func (t *UserAuthCtl) SaveUserInfo() { user.Country = info.Country _, err := user.SaveUserInfo(uid) t.CheckErr(err) + // + //exist, err := models.GetById(&user, uid) + //t.CheckErr(err) + //t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") + user.Id = uid sign, err := im.AccountImport(fmt.Sprintf("%d", user.Id), user.Avatar, user.Nickname) t.CheckErr(err) diff --git a/controllers/client/sign.go b/controllers/client/sign.go index d5be999..f811f8b 100644 --- a/controllers/client/sign.go +++ b/controllers/client/sign.go @@ -67,7 +67,7 @@ func (t *SignCtl) Sign() { t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在") customer := models.Customer{} - exist, err = models.GetById(customer, activity.CustomerId) + exist, err = models.GetById(&customer, activity.CustomerId) t.CheckErr(err) t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") diff --git a/controllers/common/wechat_oauth.go b/controllers/common/wechat_oauth.go index 6612729..94c86fc 100644 --- a/controllers/common/wechat_oauth.go +++ b/controllers/common/wechat_oauth.go @@ -7,6 +7,7 @@ import ( "hudongzhuanjia/controllers" "hudongzhuanjia/logger" "hudongzhuanjia/services/pay" + "os" "time" ) @@ -33,10 +34,11 @@ func (t *WeChatOauthCtl) Oauth() { } func (t *WeChatOauthCtl) Checkin() { + path, _ := os.Getwd() t.JSON(map[string]interface{}{ "success": "你好, tommy黄梓健", "version": Now, - "ip": t.Request.OriginRequest.RemoteAddr, + "wd": path, }) } diff --git a/models/live_config.go b/models/live_config.go index 1ba8b16..ee5d0a4 100644 --- a/models/live_config.go +++ b/models/live_config.go @@ -34,7 +34,7 @@ type LiveConfig struct { Status int `json:"status" xorm:"not null default 1 comment('直播的状态1未开始2进行中3已结束') VARCHAR(255)"` Announcement string `json:"announcement" xorm:"not null default '' comment('公告内容') VARCHAR(255)"` WatchNum int `json:"watch_num" xorm:"not null default 0 comment('观看人数') BIGINT(11)"` - ImGroupId int64 `json:"im_group_id" xorm:"not null default 0 comment('腾讯im聊天群id') BIGINT(11)"` + ImGroupId string `json:"im_group_id" xorm:"not null default '' comment('腾讯im聊天群id') VARCHAR(255)"` ImGroupName string `json:"im_group_name" xorm:"not null default '' comment('聊天群名称') VARCHAR(255)"` }