基础整理
This commit is contained in:
+72
-122
@@ -5,144 +5,94 @@ import (
|
||||
. "code.hoteas.com/golang/hotime/common"
|
||||
)
|
||||
|
||||
var User = Ctr{
|
||||
var UserCtr = 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, "请求参数异常,请校验参数")
|
||||
"info": func(that *Context) {
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Display(2, "没有登录")
|
||||
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)
|
||||
user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()})
|
||||
if user == nil {
|
||||
that.Display(4, "获取个人信息失败")
|
||||
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)
|
||||
delete(user, "password")
|
||||
|
||||
company := that.Db.Get("company", "id,name", Map{"id": user.GetCeilInt("company_id")})
|
||||
salesman := that.Db.Get("salesman", "id,name", Map{"id": user.GetCeilInt("salesman_id")})
|
||||
provider := that.Db.Get("provider", "id,name", Map{"id": user.GetCeilInt("provider_id")})
|
||||
|
||||
if user != nil {
|
||||
user["company"] = company
|
||||
user["salesman"] = salesman
|
||||
user["provider"] = provider
|
||||
}
|
||||
|
||||
that.Display(0, user)
|
||||
},
|
||||
"check": func(that *Context) {
|
||||
openid := that.Req.FormValue("openid")
|
||||
if openid == "" {
|
||||
that.Display(3, "请求参数异常,请校验参数")
|
||||
|
||||
"auth": func(that *Context) {
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Display(2, "没有登录")
|
||||
return
|
||||
}
|
||||
},
|
||||
|
||||
"edit": func(that *Context) {
|
||||
if that.Session("user_id").Data != nil {
|
||||
that.Display(2, "没有登录")
|
||||
return
|
||||
}
|
||||
|
||||
wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "user_id[!]": nil, "del_flag": 0}})
|
||||
name := that.Req.FormValue("name")
|
||||
nickname := that.Req.FormValue("nickname")
|
||||
sex := that.Req.FormValue("sex")
|
||||
email := that.Req.FormValue("email")
|
||||
avatar := that.Req.FormValue("avatar")
|
||||
address := that.Req.FormValue("address")
|
||||
phone := that.Req.FormValue("phone") //如果更换手机号则要有新的短信验证码
|
||||
code := that.Req.FormValue("code")
|
||||
|
||||
if wechat == nil {
|
||||
data := Map{"modify_time[#]": "now()"}
|
||||
if name != "" {
|
||||
data["name"] = name
|
||||
}
|
||||
if nickname != "" {
|
||||
data["nickname"] = nickname
|
||||
}
|
||||
if sex != "" {
|
||||
data["sex"] = sex
|
||||
}
|
||||
if email != "" {
|
||||
data["email"] = email
|
||||
}
|
||||
if avatar != "" {
|
||||
data["avatar"] = avatar
|
||||
}
|
||||
if address != "" {
|
||||
data["address"] = address
|
||||
}
|
||||
if phone != "" {
|
||||
|
||||
that.Display(3, "找不到该用户")
|
||||
//微信验证成功
|
||||
if that.Session("wechat_phone").ToStr() == phone {
|
||||
data["phone"] = phone
|
||||
} else if code == "" || that.Session("phone").ToStr() != phone || that.Session("code").ToStr() != code {
|
||||
that.Display(3, "手机短信验证失败")
|
||||
return
|
||||
}
|
||||
data["phone"] = phone
|
||||
}
|
||||
|
||||
re := that.Db.Update("user", data, Map{"id": that.Session("user_id").Data})
|
||||
if re == 0 {
|
||||
that.Display(4, "更新失败")
|
||||
return
|
||||
}
|
||||
|
||||
that.Display(0, wechat)
|
||||
|
||||
that.Display(4, "修改成功")
|
||||
},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user