149 lines
3.8 KiB
Go
149 lines
3.8 KiB
Go
|
package app
|
|||
|
|
|||
|
import (
|
|||
|
. "code.hoteas.com/golang/hotime"
|
|||
|
. "code.hoteas.com/golang/hotime/common"
|
|||
|
)
|
|||
|
|
|||
|
var User = Ctr{
|
|||
|
//用户微信公众号或者小程序登录
|
|||
|
"login": func(that *Context) {
|
|||
|
|
|||
|
acttoken := that.Req.FormValue("acttoken")
|
|||
|
retoken := that.Req.FormValue("retoken")
|
|||
|
appid := that.Req.FormValue("appid")
|
|||
|
unionid := that.Req.FormValue("unionid")
|
|||
|
openid := that.Req.FormValue("openid")
|
|||
|
nickname := that.Req.FormValue("nickname")
|
|||
|
avatar := that.Req.FormValue("avatar")
|
|||
|
Type := ObjToInt(that.Req.FormValue("type"))
|
|||
|
|
|||
|
sn := that.Req.FormValue("sn")
|
|||
|
|
|||
|
if acttoken == "" || retoken == "" || appid == "" || unionid == "" || openid == "" || nickname == "" || avatar == "" || that.Req.FormValue("type") == "" {
|
|||
|
that.Display(3, "请求参数异常,请校验参数")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "del_flag": 0}})
|
|||
|
|
|||
|
defer func() {
|
|||
|
if sn == "" {
|
|||
|
return
|
|||
|
}
|
|||
|
if wechat.GetCeilInt("user_id") == 0 {
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
salesman := that.Db.Get("salesman", "*", Map{"sn": sn})
|
|||
|
if salesman.GetCeilInt("id") == 0 {
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
user := that.Db.Get("user", "*", Map{"id": wechat.GetCeilInt("user_id")})
|
|||
|
if user == nil {
|
|||
|
return
|
|||
|
}
|
|||
|
//用户都有企服人员关联
|
|||
|
if user.GetCeilInt("salesman_id") != 0 {
|
|||
|
|
|||
|
return
|
|||
|
}
|
|||
|
//用户没有企服商id
|
|||
|
that.Db.Update("user", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": user.GetCeilInt64("id")})
|
|||
|
|
|||
|
}()
|
|||
|
|
|||
|
if wechat != nil {
|
|||
|
//有用户直接返回
|
|||
|
if wechat.GetCeilInt("user_id") != 0 {
|
|||
|
that.Display(0, wechat)
|
|||
|
return
|
|||
|
}
|
|||
|
//没有用户继续查询数据库看是否有其他unionid
|
|||
|
wechat1 := that.Db.Get("wechat", "*", Map{"AND": Map{"unionid": unionid, "openid[!]": openid, "user_id[>]": 0, "del_flag": 0}})
|
|||
|
|
|||
|
//其他表有该数据,则更新当前表数据信息
|
|||
|
if wechat1 != nil {
|
|||
|
|
|||
|
wechat["user_id"] = wechat1.GetCeilInt("user_id")
|
|||
|
wechat["acttoken"] = acttoken
|
|||
|
wechat["retoken"] = retoken
|
|||
|
wechat["appid"] = appid
|
|||
|
wechat["unionid"] = unionid
|
|||
|
wechat["openid"] = openid
|
|||
|
wechat["nickname"] = nickname
|
|||
|
wechat["avatar"] = avatar
|
|||
|
wechat["type"] = Type
|
|||
|
|
|||
|
that.Db.Update("wechat", wechat, Map{"id": wechat.GetCeilInt("id")})
|
|||
|
that.Display(0, wechat)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
//其他表也没有当前信息,则生成user表,并更新当前用户
|
|||
|
user := Map{
|
|||
|
"nick_name": nickname,
|
|||
|
"avatar_name": avatar,
|
|||
|
"del_flag": 0,
|
|||
|
}
|
|||
|
user["id"] = that.Db.Insert("user", user)
|
|||
|
|
|||
|
wechat["user_id"] = user.GetCeilInt("id")
|
|||
|
wechat["acttoken"] = acttoken
|
|||
|
wechat["retoken"] = retoken
|
|||
|
wechat["appid"] = appid
|
|||
|
wechat["unionid"] = unionid
|
|||
|
wechat["openid"] = openid
|
|||
|
wechat["nickname"] = nickname
|
|||
|
wechat["avatar"] = avatar
|
|||
|
wechat["type"] = Type
|
|||
|
that.Db.Update("wechat", wechat, Map{"id": wechat.GetCeilInt("id")})
|
|||
|
that.Display(0, wechat)
|
|||
|
return
|
|||
|
}
|
|||
|
user := Map{
|
|||
|
"nick_name": nickname,
|
|||
|
"avatar_name": avatar,
|
|||
|
"del_flag": 0,
|
|||
|
}
|
|||
|
user["id"] = that.Db.Insert("user", user)
|
|||
|
|
|||
|
wechat = Map{}
|
|||
|
wechat["user_id"] = user.GetCeilInt("id")
|
|||
|
wechat["acttoken"] = acttoken
|
|||
|
wechat["retoken"] = retoken
|
|||
|
wechat["appid"] = appid
|
|||
|
wechat["unionid"] = unionid
|
|||
|
wechat["openid"] = openid
|
|||
|
wechat["nickname"] = nickname
|
|||
|
wechat["avatar"] = avatar
|
|||
|
wechat["type"] = Type
|
|||
|
wechat["id"] = that.Db.Insert("wechat", wechat)
|
|||
|
if wechat.GetCeilInt("id") == 0 {
|
|||
|
that.Display(4, "创建用户失败")
|
|||
|
return
|
|||
|
}
|
|||
|
that.Display(0, wechat)
|
|||
|
|
|||
|
},
|
|||
|
"check": func(that *Context) {
|
|||
|
openid := that.Req.FormValue("openid")
|
|||
|
if openid == "" {
|
|||
|
that.Display(3, "请求参数异常,请校验参数")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "user_id[!]": nil, "del_flag": 0}})
|
|||
|
|
|||
|
if wechat == nil {
|
|||
|
|
|||
|
that.Display(3, "找不到该用户")
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
that.Display(0, wechat)
|
|||
|
|
|||
|
},
|
|||
|
}
|