From fab96a7f55dac2827ece96498aa3ad3f31737d68 Mon Sep 17 00:00:00 2001 From: tommy <3405129587@qq.com> Date: Mon, 18 May 2020 14:15:46 +0800 Subject: [PATCH] todo: area_id --- controllers/client/login.go | 143 +++++++++++------------------------------- controllers/client/lottery.go | 3 +- controllers/client/sign.go | 4 ++ 3 files changed, 44 insertions(+), 106 deletions(-) diff --git a/controllers/client/login.go b/controllers/client/login.go index 62f2959..02d53fd 100644 --- a/controllers/client/login.go +++ b/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) } diff --git a/controllers/client/lottery.go b/controllers/client/lottery.go index f55d900..7ab9a47 100644 --- a/controllers/client/lottery.go +++ b/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, }) } diff --git a/controllers/client/sign.go b/controllers/client/sign.go index acf83d5..42b283a 100644 --- a/controllers/client/sign.go +++ b/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, "用户不存在")