package app import ( . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" ) var Salesman = 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") phone := that.Req.FormValue("phone") Type := ObjToInt(that.Req.FormValue("type")) if acttoken == "" || retoken == "" || appid == "" || unionid == "" || openid == "" || nickname == "" || avatar == "" || that.Req.FormValue("type") == "" || phone == "" { that.Display(3, "请求参数异常,请校验参数") return } wechat := that.Db.Get("wechat", "*", Map{"AND": Map{"openid": openid, "del_flag": 0}}) salesman := that.Db.Get("salesman", "*", Map{"phone": phone}) if salesman == nil { that.Display(3, "找不到企服商") return } if wechat != nil { //有用户直接返回 if wechat.GetCeilInt("salesman_id") != 0 && wechat.GetCeilInt64("salesman_id") == salesman.GetInt64("id") { that.Display(0, wechat) return } that.Db.Update("wechat", Map{"salesman_id": salesman.GetCeilInt64("id")}, Map{"id": wechat.GetInt64("id")}) wechat["salesman_id"] = salesman.GetCeilInt64("id") that.Display(0, wechat) return } wechat = Map{} wechat["salesman_id"] = salesman.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) }, }