package app import ( . "code.hoteas.com/golang/hotime" . "code.hoteas.com/golang/hotime/common" "errors" "time" ) // Project 管理端项目 var Project = Proj{ "lxcx": Lxcx, "websocket": WebsocketCtr, "wechath5": Wechath5, "wechatmini": Wechath5, "provider": ProviderCtr, } //生成随机码的6位md5 func getSn() string { x := Rand(8) return Substr(Md5(ObjToStr(int64(x)+time.Now().UnixNano()+int64(Rand(6)))), 0, 6) } //生成随机码的4位随机数 func getCode() string { //res := "" //for i := 0; i < 4; i++ { res := ObjToStr(RandX(1000, 9999)) //} return res } //认证公共方案 func auth(that *Context, phone, companyName string) error { user := that.Db.Get("user", "id,phone,salesman_id,company_id,provider_id", Map{"id": that.Session("user_id").ToCeilInt()}) if user == nil { return errors.New("找不到用户") } //手机号与原来的不同则进行绑定 if phone != user.GetString("phone") { //微信验证成功 if that.Session("wechat_phone").ToStr() == phone { that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")}) if user.GetCeilInt("company_id") != 0 { that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")}) } user["phone"] = phone } else if that.Req.FormValue("code") == "" || that.Session("phone").ToStr() != phone || that.Session("code").ToStr() != that.Req.FormValue("code") { return errors.New("验证码错误") } else { that.Db.Update("user", Map{"phone": phone}, Map{"id": user.GetCeilInt("id")}) if user.GetCeilInt("company_id") != 0 { that.Db.Update("company", Map{"phone": phone}, Map{"id": user.GetCeilInt("company_id")}) } user["phone"] = phone } } // company := that.Db.Get("company", "name,id", Map{"id": user.GetCeilInt("company_id")}) if company != nil { that.Db.Update("company", Map{"name": companyName}, Map{"id": company.GetCeilInt64("id")}) if user.GetCeilInt64("salesman_id") != 0 { that.Db.Update("user", Map{"certification_flag": 1}, Map{"id": user.GetCeilInt("id")}) } return nil } company = Map{"name": companyName, "user_id": user.GetCeilInt("id"), } if user.GetCeilInt("salesman_id") != 0 { company["salesman_id"] = user.GetCeilInt("salesman_id") } if user.GetCeilInt("provider_id") != 0 { company["provider_id"] = user.GetCeilInt("provider_id") } if user.GetString("phone") != "" { company["phone"] = user.GetString("phone") } company["id"] = that.Db.Insert("company", company) if company.GetCeilInt64("id") == 0 { return errors.New("新建企业失败") } upUser := Map{"company_id": company.GetCeilInt64("id")} if user.GetCeilInt64("salesman_id") != 0 { upUser["certification_flag"] = 1 } that.Db.Update("user", upUser, Map{"id": that.Session("user_id").Data}) return nil }