|
|
@ -9,6 +9,7 @@ import ( |
|
|
|
"hudongzhuanjia/logger" |
|
|
|
"hudongzhuanjia/models" |
|
|
|
activity_service "hudongzhuanjia/services/activity" |
|
|
|
"hudongzhuanjia/utils" |
|
|
|
"hudongzhuanjia/utils/code" |
|
|
|
"hudongzhuanjia/utils/define" |
|
|
|
"time" |
|
|
@ -27,36 +28,41 @@ func (t *UserCtl) EntryLogin() { |
|
|
|
password := t.MustGet("password") |
|
|
|
activityId := t.MustGetInt("activity_id") // 需要获取
|
|
|
|
|
|
|
|
entryPeople := new(models.OrderEntryPerson) |
|
|
|
exist, err := entryPeople.Auth(account, password, activityId) |
|
|
|
entry := new(models.OrderEntryPerson) |
|
|
|
exist, err := entry.Auth(account, password, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ENTRYPEOPLE_NOT_EXIST, "录入人员不存在") |
|
|
|
|
|
|
|
area := new(models.AreaStore) |
|
|
|
exist, err = models.Get(area, entryPeople.AreaId) |
|
|
|
exist, err = area.Get(area, entry.AreaId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
activity := new(models.Activity) |
|
|
|
exist, err = models.Get(activity, activityId) |
|
|
|
exist, err = activity.Get(activity, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_ACTIVITY_NOT_EXIST, "互动不存在") |
|
|
|
|
|
|
|
customer := new(models.Customer) |
|
|
|
exist, err = models.Get(customer, entryPeople.Pid) |
|
|
|
exist, err = customer.Get(customer, entry.Pid) |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_CUSTOMER_NOT_EXIST, "客户不存在") |
|
|
|
|
|
|
|
// 怎讲activity
|
|
|
|
token, err := jwt.GenJwtToken(define.TYPE_ENTRYPEOPLE, entryPeople.Id, customer.Id, customer.Pid, entryPeople.AreaId, entryPeople.ActivityId) |
|
|
|
//token, err := jwt.GenJwtToken(define.TYPE_ENTRYPEOPLE, entry.Id, customer.Id, customer.Pid, entry.AreaId, entry.ActivityId)
|
|
|
|
//t.CheckErr(err)
|
|
|
|
if entry.Token == "" { |
|
|
|
entry.Token = utils.GenToken(entry.Name) |
|
|
|
} |
|
|
|
entry.AreaName = area.Name |
|
|
|
entry.ActivityName = activity.Name |
|
|
|
entry.IsSpecial = customer.IsSpecial |
|
|
|
_, err = entry.Update(entry, entry.Id) |
|
|
|
t.CheckErr(err) |
|
|
|
t.SetSession(define.TOKEN, token) |
|
|
|
entryPeople.Token = token |
|
|
|
entryPeople.AreaName = area.Name |
|
|
|
entryPeople.ActivityName = activity.Name |
|
|
|
entryPeople.IsSpecial = customer.IsSpecial |
|
|
|
entry.Token = fmt.Sprintf("%s:%s", define.TYPE_ENTRYPEOPLE, entry.Token) |
|
|
|
t.SetSession(define.TOKEN, entry.Token) |
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|
"people": entryPeople, |
|
|
|
"people": entry, |
|
|
|
}) |
|
|
|
} |
|
|
|
|
|
|
@ -90,15 +96,12 @@ func (t *UserCtl) WxLogin() { |
|
|
|
user := new(models.User) |
|
|
|
exist, err = user.GetUserByOpenid(info.OpenId) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
if user.Token == "" { |
|
|
|
user.Token = utils.GenToken(user.Openid) |
|
|
|
} |
|
|
|
user.Nickname = info.Nickname |
|
|
|
user.Openid = info.OpenId |
|
|
|
user.Gender = func() string { |
|
|
|
if info.Sex == 1 { |
|
|
|
return "男" |
|
|
|
} |
|
|
|
return "女" |
|
|
|
}() |
|
|
|
user.Gender = utils.GetGender(info.Sex) |
|
|
|
user.Avatar = info.HeadImageURL |
|
|
|
user.Unionid = info.UnionId |
|
|
|
user.City = info.City |
|
|
@ -107,9 +110,9 @@ func (t *UserCtl) WxLogin() { |
|
|
|
user.CreatedAt = time.Now() |
|
|
|
user.UpdatedAt = time.Now() |
|
|
|
if !exist { |
|
|
|
_, err = models.Add(user) |
|
|
|
_, err = user.Add(user) |
|
|
|
} else { |
|
|
|
_, err = user.SaveUserInfo(user.Id) |
|
|
|
_, err = user.Update(user, user.Id) |
|
|
|
} |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
@ -143,13 +146,14 @@ func (t *UserCtl) WxLogin() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, customer.Id, customer.Pid, area.Id, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.SetSession(define.TOKEN, jwtToken) |
|
|
|
//jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, customer.Id, customer.Pid, area.Id, activityId)
|
|
|
|
//t.CheckErr(err)
|
|
|
|
user.Token = fmt.Sprintf("%s:%s", define.TYPE_USER, user.Token) |
|
|
|
t.SetSession(define.TOKEN, user.Token) |
|
|
|
|
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|
"user": user, |
|
|
|
"token": jwtToken, |
|
|
|
"token": user.Token, |
|
|
|
"activity": activity, |
|
|
|
"sign_in": signIn, |
|
|
|
"sign": signExist, |
|
|
@ -163,16 +167,41 @@ func (t *UserCtl) WxLogin() { |
|
|
|
func (t *UserCtl) Login() { |
|
|
|
wxcode := t.MustGet("code") |
|
|
|
|
|
|
|
user := new(models.User) |
|
|
|
//user := new(models.User)
|
|
|
|
token, err := wechat.GetToken(wxcode) |
|
|
|
t.CheckErr(err) |
|
|
|
user.Openid = token.OpenId |
|
|
|
exist, err := user.GetUserByOpenid(user.Openid) |
|
|
|
//user.Openid = token.OpenId
|
|
|
|
//exist, err := user.GetUserByOpenid(user.Openid)
|
|
|
|
//t.CheckErr(err)
|
|
|
|
//if !exist {
|
|
|
|
// _, err = models.Add(user)
|
|
|
|
// t.CheckErr(err)
|
|
|
|
//}
|
|
|
|
info, err := wechat.GetUserInfo(token) |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
user := new(models.User) |
|
|
|
exist, err := user.GetUserByOpenid(info.OpenId) |
|
|
|
t.CheckErr(err) |
|
|
|
if user.Token == "" { |
|
|
|
user.Token = utils.GenToken(user.Openid) |
|
|
|
} |
|
|
|
user.Nickname = info.Nickname |
|
|
|
user.Openid = info.OpenId |
|
|
|
user.Gender = utils.GetGender(info.Sex) |
|
|
|
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 = models.Add(user) |
|
|
|
t.CheckErr(err) |
|
|
|
_, err = user.Add(user) |
|
|
|
} else { |
|
|
|
_, err = user.Update(user, user.Id) |
|
|
|
} |
|
|
|
t.CheckErr(err) |
|
|
|
|
|
|
|
area := &models.AreaStore{} |
|
|
|
admin := 0 |
|
|
@ -198,17 +227,17 @@ func (t *UserCtl) Login() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, 0, 0, 0, 0) |
|
|
|
t.CheckErr(err) |
|
|
|
t.SetSession(define.TOKEN, jwtToken) |
|
|
|
|
|
|
|
//jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, 0, 0, 0, 0)
|
|
|
|
//t.CheckErr(err)
|
|
|
|
user.Token = fmt.Sprintf("%s:%s", define.TYPE_LIVEUSER, user.Token) |
|
|
|
t.SetSession(define.TOKEN, user.Token) |
|
|
|
sign, err := im.AccountImport(fmt.Sprintf("%d", user.Id), user.Nickname, user.Avatar) |
|
|
|
t.CheckErr(err) |
|
|
|
user.Sig = sign |
|
|
|
|
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|
"user": user, |
|
|
|
"token": jwtToken, |
|
|
|
"token": user.Token, |
|
|
|
"area": area, |
|
|
|
"admin": admin, |
|
|
|
}) |
|
|
@ -239,7 +268,7 @@ func (t *UserCtl) DebugLogin() { |
|
|
|
t.CheckErr(err) |
|
|
|
t.Assert(exist, code.MSG_AREASTORE_NOT_EXIST, "地区不存在") |
|
|
|
|
|
|
|
jwtToken, err := jwt.GenJwtToken(define.TYPE_H5USER, user.Id, customer.Id, customer.Pid, area.Id, activityId) |
|
|
|
jwtToken, err := jwt.GenJwtToken(define.TYPE_USER, user.Id, customer.Id, customer.Pid, area.Id, activityId) |
|
|
|
t.CheckErr(err) |
|
|
|
t.SetSession(define.TOKEN, jwtToken) |
|
|
|
t.JSON(map[string]interface{}{ |
|
|
|