Browse Source

todo: area_id

master
黄梓健 5 years ago
parent
commit
fab96a7f55
  1. 143
      controllers/client/login.go
  2. 3
      controllers/client/lottery.go
  3. 4
      controllers/client/sign.go

143
controllers/client/login.go

@ -63,7 +63,6 @@ func (t *UserCtl) EntryLogin() {
func (t *UserCtl) WxLogin() {
activityId := t.MustGetInt64("activity_id")
wxcode := t.MustGet("code")
_type, _ := t.Get("type") // mini 小程序登陆 base 静默授权 userinfo 或者为空 非静默授权
activity, exist, err := activity_service.GetActivityById(activityId)
t.CheckErr(err)
@ -83,64 +82,42 @@ func (t *UserCtl) WxLogin() {
t.CheckErr(err)
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在")
token, err := wechat.GetToken(wxcode)
t.CheckErr(err)
if token.AccessToken == "" || token.OpenId == "" {
t.ERROR("code无效", code.MSG_ERR)
}
info, err := wechat.GetUserInfo(token)
t.CheckErr(err)
user := new(models.User)
exist, err = user.GetUserByOpenid(info.OpenId)
t.CheckErr(err)
user.ActivityId = activityId
user.AreaId = area.Id
user.AreaName = area.Name
if _type == "mini" {
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)
if token.AccessToken == "" || token.OpenId == "" {
t.ERROR("code无效", code.MSG_ERR)
}
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 {
if info.Sex == 1 {
return "男"
}
return "女"
}()
user.Avatar = info.HeadImageURL
user.Unionid = info.UnionId
user.City = info.City
user.Province = info.Province
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)
user.Nickname = info.Nickname
user.Openid = info.OpenId
user.Gender = func() string {
if info.Sex == 1 {
return "男"
}
t.CheckErr(err)
return "女"
}()
user.Avatar = info.HeadImageURL
user.Unionid = info.UnionId
user.City = info.City
user.Province = info.Province
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)
history := new(models.SignHistory)
signExist, err := history.GetByUserId(activityId, user.Id, activity.RehearsalId, area.Id)
@ -176,60 +153,16 @@ func (t *UserCtl) WxLogin() {
func (t *UserCtl) Login() {
wxcode := t.MustGet("code")
_type, _ := t.Get("type")
// _type, _ := t.Get("type")
user := new(models.User)
if _type == "mini" {
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)
t.CheckErr(err)
if token.AccessToken == "" || token.OpenId == "" {
t.ERROR("code无效", code.MSG_ERR)
}
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 {
if info.Sex == 1 {
return "男"
}
return "女"
}()
user.Avatar = info.HeadImageURL
user.Unionid = info.UnionId
user.City = info.City
user.Province = info.Province
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)
}
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)
}

3
controllers/client/lottery.go

@ -59,10 +59,11 @@ func (t *LotteryCtl) CheckLottery() {
record := new(models.LotteryDrawRecord)
exist, err = record.GetByUserIdAndLadderId(uid, ladderId)
t.CheckErr(err)
t.Assert(exist, code.MSG_LOTTERY_DRAW_NOT_HIT, "没有中奖")
//t.Assert(exist, code.MSG_LOTTERY_DRAW_NOT_HIT, "没有中奖")
t.JSON(map[string]interface{}{
"record": record,
"ladder": ladder,
"status": exist,
})
}

4
controllers/client/sign.go

@ -5,6 +5,7 @@ import (
"fmt"
"github.com/ouxuanserver/osmanthuswine/src/core"
"hudongzhuanjia/controllers"
"hudongzhuanjia/logger"
"hudongzhuanjia/models"
ws_send_service "hudongzhuanjia/services/ws_send"
"hudongzhuanjia/utils/code"
@ -110,6 +111,9 @@ func (t *SignCtl) Sign() {
user := new(models.User)
exist, err = models.GetById(user, uid)
logger.Error("user:===>%+v", user)
logger.Error("token:==>%v", t.MustGet("token"))
logger.Error("user_id:===>%v", uid)
t.CheckErr(err)
t.Assert(exist, code.MSG_USER_NOT_EXIST, "用户不存在")

Loading…
Cancel
Save