package app import ( . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" ) var UserCtr = Ctr{ "test": func(that *Context) { that.Session("user_id", 1) that.Session("wechat_id", 1) that.Display(0, 1) }, //用户微信公众号或者小程序登录 "info": func(that *Context) { if that.Session("user_id").Data == nil { that.Display(2, "没有登录") return } user := that.Db.Get("user", "*", Map{"id": that.Session("user_id").ToCeilInt()}) if user == nil { that.Display(2, "获取个人信息失败") return } 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) }, "edit": func(that *Context) { if that.Session("user_id").Data == nil { that.Display(2, "没有登录") return } 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") 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 != "" { //微信验证成功 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, "修改成功") }, }