重新索引

This commit is contained in:
hoteas 2023-03-03 06:31:30 +08:00
parent 6ff34dc11b
commit 7c427d8692
4 changed files with 563 additions and 494 deletions

View File

@ -187,8 +187,11 @@ var User = Ctr{
return return
} }
} }
uWhere := Map{"phone": phone}
user := this.Db.Get("user", "*", Map{"phone": phone}) if this.Session("user_id").ToCeilInt() != 0 {
uWhere = Map{"id": this.Session("user_id").ToCeilInt()}
}
user := this.Db.Get("user", "*", uWhere)
data := Map{"name": name, data := Map{"name": name,
"phone": phone, "phone": phone,
//"org_id": orgId, //"org_id": orgId,

View File

@ -45,38 +45,104 @@ var Wechat = Ctr{
}, },
//微信注册0已经完整的注册了1还没有注册 //微信注册0已经完整的注册了1还没有注册
"codebase": func(this *Context) { "codebase": func(this *Context) {
//wx := Weixin(this)
////auth := wx.GetOauth(this.Req, this.Resp)
//auth := wx.GetOauth()
//resToken, err := auth.GetUserAccessToken(this.Req.FormValue("code"))
//if err != nil {
// this.Display(6, "code错误")
// return
//}
//
////判断用户是否已经注册
//user := this.Db.Get("wechat", Map{"[><]user": "wechat.user_id=user.id"}, "user.id,user.state", Map{"openid": resToken.OpenID})
//if user != nil {
// this.Session("user_id", user.Get("id"))
// this.Display(0, 0)
// return
//}
//
//user_id := this.Db.Insert("user", Map{"create_time": time.Now().Unix(), "modify_time": time.Now().Unix(), "state": 2})
//if user_id == 0 {
// this.Display(4, "创建用户失败")
// return
//}
//
//wid := this.Db.Insert("wechat", Map{"openid": resToken.OpenID, "appid": this.Config.GetString("wechatAppID"), "state": 1, "user_id": user_id})
//if wid == 0 {
// this.Display(4, "关联微信失败!")
// return
//}
//
//this.Session("user_id", user.Get("id"))
//
//this.Display(0, 1)
orgId := ObjToInt(this.Req.FormValue("org_id"))
//if orgId==0{
// this.Display(3, "缺少组织id")
// return
//}
wx := Weixin(this) wx := Weixin(this)
//auth := wx.GetOauth(this.Req, this.Resp) //auth := wx.GetOauth(this.Req, this.Resp)
auth := wx.GetOauth() auth := wx.GetOauth()
resToken, err := auth.GetUserAccessToken(this.Req.FormValue("code")) resToken, err := auth.GetUserAccessToken(this.Req.FormValue("code"))
if err != nil { if err != nil {
this.Display(6, "code错误") this.Display(5, "code错误")
return return
} }
//判断用户是否已经注册 //判断用户是否已经注册
user := this.Db.Get("wechat", Map{"[><]user": "wechat.user_id=user.id"}, "user.id,user.state", Map{"openid": resToken.OpenID}) user := this.Db.Get("wechat", Map{"[><]user": "wechat.user_id=user.id"}, "user.id,user.state", Map{"openid": resToken.OpenID})
if user != nil { if user != nil && user.GetCeilInt("id") != 0 && user.GetCeilInt("state") == 0 {
this.Session("user_id", user.Get("id")) this.Session("user_id", user.Get("id"))
this.Display(0, 0) this.Display(0, Map{"type": 0, "token": this.SessionId})
return
}
//getUserInfo
userInfo, err := auth.GetUserInfo(resToken.AccessToken, resToken.OpenID)
if err != nil {
this.Display(6, "微信个人信息无法获取")
return return
} }
user_id := this.Db.Insert("user", Map{"create_time": time.Now().Unix(), "modify_time": time.Now().Unix(), "state": 2}) fmt.Println(userInfo)
if user_id == 0 {
this.Display(4, "创建用户失败") //wechatInfo := ObjToMap(userInfo)
return t := time.Now().Unix()
wechatInfo := Map{
"openid": userInfo.OpenID,
"acttoken": resToken.AccessToken,
"retoken": resToken.RefreshToken,
"appid": this.Config.GetString("wechatAppID"),
"unionid": userInfo.Unionid,
"nickname": userInfo.Nickname,
"avatar": userInfo.HeadImgURL,
}
if orgId != 0 {
wechatInfo["org_id"] = orgId
wechatInfo["status"] = 0
} }
wid := this.Db.Insert("wechat", Map{"openid": resToken.OpenID, "appid": this.Config.GetString("wechatAppID"), "state": 1, "user_id": user_id}) wechatDb := this.Db.Get("wechat", "*", Map{"openid": wechatInfo.GetString("openid")})
if wid == 0 {
this.Display(4, "关联微信失败!") if wechatDb != nil {
return
this.Db.Update("wechat", wechatInfo, Map{"id": wechatDb.GetCeilInt("id")})
//userInfo["wid"]=wechatDb.GetCeilInt("wid")
} else {
wechatInfo["create_time"] = t
wechatInfo["id"] = this.Db.Insert("wechat", wechatInfo)
} }
wechatDb = this.Db.Get("wechat", "*", Map{"openid": wechatInfo.GetString("openid")})
this.Session("user_id", user.Get("id")) this.Session("wechatInfo", wechatDb)
fmt.Println(wechatDb)
fmt.Println(this.Session("wechatInfo"))
//this.Display(0, 1)
this.Display(0, Map{"type": 1, "token": this.SessionId})
this.Display(0, 1)
}, },
//微信注册0已经完整的注册了1还没有注册 //微信注册0已经完整的注册了1还没有注册
"code": func(this *Context) { "code": func(this *Context) {

File diff suppressed because it is too large Load Diff

Binary file not shown.