Browse Source

add watch num

master
黄梓健 5 years ago
parent
commit
213c80c4f4
  1. 54
      controllers/client/login.go
  2. 2
      controllers/client/sign.go
  3. 4
      controllers/common/wechat_oauth.go
  4. 2
      models/live_config.go

54
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)

2
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, "客户不存在")

4
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,
})
}

2
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)"`
}

Loading…
Cancel
Save